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