-
Notifications
You must be signed in to change notification settings - Fork 16
/
consolidate_spain.py
executable file
·121 lines (113 loc) · 2.33 KB
/
consolidate_spain.py
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import csv
fields = [
"confirmed",
"deceased",
"hospitalized",
"intensive_care"
]
provincias = {
"C" : "GA",
"VI": "PV",
"AB": "CM",
"A" : "VC",
"AL": "AN",
"O" : "AS",
"AV": "CL",
"BA": "EX",
"PM": "IB",
"B" : "CT",
"BU": "CL",
"CC": "EX",
"CA": "AN",
"S" : "CB",
"CS": "VC",
"CR": "CM",
"CO": "AN",
"CU": "CM",
"GI": "CT",
"GR": "AN",
"GU": "CM",
"SS": "PV",
"H" : "AN",
"HU": "AR",
"J" : "AN",
"LO": "RI",
"GC": "CN",
"LE": "CL",
"L" : "CT",
"LU": "GA",
"M" : "MD",
"MA": "AN",
"MU": "MC",
"NA": "NC",
"NC": "NC",
"OR": "GA",
"P" : "CL",
"PO": "GA",
"SA": "CL",
"TF": "CN",
"SG": "CL",
"SE": "AN",
"SO": "CL",
"T" : "CT",
"TE": "AR",
"TO": "CM",
"V" : "VC",
"VA": "CL",
"BI": "PV",
"ZA": "CL",
"Z" : "AR",
"CE": "CE",
"ML": "ML"
}
CCAAs = {
"AN": "Andalucía",
"AR": "Aragón",
"AS": "Asturias",
"IB": "Baleares",
"CN": "Canarias",
"CB": "Cantabria",
"CM": "Castilla La Mancha",
"CL": "Castilla y León",
"CT": "Cataluña",
"CE": "Ceuta",
"GA": "Galicia",
"VC": "Valenciana",
"EX": "Extremadura",
"MD": "Madrid",
"ML": "Melilla",
"MC": "Murcia",
"NC": "Navarra",
"PV": "País Vasco",
"RI": "La Rioja"
}
data = {}
mapping = {
"num_uci": "intensive_care",
"num_casos": "confirmed",
"num_def": "deceased",
"num_hosp": "hospitalized"
}
curdate = None
with open(os.path.join("data", "casos_hosp_uci_def_sexo_edad_provres.csv")) as f:
for row in csv.DictReader(f):
if curdate != row["fecha"]:
lastdate = curdate
curdate = row["fecha"]
curccaa = CCAAs[provincias[row["provincia_iso"]]]
if not data:
data[curdate] = {k: {"confirmed": 0, "deceased": 0, "hospitalized": 0, "intensive_care": 0} for k in CCAAs.values()}
else:
if curdate not in data:
data[curdate] = {}
if curccaa not in data[curdate]:
data[curdate][curccaa] = dict(data[lastdate][curccaa])
for k, f in mapping.items():
data[curdate][curccaa][f] += int(row[k])
print("date,CCAA," + ",".join(fields))
for d in sorted(data.keys()):
for c in CCAAs.values():
print(",".join([d, c] + [str(data[d][c].get(k, 0)) for k in fields]))