-
Notifications
You must be signed in to change notification settings - Fork 5
/
france-departements-jobfile.js
163 lines (156 loc) · 4.8 KB
/
france-departements-jobfile.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
const path = require('path')
const _ = require('lodash')
const fs = require('fs-extra')
const moment = require('moment')
const program = require('commander')
const utils = require('./utils')
// By default try to grap latest data
program
.option('-d, --date [date]', 'Change the date of the data to be generated (defaults to yesterday)', moment().subtract(1, 'day').format('YYYY-MM-DD'))
.option('-g, --geometry [type]', 'Change the geometry type to be generated (defaults to point, ie centroids)', 'Point')
.parse(process.argv)
// Read departements DB
const departements = utils.processAdministrativeData('departements-france-outre-mer-500m', program.geometry,
'population-departements-france', 'lits-departements-france', 'dep_id')
const date = moment(program.date)
if (!date.isValid()) {
console.error('Invalid date, using yesterday as default')
date = moment().subtract(1, 'day')
}
// Read previous data if any to gill gaps
let yesterday = path.join(__dirname, 'departements-france',
(program.geometry === 'Point' ? 'departements-france-' : 'departements-france-polygons-') + `${date.clone().subtract(1, 'day').format('YYYY-MM-DD')}.json`)
if (fs.pathExistsSync(yesterday)) {
console.log('Reading data from previous day')
yesterday = fs.readJsonSync(yesterday)
}
const regionsData = require('./ARS')
let tasks = []
regionsData.forEach(region => {
tasks.push({
id: `${region}-${date.format('YYYY-MM-DD')}`,
region,
type: 'http',
options: {
url: 'https://raw.githubusercontent.com/opencovid19-fr/data/master/agences-regionales-sante/' +
`${region}/${date.format('YYYY-MM-DD')}.yaml`
}
})
})
// Add SPF sources
tasks.push({
id: `spf-donnees-hospitalieres/spf-donnees-hospitalieres-${date.format('MM-DD-YYYY')}.yaml`,
type: 'store',
options: {
store: 'fs'
}
})
tasks.push({
id: `spf-donnees-urgences-sos-medecins/spf-donnees-urgences-sos-medecins-${date.format('MM-DD-YYYY')}.yaml`,
type: 'store',
options: {
store: 'fs'
}
})
tasks.push({
id: `spf-donnees-laboratoires/spf-donnees-laboratoires-${date.format('MM-DD-YYYY')}.yaml`,
type: 'store',
options: {
store: 'fs'
}
})
tasks.push({
id: `spf-donnees-tests-pcr/spf-donnees-tests-pcr-${date.format('MM-DD-YYYY')}.yaml`,
type: 'store',
options: {
store: 'fs'
}
})
module.exports = {
id: (program.geometry === 'Point' ? 'departements-france-' : 'departements-france-polygons-') + `${date.format('YYYY-MM-DD')}`,
store: 'memory',
options: { faultTolerant: true },
tasks,
hooks: {
tasks: {
after: {
readYAML: {
objectPath: 'donneesDepartementales'
},
/* DEBUG
writeJsonFS: {
hook: 'writeJson',
store: 'fs'
}*/
}
},
jobs: {
before: {
createStores: [{
id: 'memory'
}, {
id: 'fs',
options: { path: __dirname }
},
{
id: 's3',
options: {
client: {
accessKeyId: process.env.S3_ACCESS_KEY,
secretAccessKey: process.env.S3_SECRET_ACCESS_KEY
},
bucket: process.env.S3_BUCKET
}
}]
},
after: {
mergeJson: {
},
processData: {
hook: 'apply',
dataPath: 'result.data',
function: (data) => {
utils.processData(data, departements.features, feature => element => element.code.replace('DEP-', '') === feature.properties.code)
}
},
convertToGeoJson: {
},
fillGaps: {
hook: 'apply',
dataPath: 'result.data',
function: (data) => {
// Try to fill gaps with previous data
if (yesterday.features) {
utils.processPreviousData(data.features, yesterday.features)
console.log(`Data processed for ${data.features.length} departements on ${departements.features.length} departements`)
_.forOwn(utils.properties, (value, key) => {
let n = _.get(utils.N, value)
console.log(`Found a total of ${n} ${value}`)
if (!utils.cumulativeProperties.includes(value)) {
value = utils.getAccumulatedValue(value)
n = _.get(utils.N, value)
console.log(`Found a total of ${n} ${value}`)
}
})
}
}
},
writeJsonFS: {
hook: 'writeJson',
store: 'fs',
key: `departements-france/<%= id %>.json`
},
writeJsonS3: {
hook: 'writeJson',
store: 's3',
key: `covid-19/departements-france/<%= id %>.json`,
storageOptions: {
ACL: 'public-read'
}
},
clearOutputs: {},
removeStores: ['memory', 'fs', 's3']
}
}
}
}