forked from paroj/arewedeadyet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
485 lines (427 loc) · 20.3 KB
/
index.html
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
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
<!doctype html>
<html lang="en">
<head>
<!--<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css"
integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">-->
<link rel="stylesheet" href="https://bootswatch.com/4/cyborg/bootstrap.min.css" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="shortcut icon" type="image/x-icon" href="/arewedeadyet/favicon.ico">
<title>Are we dead yet?</title>
<style>
canvas {
height: 30em;
max-height: 30em;
}
</style>
</head>
<body class="container">
<div class="jumbotron">
<p class="lead">
I am quite frustrated with corona graphs in the news, since most reporters seem to have skipped math classes
back
then.
For instance, just plotting the number of confirmed infections at the respective dates does not tell you
anything
due to the different time point of outbreak. So lets fix that first.
</p>
<hr>
<p>The following charts are based on live data from <a
href="https://github.com/pomber/covid19">https://github.com/pomber/covid19</a>, which in turn sources <a
href="https://coronavirus.jhu.edu/map.html">jhu.edu</a>.</p>
<p>
</div>
<div class="card">
<div class="card-header">
Countries to compare
</div>
<ul class="list-group list-group-flush">
<a class="list-group-item list-group-item-action" href="?countries=Italy; Germany; France; Spain">
Italy; Germany; France; Spain
</a>
<a class="list-group-item list-group-item-action" href="?countries=Korea, South; Israel; Austria; Sweden">
Korea, South; Israel; Austria; Sweden
</a>
<a class="list-group-item list-group-item-action" href="?countries=India; EU; US; Brazil">
India; EU; US; Brazil
</a>
</ul>
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Custom</span>
</div>
<input type="text" id="countries" value="Italy; Germany; France; Spain" class="form-control">
<div class="input-group-append">
<input type="button" value="Apply" onclick="refresh()" class="btn btn-primary">
</div>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
<a href="#confirmed">#</a>
<canvas id="confirmed"></canvas>
<p class="card-text">
This is still pretty useless as the countries differ in total population and population density, lets
turn to
something
actually comparable.</p>
<div class="alert alert-primary" role="alert">Here, confirmed refers to a case being <b>reported</b> in contrast
to a
case
being <b>infected</b>.
Therefore, fluctuations are introduced by working days (e.g. less tests performed on weekends &
holidays).
</div>
</div>
</div>
<div class="card mt-3">
<div class="card-header">
Spreading rate measures
</div>
<div class="card-body">
<a href="#rate">#</a>
<canvas id="rate"></canvas>
<p class="card-text">
The values are smoothed using a moving
average
over
four days.
This numbers actually allow comparing how well the different countries are doing in their corona
countermeasurements, regardless of the population size.</p>
<div class="alert alert-primary" role="alert">An infection rate of 1.0 means no new infections.
</div>
However, after the initial outbreak a significant part of populatian has been infected and any new outbreaks are dimished in this metric.
<hr>
<a href="#
bling">#</a> The same data can be visualized more intuitively as the <em>doubling time</em>,
i.e. the time it takes for the confirmed count to double. It is given below for reference.
<canvas id="tdoubling"></canvas>
<p class="card-text">
However, this representation is less numerically stable as it diverges to infinity as the infection rate
approaches to 1.0.
</p>
<hr>
<a href="#r0">#</a> Yet another way to represent the same data is the <a
href="https://en.wikipedia.org/wiki/Basic_reproduction_number#Notes">effective reproduction number R</a>.
<canvas id="r0"></canvas>
<p class="card-text">
Actually, it is very similar what we defined as the infection rate above. However, instead of comparing the
the absolute number of <em>confirmed</em> from day to day, the change in <em>confirmed</em> over a period of time is
used.
Therefore, R becomes 0.0 if there are no new infections.
</p>
<div class="alert alert-primary" role="alert">
<a href="https://en.wikipedia.org/wiki/Compartmental_models_in_epidemiology">There is a variety of models to
estimate R.</a>
I went with a rather naive approach (see code), so the actual numbers may vary from official reports.
</div>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
<a href="#fatality">#</a>
However, <em>confirmed</em> does not mean the same between different countries and even in the same country
at
different time points of the epidemic. This is due to the sampling bias induced by the limited amount of
corona test kits.
In the early days of the epidemic there are enough kits to test everyone, so many cases that do not yet show
symptoms are tested.
With ongoing spread, we hit limits on test-kit and health-system capacities and the focus shifts to testing
severe cases only. This in turn pushes the fatality rate.
<canvas id="fatality"></canvas>
<p class="card-text">A significant increase of the fatality rate indicates that</p>
<ol>
<li>the confirmed count is being under-estimated.</li>
<li>the health-system capacites being exhausted.</li>
</ol>
<p>Conversely, a decrase of the fatality rate indicates that</p>
<ol>
<li>the confirmed count was previously under-estimated. (e.g. by the exhaustion of the health system and focusing on severe cases)</li>
</ol>
<div class="alert alert-primary" role="alert">
We are only talking about an <em>estimate</em> of fatality rate here, as we cannot measure the true
fatality
rate while the epidemic is ongoing. For us the relative rate between countries is sufficient. Therefore
we simpliy chose the optimisitic deaths by confirmed ratio here.
</div>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
<a href="#dead-per-million">#</a>
In contrast to the fatality rate, the mortality rate below is shown in dead per million inhabitants.
This makes it independant of whether the confirmed count is estimated correctly. In most cases both will be
correlated.
<canvas id="dead-per-million"></canvas>
<p>
However, the mortality rate
is a better indicator of the influence of the pandepic on a countries society and economy - especially
when the health-system is exhausted.
</p>
<div class="alert alert-primary" role="alert">
The population count to compute the mortality is based on <a
href="https://github.com/paroj/arewedeadyet/blob/master/population_from_wikipedia.js">data from
wikipedia</a>
</div>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
<a href="#recovery">#</a>
To close with something positive, lets look at the absolute number of infections. That is, cases which are
neither
recovered nor died yet and are potentially infectious.
If there are no such cases left, we can assume the epidemic to be stopped.
<canvas id="recovery"></canvas>
Notably, when this graph reaches zero you
<strong>can
not</strong> assume that the epidemic is stopped due to the stochastic nature of the data.
However, a rise of the graph after a decline can indicate that a second wave is coming.
</div>
</div>
<hr>
Source-code: <a href="https://github.com/paroj/arewedeadyet">https://github.com/paroj/arewedeadyet</a><br>
<a rel="license" href="https://creativecommons.org/licenses/by-nc-sa/4.0/"><img alt="Creative Commons License"
style="border-width:0" src="https://i.creativecommons.org/l/by-nc-sa/4.0/88x31.png" /></a><br />This work is
licensed under a <a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/4.0/">Creative Commons
Attribution-NonCommercial-ShareAlike 4.0 International License</a>.
<script src="./population_from_wikipedia.js"></script>
<script>
"use strict"
var labels = null
var days = {}
function beforeDayZero(day) {
return day["confirmed"] < 500
}
function getDays(data, country) {
var confirmed = []
for (var day of data[country]) {
if (beforeDayZero(day)) continue
confirmed.push(day["confirmed"])
if (confirmed.length > labels.length) labels.push(labels.length)
}
days[country] = confirmed
return confirmed
}
function getInfected(data, country) {
var infected = []
var last_valid_recovered = null // workaround data issue at JHU
for (var day of data[country]) {
if (beforeDayZero(day)) continue
if (day["recovered"])
last_valid_recovered = day["recovered"]
infected.push(day["confirmed"] - day["deaths"] - last_valid_recovered)
}
return infected
}
function getFatalityRate(data, country) {
var fatality = []
for (var day of data[country]) {
if (beforeDayZero(day)) continue
fatality.push(day["deaths"] / day["confirmed"] * 100)
}
return fatality
}
function getDeadPerMillion(data, country) {
var dead = []
for (var day of data[country]) {
if (beforeDayZero(day)) continue
dead.push(day["deaths"] / (population[country] / 1e6))
}
return dead
}
function getRate(data, country) {
var confirmed = days[country]
var rate = [0]
for (var i = 1; i < confirmed.length; i++) {
rate.push((confirmed[i] / confirmed[i - 1]))
}
var avgd = [0, 0, 0, 0, 0]
for (var i = 4; i < rate.length; i++) {
avgd.push((rate[i] + rate[i - 1] + rate[i - 2] + rate[i - 3]) / 4)
}
return avgd
}
function getRe(data, country) {
var delta = 7 // days
var confirmed = days[country]
var rate = new Array(2*delta).fill(-1)
for (var i = delta; i < confirmed.length; i++) {
rate.push((confirmed[i] - confirmed[i - delta]) / (confirmed[i - delta] - confirmed[i - 2*delta]))
}
return rate
}
function getDoublingTime(data, country) {
return getRate(data, country).map(rate => Math.log(2) / Math.log(rate))
}
function getDatasets(data, fn, countries, fill) {
var colors = ['rgb(255, 132, 255)', 'rgb(255, 99, 132)', 'rgb(99, 255, 132)', 'rgb(99, 132, 255)', 'rgb(132, 255, 255)', 'rgb(255, 255, 132)']
var datasets = []
for (var i = 0; i < countries.length; i++) {
datasets.push(
{
label: countries[i],
fill: fill,
backgroundColor: colors[i],
borderColor: colors[i],
data: fn(data, countries[i]).map(x => x.toFixed(2))
}
)
}
return datasets
}
Chart.defaults.global.defaultFontColor = 'white'
Chart.defaults.scale.gridLines.color = "rgba(255,255,255, 0.2)"
var config = {
// The type of chart we want to create
type: 'line',
// The data for our dataset
data: {
datasets: null,
labels: null
},
// Configuration options go here
options: {
responsive: true,
maintainAspectRatio: false,
title: {
display: true,
text: 'Corona Confirmed Comparison'
},
tooltips: {
mode: 'index',
intersect: false,
},
scales: {
xAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'Days since 500 confirmed'
}
}],
yAxes: [{
display: true,
scaleLabel: {
display: true,
labelString: 'confirmed'
},
ticks: {}
}]
}
}
}
var charts = {}
function makeChart(name, config) {
var canvas = document.getElementById(name).getContext('2d')
if (name in charts) charts[name].destroy()
charts[name] = new Chart(canvas, config)
}
function mergeDays(from, to) {
// not smart: quadratic complexity, but whatever
outer:
for (var d2 of from) {
for (var i = 0; i < to.length; i++) {
var d1 = to[i]
if (d1.date == d2.date) {
d1.confirmed += d2.confirmed
d1.deaths += d2.deaths
d1.recovered += d2.recovered
continue outer
}
}
to.splice(i, 0, Object.assign({}, d2))
}
}
function aggregateEU(data, population) {
var countries = ["Austria", "Belgium", "Bulgaria", "Croatia", "Cyprus", "Czechia", "Denmark", "Estonia", "Finland", "France", "Germany", "Greece", "Hungary", "Ireland", "Italy", "Latvia", "Lithuania", "Luxembourg", "Malta", "Netherlands", "Poland", "Portugal", "Romania", "Slovakia", "Slovenia", "Spain", "Sweden"]
console.assert(countries.length == 27, "https://en.wikipedia.org/wiki/Member_state_of_the_European_Union")
data["EU"] = []
population["EU"] = 0
for (var c of countries) {
mergeDays(data[c], data["EU"])
population["EU"] += population[c]
}
}
async function refresh() {
var countries_str = document.getElementById('countries').value
var countries = countries_str.split(";").map(e => e.trim())
var err = ""
var response = await fetch("https://pomber.github.io/covid19/timeseries.json")
var data = await response.json()
aggregateEU(data, population)
var initial = !Object.keys(charts).length
for (var c of countries) {
if (!(c in data))
err += c + " is not a know country name "
if (!(c in population))
err += " population of " + c + " not known"
}
if (err) {
alert(err)
return
}
if (!initial) {
history.pushState(null, "title", "?countries=" + encodeURI(countries_str))
}
labels = [] // force recompute labels length
var cconfig = JSON.parse(JSON.stringify(config))
cconfig.data.datasets = getDatasets(data, getDays, countries, false)
cconfig.data.labels = labels
makeChart("confirmed", cconfig)
cconfig = JSON.parse(JSON.stringify(config))
cconfig.options.title.text = 'Corona infection rate comparison'
cconfig.options.scales.yAxes[0].scaleLabel.labelString = "confirmed today/yesterday"
cconfig.options.scales.yAxes[0].ticks.min = 0.9
cconfig.data.datasets = getDatasets(data, getRate, countries, false)
cconfig.data.labels = labels
makeChart("rate", cconfig)
cconfig = JSON.parse(JSON.stringify(config))
cconfig.options.title.text = 'Corona infection doubling time comparison'
cconfig.options.scales.yAxes[0].scaleLabel.labelString = "days"
cconfig.options.scales.yAxes[0].ticks.min = 0.5
cconfig.options.scales.yAxes[0].ticks.max = 75
cconfig.options.tooltips.position = "nearest"
cconfig.data.datasets = getDatasets(data, getDoublingTime, countries, false)
cconfig.data.labels = labels
makeChart("tdoubling", cconfig)
cconfig = JSON.parse(JSON.stringify(config))
cconfig.options.title.text = 'Corona effective reproduction number'
cconfig.options.scales.yAxes[0].scaleLabel.labelString = "see getRe in code"
cconfig.options.scales.yAxes[0].ticks.min = 0.0
cconfig.options.scales.yAxes[0].ticks.max = 3
cconfig.data.datasets = getDatasets(data, getRe, countries, false)
cconfig.data.labels = labels
makeChart("r0", cconfig)
cconfig = JSON.parse(JSON.stringify(config))
cconfig.options.title.text = 'Corona fatality rate comparison'
cconfig.options.scales.yAxes[0].scaleLabel.labelString = "deaths/confirmed [%]"
cconfig.data.datasets = getDatasets(data, getFatalityRate, countries, false)
cconfig.data.labels = labels
makeChart("fatality", cconfig)
cconfig = JSON.parse(JSON.stringify(config))
cconfig.options.title.text = 'Mortality rate comparison'
cconfig.options.scales.yAxes[0].scaleLabel.labelString = "deaths per million"
cconfig.data.datasets = getDatasets(data, getDeadPerMillion, countries, false)
cconfig.data.labels = labels
makeChart("dead-per-million", cconfig)
cconfig = JSON.parse(JSON.stringify(config))
cconfig.options.title.text = 'Corona infected comparison'
cconfig.options.scales.yAxes[0].scaleLabel.labelString = "confirmed - recovered - dead"
cconfig.data.datasets = getDatasets(data, getInfected, countries, false)
cconfig.data.labels = labels
makeChart("recovery", cconfig)
}
var urlParams = new URLSearchParams(window.location.search)
var countries_str = urlParams.get('countries')
// fallback for old links
if (window.location.hash && !document.getElementById(window.location.hash.substring(1))) {
countries_str = decodeURI(window.location.hash.substring(1))
}
if (countries_str) {
document.getElementById('countries').value = countries_str
}
refresh()
</script>
</body>
</html>