-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit.js
82 lines (71 loc) · 2.36 KB
/
init.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import db from './lib/database'
import * as rki from './lib/utils/rki'
import { CountyCase, CountyGeometry, StateCase, StateGeometry } from './lib/models'
import { updateNormalizedValues, convertGermanDate } from './lib/scheduler'
db.drop()
.then(() => {
db.sync()
.then(async () => {
await initStateGeometries()
await initCountyGeometries()
await initStateCases()
await initCountyCases()
process.exit(0)
})
})
async function initStateGeometries () {
const data = await rki.fetchStateGeometries()
for (const element of data.features) {
element.geometry.crs = data.crs
await StateGeometry.create({
id: element.properties.OBJECTID,
stateId: element.properties.OBJECTID_1,
geometry: element.geometry
})
}
}
async function initCountyGeometries () {
const data = await rki.fetchCountyGeometries()
for (const element of data.features) {
element.geometry.crs = data.crs
await CountyGeometry.create({
id: element.properties.OBJECTID,
stateId: element.properties.BL_ID,
geometry: element.geometry
})
}
}
async function initStateCases () {
const data = await rki.fetchStateCases()
for (const element of data.features) {
await StateCase.create({
id: element.attributes.OBJECTID,
deathRate: (element.attributes.Death / element.attributes.Fallzahl) * 100,
cases: element.attributes.Fallzahl,
deaths: element.attributes.Death,
casesPer100k: element.attributes.faelle_100000_EW,
state: element.attributes.LAN_ew_GEN,
stateId: element.attributes.OBJECTID_1,
lastUpdate: element.attributes.Aktualisierung
})
}
await updateNormalizedValues(StateCase)
}
async function initCountyCases () {
const data = await rki.fetchCountyCases()
for (const element of data.features) {
await CountyCase.create({
id: element.attributes.OBJECTID,
deathRate: element.attributes.death_rate,
cases: element.attributes.cases,
deaths: element.attributes.deaths,
casesPer100k: element.attributes.cases_per_100k,
state: element.attributes.BL,
stateId: element.attributes.BL_ID,
county: element.attributes.county,
lastUpdate: convertGermanDate(element.attributes.last_update),
cases7Per100k: element.attributes.cases7_per_100k
})
}
await updateNormalizedValues(CountyCase)
}