diff options
author | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2013-12-11 20:27:00 +0100 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2013-12-11 20:27:00 +0100 |
commit | 11766e45449a999a15c310ab048bc98db3abf8c7 (patch) | |
tree | ab381d64634c219fb26fc2a28936a496bc11e7fc | |
parent | otultra2: expose the meal and comments as separate field in the CSV. (diff) | |
download | glucometerutils-11766e45449a999a15c310ab048bc98db3abf8c7.tar glucometerutils-11766e45449a999a15c310ab048bc98db3abf8c7.tar.gz glucometerutils-11766e45449a999a15c310ab048bc98db3abf8c7.tar.bz2 glucometerutils-11766e45449a999a15c310ab048bc98db3abf8c7.tar.lz glucometerutils-11766e45449a999a15c310ab048bc98db3abf8c7.tar.xz glucometerutils-11766e45449a999a15c310ab048bc98db3abf8c7.tar.zst glucometerutils-11766e45449a999a15c310ab048bc98db3abf8c7.zip |
Diffstat (limited to '')
-rwxr-xr-x | glucometer.py | 5 | ||||
-rw-r--r-- | glucometerutils/common.py | 14 | ||||
-rw-r--r-- | glucometerutils/drivers/otultra2.py | 7 |
3 files changed, 18 insertions, 8 deletions
diff --git a/glucometer.py b/glucometer.py index 18b7ad3..33fda46 100755 --- a/glucometer.py +++ b/glucometer.py @@ -55,8 +55,9 @@ def main(): print(device.get_information_string()) elif args.action == 'dump': for reading in device.get_readings(): - print('%s,%.2f,%s' % (reading.timestamp, reading.get_value_as(args.unit), - reading.comment)) + print('"%s","%.2f","%s","%s"' % ( + reading.timestamp, reading.get_value_as(args.unit), + reading.meal, 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 8e41f07..8a36d31 100644 --- a/glucometerutils/common.py +++ b/glucometerutils/common.py @@ -50,11 +50,21 @@ def convert_glucose_unit(value, from_unit, to_unit=None): class Reading(object): - def __init__(self, timestamp, value, unit, comment=None): + def __init__(self, timestamp, value, unit, meal='', comment=''): + """Constructor for the reading object. + + Args: + timestamp: (datetime) Timestamp of the reading as reported by the meter. + value: (float) Value of the reading in the selected unit. + unit: (UNIT_MGDL|UNIT_MMOLL) The unit for the reported reading. + meal: (string) Meal-relativeness as reported by the reader, if any. + comment: (string) Comment reported by the reader, if any. + """ self.timestamp = timestamp self.value = value self.unit = unit - self.comment = comment or '' + self.meal = meal + self.comment = comment 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 4539cc2..296e188 100644 --- a/glucometerutils/drivers/otultra2.py +++ b/glucometerutils/drivers/otultra2.py @@ -280,15 +280,14 @@ 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']] - comment = '"%s","%s"' % (meal_str, comment_str) + meal = self._MEAL_CODES[line_data['meal']] + comment = self._COMMENT_CODES[line_data['comment']] # 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, comment=comment) + common.UNIT_MGDL, meal=meal, comment=comment) # The following two hashes are taken directly from LifeScan's documentation _MEAL_CODES = { |