Generate csv
This commit is contained in:
parent
127ba3c375
commit
0af3bb24eb
1
.gitignore
vendored
1
.gitignore
vendored
@ -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
6
package-lock.json
generated
@ -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",
|
||||||
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user