pump-history-stats.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import json
  2. import sys
  3. def main():
  4. pump_history = json.loads(sys.stdin.read())
  5. bolus_total = 0.0
  6. rate_total = 0.0
  7. duration_total = 0.0
  8. smb_count = 0
  9. bolus_count = 0
  10. temp_basal_count = 0
  11. suspend_count = 0
  12. resume_count = 0
  13. for event in pump_history:
  14. if 'amount' in event:
  15. bolus_total += event['amount']
  16. if event.get('isSMB', False):
  17. smb_count += 1
  18. bolus_count += 1
  19. if 'rate' in event:
  20. rate_total += event['rate']
  21. temp_basal_count += 1
  22. if 'duration (min)' in event:
  23. duration_total += event['duration (min)']
  24. if event['_type'] == 'PumpSuspend':
  25. suspend_count += 1
  26. if event['_type'] == 'PumpResume':
  27. resume_count += 1
  28. print(f'bolus_total: {bolus_total}')
  29. print(f'rate_total: {rate_total}')
  30. print(f'duration_total: {duration_total}')
  31. print(f'smb_count: {smb_count}')
  32. print(f'bolus_count: {bolus_count}')
  33. print(f'temp_basal_count: {temp_basal_count}')
  34. print(f'suspend_count: {suspend_count}')
  35. print(f'resume_count: {resume_count}')
  36. if __name__ == '__main__':
  37. main()