-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
in-progress: support BOLUS_BG and CGM features.
BOLUS_BG will add BG readings which are associated with boluses on the pump into the Nightscout treatment object. It will determine whether the BG reading was automatically filled via the Dexcom connection on the pump or was manually entered by seeing if the BG reading matches the current CGM reading as known to the pump at that time. Support for this is nearly complete. CGM will add Dexcom CGM readings from the pump to Nightscout as SGV (sensor glucose value) entries. This should only be used in a situation where xDrip is not used and the pump connection to the CGM will be the only source of CGM data to Nightscout. This requires additional testing before it should be considered ready. Both options are hidden behind the ENABLE_TESTING_MODES=true environment variable. Run tconnectsync with this environment variable and BOLUS_BG and CGM will be usable with the --features argument.
- Loading branch information
Showing
12 changed files
with
493 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import json | ||
import arrow | ||
import logging | ||
|
||
from ..parser.tconnect import TConnectEntry | ||
from ..parser.nightscout import NightscoutEntry | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
def process_cgm_events(readingData): | ||
data = [] | ||
for r in readingData: | ||
data.append(TConnectEntry.parse_reading_entry(r)) | ||
|
||
return data | ||
|
||
""" | ||
Given reading data and a time, finds the BG reading event which would have | ||
been the current one at that time. e.g., it looks before the given time, | ||
not after. | ||
This is a heuristic for checking whether the BG component of a bolus was | ||
manually entered or inferred based on the pump's CGM. | ||
""" | ||
def find_event_at(cgmEvents, find_time): | ||
find_t = arrow.get(find_time) | ||
events = list(map(lambda x: (arrow.get(x["time"]), x), cgmEvents)) | ||
events.sort() | ||
|
||
closestReading = None | ||
for t, r in events: | ||
if t > find_t: | ||
break | ||
closestReading = r | ||
|
||
|
||
return closestReading | ||
|
||
|
||
""" | ||
Given processed CGM data, adds reading entries to Nightscout. | ||
""" | ||
def ns_write_cgm_events(nightscout, cgmEvents, pretend=False): | ||
logger.debug("ns_write_cgm_events: querying for last uploaded entry") | ||
last_upload = nightscout.last_uploaded_bg_entry() | ||
last_upload_time = None | ||
if last_upload: | ||
last_upload_time = arrow.get(last_upload["dateString"]) | ||
logger.info("Last Nightscout CGM upload: %s" % last_upload_time) | ||
|
||
add_count = 0 | ||
for event in cgmEvents: | ||
created_at = event["time"] | ||
if last_upload_time and arrow.get(created_at) <= last_upload_time: | ||
if pretend: | ||
logger.info("Skipping CGM event before last upload time: %s" % event) | ||
continue | ||
|
||
entry = NightscoutEntry.entry( | ||
sgv=event["bg"], | ||
created_at=created_at | ||
) | ||
|
||
add_count += 1 | ||
|
||
logger.info(" Processing cgm reading: %s entry: %s" % (event, entry)) | ||
if not pretend: | ||
nightscout.upload_entry(entry, entity='entries') | ||
|
||
return add_count |
Oops, something went wrong.