reuse profile object
This commit is contained in:
parent
2c2b6c21a1
commit
745a3cf874
|
@ -171,12 +171,8 @@ public class ExtendedBolus implements Interval, DataPointWithLabelInterface {
|
||||||
|
|
||||||
public IobTotal iobCalc(long time) {
|
public IobTotal iobCalc(long time) {
|
||||||
IobTotal result = new IobTotal(time);
|
IobTotal result = new IobTotal(time);
|
||||||
Profile profile = MainApp.getConfigBuilder().getProfile(time);
|
|
||||||
InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
|
InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
|
||||||
|
|
||||||
if (profile == null)
|
|
||||||
return result;
|
|
||||||
|
|
||||||
int realDuration = getDurationToTime(time);
|
int realDuration = getDurationToTime(time);
|
||||||
|
|
||||||
if (realDuration > 0) {
|
if (realDuration > 0) {
|
||||||
|
|
|
@ -5,12 +5,15 @@ import android.graphics.Color;
|
||||||
import com.j256.ormlite.field.DatabaseField;
|
import com.j256.ormlite.field.DatabaseField;
|
||||||
import com.j256.ormlite.table.DatabaseTable;
|
import com.j256.ormlite.table.DatabaseTable;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.interfaces.Interval;
|
import info.nightscout.androidaps.interfaces.Interval;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
|
||||||
import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
|
import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLabelGraphSeries;
|
||||||
|
@ -50,6 +53,18 @@ public class ProfileSwitch implements Interval, DataPointWithLabelInterface {
|
||||||
@DatabaseField
|
@DatabaseField
|
||||||
public int durationInMinutes = 0;
|
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) {
|
public boolean isEqual(ProfileSwitch other) {
|
||||||
if (date != other.date) {
|
if (date != other.date) {
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1017,11 +1017,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
ProfileSwitch profileSwitch = getProfileSwitchFromHistory(time);
|
ProfileSwitch profileSwitch = getProfileSwitchFromHistory(time);
|
||||||
if (profileSwitch != null) {
|
if (profileSwitch != null) {
|
||||||
if (profileSwitch.profileJson != null) {
|
if (profileSwitch.profileJson != null) {
|
||||||
try {
|
return profileSwitch.getProfileObject();
|
||||||
return new Profile(new JSONObject(profileSwitch.profileJson));
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Profile profile = activeProfile.getProfile().getSpecificProfile(profileSwitch.profileName);
|
Profile profile = activeProfile.getProfile().getSpecificProfile(profileSwitch.profileName);
|
||||||
if (profile != null)
|
if (profile != null)
|
||||||
|
|
|
@ -326,18 +326,14 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
long now = new Date().getTime();
|
long now = new Date().getTime();
|
||||||
time = roundUpTime(time);
|
time = roundUpTime(time);
|
||||||
if (time < now && iobTable.get(time) != null) {
|
if (time < now && iobTable.get(time) != null) {
|
||||||
//log.debug(">>> Cache hit");
|
//og.debug(">>> calulateFromTreatmentsAndTemps Cache hit " + new Date(time).toLocaleString());
|
||||||
return iobTable.get(time);
|
return iobTable.get(time);
|
||||||
} else {
|
} 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 bolusIob = MainApp.getConfigBuilder().getCalculationToTimeTreatments(time).round();
|
||||||
IobTotal basalIob = MainApp.getConfigBuilder().getCalculationToTimeTempBasals(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();
|
IobTotal iobTotal = IobTotal.combine(bolusIob, basalIob).round();
|
||||||
if (time < new Date().getTime()) {
|
if (time < new Date().getTime()) {
|
||||||
iobTable.put(time, iobTotal);
|
iobTable.put(time, iobTotal);
|
||||||
|
@ -374,9 +370,9 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
if (time < now) {
|
if (time < now) {
|
||||||
basalDataTable.append(time, retval);
|
basalDataTable.append(time, retval);
|
||||||
}
|
}
|
||||||
//log.debug(">>> Cache miss " + new Date(time).toLocaleString());
|
//log.debug(">>> getBasalData Cache miss " + new Date(time).toLocaleString());
|
||||||
} else {
|
} else {
|
||||||
//log.debug(">>> Cache hit " + new Date(time).toLocaleString());
|
//log.debug(">>> getBasalData Cache hit " + new Date(time).toLocaleString());
|
||||||
}
|
}
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
@ -391,10 +387,10 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
time = roundUpTime(previous);
|
time = roundUpTime(previous);
|
||||||
AutosensData data = autosensDataTable.get(time);
|
AutosensData data = autosensDataTable.get(time);
|
||||||
if (data != null) {
|
if (data != null) {
|
||||||
//log.debug(">>> Cache hit " + data.log(time));
|
//log.debug(">>> getAutosensData Cache hit " + data.log(time));
|
||||||
return data;
|
return data;
|
||||||
} else {
|
} else {
|
||||||
//log.debug(">>> Cache miss " + new Date(time).toLocaleString());
|
//log.debug(">>> getAutosensData Cache miss " + new Date(time).toLocaleString());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue