diff options
author | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2013-12-11 20:56:09 +0100 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2013-12-11 20:56:09 +0100 |
commit | ad762c96b75e7ab2a6773e94f305c928e13e87e1 (patch) | |
tree | 2984c9cee9d3f1269d8e966fac13ce34c8bf11e5 | |
parent | Change all the internal representations to mg/dL for compatibility with LifeScan. (diff) | |
download | glucometerutils-ad762c96b75e7ab2a6773e94f305c928e13e87e1.tar glucometerutils-ad762c96b75e7ab2a6773e94f305c928e13e87e1.tar.gz glucometerutils-ad762c96b75e7ab2a6773e94f305c928e13e87e1.tar.bz2 glucometerutils-ad762c96b75e7ab2a6773e94f305c928e13e87e1.tar.lz glucometerutils-ad762c96b75e7ab2a6773e94f305c928e13e87e1.tar.xz glucometerutils-ad762c96b75e7ab2a6773e94f305c928e13e87e1.tar.zst glucometerutils-ad762c96b75e7ab2a6773e94f305c928e13e87e1.zip |
-rwxr-xr-x | glucometer.py | 12 | ||||
-rw-r--r-- | glucometerutils/common.py | 12 |
2 files changed, 18 insertions, 6 deletions
diff --git a/glucometer.py b/glucometer.py index 6ca2cf3..5e05a77 100755 --- a/glucometer.py +++ b/glucometer.py @@ -38,6 +38,10 @@ def main(): parser_dump.add_argument( '--unit', action='store', choices=common.VALID_UNITS, help='Select the unit to use for the dumped data.') + parser_dump.add_argument( + '--sort-by', action='store', default='timestamp', + choices=common.Reading._fields, + help='Field to order the dumped data by.') parser_date = subparsers.add_parser( 'datetime', help='Reads or sets the date and time of the glucometer.') @@ -58,7 +62,13 @@ def main(): if unit is None: unit = device.get_glucose_unit() - for reading in device.get_readings(): + readings = device.get_readings() + + if args.sort_by is not None: + readings = sorted( + readings, key=lambda reading: getattr(reading, args.sort_by)) + + for reading in readings: print('"%s","%.2f","%s","%s"' % ( reading.timestamp, reading.get_value_as(unit), reading.meal, reading.comment)) diff --git a/glucometerutils/common.py b/glucometerutils/common.py index 797fc6e..825dea1 100644 --- a/glucometerutils/common.py +++ b/glucometerutils/common.py @@ -6,6 +6,8 @@ __email__ = 'flameeyes@flameeyes.eu' __copyright__ = 'Copyright © 2013, Diego Elio Pettenò' __license__ = 'MIT' +import collections + # Constants for units UNIT_MGDL = 'mg/dL' UNIT_MMOLL = 'mmol/L' @@ -48,8 +50,10 @@ def convert_glucose_unit(value, from_unit, to_unit=None): else: return round(value * 18.0, 0) +_ReadingBase = collections.namedtuple( + '_ReadingBase', ['timestamp', 'value', 'meal', 'comment']) -class Reading(object): +class Reading(_ReadingBase): def __init__(self, timestamp, value, meal='', comment=''): """Constructor for the reading object. @@ -63,10 +67,8 @@ class Reading(object): because at least most of the LifeScan devices report the raw data in this format. """ - self.timestamp = timestamp - self.value = value - self.meal = meal - self.comment = comment + super(Reading, self).__init__( + timestamp=timestamp, value=value, meal=meal, comment=comment) def get_value_as(self, to_unit): """Returns the reading value as the given unit. |