Merge pull request #1686 from MilosKozak/fix1660

Fix1660
This commit is contained in:
Milos Kozak 2019-03-19 23:33:53 +01:00 committed by GitHub
commit 8629203041
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 43 additions and 46 deletions

View file

@ -464,7 +464,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return new ArrayList<BgReading>();
return new ArrayList<>();
}
public List<BgReading> getBgreadingsDataFromTime(long start, long end, boolean ascending) {
@ -481,7 +481,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} catch (SQLException e) {
log.error("Unhandled exception", e);
}
return new ArrayList<BgReading>();
return new ArrayList<>();
}
public List<BgReading> getAllBgreadingsDataFromTime(long mills, boolean ascending) {

View file

@ -51,17 +51,16 @@ import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.events.EventFeatureRunning;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.interfaces.Constraint;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.CobInfo;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.queue.Callback;
import info.nightscout.androidaps.utils.BolusWizard;
@ -165,18 +164,6 @@ public class WizardDialog extends DialogFragment implements OnClickListener, Com
}
@Subscribe
public void onStatusEvent(final EventNewBG e) {
Activity activity = getActivity();
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
calculateInsulin();
}
});
}
@Subscribe
public void onStatusEvent(final EventAutosensCalculationFinished e) {
Activity activity = getActivity();

View file

@ -27,7 +27,6 @@ import info.nightscout.androidaps.db.DatabaseHelper;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshOverview;
@ -39,6 +38,7 @@ import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DecimalFormatter;
@ -283,7 +283,7 @@ public class PersistentNotificationPlugin extends PluginBase {
}
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
triggerNotificationUpdate();
}

View file

@ -9,7 +9,6 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.events.EventBolusRequested;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshOverview;
@ -23,6 +22,7 @@ import info.nightscout.androidaps.plugins.aps.openAPSMA.events.EventOpenAPSUpdat
import info.nightscout.androidaps.plugins.general.overview.events.EventDismissBolusprogressIfRunning;
import info.nightscout.androidaps.plugins.general.overview.events.EventOverviewBolusProgress;
import info.nightscout.androidaps.plugins.general.wear.wearintegration.WatchUpdaterService;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.utils.SP;
/**
@ -136,7 +136,7 @@ public class WearPlugin extends PluginBase {
}
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
sendDataToWatch(true, true, true);
}

View file

@ -17,7 +17,6 @@ import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventAppInitialized;
import info.nightscout.androidaps.events.EventConfigBuilderChange;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventRefreshOverview;
import info.nightscout.androidaps.events.EventTempBasalChange;
@ -26,10 +25,11 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PluginDescription;
import info.nightscout.androidaps.interfaces.PluginType;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DecimalFormatter;
@ -115,7 +115,7 @@ public class StatuslinePlugin extends PluginBase {
if (ConfigBuilderPlugin.getPlugin().getActivePump() == null)
return "";
LoopPlugin loopPlugin = LoopPlugin.getPlugin();
if (!loopPlugin.isEnabled(PluginType.LOOP)) {
@ -138,7 +138,7 @@ public class StatuslinePlugin extends PluginBase {
IobTotal bolusIob = treatmentsInterface.getLastCalculationTreatments().round();
treatmentsInterface.updateTotalIOBTempBasals();
IobTotal basalIob = treatmentsInterface.getLastCalculationTempBasals().round();
status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob)+"U";
status += DecimalFormatter.to2Decimal(bolusIob.iob + basalIob.basaliob) + "U";
if (mPrefs.getBoolean("xdripstatus_detailediob", true)) {
@ -182,7 +182,7 @@ public class StatuslinePlugin extends PluginBase {
}
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
sendStatus();
}

View file

@ -65,8 +65,6 @@ public class IobCobCalculatorPlugin extends PluginBase {
private volatile List<BgReading> bgReadings = null; // newest at index 0
private volatile List<BgReading> bucketed_data = null;
private double dia = Constants.defaultDIA;
final Object dataLock = new Object();
boolean stopCalculationTrigger = false;
@ -118,11 +116,22 @@ public class IobCobCalculatorPlugin extends PluginBase {
return rounded;
}
void loadBgData(long now) {
long start = (long) (now - 60 * 60 * 1000L * (24 + dia));
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, now, false);
if (L.isEnabled(L.AUTOSENS))
log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start) + " End date: " + DateUtil.dateAndTimeString(now));
void loadBgData(long to) {
Profile profile = ProfileFunctions.getInstance().getProfile(to);
double dia = Constants.defaultDIA;
if (profile != null) dia = profile.getDia();
long start = to - T.hours((long) (24 + dia)).msecs();
if (DateUtil.isCloseToNow(to)) {
// if close to now expect there can be some readings with time in close future (caused by wrong time setting)
// so read all records
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, false);
if (L.isEnabled(L.AUTOSENS))
log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start));
} else {
bgReadings = MainApp.getDbHelper().getBgreadingsDataFromTime(start, to, false);
if (L.isEnabled(L.AUTOSENS))
log.debug("BG data loaded. Size: " + bgReadings.size() + " Start date: " + DateUtil.dateAndTimeString(start) + " End date: " + DateUtil.dateAndTimeString(to));
}
}
public boolean isAbout5minData() {
@ -608,10 +617,6 @@ public class IobCobCalculatorPlugin extends PluginBase {
}
if (ConfigBuilderPlugin.getPlugin() == null)
return; // app still initializing
Profile profile = ProfileFunctions.getInstance().getProfile();
if (profile == null)
return; // app still initializing
dia = profile.getDia();
if (ev == null) { // on init no need of reset
return;
}

View file

@ -21,10 +21,10 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.utils.T;
@ -67,7 +67,7 @@ public class BGSourceFragment extends SubscriberFragment {
}
@Subscribe
public void onStatusEvent(final EventNewBG unused) {
public void onStatusEvent(final EventAutosensCalculationFinished unused) {
updateGUI();
}

View file

@ -28,12 +28,12 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.plugins.treatments.Treatment;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.plugins.treatments.dialogs.WizardInfoDialog;
@ -266,7 +266,7 @@ public class TreatmentsBolusFragment extends SubscriberFragment implements View.
}
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
updateGUI();
}

View file

@ -25,14 +25,14 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.db.ExtendedBolus;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
public class TreatmentsExtendedBolusesFragment extends SubscriberFragment {
@ -186,7 +186,7 @@ public class TreatmentsExtendedBolusesFragment extends SubscriberFragment {
}
@Subscribe
public void onStatusEvent(final EventNewBG ev) {
public void onStatusEvent(final EventAutosensCalculationFinished ev) {
updateGUI();
}

View file

@ -25,16 +25,16 @@ import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.Profile;
import info.nightscout.androidaps.db.Source;
import info.nightscout.androidaps.db.TemporaryBasal;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.plugins.common.SubscriberFragment;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
import info.nightscout.androidaps.plugins.general.nsclient.UploadQueue;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin;
import info.nightscout.androidaps.utils.DateUtil;
import info.nightscout.androidaps.utils.DecimalFormatter;
import info.nightscout.androidaps.utils.FabricPrivacy;
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload;
public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment {
@ -212,7 +212,7 @@ public class TreatmentsTemporaryBasalsFragment extends SubscriberFragment {
}
@Subscribe
public void onStatusEvent(final EventNewBG ignored) {
public void onStatusEvent(final EventAutosensCalculationFinished ignored) {
updateGUI();
}

View file

@ -182,4 +182,9 @@ public class DateUtil {
public static long roundDateToSec(long date) {
return date - date % 1000;
}
public static boolean isCloseToNow(long date) {
long diff = Math.abs(date - now());
return diff < T.mins(2).msecs();
}
}