summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-12-28 13:15:38 +0100
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-12-28 14:12:12 +0100
commit3be9661b16b31e13bf974fde9bd67c1ec28be7f6 (patch)
tree51b41c558a4eda04543bb6f514149b1f2c01e284
parentUse Python3 Enum class for meal flags. (diff)
downloadglucometerutils-3be9661b16b31e13bf974fde9bd67c1ec28be7f6.tar
glucometerutils-3be9661b16b31e13bf974fde9bd67c1ec28be7f6.tar.gz
glucometerutils-3be9661b16b31e13bf974fde9bd67c1ec28be7f6.tar.bz2
glucometerutils-3be9661b16b31e13bf974fde9bd67c1ec28be7f6.tar.lz
glucometerutils-3be9661b16b31e13bf974fde9bd67c1ec28be7f6.tar.xz
glucometerutils-3be9661b16b31e13bf974fde9bd67c1ec28be7f6.tar.zst
glucometerutils-3be9661b16b31e13bf974fde9bd67c1ec28be7f6.zip
-rw-r--r--glucometerutils/common.py13
-rw-r--r--glucometerutils/drivers/fslibre.py8
2 files changed, 11 insertions, 10 deletions
diff --git a/glucometerutils/common.py b/glucometerutils/common.py
index 4c6e115..31584b4 100644
--- a/glucometerutils/common.py
+++ b/glucometerutils/common.py
@@ -23,8 +23,9 @@ class Meal(enum.Enum):
AFTER = 'After Meal'
# Constants for measure method
-BLOOD_SAMPLE = 'blood sample'
-CGM = 'CGM' # Continuous Glucose Monitoring
+class MeasurementMethod(enum.Enum):
+ BLOOD_SAMPLE = 'blood sample'
+ CGM = 'CGM' # Continuous Glucose Monitoring
def convert_glucose_unit(value, from_unit, to_unit=None):
@@ -54,7 +55,7 @@ _ReadingBase = collections.namedtuple(
class GlucoseReading(_ReadingBase):
def __new__(cls, timestamp, value, meal=Meal.NONE, comment='',
- measure_method=BLOOD_SAMPLE):
+ measure_method=MeasurementMethod.BLOOD_SAMPLE):
"""Constructor for the glucose reading object.
Args:
@@ -87,7 +88,7 @@ class GlucoseReading(_ReadingBase):
"""Returns the reading as a formatted comma-separated value string."""
return '"%s","%.2f","%s","%s","%s"' % (
self.timestamp, self.get_value_as(unit), self.meal.value,
- self.measure_method, self.comment)
+ self.measure_method.value, self.comment)
class KetoneReading(_ReadingBase):
def __new__(cls, timestamp, value, comment='', **kwargs):
@@ -104,7 +105,7 @@ class KetoneReading(_ReadingBase):
"""
return super(KetoneReading, cls).__new__(
cls, timestamp=timestamp, value=value, comment=comment,
- measure_method=BLOOD_SAMPLE)
+ measure_method=MeasurementMethod.BLOOD_SAMPLE)
def get_value_as(self, *args):
"""Returns the reading value in mmol/L."""
@@ -113,7 +114,7 @@ class KetoneReading(_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.measure_method,
+ self.timestamp, self.get_value_as(unit), self.measure_method.value,
self.comment)
diff --git a/glucometerutils/drivers/fslibre.py b/glucometerutils/drivers/fslibre.py
index 52632b3..6e3988c 100644
--- a/glucometerutils/drivers/fslibre.py
+++ b/glucometerutils/drivers/fslibre.py
@@ -126,17 +126,17 @@ def _parse_arresult(record):
if parsed_record['reading-type'] == 2:
comment_parts.append('(Scan)')
- measure_method = common.CGM
+ measure_method = common.MeasurementMethod.CGM
cls = common.GlucoseReading
value = parsed_record['value']
elif parsed_record['reading-type'] == 0:
comment_parts.append('(Blood)')
- measure_method = common.BLOOD_SAMPLE
+ measure_method = common.MeasurementMethod.BLOOD_SAMPLE
cls = common.GlucoseReading
value = parsed_record['value']
elif parsed_record['reading-type'] == 1:
comment_parts.append('(Ketone)')
- measure_method = common.BLOOD_SAMPLE
+ measure_method = common.MeasurementMethod.BLOOD_SAMPLE
cls = common.KetoneReading
# automatically convert the raw value in mmol/L
value = _convert_ketone_unit(parsed_record['value'])
@@ -226,7 +226,7 @@ class Device(freestyle.FreeStyleHidDevice):
_extract_timestamp(parsed_record),
parsed_record['value'],
comment='(Sensor)',
- measure_method=common.CGM)
+ measure_method=common.MeasurementMethod.CGM)
# Then get the results of explicit scans and blood tests (and other
# events).