diff options
author | Ben <b-schaefer@posteo.de> | 2019-04-11 11:44:25 +0200 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.com> | 2019-05-05 18:04:36 +0200 |
commit | 3e1ef26874dc7ec76069a0c9dd1f15fae9505bb0 (patch) | |
tree | 0df4c43810f63727ba0de1f85e6b55ad5ce15d3f | |
parent | Bug fix: incorrect argument order in call to construct.Const. (diff) | |
download | glucometerutils-3e1ef26874dc7ec76069a0c9dd1f15fae9505bb0.tar glucometerutils-3e1ef26874dc7ec76069a0c9dd1f15fae9505bb0.tar.gz glucometerutils-3e1ef26874dc7ec76069a0c9dd1f15fae9505bb0.tar.bz2 glucometerutils-3e1ef26874dc7ec76069a0c9dd1f15fae9505bb0.tar.lz glucometerutils-3e1ef26874dc7ec76069a0c9dd1f15fae9505bb0.tar.xz glucometerutils-3e1ef26874dc7ec76069a0c9dd1f15fae9505bb0.tar.zst glucometerutils-3e1ef26874dc7ec76069a0c9dd1f15fae9505bb0.zip |
Diffstat (limited to '')
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | glucometerutils/common.py | 17 | ||||
-rw-r--r-- | glucometerutils/drivers/fslibre.py | 35 |
3 files changed, 45 insertions, 9 deletions
@@ -7,3 +7,5 @@ /dist/ __pycache__/ build +.idea/ +*venv/
\ No newline at end of file diff --git a/glucometerutils/common.py b/glucometerutils/common.py index ad56b8b..f549087 100644 --- a/glucometerutils/common.py +++ b/glucometerutils/common.py @@ -28,6 +28,7 @@ class Meal(enum.Enum): class MeasurementMethod(enum.Enum): BLOOD_SAMPLE = 'blood sample' CGM = 'CGM' # Continuous Glucose Monitoring + TIME = 'time' def convert_glucose_unit(value, from_unit, to_unit): @@ -98,6 +99,22 @@ class KetoneReading: self.comment) @attr.s +class TimeAdjustment: + timestamp = attr.ib() # type: datetime.datetime + old_timestamp = attr.ib() # type: datetime.datetime + measure_method = attr.ib( + default=MeasurementMethod.TIME, + validator=attr.validators.in_( + MeasurementMethod)) # type: MeasurementMethod + + def as_csv(self, unit): + del unit + return '"%s","","%s","%s"' % ( + self.timestamp, self.measure_method.value, self.old_timestamp + ) + + +@attr.s class MeterInfo: """General information about the meter. diff --git a/glucometerutils/drivers/fslibre.py b/glucometerutils/drivers/fslibre.py index ecf6dd6..7d3e496 100644 --- a/glucometerutils/drivers/fslibre.py +++ b/glucometerutils/drivers/fslibre.py @@ -57,6 +57,15 @@ _ARRESULT_TYPE2_ENTRY_MAP = ( (28, 'errors'), ) +_ARRESULT_TYPE5_ENTRY_MAP = ( + (9, 'old_month'), + (10, 'old_day'), + (11, 'old_year'), + (12, 'old_hour'), + (13, 'old_minute'), + (14, 'old_second'), +) + # Fields only valid when rapid-acting-flag is "1" _ARRESULT_RAPID_INSULIN_ENTRY_MAP = ( (43, 'double-rapid-acting-insulin'), @@ -77,19 +86,19 @@ def _parse_record(record, entry_map): return {} -def _extract_timestamp(parsed_record): +def _extract_timestamp(parsed_record, prefix=''): """Extract the timestamp from a parsed record. This leverages the fact that all the records have the same base structure. """ return datetime.datetime( - parsed_record['year'] + 2000, - parsed_record['month'], - parsed_record['day'], - parsed_record['hour'], - parsed_record['minute'], - parsed_record['second']) + parsed_record[prefix + 'year'] + 2000, + parsed_record[prefix + 'month'], + parsed_record[prefix + 'day'], + parsed_record[prefix + 'hour'], + parsed_record[prefix + 'minute'], + parsed_record[prefix + 'second']) def _convert_ketone_unit(raw_value): @@ -110,10 +119,18 @@ def _parse_arresult(record): parsed_record = _parse_record(record, _BASE_ENTRY_MAP) # There are other record types, but we don't currently need to expose these. - if not parsed_record or parsed_record['type'] != 2: + if not parsed_record: + return None + elif parsed_record['type'] == 2: + parsed_record.update(_parse_record(record, _ARRESULT_TYPE2_ENTRY_MAP)) + elif parsed_record['type'] == 5: + parsed_record.update(_parse_record(record, _ARRESULT_TYPE5_ENTRY_MAP)) + return common.TimeAdjustment( + _extract_timestamp(parsed_record), + _extract_timestamp(parsed_record, 'old_')) + else: return None - parsed_record.update(_parse_record(record, _ARRESULT_TYPE2_ENTRY_MAP)) # Check right away if we have rapid insulin if parsed_record['rapid-acting-flag']: |