Skip to content

Commit

Permalink
Oref0 determine basal arg parsing cleanup (openaps#1119)
Browse files Browse the repository at this point in the history
* Update to cleanup oref0-determine-basal.js argument processing.

* Fix syntax error.

* fixed spelling error.

* Fix null dereference error.

* Fixed more null dereferences.

* Check for too many arguments.

* Removed determine-basal device and associated reports.

* Removed invalid determine-basal report from setup.

* Remove setup for enact/suggested.json report that no longer functions.

* Modify oref0-determine-basal test to account for argument changes.
  • Loading branch information
jpcunningh authored and scottleibrand committed Oct 7, 2018
1 parent b29e55d commit 26b9b8f
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 106 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ Valid commands:
oref0 ifttt-notify
oref0 get-profile
oref0 calculate-iob
oref0 determine-basal
oref0 help - this message
```

Expand Down
63 changes: 26 additions & 37 deletions bin/oref0-determine-basal.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,81 +20,70 @@ var determine_basal = require('../lib/determine-basal/determine-basal');
/* istanbul ignore next */
if (!module.parent) {
var argv = require('yargs')
.usage("$0 iob.json currenttemp.json glucose.json profile.json [[--auto-sens] autosens.json] [meal.json] [--reservoir reservoir.json] --currentTime [currentTime]")
.usage("$0 <iob.json> <currenttemp.json> <glucose.json> <profile.json> [--auto-sens <autosens.json>] [--meal <meal.json>] [--reservoir <reservoir.json>] [--currentTime <currentTime>]")
.option('auto-sens', {
alias: 'a',
nargs: 1,
describe: "Auto-sensitivity configuration",
default: true

default: false
})
.option('currentTime', {
alias: 'c',
nargs: 1,
describe: "Override current time (for R&D only - disables safety checks)",
default: false

})
.option('reservoir', {
alias: 'r',
nargs: 1,
describe: "Reservoir status file for SuperMicroBolus mode (oref1)",
default: false

})
.option('meal', {
alias: 'm',
nargs: 1,
describe: "json doc describing meals",
default: true

default: false
})
.option('missing-auto-sens-ok', {
describe: "If auto-sens data is missing, try anyway.",
boolean: true,
default: true

})
.option('missing-meal-ok', {
describe: "If meal data is missing, try anyway.",
boolean: true,
default: true

})
.option('microbolus', {
describe: "Enable SuperMicroBolus mode (oref1)",
boolean: true,
default: false

})
// error and show help if some other args given
.demand(4)
.strict(true)
.help('help')
;
function usage ( ) {
argv.showHelp( );
}

var params = argv.argv;
var inputs = params._;
var errors = [ ];
var warnings = [ ];

var iob_input = params._[0];
if ([null, '--help', '-h', 'help'].indexOf(iob_input) > 0) {

usage( );
process.exit(0)
}
var currenttemp_input = params._[1];
var glucose_input = params._[2];
var profile_input = params._[3];
var meal_input = params._[4];
var autosens_input = params.autoSens;
if (params._.length > 5) {
autosens_input = params.autoSens ? params._[4] : false;
meal_input = params._[5];
}
if (params.meal && params.meal !== true && !meal_input) {
meal_input = params.meal;
if (inputs.length > 4) {
argv.showHelp( );
console.error('Too many arguments');
process.exit(1);
}
var reservoir_input = params.reservoir;

if (!iob_input || !currenttemp_input || !glucose_input || !profile_input) {
usage( );
process.exit(1);
}
var iob_input = inputs[0];
var currenttemp_input = inputs[1];
var glucose_input = inputs[2];
var profile_input = inputs[3];
var meal_input = params.meal;
var autosens_input = params['auto-sens'];
var reservoir_input = params.reservoir;

var fs = require('fs');
try {
Expand All @@ -116,12 +105,12 @@ if (!module.parent) {
//printing microbolus before attempting check
//console.error("Microbolus var is currently set to: ",params['microbolus']);

if (params['microbolus']) {
if (params.microbolus) {
if (fs.existsSync("autotune")) {
console.error("Autotune exists! Hoorah! You can use microbolus-related features.")
} else {
console.error("Warning: Autotune has not been run. All microboluses will be disabled until you manually run autotune or add it to run nightly in your loop.");
params['microbolus'] = false;
params.microbolus = false;
//console.error("Microbolus var is currently set to: ",params['microbolus']);
}
}
Expand Down
4 changes: 2 additions & 2 deletions bin/oref0-pump-loop.sh
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,9 @@ function smb_suggest {
function determine_basal {
cat monitor/meal.json
if ( grep -q 12 settings/model.json ); then
oref0-determine-basal monitor/iob.json monitor/temp_basal.json monitor/glucose.json settings/profile.json settings/autosens.json monitor/meal.json --reservoir monitor/reservoir.json > enact/smb-suggested.json
oref0-determine-basal monitor/iob.json monitor/temp_basal.json monitor/glucose.json settings/profile.json --auto-sens settings/autosens.json --meal monitor/meal.json --reservoir monitor/reservoir.json > enact/smb-suggested.json
else
oref0-determine-basal monitor/iob.json monitor/temp_basal.json monitor/glucose.json settings/profile.json settings/autosens.json monitor/meal.json --microbolus --reservoir monitor/reservoir.json > enact/smb-suggested.json
oref0-determine-basal monitor/iob.json monitor/temp_basal.json monitor/glucose.json settings/profile.json --auto-sens settings/autosens.json --meal monitor/meal.json --microbolus --reservoir monitor/reservoir.json > enact/smb-suggested.json
fi
cp -up enact/smb-suggested.json enact/suggested.json
}
Expand Down
2 changes: 0 additions & 2 deletions bin/oref0-setup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -1132,8 +1132,6 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
do_openaps_import $HOME/src/oref0/lib/oref0-setup/pancreabble.json
sudo cp $HOME/src/oref0/lib/oref0-setup/pancreoptions.json $directory/pancreoptions.json
fi
echo Running: openaps report add enact/suggested.json text determine-basal shell monitor/iob.json monitor/temp_basal.json monitor/glucose.json settings/profile.json settings/autosens.json monitor/meal.json
openaps report add enact/suggested.json text determine-basal shell monitor/iob.json monitor/temp_basal.json monitor/glucose.json settings/profile.json settings/autosens.json monitor/meal.json

if is_edison; then
sudo apt-get -y -t jessie-backports install jq
Expand Down
1 change: 0 additions & 1 deletion bin/oref0.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ Valid commands:
oref0 get-profile
oref0 calculate-iob
oref0 meal
oref0 determine-basal
oref0 export-loop [backup-loop.json] - Print a backup json representation of
entire configuration. Optionally, if a
filename is specified, listing is
Expand Down
2 changes: 1 addition & 1 deletion examples/example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

oref0-calculate-iob pumphistory.json profile.json clock.json autosens.json > iob.json
oref0-meal pumphistory.json profile.json clock.json glucose.json basal_profile.json carbhistory.json > meal.json
oref0-determine-basal iob.json temp_basal.json glucose.json profile.json autosens.json meal.json --microbolus --currentTime 1527924300000 > suggested.json
oref0-determine-basal iob.json temp_basal.json glucose.json profile.json --auto-sens autosens.json --meal meal.json --microbolus --currentTime 1527924300000 > suggested.json
cat suggested.json | jq -C -c '. | del(.predBGs) | del(.reason)'
cat suggested.json | jq -C -c .reason
cat suggested.json | jq -C -c .predBGs
6 changes: 3 additions & 3 deletions lib/determine-basal/determine-basal.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
sensitivityRatio = Math.min(sensitivityRatio, profile.autosens_max);
sensitivityRatio = round(sensitivityRatio,2);
process.stderr.write("Sensitivity ratio set to "+sensitivityRatio+" based on temp target of "+target_bg+"; ");
} else if (typeof autosens_data !== 'undefined' ) {
} else if (typeof autosens_data !== 'undefined' && autosens_data) {
sensitivityRatio = autosens_data.ratio;
process.stderr.write("Autosens ratio: "+sensitivityRatio+"; ");
}
Expand All @@ -166,7 +166,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
// adjust min, max, and target BG for sensitivity, such that 50% increase in ISF raises target from 100 to 120
if (profile.temptargetSet) {
//process.stderr.write("Temp Target set, not adjusting with autosens; ");
} else if (typeof autosens_data !== 'undefined' ) {
} else if (typeof autosens_data !== 'undefined' && autosens_data) {
if ( profile.sensitivity_raises_target && autosens_data.ratio < 1 || profile.resistance_lowers_target && autosens_data.ratio > 1 ) {
// with a target of 100, default 0.7-1.2 autosens min/max range would allow a 93-117 target range
min_bg = round((min_bg - 60) / autosens_data.ratio) + 60;
Expand Down Expand Up @@ -213,7 +213,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_

var profile_sens = round(profile.sens,1)
var sens = profile.sens;
if (typeof autosens_data !== 'undefined' ) {
if (typeof autosens_data !== 'undefined' && autosens_data) {
sens = profile.sens / sensitivityRatio;
sens = round(sens, 1);
if (sens != profile_sens) {
Expand Down
13 changes: 0 additions & 13 deletions lib/oref0-setup/device.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,6 @@
"extra": "detect-sensitivity.ini"
}
},
{
"determine-basal": {
"vendor": "openaps.vendors.process",
"extra": "determine-basal.ini"
},
"type": "device",
"name": "determine-basal",
"extra": {
"fields": "iob temp_basal glucose profile",
"cmd": "oref0",
"args": "determine-basal"
}
},
{
"pebble": {
"vendor": "openaps.vendors.process",
Expand Down
17 changes: 0 additions & 17 deletions lib/oref0-setup/report.json
Original file line number Diff line number Diff line change
Expand Up @@ -316,23 +316,6 @@
"type": "report",
"name": "settings/profile.json"
},
{
"type": "report",
"name": "enact/suggested.json",
"enact/suggested.json": {
"profile": "settings/profile.json",
"use": "shell",
"temp_basal": "monitor/temp_basal.json",
"reporter": "text",
"json_default": "True",
"meal": "monitor/meal.json",
"autosens": "settings/autosens.json",
"device": "determine-basal",
"remainder": "",
"iob": "monitor/iob.json",
"glucose": "monitor/glucose.json"
}
},
{
"type": "report",
"enact/enacted.json": {
Expand Down
15 changes: 0 additions & 15 deletions lib/oref0-setup/supermicrobolus.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
[
{
"enact/smb-suggested.json": {
"profile": "settings/profile.json",
"use": "shell",
"temp_basal": "monitor/temp_basal.json",
"reporter": "JSON",
"json_default": "True",
"device": "determine-basal",
"remainder": "settings/autosens.json monitor/meal.json --microbolus --reservoir monitor/reservoir.json",
"iob": "monitor/iob.json",
"glucose": "monitor/glucose.json"
},
"type": "report",
"name": "enact/smb-suggested.json"
},
{
"enact/smb-enacted.json": {
"device": "pump",
Expand Down
18 changes: 4 additions & 14 deletions tests/command-behavior.tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ test-detect-sensitivity () {
cat stderr_output | grep -q "ISF adjusted from 100 to 100" || fail_test "oref0-detect-sensitivity error: \n$ERROR_LINES"

# Make sure output has ratio
cat stdout_output | jq ".ratio" | grep -q "1" || fail_test "oref0-determine-sensitivity did not report correct sensitivity"
cat stdout_output | jq ".ratio" | grep -q "1" || fail_test "oref0-detect-sensitivity did not report correct sensitivity"

# Run detect-sensitivity with carbhistory and capture output
../bin/oref0-detect-sensitivity.js glucose.json pumphistory_zoned.json insulin_sensitivities.json basal_profile.json profile.json carbhistory.json 2>stderr_output 1>stdout_output
Expand All @@ -230,7 +230,7 @@ test-detect-sensitivity () {
cat stderr_output | grep -q "ISF adjusted from 100 to 100" || fail_test "oref0-detect-sensitivity error: \n$ERROR_LINES"

# Make sure output has ratio
cat stdout_output | jq ".ratio" | grep -q "1" || fail_test "oref0-determine-sensitivity did not report correct sensitivity"
cat stdout_output | jq ".ratio" | grep -q "1" || fail_test "oref0-detect-sensitivity did not report correct sensitivity"

# Run oref0-detect-sensitivity with carbhistory and temptargets and capture output
../bin/oref0-detect-sensitivity.js glucose.json pumphistory_zoned.json insulin_sensitivities.json basal_profile.json profile.json carbhistory.json temptargets.json 2>stderr_output 1>stdout_output
Expand All @@ -240,7 +240,7 @@ test-detect-sensitivity () {
cat stderr_output | grep -q "ISF adjusted from 100 to 100" || fail_test "oref0-detect-sensitivity error: \n$ERROR_LINES"

# Make sure output has ratio
cat stdout_output | jq ".ratio" | grep -q "1" || fail_test "oref0-determine-sensitivity did not report correct sensitivity"
cat stdout_output | jq ".ratio" | grep -q "1" || fail_test "oref0-detect-sensitivity did not report correct sensitivity"

# If we made it here, the test passed
echo "oref0-detect-sensitivites test passed"
Expand All @@ -258,7 +258,7 @@ test-determine-basal () {
cat stdout_output | jq ".reason" | grep -q "BG data is too old" || fail_test "oref0-determine-basal did not report correct reason"

# Run determine-basal with options
../bin/oref0-determine-basal.js --reservoir reservoir.json iob.json --currentTime "2018-09-05T09:44:11-05:00" temp_basal.json glucose.json --auto-sens autosens.json profile.json meal.json 2>stderr_output 1>stdout_output
../bin/oref0-determine-basal.js --reservoir reservoir.json iob.json --currentTime "2018-09-05T09:44:11-05:00" temp_basal.json glucose.json --auto-sens autosens.json profile.json --meal meal.json 2>stderr_output 1>stdout_output

# Make sure stderr output contains expected time
ERROR_LINES=$( cat stderr_output )
Expand All @@ -267,16 +267,6 @@ test-determine-basal () {
# Make sure output has reason
cat stdout_output | jq ".reason" | grep -q "BG data is too old" || fail_test "oref0-determine-basal with options did not report correct reason"

# Run determine-basal with alternate methods of arguments
../bin/oref0-determine-basal.js iob.json temp_basal.json glucose.json profile.json autosens.json meal.json 2>stderr_output 1>stdout_output

# Make sure stderr output contains expected time
ERROR_LINES=$( cat stderr_output )
cat stderr_output | jq .time | grep -q "2018-09-05T14:44:11.000Z" || fail_test "oref0-determine-basal with alternate options error: \n$ERROR_LINES"

# Make sure output has reason
cat stdout_output | jq ".reason" | grep -q "BG data is too old" || fail_test "oref0-determine-basal with alternate options did not report correct reason"

# If we made it here, the test passed
echo "oref0-determine-basal test passed"
}
Expand Down

0 comments on commit 26b9b8f

Please sign in to comment.