merge bolus & basal into one plugin

This commit is contained in:
Milos Kozak 2017-05-12 16:27:33 +02:00
parent eddd8ac56d
commit abdc1022bf
28 changed files with 256 additions and 449 deletions

View file

@ -50,14 +50,12 @@ import info.nightscout.androidaps.plugins.SourceGlimp.SourceGlimpFragment;
import info.nightscout.androidaps.plugins.SourceMM640g.SourceMM640gFragment;
import info.nightscout.androidaps.plugins.SourceNSClient.SourceNSClientFragment;
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.Treatments.TreatmentsFragment;
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpFragment;
import info.nightscout.androidaps.plugins.Wear.WearFragment;
import info.nightscout.androidaps.plugins.Persistentnotification.PersistentNotificationPlugin;
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslineFragment;
import info.nightscout.androidaps.plugins.XDripStatusline.StatuslinePlugin;
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
import io.fabric.sdk.android.Fabric;
@ -114,7 +112,6 @@ public class MainApp extends Application {
pluginsList.add(CircadianPercentageProfileFragment.getPlugin());
if (Config.APS) pluginsList.add(TempTargetRangeFragment.getPlugin());
pluginsList.add(TreatmentsFragment.getPlugin());
if (Config.TEMPBASALS) pluginsList.add(TempBasalsFragment.getPlugin());
if (Config.SAFETY) pluginsList.add(SafetyFragment.getPlugin());
if (Config.APS) pluginsList.add(ObjectivesFragment.getPlugin());
pluginsList.add(SourceXdripFragment.getPlugin());

View file

@ -8,7 +8,7 @@ import java.util.Date;
public interface PluginBase {
int GENERAL = 1;
int TREATMENT = 2;
int TEMPBASAL = 3;
//int TEMPBASAL = 3;
int PROFILE = 4;
int APS = 5;
int PUMP = 6;

View file

@ -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();
}

View file

@ -1,8 +1,10 @@
package info.nightscout.androidaps.interfaces;
import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.data.IobTotal;
@ -12,9 +14,21 @@ import info.nightscout.androidaps.data.IobTotal;
public interface TreatmentsInterface {
void updateTotalIOBTreatments();
void updateTotalIOBTempBasals();
IobTotal getLastCalculationTreatments();
IobTotal getCalculationToTimeTreatments(long time);
IobTotal getLastCalculationTempBasals();
IobTotal getCalculationToTimeTempBasals(long time);
MealData getMealData();
List<Treatment> getTreatments();
List<Treatment> getTreatments5MinBack(long time);
TempBasal getTempBasal (Date time);
TempBasal getExtendedBolus (Date time);
long oldestDataAvaialable();
}

View file

@ -55,8 +55,6 @@ public class ConfigBuilderFragment extends Fragment {
ListView loopListView;
TextView loopLabel;
ListView treatmentsListView;
ListView tempsListView;
TextView tempsLabel;
ListView profileListView;
ListView apsListView;
TextView apsLabel;
@ -74,7 +72,6 @@ public class ConfigBuilderFragment extends Fragment {
PluginCustomAdapter pumpDataAdapter = null;
PluginCustomAdapter loopDataAdapter = null;
PluginCustomAdapter treatmentsDataAdapter = null;
PluginCustomAdapter tempsDataAdapter = null;
PluginCustomAdapter profileDataAdapter = null;
PluginCustomAdapter apsDataAdapter = null;
PluginCustomAdapter constraintsDataAdapter = null;
@ -102,8 +99,6 @@ public class ConfigBuilderFragment extends Fragment {
loopListView = (ListView) view.findViewById(R.id.configbuilder_looplistview);
loopLabel = (TextView) view.findViewById(R.id.configbuilder_looplabel);
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);
apsListView = (ListView) view.findViewById(R.id.configbuilder_apslistview);
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);
treatmentsListView.setAdapter(treatmentsDataAdapter);
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);
profileListView.setAdapter(profileDataAdapter);
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
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) {
holder.checkboxEnabled.setEnabled(false);
plugin.setFragmentEnabled(type, true);
@ -333,7 +323,6 @@ public class ConfigBuilderFragment extends Fragment {
case PluginBase.BGSOURCE:
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(BgSourceInterface.class);
break;
case PluginBase.TEMPBASAL:
case PluginBase.TREATMENT:
case PluginBase.PUMP:
pluginsInCategory = MainApp.getSpecificPluginsListByInterface(PumpInterface.class);

View file

@ -35,12 +35,12 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
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.DeviceStatus;
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.OpenAPSMA.DetermineBasalResultMA;
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.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.NSClientInternal.data.DbLogger;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgError;
import info.nightscout.utils.BatteryLevel;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SP;
@ -65,7 +64,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
static PumpInterface activePump;
static ProfileInterface activeProfile;
static TreatmentsInterface activeTreatments;
static TempBasalsInterface activeTempBasals;
static APSInterface activeAPS;
static LoopPlugin activeLoop;
static InsulinInterface activeInsulin;
@ -206,10 +204,6 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
return activeTreatments;
}
public static TempBasalsInterface getActiveTempBasals() {
return activeTempBasals;
}
public static InsulinInterface getActiveInsulin() {
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
pluginsInCategory = MainApp.getSpecificPluginsList(PluginBase.TREATMENT);
activeTreatments = (TreatmentsInterface) getTheOneEnabledInArray(pluginsInCategory, PluginBase.TREATMENT);

View file

@ -339,7 +339,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
//log.debug(">>> Cache miss " + new Date(time).toLocaleString());
}
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) {
log.debug(new Date(time).toLocaleString() + " basaliob: " + basalIob.basaliob );

View file

@ -222,7 +222,7 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) 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())));
log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString());

View file

@ -18,7 +18,6 @@ import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.interfaces.APSInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.Loop.APSResult;
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
@ -188,11 +187,10 @@ public class OpenAPSMAPlugin implements PluginBase, APSInterface {
Date start = new Date();
TreatmentsInterface treatments = MainApp.getConfigBuilder().getActiveTreatments();
TempBasalsInterface tempBasals = MainApp.getConfigBuilder().getActiveTempBasals();
treatments.updateTotalIOBTreatments();
tempBasals.updateTotalIOBTempBasals();
treatments.updateTotalIOBTempBasals();
IobTotal bolusIob = treatments.getLastCalculationTreatments();
IobTotal basalIob = tempBasals.getLastCalculationTempBasals();
IobTotal basalIob = treatments.getLastCalculationTempBasals();
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();

View file

@ -47,7 +47,6 @@ import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.data.IobTotal;
@ -413,11 +412,10 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Co
TreatmentsInterface treatments = ConfigBuilderPlugin.getActiveTreatments();
treatments.updateTotalIOBTreatments();
IobTotal bolusIob = treatments.getLastCalculationTreatments();
TempBasalsInterface tempBasals = ConfigBuilderPlugin.getActiveTempBasals();
IobTotal basalIob = new IobTotal(new Date().getTime());
if (tempBasals != null) {
tempBasals.updateTotalIOBTempBasals();
basalIob = tempBasals.getLastCalculationTempBasals().round();
if (treatments != null) {
treatments.updateTotalIOBTempBasals();
basalIob = treatments.getLastCalculationTempBasals().round();
}
bolusIobInsulin.setText(DecimalFormatter.to2Decimal(-bolusIob.iob) + "U");

View file

@ -192,7 +192,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
bgView = (TextView) view.findViewById(R.id.overview_bg);
arrowView = (TextView) view.findViewById(R.id.overview_arrow);
if(smallWidth){
if (smallWidth) {
arrowView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 35);
}
timeAgoView = (TextView) view.findViewById(R.id.overview_timeago);
@ -997,12 +997,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// iob
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments();
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTempBasals();
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round();
IobTotal basalIob = new IobTotal(new Date().getTime());
if (ConfigBuilderPlugin.getActiveTempBasals() != null) {
ConfigBuilderPlugin.getActiveTempBasals().updateTotalIOBTempBasals();
basalIob = ConfigBuilderPlugin.getActiveTempBasals().getLastCalculationTempBasals().round();
}
IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTempBasals().round();
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 "
@ -1015,7 +1012,8 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
getActivity().findViewById(R.id.overview_showprediction_label).setVisibility(View.VISIBLE);
} else {
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 *******
@ -1138,6 +1136,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
// **** IOB COB DEV graph ****
class DeviationDataPoint extends DataPoint {
public int color;
public DeviationDataPoint(double x, double y, int color) {
super(x, y);
this.color = color;

View file

@ -145,12 +145,10 @@ public class PersistentNotificationPlugin implements PluginBase{
//IOB
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments();
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTempBasals();
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round();
IobTotal basalIob = new IobTotal(new Date().getTime());
if (ConfigBuilderPlugin.getActiveTempBasals() != null) {
ConfigBuilderPlugin.getActiveTempBasals().updateTotalIOBTempBasals();
basalIob = ConfigBuilderPlugin.getActiveTempBasals().getLastCalculationTempBasals().round();
}
IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTempBasals().round();
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.basal) + ": " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U)";

View file

@ -351,20 +351,20 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
}
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 (useExtendedBoluses)
return MainApp.getConfigBuilder().getActiveTempBasals().getExtendedBolus(time);
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(time);
return null;
}
public TempBasal getRealTempBasal() {
return MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(new Date());
return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(new Date());
}
@Override
public TempBasal getExtendedBolus() {
return MainApp.getConfigBuilder().getActiveTempBasals().getExtendedBolus(new Date());
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(new Date());
}
@Override

View file

@ -352,20 +352,20 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
}
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 (useExtendedBoluses)
return MainApp.getConfigBuilder().getActiveTempBasals().getExtendedBolus(time);
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(time);
return null;
}
public TempBasal getRealTempBasal() {
return MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(new Date());
return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(new Date());
}
@Override
public TempBasal getExtendedBolus() {
return MainApp.getConfigBuilder().getActiveTempBasals().getExtendedBolus(new Date());
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(new Date());
}
@Override

View file

@ -35,12 +35,12 @@ import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
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.ProfileNS.NSProfilePlugin;
import info.nightscout.androidaps.plugins.Overview.Notification;
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
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.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
@ -309,17 +309,17 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
}
public TempBasal getTempBasal(Date time) {
return MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(time);
return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(time);
}
@Override
public TempBasal getTempBasal() {
return MainApp.getConfigBuilder().getActiveTempBasals().getTempBasal(new Date());
return MainApp.getConfigBuilder().getActiveTreatments().getTempBasal(new Date());
}
@Override
public TempBasal getExtendedBolus() {
return MainApp.getConfigBuilder().getActiveTempBasals().getExtendedBolus(new Date());
return MainApp.getConfigBuilder().getActiveTreatments().getExtendedBolus(new Date());
}
@Override

View file

@ -209,12 +209,12 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
@Override
public TempBasal getTempBasal() {
return ConfigBuilderPlugin.getActiveTempBasals().getTempBasal(new Date());
return ConfigBuilderPlugin.getActiveTreatments().getTempBasal(new Date());
}
@Override
public TempBasal getExtendedBolus() {
return ConfigBuilderPlugin.getActiveTempBasals().getExtendedBolus(new Date());
return ConfigBuilderPlugin.getActiveTreatments().getExtendedBolus(new Date());
}
@Override
@ -226,7 +226,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
@Override
public TempBasal getTempBasal(Date time) {
return ConfigBuilderPlugin.getActiveTempBasals().getTempBasal(time);
return ConfigBuilderPlugin.getActiveTreatments().getTempBasal(time);
}
@Override

View file

@ -256,8 +256,8 @@ public class SmsCommunicatorPlugin implements PluginBase {
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTreatments();
IobTotal bolusIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTreatments().round();
ConfigBuilderPlugin.getActiveTempBasals().updateTotalIOBTempBasals();
IobTotal basalIob = ConfigBuilderPlugin.getActiveTempBasals().getLastCalculationTempBasals().round();
ConfigBuilderPlugin.getActiveTreatments().updateTotalIOBTempBasals();
IobTotal basalIob = ConfigBuilderPlugin.getActiveTreatments().getLastCalculationTempBasals().round();
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 "

View file

@ -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();
}
}
}

View file

@ -16,6 +16,7 @@ import org.slf4j.LoggerFactory;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsBolusFragment;
import info.nightscout.androidaps.plugins.Treatments.fragments.TreatmentsTempBasalsFragment;
public class TreatmentsFragment extends Fragment {
private static Logger log = LoggerFactory.getLogger(TreatmentsFragment.class);
@ -32,6 +33,7 @@ public class TreatmentsFragment extends Fragment {
Context context;
Fragment bolusFragment;
Fragment tempBasalsFragment;
public class SectionsPagerAdapter extends FragmentPagerAdapter {
@ -46,7 +48,7 @@ public class TreatmentsFragment extends Fragment {
case 0:
return bolusFragment;
case 1:
return new Fragment();
return tempBasalsFragment;
/*
case 2:
return iobcobActiveFragmentObject;
@ -70,7 +72,7 @@ public class TreatmentsFragment extends Fragment {
case 0:
return getString(R.string.bolus);
case 1:
return "Empty";
return getString(R.string.tempbasals);
}
return null;
}
@ -82,6 +84,7 @@ public class TreatmentsFragment extends Fragment {
View view = inflater.inflate(R.layout.treatments_fragment, container, false);
bolusFragment = new TreatmentsBolusFragment();
tempBasalsFragment = new TreatmentsTempBasalsFragment();
sectionsPagerAdapter = new SectionsPagerAdapter(getChildFragmentManager());
viewPager = (ViewPager) view.findViewById(R.id.treatments_pager);

View file

@ -1,21 +1,31 @@
package info.nightscout.androidaps.plugins.Treatments;
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.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.db.TempBasal;
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.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
@ -32,14 +42,24 @@ import info.nightscout.utils.SP;
public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
private static Logger log = LoggerFactory.getLogger(TreatmentsPlugin.class);
public static long lastCalculationTimestamp = 0;
public static IobTotal lastCalculation;
public static IobTotal lastTreatmentCalculation;
public static IobTotal lastTempBasalsCalculation;
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 fragmentVisible = true;
private static TreatmentsPlugin treatmentsPlugin = new TreatmentsPlugin();
public static TreatmentsPlugin getPlugin() {
return treatmentsPlugin;
}
@Override
public String getFragmentClass() {
return TreatmentsFragment.class.getName();
@ -102,30 +122,78 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
}
public TreatmentsPlugin() {
useExtendedBoluses = SP.getBoolean("danar_useextended", false);
MainApp.bus().register(this);
initializeData();
}
public void initializeData() {
public static void initializeData() {
// Treatments
double dia = Constants.defaultDIA;
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));
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();
}
/*
* Recalculate IOB if value is older than 1 minute
*/
public void updateTotalIOBIfNeeded() {
if (lastCalculationTimestamp > new Date().getTime() - 60 * 1000)
return;
updateTotalIOBTreatments();
public static void checkForExpiredTemps() {
checkForExpired(tempBasals);
}
public static void checkForExpiredExtended() {
checkForExpired(extendedBoluses);
}
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
public IobTotal getLastCalculationTreatments() {
return lastCalculation;
return lastTreatmentCalculation;
}
@Override
@ -157,8 +225,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
public void updateTotalIOBTreatments() {
IobTotal total = getCalculationToTimeTreatments(new Date().getTime());
lastCalculationTimestamp = new Date().getTime();
lastCalculation = total;
lastTreatmentCalculation = total;
}
@Override
@ -212,4 +279,98 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
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();
}
}
}

View file

@ -47,12 +47,6 @@ import info.nightscout.utils.ToastUtils;
public class TreatmentsBolusFragment extends Fragment implements View.OnClickListener {
private static Logger log = LoggerFactory.getLogger(TreatmentsBolusFragment.class);
private static TreatmentsPlugin treatmentsPlugin = new TreatmentsPlugin();
public static TreatmentsPlugin getPlugin() {
return treatmentsPlugin;
}
RecyclerView recyclerView;
LinearLayoutManager llm;
@ -149,7 +143,7 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
}
MainApp.getDbHelper().delete(treatment);
treatmentsPlugin.initializeData();
TreatmentsPlugin.initializeData();
updateGUI();
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() {
public void onClick(DialogInterface dialog, int id) {
MainApp.getDbHelper().resetTreatments();
treatmentsPlugin.initializeData();
TreatmentsPlugin.initializeData();
updateGUI();
Intent restartNSClient = new Intent(Intents.ACTION_RESTART);
MainApp.instance().getApplicationContext().sendBroadcast(restartNSClient);
@ -242,10 +236,10 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
@Override
public void run() {
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.treatments), false);
if (TreatmentsPlugin.lastCalculation != null)
iobTotal.setText(DecimalFormatter.to2Decimal(TreatmentsPlugin.lastCalculation.iob) + " U");
if (TreatmentsPlugin.lastCalculation != null)
activityTotal.setText(DecimalFormatter.to3Decimal(TreatmentsPlugin.lastCalculation.activity) + " U");
if (TreatmentsPlugin.lastTreatmentCalculation != null)
iobTotal.setText(DecimalFormatter.to2Decimal(TreatmentsPlugin.lastTreatmentCalculation.iob) + " U");
if (TreatmentsPlugin.lastTreatmentCalculation != null)
activityTotal.setText(DecimalFormatter.to3Decimal(TreatmentsPlugin.lastTreatmentCalculation.activity) + " U");
}
});
}

View file

@ -1,4 +1,4 @@
package info.nightscout.androidaps.plugins.TempBasals;
package info.nightscout.androidaps.plugins.Treatments.fragments;
import android.app.Activity;
import android.content.Context;
@ -32,18 +32,13 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
public class TempBasalsFragment extends Fragment {
private static Logger log = LoggerFactory.getLogger(TempBasalsFragment.class);
private static TempBasalsPlugin tempBasalsPlugin = new TempBasalsPlugin();
public static TempBasalsPlugin getPlugin() {
return tempBasalsPlugin;
}
public class TreatmentsTempBasalsFragment extends Fragment {
private static Logger log = LoggerFactory.getLogger(TreatmentsTempBasalsFragment.class);
RecyclerView recyclerView;
LinearLayoutManager llm;
@ -157,7 +152,7 @@ public class TempBasalsFragment extends Fragment {
// MainApp.getConfigBuilder().removeCareportalEntryFromNS(_id);
//}
MainApp.getDbHelper().delete(tempBasal);
tempBasalsPlugin.initializeData();
TreatmentsPlugin.initializeData();
updateGUI();
Answers.getInstance().logCustom(new CustomEvent("RemoveTempBasal"));
}
@ -180,7 +175,7 @@ public class TempBasalsFragment extends Fragment {
llm = new LinearLayoutManager(view.getContext());
recyclerView.setLayoutManager(llm);
RecyclerViewAdapter adapter = new RecyclerViewAdapter(tempBasalsPlugin.getMergedList());
RecyclerViewAdapter adapter = new RecyclerViewAdapter(TreatmentsPlugin.getMergedList());
recyclerView.setAdapter(adapter);
tempBasalTotalView = (TextView) view.findViewById(R.id.tempbasals_totaltempiob);
@ -214,9 +209,9 @@ public class TempBasalsFragment extends Fragment {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
recyclerView.swapAdapter(new RecyclerViewAdapter(tempBasalsPlugin.getMergedList()), false);
if (tempBasalsPlugin.lastCalculation != null) {
String totalText = DecimalFormatter.to2Decimal(tempBasalsPlugin.lastCalculation.basaliob) + " U";
recyclerView.swapAdapter(new RecyclerViewAdapter(TreatmentsPlugin.getMergedList()), false);
if (TreatmentsPlugin.lastTempBasalsCalculation != null) {
String totalText = DecimalFormatter.to2Decimal(TreatmentsPlugin.lastTempBasalsCalculation.basaliob) + " U";
tempBasalTotalView.setText(totalText);
}
}

View file

@ -546,8 +546,8 @@ public class WatchUpdaterService extends WearableListenerService implements
//IOB
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTreatments();
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTreatments().round();
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOBTempBasals();
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculationTempBasals().round();
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTempBasals();
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTempBasals().round();
status += (shortString?"":(getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);
if (mPrefs.getBoolean("wear_detailediob", true)) {

View file

@ -172,8 +172,8 @@ public class StatuslinePlugin implements PluginBase {
//IOB
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTreatments();
IobTotal bolusIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTreatments().round();
MainApp.getConfigBuilder().getActiveTempBasals().updateTotalIOBTempBasals();
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTempBasals().getLastCalculationTempBasals().round();
MainApp.getConfigBuilder().getActiveTreatments().updateTotalIOBTempBasals();
IobTotal basalIob = MainApp.getConfigBuilder().getActiveTreatments().getLastCalculationTempBasals().round();
status += (shortString ? "" : (ctx.getString(R.string.treatments_iob_label_string) + " ")) + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob);

View file

@ -5,7 +5,6 @@ import org.json.JSONObject;
import java.util.Date;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.interfaces.TempBasalsInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
@ -88,13 +87,9 @@ public class BolusWizard {
// IOB calculation
TreatmentsInterface treatments = ConfigBuilderPlugin.getActiveTreatments();
treatments.updateTotalIOBTreatments();
IobTotal bolusIob = treatments.getLastCalculationTreatments();
TempBasalsInterface tempBasals = ConfigBuilderPlugin.getActiveTempBasals();
IobTotal basalIob = new IobTotal(new Date().getTime());
if (tempBasals != null) {
tempBasals.updateTotalIOBTempBasals();
basalIob = tempBasals.getLastCalculationTempBasals().round();
}
IobTotal bolusIob = treatments.getLastCalculationTreatments().round();
treatments.updateTotalIOBTempBasals();
IobTotal basalIob = treatments.getLastCalculationTempBasals().round();
insulingFromBolusIOB = includeBolusIOB ? -bolusIob.iob : 0d;
insulingFromBasalsIOB = includeBasalIOB ? -basalIob.basaliob : 0d;

View file

@ -144,24 +144,6 @@
android:layout_marginRight="10dp"
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
android:id="@+id/configbuilder_constraintslabel"
android:layout_width="wrap_content"

View file

@ -2,7 +2,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="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
android:layout_width="match_parent"

View file

@ -2,7 +2,7 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="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
android:layout_width="match_parent"