Generate csv

This commit is contained in:
PAlexanderFranklin 2024-01-03 17:54:56 -08:00
parent 127ba3c375
commit 0af3bb24eb
4 changed files with 22 additions and 9 deletions

1
.gitignore vendored
View File

@ -1,5 +1,6 @@
node_modules node_modules
options*.json options*.json
results*.json results*.json
results*.csv
uberResults*.json uberResults*.json
lyftResults*.json lyftResults*.json

6
package-lock.json generated
View File

@ -9,6 +9,7 @@
"version": "1.0.0", "version": "1.0.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"papaparse": "^5.4.1",
"puppeteer-core": "^21.1.1" "puppeteer-core": "^21.1.1"
} }
}, },
@ -557,6 +558,11 @@
"node": ">= 14" "node": ">= 14"
} }
}, },
"node_modules/papaparse": {
"version": "5.4.1",
"resolved": "https://registry.npmjs.org/papaparse/-/papaparse-5.4.1.tgz",
"integrity": "sha512-HipMsgJkZu8br23pW15uvo6sib6wne/4woLZPlFf3rpDyMe9ywEXUsuD7+6K9PRkJlVT51j/sCOYDKGGS3ZJrw=="
},
"node_modules/pend": { "node_modules/pend": {
"version": "1.2.0", "version": "1.2.0",
"resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz", "resolved": "https://registry.npmjs.org/pend/-/pend-1.2.0.tgz",

View File

@ -11,6 +11,7 @@
"author": "", "author": "",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"papaparse": "^5.4.1",
"puppeteer-core": "^21.1.1" "puppeteer-core": "^21.1.1"
} }
} }

View File

@ -1,5 +1,6 @@
import fs from "fs" import fs from "fs"
import * as utils from "./utils.js" import * as utils from "./utils.js"
import Papa from "papaparse"
function extractValuesAndLabels(data) { function extractValuesAndLabels(data) {
const result = [] const result = []
@ -25,6 +26,7 @@ async function main() {
let uberResults = JSON.parse( let uberResults = JSON.parse(
fs.readFileSync(options.uberPath ?? "./uberResults.json", "utf8"), fs.readFileSync(options.uberPath ?? "./uberResults.json", "utf8"),
) )
let columns = new Set()
let processedData = uberResults let processedData = uberResults
.filter((res) => res && !res.failedRequest) .filter((res) => res && !res.failedRequest)
.map((result) => { .map((result) => {
@ -41,19 +43,22 @@ async function main() {
if (!result.values.length) { if (!result.values.length) {
delete result.values delete result.values
} }
// find all properties to make columns with
for (const [key, value] of Object.entries(result)) {
columns.add(key)
}
return result return result
}) })
processedData.forEach((activity) => { .map((result) => {
let labels = {} columns.forEach((column) => {
activity.values?.forEach((value) => { if (typeof result[column] == "undefined") {
if (labels[value.label]) { result[column] = null
console.log(activity) }
} else { })
labels[value.label] = true return result
}
}) })
})
fs.writeFileSync("./resultsProcessed.json", JSON.stringify(processedData)) fs.writeFileSync("./resultsProcessed.json", JSON.stringify(processedData))
fs.writeFileSync("./resultsProcessed.csv", Papa.unparse(processedData))
} }
main() main()