From 745a3cf87450090f412118db2737e0fab043b1e4 Mon Sep 17 00:00:00 2001 From: Milos Kozak Date: Tue, 13 Jun 2017 19:37:31 +0200 Subject: [PATCH] reuse profile object --- .../androidaps/db/ExtendedBolus.java | 4 ---- .../androidaps/db/ProfileSwitch.java | 15 +++++++++++++++ .../ConfigBuilder/ConfigBuilderPlugin.java | 6 +----- .../IobCobCalculatorPlugin.java | 18 +++++++----------- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java b/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java index 05c5360e22..8fdd41e220 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ExtendedBolus.java @@ -171,12 +171,8 @@ public class ExtendedBolus implements Interval, DataPointWithLabelInterface { public IobTotal iobCalc(long time) { IobTotal result = new IobTotal(time); - Profile profile = MainApp.getConfigBuilder().getProfile(time); InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin(); - if (profile == null) - return result; - int realDuration = getDurationToTime(time); if (realDuration > 0) { diff --git a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java index 25ba1cb051..8c257141c5 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java +++ b/app/src/main/java/info/nightscout/androidaps/db/ProfileSwitch.java @@ -5,12 +5,15 @@ import android.graphics.Color; import com.j256.ormlite.field.DatabaseField; import com.j256.ormlite.table.DatabaseTable; +import org.json.JSONException; +import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import java.util.Date; import java.util.Objects; +import info.nightscout.androidaps.data.Profile; import info.nightscout.androidaps.interfaces.Interval; import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface; import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries; @@ -50,6 +53,18 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface { @DatabaseField public int durationInMinutes = 0; + private Profile profile = null; + + public Profile getProfileObject() { + if (profile == null) + try { + profile = new Profile(new JSONObject(profileJson)); + } catch (JSONException e) { + e.printStackTrace(); + } + return profile; + } + public boolean isEqual(ProfileSwitch other) { if (date != other.date) { return false; diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java index c5d27a7e11..d7d808ea42 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/ConfigBuilder/ConfigBuilderPlugin.java @@ -1017,11 +1017,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain ProfileSwitch profileSwitch = getProfileSwitchFromHistory(time); if (profileSwitch != null) { if (profileSwitch.profileJson != null) { - try { - return new Profile(new JSONObject(profileSwitch.profileJson)); - } catch (JSONException e) { - e.printStackTrace(); - } + return profileSwitch.getProfileObject(); } else { Profile profile = activeProfile.getProfile().getSpecificProfile(profileSwitch.profileName); if (profile != null) diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java index 4b7060e52f..2759099995 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/IobCobCalculator/IobCobCalculatorPlugin.java @@ -326,18 +326,14 @@ public class IobCobCalculatorPlugin implements PluginBase { long now = new Date().getTime(); time = roundUpTime(time); if (time < now && iobTable.get(time) != null) { - //log.debug(">>> Cache hit"); + //og.debug(">>> calulateFromTreatmentsAndTemps Cache hit " + new Date(time).toLocaleString()); return iobTable.get(time); } else { - //log.debug(">>> Cache miss " + new Date(time).toLocaleString()); + //log.debug(">>> calulateFromTreatmentsAndTemps Cache miss " + new Date(time).toLocaleString()); } IobTotal bolusIob = MainApp.getConfigBuilder().getCalculationToTimeTreatments(time).round(); IobTotal basalIob = MainApp.getConfigBuilder().getCalculationToTimeTempBasals(time).round(); -/* - if (basalIob.basaliob > 0) { - log.debug(new Date(time).toLocaleString() + " basaliob: " + basalIob.basaliob ); - } -*/ + IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round(); if (time < new Date().getTime()) { iobTable.put(time, iobTotal); @@ -374,9 +370,9 @@ public class IobCobCalculatorPlugin implements PluginBase { if (time < now) { basalDataTable.append(time, retval); } - //log.debug(">>> Cache miss " + new Date(time).toLocaleString()); + //log.debug(">>> getBasalData Cache miss " + new Date(time).toLocaleString()); } else { - //log.debug(">>> Cache hit " + new Date(time).toLocaleString()); + //log.debug(">>> getBasalData Cache hit " + new Date(time).toLocaleString()); } return retval; } @@ -391,10 +387,10 @@ public class IobCobCalculatorPlugin implements PluginBase { time = roundUpTime(previous); AutosensData data = autosensDataTable.get(time); if (data != null) { - //log.debug(">>> Cache hit " + data.log(time)); + //log.debug(">>> getAutosensData Cache hit " + data.log(time)); return data; } else { - //log.debug(">>> Cache miss " + new Date(time).toLocaleString()); + //log.debug(">>> getAutosensData Cache miss " + new Date(time).toLocaleString()); return null; } }