summaryrefslogtreecommitdiffstats
path: root/glucometerutils/drivers/accuchek_reports.py
diff options
context:
space:
mode:
Diffstat (limited to 'glucometerutils/drivers/accuchek_reports.py')
-rw-r--r--glucometerutils/drivers/accuchek_reports.py73
1 files changed, 36 insertions, 37 deletions
diff --git a/glucometerutils/drivers/accuchek_reports.py b/glucometerutils/drivers/accuchek_reports.py
index 06b69bc..c4d7527 100644
--- a/glucometerutils/drivers/accuchek_reports.py
+++ b/glucometerutils/drivers/accuchek_reports.py
@@ -19,45 +19,46 @@ import datetime
import glob
import os
-from glucometerutils import common
-from glucometerutils import exceptions
+from glucometerutils import common, exceptions
from glucometerutils.support import driver_base
_UNIT_MAP = {
- 'mmol/l': common.Unit.MMOL_L,
- 'mg/dl': common.Unit.MG_DL,
+ "mmol/l": common.Unit.MMOL_L,
+ "mg/dl": common.Unit.MG_DL,
}
-_DATE_CSV_KEY = 'Date'
-_TIME_CSV_KEY = 'Time'
-_RESULT_CSV_KEY = 'Result'
-_UNIT_CSV_KEY = 'Unit'
-_TEMPWARNING_CSV_KEY = 'Temperature warning' # ignored
-_OUTRANGE_CSV_KEY = 'Out of target range' # ignored
-_OTHER_CSV_KEY = 'Other' # ignored
-_BEFORE_MEAL_CSV_KEY = 'Before meal'
-_AFTER_MEAL_CSV_KEY = 'After meal'
+_DATE_CSV_KEY = "Date"
+_TIME_CSV_KEY = "Time"
+_RESULT_CSV_KEY = "Result"
+_UNIT_CSV_KEY = "Unit"
+_TEMPWARNING_CSV_KEY = "Temperature warning" # ignored
+_OUTRANGE_CSV_KEY = "Out of target range" # ignored
+_OTHER_CSV_KEY = "Other" # ignored
+_BEFORE_MEAL_CSV_KEY = "Before meal"
+_AFTER_MEAL_CSV_KEY = "After meal"
# Control test has extra whitespace which is not ignored.
-_CONTROL_CSV_KEY = 'Control test' + ' '*197
+_CONTROL_CSV_KEY = "Control test" + " " * 197
-_DATE_FORMAT = '%d.%m.%Y'
-_TIME_FORMAT = '%H:%M'
+_DATE_FORMAT = "%d.%m.%Y"
+_TIME_FORMAT = "%H:%M"
-_DATETIME_FORMAT = ' '.join((_DATE_FORMAT, _TIME_FORMAT))
+_DATETIME_FORMAT = " ".join((_DATE_FORMAT, _TIME_FORMAT))
class Device(driver_base.GlucometerDriver):
def __init__(self, device):
if not device or not os.path.isdir(device):
raise exceptions.CommandLineError(
- '--device parameter is required, should point to mount path '
- 'for the meter.')
+ "--device parameter is required, should point to mount path "
+ "for the meter."
+ )
- reports_path = os.path.join(device, '*', 'Reports', '*.csv')
+ reports_path = os.path.join(device, "*", "Reports", "*.csv")
report_files = glob.glob(reports_path)
if not report_files:
raise exceptions.ConnectionFailed(
- 'No report file found in path "%s".' % reports_path)
+ 'No report file found in path "%s".' % reports_path
+ )
self.report_file = report_files[0]
@@ -68,35 +69,32 @@ class Device(driver_base.GlucometerDriver):
next(self.report)
return csv.DictReader(
- self.report,
- delimiter=';',
- skipinitialspace=True,
- quoting=csv.QUOTE_NONE)
+ self.report, delimiter=";", skipinitialspace=True, quoting=csv.QUOTE_NONE
+ )
def connect(self):
- self.report = open(
- self.report_file, 'r', newline='\r\n', encoding='utf-8')
+ self.report = open(self.report_file, "r", newline="\r\n", encoding="utf-8")
def disconnect(self):
self.report.close()
def get_meter_info(self):
return common.MeterInfo(
- '%s glucometer' % self.get_model(),
+ "%s glucometer" % self.get_model(),
serial_number=self.get_serial_number(),
- native_unit=self.get_glucose_unit())
+ native_unit=self.get_glucose_unit(),
+ )
def get_model(self):
# $device/MODEL/Reports/*.csv
- return os.path.basename(
- os.path.dirname(os.path.dirname(self.report_file)))
+ return os.path.basename(os.path.dirname(os.path.dirname(self.report_file)))
def get_serial_number(self):
self.report.seek(0)
# ignore the first line.
next(self.report)
# The second line of the CSV is serial-no;report-date;report-time;;;;;;;
- return next(self.report).split(';')[0]
+ return next(self.report).split(";")[0]
def get_glucose_unit(self):
# Get the first record available and parse that.
@@ -115,13 +113,12 @@ class Device(driver_base.GlucometerDriver):
def _extract_datetime(self, record): # pylint: disable=no-self-use
# Date and time are in separate column, but we want to parse them
# together.
- date_and_time = ' '.join((record[_DATE_CSV_KEY], record[_TIME_CSV_KEY]))
+ date_and_time = " ".join((record[_DATE_CSV_KEY], record[_TIME_CSV_KEY]))
return datetime.datetime.strptime(date_and_time, _DATETIME_FORMAT)
def _extract_meal(self, record): # pylint: disable=no-self-use
if record[_AFTER_MEAL_CSV_KEY] and record[_BEFORE_MEAL_CSV_KEY]:
- raise exceptions.InvalidResponse(
- 'Reading cannot be before and after meal.')
+ raise exceptions.InvalidResponse("Reading cannot be before and after meal.")
elif record[_AFTER_MEAL_CSV_KEY]:
return common.Meal.AFTER
elif record[_BEFORE_MEAL_CSV_KEY]:
@@ -139,5 +136,7 @@ class Device(driver_base.GlucometerDriver):
common.convert_glucose_unit(
float(record[_RESULT_CSV_KEY]),
_UNIT_MAP[record[_UNIT_CSV_KEY]],
- common.Unit.MG_DL),
- meal=self._extract_meal(record))
+ common.Unit.MG_DL,
+ ),
+ meal=self._extract_meal(record),
+ )