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

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,6 +546,7 @@ 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 = {}
if data.get('comment') is not None:
for part in data.get('comment').split('; '): for part in data.get('comment').split('; '):
relevant = rrelevant.search(part) relevant = rrelevant.search(part)
if relevant is not None: if relevant is not None:
@ -539,11 +555,10 @@ def parse_entry(data, icons, fmt='%Y-%m-%d %H:%M:%S'):
''' 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:
if int(float(cvalue)) == float(cvalue):
cvalue = int(float(cvalue)) cvalue = int(float(cvalue))
# if int(float(cvalue)) == float(cvalue) else:
# cvalue = int(float(cvalue)) cvalue = float(cvalue)
# else
# cvalue = float(cvalue)
except: except:
pass pass
cvalue = str(cvalue) cvalue = str(cvalue)
@ -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,