merge bolus & basal into one plugin
This commit is contained in:
parent
eddd8ac56d
commit
abdc1022bf
28 changed files with 256 additions and 449 deletions
|
@ -50,14 +50,12 @@ import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpFragment;
|
||||||
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gFragment;
|
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gFragment;
|
||||||
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment;
|
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment;
|
||||||
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment;
|
import info.nightscout.androidaps.plugins.SourceXdrip.SourceXdripFragment;
|
||||||
import info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment;
|
|
||||||
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangeFragment;
|
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangeFragment;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
|
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
|
||||||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpFragment;
|
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpFragment;
|
||||||
import info.nightscout.androidaps.plugins.Wear.WearFragment;
|
import info.nightscout.androidaps.plugins.Wear.WearFragment;
|
||||||
import info.nightscout.androidaps.plugins.Persistentnotification.PersistentNotificationPlugin;
|
import info.nightscout.androidaps.plugins.Persistentnotification.PersistentNotificationPlugin;
|
||||||
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslineFragment;
|
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslineFragment;
|
||||||
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
|
|
||||||
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
|
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
|
||||||
import io.fabric.sdk.android.Fabric;
|
import io.fabric.sdk.android.Fabric;
|
||||||
|
|
||||||
|
@ -114,7 +112,6 @@ public class MainApp extends Application {
|
||||||
pluginsList.add(CircadianPercentageProfileFragment.getPlugin());
|
pluginsList.add(CircadianPercentageProfileFragment.getPlugin());
|
||||||
if (Config.APS) pluginsList.add(TempTargetRangeFragment.getPlugin());
|
if (Config.APS) pluginsList.add(TempTargetRangeFragment.getPlugin());
|
||||||
pluginsList.add(TreatmentsFragment.getPlugin());
|
pluginsList.add(TreatmentsFragment.getPlugin());
|
||||||
if (Config.TEMPBASALS) pluginsList.add(TempBasalsFragment.getPlugin());
|
|
||||||
if (Config.SAFETY) pluginsList.add(SafetyFragment.getPlugin());
|
if (Config.SAFETY) pluginsList.add(SafetyFragment.getPlugin());
|
||||||
if (Config.APS) pluginsList.add(ObjectivesFragment.getPlugin());
|
if (Config.APS) pluginsList.add(ObjectivesFragment.getPlugin());
|
||||||
pluginsList.add(SourceXdripFragment.getPlugin());
|
pluginsList.add(SourceXdripFragment.getPlugin());
|
||||||
|
|
|
@ -8,7 +8,7 @@ import java.util.Date;
|
||||||
public interface PluginBase {
|
public interface PluginBase {
|
||||||
int GENERAL = 1;
|
int GENERAL = 1;
|
||||||
int TREATMENT = 2;
|
int TREATMENT = 2;
|
||||||
int TEMPBASAL = 3;
|
//int TEMPBASAL = 3;
|
||||||
int PROFILE = 4;
|
int PROFILE = 4;
|
||||||
int APS = 5;
|
int APS = 5;
|
||||||
int PUMP = 6;
|
int PUMP = 6;
|
||||||
|
|
|
@ -1,20 +0,0 @@
|
||||||
package info.nightscout.androidaps.interfaces;
|
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.db.TempBasal;
|
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 14.06.2016.
|
|
||||||
*/
|
|
||||||
public interface TempBasalsInterface {
|
|
||||||
void updateTotalIOBTempBasals();
|
|
||||||
IobTotal getLastCalculationTempBasals();
|
|
||||||
IobTotal getCalculationToTimeTempBasals(long time);
|
|
||||||
|
|
||||||
TempBasal getTempBasal (Date time);
|
|
||||||
TempBasal getExtendedBolus (Date time);
|
|
||||||
|
|
||||||
long oldestDataAvaialable();
|
|
||||||
}
|
|
|
@ -1,8 +1,10 @@
|
||||||
package info.nightscout.androidaps.interfaces;
|
package info.nightscout.androidaps.interfaces;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
|
import info.nightscout.androidaps.db.TempBasal;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
|
|
||||||
|
@ -12,9 +14,21 @@ import info.nightscout.androidaps.data.IobTotal;
|
||||||
public interface TreatmentsInterface {
|
public interface TreatmentsInterface {
|
||||||
|
|
||||||
void updateTotalIOBTreatments();
|
void updateTotalIOBTreatments();
|
||||||
|
void updateTotalIOBTempBasals();
|
||||||
|
|
||||||
IobTotal getLastCalculationTreatments();
|
IobTotal getLastCalculationTreatments();
|
||||||
IobTotal getCalculationToTimeTreatments(long time);
|
IobTotal getCalculationToTimeTreatments(long time);
|
||||||
|
IobTotal getLastCalculationTempBasals();
|
||||||
|
IobTotal getCalculationToTimeTempBasals(long time);
|
||||||
|
|
||||||
MealData getMealData();
|
MealData getMealData();
|
||||||
|
|
||||||
List<Treatment> getTreatments();
|
List<Treatment> getTreatments();
|
||||||
List<Treatment> getTreatments5MinBack(long time);
|
List<Treatment> getTreatments5MinBack(long time);
|
||||||
|
|
||||||
|
TempBasal getTempBasal (Date time);
|
||||||
|
TempBasal getExtendedBolus (Date time);
|
||||||
|
|
||||||
|
long oldestDataAvaialable();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,8 +55,6 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
ListView loopListView;
|
ListView loopListView;
|
||||||
TextView loopLabel;
|
TextView loopLabel;
|
||||||
ListView treatmentsListView;
|
ListView treatmentsListView;
|
||||||
ListView tempsListView;
|
|
||||||
TextView tempsLabel;
|
|
||||||
ListView profileListView;
|
ListView profileListView;
|
||||||
ListView apsListView;
|
ListView apsListView;
|
||||||
TextView apsLabel;
|
TextView apsLabel;
|
||||||
|
@ -74,7 +72,6 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
PluginCustomAdapter pumpDataAdapter = null;
|
PluginCustomAdapter pumpDataAdapter = null;
|
||||||
PluginCustomAdapter loopDataAdapter = null;
|
PluginCustomAdapter loopDataAdapter = null;
|
||||||
PluginCustomAdapter treatmentsDataAdapter = null;
|
PluginCustomAdapter treatmentsDataAdapter = null;
|
||||||
PluginCustomAdapter tempsDataAdapter = null;
|
|
||||||
PluginCustomAdapter profileDataAdapter = null;
|
PluginCustomAdapter profileDataAdapter = null;
|
||||||
PluginCustomAdapter apsDataAdapter = null;
|
PluginCustomAdapter apsDataAdapter = null;
|
||||||
PluginCustomAdapter constraintsDataAdapter = null;
|
PluginCustomAdapter constraintsDataAdapter = null;
|
||||||
|
@ -102,8 +99,6 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
loopListView = (ListView) view.findViewById(R.id.configbuilder_looplistview);
|
loopListView = (ListView) view.findViewById(R.id.configbuilder_looplistview);
|
||||||
loopLabel = (TextView) view.findViewById(R.id.configbuilder_looplabel);
|
loopLabel = (TextView) view.findViewById(R.id.configbuilder_looplabel);
|
||||||
treatmentsListView = (ListView) view.findViewById(R.id.configbuilder_treatmentslistview);
|
treatmentsListView = (ListView) view.findViewById(R.id.configbuilder_treatmentslistview);
|
||||||
tempsListView = (ListView) view.findViewById(R.id.configbuilder_tempslistview);
|
|
||||||
tempsLabel = (TextView) view.findViewById(R.id.configbuilder_tempslabel);
|
|
||||||
profileListView = (ListView) view.findViewById(R.id.configbuilder_profilelistview);
|
profileListView = (ListView) view.findViewById(R.id.configbuilder_profilelistview);
|
||||||
apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview);
|
apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview);
|
||||||
apsLabel = (TextView) view.findViewById(R.id.configbuilder_apslabel);
|
apsLabel = (TextView) view.findViewById(R.id.configbuilder_apslabel);
|
||||||
|
@ -163,11 +158,6 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
treatmentsDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.TREATMENT), PluginBase.TREATMENT);
|
treatmentsDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.TREATMENT), PluginBase.TREATMENT);
|
||||||
treatmentsListView.setAdapter(treatmentsDataAdapter);
|
treatmentsListView.setAdapter(treatmentsDataAdapter);
|
||||||
setListViewHeightBasedOnChildren(treatmentsListView);
|
setListViewHeightBasedOnChildren(treatmentsListView);
|
||||||
tempsDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInList(PluginBase.TEMPBASAL), PluginBase.TEMPBASAL);
|
|
||||||
tempsListView.setAdapter(tempsDataAdapter);
|
|
||||||
setListViewHeightBasedOnChildren(tempsListView);
|
|
||||||
if (MainApp.getSpecificPluginsVisibleInList(PluginBase.TEMPBASAL).size() == 0)
|
|
||||||
tempsLabel.setVisibility(View.GONE);
|
|
||||||
profileDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginBase.BGSOURCE), PluginBase.PROFILE);
|
profileDataAdapter = new PluginCustomAdapter(getContext(), smallWidth?R.layout.configbuilder_smallitem :R.layout.configbuilder_simpleitem, MainApp.getSpecificPluginsVisibleInListByInterface(ProfileInterface.class, PluginBase.BGSOURCE), PluginBase.PROFILE);
|
||||||
profileListView.setAdapter(profileDataAdapter);
|
profileListView.setAdapter(profileDataAdapter);
|
||||||
setListViewHeightBasedOnChildren(profileListView);
|
setListViewHeightBasedOnChildren(profileListView);
|
||||||
|
@ -275,7 +265,7 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hide enabled control and force enabled plugin if there is only one plugin available
|
// Hide enabled control and force enabled plugin if there is only one plugin available
|
||||||
if (type == PluginBase.INSULIN || type == PluginBase.PUMP || type == PluginBase.TREATMENT || type == PluginBase.TEMPBASAL || type == PluginBase.PROFILE)
|
if (type == PluginBase.INSULIN || type == PluginBase.PUMP || type == PluginBase.TREATMENT || type == PluginBase.PROFILE)
|
||||||
if (pluginList.size() < 2) {
|
if (pluginList.size() < 2) {
|
||||||
holder.checkboxEnabled.setEnabled(false);
|
holder.checkboxEnabled.setEnabled(false);
|
||||||
plugin.setFragmentEnabled(type, true);
|
plugin.setFragmentEnabled(type, true);
|
||||||
|
@ -333,7 +323,6 @@ public class ConfigBuilderFragment extends Fragment {
|
||||||
case PluginBase.BGSOURCE:
|
case PluginBase.BGSOURCE:
|
||||||
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(BgSourceInterface.class);
|
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(BgSourceInterface.class);
|
||||||
break;
|
break;
|
||||||
case PluginBase.TEMPBASAL:
|
|
||||||
case PluginBase.TREATMENT:
|
case PluginBase.TREATMENT:
|
||||||
case PluginBase.PUMP:
|
case PluginBase.PUMP:
|
||||||
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(PumpInterface.class);
|
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(PumpInterface.class);
|
||||||
|
|
|
@ -35,12 +35,12 @@ import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
|
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgError;
|
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.Loop.DeviceStatus;
|
import info.nightscout.androidaps.plugins.Loop.DeviceStatus;
|
||||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.DbLogger;
|
||||||
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA;
|
import info.nightscout.androidaps.plugins.OpenAPSAMA.DetermineBasalResultAMA;
|
||||||
import info.nightscout.androidaps.plugins.OpenAPSMA.DetermineBasalResultMA;
|
import info.nightscout.androidaps.plugins.OpenAPSMA.DetermineBasalResultMA;
|
||||||
import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog;
|
import info.nightscout.androidaps.plugins.Overview.Dialogs.BolusProgressDialog;
|
||||||
|
@ -49,8 +49,7 @@ import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogressIfRunning;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.DbLogger;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgError;
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
|
||||||
import info.nightscout.utils.BatteryLevel;
|
import info.nightscout.utils.BatteryLevel;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
@ -65,7 +64,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
static PumpInterface activePump;
|
static PumpInterface activePump;
|
||||||
static ProfileInterface activeProfile;
|
static ProfileInterface activeProfile;
|
||||||
static TreatmentsInterface activeTreatments;
|
static TreatmentsInterface activeTreatments;
|
||||||
static TempBasalsInterface activeTempBasals;
|
|
||||||
static APSInterface activeAPS;
|
static APSInterface activeAPS;
|
||||||
static LoopPlugin activeLoop;
|
static LoopPlugin activeLoop;
|
||||||
static InsulinInterface activeInsulin;
|
static InsulinInterface activeInsulin;
|
||||||
|
@ -206,10 +204,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
return activeTreatments;
|
return activeTreatments;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TempBasalsInterface getActiveTempBasals() {
|
|
||||||
return activeTempBasals;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static InsulinInterface getActiveInsulin() {
|
public static InsulinInterface getActiveInsulin() {
|
||||||
return activeInsulin;
|
return activeInsulin;
|
||||||
}
|
}
|
||||||
|
@ -312,17 +306,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// PluginBase.TEMPBASAL
|
|
||||||
pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.TEMPBASAL);
|
|
||||||
activeTempBasals = (TempBasalsInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.TEMPBASAL);
|
|
||||||
if (Config.logConfigBuilder && activeTempBasals != null)
|
|
||||||
log.debug("Selected tempbasal interface: " + ((PluginBase) activeTempBasals).getName());
|
|
||||||
for (PluginBase p : pluginsInCategory) {
|
|
||||||
if (!p.getName().equals(((PluginBase) activeTempBasals).getName())) {
|
|
||||||
p.setFragmentVisible(PluginBase.TEMPBASAL, false);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// PluginBase.TREATMENT
|
// PluginBase.TREATMENT
|
||||||
pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.TREATMENT);
|
pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.TREATMENT);
|
||||||
activeTreatments = (TreatmentsInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.TREATMENT);
|
activeTreatments = (TreatmentsInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.TREATMENT);
|
||||||
|
|
|
@ -339,7 +339,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
//log.debug(">>> Cache miss " + new Date(time).toLocaleString());
|
//log.debug(">>> Cache miss " + new Date(time).toLocaleString());
|
||||||
}
|
}
|
||||||
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getCalculationToTimeTreatments(time).round();
|
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getCalculationToTimeTreatments(time).round();
|
||||||
IobTotal basalIob = ConfigBuilderPlugin.getActiveTempBasals().getCalculationToTimeTempBasals(time).round();
|
IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getCalculationToTimeTempBasals(time).round();
|
||||||
/*
|
/*
|
||||||
if (basalIob.basaliob > 0) {
|
if (basalIob.basaliob > 0) {
|
||||||
log.debug(new Date(time).toLocaleString() + " basaliob: " + basalIob.basaliob );
|
log.debug(new Date(time).toLocaleString() + " basaliob: " + basalIob.basaliob );
|
||||||
|
|
|
@ -222,7 +222,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
|
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
|
||||||
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;
|
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;
|
||||||
|
|
||||||
long oldestDataAvailable = MainApp.getConfigBuilder().getActiveTempBasals().oldestDataAvaialable();
|
long oldestDataAvailable = MainApp.getConfigBuilder().getActiveTreatments().oldestDataAvaialable();
|
||||||
long getBGDataFrom = Math.max(oldestDataAvailable, (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + profile.getDia())));
|
long getBGDataFrom = Math.max(oldestDataAvailable, (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + profile.getDia())));
|
||||||
log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString());
|
log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString());
|
||||||
|
|
||||||
|
|
|
@ -18,7 +18,6 @@ import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.interfaces.APSInterface;
|
import info.nightscout.androidaps.interfaces.APSInterface;
|
||||||
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.interfaces.TempBasalsInterface;
|
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
|
||||||
|
@ -188,11 +187,10 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
|
||||||
|
|
||||||
Date start = new Date();
|
Date start = new Date();
|
||||||
TreatmentsInterface treatments = MainApp.getConfigBuilder().getActiveTreatments();
|
TreatmentsInterface treatments = MainApp.getConfigBuilder().getActiveTreatments();
|
||||||
TempBasalsInterface tempBasals = MainApp.getConfigBuilder().getActiveTempBasals();
|
|
||||||
treatments.updateTotalIOBTreatments();
|
treatments.updateTotalIOBTreatments();
|
||||||
tempBasals.updateTotalIOBTempBasals();
|
treatments.updateTotalIOBTempBasals();
|
||||||
IobTotal bolusIob = treatments.getLastCalculationTreatments();
|
IobTotal bolusIob = treatments.getLastCalculationTreatments();
|
||||||
IobTotal basalIob = tempBasals.getLastCalculationTempBasals();
|
IobTotal basalIob = treatments.getLastCalculationTempBasals();
|
||||||
|
|
||||||
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
|
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,6 @@ import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.events.EventNewBG;
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
import info.nightscout.androidaps.events.EventRefreshGui;
|
import info.nightscout.androidaps.events.EventRefreshGui;
|
||||||
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
|
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
|
@ -413,11 +412,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Co
|
||||||
TreatmentsInterface treatments = ConfigBuilderPlugin.getActiveTreatments();
|
TreatmentsInterface treatments = ConfigBuilderPlugin.getActiveTreatments();
|
||||||
treatments.updateTotalIOBTreatments();
|
treatments.updateTotalIOBTreatments();
|
||||||
IobTotal bolusIob = treatments.getLastCalculationTreatments();
|
IobTotal bolusIob = treatments.getLastCalculationTreatments();
|
||||||
TempBasalsInterface tempBasals = ConfigBuilderPlugin.getActiveTempBasals();
|
|
||||||
IobTotal basalIob = new IobTotal(new Date().getTime());
|
IobTotal basalIob = new IobTotal(new Date().getTime());
|
||||||
if (tempBasals != null) {
|
if (treatments != null) {
|
||||||
tempBasals.updateTotalIOBTempBasals();
|
treatments.updateTotalIOBTempBasals();
|
||||||
basalIob = tempBasals.getLastCalculationTempBasals().round();
|
basalIob = treatments.getLastCalculationTempBasals().round();
|
||||||
}
|
}
|
||||||
|
|
||||||
bolusIobInsulin.setText(DecimalFormatter.to2Decimal(-bolusIob.iob) + "U");
|
bolusIobInsulin.setText(DecimalFormatter.to2Decimal(-bolusIob.iob) + "U");
|
||||||
|
|
|
@ -997,12 +997,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
// iob
|
// iob
|
||||||
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments();
|
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments();
|
||||||
|
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTempBasals();
|
||||||
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round();
|
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round();
|
||||||
IobTotal basalIob = new IobTotal(new Date().getTime());
|
IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTempBasals().round();
|
||||||
if (ConfigBuilderPlugin.getActiveTempBasals() != null) {
|
|
||||||
ConfigBuilderPlugin.getActiveTempBasals().updateTotalIOBTempBasals();
|
|
||||||
basalIob = ConfigBuilderPlugin.getActiveTempBasals().getLastCalculationTempBasals().round();
|
|
||||||
}
|
|
||||||
|
|
||||||
String iobtext = getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
String iobtext = getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
||||||
+ getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
+ getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
||||||
|
@ -1015,7 +1012,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
getActivity().findViewById(R.id.overview_showprediction_label).setVisibility(View.VISIBLE);
|
getActivity().findViewById(R.id.overview_showprediction_label).setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
showPredictionView.setVisibility(View.GONE);
|
showPredictionView.setVisibility(View.GONE);
|
||||||
getActivity().findViewById(R.id.overview_showprediction_label).setVisibility(View.GONE); }
|
getActivity().findViewById(R.id.overview_showprediction_label).setVisibility(View.GONE);
|
||||||
|
}
|
||||||
|
|
||||||
// ****** GRAPH *******
|
// ****** GRAPH *******
|
||||||
|
|
||||||
|
@ -1138,6 +1136,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
// **** IOB COB DEV graph ****
|
// **** IOB COB DEV graph ****
|
||||||
class DeviationDataPoint extends DataPoint {
|
class DeviationDataPoint extends DataPoint {
|
||||||
public int color;
|
public int color;
|
||||||
|
|
||||||
public DeviationDataPoint(double x, double y, int color) {
|
public DeviationDataPoint(double x, double y, int color) {
|
||||||
super(x, y);
|
super(x, y);
|
||||||
this.color = color;
|
this.color = color;
|
||||||
|
|
|
@ -145,12 +145,10 @@ public class PersistentNotificationPlugin implements PluginBase{
|
||||||
|
|
||||||
//IOB
|
//IOB
|
||||||
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments();
|
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments();
|
||||||
|
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTempBasals();
|
||||||
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round();
|
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round();
|
||||||
IobTotal basalIob = new IobTotal(new Date().getTime());
|
IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTempBasals().round();
|
||||||
if (ConfigBuilderPlugin.getActiveTempBasals() != null) {
|
|
||||||
ConfigBuilderPlugin.getActiveTempBasals().updateTotalIOBTempBasals();
|
|
||||||
basalIob = ConfigBuilderPlugin.getActiveTempBasals().getLastCalculationTempBasals().round();
|
|
||||||
}
|
|
||||||
String line2 = ctx.getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
String line2 = ctx.getString(R.string.treatments_iob_label_string) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
||||||
+ ctx.getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
+ ctx.getString(R.string.bolus) + ": " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
||||||
+ ctx.getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
|
+ ctx.getString(R.string.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";
|
||||||
|
|
|
@ -351,20 +351,20 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
|
||||||
}
|
}
|
||||||
|
|
||||||
public TempBasal getTempBasal(Date time) {
|
public TempBasal getTempBasal(Date time) {
|
||||||
TempBasal temp = MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(time);
|
TempBasal temp = MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(time);
|
||||||
if (temp != null) return temp;
|
if (temp != null) return temp;
|
||||||
if (useExtendedBoluses)
|
if (useExtendedBoluses)
|
||||||
return MainApp.getConfigBuilder().getActiveTempBasals().getExtendedBolus(time);
|
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(time);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TempBasal getRealTempBasal() {
|
public TempBasal getRealTempBasal() {
|
||||||
return MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(new Date());
|
return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TempBasal getExtendedBolus() {
|
public TempBasal getExtendedBolus() {
|
||||||
return MainApp.getConfigBuilder().getActiveTempBasals().getExtendedBolus(new Date());
|
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -352,20 +352,20 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
|
||||||
}
|
}
|
||||||
|
|
||||||
public TempBasal getTempBasal(Date time) {
|
public TempBasal getTempBasal(Date time) {
|
||||||
TempBasal temp = MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(time);
|
TempBasal temp = MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(time);
|
||||||
if (temp != null) return temp;
|
if (temp != null) return temp;
|
||||||
if (useExtendedBoluses)
|
if (useExtendedBoluses)
|
||||||
return MainApp.getConfigBuilder().getActiveTempBasals().getExtendedBolus(time);
|
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(time);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public TempBasal getRealTempBasal() {
|
public TempBasal getRealTempBasal() {
|
||||||
return MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(new Date());
|
return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TempBasal getExtendedBolus() {
|
public TempBasal getExtendedBolus() {
|
||||||
return MainApp.getConfigBuilder().getActiveTempBasals().getExtendedBolus(new Date());
|
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -35,12 +35,12 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PumpDescription;
|
import info.nightscout.androidaps.interfaces.PumpDescription;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
|
||||||
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
|
||||||
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
|
||||||
import info.nightscout.androidaps.plugins.Overview.Notification;
|
import info.nightscout.androidaps.plugins.Overview.Notification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||||
|
import info.nightscout.androidaps.plugins.ProfileNS.NSProfilePlugin;
|
||||||
|
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
|
import info.nightscout.androidaps.plugins.PumpDanaRv2.services.DanaRv2ExecutionService;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
@ -309,17 +309,17 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
|
||||||
}
|
}
|
||||||
|
|
||||||
public TempBasal getTempBasal(Date time) {
|
public TempBasal getTempBasal(Date time) {
|
||||||
return MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(time);
|
return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TempBasal getTempBasal() {
|
public TempBasal getTempBasal() {
|
||||||
return MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(new Date());
|
return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TempBasal getExtendedBolus() {
|
public TempBasal getExtendedBolus() {
|
||||||
return MainApp.getConfigBuilder().getActiveTempBasals().getExtendedBolus(new Date());
|
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -209,12 +209,12 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TempBasal getTempBasal() {
|
public TempBasal getTempBasal() {
|
||||||
return ConfigBuilderPlugin.getActiveTempBasals().getTempBasal(new Date());
|
return ConfigBuilderPlugin.getActiveTreatments().getTempBasal(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TempBasal getExtendedBolus() {
|
public TempBasal getExtendedBolus() {
|
||||||
return ConfigBuilderPlugin.getActiveTempBasals().getExtendedBolus(new Date());
|
return ConfigBuilderPlugin.getActiveTreatments().getExtendedBolus(new Date());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -226,7 +226,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TempBasal getTempBasal(Date time) {
|
public TempBasal getTempBasal(Date time) {
|
||||||
return ConfigBuilderPlugin.getActiveTempBasals().getTempBasal(time);
|
return ConfigBuilderPlugin.getActiveTreatments().getTempBasal(time);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -256,8 +256,8 @@ public class SmsCommunicatorPlugin implements PluginBase {
|
||||||
|
|
||||||
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments();
|
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments();
|
||||||
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round();
|
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round();
|
||||||
ConfigBuilderPlugin.getActiveTempBasals().updateTotalIOBTempBasals();
|
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTempBasals();
|
||||||
IobTotal basalIob = ConfigBuilderPlugin.getActiveTempBasals().getLastCalculationTempBasals().round();
|
IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTempBasals().round();
|
||||||
|
|
||||||
reply += MainApp.sResources.getString(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
reply += MainApp.sResources.getString(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
||||||
+ MainApp.sResources.getString(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
+ MainApp.sResources.getString(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
||||||
|
|
|
@ -1,279 +0,0 @@
|
||||||
package info.nightscout.androidaps.plugins.TempBasals;
|
|
||||||
|
|
||||||
import android.support.annotation.Nullable;
|
|
||||||
|
|
||||||
import com.j256.ormlite.dao.Dao;
|
|
||||||
import com.squareup.otto.Subscribe;
|
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.sql.SQLException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import info.nightscout.androidaps.Config;
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
|
||||||
import info.nightscout.androidaps.R;
|
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
|
||||||
import info.nightscout.androidaps.db.TempBasal;
|
|
||||||
import info.nightscout.androidaps.events.EventPreferenceChange;
|
|
||||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
|
||||||
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
|
|
||||||
import info.nightscout.utils.SP;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by mike on 05.08.2016.
|
|
||||||
*/
|
|
||||||
public class TempBasalsPlugin implements PluginBase, TempBasalsInterface {
|
|
||||||
private static Logger log = LoggerFactory.getLogger(TempBasalsPlugin.class);
|
|
||||||
|
|
||||||
public static long lastCalculationTimestamp = 0;
|
|
||||||
public static IobTotal lastCalculation;
|
|
||||||
|
|
||||||
private static List<TempBasal> tempBasals;
|
|
||||||
private static List<TempBasal> extendedBoluses;
|
|
||||||
|
|
||||||
private static boolean useExtendedBoluses = false;
|
|
||||||
|
|
||||||
private static boolean fragmentEnabled = true;
|
|
||||||
private static boolean fragmentVisible = true;
|
|
||||||
|
|
||||||
public TempBasalsPlugin() {
|
|
||||||
useExtendedBoluses = SP.getBoolean("danar_useextended", false);
|
|
||||||
initializeData();
|
|
||||||
MainApp.bus().register(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getFragmentClass() {
|
|
||||||
return TempBasalsFragment.class.getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getName() {
|
|
||||||
return MainApp.instance().getString(R.string.tempbasals);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String getNameShort() {
|
|
||||||
String name = MainApp.sResources.getString(R.string.tempbasals_shortname);
|
|
||||||
if (!name.trim().isEmpty()){
|
|
||||||
//only if translation exists
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
// use long name as fallback
|
|
||||||
return getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isEnabled(int type) {
|
|
||||||
return type == TEMPBASAL && fragmentEnabled && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isVisibleInTabs(int type) {
|
|
||||||
return type == TEMPBASAL && fragmentVisible && MainApp.getConfigBuilder().getPumpDescription().isTempBasalCapable;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean canBeHidden(int type) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasFragment() {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean showInList(int type) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setFragmentEnabled(int type, boolean fragmentEnabled) {
|
|
||||||
if (type == TEMPBASAL) this.fragmentEnabled = fragmentEnabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setFragmentVisible(int type, boolean fragmentVisible) {
|
|
||||||
if (type == TEMPBASAL) this.fragmentVisible = fragmentVisible;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getType() {
|
|
||||||
return PluginBase.TEMPBASAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void initializeData() {
|
|
||||||
double dia = 3;
|
|
||||||
if (MainApp.getConfigBuilder().getActiveProfile() != null && MainApp.getConfigBuilder().getActiveProfile().getProfile() != null)
|
|
||||||
dia = MainApp.getConfigBuilder().getActiveProfile().getProfile().getDia();
|
|
||||||
long fromMills = (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + dia));
|
|
||||||
tempBasals = MainApp.getDbHelper().getTempbasalsDataFromTime(fromMills, false, false);
|
|
||||||
extendedBoluses = MainApp.getDbHelper().getTempbasalsDataFromTime(fromMills, false, true);
|
|
||||||
|
|
||||||
// Update ended
|
|
||||||
checkForExpiredExtended();
|
|
||||||
checkForExpiredTemps();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkForExpiredTemps() {
|
|
||||||
checkForExpired(tempBasals);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void checkForExpiredExtended() {
|
|
||||||
checkForExpired(extendedBoluses);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void checkForExpired(List<TempBasal> list) {
|
|
||||||
long now = new Date().getTime();
|
|
||||||
for (int position = list.size() - 1; position >= 0; position--) {
|
|
||||||
TempBasal t = list.get(position);
|
|
||||||
boolean update = false;
|
|
||||||
if (t.timeEnd == null && t.getPlannedTimeEnd() < now) {
|
|
||||||
t.timeEnd = new Date(t.getPlannedTimeEnd());
|
|
||||||
if (Config.logTempBasalsCut)
|
|
||||||
log.debug("Add timeEnd to old record");
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
if (position > 0) {
|
|
||||||
Date startofnewer = list.get(position - 1).timeStart;
|
|
||||||
if (t.timeEnd == null) {
|
|
||||||
t.timeEnd = new Date(Math.min(startofnewer.getTime(), t.getPlannedTimeEnd()));
|
|
||||||
if (Config.logTempBasalsCut)
|
|
||||||
log.debug("Add timeEnd to old record");
|
|
||||||
update = true;
|
|
||||||
} else if (t.timeEnd.getTime() > startofnewer.getTime()) {
|
|
||||||
t.timeEnd = startofnewer;
|
|
||||||
update = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (update) {
|
|
||||||
try {
|
|
||||||
Dao<TempBasal, Long> dao = MainApp.getDbHelper().getDaoTempBasals();
|
|
||||||
dao.update(t);
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (Config.logTempBasalsCut) {
|
|
||||||
log.debug("Fixing unfinished temp end: " + t.log());
|
|
||||||
if (position > 0)
|
|
||||||
log.debug("Previous: " + list.get(position - 1).log());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Recalculate IOB if value is older than 1 minute
|
|
||||||
*/
|
|
||||||
public void updateTotalIOBIfNeeded() {
|
|
||||||
if (lastCalculationTimestamp > new Date().getTime() - 60 * 1000)
|
|
||||||
return;
|
|
||||||
updateTotalIOBTempBasals();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IobTotal getLastCalculationTempBasals() {
|
|
||||||
return lastCalculation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IobTotal getCalculationToTimeTempBasals(long time) {
|
|
||||||
checkForExpired(tempBasals);
|
|
||||||
checkForExpired(extendedBoluses);
|
|
||||||
IobTotal total = new IobTotal(time);
|
|
||||||
for (Integer pos = 0; pos < tempBasals.size(); pos++) {
|
|
||||||
TempBasal t = tempBasals.get(pos);
|
|
||||||
if (t.timeStart.getTime() > time) continue;
|
|
||||||
IobTotal calc = t.iobCalc(time);
|
|
||||||
//log.debug("BasalIOB " + new Date(time) + " >>> " + calc.basaliob);
|
|
||||||
total.plus(calc);
|
|
||||||
}
|
|
||||||
if (useExtendedBoluses) {
|
|
||||||
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
|
|
||||||
TempBasal t = extendedBoluses.get(pos);
|
|
||||||
if (t.timeStart.getTime() > time) continue;
|
|
||||||
IobTotal calc = t.iobCalc(time);
|
|
||||||
total.plus(calc);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return total;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void updateTotalIOBTempBasals() {
|
|
||||||
IobTotal total = getCalculationToTimeTempBasals(new Date().getTime());
|
|
||||||
|
|
||||||
lastCalculationTimestamp = new Date().getTime();
|
|
||||||
lastCalculation = total;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
|
||||||
public TempBasal getTempBasal(Date time) {
|
|
||||||
checkForExpired(tempBasals);
|
|
||||||
for (TempBasal t : tempBasals) {
|
|
||||||
if (t.isInProgress(time)) return t;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TempBasal getExtendedBolus(Date time) {
|
|
||||||
checkForExpired(extendedBoluses);
|
|
||||||
for (TempBasal t : extendedBoluses) {
|
|
||||||
if (t.isInProgress(time)) return t;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public long oldestDataAvaialable() {
|
|
||||||
long oldestTemp = new Date().getTime();
|
|
||||||
if (tempBasals.size() > 0)
|
|
||||||
oldestTemp = Math.min(oldestTemp, tempBasals.get(tempBasals.size() - 1).timeStart.getTime());
|
|
||||||
if (extendedBoluses.size() > 0)
|
|
||||||
oldestTemp = Math.min(oldestTemp, extendedBoluses.get(extendedBoluses.size() - 1).timeStart.getTime());
|
|
||||||
oldestTemp -= 15 * 60 * 1000L; // allow 15 min before
|
|
||||||
return oldestTemp;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<TempBasal> getMergedList() {
|
|
||||||
if (useExtendedBoluses) {
|
|
||||||
List<TempBasal> merged = new ArrayList<TempBasal>();
|
|
||||||
merged.addAll(tempBasals);
|
|
||||||
merged.addAll(extendedBoluses);
|
|
||||||
|
|
||||||
class CustomComparator implements Comparator<TempBasal> {
|
|
||||||
public int compare(TempBasal object1, TempBasal object2) {
|
|
||||||
return (int) (object2.timeIndex - object1.timeIndex);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Collections.sort(merged, new CustomComparator());
|
|
||||||
return merged;
|
|
||||||
} else {
|
|
||||||
return tempBasals;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Subscribe
|
|
||||||
public void onStatusEvent(final EventTempBasalChange ev) {
|
|
||||||
initializeData();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void onStatusEvent(final EventPreferenceChange s) {
|
|
||||||
if (s.isChanged("danar_useextended")) {
|
|
||||||
useExtendedBoluses = SP.getBoolean("danar_useextended", false);
|
|
||||||
initializeData();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsBolusFragment;
|
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsBolusFragment;
|
||||||
|
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsTempBasalsFragment;
|
||||||
|
|
||||||
public class TreatmentsFragment extends Fragment {
|
public class TreatmentsFragment extends Fragment {
|
||||||
private static Logger log = LoggerFactory.getLogger(TreatmentsFragment.class);
|
private static Logger log = LoggerFactory.getLogger(TreatmentsFragment.class);
|
||||||
|
@ -32,6 +33,7 @@ public class TreatmentsFragment extends Fragment {
|
||||||
Context context;
|
Context context;
|
||||||
|
|
||||||
Fragment bolusFragment;
|
Fragment bolusFragment;
|
||||||
|
Fragment tempBasalsFragment;
|
||||||
|
|
||||||
public class SectionsPagerAdapter extends FragmentPagerAdapter {
|
public class SectionsPagerAdapter extends FragmentPagerAdapter {
|
||||||
|
|
||||||
|
@ -46,7 +48,7 @@ public class TreatmentsFragment extends Fragment {
|
||||||
case 0:
|
case 0:
|
||||||
return bolusFragment;
|
return bolusFragment;
|
||||||
case 1:
|
case 1:
|
||||||
return new Fragment();
|
return tempBasalsFragment;
|
||||||
/*
|
/*
|
||||||
case 2:
|
case 2:
|
||||||
return iobcobActiveFragmentObject;
|
return iobcobActiveFragmentObject;
|
||||||
|
@ -70,7 +72,7 @@ public class TreatmentsFragment extends Fragment {
|
||||||
case 0:
|
case 0:
|
||||||
return getString(R.string.bolus);
|
return getString(R.string.bolus);
|
||||||
case 1:
|
case 1:
|
||||||
return "Empty";
|
return getString(R.string.tempbasals);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -82,6 +84,7 @@ public class TreatmentsFragment extends Fragment {
|
||||||
View view = inflater.inflate(R.layout.treatments_fragment, container, false);
|
View view = inflater.inflate(R.layout.treatments_fragment, container, false);
|
||||||
|
|
||||||
bolusFragment = new TreatmentsBolusFragment();
|
bolusFragment = new TreatmentsBolusFragment();
|
||||||
|
tempBasalsFragment = new TreatmentsTempBasalsFragment();
|
||||||
|
|
||||||
sectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
|
sectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
|
||||||
viewPager = (ViewPager) view.findViewById(R.id.treatments_pager);
|
viewPager = (ViewPager) view.findViewById(R.id.treatments_pager);
|
||||||
|
|
|
@ -1,21 +1,31 @@
|
||||||
package info.nightscout.androidaps.plugins.Treatments;
|
package info.nightscout.androidaps.plugins.Treatments;
|
||||||
|
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
|
import com.j256.ormlite.dao.Dao;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.sql.SQLException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Comparator;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.Iob;
|
import info.nightscout.androidaps.data.Iob;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
|
import info.nightscout.androidaps.db.TempBasal;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
|
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||||
import info.nightscout.androidaps.events.EventTreatmentChange;
|
import info.nightscout.androidaps.events.EventTreatmentChange;
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
|
@ -32,14 +42,24 @@ import info.nightscout.utils.SP;
|
||||||
public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
private static Logger log = LoggerFactory.getLogger(TreatmentsPlugin.class);
|
private static Logger log = LoggerFactory.getLogger(TreatmentsPlugin.class);
|
||||||
|
|
||||||
public static long lastCalculationTimestamp = 0;
|
public static IobTotal lastTreatmentCalculation;
|
||||||
public static IobTotal lastCalculation;
|
public static IobTotal lastTempBasalsCalculation;
|
||||||
|
|
||||||
public static List<Treatment> treatments;
|
public static List<Treatment> treatments;
|
||||||
|
private static List<TempBasal> tempBasals;
|
||||||
|
private static List<TempBasal> extendedBoluses;
|
||||||
|
|
||||||
|
private static boolean useExtendedBoluses = false;
|
||||||
|
|
||||||
private static boolean fragmentEnabled = true;
|
private static boolean fragmentEnabled = true;
|
||||||
private static boolean fragmentVisible = true;
|
private static boolean fragmentVisible = true;
|
||||||
|
|
||||||
|
private static TreatmentsPlugin treatmentsPlugin = new TreatmentsPlugin();
|
||||||
|
|
||||||
|
public static TreatmentsPlugin getPlugin() {
|
||||||
|
return treatmentsPlugin;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getFragmentClass() {
|
public String getFragmentClass() {
|
||||||
return TreatmentsFragment.class.getName();
|
return TreatmentsFragment.class.getName();
|
||||||
|
@ -102,30 +122,78 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
}
|
}
|
||||||
|
|
||||||
public TreatmentsPlugin() {
|
public TreatmentsPlugin() {
|
||||||
|
useExtendedBoluses = SP.getBoolean("danar_useextended", false);
|
||||||
MainApp.bus().register(this);
|
MainApp.bus().register(this);
|
||||||
initializeData();
|
initializeData();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void initializeData() {
|
public static void initializeData() {
|
||||||
|
// Treatments
|
||||||
double dia = Constants.defaultDIA;
|
double dia = Constants.defaultDIA;
|
||||||
if (MainApp.getConfigBuilder().getActiveProfile() != null && MainApp.getConfigBuilder().getActiveProfile().getProfile() != null)
|
if (MainApp.getConfigBuilder().getActiveProfile() != null && MainApp.getConfigBuilder().getActiveProfile().getProfile() != null)
|
||||||
dia = MainApp.getConfigBuilder().getActiveProfile().getProfile().getDia();
|
dia = MainApp.getConfigBuilder().getActiveProfile().getProfile().getDia();
|
||||||
long fromMills = (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + dia));
|
long fromMills = (long) (new Date().getTime() - 60 * 60 * 1000L * (24 + dia));
|
||||||
treatments = MainApp.getDbHelper().getTreatmentDataFromTime(fromMills, false);
|
treatments = MainApp.getDbHelper().getTreatmentDataFromTime(fromMills, false);
|
||||||
|
|
||||||
|
// Temp basals
|
||||||
|
tempBasals = MainApp.getDbHelper().getTempbasalsDataFromTime(fromMills, false, false);
|
||||||
|
extendedBoluses = MainApp.getDbHelper().getTempbasalsDataFromTime(fromMills, false, true);
|
||||||
|
|
||||||
|
// Update ended
|
||||||
|
checkForExpiredExtended();
|
||||||
|
checkForExpiredTemps();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
public static void checkForExpiredTemps() {
|
||||||
* Recalculate IOB if value is older than 1 minute
|
checkForExpired(tempBasals);
|
||||||
*/
|
}
|
||||||
public void updateTotalIOBIfNeeded() {
|
|
||||||
if (lastCalculationTimestamp > new Date().getTime() - 60 * 1000)
|
public static void checkForExpiredExtended() {
|
||||||
return;
|
checkForExpired(extendedBoluses);
|
||||||
updateTotalIOBTreatments();
|
}
|
||||||
|
|
||||||
|
private static void checkForExpired(List<TempBasal> list) {
|
||||||
|
long now = new Date().getTime();
|
||||||
|
for (int position = list.size() - 1; position >= 0; position--) {
|
||||||
|
TempBasal t = list.get(position);
|
||||||
|
boolean update = false;
|
||||||
|
if (t.timeEnd == null && t.getPlannedTimeEnd() < now) {
|
||||||
|
t.timeEnd = new Date(t.getPlannedTimeEnd());
|
||||||
|
if (Config.logTempBasalsCut)
|
||||||
|
log.debug("Add timeEnd to old record");
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
if (position > 0) {
|
||||||
|
Date startofnewer = list.get(position - 1).timeStart;
|
||||||
|
if (t.timeEnd == null) {
|
||||||
|
t.timeEnd = new Date(Math.min(startofnewer.getTime(), t.getPlannedTimeEnd()));
|
||||||
|
if (Config.logTempBasalsCut)
|
||||||
|
log.debug("Add timeEnd to old record");
|
||||||
|
update = true;
|
||||||
|
} else if (t.timeEnd.getTime() > startofnewer.getTime()) {
|
||||||
|
t.timeEnd = startofnewer;
|
||||||
|
update = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (update) {
|
||||||
|
try {
|
||||||
|
Dao<TempBasal, Long> dao = MainApp.getDbHelper().getDaoTempBasals();
|
||||||
|
dao.update(t);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
if (Config.logTempBasalsCut) {
|
||||||
|
log.debug("Fixing unfinished temp end: " + t.log());
|
||||||
|
if (position > 0)
|
||||||
|
log.debug("Previous: " + list.get(position - 1).log());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IobTotal getLastCalculationTreatments() {
|
public IobTotal getLastCalculationTreatments() {
|
||||||
return lastCalculation;
|
return lastTreatmentCalculation;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -157,8 +225,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
public void updateTotalIOBTreatments() {
|
public void updateTotalIOBTreatments() {
|
||||||
IobTotal total = getCalculationToTimeTreatments(new Date().getTime());
|
IobTotal total = getCalculationToTimeTreatments(new Date().getTime());
|
||||||
|
|
||||||
lastCalculationTimestamp = new Date().getTime();
|
lastTreatmentCalculation = total;
|
||||||
lastCalculation = total;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -212,4 +279,98 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
|
||||||
updateTotalIOBTreatments();
|
updateTotalIOBTreatments();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IobTotal getLastCalculationTempBasals() {
|
||||||
|
return lastTempBasalsCalculation;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public IobTotal getCalculationToTimeTempBasals(long time) {
|
||||||
|
checkForExpired(tempBasals);
|
||||||
|
checkForExpired(extendedBoluses);
|
||||||
|
IobTotal total = new IobTotal(time);
|
||||||
|
for (Integer pos = 0; pos < tempBasals.size(); pos++) {
|
||||||
|
TempBasal t = tempBasals.get(pos);
|
||||||
|
if (t.timeStart.getTime() > time) continue;
|
||||||
|
IobTotal calc = t.iobCalc(time);
|
||||||
|
//log.debug("BasalIOB " + new Date(time) + " >>> " + calc.basaliob);
|
||||||
|
total.plus(calc);
|
||||||
|
}
|
||||||
|
if (useExtendedBoluses) {
|
||||||
|
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
|
||||||
|
TempBasal t = extendedBoluses.get(pos);
|
||||||
|
if (t.timeStart.getTime() > time) continue;
|
||||||
|
IobTotal calc = t.iobCalc(time);
|
||||||
|
total.plus(calc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return total;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateTotalIOBTempBasals() {
|
||||||
|
IobTotal total = getCalculationToTimeTempBasals(new Date().getTime());
|
||||||
|
|
||||||
|
lastTempBasalsCalculation = total;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public TempBasal getTempBasal(Date time) {
|
||||||
|
checkForExpired(tempBasals);
|
||||||
|
for (TempBasal t : tempBasals) {
|
||||||
|
if (t.isInProgress(time)) return t;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public TempBasal getExtendedBolus(Date time) {
|
||||||
|
checkForExpired(extendedBoluses);
|
||||||
|
for (TempBasal t : extendedBoluses) {
|
||||||
|
if (t.isInProgress(time)) return t;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long oldestDataAvaialable() {
|
||||||
|
long oldestTemp = new Date().getTime();
|
||||||
|
if (tempBasals.size() > 0)
|
||||||
|
oldestTemp = Math.min(oldestTemp, tempBasals.get(tempBasals.size() - 1).timeStart.getTime());
|
||||||
|
if (extendedBoluses.size() > 0)
|
||||||
|
oldestTemp = Math.min(oldestTemp, extendedBoluses.get(extendedBoluses.size() - 1).timeStart.getTime());
|
||||||
|
oldestTemp -= 15 * 60 * 1000L; // allow 15 min before
|
||||||
|
return oldestTemp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<TempBasal> getMergedList() {
|
||||||
|
if (useExtendedBoluses) {
|
||||||
|
List<TempBasal> merged = new ArrayList<TempBasal>();
|
||||||
|
merged.addAll(tempBasals);
|
||||||
|
merged.addAll(extendedBoluses);
|
||||||
|
|
||||||
|
class CustomComparator implements Comparator<TempBasal> {
|
||||||
|
public int compare(TempBasal object1, TempBasal object2) {
|
||||||
|
return (int) (object2.timeIndex - object1.timeIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Collections.sort(merged, new CustomComparator());
|
||||||
|
return merged;
|
||||||
|
} else {
|
||||||
|
return tempBasals;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onStatusEvent(final EventTempBasalChange ev) {
|
||||||
|
initializeData();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onStatusEvent(final EventPreferenceChange s) {
|
||||||
|
if (s.isChanged("danar_useextended")) {
|
||||||
|
useExtendedBoluses = SP.getBoolean("danar_useextended", false);
|
||||||
|
initializeData();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,12 +47,6 @@ import info.nightscout.utils.ToastUtils;
|
||||||
public class TreatmentsBolusFragment extends Fragment implements View.OnClickListener {
|
public class TreatmentsBolusFragment extends Fragment implements View.OnClickListener {
|
||||||
private static Logger log = LoggerFactory.getLogger(TreatmentsBolusFragment.class);
|
private static Logger log = LoggerFactory.getLogger(TreatmentsBolusFragment.class);
|
||||||
|
|
||||||
private static TreatmentsPlugin treatmentsPlugin = new TreatmentsPlugin();
|
|
||||||
|
|
||||||
public static TreatmentsPlugin getPlugin() {
|
|
||||||
return treatmentsPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
RecyclerView recyclerView;
|
RecyclerView recyclerView;
|
||||||
LinearLayoutManager llm;
|
LinearLayoutManager llm;
|
||||||
|
|
||||||
|
@ -149,7 +143,7 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
|
||||||
MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
|
MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
|
||||||
}
|
}
|
||||||
MainApp.getDbHelper().delete(treatment);
|
MainApp.getDbHelper().delete(treatment);
|
||||||
treatmentsPlugin.initializeData();
|
TreatmentsPlugin.initializeData();
|
||||||
updateGUI();
|
updateGUI();
|
||||||
Answers.getInstance().logCustom(new CustomEvent("RemoveTreatment"));
|
Answers.getInstance().logCustom(new CustomEvent("RemoveTreatment"));
|
||||||
}
|
}
|
||||||
|
@ -201,7 +195,7 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
|
||||||
builder.setPositiveButton(this.getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(this.getContext().getString(R.string.ok), new DialogInterface.OnClickListener() {
|
||||||
public void onClick(DialogInterface dialog, int id) {
|
public void onClick(DialogInterface dialog, int id) {
|
||||||
MainApp.getDbHelper().resetTreatments();
|
MainApp.getDbHelper().resetTreatments();
|
||||||
treatmentsPlugin.initializeData();
|
TreatmentsPlugin.initializeData();
|
||||||
updateGUI();
|
updateGUI();
|
||||||
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
|
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
|
||||||
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
|
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
|
||||||
|
@ -242,10 +236,10 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.treatments), false);
|
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.treatments), false);
|
||||||
if (TreatmentsPlugin.lastCalculation != null)
|
if (TreatmentsPlugin.lastTreatmentCalculation != null)
|
||||||
iobTotal.setText(DecimalFormatter.to2Decimal(TreatmentsPlugin.lastCalculation.iob) + " U");
|
iobTotal.setText(DecimalFormatter.to2Decimal(TreatmentsPlugin.lastTreatmentCalculation.iob) + " U");
|
||||||
if (TreatmentsPlugin.lastCalculation != null)
|
if (TreatmentsPlugin.lastTreatmentCalculation != null)
|
||||||
activityTotal.setText(DecimalFormatter.to3Decimal(TreatmentsPlugin.lastCalculation.activity) + " U");
|
activityTotal.setText(DecimalFormatter.to3Decimal(TreatmentsPlugin.lastTreatmentCalculation.activity) + " U");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package info.nightscout.androidaps.plugins.TempBasals;
|
package info.nightscout.androidaps.plugins.Treatments.fragments;
|
||||||
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -32,18 +32,13 @@ import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.db.TempBasal;
|
import info.nightscout.androidaps.db.TempBasal;
|
||||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||||
|
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
|
||||||
|
|
||||||
public class TempBasalsFragment extends Fragment {
|
public class TreatmentsTempBasalsFragment extends Fragment {
|
||||||
private static Logger log = LoggerFactory.getLogger(TempBasalsFragment.class);
|
private static Logger log = LoggerFactory.getLogger(TreatmentsTempBasalsFragment.class);
|
||||||
|
|
||||||
private static TempBasalsPlugin tempBasalsPlugin = new TempBasalsPlugin();
|
|
||||||
|
|
||||||
public static TempBasalsPlugin getPlugin() {
|
|
||||||
return tempBasalsPlugin;
|
|
||||||
}
|
|
||||||
|
|
||||||
RecyclerView recyclerView;
|
RecyclerView recyclerView;
|
||||||
LinearLayoutManager llm;
|
LinearLayoutManager llm;
|
||||||
|
@ -157,7 +152,7 @@ public class TempBasalsFragment extends Fragment {
|
||||||
// MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
|
// MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
|
||||||
//}
|
//}
|
||||||
MainApp.getDbHelper().delete(tempBasal);
|
MainApp.getDbHelper().delete(tempBasal);
|
||||||
tempBasalsPlugin.initializeData();
|
TreatmentsPlugin.initializeData();
|
||||||
updateGUI();
|
updateGUI();
|
||||||
Answers.getInstance().logCustom(new CustomEvent("RemoveTempBasal"));
|
Answers.getInstance().logCustom(new CustomEvent("RemoveTempBasal"));
|
||||||
}
|
}
|
||||||
|
@ -180,7 +175,7 @@ public class TempBasalsFragment extends Fragment {
|
||||||
llm = new LinearLayoutManager(view.getContext());
|
llm = new LinearLayoutManager(view.getContext());
|
||||||
recyclerView.setLayoutManager(llm);
|
recyclerView.setLayoutManager(llm);
|
||||||
|
|
||||||
RecyclerViewAdapter adapter = new RecyclerViewAdapter(tempBasalsPlugin.getMergedList());
|
RecyclerViewAdapter adapter = new RecyclerViewAdapter(TreatmentsPlugin.getMergedList());
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
tempBasalTotalView = (TextView) view.findViewById(R.id.tempbasals_totaltempiob);
|
tempBasalTotalView = (TextView) view.findViewById(R.id.tempbasals_totaltempiob);
|
||||||
|
@ -214,9 +209,9 @@ public class TempBasalsFragment extends Fragment {
|
||||||
activity.runOnUiThread(new Runnable() {
|
activity.runOnUiThread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
recyclerView.swapAdapter(new RecyclerViewAdapter(tempBasalsPlugin.getMergedList()), false);
|
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getMergedList()), false);
|
||||||
if (tempBasalsPlugin.lastCalculation != null) {
|
if (TreatmentsPlugin.lastTempBasalsCalculation != null) {
|
||||||
String totalText = DecimalFormatter.to2Decimal(tempBasalsPlugin.lastCalculation.basaliob) + " U";
|
String totalText = DecimalFormatter.to2Decimal(TreatmentsPlugin.lastTempBasalsCalculation.basaliob) + " U";
|
||||||
tempBasalTotalView.setText(totalText);
|
tempBasalTotalView.setText(totalText);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -546,8 +546,8 @@ public class WatchUpdaterService extends WearableListenerService implements
|
||||||
//IOB
|
//IOB
|
||||||
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTreatments();
|
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTreatments();
|
||||||
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTreatments().round();
|
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTreatments().round();
|
||||||
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOBTempBasals();
|
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTempBasals();
|
||||||
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculationTempBasals().round();
|
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTempBasals().round();
|
||||||
status += (shortString?"":(getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);
|
status += (shortString?"":(getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);
|
||||||
|
|
||||||
if (mPrefs.getBoolean("wear_detailediob", true)) {
|
if (mPrefs.getBoolean("wear_detailediob", true)) {
|
||||||
|
|
|
@ -172,8 +172,8 @@ public class StatuslinePlugin implements PluginBase {
|
||||||
//IOB
|
//IOB
|
||||||
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTreatments();
|
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTreatments();
|
||||||
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTreatments().round();
|
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTreatments().round();
|
||||||
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOBTempBasals();
|
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTempBasals();
|
||||||
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculationTempBasals().round();
|
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTempBasals().round();
|
||||||
status += (shortString ? "" : (ctx.getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);
|
status += (shortString ? "" : (ctx.getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,6 @@ import org.json.JSONObject;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
|
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
|
|
||||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
|
@ -88,13 +87,9 @@ public class BolusWizard {
|
||||||
// IOB calculation
|
// IOB calculation
|
||||||
TreatmentsInterface treatments = ConfigBuilderPlugin.getActiveTreatments();
|
TreatmentsInterface treatments = ConfigBuilderPlugin.getActiveTreatments();
|
||||||
treatments.updateTotalIOBTreatments();
|
treatments.updateTotalIOBTreatments();
|
||||||
IobTotal bolusIob = treatments.getLastCalculationTreatments();
|
IobTotal bolusIob = treatments.getLastCalculationTreatments().round();
|
||||||
TempBasalsInterface tempBasals = ConfigBuilderPlugin.getActiveTempBasals();
|
treatments.updateTotalIOBTempBasals();
|
||||||
IobTotal basalIob = new IobTotal(new Date().getTime());
|
IobTotal basalIob = treatments.getLastCalculationTempBasals().round();
|
||||||
if (tempBasals != null) {
|
|
||||||
tempBasals.updateTotalIOBTempBasals();
|
|
||||||
basalIob = tempBasals.getLastCalculationTempBasals().round();
|
|
||||||
}
|
|
||||||
|
|
||||||
insulingFromBolusIOB = includeBolusIOB ? -bolusIob.iob : 0d;
|
insulingFromBolusIOB = includeBolusIOB ? -bolusIob.iob : 0d;
|
||||||
insulingFromBasalsIOB = includeBasalIOB ? -basalIob.basaliob : 0d;
|
insulingFromBasalsIOB = includeBasalIOB ? -basalIob.basaliob : 0d;
|
||||||
|
|
|
@ -144,24 +144,6 @@
|
||||||
android:layout_marginRight="10dp"
|
android:layout_marginRight="10dp"
|
||||||
android:background="@color/cardColorBackground" />
|
android:background="@color/cardColorBackground" />
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/configbuilder_tempslabel"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginLeft="5dp"
|
|
||||||
android:text="@string/configbuilder_tempbasals"
|
|
||||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
|
||||||
android:textStyle="bold" />
|
|
||||||
|
|
||||||
<ListView
|
|
||||||
android:id="@+id/configbuilder_tempslistview"
|
|
||||||
android:layout_width="match_parent"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:layout_marginLeft="10dp"
|
|
||||||
android:layout_marginRight="10dp"
|
|
||||||
android:background="@color/cardColorBackground" />
|
|
||||||
|
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/configbuilder_constraintslabel"
|
android:id="@+id/configbuilder_constraintslabel"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment">
|
tools:context="info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsTempBasalsFragment">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context="info.nightscout.androidaps.plugins.TempBasals.TempBasalsFragment">
|
tools:context="info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsTempBasalsFragment">
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
|
|
Loading…
Reference in a new issue