commit
44279f78a8
3 changed files with 78 additions and 12 deletions
|
@ -284,18 +284,36 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
|
||||||
else {
|
else {
|
||||||
console.error("Time now is "+now+"; ");
|
console.error("Time now is "+now+"; ");
|
||||||
}
|
}
|
||||||
|
console.error(" ");
|
||||||
|
console.error("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
|
||||||
|
console.error("++ Dynamic ISF Beta 1.3 - Based on rolling 24 hours ++");
|
||||||
|
console.error("++++++++++++++++++++++++++++++++++++++++++++++++++++++");
|
||||||
|
console.error(" ");
|
||||||
|
|
||||||
if (meal_data.TDDAIMI7){
|
if (meal_data.TDDAIMI7){
|
||||||
var tdd7 = meal_data.TDDAIMI7;
|
var tdd7 = meal_data.TDDAIMI7;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
var tdd7 = ((basal * 12)*100)/21;
|
||||||
}
|
}
|
||||||
else{
|
console.error("7-day average TDD is: " +tdd7+ "; ");
|
||||||
var tdd7 = ((basal * 12)*100)/21;
|
console.error(" ");
|
||||||
}
|
|
||||||
var tdd_pump_now = meal_data.TDDPUMP;
|
if (meal_data.TDDLast24){
|
||||||
var tdd_pump = ( tdd_pump_now / (now / 24));
|
var tdd_24 = meal_data.TDDLast24;
|
||||||
var TDD = (tdd7 * 0.4) + (tdd_pump * 0.6);
|
}
|
||||||
console.error("Pump extrapolated TDD = "+tdd_pump+"; ");
|
else {
|
||||||
|
var tdd_24 = (( basal * 24 ) * 2.8);
|
||||||
|
}
|
||||||
|
|
||||||
|
var TDD = (tdd7 * 0.3) + (tdd_24 * 0.7);
|
||||||
|
|
||||||
|
console.error("Rolling 24 hour TDD = "+tdd_24+"; ");
|
||||||
|
console.error(" ");
|
||||||
|
console.error("Weighted Average TDD = "+TDD+"; ");
|
||||||
|
console.error(" ");
|
||||||
//if (tdd7 > 0){
|
//if (tdd7 > 0){
|
||||||
if ( tdd_pump > tdd7 && now < 5 || now < 7 && TDD < ( 0.8 * tdd7 ) ){
|
/*if ( tdd_pump > tdd7 && now < 5 || now < 7 && TDD < ( 0.8 * tdd7 ) ){
|
||||||
TDD = ( 0.8 * tdd7 );
|
TDD = ( 0.8 * tdd7 );
|
||||||
console.log("Excess or too low insulin from pump so TDD set to "+TDD+" based on 75% of TDD7; ");
|
console.log("Excess or too low insulin from pump so TDD set to "+TDD+" based on 75% of TDD7; ");
|
||||||
rT.reason += "TDD: " +TDD+ " due to low or high tdd from pump; ";
|
rT.reason += "TDD: " +TDD+ " due to low or high tdd from pump; ";
|
||||||
|
@ -316,12 +334,13 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
|
||||||
else {
|
else {
|
||||||
console.log("TDD 7 ="+tdd7+", TDD Pump ="+tdd_pump+" and TDD = "+TDD+";");
|
console.log("TDD 7 ="+tdd7+", TDD Pump ="+tdd_pump+" and TDD = "+TDD+";");
|
||||||
rT.reason += "TDD: " +TDD+ " based on standard pump 60/tdd7 40 split; ";
|
rT.reason += "TDD: " +TDD+ " based on standard pump 60/tdd7 40 split; ";
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
var variable_sens = (277700 / (TDD * bg));
|
var variable_sens = (277700 / (TDD * bg));
|
||||||
variable_sens = round(variable_sens,1);
|
variable_sens = round(variable_sens,1);
|
||||||
console.log("Current sensitivity for predictions is " +variable_sens+" based on current bg");
|
console.log("Current sensitivity for predictions is " +variable_sens+" based on current bg");
|
||||||
|
console.error(" ");
|
||||||
|
|
||||||
sens = variable_sens;
|
sens = variable_sens;
|
||||||
if ( high_temptarget_raises_sensitivity && profile.temptargetSet && target_bg > normalTarget || profile.low_temptarget_lowers_sensitivity && profile.temptargetSet && target_bg < normalTarget ) {
|
if ( high_temptarget_raises_sensitivity && profile.temptargetSet && target_bg > normalTarget || profile.low_temptarget_lowers_sensitivity && profile.temptargetSet && target_bg < normalTarget ) {
|
||||||
|
@ -389,7 +408,7 @@ var determine_basal = function determine_basal(glucose_status, currenttemp, iob_
|
||||||
if (iob_data.iob > 0) {
|
if (iob_data.iob > 0) {
|
||||||
var naive_eventualBG = round( bg - (iob_data.iob * sens) );
|
var naive_eventualBG = round( bg - (iob_data.iob * sens) );
|
||||||
} else { // if IOB is negative, be more conservative and use the lower of sens, profile.sens
|
} else { // if IOB is negative, be more conservative and use the lower of sens, profile.sens
|
||||||
naive_eventualBG = round( bg - (iob_data.iob * Math.min(sens, profile.sens) ) );
|
naive_eventualBG = round( bg - (iob_data.iob * sens ) );
|
||||||
}
|
}
|
||||||
// and adjust it for the deviation above
|
// and adjust it for the deviation above
|
||||||
var eventualBG = naive_eventualBG + deviation;
|
var eventualBG = naive_eventualBG + deviation;
|
||||||
|
|
|
@ -260,6 +260,7 @@ class DetermineBasalAdapterSMBDynamicISFJS internal constructor(private val scri
|
||||||
|
|
||||||
this.mealData.put("TDDAIMI7", tddCalculator.averageTDD(tddCalculator.calculate(7)).totalAmount)
|
this.mealData.put("TDDAIMI7", tddCalculator.averageTDD(tddCalculator.calculate(7)).totalAmount)
|
||||||
this.mealData.put("TDDPUMP", tddCalculator.calculateDaily().totalAmount)
|
this.mealData.put("TDDPUMP", tddCalculator.calculateDaily().totalAmount)
|
||||||
|
this.mealData.put("TDDLast24", tddCalculator!!.calculate24Daily().totalAmount)
|
||||||
|
|
||||||
if (constraintChecker.isAutosensModeEnabled().value()) {
|
if (constraintChecker.isAutosensModeEnabled().value()) {
|
||||||
autosensData.put("ratio", autosensDataRatio)
|
autosensData.put("ratio", autosensDataRatio)
|
||||||
|
|
|
@ -103,13 +103,13 @@ class TddCalculator @Inject constructor(
|
||||||
val tbr = iobCobCalculator.getTempBasalIncludingConvertedExtended(t)
|
val tbr = iobCobCalculator.getTempBasalIncludingConvertedExtended(t)
|
||||||
val profile = profileFunction.getProfile(t) ?: continue
|
val profile = profileFunction.getProfile(t) ?: continue
|
||||||
val absoluteRate = tbr?.convertedToAbsolute(t, profile) ?: profile.getBasal(t)
|
val absoluteRate = tbr?.convertedToAbsolute(t, profile) ?: profile.getBasal(t)
|
||||||
tdd.basalAmount += absoluteRate / T.mins(5).msecs().toDouble() * calculationStep.toDouble()
|
tdd.basalAmount += absoluteRate / 60.0 * 5.0
|
||||||
|
|
||||||
if (!activePlugin.activePump.isFakingTempsByExtendedBoluses) {
|
if (!activePlugin.activePump.isFakingTempsByExtendedBoluses) {
|
||||||
// they are not included in TBRs
|
// they are not included in TBRs
|
||||||
val eb = iobCobCalculator.getExtendedBolus(t)
|
val eb = iobCobCalculator.getExtendedBolus(t)
|
||||||
val absoluteEbRate = eb?.rate ?: 0.0
|
val absoluteEbRate = eb?.rate ?: 0.0
|
||||||
tdd.bolusAmount += absoluteEbRate / T.mins(5).msecs().toDouble() * calculationStep.toDouble()
|
tdd.bolusAmount += absoluteEbRate / 60.0 * 5.0
|
||||||
}
|
}
|
||||||
//result.put(midnight, tdd)
|
//result.put(midnight, tdd)
|
||||||
}
|
}
|
||||||
|
@ -122,7 +122,53 @@ class TddCalculator @Inject constructor(
|
||||||
aapsLogger.debug(LTag.CORE, tdd.toString())
|
aapsLogger.debug(LTag.CORE, tdd.toString())
|
||||||
return tdd
|
return tdd
|
||||||
}
|
}
|
||||||
|
fun calculate24Daily():TotalDailyDose {
|
||||||
|
val startTime = dateUtil.now() - T.hours(hour = 24).msecs()
|
||||||
|
val endTime = dateUtil.now()
|
||||||
|
val tdd = TotalDailyDose(timestamp = startTime)
|
||||||
|
//val result = TotalDailyDose()
|
||||||
|
repository.getBolusesDataFromTimeToTime(startTime, endTime, true).blockingGet()
|
||||||
|
.filter { it.type != Bolus.Type.PRIMING }
|
||||||
|
.forEach { t ->
|
||||||
|
//val midnight = MidnightTime.calc(t.timestamp)
|
||||||
|
//val tdd = result[midnight] ?: TotalDailyDose(timestamp = midnight)
|
||||||
|
tdd.bolusAmount += t.amount
|
||||||
|
//result.put(midnight, tdd)
|
||||||
|
}
|
||||||
|
repository.getCarbsDataFromTimeToTimeExpanded(startTime, endTime, true).blockingGet().forEach { t ->
|
||||||
|
//val midnight = MidnightTime.calc(t.timestamp)
|
||||||
|
//val tdd = result[midnight] ?: TotalDailyDose(timestamp = midnight)
|
||||||
|
tdd.carbs += t.amount
|
||||||
|
//result.put(midnight, tdd)
|
||||||
|
}
|
||||||
|
val calculationStep = T.mins(5).msecs()
|
||||||
|
val tempBasals = iobCobCalculator.getTempBasalIncludingConvertedExtendedForRange(startTime, endTime, calculationStep)
|
||||||
|
for (t in startTime until endTime step calculationStep) {
|
||||||
|
|
||||||
|
//val midnight = MidnightTime.calc(t)
|
||||||
|
//val tdd = result[midnight] ?: TotalDailyDose(timestamp = midnight)
|
||||||
|
val tbr = iobCobCalculator.getTempBasalIncludingConvertedExtended(t)
|
||||||
|
val profile = profileFunction.getProfile(t) ?: continue
|
||||||
|
val absoluteRate = tbr?.convertedToAbsolute(t, profile) ?: profile.getBasal(t)
|
||||||
|
tdd.basalAmount += absoluteRate / 60.0 * 5.0
|
||||||
|
|
||||||
|
if (!activePlugin.activePump.isFakingTempsByExtendedBoluses) {
|
||||||
|
// they are not included in TBRs
|
||||||
|
val eb = iobCobCalculator.getExtendedBolus(t)
|
||||||
|
val absoluteEbRate = eb?.rate ?: 0.0
|
||||||
|
tdd.bolusAmount += absoluteEbRate / 60.0 * 5.0
|
||||||
|
}
|
||||||
|
//result.put(midnight, tdd)
|
||||||
|
}
|
||||||
|
//for (i in 0 until tdd.size()) {
|
||||||
|
//val tdd = result.valueAt(i)
|
||||||
|
tdd.totalAmount = tdd.bolusAmount + tdd.basalAmount
|
||||||
|
//}
|
||||||
|
|
||||||
|
|
||||||
|
aapsLogger.debug(LTag.CORE, tdd.toString())
|
||||||
|
return tdd
|
||||||
|
}
|
||||||
fun averageTDD(tdds: LongSparseArray<TotalDailyDose>): TotalDailyDose {
|
fun averageTDD(tdds: LongSparseArray<TotalDailyDose>): TotalDailyDose {
|
||||||
val totalTdd = TotalDailyDose(timestamp = dateUtil.now())
|
val totalTdd = TotalDailyDose(timestamp = dateUtil.now())
|
||||||
for (i in 0 until tdds.size()) {
|
for (i in 0 until tdds.size()) {
|
||||||
|
|
Loading…
Reference in a new issue