-
Notifications
You must be signed in to change notification settings - Fork 0
/
collect.js
49 lines (44 loc) · 1.5 KB
/
collect.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
import { readYAML, writeJsonData } from './utils.js'
import esMain from 'es-main'
import { disarmament } from './disarmament.js'
import { populationInfo } from './population.js'
import { other } from './treaty.js'
const getAllData = async (inputs) => {
const { otherUNTreaties, disarmamentTreaties, nwfzTreaties } = inputs
const [otherData, disarmamentData, nwfzData] = await Promise.all([
other(otherUNTreaties),
disarmament(disarmamentTreaties),
disarmament(nwfzTreaties)
])
return Object.assign({}, otherData, disarmamentData, nwfzData)
}
const aggregate = (rawData) => {
const results = {}
for (const [treaty, data] of Object.entries(rawData)) {
for (const [countryCode, { signed, joined, joiningMechanism, withdrew }] of Object.entries(data)) {
if (results[countryCode] === undefined) {
results[countryCode] = {}
}
results[countryCode][treaty] = { signed, joined, joiningMechanism, withdrew }
}
}
return results
}
export const collectAllData = async () => {
const inputs = readYAML('inputs.yaml')
const [rawTreatyData, populationData] = await Promise.all([
getAllData(inputs),
populationInfo()
])
const aggregatedData = aggregate(rawTreatyData)
writeJsonData('raw.json', rawTreatyData)
writeJsonData('population.json', populationData)
writeJsonData('aggregated.json', aggregatedData)
return { rawTreatyData, populationData, aggregatedData }
}
const main = async () => {
await collectAllData()
}
if (esMain(import.meta)) {
main()
}