This repository has been archived by the owner on Dec 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 33
/
index.js
227 lines (211 loc) · 6.38 KB
/
index.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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
const parse = require('../../_lib/parse.js')
const transform = require('../../_lib/transform.js')
const maintainers = require('../../_lib/maintainers.js')
const geography = require('../../_lib/geography/index.js')
module.exports = {
state: 'UT',
country: 'iso1:US',
aggregate: 'county',
maintainers: [ maintainers.lazd ],
scrapers: [
{
startDate: '2020-01-01',
crawl: [
{
type: 'page',
data: 'table',
url: 'https://coronavirus.utah.gov/latest/'
}
],
scrape ($) {
let counties = []
const $table = $('th:contains("District")').closest('table')
const $trs = $table.find('tbody > tr')
$trs.each((index, tr) => {
const $tr = $(tr)
const county = parse.string($tr.find('td:first-child').text())
const cases = parse.number($tr.find('td:last-child').text())
if (index > 0 && !county.includes('Non-Utah')) {
_ut.maybeAggregateCounties(counties, county, cases)
}
})
// Backfill any named counties without data
counties = geography.addEmptyRegions(counties, _ut.counties, 'county')
counties.push(transform.sumData(counties))
return counties
}
},
{
startDate: '2020-03-19',
crawl: [
{
type: 'page',
data: 'table',
url: 'https://coronavirus-dashboard.utah.gov/'
}
],
scrape ($) {
let counties = []
const script = $('script[type="application/json"]').html()
const { data } = JSON.parse(script).x
for (const [ index, county ] of Object.entries(data[0])) {
_ut.maybeAggregateCounties(counties, county, parse.number(data[1][index]) + parse.number(data[2][index]))
}
// Totals come from here
counties.push({
tested: parse.number($('#reported-people-tested .value-output').text()),
cases: parse.number($('#covid-19-cases .value-output').text()),
deaths: parse.number($('#covid-19-deaths .value-output').text()),
hospitalized: parse.number($('#ccovid-19-hospitalizations .value-output').text())
})
// Backfill any named counties without data
counties = geography.addEmptyRegions(counties, _ut.counties, 'county')
// We don't sum data because we already have totals from above
return counties
}
},
{
startDate: '2020-04-08',
friendly: {
url: 'https://health.utah.gov/',
name: 'Utah Department of Health'
},
crawl: [
{
type: 'page',
data: 'table',
url: 'https://coronavirus-dashboard.utah.gov/'
}
],
scrape ($) {
let counties = []
const script = $('script[type="application/json"]').html()
const { data } = JSON.parse(script).x
for (const [ index, county ] of Object.entries(data[0])) {
_ut.maybeAggregateCounties(counties, county, parse.number(data[1][index]) + parse.number(data[2][index]))
}
// Totals come from here
counties.push({
tested: parse.number($('#total-reported-people-tested .value-output').text()),
cases: parse.number($('#total-covid-19-cases .value-output').text()),
deaths: parse.number($('#total-covid-19-deaths .value-output').text()),
hospitalized: parse.number($('#total-covid-19-hospitalizations .value-output').text())
})
// Backfill any named counties without data
counties = geography.addEmptyRegions(counties, _ut.counties, 'county')
// We don't sum data because we already have totals from above
return counties
}
}
]
}
const _ut = {
counties: [
// 'Beaver County',
// 'Box Elder County',
// 'Cache County',
// 'Carbon County',
// 'Daggett County',
'Davis County',
// 'Duchesne County',
// 'Emery County',
// 'Garfield County',
// 'Grand County',
// 'Iron County',
// 'Juab County',
// 'Kane County',
// 'Millard County',
// 'Morgan County',
// 'Piute County',
// 'Rich County',
'Salt Lake County',
'San Juan County',
// 'Sanpete County',
// 'Sevier County',
'Summit County',
'Tooele County',
// 'Uintah County',
'Utah County',
'Wasatch County'
// 'Washington County',
// 'Wayne County'
// 'Weber County'
],
maybeAggregateCounties (counties, county, cases) {
if (county === 'State Total') {
return
}
if (county === 'TriCounty' || county === 'Tri County') {
const aggCounties = [ 'Uintah County', 'Duchesne County', 'Daggett County' ]
aggCounties.forEach(county => {
counties.push({
county,
aggregatedIn: 'TriCounty Utah',
cases
})
})
return
}
if (county === 'Weber-Morgan') {
const aggCounties = [ 'Weber County', 'Morgan County' ]
aggCounties.forEach(county => {
counties.push({
county,
aggregatedIn: 'Weber-Morgan Utah',
cases
})
})
return
}
if (county === 'Southeast Utah') {
const aggCounties = [ 'Carbon County', 'Emery County', 'Grand County' ]
aggCounties.forEach(county => {
counties.push({
county,
aggregatedIn: 'Southeast Utah',
cases
})
})
return
}
if (county === 'Southwest Utah') {
const aggCounties = [ 'Beaver County', 'Garfield County', 'Iron County', 'Kane County', 'Washington County' ]
aggCounties.forEach(county => {
counties.push({
county,
aggregatedIn: 'Southwest Utah',
cases
})
})
return
}
if (county === 'Central Utah') {
const aggCounties = [
'Juab County', 'Millard County', 'Piute County', 'Sanpete County', 'Sevier County', 'Wayne County'
]
aggCounties.forEach(county => {
counties.push({
county,
aggregatedIn: 'Central Utah',
cases
})
})
return
}
if (county === 'Bear River') {
const aggCounties = [ 'Box Elder County', 'Cache County', 'Rich County' ]
aggCounties.forEach(county => {
counties.push({
county,
aggregatedIn: 'Bear River',
cases
})
})
return
}
counties.push({
county: geography.addCounty(county),
cases
})
}
}