From 784387dcb855900591c5e25d6f5bc7ad8ef42d13 Mon Sep 17 00:00:00 2001 From: James Woglom Date: Mon, 30 Sep 2024 00:49:59 -0400 Subject: [PATCH] sensor start/stop/join eventtypes --- tconnectsync/parser/nightscout.py | 6 ++--- .../process_cgm_start_join_stop.py | 23 +++++++++++++++---- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/tconnectsync/parser/nightscout.py b/tconnectsync/parser/nightscout.py index 1d9e2cf..574837d 100644 --- a/tconnectsync/parser/nightscout.py +++ b/tconnectsync/parser/nightscout.py @@ -16,9 +16,9 @@ EXERCISE_EVENTTYPE = "Exercise" SLEEP_EVENTTYPE = "Sleep" ALARM_EVENTTYPE = "Alarm" CGM_ALERT_EVENTTYPE = "CGM Alert" -CGM_START_EVENTTYPE = "CGM Start Session" -CGM_JOIN_EVENTTYPE = "CGM Join Session" -CGM_STOP_EVENTTYPE = "CGM Stop Session" +CGM_START_EVENTTYPE = "Sensor Start" +CGM_JOIN_EVENTTYPE = "Sensor Start" +CGM_STOP_EVENTTYPE = "Sensor Stop" IOB_ACTIVITYTYPE = "tconnect_iob" diff --git a/tconnectsync/sync/tandemsource/process_cgm_start_join_stop.py b/tconnectsync/sync/tandemsource/process_cgm_start_join_stop.py index ae5efb0..0db2898 100644 --- a/tconnectsync/sync/tandemsource/process_cgm_start_join_stop.py +++ b/tconnectsync/sync/tandemsource/process_cgm_start_join_stop.py @@ -9,6 +9,8 @@ from ...eventparser import events as eventtypes from ...domain.tandemsource.event_class import EventClass from ...parser.nightscout import ( CGM_START_EVENTTYPE, + CGM_JOIN_EVENTTYPE, + CGM_STOP_EVENTTYPE, NightscoutEntry ) @@ -26,12 +28,23 @@ class ProcessCGMStartJoinStop: return features.PUMP_EVENTS in self.features or features.CGM_ALERTS in self.features def process(self, events, time_start, time_end): - logger.debug("ProcessCGMStartJoinStop: querying for last uploaded entry") - last_upload = self.nightscout.last_uploaded_entry(CGM_START_EVENTTYPE, time_start=time_start, time_end=time_end) + last_upload = None last_upload_time = None - if last_upload: - last_upload_time = arrow.get(last_upload["created_at"]) - logger.info("ProcessCGMStartJoinStop: Last Nightscout cgmstart upload: %s" % last_upload_time) + for eventtype in [CGM_START_EVENTTYPE, CGM_JOIN_EVENTTYPE, CGM_STOP_EVENTTYPE]: + logger.debug("ProcessCGMStartJoinStop: querying for last uploaded entry for %s" % eventtype) + _last_upload = self.nightscout.last_uploaded_entry(eventtype, time_start=time_start, time_end=time_end) + _last_upload_time = None + if _last_upload: + _last_upload_time = arrow.get(_last_upload["created_at"]) + + if not last_upload_time: + last_upload = _last_upload + last_upload_time = _last_upload_time + elif _last_upload_time > last_upload_time: + last_upload = _last_upload + last_upload_time = _last_upload_time + logger.info("ProcessCGMStartJoinStop: Last Nightscout %s upload: %s" % (eventtype, _last_upload_time)) + logger.info("ProcessCGMStartJoinStop: Overall last Nightscout upload: %s %s" % (last_upload_time, last_upload)) allEvents = [] for event in sorted(events, key=lambda x: x.eventTimestamp):