diff options
author | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2013-12-11 20:39:27 +0100 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2013-12-11 20:39:27 +0100 |
commit | 3d5618f3f81e07859861c2f3c06cc5c4e877b905 (patch) | |
tree | a7f7af21012eeff6b23ee71fa928533fe00e0657 | |
parent | glucometer.py: if no unit is provided on command line, use the default of the meter. (diff) | |
download | glucometerutils-3d5618f3f81e07859861c2f3c06cc5c4e877b905.tar glucometerutils-3d5618f3f81e07859861c2f3c06cc5c4e877b905.tar.gz glucometerutils-3d5618f3f81e07859861c2f3c06cc5c4e877b905.tar.bz2 glucometerutils-3d5618f3f81e07859861c2f3c06cc5c4e877b905.tar.lz glucometerutils-3d5618f3f81e07859861c2f3c06cc5c4e877b905.tar.xz glucometerutils-3d5618f3f81e07859861c2f3c06cc5c4e877b905.tar.zst glucometerutils-3d5618f3f81e07859861c2f3c06cc5c4e877b905.zip |
-rw-r--r-- | glucometerutils/common.py | 18 | ||||
-rw-r--r-- | glucometerutils/drivers/otultra2.py | 9 |
2 files changed, 12 insertions, 15 deletions
diff --git a/glucometerutils/common.py b/glucometerutils/common.py index 8a36d31..797fc6e 100644 --- a/glucometerutils/common.py +++ b/glucometerutils/common.py @@ -50,19 +50,21 @@ def convert_glucose_unit(value, from_unit, to_unit=None): class Reading(object): - def __init__(self, timestamp, value, unit, meal='', comment=''): + def __init__(self, timestamp, value, 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. + value: (float) Value of the reading, in mg/dL. meal: (string) Meal-relativeness as reported by the reader, if any. comment: (string) Comment reported by the reader, if any. + + The value is stored in mg/dL, even though this is not the standard value, + because at least most of the LifeScan devices report the raw data in this + format. """ self.timestamp = timestamp self.value = value - self.unit = unit self.meal = meal self.comment = comment @@ -70,10 +72,6 @@ class Reading(object): """Returns the reading value as the given unit. Args: - to_unit: either UNIT_MGDL or UNIT_MMOLL as wanted; if None, the - value as recorded will be returned. + to_unit: (UNIT_MGDL|UNIT_MMOLL) The unit to return the value to. """ - if to_unit is None: - return self.value - - return convert_glucose_unit(self.value, self.unit, to_unit) + return convert_glucose_unit(self.value, UNIT_MGDL, to_unit) diff --git a/glucometerutils/drivers/otultra2.py b/glucometerutils/drivers/otultra2.py index 296e188..1a7b794 100644 --- a/glucometerutils/drivers/otultra2.py +++ b/glucometerutils/drivers/otultra2.py @@ -283,11 +283,10 @@ class Device(object): 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, meal=meal, comment=comment) + # OneTouch2 always returns the data in mg/dL even if the glucometer is set + # to mmol/L, so there is no conversion required. + yield common.Reading( + date, float(line_data['value']), meal=meal, comment=comment) # The following two hashes are taken directly from LifeScan's documentation _MEAL_CODES = { |