diff --git a/README.md b/README.md index b506183..2813207 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,10 @@ print(df) ## Changelog +## 0.0.4 + +Added `vaccines_supplied_by_manufacturer()` + ## 0.0.3 Added `vaccinations_by_region()` diff --git a/cepimose/__init__.py b/cepimose/__init__.py index 7c538fb..3c88575 100644 --- a/cepimose/__init__.py +++ b/cepimose/__init__.py @@ -1,8 +1,9 @@ import requests -from .data import _source, _headers, _vaccinations_by_day_req, _vaccinations_by_age_req, _vaccines_supplied_and_used_req, _vaccinations_by_region_req -from .parser import _parse_vaccinations_by_age, _parse_vaccinations_by_day, _parse_vaccines_supplued_and_used, _parse_vaccinations_by_region +from .data import _source, _headers, _vaccinations_by_day_req, _vaccinations_by_age_req, _vaccines_supplied_and_used_req, _vaccinations_by_region_req, _vaccines_supplied_by_manufacturer_req +from .parser import _parse_vaccinations_by_age, _parse_vaccinations_by_day, _parse_vaccines_supplued_and_used, _parse_vaccinations_by_region, _parse_vaccines_supplied_by_manufacturer + +from .types import VaccinationByAgeRow, VaccinationByDayRow, VaccineSupplyUsage, VaccinationByRegionRow, VaccinationByManufacturerRow -from .types import VaccinationByAgeRow, VaccinationByDayRow, VaccineSupplyUsage, VaccinationByRegionRow def _get_data(req, parse_response): resp = requests.post(_source, headers=_headers, json=req) @@ -10,16 +11,21 @@ def _get_data(req, parse_response): return parse_response(resp.json()) - - def vaccinations_by_day() -> 'list[VaccinationByDayRow]': return _get_data(_vaccinations_by_day_req, _parse_vaccinations_by_day) + def vaccinations_by_age() -> 'list[VaccinationByAgeRow]': return _get_data(_vaccinations_by_age_req, _parse_vaccinations_by_age) + def vaccines_supplied_and_used() -> 'list[VaccineSupplyUsage]': return _get_data(_vaccines_supplied_and_used_req, _parse_vaccines_supplued_and_used) + def vaccinations_by_region() -> 'list[VaccinationByRegionRow]': - return _get_data(_vaccinations_by_region_req, _parse_vaccinations_by_region) \ No newline at end of file + return _get_data(_vaccinations_by_region_req, _parse_vaccinations_by_region) + + +def vaccines_supplied_by_manufacturer() -> 'list[VaccinationByManufacturerRow]': + return _get_data(_vaccines_supplied_by_manufacturer_req, _parse_vaccines_supplied_by_manufacturer) diff --git a/cepimose/data.py b/cepimose/data.py index ec1735d..9758e8e 100644 --- a/cepimose/data.py +++ b/cepimose/data.py @@ -748,4 +748,182 @@ } ], "version": "1.0.0" +} + +_vaccines_supplied_by_manufacturer_req = { + "cancelQueries": [], + "modelId": 159824, + "queries": [ + { + "ApplicationContext": { + "DatasetId": "7b40529e-a50e-4dd3-8fe8-997894b4cdaa", + "Sources": [ + { + "ReportId": "b201281d-b2e7-4470-9f4e-0b3063794c76" + } + ] + }, + "Query": { + "Commands": [ + { + "SemanticQueryDataShapeCommand": { + "Binding": { + "DataReduction": { + "DataVolume": 4, + "Intersection": { + "BinnedLineSample": {} + } + }, + "Primary": { + "Groupings": [ + { + "Projections": [ + 0, + 2 + ] + } + ] + }, + "Secondary": { + "Groupings": [ + { + "Projections": [ + 1 + ] + } + ] + }, + "Version": 1 + }, + "ExecutionMetricsKind": 1, + "Query": { + "From": [ + { + "Entity": "Calendar", + "Name": "c1", + "Type": 0 + }, + { + "Entity": "Vezno_Vrsta_cepiva", + "Name": "v", + "Type": 0 + }, + { + "Entity": "NIJZ_Odmerki", + "Name": "n", + "Type": 0 + } + ], + "Select": [ + { + "Column": { + "Expression": { + "SourceRef": { + "Source": "c1" + } + }, + "Property": "Date" + }, + "Name": "Calendar.Date" + }, + { + "Column": { + "Expression": { + "SourceRef": { + "Source": "v" + } + }, + "Property": "Vrsta_cepiva" + }, + "Name": "Vezno_Vrsta_cepiva.Vrsta_cepiva" + }, + { + "Measure": { + "Expression": { + "SourceRef": { + "Source": "n" + } + }, + "Property": "Tekoča vsota za mero odmerki* v polju Date" + }, + "Name": "NIJZ_Odmerki.Tekoča vsota za mero odmerki* v polju Date" + } + ], + "Version": 2, + "Where": [ + { + "Condition": { + "Comparison": { + "ComparisonKind": 2, + "Left": { + "Column": { + "Expression": { + "SourceRef": { + "Source": "c1" + } + }, + "Property": "Date" + } + }, + "Right": { + "DateSpan": { + "Expression": { + "Literal": { + "Value": "datetime'2020-12-20T00:00:00'" + } + }, + "TimeUnit": 5 + } + } + } + } + }, + { + "Condition": { + "Not": { + "Expression": { + "In": { + "Expressions": [ + { + "Column": { + "Expression": { + "SourceRef": { + "Source": "n" + } + }, + "Property": "Vrsta cepiva" + } + } + ], + "Values": [ + [ + { + "Literal": { + "Value": "'Skupaj'" + } + } + ], + [ + { + "Literal": { + "Value": "null" + } + } + ] + ] + } + } + } + } + } + ] + } + } + } + ] + }, + "QueryId": "" + } + ], + "version": "1.0.0" } \ No newline at end of file diff --git a/cepimose/parser.py b/cepimose/parser.py index eae39ba..d8725f0 100644 --- a/cepimose/parser.py +++ b/cepimose/parser.py @@ -1,6 +1,6 @@ import datetime -from .types import VaccinationByDayRow, VaccinationByAgeRow, VaccineSupplyUsage, VaccinationByRegionRow +from .types import VaccinationByDayRow, VaccinationByAgeRow, VaccineSupplyUsage, VaccinationByRegionRow, VaccinationByManufacturerRow def parse_date(raw): return datetime.datetime.utcfromtimestamp(float(raw)/1000.0) @@ -87,4 +87,32 @@ def _parse_vaccinations_by_region(data) -> 'list[VaccinationByRegionRow]': share_second=share_second )) + return parsed_data + +def _parse_vaccines_supplied_by_manufacturer(data) -> 'list[VaccinationByManufacturerRow]': + resp = data["results"][0]["result"]["data"]["dsr"]["DS"][0]["PH"][0]["DM0"] + parsed_data = [] + + for element in resp: + + el = next(filter(lambda x: 'M0' in x, element["X"])) + + date = parse_date(element["G0"]) + moderna = None + pfizer = None + az = None + if el.get("I", None) == 1: + moderna = int(el['M0']) + elif el.get("I", None) == 2: + pfizer = int(el['M0']) + else: + az = int(el['M0']) + + parsed_data.append(VaccinationByManufacturerRow( + date=date, + pfizer=pfizer, + moderna=moderna, + az=az, + )) + return parsed_data \ No newline at end of file diff --git a/cepimose/types.py b/cepimose/types.py index b8f3897..7bee296 100644 --- a/cepimose/types.py +++ b/cepimose/types.py @@ -1,5 +1,6 @@ from dataclasses import dataclass import datetime +from typing import Optional @dataclass class VaccinationByDayRow: @@ -29,4 +30,11 @@ class VaccinationByRegionRow: count_second: int share_first: float share_second: float + +@dataclass +class VaccinationByManufacturerRow: + date: datetime.datetime + pfizer: Optional[int] + moderna: Optional[int] + az: Optional[int] \ No newline at end of file diff --git a/setup.cfg b/setup.cfg index ab51c66..2502a2a 100644 --- a/setup.cfg +++ b/setup.cfg @@ -1,7 +1,7 @@ [metadata] # replace with your username: name = cepimose -version = 0.0.3 +version = 0.0.4 author = sledilnik.org author_email = info@sledilnik.org description = A small example package to get raw data from NIJZ vaccinations dashboard