-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#54: Finished basic data availability report
- Loading branch information
darnjo
committed
Sep 26, 2023
1 parent
171114a
commit 2fe0a22
Showing
3 changed files
with
88 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,3 +106,4 @@ dist | |
.DS_Store | ||
.vscode | ||
output | ||
data-availability-report.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
'use strict'; | ||
|
||
const { writeFile } = require('fs/promises'); | ||
|
||
/* | ||
{ | ||
"description": "RESO Data Availability Report", | ||
"version": "1.7", | ||
"generatedOn": "2023-09-11T17:37:06.066Z", | ||
"resources": [ | ||
{ | ||
"resourceName": "Office", | ||
"recordCount": 1751, | ||
"numRecordsFetched": 1709, | ||
"numSamples": 18, | ||
"pageSize": 100, | ||
"averageResponseBytes": 106953, | ||
"averageResponseTimeMs": 547, | ||
"dateField": "ModificationTimestamp", | ||
"dateLow": "2019-08-14T13:59:06Z", | ||
"dateHigh": "2023-08-28T13:46:24Z", | ||
"keyFields": [ | ||
"OfficeKey" //TODO: key fields needs to be in the metadata report instead | ||
] | ||
}, | ||
"fields": [ | ||
], | ||
"lookups": [], | ||
"lookupValues": [] | ||
} | ||
*/ | ||
const scorePayload = (records = [], availabilityMap = {}) => { | ||
records.forEach(r => { | ||
Object.entries(r).forEach(([k, v]) => { | ||
if (!availabilityMap?.[k]) { | ||
availabilityMap[k] = 0; | ||
} | ||
|
||
if (!!v) { | ||
availabilityMap[k]++; | ||
} | ||
}); | ||
}); | ||
|
||
return availabilityMap; | ||
}; | ||
|
||
const consolidateResults = (availabilityMap = {}, totalRecordCount = 0) => { | ||
return { | ||
totalRecordCount, | ||
fields: Object.entries(availabilityMap ?? {}).map(([k, v]) => { | ||
return { fieldName: k, frequency: v }; | ||
}) | ||
}; | ||
}; | ||
|
||
const writeDataAvailabilityReport = async (availabilityMap = {}, totalRecordCount = 0) => { | ||
const AVAILABILITY_REPORT_FILENAME = 'data-availability-report.json'; | ||
|
||
try { | ||
await writeFile( | ||
AVAILABILITY_REPORT_FILENAME, | ||
JSON.stringify( | ||
{ | ||
description: 'RESO Data Availability Report', | ||
version: '1.7', | ||
generatedOn: new Date().toISOString(), | ||
fields: consolidateResults(availabilityMap, totalRecordCount) | ||
}, | ||
null, | ||
' ' | ||
) | ||
); | ||
|
||
console.log(`Results written to ${AVAILABILITY_REPORT_FILENAME}`); | ||
} catch (err) { | ||
console.error(err); | ||
} | ||
}; | ||
|
||
module.exports = { | ||
scorePayload, | ||
writeDataAvailabilityReport | ||
}; |