This repository has been archived by the owner on Jul 31, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanAllRPFG3.js
89 lines (80 loc) · 2.71 KB
/
cleanAllRPFG3.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import fs from 'fs'
import dataInelgiblerpgf3 from './metadatarpgf3.json' assert { type: 'json' }
import dataEligiblerpgf3 from './test_result_rpgf3.json' assert { type: 'json' }
import address from './metadataAddress.json' assert { type: 'json' }
let finalData1 = []
let tempData = []
let finalData2 = []
let mergeData = []
for (let [index, value] of dataInelgiblerpgf3.entries()) {
// const newAddress = address[index].substring(60, 102)
const newAddress1 = address[index]
const newAddress2 = newAddress1.substring(60, 102)
const newObj = {
...value,
metadataPtr: newAddress1,
address: newAddress2,
statusReview: 'remove',
statusRPGF3: 'ineligible',
'New Main-Category': null,
ballot: null,
median: null,
scaled: null,
rank: null,
}
console.log(newAddress1, newAddress2)
finalData1.push(newObj)
}
for (let [index, value] of finalData1.entries()) {
let duplicate = false
for (let each of dataEligiblerpgf3) {
if (value['displayName'] === each['displayName']) {
duplicate = true
}
}
if (duplicate === false) {
let newStatus = 'ineligible'
if (value.ballot >= 17 && value.scaled != 0) {
newStatus = 'eligible'
}
const newObj = {
...value,
statusReview: 'pass',
statusRPGF3: newStatus,
}
tempData.push(newObj)
}
}
finalData2 = [...dataEligiblerpgf3, ...tempData]
console.log(finalData1.length, finalData2.length)
mergeData = [...finalData2]
console.log(mergeData.length)
// function removeBackslashesAndNewlines(obj) {
// const result = {}
// for (const key in obj) {
// if (Object.prototype.hasOwnProperty.call(obj, key)) {
// const value = obj[key]
// if (typeof value === 'string') {
// // Replace backslashes and newlines globally in the string
// result[key] = value.replace(/\\ /g, '').replace(/\\n/g, '')
// } else if (typeof value === 'object' && value !== null) {
// // Recursively remove backslashes and newlines from nested objects
// result[key] = removeBackslashesAndNewlines(value)
// } else {
// // For non-string and non-object values, just copy as is
// result[key] = value
// }
// }
// }
// return result
// }
// for (let i = 0; i < dataEligiblerpgf3.length; i++) {
// const objectWithoutBackslashesAndNewlines = removeBackslashesAndNewlines(
// dataEligiblerpgf3[i]
// )
// console.log(objectWithoutBackslashesAndNewlines)
// finalData2.push(objectWithoutBackslashesAndNewlines)
// }
fs.writeFileSync('finalDataRPGF3_1.json', JSON.stringify(finalData1, null, 2))
fs.writeFileSync('finalDataRPGF3_2.json', JSON.stringify(finalData2, null, 2))
fs.writeFileSync('finalDataRPGF3.json', JSON.stringify(mergeData, null, 2))