Skip to content

Commit

Permalink
feat: ✨ add abort update lab tests func (#102)
Browse files Browse the repository at this point in the history
  • Loading branch information
jalezi authored Apr 19, 2022
1 parent a984132 commit bfb70ca
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
44 changes: 44 additions & 0 deletions cepimose/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
_vaccinations_by_manufacturer_used_request,
_lab_start_ts_req,
_lab_end_ts_req,
_lab_end_ts_req_with_cache,
_lab_PCR_tests_performed_req,
_lab_PCR_total_tests_performed_req,
_lab_active_cases_estimated_req,
Expand Down Expand Up @@ -502,6 +503,19 @@ def lab_end_timestamp() -> datetime.datetime:
)


def lab_end_timestamp_with_cache() -> datetime.datetime:
"""Gets NIJZ last data update time
Returns:
datetime: datetime representing NIJZ last data update time
"""
return _get_data(
_lab_end_ts_req_with_cache,
_parse_vaccinations_timestamp,
_lab_dashboard_headers,
)


def lab_PCR_tests_performed() -> int:
"""Gets performed PCR tests on today
Expand Down Expand Up @@ -718,3 +732,33 @@ def get_lab_dashboard() -> LabDashboard:
)

return result


def abort_update_labtests():
end_date = lab_end_timestamp()
end_date_with_cache = lab_end_timestamp_with_cache()

yesterday = datetime.date.today() - datetime.timedelta(days=1)
now = datetime.datetime.now()

should_abort = end_date.date() < yesterday
should_abort_with_cache = end_date_with_cache.date() < yesterday

result = {
"abort": True,
"now": now,
"date_no_cache": end_date,
"date_with_cache": end_date_with_cache,
"date": yesterday - datetime.timedelta(days=1),
}

if should_abort and should_abort_with_cache:
print("Aborting update labtests")
print(
f"Now is {now}. Date no cache: {end_date.date()}. Date with cache: {end_date_with_cache.date()}. Expecting: {yesterday}"
)
return result

result["abort"] = False
result["date"] = yesterday
return result
3 changes: 2 additions & 1 deletion cepimose/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,8 @@ def _create_vaccinations_data_range_request(
}
}

_lab_end_ts_req = _create_req("lab", [_lab_end_ts_command], cache_key=True)
_lab_end_ts_req = _create_req("lab", [_lab_end_ts_command])
_lab_end_ts_req_with_cache = _create_req("lab", [_lab_end_ts_command], cache_key=True)

_lab_PCR_tests_performed_command = {
"SemanticQueryDataShapeCommand": {
Expand Down

0 comments on commit bfb70ca

Please sign in to comment.