summaryrefslogtreecommitdiffstats
path: root/glucometerutils/common.py
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-12-28 13:10:12 +0100
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-12-28 14:12:07 +0100
commit2c9501b641f1924335833814c1d6455ef7952b66 (patch)
tree6ff21622c01c3370bbca4e1ff6f1408893729914 /glucometerutils/common.py
parentUse Python3 Enum class for glucose units. (diff)
downloadglucometerutils-2c9501b641f1924335833814c1d6455ef7952b66.tar
glucometerutils-2c9501b641f1924335833814c1d6455ef7952b66.tar.gz
glucometerutils-2c9501b641f1924335833814c1d6455ef7952b66.tar.bz2
glucometerutils-2c9501b641f1924335833814c1d6455ef7952b66.tar.lz
glucometerutils-2c9501b641f1924335833814c1d6455ef7952b66.tar.xz
glucometerutils-2c9501b641f1924335833814c1d6455ef7952b66.tar.zst
glucometerutils-2c9501b641f1924335833814c1d6455ef7952b66.zip
Diffstat (limited to 'glucometerutils/common.py')
-rw-r--r--glucometerutils/common.py13
1 files changed, 7 insertions, 6 deletions
diff --git a/glucometerutils/common.py b/glucometerutils/common.py
index 9350983..4c6e115 100644
--- a/glucometerutils/common.py
+++ b/glucometerutils/common.py
@@ -17,9 +17,10 @@ class Unit(enum.Enum):
MMOL_L = 'mmol/L'
# Constants for meal information
-NO_MEAL = ''
-BEFORE_MEAL = 'Before Meal'
-AFTER_MEAL = 'After Meal'
+class Meal(enum.Enum):
+ NONE = ''
+ BEFORE = 'Before Meal'
+ AFTER = 'After Meal'
# Constants for measure method
BLOOD_SAMPLE = 'blood sample'
@@ -52,7 +53,7 @@ _ReadingBase = collections.namedtuple(
'_ReadingBase', ['timestamp', 'value', 'comment', 'measure_method'])
class GlucoseReading(_ReadingBase):
- def __new__(cls, timestamp, value, meal=NO_MEAL, comment='',
+ def __new__(cls, timestamp, value, meal=Meal.NONE, comment='',
measure_method=BLOOD_SAMPLE):
"""Constructor for the glucose reading object.
@@ -85,8 +86,8 @@ class GlucoseReading(_ReadingBase):
def as_csv(self, unit):
"""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, self.measure_method,
- self.comment)
+ self.timestamp, self.get_value_as(unit), self.meal.value,
+ self.measure_method, self.comment)
class KetoneReading(_ReadingBase):
def __new__(cls, timestamp, value, comment='', **kwargs):