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
/
rpgf3.js
62 lines (59 loc) · 1.74 KB
/
rpgf3.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
import fs from 'fs'
import result from './rpgf3_result.json' assert { type: 'json' }
let fetchData = []
let fetchDataNew = []
let finalData = []
const fetchSheet = async () => {
try {
let query = encodeURIComponent('Select *')
let sheet = 'Metadata_full'
const sheetID = '13ihSoZycgH2h6ZvlARuj7q2zPvGtBqQ8LoNrJemTUU4'
let data = await fetch(
`https://docs.google.com/spreadsheets/d/${sheetID}/gviz/tq?tqx=out:json&sheet=${sheet}&tq=${query}`
)
data = await data.text()
let jsonData = await JSON.parse(data.slice(47, -2))
await jsonData.table.rows.forEach(async (row) => {
let obj = {}
row.c.forEach((cell, index) => {
if (cell) {
if (cell.v) {
obj[jsonData.table.cols[index].label] = cell.v
}
}
})
fetchData.push(obj)
})
} catch (err) {
console.log(err)
} finally {
fetchDataNew = fetchData
// console.log(fetchDataNew.length)
}
}
const resultData = async () => {
for (let each of fetchDataNew) {
for (let [index, each2] of result.entries()) {
console.log(each['Approval Attestation ID'], each2['project_id'])
if (each['Approval Attestation ID'] === each2['project_id']) {
const { votes_count, median_amount, scaled_amount, ...left } = each2
const newObj = {
...each,
ballot: votes_count,
median: median_amount,
scaled: scaled_amount,
rank: index + 1,
}
finalData.push(newObj)
}
}
}
console.log(finalData.length)
fs.writeFileSync('test_result_rpgf3.json', JSON.stringify(finalData))
}
const mergeData = async () => {
await fetchSheet()
await resultData()
finalData.sort((a, b) => a['scaled'] - b['scaled'])
}
mergeData()