Convert value array to object properties
This commit is contained in:
parent
2875f8a96b
commit
127ba3c375
@ -26,15 +26,33 @@ async function main() {
|
|||||||
fs.readFileSync(options.uberPath ?? "./uberResults.json", "utf8"),
|
fs.readFileSync(options.uberPath ?? "./uberResults.json", "utf8"),
|
||||||
)
|
)
|
||||||
let processedData = uberResults
|
let processedData = uberResults
|
||||||
.filter((res) => res)
|
.filter((res) => res && !res.failedRequest)
|
||||||
.map((result) => {
|
.map((result) => {
|
||||||
result.values = extractValuesAndLabels(result.unparsedData)
|
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
|
delete result.unparsedData
|
||||||
if (!result.values.length) {
|
if (!result.values.length) {
|
||||||
delete result.values
|
delete result.values
|
||||||
}
|
}
|
||||||
return result
|
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))
|
fs.writeFileSync("./resultsProcessed.json", JSON.stringify(processedData))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user