Merge pull request #148 from AdrianLxM/minutesrunning

Update determine-basal.js with minutesrunning
This commit is contained in:
Milos Kozak 2017-01-30 09:53:33 +01:00 committed by GitHub
commit a82c579014
3 changed files with 24 additions and 5 deletions

View file

@ -197,7 +197,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
if (iob_data.basaliob) { basaliob = iob_data.basaliob; }
else { basaliob = iob_data.iob - iob_data.bolussnooze; }
// generate predicted future BGs based on IOB, COB, and current absortpion rate
// generate predicted future BGs based on IOB, COB, and current absorption rate
var COBpredBGs = [];
var aCOBpredBGs = [];
@ -347,6 +347,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
// use snoozeBG to more gradually ramp in any counteraction of the user's boluses
// multiply by 2 to low-temp faster for increased hypo safety
var insulinReq = 2 * Math.min(0, (snoozeBG - target_bg) / sens);
insulinReq = round( insulinReq , 2);
if (minDelta < 0 && minDelta > expectedDelta) {
// if we're barely falling, newinsulinReq should be barely negative
rT.reason += ", Snooze BG " + convert_bg(snoozeBG, profile);
@ -374,9 +375,19 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
}
}
var minutes_running;
if (typeof currenttemp.duration == 'undefined' || currenttemp.duration == 0) {
minutes_running = 30;
} else if (typeof currenttemp.minutesrunning !== 'undefined'){
// If the time the current temp is running is not defined, use default request duration of 30 minutes.
minutes_running = currenttemp.minutesrunning;
} else {
minutes_running = 30 - currenttemp.duration;
}
// if there is a low-temp running, and eventualBG would be below min_bg without it, let it run
if (round_basal(currenttemp.rate, profile) < round_basal(basal, profile) ) {
var lowtempimpact = (currenttemp.rate - basal) * (currenttemp.duration/60) * sens;
var lowtempimpact = (currenttemp.rate - basal) * ((30-minutes_running)/60) * sens;
var adjEventualBG = eventualBG + lowtempimpact;
if ( adjEventualBG < min_bg ) {
rT.reason += "letting low temp of " + currenttemp.rate + " run.";

View file

@ -131,7 +131,7 @@ public class TempBasal {
public int getRealDuration() {
Long msecs = getTimeEnd().getTime() - timeStart.getTime();
return (int) (msecs / 60 / 1000);
return Math.round(msecs / 60f / 1000);
}
public long getMillisecondsFromStart() {
@ -140,8 +140,8 @@ public class TempBasal {
public int getPlannedRemainingMinutes() {
if (timeEnd != null) return 0;
long remainingMin = (getPlannedTimeEnd().getTime() - new Date().getTime()) / 1000 / 60;
return (remainingMin < 0) ? 0 : (int) remainingMin;
float remainingMin = (getPlannedTimeEnd().getTime() - new Date().getTime()) / 1000f / 60;
return (remainingMin < 0) ? 0 : Math.round(remainingMin);
}
public boolean isInProgress() {

View file

@ -20,6 +20,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
@ -234,6 +235,13 @@ public class DetermineBasalAdapterAMAJS {
mCurrentTemp.add("temp", "absolute");
mCurrentTemp.add("duration", pump.getTempBasalRemainingMinutes());
mCurrentTemp.add("rate", pump.getTempBasalAbsoluteRate());
// as we have non default temps longer than 30 mintues
TempBasal tempBasal = pump.getTempBasal();
if(tempBasal != null){
mCurrentTemp.add("minutesrunning", tempBasal.getRealDuration());
}
mV8rt.add(PARAM_currentTemp, mCurrentTemp);
mIobData = mV8rt.executeArrayScript(IobTotal.convertToJSONArray(iobArray).toString());