-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathtableview.html
447 lines (428 loc) · 14.2 KB
/
tableview.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
<!DOCTYPE html>
<html prefix="og: http://ogp.me/ns#" lang="ja">
<head>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-162141832-1"></script>
<script>
window.dataLayer = window.dataLayer || []
function gtag(){dataLayer.push(arguments)}
gtag('js', new Date())
gtag('config', 'UA-162141832-1')
</script>
<meta charset="utf-8"/>
<title>新型コロナウイルス感染症(国内事例)の状況 (厚生労働省フォーマット) #StopCOVID19JP</title>
<meta property="og:title" content="新型コロナウイルス感染症(国内事例)の状況 (厚生労働省フォーマット) #StopCOVID19JP"/>
<meta property="og:description" content="厚生労働省発表の新型コロナウイルス感染症(国内事例)の状況PDFをCSV化し、元の表示風に変換して表示するアプリ #StopCOVID19JP"/>
<meta name="theme-color" content="#AD232F"/>
<meta name="msapplication-TileColor" content="#AD232F"/>
<link rel="icon" type="image/png" href="covid19japan-icon.png"/>
<link rel="apple-touch-icon" href="covid19japan-leargeicon.png"/>
<meta name="msapplication-square310x310logo" content="covid19japan-leargeicon.png"/>
<meta name="twitter:card" content="summary_large_image"/>
<meta property="og:image" content="https://www.stopcovid19.jp/img/tableview_20200410.png"/>
<meta name="twitter:image" content="https://www.stopcovid19.jp/img/tableview_20200410.png"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<meta name="format-detection" content="telephone=no"/>
<link href="https://fonts.googleapis.com/css2?family=Overpass:wght@700&display=swap" rel="stylesheet">
<style>
body {
--main-color: #AD232F;
color: black;
font-family: sans-serif;
word-wrap: break-word;
margin: 0;
font-size: 10px;
x-font-size: 1vw;
text-align: center;
}
h1 {
font-size: 160%;
}
h1 a {
text-decoration: none;
color: black !important;
}
#table {
display: inline-block;
}
#table table {
display: inline-block;
border-collapse: collapse;
}
#table td, #table th {
text-align: center;
width: 8.2em;
border: 1px solid black;
}
#table td {
padding: 0;
line-height: 1.1;
}
#table td:first-child {
background-color: #FDF2D0;
}
#table th {
background-color: #DFEBF6;
}
#table tr:last-child td {
background-color: #E4EEDC;
}
#zero {
display: inline-block;
vertical-align: top;
}
#zero > div {
border: 1px solid black;
margin-left: 20px;
padding: .5em 0;
width: 6em;
text-align: center;
line-height: 1.8;
}
.dataset * {
display: inline-block;
margin-top: 1em;
margin-right: 1em;
}
a:link {
color: #000;
}
a:visited {
color: #666;
}
a:hover {
color: black;
}
a:active {
color: black;
}
/* credit */
.credit {
margin: 2em 0 1em 0;
text-align: center;
}
#link {
margin: 1em;
}
#link img {
width: 80vw;
max-width: 300px;
}
/* for print */
@media print {
h1 {
margin-top: 0;
}
body {
font-size: 8px;
}
#table td {
line-height: 1.12;
}
.dataset, .lang, #link {
display: none;
}
.credit {
margin: .5em;
font-size: 80%;
}
.credit div {
display: inline;
margin-left: 1em;
}
}
</style>
<script src="fukuno.js"></script>
<script src="translation.js"></script>
<script>"use strict"
const PREF = [ "北海道", "青森県", "岩手県", "宮城県", "秋田県", "山形県", "福島県", "茨城県", "栃木県", "群馬県", "埼玉県", "千葉県", "東京都", "神奈川県", "新潟県", "富山県", "石川県", "福井県", "山梨県", "長野県", "岐阜県", "静岡県", "愛知県", "三重県", "滋賀県", "京都府", "大阪府", "兵庫県", "奈良県", "和歌山県", "鳥取県", "島根県", "岡山県", "広島県", "山口県", "徳島県", "香川県", "愛媛県", "高知県", "福岡県", "佐賀県", "長崎県", "熊本県", "大分県", "宮崎県", "鹿児島県", "沖縄県" ]
const PREF_EN = [ "Hokkaido", "Aomori", "Iwate", "Miyagi", "Akita", "Yamagata", "Fukushima", "Ibaraki", "Tochigi", "Gunma", "Saitama", "Chiba", "Tokyo", "Kanagawa", "Niigata", "Toyama", "Ishikawa", "Fukui", "Yamanashi", "Nagano", "Gifu", "Shizuoka", "Aichi", "Mie", "Shiga", "Kyoto", "Osaka", "Hyogo", "Nara", "Wakayama", "Tottori", "Shimane", "Okayama", "Hiroshima", "Yamaguchi", "Tokushima", "Kagawa", "Ehime", "Kochi", "Fukuoka", "Saga", "Nagasaki", "Kumamoto", "Oita", "Miyazaki", "Kagoshima", "Okinawa" ]
const PREF_S = [ '北海道', '青森', '岩手', '宮城', '秋田', '山形', '福島', '茨城', '栃木', '群馬', '埼玉', '千葉', '東京', '神奈川', '新潟', '富山', '石川', '福井', '山梨', '長野', '岐阜', '静岡', '愛知', '三重', '滋賀', '京都', '大阪', '兵庫', '奈良', '和歌山', '鳥取', '島根', '岡山', '広島', '山口', '徳島', '香川', '愛媛', '高知', '福岡', '佐賀', '長崎', '熊本', '大分', '宮崎', '鹿児島', '沖縄' ]
const getLang = function() {
const hash = document.location.hash
if (hash.indexOf('en') >= 0) {
return "en"
}
if (hash.indexOf('ja') >= 0) {
return "ja"
}
const lang = (window.navigator.languages && window.navigator.languages[0]) || window.navigator.language || window.navigator.userLanguage || window.navigator.browserLanguage
return lang
}
const tx = function(s) {
if (typeof s != 'string')
return s
let lang = getLang()
if (lang.match('ja'))
return s
lang = 'en'
// return s
for (const ja in TX) {
for (;;) {
const n = s.indexOf(ja)
if (n < 0)
break
s = s.substring(0, n) + TX[ja][lang] + s.substring(n + ja.length)
}
}
const txarray = function(s, ar, aren) {
for (let i = 0; i < ar.length; i++) {
const s2 = ar[i]
for (;;) {
const n = s.indexOf(s2)
if (n < 0)
break
s = s.substring(0, n) + aren[i] + s.substring(n + s2.length)
}
}
return s
}
s = txarray(s, PREF, PREF_EN)
s = txarray(s, PREF_S, PREF_EN)
return s
}
const translate = function() {
document.title = tx(document.title)
//document.body.innerHTML = tx(document.body.innerHTML)
contents.innerHTML = tx(contents.innerHTML)
credit.innerHTML = tx(credit.innerHTML)
if (getLang() == 'en') {
document.getElementsByTagName('html')[0].setAttribute('lang', 'en')
/*
for (const css of document.styleSheets.cssRules) {
console.log(css)
}
*/
}
}
const fix0 = function(n, beam) {
const s = "000000000" + n
return s.substring(s.length - beam)
}
const formatYMD = function(t) {
return t.getFullYear() + "-" + fix0(t.getMonth() + 1, 2) + "-" + fix0(t.getDate(), 2)
}
const formatDay = function(t) {
if (getLang() == 'ja') {
return formatDayJP(t)
}
return formatYMD(t)
}
const formatDayJP = function(t) {
return (t.getMonth() + 1) + "月" + t.getDate() + "日(" + "日月火水木金土".charAt(t.getDay()) + ")"
}
const fetchCSV = async function(url) {
const csv = await (await fetch(url)).text()
const data = decodeCSV(csv)
return csv2json(data)
}
const cutQuery = function(url) {
const n = url.lastIndexOf('?')
if (n >= 0)
return url.substring(0, n)
return url
}
const calcRatio = function(cnt, base) {
if (base == 0 || isNaN(cnt) || isNaN(base))
return "-"
const n = cnt / base * 100
return fixfloat(n, n >= 100 ? 0 : 1) + "%"
}
const shortenPref = function(pref) {
if (pref == '東京都')
return '東京'
if (pref.endsWith("県") || pref.endsWith("府")) {
return pref.substring(0, pref.length - 1)
}
return pref
}
const getPrevTarget = function(list, target) {
const tyesterday = new Date(target.lastUpdate).getTime() - (1000 * 60 * 60 * 24)
const yesterday = formatYMD(new Date(tyesterday))
for (const d of list) {
if (d.lastUpdate == yesterday) {
return d
}
}
return null
}
const showTable = async function(target, data, prevdata, popudata) {
const tbl = create('table')
const head = [ '', formatDay(new Date(target.lastUpdate)), '対前日', '人口一万人当たり', '2_うち現在は入院等', '2_うち退院', '2_うち死亡' ]
let tr = create('tr')
for (const s of head) {
const th = create('th')
if (s.startsWith('2_')) {
th.textContent = tx(s.substring(2))
th.colSpan = 2
} else {
th.textContent = tx(s)
}
tr.appendChild(th)
}
tbl.appendChild(tr)
const calcRatio = function(n, m) {
if (m == 0) { return '0%' }
if (isNaN(n)) { return '-' }
const r = Math.floor(n / m * 100)
return r + "%"
}
const sorted = []
for (const d of data) {
sorted.push(d)
}
sorted.sort(function(a, b) {
return b.npatients - a.npatients
})
const popuname = 'population_jp'
const sumname = [ 'npatients', 'patientsdif', 'ncurrentpatients', 'nexits', 'ndeaths' ]
const total = {}
for (const n of sumname) {
total[n] = 0
}
const getData = function(list, pref) {
if (!list)
return null
for (const d of list) {
if (d.name_jp == pref)
return d
}
return null
}
for (let i = 0; i <= sorted.length; i++) {
const add = function(n) {
const td = create('td')
td.textContent = tx(n)
tr.appendChild(td)
}
if (i == sorted.length) {
tr = create('tr')
add('総計')
add(total.npatients)
add(total.patientsdif)
const parsei = p => isNaN(p) ? 0 : parseInt(p)
const popu = popudata.reduce((p, d) => p + parsei(d[popuname]), 0)
//console.log('total pp', popu)
const ratio = fixfloat(total.npatients * 10000 / popu + .0005, 3)
add(ratio)
add(total.ncurrentpatients)
add(calcRatio(total.ncurrentpatients, total.npatients))
add(total.nexits)
add(calcRatio(total.nexits, total.npatients))
add(total.ndeaths)
add(calcRatio(total.ndeaths, total.npatients))
tbl.appendChild(tr)
break
}
const d = sorted[i]
if (d.npatients == 0)
continue
tr = create('tr')
add(d.name_jp)
add(d.npatients)
if (prevdata) {
const prevnpatients = getData(prevdata, d.name_jp).npatients
d.patientsdif = d.npatients - prevnpatients
//console.log(d.patientsdif, d.npatients - prevnpatients)
} else {
d.patientsdif = '-'
}
add(d.patientsdif)
const popu = getData(popudata, d.name_jp)[popuname]
const ratio = fixfloat(d.npatients * 10000 / popu + .0005, 3)
//console.log(d.patientsratio, ratio)
add(ratio)
add(d.ncurrentpatients)
add(calcRatio(d.ncurrentpatients, d.npatients))
add(d.nexits)
add(calcRatio(d.nexits, d.npatients))
add(d.ndeaths)
add(calcRatio(d.ndeaths, d.npatients))
tbl.appendChild(tr)
for (const n of sumname) {
if (!isNaN(d[n])) {
total[n] += parseInt(d[n])
}
}
}
table.innerHTML = ''
table.appendChild(tbl)
}
const showZero = function(data) {
const ss = []
for (let i = 0; i < data.length; i++) {
const d = data[i]
if (d.npatients == 0) {
ss.push(shortenPref(d.name_jp))
}
}
if (ss.length > 0) {
zero.innerHTML = '<div><0件><br>' + tx(ss.join('<br>')) + "</div>"
} else {
zero.innerHTML = ''
}
}
const showSource = function(target) {
datasrc.innerHTML = tx(`CSVダウンロード: <a href=${target.url_csv}>${target.description}</a> 厚生労働省公表データ: <a href=${target.srcurl_pdf_archived}>PDF</a>`)
}
const main = async function() {
translate()
const list = await fetchCSV('data/covid19japan-all.csv')
console.log(list)
for (let i = 0; i < list.length; i++) {
const d = list[i]
const op = create('option')
op.textContent = d.lastUpdate
dateselect.appendChild(op)
if (i == list.length - 1) {
dateselect.selectedIndex = i
}
}
const show = async function() {
const day = dateselect.value
let target = null
for (const d of list) {
if (d.lastUpdate == day) {
target = d
}
}
console.log(target)
const url_data = target.url_csv
const data = await fetchCSV(url_data)
console.log(data)
const prev = getPrevTarget(list, target)
let prevdata = null
if (prev) {
prevdata = await fetchCSV(prev.url_csv)
}
console.log(prevdata)
//const popudata = await fetchCSV('data/jmari_med_or_jp/population_jp.csv')
//const popudata = await fetchCSV('data/stat_go_jp/population_jp_2016.csv')
const popudata = await fetchCSV('data/stat_go_jp/population_jp_2018.csv')
console.log(popudata)
showTable(target, data, prevdata, popudata)
showZero(data)
showSource(target)
}
show()
dateselect.onchange = show
}
document.addEventListener("DOMContentLoaded", main)
</script>
</head>
<body>
<div id=contents>
<h1><a href=https://www.stopcovid19.jp/tableview.html>新型コロナウイルス感染症(国内事例)の状況(PCR検査陽性者数の累積)(単位:人)</a></h1>
<div id='table'></div><div id='zero'></div>
<div class='dataset'><select id=dateselect></select><span id=datasrc></span></div>
<div id=credit class="credit">
<div>DATA: <a href=https://creativecommons.org/licenses/by/4.0/deed.ja>CC BY</a>「<a href=https://www.mhlw.go.jp/stf/seisakunitsuite/bunya/0000164708_00001.html>新型コロナウイルス感染症について - 厚生労働省</a>」→ <a href=https://www.stopcovid19.jp/data/covid19japan.json>JSON</a> / <a href=https://www.stopcovid19.jp/data/covid19japan.csv>CSV</a> (集約版 <a href=https://www.stopcovid19.jp/data/covid19japan-all.csv>CSV</a> / <a href=https://www.stopcovid19.jp/data/covid19japan-all.json>JSON</a>)</div>
<div>DATA: <a href=https://creativecommons.org/licenses/by/4.0/deed.ja>CC BY</a>「<a href=https://www.stat.go.jp/data/jinsui/2018np/index.html>人口(都道府県別)(平成30年) - 総務省「人口推計」</a>」→ <a href=https://www.stopcovid19.jp/data/stat_go_jp/index.csv>CSV</a> → <a href=https://www.stopcovid19.jp/data/stat_go_jp/population_jp_2018.csv>CSV</a></div>
<div>DOMAIN: <a href=https://www.code4japan.org/>Code for Japan</a> - 新型コロナウイルス感染症対策プロジェクト <a href="https://twitter.com/search?q=%23StopCOVID19JP">#StopCOVID19JP</a></div>
<div>APP (アプリ開発/提供): <a href=https://creativecommons.org/licenses/by/4.0/deed.ja>CC BY</a> <a href=https://fukuno.jig.jp/>jig.jp 福野泰介</a> <a href=https://twitter.com/taisukef>@taisukef</a> (<a href=https://github.com/code4sabae/covid19>src on GitHub</a>)</div>
「<a href=https://fukuno.jig.jp/2817>厚生労働省の方へ、CSVオープンデータ化で効率化しましょう! 新型コロナウイルス国内事例における都道府県別の患者報告数表示アプリ</a>」</div>
</div>
<div class=lang><a href=#en onclick='javascript:location.hash="#en";location.reload()'>English</a> / <a href='#ja' onclick='javascript:location.hash="#ja";location.reload()'>Japanese</a></div>
<div id="link"><a href=https://www.stopcovid19.jp/><img alt="COVID-19 JAPAN" src="covid19japan.png"/></a></div>
</body>
</html>