summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2013-12-08 00:16:34 +0100
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2013-12-08 00:16:34 +0100
commit6402d15887c24c7cf1c1e96b21c142f28c13eb9d (patch)
tree20c429184ac13143737e0c2473fff9c8f7c1d2e4
parentRead more data out of the OTUltra2 dump lines. Return data in a Reading object. (diff)
downloadglucometerutils-6402d15887c24c7cf1c1e96b21c142f28c13eb9d.tar
glucometerutils-6402d15887c24c7cf1c1e96b21c142f28c13eb9d.tar.gz
glucometerutils-6402d15887c24c7cf1c1e96b21c142f28c13eb9d.tar.bz2
glucometerutils-6402d15887c24c7cf1c1e96b21c142f28c13eb9d.tar.lz
glucometerutils-6402d15887c24c7cf1c1e96b21c142f28c13eb9d.tar.xz
glucometerutils-6402d15887c24c7cf1c1e96b21c142f28c13eb9d.tar.zst
glucometerutils-6402d15887c24c7cf1c1e96b21c142f28c13eb9d.zip
-rwxr-xr-xglucometer.py3
-rw-r--r--glucometerutils/common.py3
-rw-r--r--glucometerutils/drivers/otultra2.py32
3 files changed, 35 insertions, 3 deletions
diff --git a/glucometer.py b/glucometer.py
index facd88b..1cd0303 100755
--- a/glucometer.py
+++ b/glucometer.py
@@ -46,7 +46,8 @@ def main():
if args.action == 'dump':
for reading in device.get_readings():
- print('%s,%f' % (reading.timestamp, reading.get_value_as(args.unit)))
+ print('%s,%.2f,%s' % (reading.timestamp, reading.get_value_as(args.unit),
+ reading.comment))
elif args.action == 'datetime':
if args.set == 'now':
print(device.set_datetime())
diff --git a/glucometerutils/common.py b/glucometerutils/common.py
index a93ecf0..8e41f07 100644
--- a/glucometerutils/common.py
+++ b/glucometerutils/common.py
@@ -50,10 +50,11 @@ def convert_glucose_unit(value, from_unit, to_unit=None):
class Reading(object):
- def __init__(self, timestamp, value, unit):
+ def __init__(self, timestamp, value, unit, comment=None):
self.timestamp = timestamp
self.value = value
self.unit = unit
+ self.comment = comment or ''
def get_value_as(self, to_unit):
"""Returns the reading value as the given unit.
diff --git a/glucometerutils/drivers/otultra2.py b/glucometerutils/drivers/otultra2.py
index 4eb2eb1..1a29d36 100644
--- a/glucometerutils/drivers/otultra2.py
+++ b/glucometerutils/drivers/otultra2.py
@@ -251,9 +251,39 @@ class Device(object):
line_data = match.groupdict()
date = self._parse_datetime(line_data['datetime'])
+ meal_str = self._MEAL_CODES[line_data['meal']]
+ comment_str = self._COMMENT_CODES[line_data['comment']]
+
+ if meal_str and comment_str:
+ comment = '%s & %s' % (meal_str, comment_str)
+ else:
+ comment = meal_str or comment_str
# OneTouch2 always returns the data in mg/dL even if the
# glucometer is set to mmol/L. We need to convert it to the
# requested unit here.
yield common.Reading(date, int(line_data['value']),
- common.UNIT_MGDL)
+ common.UNIT_MGDL, comment=comment)
+
+
+ # The following two hashes are taken directly from LifeScan's documentation
+ _MEAL_CODES = {
+ 'N': '',
+ 'B': 'Before Meal',
+ 'A': 'After Meal',
+ }
+
+ _COMMENT_CODES = {
+ '00': '', # would be 'No Comment'
+ '01': 'Not Enough Food',
+ '02': 'Too Much Food',
+ '03': 'Mild Exercise',
+ '04': 'Hard Exercise',
+ '05': 'Medication',
+ '06': 'Stress',
+ '07': 'Illness',
+ '08': 'Feel Hypo',
+ '09': 'Menses',
+ '10': 'Vacation',
+ '11': 'Other',
+ }