-
Notifications
You must be signed in to change notification settings - Fork 16
/
consolidate_uk.py
executable file
·67 lines (59 loc) · 2.04 KB
/
consolidate_uk.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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import os
import csv
fields = [
"confirmed",
"deceased",
"hospitalized",
"intensive_care",
"vaccinated_once",
"vaccinated_fully"
]
countries = [
"England",
"Wales",
"Scotland",
"Northern Ireland"
]
data = {}
lastdate = "2100-01-01"
mapping = {
"covidOccupiedMVBeds": "intensive_care",
"cumCasesBySpecimenDate": "confirmed",
"cumDeaths28DaysByDeathDate": "deceased",
"hospitalCases": "hospitalized"
}
curcountry = None
with open(os.path.join("data", "covid-19-indicators-uk.csv")) as f:
for row in csv.DictReader(f):
if curcountry != row["areaName"]:
if any([not row[k] for k in mapping]):
continue
curcountry = row["areaName"]
if row["date"] < lastdate:
lastdate = row["date"]
if row["date"] not in data:
data[row["date"]] = {
"England": {},
"Wales": {},
"Scotland": {},
"Northern Ireland": {}
}
for k, f in mapping.items():
data[row["date"]][row["areaName"]][f] = row[k] or 0
curcountry = None
with open(os.path.join("data", "covid-19-vaccines-uk.csv")) as f:
for row in csv.DictReader(f):
if curcountry != row["areaName"]:
curcountry = row["areaName"]
if row["date"] < lastdate:
lastdate = row["date"]
data[row["date"]][row["areaName"]]["vaccinated_once"] = row["cumPeopleVaccinatedFirstDoseByPublishDate"] if not row["cumPeopleVaccinatedFirstDoseByVaccinationDate"] else row["cumPeopleVaccinatedFirstDoseByVaccinationDate"]
data[row["date"]][row["areaName"]]["vaccinated_fully"] = row["cumPeopleVaccinatedCompleteByVaccinationDate"] or row["cumPeopleVaccinatedCompleteByPublishDate"]
print("date,country," + ",".join(fields))
for d in sorted(data.keys()):
if d > lastdate:
continue
for c in countries:
print(",".join([d, c] + [str(data[d][c].get(k, 0)) for k in fields]))