From 127ba3c375511a90bc7aa0c11ed094f735edc92a Mon Sep 17 00:00:00 2001 From: PAlexanderFranklin Date: Wed, 3 Jan 2024 17:32:54 -0800 Subject: [PATCH] Convert value array to object properties --- src/generateCSV.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/generateCSV.js b/src/generateCSV.js index 13e1dca..076a5a7 100644 --- a/src/generateCSV.js +++ b/src/generateCSV.js @@ -26,15 +26,33 @@ async function main() { fs.readFileSync(options.uberPath ?? "./uberResults.json", "utf8"), ) let processedData = uberResults - .filter((res) => res) + .filter((res) => res && !res.failedRequest) .map((result) => { result.values = extractValuesAndLabels(result.unparsedData) + result.values.forEach((value) => { + if (typeof result[value.label] == "undefined") { + result[value.label] = value.value + } + }) + result.values = result.values.filter( + (value) => value.value !== result[value.label], + ) delete result.unparsedData if (!result.values.length) { delete result.values } return result }) + processedData.forEach((activity) => { + let labels = {} + activity.values?.forEach((value) => { + if (labels[value.label]) { + console.log(activity) + } else { + labels[value.label] = true + } + }) + }) fs.writeFileSync("./resultsProcessed.json", JSON.stringify(processedData)) }