Skip to content

Commit

Permalink
Merge pull request #23 from jalezi/by_gender
Browse files Browse the repository at this point in the history
feat: +vaccinations_gender_by_date
  • Loading branch information
stefanb authored May 18, 2021
2 parents 941cdc5 + b12f43c commit 6d16338
Show file tree
Hide file tree
Showing 6 changed files with 460 additions and 14 deletions.
63 changes: 62 additions & 1 deletion cepimose/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import datetime
import requests
import time
from .data import (
_source,
_headers,
Expand All @@ -14,6 +16,7 @@
_vaccinations_timestamp_req,
_vaccinations_age_group_by_region_on_day_requests,
_vaccination_by_manufacturer_supplied_used_requests,
_vaccinations_gender_by_date_requests,
)
from .parser import (
_parse_vaccinations_by_age,
Expand All @@ -28,11 +31,13 @@
_parse_vaccinations_timestamp,
_parse_vaccinations_age_group_by_region_on_day,
_parse_vaccinations_by_manufacturer_supplied_used,
_parse_vaccinations_gender_by_date,
)

from .types import (
VaccinationByAgeRow,
VaccinationByDayRow,
VaccinationsByGender,
VaccineSupplyUsage,
VaccinationByRegionRow,
VaccinationByManufacturerRow,
Expand All @@ -41,7 +46,7 @@
VaccinationAgeGroupByRegionOnDay,
)

from .enums import Manufacturer, Region, AgeGroup
from .enums import Manufacturer, Region, AgeGroup, Gender


def _get_data(req, parse_response):
Expand Down Expand Up @@ -167,3 +172,59 @@ def vaccinations_by_manufacturer_supplied_used(
req = _vaccination_by_manufacturer_supplied_used_requests[group][0]
doses = _get_data(req, _parse_vaccinations_by_manufacturer_supplied_used)
return doses


# PAGE 1
# gender
def vaccinations_gender_by_date(date: datetime.datetime = None):

start = time.perf_counter()

if date == None:
result = []
for day in _vaccinations_gender_by_date_requests:
date = day["date"]
female = day[Gender.FEMALE]
male = day[Gender.MALE]
female_first = _get_data(female[0], _parse_vaccinations_gender_by_date)
female_second = _get_data(female[1], _parse_vaccinations_gender_by_date)
male_first = _get_data(male[0], _parse_vaccinations_gender_by_date)
male_second = _get_data(male[1], _parse_vaccinations_gender_by_date)
result.append(
VaccinationsByGender(
date=date,
female_first=female_first,
female_second=female_second,
male_first=male_first,
male_second=male_second,
)
)
finish = time.perf_counter()
print(f"Elapsed time: {finish - start}")
return result

filtered_days = list(
filter(lambda item: item["date"] == date, _vaccinations_gender_by_date_requests)
)

if len(filtered_days) == 0:
return None

day = filtered_days[0]

date = day["date"]
female = day[Gender.FEMALE]
male = day[Gender.MALE]
female_first = _get_data(female[0], _parse_vaccinations_gender_by_date)
female_second = _get_data(female[1], _parse_vaccinations_gender_by_date)
male_first = _get_data(male[0], _parse_vaccinations_gender_by_date)
male_second = _get_data(male[1], _parse_vaccinations_gender_by_date)
finish = time.perf_counter()
print(f"Elapsed time: {finish - start}")
return VaccinationsByGender(
date=date,
female_first=female_first,
female_second=female_second,
male_first=male_first,
male_second=male_second,
)
Loading

0 comments on commit 6d16338

Please sign in to comment.