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
/
Copy pathretropgf3.js
216 lines (199 loc) · 7.88 KB
/
retropgf3.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
import fs from 'fs'
import fetchData from './retropgf3.json' assert { type: 'json' }
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))
jsonData.table.rows.forEach((row) => {
let obj = {}
row.c.forEach((cell, index) => {
if (cell && cell.v) {
if (
jsonData.table.cols[index].label === 'displayName' ||
jsonData.table.cols[index].label === 'Approval Attestation ID' ||
jsonData.table.cols[index].label === 'New Main-Category'
) {
obj[jsonData.table.cols[index].label] = cell.v
}
}
})
fetchData.push(obj)
})
} catch (err) {
console.error(err)
} finally {
fs.writeFileSync('retropgf3.json', JSON.stringify(fetchData))
}
}
let countBallotFetch = 0
const fetchBallot = async () => {
for (let i = 0; i < fetchData.length; i++) {
const each = fetchData[i]
console.log(each.displayName, each['Approval Attestation ID'])
try {
const query = {
query:
'query RetroPGFApplicationPageRouteQuery(\n $id: ID!\n) {\n retroPGF {\n project(id: $id) {\n id\n ...RetroPGFApplicationBannerFragment\n ...RetroPGFApplicationContentFragment\n }\n }\n}\n\nfragment ENSAvatarFragment on ResolvedName {\n name\n}\n\nfragment NounResolvedLinkFragment on ResolvedName {\n address\n ...NounResolvedNameFragment\n}\n\nfragment NounResolvedNameFragment on ResolvedName {\n address\n name\n}\n\nfragment RetroPGFAddProjectToBallotModalContentFragment on Project {\n id\n ...RetroPGFModalApplicationRowFragment\n}\n\nfragment RetroPGFApplicationBannerFragment on Project {\n id\n bio\n impactCategory\n displayName\n websiteUrl\n applicant {\n address {\n address\n resolvedName {\n ...NounResolvedLinkFragment\n }\n }\n id\n }\n applicantType\n profile {\n profileImageUrl\n bannerImageUrl\n id\n }\n includedInBallots\n ...RetroPGFAddProjectToBallotModalContentFragment\n}\n\nfragment RetroPGFApplicationContentContributionLinkFragment on ContributionLink {\n type\n url\n description\n}\n\nfragment RetroPGFApplicationContentFragment on Project {\n impactDescription\n contributionDescription\n contributionLinks {\n ...RetroPGFApplicationContentContributionLinkFragment\n }\n impactMetrics {\n ...RetroPGFApplicationContentImpactMetricFragment\n }\n ...RetroPGFApplicationContentFundingSourceFragment\n ...RetroPGFApplicationListContainerFragment\n}\n\nfragment RetroPGFApplicationContentFundingSourceFragment on Project {\n fundingSources {\n type\n currency\n amount\n description\n }\n}\n\nfragment RetroPGFApplicationContentImpactMetricFragment on ImpactMetric {\n description\n number\n url\n}\n\nfragment RetroPGFApplicationListContainerFragment on Project {\n lists {\n ...RetroPGFListRowFragment\n id\n }\n}\n\nfragment RetroPGFListRowFragment on List {\n id\n author {\n resolvedName {\n ...NounResolvedNameFragment\n ...ENSAvatarFragment\n }\n }\n listName\n listDescription\n categories\n listContent {\n project {\n displayName\n profile {\n profileImageUrl\n id\n }\n id\n }\n }\n}\n\nfragment RetroPGFModalApplicationRowFragment on Project {\n displayName\n bio\n profile {\n profileImageUrl\n id\n }\n}\n',
variables: {
id: each['Approval Attestation ID'],
},
}
const rawData = await fetch('https://vote.optimism.io/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify(query),
})
const newData = await rawData.json()
const totalBallots = newData.data.retroPGF.project.includedInBallots
// const typeProjects = newData.data.retroPGF.project.applicantType
const totalLists = newData.data.retroPGF.project.lists.length
// Create a new object with the existing data and the ballot count
const { displayName, ...rest } = each
fetchData[i] = {
...rest,
name: displayName,
value: totalBallots,
// type: typeProjects,
lists: totalLists,
}
// Log the updated data
console.log(fetchData[i])
} catch (err) {
console.error(err)
// Retry after a delay in case of an error
await new Promise((resolve) => setTimeout(resolve, 2000))
} finally {
countBallotFetch++
console.log(countBallotFetch)
}
}
}
const categoriesFilter = () => {
const opStackData = fetchData
.filter((each) => each['New Main-Category'] === 'OP_Stack')
.map(
({
'Approval Attestation ID': x,
'New Main-Category': y,
lists: z,
...rest
}) => rest
)
const collectiveGovernanceData = fetchData
.filter((each) => each['New Main-Category'] === 'Collective_Governance')
.map(
({
'Approval Attestation ID': x,
'New Main-Category': y,
lists: z,
...rest
}) => rest
)
const developerEcosystemData = fetchData
.filter((each) => each['New Main-Category'] === 'Developer_Ecosystem')
.map(
({
'Approval Attestation ID': x,
'New Main-Category': y,
lists: z,
...rest
}) => rest
)
const endUserExperienceAdoptionData = fetchData
.filter(
(each) => each['New Main-Category'] === 'End_User_Experience_Adoption'
)
.map(
({
'Approval Attestation ID': x,
'New Main-Category': y,
lists: z,
...rest
}) => rest
)
fs.writeFileSync('opStackData.json', JSON.stringify(opStackData))
fs.writeFileSync(
'collectiveGovernanceData.json',
JSON.stringify(collectiveGovernanceData)
)
fs.writeFileSync(
'developerEcosystemData.json',
JSON.stringify(developerEcosystemData)
)
fs.writeFileSync(
'endUserExperienceAdoptionData.json',
JSON.stringify(endUserExperienceAdoptionData)
)
}
const listFilter = () => {
const listOpStackData = fetchData
.filter((each) => each['New Main-Category'] === 'OP_Stack')
.map(
({
'Approval Attestation ID': x,
'New Main-Category': y,
value: z,
...rest
}) => rest
)
const listCollectiveGovernanceData = fetchData
.filter((each) => each['New Main-Category'] === 'Collective_Governance')
.map(
({
'Approval Attestation ID': x,
'New Main-Category': y,
value: z,
...rest
}) => rest
)
const listDeveloperEcosystemData = fetchData
.filter((each) => each['New Main-Category'] === 'Developer_Ecosystem')
.map(
({
'Approval Attestation ID': x,
'New Main-Category': y,
value: z,
...rest
}) => rest
)
const listEndUserExperienceAdoptionData = fetchData
.filter(
(each) => each['New Main-Category'] === 'End_User_Experience_Adoption'
)
.map(
({
'Approval Attestation ID': x,
'New Main-Category': y,
value: z,
...rest
}) => rest
)
fs.writeFileSync('listOpStackData.json', JSON.stringify(listOpStackData))
fs.writeFileSync(
'listCollectiveGovernanceData.json',
JSON.stringify(listCollectiveGovernanceData)
)
fs.writeFileSync(
'listDeveloperEcosystemData.json',
JSON.stringify(listDeveloperEcosystemData)
)
fs.writeFileSync(
'listEndUserExperienceAdoptionData.json',
JSON.stringify(listEndUserExperienceAdoptionData)
)
}
const wait = async () => {
await fetchBallot()
await categoriesFilter()
await listFilter()
}
wait()