forked from covid19india/api
-
Notifications
You must be signed in to change notification settings - Fork 1
/
raw_data-to-state_district_wise_data.js
67 lines (59 loc) · 2.01 KB
/
raw_data-to-state_district_wise_data.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
const fs = require('fs');
const moment = require("moment");
const rawData = require('./raw_data');
console.log('Starting district wise data processing');
try {
const StateDistrictWiseData = rawData.raw_data.reduce((acc, row) => {
const isToday = moment().utcOffset(330).isSame(moment(row.dateannounced, "DD-MM-YYYY"), "day");
let stateName = row.detectedstate;
if(!stateName) {
stateName = 'Unknown';
}
if(!acc[stateName]) {
acc[stateName] = {districtData: {}};
}
let districtName = row.detecteddistrict;
if(!districtName) {
districtName = 'Unknown';
}
if(!acc[stateName].districtData[districtName]) {
acc[stateName].districtData[districtName] = {
// active: 0,
confirmed: 0,
// deaths: 0,
lastupdatedtime: "",
// recovered: 0,
delta: {
confirmed: 0
}
};
}
const currentDistrict = acc[stateName].districtData[districtName];
currentDistrict.confirmed++;
if (isToday) {
currentDistrict.delta.confirmed++;
}
// if(row.currentstatus === 'Hospitalized') {
// currentDistrict.active++;
// } else if(row.currentstatus === 'Deceased') {
// currentDistrict.deaths++;
// } else if(row.currentstatus === 'Recovered') {
// currentDistrict.recovered++;
// }
return acc;
}, {});
let stateDistrictWiseDataV2 = Object.keys(StateDistrictWiseData).map(state => {
let districtData = StateDistrictWiseData[state].districtData;
return {
state,
districtData: Object.keys(districtData).map(district => {
return { district, ...districtData[district] };
})
}
});
fs.writeFileSync('state_district_wise.json', JSON.stringify(StateDistrictWiseData, null, 2));
fs.writeFileSync('./v2/state_district_wise.json', JSON.stringify(stateDistrictWiseDataV2, null, 2));
console.log('Starting district wise data processing ...done');
} catch(err) {
console.log('Error processing district wise data', err);
}