-
Notifications
You must be signed in to change notification settings - Fork 16
/
generate_prefecture_history.js
63 lines (49 loc) · 1.61 KB
/
generate_prefecture_history.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
const fs = require('fs')
const _ = require('lodash')
const moment = require('moment')
const Papa = require('papaparse')
const Prefectures = require('./src/prefectures.js')
const main = () => {
const today = moment()
const startDate = moment('2020-03-26')
const prefectureNames = Prefectures.prefectureNamesEn()
const prefectureRecoveries = {
'Port Quarantine': {},
'Unspecified': {}
}
for (const prefectureName of prefectureNames) {
prefectureRecoveries[prefectureName] = {}
}
let date = startDate
let dates = []
while (date < today) {
const dateString = date.format('YYYY-MM-DD')
const filename = `docs/summary/${dateString}.json`
if (fs.statSync(filename).isFile()) {
console.log(filename)
dates.push(dateString)
const summary = JSON.parse(fs.readFileSync(filename))
for (const prefectureDay of summary.prefectures) {
const recovered = prefectureDay.recovered
if (prefectureRecoveries[prefectureDay.name]) {
prefectureRecoveries[prefectureDay.name][dateString] = recovered
}
}
}
date = date.add(1, 'days')
}
const csvData = _.map(_.keys(prefectureRecoveries), k => {
let v = prefectureRecoveries[k]
let o = Object.assign({name: k}, v)
return o
})
let csvString = Papa.unparse(csvData, {
header: true,
columns: _.concat(['name'], _.reverse(dates))
})
console.log(csvData)
fs.writeFileSync('./docs/prefecture_recoveries.csv', csvString)
fs.writeFileSync('./docs/prefecture_recoveries.json', JSON.stringify(prefectureRecoveries))
//console.log(prefectureRecoveries)
}
main()