Skip to content

Commit

Permalink
vaccinations_by_region
Browse files Browse the repository at this point in the history
  • Loading branch information
Andraz Vrhovec committed Apr 2, 2021
1 parent bd0ed02 commit cad3ab1
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 8 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ print(df)

## Changelog

## 0.0.4

Added `vaccines_supplied_by_manufacturer()`

## 0.0.3

Added `vaccinations_by_region()`
Expand Down
18 changes: 12 additions & 6 deletions cepimose/__init__.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
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)
resp.raise_for_status()
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)
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)
178 changes: 178 additions & 0 deletions cepimose/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
30 changes: 29 additions & 1 deletion cepimose/parser.py
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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
8 changes: 8 additions & 0 deletions cepimose/types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from dataclasses import dataclass
import datetime
from typing import Optional

@dataclass
class VaccinationByDayRow:
Expand Down Expand Up @@ -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]

2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[metadata]
# replace with your username:
name = cepimose
version = 0.0.3
version = 0.0.4
author = sledilnik.org
author_email = [email protected]
description = A small example package to get raw data from NIJZ vaccinations dashboard
Expand Down

0 comments on commit cad3ab1

Please sign in to comment.