-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.js
56 lines (51 loc) · 1.93 KB
/
loader.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
const fs = require('fs');
const propMapping = {
totale_casi: "http://covid19#TotalCases",
ricoverati_con_sintomi: "http://covid19#HospitalisedWithSymptoms",
terapia_intensiva: "http://covid19#IntensiveCare",
totale_ospedalizzati: "http://covid19#TotalHospitalised",
isolamento_domiciliare: "http://covid19#HomeConfinement",
totale_attualmente_positivi: "http://covid19#TotalPositiveCases",
nuovi_attualmente_positivi: "http://covid19#DailyPositiveCases",
dimessi_guariti: "http://covid19#Recovered",
deceduti: "http://covid19#Death",
tamponi: "http://covid19#TestPerformed"
}
const baseURIPlace = "http://covid19/Italy/Province/"
const baseURIPlaceRegion = "http://covid19/Italy/Region/"
module.exports = {
loadFromRegions(file){
var obj = JSON.parse(fs.readFileSync(file, 'utf8'));
let obs = []
obj.forEach(pRecord => {
pRecord.data = pRecord.data.replace(" ", "T") + "Z"
Object.keys(propMapping).forEach( property =>{
if(!propMapping.hasOwnProperty(property))return;
obs.push({
place: baseURIPlaceRegion + fillBlanks(pRecord.denominazione_regione),
value: pRecord[property],
timestamp: pRecord.data,
property: propMapping[property]
})
})
});
return obs
},
loadFromProvince(file){
var obj = JSON.parse(fs.readFileSync(file, 'utf8'));
let obs = []
obj.forEach(pRecord => {
pRecord.data = pRecord.data.replace(" ","T") + "Z"
obs.push({
place: baseURIPlace + fillBlanks(pRecord.denominazione_provincia),
value: pRecord.totale_casi,
timestamp: pRecord.data,
property: propMapping.totale_casi
})
});
return obs
}
}
function fillBlanks(name) {
return name.replace(/\ /g,"_")
}