forked from owid/covid-19-data
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathestonia.py
64 lines (51 loc) · 2.2 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
62
63
64
import pandas as pd
from cowidev.utils import paths
from cowidev.vax.utils.utils import build_vaccine_timeline
class Estonia:
location: str = "Estonia"
# We should soon migrate to v3 of the API. Currently waiting for documentation for v3 to be released at
# https://www.terviseamet.ee/et/koroonaviirus/avaandmed
source_url: str = "https://opendata.digilugu.ee/covid19/vaccination/v2/opendata_covid19_vaccination_total.json"
source_url_ref: str = "https://opendata.digilugu.ee"
def read(self) -> pd.DataFrame:
return self._parse_data()
def _parse_data(self) -> pd.DataFrame:
df = pd.read_json(self.source_url)
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 pipe_location(self, df: pd.DataFrame) -> pd.DataFrame:
return df.assign(location=self.location)
def pipe_vaccine_name(self, df: pd.DataFrame) -> pd.DataFrame:
df = build_vaccine_timeline(
df,
{
"Pfizer/BioNTech": "2020-12-01",
"Moderna": "2021-01-14",
"Oxford/AstraZeneca": "2021-02-09",
"Johnson&Johnson": "2021-04-14",
},
)
return df
def pipe_source(self, df: pd.DataFrame) -> pd.DataFrame:
return df.assign(source_url=self.source_url_ref)
def pipeline(self, df: pd.DataFrame) -> pd.DataFrame:
return df.pipe(self.pipe_location).pipe(self.pipe_vaccine_name).pipe(self.pipe_source)
def export(self):
destination = paths.out_vax(self.location)
self.read().pipe(self.pipeline).to_csv(destination, index=False)
def main():
Estonia().export()
if __name__ == "__main__":
main()