summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Martin <s.martin49@gmail.com>2017-09-23 11:35:55 +0200
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-09-25 16:12:06 +0200
commitca24a364679505bfe892a6ec1c0dde0abdf891c0 (patch)
tree29ff2637bc5b8533330db3bf82f4b49097639a53
parentfslibre: set measure_method when parsing records (diff)
downloadglucometerutils-ca24a364679505bfe892a6ec1c0dde0abdf891c0.tar
glucometerutils-ca24a364679505bfe892a6ec1c0dde0abdf891c0.tar.gz
glucometerutils-ca24a364679505bfe892a6ec1c0dde0abdf891c0.tar.bz2
glucometerutils-ca24a364679505bfe892a6ec1c0dde0abdf891c0.tar.lz
glucometerutils-ca24a364679505bfe892a6ec1c0dde0abdf891c0.tar.xz
glucometerutils-ca24a364679505bfe892a6ec1c0dde0abdf891c0.tar.zst
glucometerutils-ca24a364679505bfe892a6ec1c0dde0abdf891c0.zip
-rw-r--r--glucometerutils/drivers/fslibre.py28
1 files changed, 24 insertions, 4 deletions
diff --git a/glucometerutils/drivers/fslibre.py b/glucometerutils/drivers/fslibre.py
index c4c5365..a0f0517 100644
--- a/glucometerutils/drivers/fslibre.py
+++ b/glucometerutils/drivers/fslibre.py
@@ -45,7 +45,9 @@ _HISTORY_ENTRY_MAP = _BASE_ENTRY_MAP + (
# Fields of the results returned by $arresult? where type = 2
_ARRESULT_TYPE2_ENTRY_MAP = (
- (9, 'reading-type'), # 0 = glucose blood strip, 2 = sensor
+ (9, 'reading-type'), # 0 = glucose blood strip,
+ # 1 = ketone blood strip,
+ # 2 = glucose sensor
(12, 'value'),
(15, 'sport-flag'),
(16, 'medication-flag'),
@@ -93,6 +95,11 @@ def _extract_timestamp(parsed_record):
parsed_record['second'])
+def _convert_ketone_unit(raw_value):
+ """Convert raw ketone value as read in the device to its value in mmol/L."""
+ return int((raw_value + 1) / 2.) / 10.
+
+
def _parse_arresult(record):
"""Takes an array of string fields as input and parses it into a Reading."""
@@ -114,15 +121,27 @@ def _parse_arresult(record):
comment_parts = []
measure_method = None
+ cls = None
+ value = None
if parsed_record['reading-type'] == 2:
comment_parts.append('(Scan)')
measure_method = common.CGM
+ cls = common.GlucoseReading
+ value = parsed_record['value']
elif parsed_record['reading-type'] == 0:
comment_parts.append('(Blood)')
measure_method = common.BLOOD_SAMPLE
+ cls = common.GlucoseReading
+ value = parsed_record['value']
+ elif parsed_record['reading-type'] == 1:
+ comment_parts.append('(Ketone)')
+ measure_method = common.BLOOD_SAMPLE
+ cls = common.KetoneReading
+ # automatically convert the raw value in mmol/L
+ value = _convert_ketone_unit(parsed_record['value'])
else:
- # ketone reading
+ # unknown reading
return None
custom_comments = record[29:35]
@@ -161,9 +180,10 @@ def _parse_arresult(record):
else:
comment_parts.append('Rapid-acting insulin')
- return common.GlucoseReading(
+
+ return cls(
_extract_timestamp(parsed_record),
- parsed_record['value'],
+ value,
comment='; '.join(comment_parts),
measure_method=measure_method)