calculate iob based on insulin stored with treatment
This commit is contained in:
parent
9fc1d59bd0
commit
863e6454eb
10 changed files with 35 additions and 14 deletions
|
@ -18,6 +18,7 @@ import org.slf4j.LoggerFactory;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||||
|
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
|
import info.nightscout.androidaps.plugins.Actions.ActionsFragment;
|
||||||
|
@ -212,6 +213,21 @@ public class MainApp extends Application {
|
||||||
return newList;
|
return newList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public static InsulinInterface getInsulinIterfaceById(int id) {
|
||||||
|
ArrayList<PluginBase> newList = new ArrayList<>();
|
||||||
|
|
||||||
|
if (pluginsList != null) {
|
||||||
|
for (PluginBase p : pluginsList) {
|
||||||
|
if (p.getType() == PluginBase.INSULIN && ((InsulinInterface)p).getId() == id)
|
||||||
|
return (InsulinInterface) p;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.error("InsulinInterface not found");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
public static ArrayList<PluginBase> getSpecificPluginsVisibleInList(int type) {
|
public static ArrayList<PluginBase> getSpecificPluginsVisibleInList(int type) {
|
||||||
ArrayList<PluginBase> newList = new ArrayList<>();
|
ArrayList<PluginBase> newList = new ArrayList<>();
|
||||||
|
|
||||||
|
|
|
@ -98,7 +98,7 @@ public class TempBasal {
|
||||||
tempBolusPart.insulin = tempBolusSize;
|
tempBolusPart.insulin = tempBolusSize;
|
||||||
tempBolusPart.created_at = new Date(date);
|
tempBolusPart.created_at = new Date(date);
|
||||||
|
|
||||||
Iob aIOB = insulinInterface.iobCalc(tempBolusPart, time, profile.getDia());
|
Iob aIOB = insulinInterface.iobCalcForTreatment(tempBolusPart, time, profile.getDia());
|
||||||
result.basaliob += aIOB.iobContrib;
|
result.basaliob += aIOB.iobContrib;
|
||||||
result.activity += aIOB.activityContrib;
|
result.activity += aIOB.activityContrib;
|
||||||
Double dia_ago = time - profile.getDia() * 60 * 60 * 1000;
|
Double dia_ago = time - profile.getDia() * 60 * 60 * 1000;
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.List;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.data.Iob;
|
import info.nightscout.androidaps.data.Iob;
|
||||||
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
|
||||||
|
@ -147,4 +148,11 @@ public class Treatment implements DataPointWithLabelInterface {
|
||||||
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Iob iobCalc(long time, double dia) {
|
||||||
|
InsulinInterface insulinInterface = MainApp.getInsulinIterfaceById(insulinType);
|
||||||
|
if (insulinInterface == null)
|
||||||
|
insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
|
||||||
|
|
||||||
|
return insulinInterface.iobCalcForTreatment(this, time, dia);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,5 +17,5 @@ public interface InsulinInterface {
|
||||||
String getFriendlyName();
|
String getFriendlyName();
|
||||||
String getComment();
|
String getComment();
|
||||||
double getDia();
|
double getDia();
|
||||||
public Iob iobCalc(Treatment treatment, long time, Double dia);
|
public Iob iobCalcForTreatment(Treatment treatment, long time, Double dia);
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ public class ActivityGraph extends GraphView {
|
||||||
List<DataPoint> iobArray = new ArrayList<DataPoint>();
|
List<DataPoint> iobArray = new ArrayList<DataPoint>();
|
||||||
|
|
||||||
for (long time = 0; time <= hours * 60 * 60 * 1000; time += 5 * 60 * 1000L) {
|
for (long time = 0; time <= hours * 60 * 60 * 1000; time += 5 * 60 * 1000L) {
|
||||||
Iob iob = insulin.iobCalc(t, time, dia);
|
Iob iob = t.iobCalc(time, dia);
|
||||||
activityArray.add(new DataPoint(time / 60 / 1000, iob.activityContrib));
|
activityArray.add(new DataPoint(time / 60 / 1000, iob.activityContrib));
|
||||||
iobArray.add(new DataPoint(time / 60 / 1000, iob.iobContrib));
|
iobArray.add(new DataPoint(time / 60 / 1000, iob.iobContrib));
|
||||||
}
|
}
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class InsulinFastactingPlugin implements PluginBase, InsulinInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iob iobCalc(Treatment treatment, long time, Double dia) {
|
public Iob iobCalcForTreatment(Treatment treatment, long time, Double dia) {
|
||||||
Iob result = new Iob();
|
Iob result = new Iob();
|
||||||
|
|
||||||
Double scaleFactor = 3.0 / dia;
|
Double scaleFactor = 3.0 / dia;
|
||||||
|
|
|
@ -100,7 +100,7 @@ public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInte
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Iob iobCalc(Treatment treatment, long time, Double dia) {
|
public Iob iobCalcForTreatment(Treatment treatment, long time, Double dia) {
|
||||||
Iob result = new Iob();
|
Iob result = new Iob();
|
||||||
|
|
||||||
//Double scaleFactor = 3.0 / dia;
|
//Double scaleFactor = 3.0 / dia;
|
||||||
|
|
|
@ -205,7 +205,6 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
if (MainApp.getConfigBuilder() == null || ConfigBuilderPlugin.getActiveProfile() == null) // app not initialized yet
|
if (MainApp.getConfigBuilder() == null || ConfigBuilderPlugin.getActiveProfile() == null) // app not initialized yet
|
||||||
return total;
|
return total;
|
||||||
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
||||||
InsulinInterface insulinInterface = MainApp.getConfigBuilder().getActiveInsulin();
|
|
||||||
if (profile == null)
|
if (profile == null)
|
||||||
return total;
|
return total;
|
||||||
|
|
||||||
|
@ -214,10 +213,10 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
for (Integer pos = 0; pos < treatments.size(); pos++) {
|
for (Integer pos = 0; pos < treatments.size(); pos++) {
|
||||||
Treatment t = treatments.get(pos);
|
Treatment t = treatments.get(pos);
|
||||||
if (t.created_at.getTime() > time) continue;
|
if (t.created_at.getTime() > time) continue;
|
||||||
Iob tIOB = insulinInterface.iobCalc(t, time, dia);
|
Iob tIOB = t.iobCalc(time, dia);
|
||||||
total.iob += tIOB.iobContrib;
|
total.iob += tIOB.iobContrib;
|
||||||
total.activity += tIOB.activityContrib;
|
total.activity += tIOB.activityContrib;
|
||||||
Iob bIOB = insulinInterface.iobCalc(t, time, dia / SP.getInt("openapsama_bolussnooze_dia_divisor", 2));
|
Iob bIOB = t.iobCalc(time, dia / SP.getInt("openapsama_bolussnooze_dia_divisor", 2));
|
||||||
total.bolussnooze += bIOB.iobContrib;
|
total.bolussnooze += bIOB.iobContrib;
|
||||||
}
|
}
|
||||||
return total;
|
return total;
|
||||||
|
|
|
@ -75,13 +75,12 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
|
||||||
if (MainApp.getConfigBuilder() == null || ConfigBuilderPlugin.getActiveProfile() == null) // app not initialized yet
|
if (MainApp.getConfigBuilder() == null || ConfigBuilderPlugin.getActiveProfile() == null) // app not initialized yet
|
||||||
return;
|
return;
|
||||||
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
||||||
InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
|
if (profile == null)
|
||||||
if (profile == null || insulinInterface == null)
|
|
||||||
return;
|
return;
|
||||||
holder.date.setText(DateUtil.dateAndTimeString(treatments.get(position).created_at));
|
holder.date.setText(DateUtil.dateAndTimeString(treatments.get(position).created_at));
|
||||||
holder.insulin.setText(DecimalFormatter.to2Decimal(treatments.get(position).insulin) + " U");
|
holder.insulin.setText(DecimalFormatter.to2Decimal(treatments.get(position).insulin) + " U");
|
||||||
holder.carbs.setText(DecimalFormatter.to0Decimal(treatments.get(position).carbs) + " g");
|
holder.carbs.setText(DecimalFormatter.to0Decimal(treatments.get(position).carbs) + " g");
|
||||||
Iob iob = insulinInterface.iobCalc(treatments.get(position), new Date().getTime(), profile.getDia());
|
Iob iob = treatments.get(position).iobCalc(new Date().getTime(), profile.getDia());
|
||||||
holder.iob.setText(DecimalFormatter.to2Decimal(iob.iobContrib) + " U");
|
holder.iob.setText(DecimalFormatter.to2Decimal(iob.iobContrib) + " U");
|
||||||
holder.activity.setText(DecimalFormatter.to3Decimal(iob.activityContrib) + " U");
|
holder.activity.setText(DecimalFormatter.to3Decimal(iob.activityContrib) + " U");
|
||||||
holder.mealOrCorrection.setText(treatments.get(position).mealBolus ? MainApp.sResources.getString(R.string.mealbolus) : MainApp.sResources.getString(R.string.correctionbous));
|
holder.mealOrCorrection.setText(treatments.get(position).mealBolus ? MainApp.sResources.getString(R.string.mealbolus) : MainApp.sResources.getString(R.string.correctionbous));
|
||||||
|
|
|
@ -203,7 +203,6 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
|
||||||
if (MainApp.getConfigBuilder() == null || ConfigBuilderPlugin.getActiveProfile() == null) // app not initialized yet
|
if (MainApp.getConfigBuilder() == null || ConfigBuilderPlugin.getActiveProfile() == null) // app not initialized yet
|
||||||
return total;
|
return total;
|
||||||
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
|
||||||
InsulinInterface insulinInterface = MainApp.getConfigBuilder().getActiveInsulin();
|
|
||||||
if (profile == null)
|
if (profile == null)
|
||||||
return total;
|
return total;
|
||||||
|
|
||||||
|
@ -212,10 +211,10 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
|
||||||
for (Integer pos = 0; pos < treatments.size(); pos++) {
|
for (Integer pos = 0; pos < treatments.size(); pos++) {
|
||||||
Treatment t = treatments.get(pos);
|
Treatment t = treatments.get(pos);
|
||||||
if (t.created_at.getTime() > time) continue;
|
if (t.created_at.getTime() > time) continue;
|
||||||
Iob tIOB = insulinInterface.iobCalc(t, time, dia);
|
Iob tIOB = t.iobCalc(time, dia);
|
||||||
total.iob += tIOB.iobContrib;
|
total.iob += tIOB.iobContrib;
|
||||||
total.activity += tIOB.activityContrib;
|
total.activity += tIOB.activityContrib;
|
||||||
Iob bIOB = insulinInterface.iobCalc(t, time, dia / SP.getInt("openapsama_bolussnooze_dia_divisor", 2));
|
Iob bIOB = t.iobCalc(time, dia / SP.getInt("openapsama_bolussnooze_dia_divisor", 2));
|
||||||
total.bolussnooze += bIOB.iobContrib;
|
total.bolussnooze += bIOB.iobContrib;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue