Skip to content

Commit a3f82a8

Browse files
authoredNov 12, 2017
Optimize oref0-pump-loop, and bug fixes (openaps#772)
* standardize on openaps report invoke * not-yet-tested refactoring of monitor-pump, meal.json, etc. * more refactoring for speed * redirect output to the right files * don't display full traceback on time set errors * only run refresh_ commands if we don't have new glucose data yet * remove end-of-line whitespace * update pump_loop_completed before glucose-fresh checks * reset pump clock if >55s off; better error messaging * syntax * nest ifs so we quit immediately if fresh * hide red-herring 'date: invalid date ‘@’' message * don't redirect oref0-meal stderr to meal.json * more accurate log message * show monitor/status.json if it's bolusing * allow bolus and bolus wizard timestamps to differ by 1 second * boluswizard uses current.carb_input not current.carbs * warn if Treatment carbs unclassified * profile.A52_risk_enable variable reference * don't wait_for_bg after a Warning * replace () with { ;} * use try and retry functions * retry basal_profile.json pull if it fails * Couldn't * curly braces and clearer error * syntax * exclude .pyc files from git * lots more try, move suspended check to fail function * log when Reducing insulinReq for expectedDelta * try inside smb_suggest * grammar * wait_for_bg if too old; clarify error messages * not sure how that got removed * touch pump_loop_completed to wait for a new BG * newlines * check that profile has a valid current_basal * differentiate things we can continue from if they fail * "grep: enact/smb-suggested.json: No such file or directory" is not useful * rename refresh_pumphistory_and_meal for error clarity * continuing * "grep: enact/smb-suggested.json: No such file or directory" is not useful * install ntpdate * only show reason too old if it's recent * make sure status.json is fresh before checking if it says pump is suspended * use try_return to more clearly log when ESC or bolus fails * move calculate_iob into merge_pumphistory as it requires pumphistory-merged.json * syntax
1 parent 83ff660 commit a3f82a8

9 files changed

+207
-124
lines changed
 

‎.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,5 @@ npm-debug.log
2323
bin/__pycache__
2424

2525
package-lock.json
26+
27+
*.pyc

‎bin/oref0-ns-loop.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ function ns_temptargets {
8686
cat settings/ns-temptargets.json.new | jq .[0].duration | egrep -q [0-9] && mv settings/ns-temptargets.json.new settings/ns-temptargets.json
8787
# TODO: merge local-temptargets.json with ns-temptargets.json
8888
#openaps report invoke settings/ns-temptargets.json settings/profile.json
89-
echo -n "Refreshed NS temptargets: "
89+
echo -n "Latest NS temptargets: "
9090
cat settings/ns-temptargets.json | jq -c -C '.[0] | { target: .targetBottom, duration: .duration, start: .created_at }'
9191
# delete any local-temptarget files last modified more than 24h ago
9292
find settings/local-temptarget* -mmin +1440 -exec rm {} \;

‎bin/oref0-pump-loop.sh

+170-104
Large diffs are not rendered by default.

‎bin/oref0-set-device-clocks.sh

+4-3
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ checkNTP() { ntp-wait -n 1 -v || ( sudo /etc/init.d/ntp restart && ntp-wait -n 1
4545

4646
if checkNTP; then
4747
sudo ntpdate -s -b time.nist.gov
48-
echo Setting pump and CGM time to $(date)
49-
openaps use $PUMP set_clock --to now
50-
openaps use $CGM UpdateTime --to now
48+
echo Setting pump time to $(date)
49+
openaps use $PUMP set_clock --to now 2>&1 >/dev/null | tail -1
50+
echo Setting CGM time to $(date)
51+
openaps use $CGM UpdateTime --to now 2>&1 >/dev/null | tail -1
5152
fi

‎bin/oref0-setup.sh

+15-13
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ if [[ -z "$DIR" || -z "$serial" ]]; then
160160
serial=$REPLY
161161
echocolor "Ok, $serial it is."
162162
echo
163-
163+
164164
read -p "Do you have an x12 (i.e. 512 or 712) pump? y/[N] " -r
165165
if [[ $REPLY =~ ^[Yy]$ ]]; then
166166
pumpmodel=x12
@@ -626,21 +626,21 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
626626
cp $HOME/src/oref0/headless/interfaces.ap /etc/network/ || die "Couldn't copy interfaces.ap"
627627
cp /etc/network/interfaces /etc/network/interfaces.client || die "Couldn't copy interfaces.client"
628628
#Stop automatic startup of hostapd & dnsmasq
629-
update-rc.d -f hostapd remove
630-
update-rc.d -f dnsmasq remove
629+
update-rc.d -f hostapd remove
630+
update-rc.d -f dnsmasq remove
631631
# Edit /etc/hostapd/hostapd.conf for wifi using Hostname
632632
sed -i.bak -e "s/ssid=OpenAPS/ssid=${HOSTNAME}/" /etc/hostapd/hostapd.conf
633-
# Add Commands to /etc/rc.local
633+
# Add Commands to /etc/rc.local
634634
# Interrupt Kernel Messages
635635
if ! grep -q 'sudo dmesg -n 1' /etc/rc.local; then
636636
sed -i.bak -e '$ i sudo dmesg -n 1' /etc/rc.local
637-
fi
637+
fi
638638
# Add to /etc/rc.local to check if in hotspot mode and turn back to client mode during bootup
639639
if ! grep -q 'cp /etc/network/interfaces.client /etc/network/interfaces' /etc/rc.local; then
640640
sed -i.bak -e "$ i if [ -f /etc/network/interfaces.client ]; then\n\tif grep -q '#wpa-' /etc/network/interfaces; then\n\t\tsudo ifdown wlan0\n\t\tsudo cp /etc/network/interfaces.client /etc/network/interfaces\n\t\tsudo ifup wlan0\n\tfi\nfi" /etc/rc.local || die "Couldn't modify /etc/rc.local"
641641
fi
642-
fi
643-
642+
fi
643+
644644
# add/configure devices
645645
if [[ ${CGM,,} =~ "g5" || ${CGM,,} =~ "g5-upload" ]]; then
646646
openaps use cgm config --G5
@@ -848,19 +848,19 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
848848
done
849849
touch /tmp/reboot-required
850850
fi
851-
851+
852852
# disable IPv6
853853
if ! grep -q 'net.ipv6.conf.all.disable_ipv6=1' /etc/sysctl.conf; then
854854
sudo echo 'net.ipv6.conf.all.disable_ipv6=1' >> /etc/sysctl.conf
855-
fi
855+
fi
856856
if ! grep -q 'net.ipv6.conf.default.disable_ipv6=1' /etc/sysctl.conf; then
857857
sudo echo 'net.ipv6.conf.default.disable_ipv6=1' >> /etc/sysctl.conf
858-
fi
858+
fi
859859
if ! grep -q 'net.ipv6.conf.lo.disable_ipv6=1' /etc/sysctl.conf; then
860860
sudo echo 'net.ipv6.conf.lo.disable_ipv6=1' >> /etc/sysctl.conf
861-
fi
861+
fi
862862
sudo sysctl -p
863-
863+
864864
# Install EdisonVoltage
865865
if [[ "$ttyport" =~ "spidev5.1" ]]; then
866866
if egrep -i "edison" /etc/passwd 2>/dev/null; then
@@ -927,7 +927,7 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
927927
echo "settings removed, getting ready to add x12 settings"
928928
openaps alias add get-settings "report invoke settings/model.json settings/bg_targets.json settings/insulin_sensitivities_raw.json settings/insulin_sensitivities.json settings/carb_ratios.json settings/profile.json" || die "Could not add x12 settings"
929929
else
930-
sudo apt-get -y install bc jq
930+
sudo apt-get -y install bc jq ntpdate
931931
cd $directory || die "Can't cd $directory"
932932
for type in supermicrobolus; do
933933
echo importing $type file
@@ -1026,6 +1026,8 @@ if [[ $REPLY =~ ^[Yy]$ ]]; then
10261026
(crontab -l; crontab -l | grep -q "oref0-radio-reboot" || echo "* * * * * oref0-radio-reboot") | crontab -
10271027
fi
10281028
(crontab -l; crontab -l | grep -q "cd $directory && ( ps aux | grep -v grep | grep bash | grep -q 'bin/oref0-pump-loop'" || echo "* * * * * cd $directory && ( ps aux | grep -v grep | grep bash | grep -q 'bin/oref0-pump-loop' || oref0-pump-loop ) 2>&1 | tee -a /var/log/openaps/pump-loop.log") | crontab -
1029+
# try to start oref0-pump-loop every 30s
1030+
(crontab -l; crontab -l | grep -q "cd $directory && sleep 30 && ( ps aux | grep -v grep | grep bash | grep -q 'bin/oref0-pump-loop'" || echo "* * * * * cd $directory && sleep 30 && ( ps aux | grep -v grep | grep bash | grep -q 'bin/oref0-pump-loop' || oref0-pump-loop ) 2>&1 | tee -a /var/log/openaps/pump-loop.log") | crontab -
10291031
if [[ ! -z "$BT_PEB" ]]; then
10301032
(crontab -l; crontab -l | grep -q "cd $directory && ( ps aux | grep -v grep | grep -q 'peb-urchin-status $BT_PEB '" || echo "* * * * * cd $directory && ( ps aux | grep -v grep | grep -q 'peb-urchin-status $BT_PEB' || peb-urchin-status $BT_PEB ) 2>&1 | tee -a /var/log/openaps/urchin-loop.log") | crontab -
10311033
fi

‎lib/determine-basal/determine-basal.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
330330
// enable SMB/UAM (if enabled in preferences) while we have COB
331331
} else if (profile.enableSMB_with_COB && meal_data.mealCOB) {
332332
if (meal_data.bwCarbs) {
333-
if (A52_risk_enable) {
333+
if (profile.A52_risk_enable) {
334334
console.error("Warning: SMB enabled with Bolus Wizard carbs: be sure to easy bolus 30s before using Bolus Wizard")
335335
enableSMB=true;
336336
} else {
@@ -1009,7 +1009,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
10091009
// to the what fraction of expectedDelta we're dropping at
10101010
if (minDelta < 0 && minDelta > expectedDelta) {
10111011
var newinsulinReq = round(( insulinReq * (1 - (minDelta / expectedDelta)) ), 2);
1012-
//console.error("Reducing insulinReq from " + insulinReq + " to " + newinsulinReq);
1012+
console.error("Reducing insulinReq from " + insulinReq + " to " + newinsulinReq + " for minDelta " + minDelta + " vs. expectedDelta " + expectedDelta);
10131013
insulinReq = newinsulinReq;
10141014
}
10151015
// if that would put us over max_iob, then reduce accordingly

‎lib/meal/history.js

+9-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ function arrayHasElementWithSameTimestampAndProperty(array,t,propname) {
55
for (var j=0; j < array.length; j++) {
66
var element = array[j];
77
if (element.timestamp == t && element[propname] != undefined) return true;
8+
if ( element[propname] != undefined ) {
9+
eDate = new Date(element.timestamp);
10+
tDate = new Date(t);
11+
tMin = new Date(tDate.getTime() - 2000);
12+
tMax = new Date(tDate.getTime() + 2000);
13+
//console.error(tDate, tMin, tMax);
14+
if (eDate > tMin && eDate < tMax) return true;
15+
}
816
}
917
return false;
1018
}
@@ -49,7 +57,7 @@ function findMealInputs (inputs) {
4957
var temp = {};
5058
temp.timestamp = current.timestamp;
5159
temp.carbs = current.carb_input;
52-
temp.bwCarbs = current.carbs;
60+
temp.bwCarbs = current.carb_input;
5361

5462
// don't enter the treatment if there's another treatment with the same exact timestamp
5563
// to prevent duped carb entries from multiple sources

‎lib/meal/total.js

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ function recentCarbs(opts, time) {
5454
} else if (treatment.bwCarbs >= 1) {
5555
bwCarbs += parseFloat(treatment.bwCarbs);
5656
bwFound = true;
57+
} else {
58+
console.error("Treatment carbs unclassified:",treatment);
5759
}
5860
//console.error(treatment.carbs, maxCarbs, treatmentDate);
5961
carbs += parseFloat(treatment.carbs);
@@ -97,10 +99,12 @@ function recentCarbs(opts, time) {
9799

98100
// if currentDeviation is null or maxDeviation is 0, set mealCOB to 0 for zombie-carb safety
99101
if (typeof(c.currentDeviation) === 'undefined' || c.currentDeviation === null) {
102+
console.error("");
100103
console.error("Warning: setting mealCOB to 0 because currentDeviation is null/undefined");
101104
mealCOB = 0;
102105
}
103106
if (typeof(c.maxDeviation) === 'undefined' || c.maxDeviation === null) {
107+
console.error("");
104108
console.error("Warning: setting mealCOB to 0 because maxDeviation is 0 or undefined");
105109
mealCOB = 0;
106110
}

‎www/app.pyc

-1.71 KB
Binary file not shown.

0 commit comments

Comments
 (0)
Please sign in to comment.