Skip to content

Commit

Permalink
simulator bugfix and better logging (#1356)
Browse files Browse the repository at this point in the history
* print pretty stats on one line, and csv stats on another

* check if temp_basal.json is empty, and write a valid one if so

* more accurate logging
  • Loading branch information
scottleibrand authored Feb 3, 2020
1 parent 3cddf42 commit 16b9840
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
12 changes: 6 additions & 6 deletions bin/glucose-stats.awk
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ BEGIN {
if (!min_bg) { min_bg=70 }
if (!max_bg) { max_bg=180 }
}
{ sum+=$1; count++ }
{ sum+=$1; count++; squares+=$1^2; }
($1 < 39) { next }
($1 < min) { min=$1 }
($1 > max) { max=$1 }
($1 <= max_bg && $1 >= min_bg) { inrange++ }
($1 > max_bg) { high++ }
($1 < min_bg) { low++ }
END { print "Count: " count;
printf "Min / Max / Average: %.0f / %.0f / %.1f\n", min, max, sum/count
printf "%%TIR / high / low (%.0f-%.0f): ", min_bg, max_bg
#print "%TIR / high / low (" min_bg "-" max_bg "): " \
printf "%.1f%% / %.1f%% / %.1f%%\n", inrange/(high+inrange+low)*100, high/(high+inrange+low)*100, low/(high+inrange+low)*100
END { # print "Count: " count;
printf "Count %.0f / Min %.0f / Max %.0f / Average %.1f / StdDev %.1f / ", count, min, max, sum/count, sqrt(squares/count-(sum/count)^2)
#printf "%%TIR / low / high (%.0f-%.0f): ", min_bg, max_bg
printf "%.1f%% TIR / %.1f%% low / %.1f%% high (%.0f-%.0f)\n", inrange/(high+inrange+low)*100, low/(high+inrange+low)*100, high/(high+inrange+low)*100, min_bg, max_bg
printf "%.0f,%.1f,%.1f,%.1f,%.1f", count, sum/count, low/(high+inrange+low)*100, high/(high+inrange+low)*100, sqrt(squares/count-(sum/count)^2)
}
3 changes: 3 additions & 0 deletions bin/oref0-simulator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ function main {
jq '. | .duration=.duration-5 | { rate: .rate, duration: .duration, temp: "absolute" }' temp_basal.json > temp_basal.json.new
mv temp_basal.json.new temp_basal.json
fi
if ! [ -s temp_basal.json ]; then
echo '{"rate": 0, "duration": 0, "temp": "absolute"}' > temp_basal.json
fi
#cat temp_basal.json | jq -c
Expand Down
2 changes: 1 addition & 1 deletion lib/determine-basal/determine-basal.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
cid = Math.min(remainingCATime*60/5/2,Math.max(0, meal_data.mealCOB * csf / ci ));
}
// duration (hours) = duration (5m) * 5 / 60 * 2 (to account for linear decay)
console.error("Carb Impact:",ci,"mg/dL per 5m; CI Duration:",round(cid*5/60*2,1),"hours; remaining CI (~2h peak):",round(remainingCIpeak,1),"mg/dL per 5m");
console.error("Carb Impact:",ci,"mg/dL per 5m; CI Duration:",round(cid*5/60*2,1),"hours; remaining CI (",remainingCATime," peak):",round(remainingCIpeak,1),"mg/dL per 5m");

var minIOBPredBG = 999;
var minCOBPredBG = 999;
Expand Down

0 comments on commit 16b9840

Please sign in to comment.