reuse profile object

This commit is contained in:
Milos Kozak 2017-06-13 19:37:31 +02:00
parent 2c2b6c21a1
commit 745a3cf874
4 changed files with 23 additions and 20 deletions

View file

@ -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) {

View file

@ -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;

View file

@ -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)

View file

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