forked from MaJingRui-SH/Coronavirus-Dashboard
-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncData.js
36 lines (31 loc) · 914 Bytes
/
syncData.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
const globals = require("./globals");
const fs = require("fs");
const utilities = require("./utilities");
exports.gatherAllRegions = () => {
return Promise.all(
globals.allRegions.map(region =>
fs.promises.readFile(utilities.getJSONPath(region.sheetName))
)
).then(values => {
let data = {};
values.forEach(region => {
const regionData = JSON.parse(region);
const regionName = regionData.regionName;
console.log(regionData.regions.length);
console.log(regionData.regionName);
data[regionName] = regionData;
data[regionName].recoveryRate =
Math.ceil((parseInt(
data[regionName].regionTotal.recovered.replace(",", "")
) /
parseInt(
data[regionName].regionTotal.cases.replace(",", "")
)) *
100);
});
return {
...data,
allRegions: Object.keys(data)
};
});
};