Skip to content

Commit

Permalink
Add 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 7213acf commit 908cda8
Show file tree
Hide file tree
Showing 7 changed files with 338 additions and 9 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,16 @@ print(df)
```

## Changelog

## 0.0.3

Added `vaccinations_by_region()`

## 0.0.2

Initial release

## Dev

```
Expand Down
11 changes: 7 additions & 4 deletions cepimose/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import requests
from .data import _source, _headers, _vaccinations_by_day_req, _vaccinations_by_age_req, _vaccines_supplied_and_used_req
from .parser import _parse_vaccinations_by_age, _parse_vaccinations_by_day, _parse_vaccines_supplued_and_used
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 .types import VaccinationByAgeRow, VaccinationByDayRow, VaccineSupplyUsage
from .types import VaccinationByAgeRow, VaccinationByDayRow, VaccineSupplyUsage, VaccinationByRegionRow

def _get_data(req, parse_response):
resp = requests.post(_source, headers=_headers, json=req)
Expand All @@ -19,4 +19,7 @@ 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)
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)
258 changes: 258 additions & 0 deletions cepimose/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -493,4 +493,262 @@
}
],
"version": "1.0.0"
}

_vaccinations_by_region_req = {
"cancelQueries": [],
"modelId": 159824,
"queries": [
{
"ApplicationContext": {
"DatasetId": "7b40529e-a50e-4dd3-8fe8-997894b4cdaa",
"Sources": [
{
"ReportId": "b201281d-b2e7-4470-9f4e-0b3063794c76"
}
]
},
"CacheKey": "{\"Commands\":[{\"SemanticQueryDataShapeCommand\":{\"Query\":{\"Version\":2,\"From\":[{\"Name\":\"e\",\"Entity\":\"eRCO_podatki\",\"Type\":0},{\"Name\":\"s1\",\"Entity\":\"Sifrant_regija\",\"Type\":0},{\"Name\":\"c\",\"Entity\":\"Calendar\",\"Type\":0}],\"Select\":[{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s1\"}},\"Property\":\"Regija\"},\"Name\":\"Sifrant_regija.Regija\"},{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"e\"}},\"Property\":\"Odmerek\"},\"Name\":\"eRCO_podatki.Odmerek\"},{\"Measure\":{\"Expression\":{\"SourceRef\":{\"Source\":\"e\"}},\"Property\":\"Delež_regija\"},\"Name\":\"eRCO_podatki.Delež_regija\"},{\"Aggregation\":{\"Expression\":{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"e\"}},\"Property\":\"Weight\"}},\"Function\":0},\"Name\":\"Sum(eRCO_podatki.Weight)\"}],\"Where\":[{\"Condition\":{\"Not\":{\"Expression\":{\"In\":{\"Expressions\":[{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"e\"}},\"Property\":\"CepivoIme\"}}],\"Values\":[[{\"Literal\":{\"Value\":\"null\"}}]]}}}}},{\"Condition\":{\"Not\":{\"Expression\":{\"In\":{\"Expressions\":[{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"s1\"}},\"Property\":\"Regija\"}}],\"Values\":[[{\"Literal\":{\"Value\":\"null\"}}],[{\"Literal\":{\"Value\":\"'Celotna Slovenija'\"}}],[{\"Literal\":{\"Value\":\"'TUJINA'\"}}]]}}}}},{\"Condition\":{\"Comparison\":{\"ComparisonKind\":1,\"Left\":{\"Column\":{\"Expression\":{\"SourceRef\":{\"Source\":\"c\"}},\"Property\":\"Date\"}},\"Right\":{\"DateSpan\":{\"Expression\":{\"Literal\":{\"Value\":\"datetime'2020-12-26T01:00:00'\"}},\"TimeUnit\":5}}}}}],\"OrderBy\":[{\"Direction\":2,\"Expression\":{\"Measure\":{\"Expression\":{\"SourceRef\":{\"Source\":\"e\"}},\"Property\":\"Delež_regija\"}}}]},\"Binding\":{\"Primary\":{\"Groupings\":[{\"Projections\":[0,2,3]}]},\"Secondary\":{\"Groupings\":[{\"Projections\":[1]}]},\"DataReduction\":{\"DataVolume\":4,\"Primary\":{\"Window\":{\"Count\":200}},\"Secondary\":{\"Top\":{\"Count\":60}}},\"SuppressedJoinPredicates\":[3],\"Version\":1}}}]}",
"Query": {
"Commands": [
{
"SemanticQueryDataShapeCommand": {
"Binding": {
"DataReduction": {
"DataVolume": 4,
"Primary": {
"Window": {
"Count": 200
}
},
"Secondary": {
"Top": {
"Count": 60
}
}
},
"Primary": {
"Groupings": [
{
"Projections": [
0,
2,
3
]
}
]
},
"Secondary": {
"Groupings": [
{
"Projections": [
1
]
}
]
},
"SuppressedJoinPredicates": [
3
],
"Version": 1
},
"Query": {
"From": [
{
"Entity": "eRCO_podatki",
"Name": "e",
"Type": 0
},
{
"Entity": "Sifrant_regija",
"Name": "s1",
"Type": 0
},
{
"Entity": "Calendar",
"Name": "c",
"Type": 0
}
],
"OrderBy": [
{
"Direction": 2,
"Expression": {
"Measure": {
"Expression": {
"SourceRef": {
"Source": "e"
}
},
"Property": "Delež_regija"
}
}
}
],
"Select": [
{
"Column": {
"Expression": {
"SourceRef": {
"Source": "s1"
}
},
"Property": "Regija"
},
"Name": "Sifrant_regija.Regija"
},
{
"Column": {
"Expression": {
"SourceRef": {
"Source": "e"
}
},
"Property": "Odmerek"
},
"Name": "eRCO_podatki.Odmerek"
},
{
"Measure": {
"Expression": {
"SourceRef": {
"Source": "e"
}
},
"Property": "Delež_regija"
},
"Name": "eRCO_podatki.Delež_regija"
},
{
"Aggregation": {
"Expression": {
"Column": {
"Expression": {
"SourceRef": {
"Source": "e"
}
},
"Property": "Weight"
}
},
"Function": 0
},
"Name": "Sum(eRCO_podatki.Weight)"
}
],
"Version": 2,
"Where": [
{
"Condition": {
"Not": {
"Expression": {
"In": {
"Expressions": [
{
"Column": {
"Expression": {
"SourceRef": {
"Source": "e"
}
},
"Property": "CepivoIme"
}
}
],
"Values": [
[
{
"Literal": {
"Value": "null"
}
}
]
]
}
}
}
}
},
{
"Condition": {
"Not": {
"Expression": {
"In": {
"Expressions": [
{
"Column": {
"Expression": {
"SourceRef": {
"Source": "s1"
}
},
"Property": "Regija"
}
}
],
"Values": [
[
{
"Literal": {
"Value": "null"
}
}
],
[
{
"Literal": {
"Value": "'Celotna Slovenija'"
}
}
],
[
{
"Literal": {
"Value": "'TUJINA'"
}
}
]
]
}
}
}
}
},
{
"Condition": {
"Comparison": {
"ComparisonKind": 1,
"Left": {
"Column": {
"Expression": {
"SourceRef": {
"Source": "c"
}
},
"Property": "Date"
}
},
"Right": {
"DateSpan": {
"Expression": {
"Literal": {
"Value": "datetime'2020-12-26T01:00:00'"
}
},
"TimeUnit": 5
}
}
}
}
}
]
}
}
}
]
},
"QueryId": ""
}
],
"version": "1.0.0"
}
23 changes: 22 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
from .types import VaccinationByDayRow, VaccinationByAgeRow, VaccineSupplyUsage, VaccinationByRegionRow

def parse_date(raw):
return datetime.datetime.utcfromtimestamp(float(raw)/1000.0)
Expand Down Expand Up @@ -66,4 +66,25 @@ def _parse_vaccines_supplued_and_used(data) -> 'list[VaccineSupplyUsage]':
)
parsed_data.append(row)

return parsed_data

def _parse_vaccinations_by_region(data) -> 'list[VaccinationByRegionRow]':
resp = data["results"][0]["result"]["data"]["dsr"]["DS"][0]["PH"][0]["DM0"]
parsed_data = []

for element in resp:
region = str(element["G0"])
count_first = int(element["X"][0]["C"][1])
count_second = int(element["X"][1]["C"][1])
share_first = float(element["X"][0]["C"][0])/100.0
share_second = float(element["X"][1]["C"][0])/100.0

parsed_data.append(VaccinationByRegionRow(
region=region,
count_first=count_first,
count_second=count_second,
share_first=share_first,
share_second=share_second
))

return parsed_data
11 changes: 10 additions & 1 deletion cepimose/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,13 @@ class VaccinationByAgeRow:
class VaccineSupplyUsage:
date: datetime.datetime
supplied: int
used: int
used: int

@dataclass
class VaccinationByRegionRow:
region: str
count_first: int
count_second: int
share_first: float
share_second: float

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.2
version = 0.0.3
author = sledilnik.org
author_email = [email protected]
description = A small example package to get raw data from NIJZ vaccinations dashboard
Expand Down
Loading

0 comments on commit 908cda8

Please sign in to comment.