forked from owid/covid-19-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathestonia.py
61 lines (44 loc) · 2.09 KB
/
estonia.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
import pandas as pd
def read(source: str) -> pd.DataFrame:
return parse_data(source)
def parse_data(source: str) -> pd.DataFrame:
df = pd.read_json(source)
df = (
df[["StatisticsDate", "MeasurementType", "TotalCount"]]
.pivot(index="StatisticsDate", columns="MeasurementType", values="TotalCount")
.reset_index()
.rename(
columns={
"StatisticsDate": "date",
"DosesAdministered": "total_vaccinations",
"FullyVaccinated": "people_fully_vaccinated",
"Vaccinated": "people_vaccinated",
}
)
)
return df[["date", "people_fully_vaccinated", "people_vaccinated", "total_vaccinations"]]
def enrich_location(df: pd.DataFrame) -> pd.DataFrame:
return df.assign(location="Estonia")
def enrich_vaccine_name(df: pd.DataFrame) -> pd.DataFrame:
def _enrich_vaccine_name(date: str) -> str:
if date < "2021-01-14":
return "Pfizer/BioNTech"
elif "2021-01-14" <= date < "2021-02-09":
return "Moderna, Pfizer/BioNTech"
elif "2021-02-09" <= date < "2021-04-14":
return "Moderna, Oxford/AstraZeneca, Pfizer/BioNTech"
elif "2021-04-14" <= date:
# https://vaktsineeri.ee/covid-19/vaktsineerimine-eestis/
# https://vaktsineeri.ee/uudised/sel-nadalal-alustatakse-lamavate-haigete-ja-liikumisraskustega-inimeste-kodus-vaktsineerimist/
return "Johnson&Johnson, Moderna, Oxford/AstraZeneca, Pfizer/BioNTech"
return df.assign(vaccine=df.date.apply(_enrich_vaccine_name))
def enrich_source(df: pd.DataFrame) -> pd.DataFrame:
return df.assign(source_url="https://opendata.digilugu.ee")
def pipeline(df: pd.DataFrame) -> pd.DataFrame:
return df.pipe(enrich_location).pipe(enrich_vaccine_name).pipe(enrich_source)
def main(paths):
source = "https://opendata.digilugu.ee/covid19/vaccination/v2/opendata_covid19_vaccination_total.json"
destination = paths.tmp_vax_out("Estonia")
read(source).pipe(pipeline).to_csv(destination, index=False)
if __name__ == "__main__":
main()