IobCobCalculatorPlugin injection
This commit is contained in:
parent
295ce489bf
commit
348936e1b8
19 changed files with 322 additions and 315 deletions
|
@ -74,7 +74,7 @@
|
|||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name=".plugins.pump.danaRS.activities.PairingHelperActivity" />
|
||||
<activity android:name=".activities.HistoryBrowseActivity" />
|
||||
<activity android:name=".historyBrowser.HistoryBrowseActivity" />
|
||||
<activity android:name=".activities.SurveyActivity" />
|
||||
<activity android:name=".activities.StatsActivity" />
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ import com.joanzapata.iconify.fonts.FontAwesomeModule;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.AndroidInjection;
|
||||
import info.nightscout.androidaps.activities.HistoryBrowseActivity;
|
||||
import info.nightscout.androidaps.historyBrowser.HistoryBrowseActivity;
|
||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
||||
import info.nightscout.androidaps.activities.PreferencesActivity;
|
||||
import info.nightscout.androidaps.activities.SingleFragmentActivity;
|
||||
|
|
|
@ -138,6 +138,7 @@ public class MainApp extends DaggerApplication {
|
|||
@Inject InsulinOrefFreePeakPlugin insulinOrefFreePeakPlugin;
|
||||
@Inject InsulinOrefRapidActingPlugin insulinOrefRapidActingPlugin;
|
||||
@Inject InsulinOrefUltraRapidActingPlugin insulinOrefUltraRapidActingPlugin;
|
||||
@Inject IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||
@Inject LocalProfilePlugin localProfilePlugin;
|
||||
@Inject LoopPlugin loopPlugin;
|
||||
@Inject ObjectivesPlugin objectivesPlugin;
|
||||
|
@ -207,7 +208,7 @@ public class MainApp extends DaggerApplication {
|
|||
pluginsList = new ArrayList<>();
|
||||
// Register all tabs in app here
|
||||
pluginsList.add(overviewPlugin);
|
||||
pluginsList.add(IobCobCalculatorPlugin.getPlugin());
|
||||
pluginsList.add(iobCobCalculatorPlugin);
|
||||
if (!Config.NSCLIENT) pluginsList.add(actionsPlugin);
|
||||
pluginsList.add(insulinOrefRapidActingPlugin);
|
||||
pluginsList.add(insulinOrefUltraRapidActingPlugin);
|
||||
|
|
|
@ -4,6 +4,7 @@ import dagger.Module
|
|||
import dagger.android.ContributesAndroidInjector
|
||||
import info.nightscout.androidaps.MainActivity
|
||||
import info.nightscout.androidaps.activities.*
|
||||
import info.nightscout.androidaps.historyBrowser.HistoryBrowseActivity
|
||||
import info.nightscout.androidaps.plugins.general.maintenance.activities.LogSettingActivity
|
||||
import info.nightscout.androidaps.plugins.general.overview.activities.QuickWizardListActivity
|
||||
import info.nightscout.androidaps.plugins.pump.common.dialog.RileyLinkBLEScanActivity
|
||||
|
|
|
@ -20,6 +20,8 @@ import info.nightscout.androidaps.data.Profile
|
|||
import info.nightscout.androidaps.db.BgReading
|
||||
import info.nightscout.androidaps.db.DatabaseHelper
|
||||
import info.nightscout.androidaps.interfaces.Constraint
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker
|
||||
|
@ -33,23 +35,23 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP
|
|||
import io.reactivex.android.schedulers.AndroidSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import kotlinx.android.synthetic.main.dialog_wizard.*
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.text.DecimalFormat
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
import kotlin.math.abs
|
||||
|
||||
class WizardDialog : DaggerDialogFragment() {
|
||||
private val log = LoggerFactory.getLogger(WizardDialog::class.java)
|
||||
|
||||
@Inject lateinit var aapsLogger: AAPSLogger
|
||||
@Inject lateinit var constraintChecker: ConstraintChecker
|
||||
@Inject lateinit var mainApp: MainApp
|
||||
@Inject lateinit var sp: SP
|
||||
@Inject lateinit var rxBus: RxBusWrapper
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var profileFunction: ProfileFunction
|
||||
@Inject lateinit var treatmentsPlugin: TreatmentsPlugin
|
||||
@Inject lateinit var configBuilderPlugin: ConfigBuilderPlugin
|
||||
@Inject lateinit var sp: SP
|
||||
@Inject lateinit var rxBus: RxBusWrapper
|
||||
@Inject lateinit var iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||
|
||||
private var wizard: BolusWizard? = null
|
||||
|
||||
|
@ -114,7 +116,7 @@ class WizardDialog : DaggerDialogFragment() {
|
|||
// ok button
|
||||
ok.setOnClickListener {
|
||||
if (okClicked) {
|
||||
log.debug("guarding: ok already clicked")
|
||||
aapsLogger.debug(LTag.UI, "guarding: ok already clicked")
|
||||
} else {
|
||||
okClicked = true
|
||||
calculateInsulin()
|
||||
|
@ -263,7 +265,7 @@ class WizardDialog : DaggerDialogFragment() {
|
|||
val specificProfile: Profile?
|
||||
if (profileName == resourceHelper.gs(R.string.active)) {
|
||||
specificProfile = profileFunction.getProfile()
|
||||
profileName = profileFunction.getProfileName() ?: return
|
||||
profileName = profileFunction.getProfileName()
|
||||
} else
|
||||
specificProfile = profileStore.getSpecificProfile(profileName)
|
||||
|
||||
|
@ -286,7 +288,7 @@ class WizardDialog : DaggerDialogFragment() {
|
|||
// COB
|
||||
var cob = 0.0
|
||||
if (treatments_wizard_cobcheckbox.isChecked) {
|
||||
val cobInfo = IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "Wizard COB")
|
||||
val cobInfo = iobCobCalculatorPlugin.getCobInfo(false, "Wizard COB")
|
||||
cobInfo.displayCob?.let { cob = it }
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.activities;
|
||||
package info.nightscout.androidaps.historyBrowser;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.os.SystemClock;
|
||||
|
@ -18,35 +18,44 @@ import androidx.core.content.res.ResourcesCompat;
|
|||
import com.jjoe64.graphview.GraphView;
|
||||
import com.wdullaer.materialdatetimepicker.date.DatePickerDialog;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.events.EventCustomCalculationFinished;
|
||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
|
||||
import info.nightscout.androidaps.plugins.general.overview.OverviewFragment;
|
||||
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin;
|
||||
import info.nightscout.androidaps.plugins.general.overview.graphData.GraphData;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventIobCalculationProgress;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||
import io.reactivex.android.schedulers.AndroidSchedulers;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
||||
private static Logger log = LoggerFactory.getLogger(HistoryBrowseActivity.class);
|
||||
@Inject AAPSLogger aapsLogger;
|
||||
@Inject RxBusWrapper rxBus;
|
||||
@Inject SP sp;
|
||||
@Inject ResourceHelper resourceHelper;
|
||||
@Inject ProfileFunction profileFunction;
|
||||
@Inject IobCobStaticCalculatorPlugin iobCobStaticCalculatorPlugin;
|
||||
@Inject ConfigBuilderPlugin configBuilderPlugin;
|
||||
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
ImageButton chartButton;
|
||||
|
@ -66,14 +75,9 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
private int rangeToDisplay = 24; // for graph
|
||||
private long start = 0;
|
||||
|
||||
IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||
|
||||
EventCustomCalculationFinished eventCustomCalculationFinished = new EventCustomCalculationFinished();
|
||||
|
||||
public HistoryBrowseActivity() {
|
||||
iobCobCalculatorPlugin = new IobCobCalculatorPlugin();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
@ -153,9 +157,9 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
dpd.show(getSupportFragmentManager(), "Datepickerdialog");
|
||||
});
|
||||
|
||||
bgGraph.getGridLabelRenderer().setGridColor(MainApp.gc(R.color.graphgrid));
|
||||
bgGraph.getGridLabelRenderer().setGridColor(resourceHelper.gc(R.color.graphgrid));
|
||||
bgGraph.getGridLabelRenderer().reloadStyles();
|
||||
iobGraph.getGridLabelRenderer().setGridColor(MainApp.gc(R.color.graphgrid));
|
||||
iobGraph.getGridLabelRenderer().setGridColor(resourceHelper.gc(R.color.graphgrid));
|
||||
iobGraph.getGridLabelRenderer().reloadStyles();
|
||||
iobGraph.getGridLabelRenderer().setHorizontalLabelsVisible(false);
|
||||
bgGraph.getGridLabelRenderer().setLabelVerticalWidth(50);
|
||||
|
@ -169,25 +173,25 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
public void onPause() {
|
||||
super.onPause();
|
||||
disposable.clear();
|
||||
iobCobCalculatorPlugin.stopCalculation("onPause");
|
||||
iobCobStaticCalculatorPlugin.stopCalculation("onPause");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
disposable.add(RxBus.Companion.getINSTANCE()
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventAutosensCalculationFinished.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> {
|
||||
if (event.getCause() == eventCustomCalculationFinished) {
|
||||
log.debug("EventAutosensCalculationFinished");
|
||||
aapsLogger.debug(LTag.AUTOSENS, "EventAutosensCalculationFinished");
|
||||
synchronized (HistoryBrowseActivity.this) {
|
||||
updateGUI("EventAutosensCalculationFinished");
|
||||
}
|
||||
}
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
disposable.add(RxBus.Companion.getINSTANCE()
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventIobCalculationProgress.class)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.subscribe(event -> {
|
||||
|
@ -210,19 +214,19 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
|
||||
private void runCalculation(String from) {
|
||||
long end = start + T.hours(rangeToDisplay).msecs();
|
||||
iobCobCalculatorPlugin.stopCalculation(from);
|
||||
iobCobCalculatorPlugin.clearCache();
|
||||
iobCobCalculatorPlugin.runCalculation(from, end, true, false, eventCustomCalculationFinished);
|
||||
iobCobStaticCalculatorPlugin.stopCalculation(from);
|
||||
iobCobStaticCalculatorPlugin.clearCache();
|
||||
iobCobStaticCalculatorPlugin.runCalculation(from, end, true, false, eventCustomCalculationFinished);
|
||||
}
|
||||
|
||||
void updateGUI(String from) {
|
||||
log.debug("updateGUI from: " + from);
|
||||
aapsLogger.debug(LTag.UI, "updateGUI from: " + from);
|
||||
|
||||
if (noProfile == null || buttonDate == null || buttonZoom == null || bgGraph == null || iobGraph == null || seekBar == null)
|
||||
return;
|
||||
|
||||
final PumpInterface pump = ConfigBuilderPlugin.getPlugin().getActivePump();
|
||||
final Profile profile = ProfileFunctions.getInstance().getProfile();
|
||||
final PumpInterface pump = configBuilderPlugin.getActivePump();
|
||||
final Profile profile = profileFunction.getProfile();
|
||||
|
||||
if (profile == null) {
|
||||
noProfile.setVisibility(View.VISIBLE);
|
||||
|
@ -239,16 +243,16 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
|
||||
final boolean showPrediction = false;
|
||||
|
||||
showBasal = SP.getBoolean("hist_showbasals", true);
|
||||
showIob = SP.getBoolean("hist_showiob", true);
|
||||
showCob = SP.getBoolean("hist_showcob", true);
|
||||
showDev = SP.getBoolean("hist_showdeviations", false);
|
||||
showRat = SP.getBoolean("hist_showratios", false);
|
||||
showActPrim = SP.getBoolean("hist_showactivityprimary", false);
|
||||
showActSec = SP.getBoolean("hist_showactivitysecondary", false);
|
||||
showDevslope = SP.getBoolean("hist_showdevslope", false);
|
||||
showBasal = sp.getBoolean("hist_showbasals", true);
|
||||
showIob = sp.getBoolean("hist_showiob", true);
|
||||
showCob = sp.getBoolean("hist_showcob", true);
|
||||
showDev = sp.getBoolean("hist_showdeviations", false);
|
||||
showRat = sp.getBoolean("hist_showratios", false);
|
||||
showActPrim = sp.getBoolean("hist_showactivityprimary", false);
|
||||
showActSec = sp.getBoolean("hist_showactivitysecondary", false);
|
||||
showDevslope = sp.getBoolean("hist_showdevslope", false);
|
||||
|
||||
int hoursToFetch;
|
||||
//int hoursToFetch;
|
||||
final long toTime;
|
||||
final long fromTime;
|
||||
//if (showPrediction) {
|
||||
|
@ -264,13 +268,13 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
toTime = start + T.hours(rangeToDisplay).msecs();
|
||||
//}
|
||||
|
||||
log.debug("Period: " + DateUtil.dateAndTimeString(fromTime) + " - " + DateUtil.dateAndTimeString(toTime));
|
||||
aapsLogger.debug(LTag.UI, "Period: " + DateUtil.dateAndTimeString(fromTime) + " - " + DateUtil.dateAndTimeString(toTime));
|
||||
|
||||
final long pointer = System.currentTimeMillis();
|
||||
|
||||
// ------------------ 1st graph
|
||||
|
||||
final GraphData graphData = new GraphData(bgGraph, iobCobCalculatorPlugin);
|
||||
final GraphData graphData = new GraphData(bgGraph, iobCobStaticCalculatorPlugin);
|
||||
|
||||
// **** In range Area ****
|
||||
graphData.addInRangeArea(fromTime, toTime, lowLine, highLine);
|
||||
|
@ -303,7 +307,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
// ------------------ 2nd graph
|
||||
|
||||
new Thread(() -> {
|
||||
final GraphData secondGraphData = new GraphData(iobGraph, iobCobCalculatorPlugin);
|
||||
final GraphData secondGraphData = new GraphData(iobGraph, iobCobStaticCalculatorPlugin);
|
||||
|
||||
boolean useIobForScale = false;
|
||||
boolean useCobForScale = false;
|
||||
|
@ -360,7 +364,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
}
|
||||
|
||||
private void setupChartMenu() {
|
||||
chartButton = (ImageButton) findViewById(R.id.overview_chartMenuButton);
|
||||
chartButton = findViewById(R.id.overview_chartMenuButton);
|
||||
chartButton.setOnClickListener(v -> {
|
||||
MenuItem item, dividerItem;
|
||||
CharSequence title;
|
||||
|
@ -369,7 +373,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
PopupMenu popup = new PopupMenu(v.getContext(), v);
|
||||
|
||||
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.BAS.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_basals));
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.BAS.ordinal(), Menu.NONE, resourceHelper.gs(R.string.overview_show_basals));
|
||||
title = item.getTitle();
|
||||
if (titleMaxChars < title.length()) titleMaxChars = title.length();
|
||||
s = new SpannableString(title);
|
||||
|
@ -378,7 +382,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
item.setCheckable(true);
|
||||
item.setChecked(showBasal);
|
||||
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.ACTPRIM.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_activity));
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.ACTPRIM.ordinal(), Menu.NONE, resourceHelper.gs(R.string.overview_show_activity));
|
||||
title = item.getTitle();
|
||||
if (titleMaxChars < title.length()) titleMaxChars = title.length();
|
||||
s = new SpannableString(title);
|
||||
|
@ -390,7 +394,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
dividerItem = popup.getMenu().add("");
|
||||
dividerItem.setEnabled(false);
|
||||
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.IOB.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_iob));
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.IOB.ordinal(), Menu.NONE, resourceHelper.gs(R.string.overview_show_iob));
|
||||
title = item.getTitle();
|
||||
if (titleMaxChars < title.length()) titleMaxChars = title.length();
|
||||
s = new SpannableString(title);
|
||||
|
@ -399,7 +403,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
item.setCheckable(true);
|
||||
item.setChecked(showIob);
|
||||
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.COB.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_cob));
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.COB.ordinal(), Menu.NONE, resourceHelper.gs(R.string.overview_show_cob));
|
||||
title = item.getTitle();
|
||||
if (titleMaxChars < title.length()) titleMaxChars = title.length();
|
||||
s = new SpannableString(title);
|
||||
|
@ -408,7 +412,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
item.setCheckable(true);
|
||||
item.setChecked(showCob);
|
||||
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.DEV.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_deviations));
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.DEV.ordinal(), Menu.NONE, resourceHelper.gs(R.string.overview_show_deviations));
|
||||
title = item.getTitle();
|
||||
if (titleMaxChars < title.length()) titleMaxChars = title.length();
|
||||
s = new SpannableString(title);
|
||||
|
@ -417,7 +421,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
item.setCheckable(true);
|
||||
item.setChecked(showDev);
|
||||
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.SEN.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_sensitivity));
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.SEN.ordinal(), Menu.NONE, resourceHelper.gs(R.string.overview_show_sensitivity));
|
||||
title = item.getTitle();
|
||||
if (titleMaxChars < title.length()) titleMaxChars = title.length();
|
||||
s = new SpannableString(title);
|
||||
|
@ -426,7 +430,7 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
item.setCheckable(true);
|
||||
item.setChecked(showRat);
|
||||
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.ACTSEC.ordinal(), Menu.NONE, MainApp.gs(R.string.overview_show_activity));
|
||||
item = popup.getMenu().add(Menu.NONE, OverviewFragment.CHARTTYPE.ACTSEC.ordinal(), Menu.NONE, resourceHelper.gs(R.string.overview_show_activity));
|
||||
title = item.getTitle();
|
||||
if (titleMaxChars < title.length()) titleMaxChars = title.length();
|
||||
s = new SpannableString(title);
|
||||
|
@ -453,21 +457,21 @@ public class HistoryBrowseActivity extends NoSplashAppCompatActivity {
|
|||
|
||||
popup.setOnMenuItemClickListener(item1 -> {
|
||||
if (item1.getItemId() == OverviewFragment.CHARTTYPE.BAS.ordinal()) {
|
||||
SP.putBoolean("hist_showbasals", !item1.isChecked());
|
||||
sp.putBoolean("hist_showbasals", !item1.isChecked());
|
||||
} else if (item1.getItemId() == OverviewFragment.CHARTTYPE.IOB.ordinal()) {
|
||||
SP.putBoolean("hist_showiob", !item1.isChecked());
|
||||
sp.putBoolean("hist_showiob", !item1.isChecked());
|
||||
} else if (item1.getItemId() == OverviewFragment.CHARTTYPE.COB.ordinal()) {
|
||||
SP.putBoolean("hist_showcob", !item1.isChecked());
|
||||
sp.putBoolean("hist_showcob", !item1.isChecked());
|
||||
} else if (item1.getItemId() == OverviewFragment.CHARTTYPE.DEV.ordinal()) {
|
||||
SP.putBoolean("hist_showdeviations", !item1.isChecked());
|
||||
sp.putBoolean("hist_showdeviations", !item1.isChecked());
|
||||
} else if (item1.getItemId() == OverviewFragment.CHARTTYPE.SEN.ordinal()) {
|
||||
SP.putBoolean("hist_showratios", !item1.isChecked());
|
||||
sp.putBoolean("hist_showratios", !item1.isChecked());
|
||||
} else if (item1.getItemId() == OverviewFragment.CHARTTYPE.ACTPRIM.ordinal()) {
|
||||
SP.putBoolean("hist_showactivityprimary", !item1.isChecked());
|
||||
sp.putBoolean("hist_showactivityprimary", !item1.isChecked());
|
||||
} else if (item1.getItemId() == OverviewFragment.CHARTTYPE.ACTSEC.ordinal()) {
|
||||
SP.putBoolean("hist_showactivitysecondary", !item1.isChecked());
|
||||
sp.putBoolean("hist_showactivitysecondary", !item1.isChecked());
|
||||
} else if (item1.getItemId() == OverviewFragment.CHARTTYPE.DEVSLOPE.ordinal()) {
|
||||
SP.putBoolean("hist_showdevslope", !item1.isChecked());
|
||||
sp.putBoolean("hist_showdevslope", !item1.isChecked());
|
||||
}
|
||||
updateGUI("onGraphCheckboxesCheckedChanged");
|
||||
return true;
|
|
@ -0,0 +1,22 @@
|
|||
package info.nightscout.androidaps.historyBrowser
|
||||
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import javax.inject.Inject
|
||||
|
||||
class IobCobStaticCalculatorPlugin @Inject constructor(
|
||||
aapsLogger: AAPSLogger,
|
||||
rxBus: RxBusWrapper,
|
||||
sp: SP,
|
||||
profileFunction: ProfileFunction,
|
||||
configBuilderPlugin: ConfigBuilderPlugin,
|
||||
treatmentsPlugin: TreatmentsPlugin
|
||||
) : IobCobCalculatorPlugin(aapsLogger, rxBus, sp, profileFunction, configBuilderPlugin, treatmentsPlugin) {
|
||||
override fun onStart() { // do not attach to rxbus
|
||||
}
|
||||
}
|
|
@ -30,8 +30,6 @@ public interface TreatmentsInterface {
|
|||
IobTotal getLastCalculationTempBasals();
|
||||
IobTotal getCalculationToTimeTempBasals(long time);
|
||||
|
||||
MealData getMealData();
|
||||
|
||||
List<Treatment> getTreatmentsFromHistory();
|
||||
List<Treatment> getCarbTreatments5MinBackFromHistory(long time);
|
||||
List<Treatment> getTreatmentsFromHistoryAfterTimestamp(long timestamp);
|
||||
|
|
|
@ -48,6 +48,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
private final MainApp mainApp;
|
||||
private final ConfigBuilderPlugin configBuilderPlugin;
|
||||
private final TreatmentsPlugin treatmentsPlugin;
|
||||
private final IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||
|
||||
// last values
|
||||
DetermineBasalAdapterAMAJS lastDetermineBasalAdapterAMAJS = null;
|
||||
|
@ -64,7 +65,8 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
ProfileFunction profileFunction,
|
||||
MainApp mainApp,
|
||||
ConfigBuilderPlugin configBuilderPlugin,
|
||||
TreatmentsPlugin treatmentsPlugin
|
||||
TreatmentsPlugin treatmentsPlugin,
|
||||
IobCobCalculatorPlugin iobCobCalculatorPlugin
|
||||
) {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.APS)
|
||||
|
@ -82,6 +84,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
this.mainApp = mainApp;
|
||||
this.configBuilderPlugin = configBuilderPlugin;
|
||||
this.treatmentsPlugin = treatmentsPlugin;
|
||||
this.iobCobCalculatorPlugin = iobCobCalculatorPlugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -151,11 +154,11 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
long start = System.currentTimeMillis();
|
||||
long startPart = System.currentTimeMillis();
|
||||
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayInDia(profile);
|
||||
IobTotal[] iobArray = iobCobCalculatorPlugin.calculateIobArrayInDia(profile);
|
||||
Profiler.log(aapsLogger, LTag.APS, "calculateIobArrayInDia()", startPart);
|
||||
|
||||
startPart = System.currentTimeMillis();
|
||||
MealData mealData = treatmentsPlugin.getMealData();
|
||||
MealData mealData = iobCobCalculatorPlugin.getMealData();
|
||||
Profiler.log(aapsLogger, LTag.APS, "getMealData()", startPart);
|
||||
|
||||
double maxIob = constraintChecker.getMaxIOBAllowed().value();
|
||||
|
@ -187,7 +190,7 @@ public class OpenAPSAMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
startPart = System.currentTimeMillis();
|
||||
if (constraintChecker.isAutosensModeEnabled().value()) {
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
|
||||
AutosensData autosensData = iobCobCalculatorPlugin.getLastAutosensDataSynchronized("OpenAPSPlugin");
|
||||
if (autosensData == null) {
|
||||
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.openaps_noasdata)));
|
||||
return;
|
||||
|
|
|
@ -27,6 +27,7 @@ import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
|||
import info.nightscout.androidaps.plugins.configBuilder.ConstraintChecker;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
|
@ -48,6 +49,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
private final MainApp mainApp;
|
||||
private final ConfigBuilderPlugin configBuilderPlugin;
|
||||
private final TreatmentsPlugin treatmentsPlugin;
|
||||
private final IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||
|
||||
// last values
|
||||
DetermineBasalAdapterMAJS lastDetermineBasalAdapterMAJS = null;
|
||||
|
@ -63,7 +65,8 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
ProfileFunction profileFunction,
|
||||
MainApp mainApp,
|
||||
ConfigBuilderPlugin configBuilderPlugin,
|
||||
TreatmentsPlugin treatmentsPlugin
|
||||
TreatmentsPlugin treatmentsPlugin,
|
||||
IobCobCalculatorPlugin iobCobCalculatorPlugin
|
||||
) {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.APS)
|
||||
|
@ -81,6 +84,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
this.mainApp = mainApp;
|
||||
this.configBuilderPlugin = configBuilderPlugin;
|
||||
this.treatmentsPlugin = treatmentsPlugin;
|
||||
this.iobCobCalculatorPlugin = iobCobCalculatorPlugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -157,7 +161,7 @@ public class OpenAPSMAPlugin extends PluginBase implements APSInterface {
|
|||
|
||||
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
|
||||
|
||||
MealData mealData = treatmentsPlugin.getMealData();
|
||||
MealData mealData = iobCobCalculatorPlugin.getMealData();
|
||||
|
||||
double maxIob = constraintChecker.getMaxIOBAllowed().value();
|
||||
Profiler.log(aapsLogger, LTag.APS, "MA data gathering", start);
|
||||
|
|
|
@ -53,6 +53,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
private final MainApp mainApp;
|
||||
private final ConfigBuilderPlugin configBuilderPlugin;
|
||||
private final TreatmentsPlugin treatmentsPlugin;
|
||||
private final IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||
|
||||
private static OpenAPSSMBPlugin openAPSSMBPlugin;
|
||||
|
||||
|
@ -81,7 +82,9 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
ProfileFunction profileFunction,
|
||||
MainApp mainApp,
|
||||
ConfigBuilderPlugin configBuilderPlugin,
|
||||
TreatmentsPlugin treatmentsPlugin
|
||||
TreatmentsPlugin treatmentsPlugin,
|
||||
IobCobCalculatorPlugin iobCobCalculatorPlugin
|
||||
|
||||
) {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.APS)
|
||||
|
@ -100,6 +103,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
this.mainApp = mainApp;
|
||||
this.configBuilderPlugin = configBuilderPlugin;
|
||||
this.treatmentsPlugin = treatmentsPlugin;
|
||||
this.iobCobCalculatorPlugin = iobCobCalculatorPlugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -174,7 +178,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
long start = System.currentTimeMillis();
|
||||
long startPart = System.currentTimeMillis();
|
||||
|
||||
MealData mealData = treatmentsPlugin.getMealData();
|
||||
MealData mealData = iobCobCalculatorPlugin.getMealData();
|
||||
Profiler.log(aapsLogger, LTag.APS, "getMealData()", startPart);
|
||||
|
||||
Constraint<Double> maxIOBAllowedConstraint = constraintChecker.getMaxIOBAllowed();
|
||||
|
@ -208,7 +212,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
|
||||
startPart = System.currentTimeMillis();
|
||||
if (constraintChecker.isAutosensModeEnabled().value()) {
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("OpenAPSPlugin");
|
||||
AutosensData autosensData = iobCobCalculatorPlugin.getLastAutosensDataSynchronized("OpenAPSPlugin");
|
||||
if (autosensData == null) {
|
||||
rxBus.send(new EventOpenAPSUpdateResultGui(resourceHelper.gs(R.string.openaps_noasdata)));
|
||||
return;
|
||||
|
@ -219,7 +223,7 @@ public class OpenAPSSMBPlugin extends PluginBase implements APSInterface, Constr
|
|||
lastAutosensResult.sensResult = "autosens disabled";
|
||||
}
|
||||
|
||||
IobTotal[] iobArray = IobCobCalculatorPlugin.getPlugin().calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget);
|
||||
IobTotal[] iobArray = iobCobCalculatorPlugin.calculateIobArrayForSMB(lastAutosensResult, SMBDefaults.exercise_mode, SMBDefaults.half_basal_exercise_target, isTempTarget);
|
||||
Profiler.log(aapsLogger, LTag.APS, "calculateIobArrayInDia()", startPart);
|
||||
|
||||
startPart = System.currentTimeMillis();
|
||||
|
|
|
@ -12,7 +12,7 @@ import info.nightscout.androidaps.Config
|
|||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.activities.ErrorHelperActivity
|
||||
import info.nightscout.androidaps.activities.HistoryBrowseActivity
|
||||
import info.nightscout.androidaps.historyBrowser.HistoryBrowseActivity
|
||||
import info.nightscout.androidaps.activities.TDDStatsActivity
|
||||
import info.nightscout.androidaps.dialogs.*
|
||||
import info.nightscout.androidaps.events.*
|
||||
|
|
|
@ -138,6 +138,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
|
|||
@Inject LoopPlugin loopPlugin;
|
||||
@Inject ConfigBuilderPlugin configBuilderPlugin;
|
||||
@Inject TreatmentsPlugin treatmentsPlugin;
|
||||
@Inject IobCobCalculatorPlugin iobCobCalculatorPlugin;
|
||||
@Inject NotificationStore notificationStore;
|
||||
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
@ -1319,7 +1320,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
|
|||
// cob
|
||||
if (cobView != null) { // view must not exists
|
||||
String cobText = resourceHelper.gs(R.string.value_unavailable_short);
|
||||
CobInfo cobInfo = IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "Overview COB");
|
||||
CobInfo cobInfo = iobCobCalculatorPlugin.getCobInfo(false, "Overview COB");
|
||||
if (cobInfo.displayCob != null) {
|
||||
cobText = DecimalFormatter.to0Decimal(cobInfo.displayCob);
|
||||
if (cobInfo.futureCarbs > 0)
|
||||
|
@ -1371,7 +1372,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
|
|||
|
||||
// Sensitivity
|
||||
if (sensitivityView != null) {
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensData("Overview");
|
||||
AutosensData autosensData = iobCobCalculatorPlugin.getLastAutosensData("Overview");
|
||||
if (autosensData != null)
|
||||
sensitivityView.setText(String.format(Locale.ENGLISH, "%.0f%%", autosensData.autosensResult.ratio * 100));
|
||||
else
|
||||
|
@ -1421,7 +1422,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
|
|||
// ------------------ 1st graph
|
||||
Profiler.log(aapsLogger, LTag.OVERVIEW, from + " - 1st graph - START", updateGUIStart);
|
||||
|
||||
final GraphData graphData = new GraphData(bgGraph, IobCobCalculatorPlugin.getPlugin());
|
||||
final GraphData graphData = new GraphData(bgGraph, iobCobCalculatorPlugin);
|
||||
|
||||
// **** In range Area ****
|
||||
graphData.addInRangeArea(fromTime, endTime, lowLine, highLine);
|
||||
|
@ -1457,7 +1458,7 @@ public class OverviewFragment extends DaggerFragment implements View.OnClickList
|
|||
// ------------------ 2nd graph
|
||||
Profiler.log(aapsLogger, LTag.OVERVIEW, from + " - 2nd graph - START", updateGUIStart);
|
||||
|
||||
final GraphData secondGraphData = new GraphData(iobGraph, IobCobCalculatorPlugin.getPlugin());
|
||||
final GraphData secondGraphData = new GraphData(iobGraph, iobCobCalculatorPlugin);
|
||||
|
||||
boolean useIobForScale = false;
|
||||
boolean useCobForScale = false;
|
||||
|
|
|
@ -60,7 +60,8 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
private val profileFunction: ProfileFunction,
|
||||
private val configBuilderPlugin: ConfigBuilderPlugin,
|
||||
private val treatmentsPlugin: TreatmentsPlugin,
|
||||
private val loopPlugin: LoopPlugin
|
||||
private val loopPlugin: LoopPlugin,
|
||||
private val iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||
) : PluginBase(PluginDescription()
|
||||
.mainType(PluginType.GENERAL)
|
||||
.fragmentClass(SmsCommunicatorFragment::class.java.name)
|
||||
|
@ -285,7 +286,7 @@ class SmsCommunicatorPlugin @Inject constructor(
|
|||
val bolusIob = treatmentsPlugin.lastCalculationTreatments.round()
|
||||
treatmentsPlugin.updateTotalIOBTempBasals()
|
||||
val basalIob = treatmentsPlugin.lastCalculationTempBasals.round()
|
||||
val cobInfo = IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "SMS COB")
|
||||
val cobInfo = iobCobCalculatorPlugin.getCobInfo(false, "SMS COB")
|
||||
reply += (resourceHelper.gs(R.string.sms_iob) + " " + DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U ("
|
||||
+ resourceHelper.gs(R.string.sms_bolus) + " " + DecimalFormatter.to2Decimal(bolusIob.iob) + "U "
|
||||
+ resourceHelper.gs(R.string.sms_basal) + " " + DecimalFormatter.to2Decimal(basalIob.basaliob) + "U), "
|
||||
|
|
|
@ -35,7 +35,8 @@ class StatusLinePlugin @Inject constructor(
|
|||
private val mainApp: MainApp,
|
||||
private val configBuilderPlugin: ConfigBuilderPlugin,
|
||||
private val treatmentsPlugin: TreatmentsPlugin,
|
||||
private val loopPlugin: LoopPlugin
|
||||
private val loopPlugin: LoopPlugin,
|
||||
private val iobCobCalculatorPlugin: IobCobCalculatorPlugin
|
||||
) : PluginBase(
|
||||
PluginDescription()
|
||||
.mainType(PluginType.GENERAL)
|
||||
|
@ -137,7 +138,7 @@ class StatusLinePlugin @Inject constructor(
|
|||
}
|
||||
val bgi = -(bolusIob.activity + basalIob.activity) * 5 * Profile.fromMgdlToUnits(profile.isfMgdl, profileFunction.getUnits())
|
||||
status += " " + (if (bgi >= 0) "+" else "") + DecimalFormatter.to2Decimal(bgi)
|
||||
status += " " + IobCobCalculatorPlugin.getPlugin().getCobInfo(false, "StatusLinePlugin").generateCOBString()
|
||||
status += " " + iobCobCalculatorPlugin.getCobInfo(false, "StatusLinePlugin").generateCOBString()
|
||||
return status
|
||||
}
|
||||
}
|
|
@ -7,16 +7,18 @@ import androidx.annotation.Nullable;
|
|||
import androidx.collection.LongSparseArray;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.data.MealData;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.db.BgReading;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
|
@ -29,30 +31,36 @@ import info.nightscout.androidaps.events.EventPreferenceChange;
|
|||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.logging.L;
|
||||
import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData;
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin;
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin;
|
||||
import info.nightscout.androidaps.plugins.treatments.Treatment;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
import static info.nightscout.androidaps.utils.DateUtil.now;
|
||||
|
||||
/**
|
||||
* Created by mike on 24.04.2017.
|
||||
*/
|
||||
|
||||
@Singleton
|
||||
public class IobCobCalculatorPlugin extends PluginBase {
|
||||
private Logger log = LoggerFactory.getLogger(L.AUTOSENS);
|
||||
private final AAPSLogger aapsLogger;
|
||||
private final RxBusWrapper rxBus;
|
||||
private final SP sp;
|
||||
private final ProfileFunction profileFunction;
|
||||
private final ConfigBuilderPlugin configBuilderPlugin;
|
||||
private final TreatmentsPlugin treatmentsPlugin;
|
||||
|
||||
private CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
private static IobCobCalculatorPlugin plugin = null;
|
||||
|
@ -60,7 +68,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
@Deprecated
|
||||
public static IobCobCalculatorPlugin getPlugin() {
|
||||
if (plugin == null)
|
||||
plugin = new IobCobCalculatorPlugin();
|
||||
throw new IllegalStateException("Accessing IobCobCalculatorPlugin before first instantiation");
|
||||
return plugin;
|
||||
}
|
||||
|
||||
|
@ -76,7 +84,15 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
boolean stopCalculationTrigger = false;
|
||||
private Thread thread = null;
|
||||
|
||||
public IobCobCalculatorPlugin() {
|
||||
@Inject
|
||||
public IobCobCalculatorPlugin(
|
||||
AAPSLogger aapsLogger,
|
||||
RxBusWrapper rxBus,
|
||||
SP sp,
|
||||
ProfileFunction profileFunction,
|
||||
ConfigBuilderPlugin configBuilderPlugin,
|
||||
TreatmentsPlugin treatmentsPlugin
|
||||
) {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.GENERAL)
|
||||
.pluginName(R.string.iobcobcalculator)
|
||||
|
@ -84,25 +100,26 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
.neverVisible(true)
|
||||
.alwaysEnabled(true)
|
||||
);
|
||||
this.plugin = this;
|
||||
this.aapsLogger = aapsLogger;
|
||||
this.rxBus = rxBus;
|
||||
this.sp = sp;
|
||||
this.profileFunction = profileFunction;
|
||||
this.configBuilderPlugin = configBuilderPlugin;
|
||||
this.treatmentsPlugin = treatmentsPlugin;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
// EventConfigBuilderChange
|
||||
disposable.add(RxBus.Companion.getINSTANCE()
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventConfigBuilderChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (this != getPlugin()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
stopCalculation("onEventConfigBuilderChange");
|
||||
synchronized (dataLock) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Invalidating cached data because of configuration change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records");
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Invalidating cached data because of configuration change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records");
|
||||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
}
|
||||
|
@ -110,24 +127,16 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
}, FabricPrivacy::logException)
|
||||
);
|
||||
// EventNewBasalProfile
|
||||
disposable.add(RxBus.Companion.getINSTANCE()
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventNewBasalProfile.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (this != getPlugin()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
if (ConfigBuilderPlugin.getPlugin() == null)
|
||||
return; // app still initializing
|
||||
if (event == null) { // on init no need of reset
|
||||
return;
|
||||
}
|
||||
stopCalculation("onNewProfile");
|
||||
synchronized (dataLock) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Invalidating cached data because of new profile. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records");
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Invalidating cached data because of new profile. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records");
|
||||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
basalDataTable = new LongSparseArray<>();
|
||||
|
@ -136,29 +145,19 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
}, FabricPrivacy::logException)
|
||||
);
|
||||
// EventNewBG
|
||||
disposable.add(RxBus.Companion.getINSTANCE()
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventNewBG.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (this != getPlugin()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
stopCalculation("onEventNewBG");
|
||||
runCalculation("onEventNewBG", System.currentTimeMillis(), true, true, event);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
// EventPreferenceChange
|
||||
disposable.add(RxBus.Companion.getINSTANCE()
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventPreferenceChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (this != getPlugin()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
if (event.isChanged(R.string.key_openapsama_autosens_period) ||
|
||||
event.isChanged(R.string.key_age) ||
|
||||
event.isChanged(R.string.key_absorption_maxtime) ||
|
||||
|
@ -170,8 +169,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
) {
|
||||
stopCalculation("onEventPreferenceChange");
|
||||
synchronized (dataLock) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Invalidating cached data because of preference change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records" + " BasalData: " + basalDataTable.size() + " records");
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Invalidating cached data because of preference change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records" + " BasalData: " + basalDataTable.size() + " records");
|
||||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
basalDataTable = new LongSparseArray<>();
|
||||
|
@ -181,23 +179,20 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
}, FabricPrivacy::logException)
|
||||
);
|
||||
// EventAppInitialized
|
||||
disposable.add(RxBus.Companion.getINSTANCE()
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventAppInitialized.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
if (this != getPlugin()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
runCalculation("onEventAppInitialized", System.currentTimeMillis(), true, true, event);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
// EventNewHistoryData
|
||||
disposable.add(RxBus.Companion.getINSTANCE()
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventNewHistoryData.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> newHistoryData(event), FabricPrivacy::logException)
|
||||
.subscribe(event -> {
|
||||
newHistoryData(event);
|
||||
}, FabricPrivacy::logException)
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -236,7 +231,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
}
|
||||
|
||||
void loadBgData(long to) {
|
||||
Profile profile = ProfileFunctions.getInstance().getProfile(to);
|
||||
Profile profile = profileFunction.getProfile(to);
|
||||
double dia = Constants.defaultDIA;
|
||||
if (profile != null) dia = profile.getDia();
|
||||
long start = to - T.hours((long) (24 + dia)).msecs();
|
||||
|
@ -244,12 +239,10 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
// if close to now expect there can be some readings with time in close future (caused by wrong time setting)
|
||||
// so read all records
|
||||
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, false);
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start));
|
||||
aapsLogger.debug(LTag.AUTOSENS, "BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start));
|
||||
} else {
|
||||
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, to, false);
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start) + " End date: " + DateUtil.dateAndTimeString(to));
|
||||
aapsLogger.debug(LTag.AUTOSENS, "BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start) + " End date: " + DateUtil.dateAndTimeString(to));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -269,15 +262,13 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
totalDiff += diff;
|
||||
diff = Math.abs(diff);
|
||||
if (diff > T.secs(30).msecs()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Interval detection: values: " + bgReadings.size() + " diff: " + (diff / 1000) + "[s] is5minData: " + false);
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Interval detection: values: " + bgReadings.size() + " diff: " + (diff / 1000) + "[s] is5minData: " + false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
long averageDiff = totalDiff / bgReadings.size() / 1000;
|
||||
boolean is5mindata = averageDiff < 1;
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Interval detection: values: " + bgReadings.size() + " averageDiff: " + averageDiff + "[s] is5minData: " + is5mindata);
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Interval detection: values: " + bgReadings.size() + " averageDiff: " + averageDiff + "[s] is5minData: " + is5mindata);
|
||||
return is5mindata;
|
||||
}
|
||||
}
|
||||
|
@ -359,8 +350,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
|
||||
bucketed_data = new ArrayList<>();
|
||||
bucketed_data.add(bgReadings.get(0));
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Adding. bgTime: " + DateUtil.toISOString(bgReadings.get(0).date) + " lastbgTime: " + "none-first-value" + " " + bgReadings.get(0).toString());
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Adding. bgTime: " + DateUtil.toISOString(bgReadings.get(0).date) + " lastbgTime: " + "none-first-value" + " " + bgReadings.get(0).toString());
|
||||
int j = 0;
|
||||
for (int i = 1; i < bgReadings.size(); ++i) {
|
||||
long bgTime = bgReadings.get(i).date;
|
||||
|
@ -388,8 +378,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
newBgreading.value = Math.round(nextbg);
|
||||
//console.error("Interpolated", bucketed_data[j]);
|
||||
bucketed_data.add(newBgreading);
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Adding. bgTime: " + DateUtil.toISOString(bgTime) + " lastbgTime: " + DateUtil.toISOString(lastbgTime) + " " + newBgreading.toString());
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Adding. bgTime: " + DateUtil.toISOString(bgTime) + " lastbgTime: " + DateUtil.toISOString(lastbgTime) + " " + newBgreading.toString());
|
||||
|
||||
elapsed_minutes = elapsed_minutes - 5;
|
||||
lastbg = nextbg;
|
||||
|
@ -400,16 +389,14 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
newBgreading.value = bgReadings.get(i).value;
|
||||
newBgreading.date = bgTime;
|
||||
bucketed_data.add(newBgreading);
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Adding. bgTime: " + DateUtil.toISOString(bgTime) + " lastbgTime: " + DateUtil.toISOString(lastbgTime) + " " + newBgreading.toString());
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Adding. bgTime: " + DateUtil.toISOString(bgTime) + " lastbgTime: " + DateUtil.toISOString(lastbgTime) + " " + newBgreading.toString());
|
||||
} else if (Math.abs(elapsed_minutes) > 2) {
|
||||
j++;
|
||||
BgReading newBgreading = new BgReading();
|
||||
newBgreading.value = bgReadings.get(i).value;
|
||||
newBgreading.date = bgTime;
|
||||
bucketed_data.add(newBgreading);
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Adding. bgTime: " + DateUtil.toISOString(bgTime) + " lastbgTime: " + DateUtil.toISOString(lastbgTime) + " " + newBgreading.toString());
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Adding. bgTime: " + DateUtil.toISOString(bgTime) + " lastbgTime: " + DateUtil.toISOString(lastbgTime) + " " + newBgreading.toString());
|
||||
} else {
|
||||
bucketed_data.get(j).value = (bucketed_data.get(j).value + bgReadings.get(i).value) / 2;
|
||||
//log.error("***** Average");
|
||||
|
@ -422,34 +409,30 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
BgReading previous = bucketed_data.get(i + 1);
|
||||
long msecDiff = current.date - previous.date;
|
||||
long adjusted = (msecDiff - T.mins(5).msecs()) / 1000;
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Adjusting bucketed data time. Current: " + DateUtil.toISOString(current.date) + " to: " + DateUtil.toISOString(previous.date + T.mins(5).msecs()) + " by " + adjusted + " sec");
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Adjusting bucketed data time. Current: " + DateUtil.toISOString(current.date) + " to: " + DateUtil.toISOString(previous.date + T.mins(5).msecs()) + " by " + adjusted + " sec");
|
||||
if (Math.abs(adjusted) > 90) {
|
||||
// too big adjustment, fallback to non 5 min data
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Fallback to non 5 min data");
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Fallback to non 5 min data");
|
||||
createBucketedDataRecalculated();
|
||||
return;
|
||||
}
|
||||
current.date = previous.date + T.mins(5).msecs();
|
||||
}
|
||||
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Bucketed data created. Size: " + bucketed_data.size());
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Bucketed data created. Size: " + bucketed_data.size());
|
||||
}
|
||||
|
||||
public long calculateDetectionStart(long from, boolean limitDataToOldestAvailable) {
|
||||
Profile profile = ProfileFunctions.getInstance().getProfile(from);
|
||||
long calculateDetectionStart(long from, boolean limitDataToOldestAvailable) {
|
||||
Profile profile = profileFunction.getProfile(from);
|
||||
double dia = Constants.defaultDIA;
|
||||
if (profile != null) dia = profile.getDia();
|
||||
|
||||
long oldestDataAvailable = TreatmentsPlugin.getPlugin().oldestDataAvailable();
|
||||
long oldestDataAvailable = treatmentsPlugin.oldestDataAvailable();
|
||||
long getBGDataFrom;
|
||||
if (limitDataToOldestAvailable) {
|
||||
getBGDataFrom = Math.max(oldestDataAvailable, (long) (from - T.hours(1).msecs() * (24 + dia)));
|
||||
if (getBGDataFrom == oldestDataAvailable)
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Limiting data to oldest available temps: " + DateUtil.dateAndTimeFullString(oldestDataAvailable));
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Limiting data to oldest available temps: " + DateUtil.dateAndTimeFullString(oldestDataAvailable));
|
||||
} else
|
||||
getBGDataFrom = (long) (from - T.hours(1).msecs() * (24 + dia));
|
||||
return getBGDataFrom;
|
||||
|
@ -461,13 +444,13 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
}
|
||||
}
|
||||
|
||||
public IobTotal calculateFromTreatmentsAndTempsSynchronized(long time, AutosensResult lastAutosensResult, boolean exercise_mode, int half_basal_exercise_target, boolean isTempTarget) {
|
||||
private IobTotal calculateFromTreatmentsAndTempsSynchronized(long time, AutosensResult lastAutosensResult, boolean exercise_mode, int half_basal_exercise_target, boolean isTempTarget) {
|
||||
synchronized (dataLock) {
|
||||
return calculateFromTreatmentsAndTemps(time, lastAutosensResult, exercise_mode, half_basal_exercise_target, isTempTarget);
|
||||
}
|
||||
}
|
||||
|
||||
public IobTotal calculateFromTreatmentsAndTemps(long time, Profile profile) {
|
||||
IobTotal calculateFromTreatmentsAndTemps(long time, Profile profile) {
|
||||
long now = System.currentTimeMillis();
|
||||
time = roundUpTime(time);
|
||||
if (time < now && iobTable.get(time) != null) {
|
||||
|
@ -476,23 +459,22 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
} else {
|
||||
//log.debug(">>> calculateFromTreatmentsAndTemps Cache miss " + new Date(time).toLocaleString());
|
||||
}
|
||||
IobTotal bolusIob = TreatmentsPlugin.getPlugin().getCalculationToTimeTreatments(time).round();
|
||||
IobTotal basalIob = TreatmentsPlugin.getPlugin().getCalculationToTimeTempBasals(time, true, now).round();
|
||||
if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginType.APS)) {
|
||||
// Add expected zero temp basal for next 240 mins
|
||||
IobTotal basalIobWithZeroTemp = basalIob.copy();
|
||||
TemporaryBasal t = new TemporaryBasal()
|
||||
.date(now + 60 * 1000L)
|
||||
.duration(240)
|
||||
.absolute(0);
|
||||
if (t.date < time) {
|
||||
IobTotal calc = t.iobCalc(time, profile);
|
||||
basalIobWithZeroTemp.plus(calc);
|
||||
}
|
||||
|
||||
basalIob.iobWithZeroTemp = IobTotal.combine(bolusIob, basalIobWithZeroTemp).round();
|
||||
IobTotal bolusIob = treatmentsPlugin.getCalculationToTimeTreatments(time).round();
|
||||
IobTotal basalIob = treatmentsPlugin.getCalculationToTimeTempBasals(time, true, now).round();
|
||||
// OpenAPSSMB only
|
||||
// Add expected zero temp basal for next 240 mins
|
||||
IobTotal basalIobWithZeroTemp = basalIob.copy();
|
||||
TemporaryBasal t = new TemporaryBasal()
|
||||
.date(now + 60 * 1000L)
|
||||
.duration(240)
|
||||
.absolute(0);
|
||||
if (t.date < time) {
|
||||
IobTotal calc = t.iobCalc(time, profile);
|
||||
basalIobWithZeroTemp.plus(calc);
|
||||
}
|
||||
|
||||
basalIob.iobWithZeroTemp = IobTotal.combine(bolusIob, basalIobWithZeroTemp).round();
|
||||
|
||||
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
|
||||
if (time < System.currentTimeMillis()) {
|
||||
iobTable.put(time, iobTotal);
|
||||
|
@ -500,29 +482,28 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
return iobTotal;
|
||||
}
|
||||
|
||||
public IobTotal calculateFromTreatmentsAndTemps(long time, AutosensResult lastAutosensResult, boolean exercise_mode, int half_basal_exercise_target, boolean isTempTarget) {
|
||||
private IobTotal calculateFromTreatmentsAndTemps(long time, AutosensResult lastAutosensResult, boolean exercise_mode, int half_basal_exercise_target, boolean isTempTarget) {
|
||||
long now = DateUtil.now();
|
||||
|
||||
IobTotal bolusIob = TreatmentsPlugin.getPlugin().getCalculationToTimeTreatments(time).round();
|
||||
IobTotal basalIob = TreatmentsPlugin.getPlugin().getCalculationToTimeTempBasals(time, now, lastAutosensResult, exercise_mode, half_basal_exercise_target, isTempTarget).round();
|
||||
if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginType.APS)) {
|
||||
// Add expected zero temp basal for next 240 mins
|
||||
IobTotal basalIobWithZeroTemp = basalIob.copy();
|
||||
TemporaryBasal t = new TemporaryBasal()
|
||||
.date(now + 60 * 1000L)
|
||||
.duration(240)
|
||||
.absolute(0);
|
||||
if (t.date < time) {
|
||||
Profile profile = ProfileFunctions.getInstance().getProfile(t.date);
|
||||
if (profile != null) {
|
||||
IobTotal calc = t.iobCalc(time, profile, lastAutosensResult, exercise_mode, half_basal_exercise_target, isTempTarget);
|
||||
basalIobWithZeroTemp.plus(calc);
|
||||
}
|
||||
IobTotal bolusIob = treatmentsPlugin.getCalculationToTimeTreatments(time).round();
|
||||
IobTotal basalIob = treatmentsPlugin.getCalculationToTimeTempBasals(time, now, lastAutosensResult, exercise_mode, half_basal_exercise_target, isTempTarget).round();
|
||||
// OpenAPSSMB only
|
||||
// Add expected zero temp basal for next 240 mins
|
||||
IobTotal basalIobWithZeroTemp = basalIob.copy();
|
||||
TemporaryBasal t = new TemporaryBasal()
|
||||
.date(now + 60 * 1000L)
|
||||
.duration(240)
|
||||
.absolute(0);
|
||||
if (t.date < time) {
|
||||
Profile profile = profileFunction.getProfile(t.date);
|
||||
if (profile != null) {
|
||||
IobTotal calc = t.iobCalc(time, profile, lastAutosensResult, exercise_mode, half_basal_exercise_target, isTempTarget);
|
||||
basalIobWithZeroTemp.plus(calc);
|
||||
}
|
||||
|
||||
basalIob.iobWithZeroTemp = IobTotal.combine(bolusIob, basalIobWithZeroTemp).round();
|
||||
}
|
||||
|
||||
basalIob.iobWithZeroTemp = IobTotal.combine(bolusIob, basalIobWithZeroTemp).round();
|
||||
|
||||
return IobTotal.combine(bolusIob, basalIob).round();
|
||||
}
|
||||
|
||||
|
@ -544,7 +525,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
BasalData retval = basalDataTable.get(time);
|
||||
if (retval == null) {
|
||||
retval = new BasalData();
|
||||
TemporaryBasal tb = TreatmentsPlugin.getPlugin().getTempBasalFromHistory(time);
|
||||
TemporaryBasal tb = treatmentsPlugin.getTempBasalFromHistory(time);
|
||||
retval.basal = profile.getBasal(time);
|
||||
if (tb != null) {
|
||||
retval.isTempBasalRunning = true;
|
||||
|
@ -590,14 +571,12 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
@Nullable
|
||||
public AutosensData getLastAutosensDataSynchronized(String reason) {
|
||||
if (thread != null && thread.isAlive()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("AUTOSENSDATA is waiting for calculation thread: " + reason);
|
||||
aapsLogger.debug(LTag.AUTOSENS, "AUTOSENSDATA is waiting for calculation thread: " + reason);
|
||||
try {
|
||||
thread.join(5000);
|
||||
} catch (InterruptedException ignored) {
|
||||
}
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("AUTOSENSDATA finished waiting for calculation thread: " + reason);
|
||||
aapsLogger.debug(LTag.AUTOSENS, "AUTOSENSDATA finished waiting for calculation thread: " + reason);
|
||||
}
|
||||
synchronized (dataLock) {
|
||||
return getLastAutosensData(reason);
|
||||
|
@ -611,7 +590,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
Double displayCob = null;
|
||||
double futureCarbs = 0;
|
||||
long now = now();
|
||||
List<Treatment> treatments = TreatmentsPlugin.getPlugin().getTreatmentsFromHistory();
|
||||
List<Treatment> treatments = treatmentsPlugin.getTreatmentsFromHistory();
|
||||
|
||||
if (autosensData != null) {
|
||||
displayCob = autosensData.cob;
|
||||
|
@ -649,8 +628,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
@Nullable
|
||||
public AutosensData getLastAutosensData(String reason) {
|
||||
if (autosensDataTable.size() < 1) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("AUTOSENSDATA null: autosensDataTable empty (" + reason + ")");
|
||||
aapsLogger.debug(LTag.AUTOSENS, "AUTOSENSDATA null: autosensDataTable empty (" + reason + ")");
|
||||
return null;
|
||||
}
|
||||
AutosensData data;
|
||||
|
@ -660,20 +638,18 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
// data can be processed on the background
|
||||
// in this rare case better return null and do not block UI
|
||||
// APS plugin should use getLastAutosensDataSynchronized where the blocking is not an issue
|
||||
log.debug("AUTOSENSDATA null: Exception catched (" + reason + ")");
|
||||
aapsLogger.error("AUTOSENSDATA null: Exception catched (" + reason + ")");
|
||||
return null;
|
||||
}
|
||||
if (data == null) {
|
||||
log.debug("AUTOSENSDATA null: data==null");
|
||||
aapsLogger.error("AUTOSENSDATA null: data==null");
|
||||
return null;
|
||||
}
|
||||
if (data.time < System.currentTimeMillis() - 11 * 60 * 1000) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("AUTOSENSDATA null: data is old (" + reason + ") size()=" + autosensDataTable.size() + " lastdata=" + DateUtil.dateAndTimeString(data.time));
|
||||
aapsLogger.debug(LTag.AUTOSENS, "AUTOSENSDATA null: data is old (" + reason + ") size()=" + autosensDataTable.size() + " lastdata=" + DateUtil.dateAndTimeString(data.time));
|
||||
return null;
|
||||
} else {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("AUTOSENSDATA (" + reason + ") " + data.toString());
|
||||
aapsLogger.debug(LTag.AUTOSENS, "AUTOSENSDATA (" + reason + ") " + data.toString());
|
||||
return data;
|
||||
}
|
||||
}
|
||||
|
@ -685,6 +661,55 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
return "autosensDataTable empty";
|
||||
}
|
||||
|
||||
public MealData getMealData() {
|
||||
MealData result = new MealData();
|
||||
|
||||
Profile profile = profileFunction.getProfile();
|
||||
if (profile == null) return result;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
long dia_ago = now - (Double.valueOf(profile.getDia() * T.hours(1).msecs())).longValue();
|
||||
|
||||
double maxAbsorptionHours = Constants.DEFAULT_MAX_ABSORPTION_TIME;
|
||||
if (SensitivityAAPSPlugin.getPlugin().isEnabled(PluginType.SENSITIVITY) || SensitivityWeightedAveragePlugin.getPlugin().isEnabled(PluginType.SENSITIVITY)) {
|
||||
maxAbsorptionHours = sp.getDouble(R.string.key_absorption_maxtime, Constants.DEFAULT_MAX_ABSORPTION_TIME);
|
||||
} else {
|
||||
maxAbsorptionHours = sp.getDouble(R.string.key_absorption_cutoff, Constants.DEFAULT_MAX_ABSORPTION_TIME);
|
||||
}
|
||||
long absorptionTime_ago = now - (Double.valueOf(maxAbsorptionHours * T.hours(1).msecs())).longValue();
|
||||
|
||||
List<Treatment> treatments = treatmentsPlugin.getTreatmentsFromHistory();
|
||||
for (Treatment treatment : treatments) {
|
||||
if (!treatment.isValid)
|
||||
continue;
|
||||
long t = treatment.date;
|
||||
|
||||
if (t > dia_ago && t <= now) {
|
||||
if (treatment.insulin > 0 && treatment.mealBolus) {
|
||||
result.boluses += treatment.insulin;
|
||||
}
|
||||
}
|
||||
|
||||
if (t > absorptionTime_ago && t <= now) {
|
||||
if (treatment.carbs >= 1) {
|
||||
result.carbs += treatment.carbs;
|
||||
if (t > result.lastCarbTime)
|
||||
result.lastCarbTime = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AutosensData autosensData = getLastAutosensDataSynchronized("getMealData()");
|
||||
if (autosensData != null) {
|
||||
result.mealCOB = autosensData.cob;
|
||||
result.slopeFromMinDeviation = autosensData.slopeFromMinDeviation;
|
||||
result.slopeFromMaxDeviation = autosensData.slopeFromMaxDeviation;
|
||||
result.usedMinCarbsImpact = autosensData.usedMinCarbsImpact;
|
||||
}
|
||||
result.lastBolusTime = treatmentsPlugin.getLastBolusTime();
|
||||
return result;
|
||||
}
|
||||
|
||||
public IobTotal[] calculateIobArrayInDia(Profile profile) {
|
||||
// predict IOB out to DIA plus 30m
|
||||
long time = System.currentTimeMillis();
|
||||
|
@ -727,9 +752,9 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
return sb.toString();
|
||||
}
|
||||
|
||||
public AutosensResult detectSensitivityWithLock(long fromTime, long toTime) {
|
||||
AutosensResult detectSensitivityWithLock(long fromTime, long toTime) {
|
||||
synchronized (dataLock) {
|
||||
return ConfigBuilderPlugin.getPlugin().getActiveSensitivity().detectSensitivity(this, fromTime, toTime);
|
||||
return configBuilderPlugin.getActiveSensitivity().detectSensitivity(this, fromTime, toTime);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -744,19 +769,16 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
public void stopCalculation(String from) {
|
||||
if (thread != null && thread.getState() != Thread.State.TERMINATED) {
|
||||
stopCalculationTrigger = true;
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Stopping calculation thread: " + from);
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Stopping calculation thread: " + from);
|
||||
while (thread.getState() != Thread.State.TERMINATED) {
|
||||
SystemClock.sleep(100);
|
||||
}
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Calculation thread stopped: " + from);
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Calculation thread stopped: " + from);
|
||||
}
|
||||
}
|
||||
|
||||
public void runCalculation(String from, long end, boolean bgDataReload, boolean limitDataToOldestAvailable, Event cause) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Starting calculation thread: " + from + " to " + DateUtil.dateAndTimeString(end));
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Starting calculation thread: " + from + " to " + DateUtil.dateAndTimeString(end));
|
||||
if (thread == null || thread.getState() == Thread.State.TERMINATED) {
|
||||
if (SensitivityOref1Plugin.getPlugin().isEnabled(PluginType.SENSITIVITY))
|
||||
thread = new IobCobOref1Thread(this, from, end, bgDataReload, limitDataToOldestAvailable, cause);
|
||||
|
@ -767,23 +789,16 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
}
|
||||
|
||||
// When historical data is changed (comming from NS etc) finished calculations after this date must be invalidated
|
||||
public void newHistoryData(EventNewHistoryData ev) {
|
||||
if (this != getPlugin()) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Ignoring event for non default instance");
|
||||
return;
|
||||
}
|
||||
private void newHistoryData(EventNewHistoryData ev) {
|
||||
//log.debug("Locking onNewHistoryData");
|
||||
stopCalculation("onEventNewHistoryData");
|
||||
synchronized (dataLock) {
|
||||
// clear up 5 min back for proper COB calculation
|
||||
long time = ev.getTime() - 5 * 60 * 1000L;
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Invalidating cached data to: " + DateUtil.dateAndTimeFullString(time));
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Invalidating cached data to: " + DateUtil.dateAndTimeFullString(time));
|
||||
for (int index = iobTable.size() - 1; index >= 0; index--) {
|
||||
if (iobTable.keyAt(index) > time) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Removing from iobTable: " + DateUtil.dateAndTimeFullString(iobTable.keyAt(index)));
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Removing from iobTable: " + DateUtil.dateAndTimeFullString(iobTable.keyAt(index)));
|
||||
iobTable.removeAt(index);
|
||||
} else {
|
||||
break;
|
||||
|
@ -791,8 +806,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
}
|
||||
for (int index = autosensDataTable.size() - 1; index >= 0; index--) {
|
||||
if (autosensDataTable.keyAt(index) > time) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Removing from autosensDataTable: " + DateUtil.dateAndTimeFullString(autosensDataTable.keyAt(index)));
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Removing from autosensDataTable: " + DateUtil.dateAndTimeFullString(autosensDataTable.keyAt(index)));
|
||||
autosensDataTable.removeAt(index);
|
||||
} else {
|
||||
break;
|
||||
|
@ -800,8 +814,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
}
|
||||
for (int index = basalDataTable.size() - 1; index >= 0; index--) {
|
||||
if (basalDataTable.keyAt(index) > time) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Removing from basalDataTable: " + DateUtil.dateAndTimeFullString(basalDataTable.keyAt(index)));
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Removing from basalDataTable: " + DateUtil.dateAndTimeFullString(basalDataTable.keyAt(index)));
|
||||
basalDataTable.removeAt(index);
|
||||
} else {
|
||||
break;
|
||||
|
@ -814,8 +827,7 @@ public class IobCobCalculatorPlugin extends PluginBase {
|
|||
|
||||
public void clearCache() {
|
||||
synchronized (dataLock) {
|
||||
if (L.isEnabled(L.AUTOSENS))
|
||||
log.debug("Clearing cached data.");
|
||||
aapsLogger.debug(LTag.AUTOSENS, "Clearing cached data.");
|
||||
iobTable = new LongSparseArray<>();
|
||||
autosensDataTable = new LongSparseArray<>();
|
||||
basalDataTable = new LongSparseArray<>();
|
||||
|
|
|
@ -24,7 +24,6 @@ import info.nightscout.androidaps.data.DetailedBolusInfo;
|
|||
import info.nightscout.androidaps.data.Intervals;
|
||||
import info.nightscout.androidaps.data.Iob;
|
||||
import info.nightscout.androidaps.data.IobTotal;
|
||||
import info.nightscout.androidaps.data.MealData;
|
||||
import info.nightscout.androidaps.data.NonOverlappingIntervals;
|
||||
import info.nightscout.androidaps.data.OverlappingIntervals;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
|
@ -47,31 +46,28 @@ import info.nightscout.androidaps.interfaces.PumpInterface;
|
|||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBus;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction;
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
|
||||
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.general.overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensData;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.AutosensResult;
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.data.MedtronicHistoryData;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil;
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin;
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.SP;
|
||||
import info.nightscout.androidaps.utils.T;
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
import io.reactivex.schedulers.Schedulers;
|
||||
|
||||
@Singleton
|
||||
public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface {
|
||||
private final AAPSLogger aapsLogger;
|
||||
private final RxBusWrapper rxBus;
|
||||
private final MainApp mainApp;
|
||||
private final SP sp;
|
||||
private final ResourceHelper resourceHelper;
|
||||
private final ProfileFunction profileFunction;
|
||||
private final ConfigBuilderPlugin configBuilderPlugin;
|
||||
|
@ -103,10 +99,12 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
|
||||
@Inject
|
||||
public TreatmentsPlugin(AAPSLogger aapsLogger,
|
||||
RxBusWrapper rxBus,
|
||||
ResourceHelper resourceHelper,
|
||||
MainApp mainApp,
|
||||
ConfigBuilderPlugin configBuilderPlugin,
|
||||
ProfileFunction profileFunction
|
||||
SP sp,
|
||||
ProfileFunction profileFunction,
|
||||
ConfigBuilderPlugin configBuilderPlugin
|
||||
) {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.TREATMENT)
|
||||
|
@ -117,10 +115,12 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
.description(R.string.description_treatments)
|
||||
);
|
||||
this.aapsLogger = aapsLogger;
|
||||
this.rxBus = rxBus;
|
||||
this.resourceHelper = resourceHelper;
|
||||
this.mainApp = mainApp;
|
||||
this.configBuilderPlugin = configBuilderPlugin;
|
||||
this.sp = sp;
|
||||
this.profileFunction = profileFunction;
|
||||
this.configBuilderPlugin = configBuilderPlugin;
|
||||
treatmentsPlugin = this;
|
||||
}
|
||||
|
||||
|
@ -129,7 +129,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
this.service = new TreatmentService();
|
||||
initializeData(range());
|
||||
super.onStart();
|
||||
disposable.add(RxBus.Companion.getINSTANCE()
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventReloadTreatmentData.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
|
@ -137,23 +137,23 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
initializeTreatmentData(range());
|
||||
initializeExtendedBolusData(range());
|
||||
updateTotalIOBTreatments();
|
||||
RxBus.Companion.getINSTANCE().send(event.getNext());
|
||||
rxBus.send(event.getNext());
|
||||
},
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.Companion.getINSTANCE()
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventReloadProfileSwitchData.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> initializeProfileSwitchData(range()),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.Companion.getINSTANCE()
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventTempTargetChange.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> initializeTempTargetData(range()),
|
||||
FabricPrivacy::logException
|
||||
));
|
||||
disposable.add(RxBus.Companion.getINSTANCE()
|
||||
disposable.add(rxBus
|
||||
.toObservable(EventReloadTempBasalData.class)
|
||||
.observeOn(Schedulers.io())
|
||||
.subscribe(event -> {
|
||||
|
@ -265,7 +265,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
// instead of dividing the DIA that only worked on the bilinear curves,
|
||||
// multiply the time the treatment is seen active.
|
||||
long timeSinceTreatment = time - t.date;
|
||||
long snoozeTime = t.date + (long) (timeSinceTreatment * SP.getDouble(R.string.key_openapsama_bolussnooze_dia_divisor, 2.0));
|
||||
long snoozeTime = t.date + (long) (timeSinceTreatment * sp.getDouble(R.string.key_openapsama_bolussnooze_dia_divisor, 2.0));
|
||||
Iob bIOB = t.iobCalc(snoozeTime, dia);
|
||||
total.bolussnooze += bIOB.iobContrib;
|
||||
}
|
||||
|
@ -289,57 +289,6 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
lastTreatmentCalculation = getCalculationToTimeTreatments(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MealData getMealData() {
|
||||
MealData result = new MealData();
|
||||
|
||||
Profile profile = profileFunction.getProfile();
|
||||
if (profile == null) return result;
|
||||
|
||||
long now = System.currentTimeMillis();
|
||||
long dia_ago = now - (Double.valueOf(profile.getDia() * T.hours(1).msecs())).longValue();
|
||||
|
||||
double maxAbsorptionHours = Constants.DEFAULT_MAX_ABSORPTION_TIME;
|
||||
if (SensitivityAAPSPlugin.getPlugin().isEnabled(PluginType.SENSITIVITY) || SensitivityWeightedAveragePlugin.getPlugin().isEnabled(PluginType.SENSITIVITY)) {
|
||||
maxAbsorptionHours = SP.getDouble(R.string.key_absorption_maxtime, Constants.DEFAULT_MAX_ABSORPTION_TIME);
|
||||
} else {
|
||||
maxAbsorptionHours = SP.getDouble(R.string.key_absorption_cutoff, Constants.DEFAULT_MAX_ABSORPTION_TIME);
|
||||
}
|
||||
long absorptionTime_ago = now - (Double.valueOf(maxAbsorptionHours * T.hours(1).msecs())).longValue();
|
||||
|
||||
synchronized (treatments) {
|
||||
for (Treatment treatment : treatments) {
|
||||
if (!treatment.isValid)
|
||||
continue;
|
||||
long t = treatment.date;
|
||||
|
||||
if (t > dia_ago && t <= now) {
|
||||
if (treatment.insulin > 0 && treatment.mealBolus) {
|
||||
result.boluses += treatment.insulin;
|
||||
}
|
||||
}
|
||||
|
||||
if (t > absorptionTime_ago && t <= now) {
|
||||
if (treatment.carbs >= 1) {
|
||||
result.carbs += treatment.carbs;
|
||||
if (t > result.lastCarbTime)
|
||||
result.lastCarbTime = t;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
AutosensData autosensData = IobCobCalculatorPlugin.getPlugin().getLastAutosensDataSynchronized("getMealData()");
|
||||
if (autosensData != null) {
|
||||
result.mealCOB = autosensData.cob;
|
||||
result.slopeFromMinDeviation = autosensData.slopeFromMinDeviation;
|
||||
result.slopeFromMaxDeviation = autosensData.slopeFromMaxDeviation;
|
||||
result.usedMinCarbsImpact = autosensData.usedMinCarbsImpact;
|
||||
}
|
||||
result.lastBolusTime = getLastBolusTime();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Treatment> getTreatmentsFromHistory() {
|
||||
synchronized (treatments) {
|
||||
|
@ -779,7 +728,7 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
@Override
|
||||
public void addToHistoryProfileSwitch(ProfileSwitch profileSwitch) {
|
||||
//log.debug("Adding new TemporaryBasal record" + profileSwitch.log());
|
||||
RxBus.Companion.getINSTANCE().send(new EventDismissNotification(Notification.PROFILE_SWITCH_MISSING));
|
||||
rxBus.send(new EventDismissNotification(Notification.PROFILE_SWITCH_MISSING));
|
||||
MainApp.getDbHelper().createOrUpdate(profileSwitch);
|
||||
NSUpload.uploadProfileSwitch(profileSwitch);
|
||||
}
|
||||
|
@ -787,26 +736,26 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
|||
@Override
|
||||
public void doProfileSwitch(@NotNull final ProfileStore profileStore, @NotNull final String profileName, final int duration, final int percentage, final int timeShift, final long date) {
|
||||
ProfileSwitch profileSwitch = profileFunction.prepareProfileSwitch(profileStore, profileName, duration, percentage, timeShift, date);
|
||||
TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch);
|
||||
treatmentsPlugin.addToHistoryProfileSwitch(profileSwitch);
|
||||
if (percentage == 90 && duration == 10)
|
||||
SP.putBoolean(R.string.key_objectiveuseprofileswitch, true);
|
||||
sp.putBoolean(R.string.key_objectiveuseprofileswitch, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doProfileSwitch(final int duration, final int percentage, final int timeShift) {
|
||||
ProfileSwitch profileSwitch = TreatmentsPlugin.getPlugin().getProfileSwitchFromHistory(System.currentTimeMillis());
|
||||
ProfileSwitch profileSwitch = treatmentsPlugin.getProfileSwitchFromHistory(System.currentTimeMillis());
|
||||
if (profileSwitch != null) {
|
||||
profileSwitch = new ProfileSwitch();
|
||||
profileSwitch.date = System.currentTimeMillis();
|
||||
profileSwitch.source = Source.USER;
|
||||
profileSwitch.profileName = profileFunction.getProfileName(System.currentTimeMillis(), false, false);
|
||||
profileSwitch.profileJson = profileFunction.getProfile().getData().toString();
|
||||
profileSwitch.profilePlugin = ConfigBuilderPlugin.getPlugin().getActiveProfileInterface().getClass().getName();
|
||||
profileSwitch.profilePlugin = configBuilderPlugin.getActiveProfileInterface().getClass().getName();
|
||||
profileSwitch.durationInMinutes = duration;
|
||||
profileSwitch.isCPP = percentage != 100 || timeShift != 0;
|
||||
profileSwitch.timeshift = timeShift;
|
||||
profileSwitch.percentage = percentage;
|
||||
TreatmentsPlugin.getPlugin().addToHistoryProfileSwitch(profileSwitch);
|
||||
treatmentsPlugin.addToHistoryProfileSwitch(profileSwitch);
|
||||
} else {
|
||||
aapsLogger.error(LTag.PROFILE, "No profile switch exists");
|
||||
}
|
||||
|
|
|
@ -7,20 +7,24 @@ import info.nightscout.androidaps.R
|
|||
import info.nightscout.androidaps.db.TDD
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin
|
||||
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunction
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentService
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import javax.inject.Inject
|
||||
|
||||
class TddCalculator @Inject constructor(
|
||||
val aapsLogger: AAPSLogger,
|
||||
val rxBus: RxBusWrapper,
|
||||
val resourceHelper: ResourceHelper,
|
||||
val mainApp: MainApp,
|
||||
val sp: SP,
|
||||
val configBuilderPlugin: ConfigBuilderPlugin,
|
||||
val profileFunction: ProfileFunction
|
||||
) : TreatmentsPlugin(aapsLogger, resourceHelper, mainApp, configBuilderPlugin, profileFunction) {
|
||||
) : TreatmentsPlugin(aapsLogger, rxBus, resourceHelper, mainApp, sp, profileFunction, configBuilderPlugin) {
|
||||
|
||||
init {
|
||||
service = TreatmentService() // plugin is not started
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="info.nightscout.androidaps.activities.HistoryBrowseActivity">
|
||||
tools:context="info.nightscout.androidaps.historyBrowser.HistoryBrowseActivity">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
|
|
Loading…
Reference in a new issue