Skip to content

Commit bfb70ca

Browse files
authored
feat: ✨ add abort update lab tests func (#102)
1 parent a984132 commit bfb70ca

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

cepimose/__init__.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
_vaccinations_by_manufacturer_used_request,
2424
_lab_start_ts_req,
2525
_lab_end_ts_req,
26+
_lab_end_ts_req_with_cache,
2627
_lab_PCR_tests_performed_req,
2728
_lab_PCR_total_tests_performed_req,
2829
_lab_active_cases_estimated_req,
@@ -502,6 +503,19 @@ def lab_end_timestamp() -> datetime.datetime:
502503
)
503504

504505

506+
def lab_end_timestamp_with_cache() -> datetime.datetime:
507+
"""Gets NIJZ last data update time
508+
509+
Returns:
510+
datetime: datetime representing NIJZ last data update time
511+
"""
512+
return _get_data(
513+
_lab_end_ts_req_with_cache,
514+
_parse_vaccinations_timestamp,
515+
_lab_dashboard_headers,
516+
)
517+
518+
505519
def lab_PCR_tests_performed() -> int:
506520
"""Gets performed PCR tests on today
507521
@@ -718,3 +732,33 @@ def get_lab_dashboard() -> LabDashboard:
718732
)
719733

720734
return result
735+
736+
737+
def abort_update_labtests():
738+
end_date = lab_end_timestamp()
739+
end_date_with_cache = lab_end_timestamp_with_cache()
740+
741+
yesterday = datetime.date.today() - datetime.timedelta(days=1)
742+
now = datetime.datetime.now()
743+
744+
should_abort = end_date.date() < yesterday
745+
should_abort_with_cache = end_date_with_cache.date() < yesterday
746+
747+
result = {
748+
"abort": True,
749+
"now": now,
750+
"date_no_cache": end_date,
751+
"date_with_cache": end_date_with_cache,
752+
"date": yesterday - datetime.timedelta(days=1),
753+
}
754+
755+
if should_abort and should_abort_with_cache:
756+
print("Aborting update labtests")
757+
print(
758+
f"Now is {now}. Date no cache: {end_date.date()}. Date with cache: {end_date_with_cache.date()}. Expecting: {yesterday}"
759+
)
760+
return result
761+
762+
result["abort"] = False
763+
result["date"] = yesterday
764+
return result

cepimose/data.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2060,7 +2060,8 @@ def _create_vaccinations_data_range_request(
20602060
}
20612061
}
20622062

2063-
_lab_end_ts_req = _create_req("lab", [_lab_end_ts_command], cache_key=True)
2063+
_lab_end_ts_req = _create_req("lab", [_lab_end_ts_command])
2064+
_lab_end_ts_req_with_cache = _create_req("lab", [_lab_end_ts_command], cache_key=True)
20642065

20652066
_lab_PCR_tests_performed_command = {
20662067
"SemanticQueryDataShapeCommand": {

0 commit comments

Comments
 (0)