diff options
author | Samuel Martin <s.martin49@gmail.com> | 2017-09-23 10:03:31 +0200 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2017-09-25 16:12:06 +0200 |
commit | dc7055c3062ecf6b86beee1f1a7ae54aff971101 (patch) | |
tree | 9677b2bf49bcf3d29eb9f709c95638f4fce26fed | |
parent | common: add constants for measure methods (diff) | |
download | glucometerutils-dc7055c3062ecf6b86beee1f1a7ae54aff971101.tar glucometerutils-dc7055c3062ecf6b86beee1f1a7ae54aff971101.tar.gz glucometerutils-dc7055c3062ecf6b86beee1f1a7ae54aff971101.tar.bz2 glucometerutils-dc7055c3062ecf6b86beee1f1a7ae54aff971101.tar.lz glucometerutils-dc7055c3062ecf6b86beee1f1a7ae54aff971101.tar.xz glucometerutils-dc7055c3062ecf6b86beee1f1a7ae54aff971101.tar.zst glucometerutils-dc7055c3062ecf6b86beee1f1a7ae54aff971101.zip |
-rw-r--r-- | glucometerutils/common.py | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/glucometerutils/common.py b/glucometerutils/common.py index 4088091..0fcda80 100644 --- a/glucometerutils/common.py +++ b/glucometerutils/common.py @@ -57,24 +57,28 @@ def convert_glucose_unit(value, from_unit, to_unit=None): return round(value * 18.0, 0) _ReadingBase = collections.namedtuple( - '_ReadingBase', ['timestamp', 'value', 'meal', 'comment']) + '_ReadingBase', ['timestamp', 'value', 'meal', 'comment', 'measure_method']) class Reading(_ReadingBase): - def __new__(cls, timestamp, value, meal=NO_MEAL, comment=''): """Constructor for the reading object. + def __new__(cls, timestamp, value, meal=NO_MEAL, comment='', + measure_method=BLOOD_SAMPLE): Args: timestamp: (datetime) Timestamp of the reading as reported by the meter. 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. + measure_method: (string) Measure method as reported by the reader if any, + assuming blood sample otherwise. 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. """ return super(Reading, cls).__new__( - cls, timestamp=timestamp, value=value, meal=meal, comment=comment) + cls, timestamp=timestamp, value=value, meal=meal, comment=comment, + measure_method=measure_method) def get_value_as(self, to_unit): """Returns the reading value as the given unit. @@ -86,8 +90,9 @@ class Reading(_ReadingBase): def as_csv(self, unit): """Returns the reading as a formatted comma-separated value string.""" - return '"%s","%.2f","%s","%s"' % ( - self.timestamp, self.get_value_as(unit), self.meal, self.comment) + return '"%s","%.2f","%s","%s","%s"' % ( + self.timestamp, self.get_value_as(unit), self.meal, self.measure_method, + self.comment) _MeterInfoBase = collections.namedtuple( |