Changes to skip ketone measurements; optionally skip manual readings; and support decimal figures in insulin and food doses.

This commit is contained in:
Timothy Allen 2018-03-15 22:27:16 +02:00
parent b46b8b1eae
commit 5ec4b75d18
1 changed files with 46 additions and 28 deletions

View File

@ -79,6 +79,21 @@ def main():
with open(args.input_file, 'r', newline='') as f: with open(args.input_file, 'r', newline='') as f:
rows = from_csv(f) rows = from_csv(f)
''' Skip ketone entries '''
rketones = re.compile('Ketone', flags=re.IGNORECASE);
for row in rows:
if rketones.search(row.get('measure_method')):
rows.remove(row);
elif rketones.search(row.get('comment')):
rows.remove(row);
''' Skip finger stick test entries '''
rfinger = re.compile('Blood', flags=re.IGNORECASE);
if not args.fingerstick:
for row in rows:
if rfinger.search(row.get('comment')):
rows.remove(row);
for row in rows: for row in rows:
row = parse_entry(row, args.icons) row = parse_entry(row, args.icons)
@ -531,39 +546,39 @@ def parse_entry(data, icons, fmt='%Y-%m-%d %H:%M:%S'):
rrelevant = re.compile('(Food|Rapid-acting insulin|Long-acting insulin)(?: \((.*?)\))', flags=re.IGNORECASE) rrelevant = re.compile('(Food|Rapid-acting insulin|Long-acting insulin)(?: \((.*?)\))', flags=re.IGNORECASE)
rduplicate = re.compile('^(I\$\^\{\d+\S?)(\}.*)$') rduplicate = re.compile('^(I\$\^\{\d+\S?)(\}.*)$')
commentparts = {} commentparts = {}
for part in data.get('comment').split('; '): if data.get('comment') is not None:
relevant = rrelevant.search(part) for part in data.get('comment').split('; '):
if relevant is not None: relevant = rrelevant.search(part)
ctype = relevant.group(1) if relevant is not None:
cvalue = relevant.group(2) ctype = relevant.group(1)
cvalue = relevant.group(2)
''' Convert floating point-style strings (2.0) to integer-style strings (2) ''' ''' Convert floating point-style strings (2.0) to integer-style strings (2) '''
try: try:
cvalue = int(float(cvalue)) if int(float(cvalue)) == float(cvalue):
# if int(float(cvalue)) == float(cvalue) cvalue = int(float(cvalue))
# cvalue = int(float(cvalue)) else:
# else cvalue = float(cvalue)
# cvalue = float(cvalue) except:
except: pass
pass cvalue = str(cvalue)
cvalue = str(cvalue)
if re.search('Rapid', ctype) is not None: if re.search('Rapid', ctype) is not None:
cvalue += 'R' cvalue += 'R'
if re.search('Long', ctype) is not None: if re.search('Long', ctype) is not None:
cvalue += 'L' cvalue += 'L'
ctype = re.sub('Rapid-acting insulin', 'Insulin', ctype, flags=re.IGNORECASE) ctype = re.sub('Rapid-acting insulin', 'Insulin', ctype, flags=re.IGNORECASE)
ctype = re.sub('Long-acting insulin', 'Insulin', ctype, flags=re.IGNORECASE) ctype = re.sub('Long-acting insulin', 'Insulin', ctype, flags=re.IGNORECASE)
if ctype in commentparts: if ctype in commentparts:
commentparts[ctype] = commentparts[ctype] + '/' + cvalue commentparts[ctype] = commentparts[ctype] + '/' + cvalue
else: else:
commentparts[ctype] = cvalue commentparts[ctype] = cvalue
data['comment'] = commentparts data['comment'] = commentparts
else: else:
data['comment'] = {} data['comment'] = {}
''' Convert timestamp to ISO8601 (by default, at least), and store datetime object ''' ''' Convert timestamp to ISO8601 (by default, at least), and store datetime object '''
try: try:
@ -788,6 +803,9 @@ def parse_arguments():
parser.add_argument( parser.add_argument(
'--icons', action='store_true', required=False, default=True, '--icons', action='store_true', required=False, default=True,
help=('Print food and injection indicators (default: true).')) help=('Print food and injection indicators (default: true).'))
parser.add_argument(
'--fingerstick', action='store_true', required=False, default=True,
help=('Include manual finger stick results (default: true).'))
parser.add_argument( parser.add_argument(
'--units', action='store', required=False, type=str, '--units', action='store', required=False, type=str,