Start on processing file
This commit is contained in:
parent
62278a33c3
commit
2875f8a96b
@ -2,4 +2,5 @@
|
||||
"uberPhoneNumber": "1234567891",
|
||||
"startDateIso": "2023-01-01",
|
||||
"endDateIso": "2023-12-31"
|
||||
"uberPath": "./uberResults.json"
|
||||
}
|
||||
|
41
src/generateCSV.js
Normal file
41
src/generateCSV.js
Normal file
@ -0,0 +1,41 @@
|
||||
import fs from "fs"
|
||||
import * as utils from "./utils.js"
|
||||
|
||||
function extractValuesAndLabels(data) {
|
||||
const result = []
|
||||
|
||||
function traverse(obj) {
|
||||
if (obj?.value) {
|
||||
result.push({ value: obj.value / 100000, label: obj.label })
|
||||
} else if (typeof obj === "object" && obj !== null) {
|
||||
for (const key in obj) {
|
||||
if (obj.hasOwnProperty(key)) {
|
||||
traverse(obj[key])
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
traverse(data)
|
||||
return result
|
||||
}
|
||||
|
||||
async function main() {
|
||||
let options = JSON.parse(fs.readFileSync("./options.json", "utf8"))
|
||||
let uberResults = JSON.parse(
|
||||
fs.readFileSync(options.uberPath ?? "./uberResults.json", "utf8"),
|
||||
)
|
||||
let processedData = uberResults
|
||||
.filter((res) => res)
|
||||
.map((result) => {
|
||||
result.values = extractValuesAndLabels(result.unparsedData)
|
||||
delete result.unparsedData
|
||||
if (!result.values.length) {
|
||||
delete result.values
|
||||
}
|
||||
return result
|
||||
})
|
||||
fs.writeFileSync("./resultsProcessed.json", JSON.stringify(processedData))
|
||||
}
|
||||
|
||||
main()
|
Loading…
x
Reference in New Issue
Block a user