forked from paroj/arewedeadyet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
571 lines (485 loc) · 22.8 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
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
<!doctype html>
<html lang="en">
<head>
<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" href="/arewedeadyet/icons/favicon.ico" type="image/x-icon" />
<link rel="apple-touch-icon" sizes="57x57" href="/arewedeadyet/icons/apple-touch-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/arewedeadyet/icons/apple-touch-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/arewedeadyet/icons/apple-touch-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/arewedeadyet/icons/apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/arewedeadyet/icons/apple-touch-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/arewedeadyet/icons/apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/arewedeadyet/icons/apple-touch-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/arewedeadyet/icons/apple-touch-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/arewedeadyet/icons/apple-touch-icon-180x180.png">
<link rel="icon" type="image/png" href="/arewedeadyet/icons/favicon-16x16.png" sizes="16x16">
<link rel="icon" type="image/png" href="/arewedeadyet/icons/favicon-32x32.png" sizes="32x32">
<link rel="icon" type="image/png" href="/arewedeadyet/icons/favicon-96x96.png" sizes="96x96">
<link rel="icon" type="image/png" href="/arewedeadyet/icons/android-chrome-192x192.png" sizes="192x192">
<title>Are we dead yet?</title>
<style>
canvas {
height: 30em;
max-height: 30em;
}
</style>
</head>
<body class="container">
<br>
<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=Korea, South; China; Italy; US; Spain">
Korea, South; China; Italy; US; Spain
</a>
<a class="list-group-item list-group-item-action" href="?countries=Korea, South; China; Italy; US; Spain; Germany; France; Australia; Iran; Switzerland; United Kingdom; Canada">
Korea, South; China; Italy; US; Spain; Germany; France; Australia; Iran; Switzerland; United Kingdom; Canada
</a>
<a class="list-group-item list-group-item-action" href="?countries=Spain; China; Italy; US">
Spain; China; Italy; US
</a>
<a class="list-group-item list-group-item-action" href="?countries=India; Russia; Japan; Mexico">
India; Russia; Japan; Mexico
</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="Korea, South; China; Italy; US; 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-header">
Table of Contents
</div>
<ul class="list-group list-group-flush">
<a class="list-group-item list-group-item-action" href="#confirmed">Confirmed Infections</a>
<a class="list-group-item list-group-item-action" href="#rate">Infection Rate</a>
<a class="list-group-item list-group-item-action" href="#fatality">Fatality Rate</a>
<a class="list-group-item list-group-item-action" href="#fatality-count">Fatality Count</a>
<a class="list-group-item list-group-item-action" href="#dead-per-million">Mortality Rate</a>
<a class="list-group-item list-group-item-action" href="#infection-rate">Infection Rate</a>
<a class="list-group-item list-group-item-action" href="#recovery-count">Recovery Count</a>
<a class="list-group-item list-group-item-action" href="#resolution">Resolution</a>
</ul>
</div>
<div class="card mt-3">
<div class="card-body">
<canvas id="confirmed"></canvas>
<hr>
<canvas id="confirmed-logarithmic"></canvas>
This is still pretty useless as the countries differ in total population and population density, lets
turn to
something
actually comparable.
</div>
</div>
<div class="card mt-3">
<div class="card-body">
<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>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
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>
<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">
<canvas id="fatality-count"></canvas>
<p>
</p>
<div class="alert alert-primary" role="alert">
Raw fatality count over time.
</div>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
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>
<hr>
<canvas id="dead-per-million-logarithmic"></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">
<canvas id="infection-rate"></canvas>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
<canvas id="recovery-count"></canvas>
<p>
</p>
<div class="alert alert-primary" role="alert">
Raw recovery count over time.
</div>
</div>
</div>
<div class="card mt-3">
<div class="card-body">
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="resolution"></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>
<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/davidsiu/covid-19-realtime-data">https://github.com/davidsiu/covid-19-realtime-data</a>, which in turn sources <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>
<hr>
Source-code: <a href="https://github.com/davidsiu/arewedeadyet">https://github.com/davidsiu/arewedeadyet</a><br>
<hr>
<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>.
<br>
<br>
<script src="./population_from_wikipedia.js"></script>
<script>
"use strict"
var labels = []
var days = {}
Chart.defaults.global.defaultFontColor = 'white';
Chart.defaults.scale.gridLines.color = "rgba(255,255,255, 0.2)"
const DAY_ZERO_THRESHOLD = 25
function beforeDayZero(day) {
return day["confirmed"] < DAY_ZERO_THRESHOLD
}
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 = []
for (var day of data[country]) {
if (beforeDayZero(day)
|| !Number.isInteger(day["deaths"])
|| !Number.isInteger(day["recovered"])) continue
infected.push(day["confirmed"] - day["deaths"] - day["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).toFixed(2))
}
return fatality
}
function getFalities(data, country) {
var dead = []
for (var day of data[country]) {
if (beforeDayZero(day)) continue
dead.push((day["deaths"]).toFixed(2))
}
return dead
}
function getDeadPerMillion(data, country) {
var dead = []
for (var day of data[country]) {
if (beforeDayZero(day)) continue
dead.push((day["deaths"] / (population[country] / 1e6)).toFixed(2))
}
return dead
}
function getInfectionRate(data, country) {
var infection = []
for (var day of data[country]) {
if (beforeDayZero(day)) continue
infection.push((day["confirmed"] / population[country] * 100).toFixed(4))
}
return infection;
}
function getRecoveries(data, country) {
var dead = []
for (var day of data[country]) {
if (beforeDayZero(day)) continue
dead.push((day["recovered"]).toFixed(2))
}
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).toFixed(2))
}
return avgd
}
function getRandomColor() {
var letters = '0123456789ABCDEF'.split('');
var color = '#';
for (var i = 0; i < 6; i++ ) {
color += letters[Math.floor(Math.random() * 16)];
}
return color;
}
const countryColor = {};
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++) {
colors[i] = colors[i] || countryColor[i] || (countryColor[i] = getRandomColor());
datasets.push(
{
label: countries[i],
fill: fill,
backgroundColor: colors[i],
borderColor: colors[i],
data: fn(data, countries[i])
}
)
}
return datasets
}
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 ${DAY_ZERO_THRESHOLD} 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 logTickCallback(value, index, values) {
if (value === 1000000) return "1M";
if (value === 100000) return "100K";
if (value === 10000) return "10K";
if (value === 1000) return "1K";
if (value === 100) return "100";
if (value === 10) return "10";
if (value === 0) return "0";
return null;
}
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://davidsiu.github.io/covid-19-realtime-data/data/realtime_timeseries_by_country.json", {
cache: 'no-cache'
})
var data = await response.json()
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))
}
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 Confirmed Comparison (Logarithmic)'
cconfig.options.scales.yAxes[0].scaleLabel.labelString = "confirmed"
// Extremely sad. We need to go to a log scale because the US numbers
// are increasing exponentially
cconfig.options.scales.yAxes[0].type = 'logarithmic'
cconfig.options.scales.yAxes[0].ticks = {
min: 0,
max: 1000000,
callback: logTickCallback
}
cconfig.data.datasets = getDatasets(data, getDays, countries, false)
cconfig.data.labels = labels
makeChart("confirmed-logarithmic", 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 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 = 'Fatality count comparison'
cconfig.options.scales.yAxes[0].scaleLabel.labelString = "deaths"
cconfig.data.datasets = getDatasets(data, getFalities, countries, false)
cconfig.data.labels = labels
makeChart("fatality-count", 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 = 'Mortality rate comparison (Logarithmic)'
cconfig.options.scales.yAxes[0].scaleLabel.labelString = "deaths per million"
// Extremely sad. We need to go to a log scale because Italy and Spain's Mortality
// rate is considerably higher than other countries.
cconfig.options.scales.yAxes[0].type = 'logarithmic'
cconfig.options.scales.yAxes[0].ticks = {
min: 0,
max: 1000,
callback: logTickCallback
}
cconfig.data.datasets = getDatasets(data, getDeadPerMillion, countries, false)
cconfig.data.labels = labels
makeChart("dead-per-million-logarithmic", cconfig)
cconfig = JSON.parse(JSON.stringify(config))
cconfig.options.title.text = 'Infection rate'
cconfig.options.scales.yAxes[0].scaleLabel.labelString = "% of population infected"
cconfig.data.datasets = getDatasets(data, getInfectionRate, countries, false)
cconfig.data.labels = labels
makeChart("infection-rate", cconfig)
cconfig = JSON.parse(JSON.stringify(config))
cconfig.options.title.text = 'Recovery count comparison'
cconfig.options.scales.yAxes[0].scaleLabel.labelString = "recovered"
cconfig.data.datasets = getDatasets(data, getRecoveries, countries, false)
cconfig.data.labels = labels
makeChart("recovery-count", 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("resolution", cconfig)
}
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.get('countries')) {
document.getElementById('countries').value = urlParams.get('countries')
charts["_dummy"] = 1 // force non-filled style
}
refresh()
setInterval(async function() {
console.log("Refeshing with latest data...", new Date());
Chart.defaults.global.animation.duration = 0;
await refresh();
}, 60000*15);
</script>
</body>
</html>