Skip to content

Instantly share code, notes, and snippets.

@elnjensen
Created February 16, 2020 02:20
Show Gist options
  • Save elnjensen/f8d56ac09ae7fe67bc1387e0f60fa16d to your computer and use it in GitHub Desktop.
Save elnjensen/f8d56ac09ae7fe67bc1387e0f60fa16d to your computer and use it in GitHub Desktop.
Simple notebook to print Loop app settings in text form from an issue report
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Printing Loop settings from an Issue Report\n",
"\n",
"This code makes use of the [Loop report parser](https://github.com/tidepool-org/data-analytics/tree/master/projects/parsers) from Tidepool to generate a simple plain-text view of the key settings from the Loop app, as stored in an Issue Report from Loop. "
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from loop_report import LoopReport\n",
"import time"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"UNHANDLED SECTION: ## Transmitter\n",
"\n",
"UNHANDLED SECTION: ## BluetoothManager\n",
"\n",
"UNHANDLED SECTION: ## PeripheralManager\n",
"\n",
"UNHANDLED SECTION: ### Activity log\n",
"\n",
"UNHANDLED SECTION: ## StandardRetrospectiveCorrection\n",
"\n"
]
}
],
"source": [
"filename = 'Loop Report 2020-02-15 194820-0500.md'\n",
"# Directory where report file is:\n",
"path = '.'\n",
"\n",
"lr = LoopReport()\n",
"loop_dict = lr.parse_by_file(path, filename)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"def parse_schedule(sched, unit):\n",
" '''Take one of the schedules from the loop report and format \n",
" as a string. Returns the formatted string. The loop report\n",
" parser returns these as a list of two-item dictionaries with keys\n",
" 'value' and 'startTime', the latter in seconds since midnight. \n",
" '''\n",
" \n",
" # Change this as desired for cosmetics: \n",
" indent = ' '\n",
" schedule_string = ''\n",
" for i in range(len(sched)):\n",
" # In some of the dictionaries this is a float, but in some a\n",
" # string, so convert to be safe: \n",
" secs = float(sched[i]['startTime'])\n",
" time_string = time.strftime('%H:%M', time.gmtime(secs))\n",
" v = sched[i]['value']\n",
" if isinstance(v, list):\n",
" value_string = '{}–{}'.format(v[0], v[1])\n",
" else: \n",
" value_string = v\n",
" schedule_string += \"{}{}: {} {}\\n\".format(indent, \n",
" time_string, \n",
" value_string, \n",
" unit)\n",
" return schedule_string\n",
" \n",
" "
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Settings from file Loop Report 2020-02-15 194820-0500.md\n",
"\n",
"Basal rates: \n",
"\n",
" 00:00: 0.45 U/hr\n",
" 01:00: 0.55 U/hr\n",
" 03:00: 0.6 U/hr\n",
" 05:00: 0.65 U/hr\n",
" 06:00: 0.65 U/hr\n",
" 09:00: 0.75 U/hr\n",
" 14:00: 0.5 U/hr\n",
" 19:00: 0.3 U/hr\n",
" 22:00: 0.35 U/hr\n",
"\n",
"Carb ratios: \n",
"\n",
" 00:00: 10.0 g\n",
" 06:00: 11.0 g\n",
" 11:30: 10.0 g\n",
" 18:00: 9.0 g\n",
" 20:30: 10.0 g\n",
"\n",
"Insulin sensitivities: \n",
"\n",
" 00:00: 78.0 mg/dL\n",
" 06:30: 82.0 mg/dL\n",
" 21:00: 78.0 mg/dL\n",
"\n",
"Glucose target ranges: \n",
" 00:00: 90.0–90.0 mg/dL\n",
"\n",
"Suspend threshold: 70.0 mg/dL\n",
"\n",
"Insulin model: fiasp\n",
"Insulin duration: 6.0 hrs\n",
"\n",
"Maximum basal rate: 3.5 U/hr\n",
"Maximum bolus: 5.0 U\n"
]
}
],
"source": [
"print(\"Settings from file {}\\n\".format(filename))\n",
"print(\"Basal rates: \\n\")\n",
"print(parse_schedule(loop_dict['basal_rate_schedule'], 'U/hr'))\n",
"print(\"Carb ratios: \\n\")\n",
"print(parse_schedule(loop_dict['carb_ratio_schedule'], loop_dict['carb_ratio_unit']))\n",
"print(\"Insulin sensitivities: \\n\")\n",
"print(parse_schedule(loop_dict['insulin_sensitivity_factor_schedule'], \n",
" loop_dict['insulin_sensitivity_factor_unit']))\n",
"\n",
"# Doesn't seem to be a unit specified separately for this:\n",
"print(\"Glucose target ranges: \")\n",
"print(parse_schedule(loop_dict['correction_range_schedule'], \n",
" loop_dict['suspend_threshold_unit']))\n",
"\n",
"print(\"Suspend threshold: {} {}\\n\".format(loop_dict['suspend_threshold'],\n",
" loop_dict['suspend_threshold_unit']))\n",
"\n",
"print(\"Insulin model: {}\".format(loop_dict['insulin_model']))\n",
"print(\"Insulin duration: {:0.1f} hrs\\n\".format(loop_dict['insulin_action_duration']/3600.))\n",
"\n",
"print(\"Maximum basal rate: {} U/hr\".format(loop_dict['maximum_basal_rate']))\n",
"print(\"Maximum bolus: {} U\".format(loop_dict['maximum_bolus']))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment