work from old autosens branch
This commit is contained in:
parent
b67d8be1ef
commit
e90812634b
10 changed files with 291 additions and 154 deletions
|
@ -10,15 +10,18 @@ public class AutosensData {
|
||||||
long time = 0L;
|
long time = 0L;
|
||||||
public String pastSensitivity = "";
|
public String pastSensitivity = "";
|
||||||
public double deviation = 0d;
|
public double deviation = 0d;
|
||||||
boolean calculateWithDeviation = false;
|
boolean nonCarbsDeviation = false;
|
||||||
|
boolean nonEqualDeviation = false;
|
||||||
double absorbed = 0d;
|
double absorbed = 0d;
|
||||||
public double carbsFromBolus = 0d;
|
public double carbsFromBolus = 0d;
|
||||||
public double cob = 0;
|
public double cob = 0;
|
||||||
public double bgi = 0d;
|
public double bgi = 0d;
|
||||||
public double delta = 0d;
|
public double delta = 0d;
|
||||||
|
|
||||||
|
public double autosensRatio = 1d;
|
||||||
|
|
||||||
public String log(long time) {
|
public String log(long time) {
|
||||||
return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " Bgi=" + bgi + " Deviation=" + deviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob;
|
return "AutosensData: " + new Date(time).toLocaleString() + " " + pastSensitivity + " Delta=" + delta + " Bgi=" + bgi + " Deviation=" + deviation + " Absorbed=" + absorbed + " CarbsFromBolus=" + carbsFromBolus + " COB=" + cob + " autosensRatio=" + autosensRatio;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int minOld() {
|
public int minOld() {
|
||||||
|
|
|
@ -19,6 +19,7 @@ import java.util.List;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
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.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.Profile;
|
import info.nightscout.androidaps.data.Profile;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
|
@ -26,6 +27,7 @@ import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventNewBG;
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||||
|
import info.nightscout.androidaps.events.EventPreferenceChange;
|
||||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.events.BasalData;
|
||||||
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
|
||||||
|
@ -304,6 +306,8 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
if (MainApp.getConfigBuilder() == null)
|
if (MainApp.getConfigBuilder() == null)
|
||||||
return; // app still initializing
|
return; // app still initializing
|
||||||
//log.debug("Locking calculateSensitivityData");
|
//log.debug("Locking calculateSensitivityData");
|
||||||
|
long oldestTimeWithData = oldestDataAvailable();
|
||||||
|
|
||||||
synchronized (dataLock) {
|
synchronized (dataLock) {
|
||||||
|
|
||||||
if (bucketed_data == null || bucketed_data.size() < 3) {
|
if (bucketed_data == null || bucketed_data.size() < 3) {
|
||||||
|
@ -371,12 +375,14 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
if (autosensData.cob <= 0) {
|
if (autosensData.cob <= 0) {
|
||||||
if (Math.abs(deviation) < Constants.DEVIATION_TO_BE_EQUAL) {
|
if (Math.abs(deviation) < Constants.DEVIATION_TO_BE_EQUAL) {
|
||||||
autosensData.pastSensitivity += "=";
|
autosensData.pastSensitivity += "=";
|
||||||
|
autosensData.nonEqualDeviation = true;
|
||||||
} else if (deviation > 0) {
|
} else if (deviation > 0) {
|
||||||
autosensData.pastSensitivity += "+";
|
autosensData.pastSensitivity += "+";
|
||||||
|
autosensData.nonEqualDeviation = true;
|
||||||
} else {
|
} else {
|
||||||
autosensData.pastSensitivity += "-";
|
autosensData.pastSensitivity += "-";
|
||||||
}
|
}
|
||||||
autosensData.calculateWithDeviation = true;
|
autosensData.nonCarbsDeviation = true;
|
||||||
} else {
|
} else {
|
||||||
autosensData.pastSensitivity += "C";
|
autosensData.pastSensitivity += "C";
|
||||||
}
|
}
|
||||||
|
@ -384,6 +390,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
|
|
||||||
previous = autosensData;
|
previous = autosensData;
|
||||||
autosensDataTable.put(bgTime, autosensData);
|
autosensDataTable.put(bgTime, autosensData);
|
||||||
|
autosensData.autosensRatio = detectSensitivity(oldestTimeWithData, bgTime).ratio;
|
||||||
if (Config.logAutosensData)
|
if (Config.logAutosensData)
|
||||||
log.debug(autosensData.log(bgTime));
|
log.debug(autosensData.log(bgTime));
|
||||||
}
|
}
|
||||||
|
@ -392,6 +399,15 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
//log.debug("Releasing calculateSensitivityData");
|
//log.debug("Releasing calculateSensitivityData");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long oldestDataAvailable() {
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
|
long oldestDataAvailable = MainApp.getConfigBuilder().oldestDataAvailable();
|
||||||
|
long getBGDataFrom = Math.max(oldestDataAvailable, (long) (now - 60 * 60 * 1000L * (24 + MainApp.getConfigBuilder().getProfile().getDia())));
|
||||||
|
log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString());
|
||||||
|
return getBGDataFrom;
|
||||||
|
}
|
||||||
|
|
||||||
public static IobTotal calulateFromTreatmentsAndTemps(long time) {
|
public static IobTotal calulateFromTreatmentsAndTemps(long time) {
|
||||||
long now = System.currentTimeMillis();
|
long now = System.currentTimeMillis();
|
||||||
time = roundUpTime(time);
|
time = roundUpTime(time);
|
||||||
|
@ -493,17 +509,30 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
return array;
|
return array;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AutosensResult detectSensitivity(long fromTime) {
|
public static AutosensResult detectSensitivityWithLock(long fromTime, long toTime) {
|
||||||
//log.debug("Locking detectSensitivity");
|
|
||||||
synchronized (dataLock) {
|
synchronized (dataLock) {
|
||||||
|
return detectSensitivity(fromTime, toTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AutosensResult detectSensitivity(long fromTime, long toTime) {
|
||||||
|
String age = SP.getString(R.string.key_age, "");
|
||||||
|
int defaultHours = 24;
|
||||||
|
if (age.equals(MainApp.sResources.getString(R.string.key_adult))) defaultHours = 24;
|
||||||
|
if (age.equals(MainApp.sResources.getString(R.string.key_teenage))) defaultHours = 4;
|
||||||
|
if (age.equals(MainApp.sResources.getString(R.string.key_child))) defaultHours = 4;
|
||||||
|
int hoursForDetection = SP.getInt(R.string.key_openapsama_autosens_period, defaultHours);
|
||||||
|
|
||||||
|
long now = System.currentTimeMillis();
|
||||||
|
|
||||||
if (autosensDataTable == null || autosensDataTable.size() < 4) {
|
if (autosensDataTable == null || autosensDataTable.size() < 4) {
|
||||||
log.debug("No autosens data available");
|
log.debug("No autosens data available");
|
||||||
return new AutosensResult();
|
return new AutosensResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
AutosensData current = getLastAutosensData();
|
AutosensData current = getAutosensData(toTime);
|
||||||
if (current == null) {
|
if (current == null) {
|
||||||
log.debug("No current autosens data available");
|
log.debug("No autosens data available");
|
||||||
return new AutosensResult();
|
return new AutosensResult();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -519,8 +548,16 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (autosensData.calculateWithDeviation)
|
if (autosensData.time > toTime) {
|
||||||
deviationsArray.add(autosensData.deviation);
|
index++;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (autosensData.time > now - hoursForDetection * 60 * 60 * 1000L)
|
||||||
|
deviationsArray.add(autosensData.nonEqualDeviation ? autosensData.deviation : 0d);
|
||||||
|
if (deviationsArray.size() > hoursForDetection * 60 / 5)
|
||||||
|
deviationsArray.remove(0);
|
||||||
|
|
||||||
|
|
||||||
pastSensitivity += autosensData.pastSensitivity;
|
pastSensitivity += autosensData.pastSensitivity;
|
||||||
int secondsFromMidnight = Profile.secondsFromMidnight(autosensData.time);
|
int secondsFromMidnight = Profile.secondsFromMidnight(autosensData.time);
|
||||||
|
@ -537,34 +574,25 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
|
|
||||||
double sens = profile.getIsf();
|
double sens = profile.getIsf();
|
||||||
|
|
||||||
double ratio = 1;
|
|
||||||
String ratioLimit = "";
|
String ratioLimit = "";
|
||||||
String sensResult = "";
|
String sensResult = "";
|
||||||
|
|
||||||
log.debug("Records: " + index + " " + pastSensitivity);
|
log.debug("Records: " + index + " " + pastSensitivity);
|
||||||
Arrays.sort(deviations);
|
Arrays.sort(deviations);
|
||||||
|
|
||||||
for (double i = 0.9; i > 0.1; i = i - 0.02) {
|
double percentile = percentile(deviations, 0.50);
|
||||||
if (percentile(deviations, (i + 0.02)) >= 0 && percentile(deviations, i) < 0) {
|
double basalOff = percentile * (60 / 5) / Profile.toMgdl(sens, profile.getUnits());
|
||||||
log.debug(Math.round(100 * i) + "% of non-meal deviations negative (target 45%-50%)");
|
double ratio = 1 + (basalOff / profile.getMaxDailyBasal());
|
||||||
}
|
|
||||||
}
|
|
||||||
double pSensitive = percentile(deviations, 0.50);
|
|
||||||
double pResistant = percentile(deviations, 0.45);
|
|
||||||
|
|
||||||
double basalOff = 0;
|
if (percentile < 0) { // sensitive
|
||||||
|
|
||||||
if (pSensitive < 0) { // sensitive
|
|
||||||
basalOff = pSensitive * (60 / 5) / Profile.toMgdl(sens, profile.getUnits());
|
|
||||||
sensResult = "Excess insulin sensitivity detected";
|
sensResult = "Excess insulin sensitivity detected";
|
||||||
} else if (pResistant > 0) { // resistant
|
} else if (percentile > 0) { // resistant
|
||||||
basalOff = pResistant * (60 / 5) / Profile.toMgdl(sens, profile.getUnits());
|
|
||||||
sensResult = "Excess insulin resistance detected";
|
sensResult = "Excess insulin resistance detected";
|
||||||
} else {
|
} else {
|
||||||
sensResult = "Sensitivity normal";
|
sensResult = "Sensitivity normal";
|
||||||
}
|
}
|
||||||
|
|
||||||
log.debug(sensResult);
|
log.debug(sensResult);
|
||||||
ratio = 1 + (basalOff / profile.getMaxDailyBasal());
|
|
||||||
|
|
||||||
double rawRatio = ratio;
|
double rawRatio = ratio;
|
||||||
ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_min", "0.7")));
|
ratio = Math.max(ratio, SafeParse.stringToDouble(SP.getString("openapsama_autosens_min", "0.7")));
|
||||||
|
@ -575,10 +603,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
log.debug(ratioLimit);
|
log.debug(ratioLimit);
|
||||||
}
|
}
|
||||||
|
|
||||||
double newisf = Math.round(Profile.toMgdl(sens, profile.getUnits()) / ratio);
|
log.error("Sensitivity to: " + new Date(toTime).toLocaleString() + " percentile: " + percentile);
|
||||||
if (ratio != 1) {
|
|
||||||
log.debug("ISF adjusted from " + Profile.toMgdl(sens, profile.getUnits()) + " to " + newisf);
|
|
||||||
}
|
|
||||||
|
|
||||||
AutosensResult output = new AutosensResult();
|
AutosensResult output = new AutosensResult();
|
||||||
output.ratio = Round.roundTo(ratio, 0.01);
|
output.ratio = Round.roundTo(ratio, 0.01);
|
||||||
|
@ -588,8 +613,6 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
output.sensResult = sensResult;
|
output.sensResult = sensResult;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
//log.debug("Releasing detectSensitivity");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static JSONArray convertToJSONArray(IobTotal[] iobArray) {
|
public static JSONArray convertToJSONArray(IobTotal[] iobArray) {
|
||||||
|
@ -634,6 +657,25 @@ public class IobCobCalculatorPlugin implements PluginBase {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onStatusEvent(EventPreferenceChange ev) {
|
||||||
|
if (ev.isChanged(R.string.key_openapsama_autosens_period) ||
|
||||||
|
ev.isChanged(R.string.key_age)
|
||||||
|
) {
|
||||||
|
synchronized (dataLock) {
|
||||||
|
log.debug("Invalidating cached data because of preference change. IOB: " + iobTable.size() + " Autosens: " + autosensDataTable.size() + " records");
|
||||||
|
iobTable = new LongSparseArray<>();
|
||||||
|
autosensDataTable = new LongSparseArray<>();
|
||||||
|
}
|
||||||
|
sHandler.post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
calculateSensitivityData();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// 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
|
||||||
@Subscribe
|
@Subscribe
|
||||||
public void onNewHistoryData(EventNewHistoryData ev) {
|
public void onNewHistoryData(EventNewHistoryData ev) {
|
||||||
|
|
|
@ -207,14 +207,9 @@ public class OpenAPSAMAPlugin implements PluginBase, APSInterface {
|
||||||
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
|
if (!checkOnlyHardLimits(profile.getMaxDailyBasal(), "max_daily_basal", 0.1, 10)) return;
|
||||||
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;
|
if (!checkOnlyHardLimits(pump.getBaseBasalRate(), "current_basal", 0.01, 5)) return;
|
||||||
|
|
||||||
long oldestDataAvailable = MainApp.getConfigBuilder().oldestDataAvailable();
|
|
||||||
long getBGDataFrom = Math.max(oldestDataAvailable, (long) (System.currentTimeMillis() - 60 * 60 * 1000L * (24 + profile.getDia())));
|
|
||||||
log.debug("Limiting data to oldest available temps: " + new Date(oldestDataAvailable).toString());
|
|
||||||
|
|
||||||
startPart = new Date();
|
startPart = new Date();
|
||||||
if (MainApp.getConfigBuilder().isAMAModeEnabled()) {
|
if (MainApp.getConfigBuilder().isAMAModeEnabled()) {
|
||||||
//lastAutosensResult = Autosens.detectSensitivityandCarbAbsorption(getBGDataFrom, null);
|
lastAutosensResult = IobCobCalculatorPlugin.detectSensitivityWithLock(IobCobCalculatorPlugin.oldestDataAvailable(), System.currentTimeMillis());
|
||||||
lastAutosensResult = IobCobCalculatorPlugin.detectSensitivity(getBGDataFrom);
|
|
||||||
} else {
|
} else {
|
||||||
lastAutosensResult = new AutosensResult();
|
lastAutosensResult = new AutosensResult();
|
||||||
}
|
}
|
||||||
|
|
|
@ -164,6 +164,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
CheckBox showIobView;
|
CheckBox showIobView;
|
||||||
CheckBox showCobView;
|
CheckBox showCobView;
|
||||||
CheckBox showDeviationsView;
|
CheckBox showDeviationsView;
|
||||||
|
CheckBox showRatiosView;
|
||||||
|
|
||||||
RecyclerView notificationsView;
|
RecyclerView notificationsView;
|
||||||
LinearLayoutManager llm;
|
LinearLayoutManager llm;
|
||||||
|
@ -275,36 +276,25 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
showIobView = (CheckBox) view.findViewById(R.id.overview_showiob);
|
showIobView = (CheckBox) view.findViewById(R.id.overview_showiob);
|
||||||
showCobView = (CheckBox) view.findViewById(R.id.overview_showcob);
|
showCobView = (CheckBox) view.findViewById(R.id.overview_showcob);
|
||||||
showDeviationsView = (CheckBox) view.findViewById(R.id.overview_showdeviations);
|
showDeviationsView = (CheckBox) view.findViewById(R.id.overview_showdeviations);
|
||||||
|
showRatiosView = (CheckBox) view.findViewById(R.id.overview_showratios);
|
||||||
showPredictionView.setChecked(SP.getBoolean("showprediction", false));
|
showPredictionView.setChecked(SP.getBoolean("showprediction", false));
|
||||||
showBasalsView.setChecked(SP.getBoolean("showbasals", true));
|
showBasalsView.setChecked(SP.getBoolean("showbasals", true));
|
||||||
showIobView.setChecked(SP.getBoolean("showiob", false));
|
showIobView.setChecked(SP.getBoolean("showiob", false));
|
||||||
showCobView.setChecked(SP.getBoolean("showcob", false));
|
showCobView.setChecked(SP.getBoolean("showcob", false));
|
||||||
showDeviationsView.setChecked(SP.getBoolean("showdeviations", false));
|
showDeviationsView.setChecked(SP.getBoolean("showdeviations", false));
|
||||||
|
showRatiosView.setChecked(SP.getBoolean("showratios", false));
|
||||||
showPredictionView.setOnCheckedChangeListener(this);
|
showPredictionView.setOnCheckedChangeListener(this);
|
||||||
showBasalsView.setOnCheckedChangeListener(this);
|
showBasalsView.setOnCheckedChangeListener(this);
|
||||||
showIobView.setOnCheckedChangeListener(this);
|
showIobView.setOnCheckedChangeListener(this);
|
||||||
showCobView.setOnCheckedChangeListener(this);
|
showCobView.setOnCheckedChangeListener(this);
|
||||||
showDeviationsView.setOnCheckedChangeListener(this);
|
showDeviationsView.setOnCheckedChangeListener(this);
|
||||||
|
showRatiosView.setOnCheckedChangeListener(this);
|
||||||
|
|
||||||
notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications);
|
notificationsView = (RecyclerView) view.findViewById(R.id.overview_notifications);
|
||||||
notificationsView.setHasFixedSize(true);
|
notificationsView.setHasFixedSize(true);
|
||||||
llm = new LinearLayoutManager(view.getContext());
|
llm = new LinearLayoutManager(view.getContext());
|
||||||
notificationsView.setLayoutManager(llm);
|
notificationsView.setLayoutManager(llm);
|
||||||
/*
|
|
||||||
final LinearLayout graphs = (LinearLayout)view.findViewById(R.id.overview_graphs_layout);
|
|
||||||
ViewTreeObserver observer = graphs.getViewTreeObserver();
|
|
||||||
observer.addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
|
|
||||||
@Override
|
|
||||||
public void onGlobalLayout() {
|
|
||||||
log.debug("Height: " + graphs.getHeight());
|
|
||||||
graphs.getViewTreeObserver().removeGlobalOnLayoutListener(
|
|
||||||
this);
|
|
||||||
int heightNeeded = Math.max(320, graphs.getHeight() - 200);
|
|
||||||
if (heightNeeded != bgGraph.getHeight())
|
|
||||||
bgGraph.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, heightNeeded));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
*/
|
|
||||||
bgGraph.getGridLabelRenderer().setGridColor(MainApp.sResources.getColor(R.color.graphgrid));
|
bgGraph.getGridLabelRenderer().setGridColor(MainApp.sResources.getColor(R.color.graphgrid));
|
||||||
bgGraph.getGridLabelRenderer().reloadStyles();
|
bgGraph.getGridLabelRenderer().reloadStyles();
|
||||||
iobGraph.getGridLabelRenderer().setGridColor(MainApp.sResources.getColor(R.color.graphgrid));
|
iobGraph.getGridLabelRenderer().setGridColor(MainApp.sResources.getColor(R.color.graphgrid));
|
||||||
|
@ -358,34 +348,29 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
|
||||||
switch (buttonView.getId()) {
|
switch (buttonView.getId()) {
|
||||||
case R.id.overview_showprediction:
|
case R.id.overview_showprediction:
|
||||||
SP.putBoolean("showprediction", showPredictionView.isChecked());
|
|
||||||
updateGUI("onPredictionCheckedChanged");
|
|
||||||
break;
|
|
||||||
case R.id.overview_showbasals:
|
case R.id.overview_showbasals:
|
||||||
SP.putBoolean("showbasals", showBasalsView.isChecked());
|
|
||||||
updateGUI("onBasalsCheckedChanged");
|
|
||||||
break;
|
|
||||||
case R.id.overview_showiob:
|
case R.id.overview_showiob:
|
||||||
SP.putBoolean("showiob", showIobView.isChecked());
|
|
||||||
updateGUI("onIobCheckedChanged");
|
|
||||||
break;
|
break;
|
||||||
case R.id.overview_showcob:
|
case R.id.overview_showcob:
|
||||||
showDeviationsView.setOnCheckedChangeListener(null);
|
showDeviationsView.setOnCheckedChangeListener(null);
|
||||||
showDeviationsView.setChecked(false);
|
showDeviationsView.setChecked(false);
|
||||||
showDeviationsView.setOnCheckedChangeListener(this);
|
showDeviationsView.setOnCheckedChangeListener(this);
|
||||||
SP.putBoolean("showcob", showCobView.isChecked());
|
|
||||||
SP.putBoolean("showdeviations", showDeviationsView.isChecked());
|
|
||||||
updateGUI("onCobCheckedChanged");
|
|
||||||
break;
|
break;
|
||||||
case R.id.overview_showdeviations:
|
case R.id.overview_showdeviations:
|
||||||
showCobView.setOnCheckedChangeListener(null);
|
showCobView.setOnCheckedChangeListener(null);
|
||||||
showCobView.setChecked(false);
|
showCobView.setChecked(false);
|
||||||
showCobView.setOnCheckedChangeListener(this);
|
showCobView.setOnCheckedChangeListener(this);
|
||||||
SP.putBoolean("showcob", showCobView.isChecked());
|
break;
|
||||||
SP.putBoolean("showdeviations", showDeviationsView.isChecked());
|
case R.id.overview_showratios:
|
||||||
updateGUI("onDeviationsCheckedChanged");
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
SP.putBoolean("showiob", showIobView.isChecked());
|
||||||
|
SP.putBoolean("showprediction", showPredictionView.isChecked());
|
||||||
|
SP.putBoolean("showbasals", showBasalsView.isChecked());
|
||||||
|
SP.putBoolean("showcob", showCobView.isChecked());
|
||||||
|
SP.putBoolean("showdeviations", showDeviationsView.isChecked());
|
||||||
|
SP.putBoolean("showratios", showRatiosView.isChecked());
|
||||||
|
scheduleUpdateGUI("onGraphCheckboxesCheckedChanged");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1289,15 +1274,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
FixedLineGraphSeries<DataPoint> iobSeries;
|
FixedLineGraphSeries<DataPoint> iobSeries;
|
||||||
FixedLineGraphSeries<DataPoint> cobSeries;
|
FixedLineGraphSeries<DataPoint> cobSeries;
|
||||||
BarGraphSeries<DeviationDataPoint> devSeries;
|
BarGraphSeries<DeviationDataPoint> devSeries;
|
||||||
|
LineGraphSeries<DataPoint> ratioSeries;
|
||||||
Double maxIobValueFound = 0d;
|
Double maxIobValueFound = 0d;
|
||||||
Double maxCobValueFound = 0d;
|
Double maxCobValueFound = 0d;
|
||||||
Double maxDevValueFound = 0d;
|
Double maxDevValueFound = 0d;
|
||||||
|
Double maxRatioValueFound = 0d;
|
||||||
|
|
||||||
if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked()) {
|
if (showIobView.isChecked() || showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) {
|
||||||
//Date start = new Date();
|
//Date start = new Date();
|
||||||
List<DataPoint> iobArray = new ArrayList<>();
|
List<DataPoint> iobArray = new ArrayList<>();
|
||||||
List<DataPoint> cobArray = new ArrayList<>();
|
List<DataPoint> cobArray = new ArrayList<>();
|
||||||
List<DeviationDataPoint> devArray = new ArrayList<>();
|
List<DeviationDataPoint> devArray = new ArrayList<>();
|
||||||
|
List<DataPoint> ratioArray = new ArrayList<>();
|
||||||
double lastIob = 0;
|
double lastIob = 0;
|
||||||
int lastCob = 0;
|
int lastCob = 0;
|
||||||
for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) {
|
for (long time = fromTime; time <= now; time += 5 * 60 * 1000L) {
|
||||||
|
@ -1311,7 +1299,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
lastIob = iob;
|
lastIob = iob;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (showCobView.isChecked() || showDeviationsView.isChecked()) {
|
if (showCobView.isChecked() || showDeviationsView.isChecked() || showRatiosView.isChecked()) {
|
||||||
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
|
AutosensData autosensData = IobCobCalculatorPlugin.getAutosensData(time);
|
||||||
if (autosensData != null && showCobView.isChecked()) {
|
if (autosensData != null && showCobView.isChecked()) {
|
||||||
int cob = (int) autosensData.cob;
|
int cob = (int) autosensData.cob;
|
||||||
|
@ -1331,6 +1319,10 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
devArray.add(new DeviationDataPoint(time, autosensData.deviation, color));
|
devArray.add(new DeviationDataPoint(time, autosensData.deviation, color));
|
||||||
maxDevValueFound = Math.max(maxDevValueFound, Math.abs(autosensData.deviation));
|
maxDevValueFound = Math.max(maxDevValueFound, Math.abs(autosensData.deviation));
|
||||||
}
|
}
|
||||||
|
if (autosensData != null && showRatiosView.isChecked()) {
|
||||||
|
ratioArray.add(new DataPoint(time, autosensData.autosensRatio));
|
||||||
|
maxRatioValueFound = Math.max(maxRatioValueFound, Math.abs(autosensData.autosensRatio));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//Profiler.log(log, "IOB processed", start);
|
//Profiler.log(log, "IOB processed", start);
|
||||||
|
@ -1343,18 +1335,49 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
iobSeries.setThickness(3);
|
iobSeries.setThickness(3);
|
||||||
|
|
||||||
|
|
||||||
if (showIobView.isChecked() && (showCobView.isChecked() || showDeviationsView.isChecked())) {
|
Double maxByScale = null;
|
||||||
List<DataPoint> cobArrayRescaled = new ArrayList<>();
|
int graphsToShow = 0;
|
||||||
List<DeviationDataPoint> devArrayRescaled = new ArrayList<>();
|
if (showIobView.isChecked()) {
|
||||||
for (int ci = 0; ci < cobArray.size(); ci++) {
|
if (maxByScale == null) maxByScale = maxIobValueFound;
|
||||||
cobArrayRescaled.add(new DataPoint(cobArray.get(ci).getX(), cobArray.get(ci).getY() * maxIobValueFound / maxCobValueFound / 2));
|
graphsToShow++;
|
||||||
}
|
}
|
||||||
for (int ci = 0; ci < devArray.size(); ci++) {
|
if (showCobView.isChecked()) {
|
||||||
devArrayRescaled.add(new DeviationDataPoint(devArray.get(ci).getX(), devArray.get(ci).getY() * maxIobValueFound / maxDevValueFound, devArray.get(ci).color));
|
if (maxByScale == null) maxByScale = maxCobValueFound;
|
||||||
|
graphsToShow++;
|
||||||
|
}
|
||||||
|
if (showDeviationsView.isChecked()) {
|
||||||
|
if (maxByScale == null) maxByScale = maxDevValueFound;
|
||||||
|
graphsToShow++;
|
||||||
|
}
|
||||||
|
if (showRatiosView.isChecked()) {
|
||||||
|
if (maxByScale == null) maxByScale = maxRatioValueFound;
|
||||||
|
graphsToShow++;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (graphsToShow > 1) {
|
||||||
|
if (!maxByScale.equals(maxCobValueFound)) {
|
||||||
|
List<DataPoint> cobArrayRescaled = new ArrayList<>();
|
||||||
|
for (int ci = 0; ci < cobArray.size(); ci++) {
|
||||||
|
cobArrayRescaled.add(new DataPoint(cobArray.get(ci).getX(), cobArray.get(ci).getY() * maxByScale / maxCobValueFound / 2));
|
||||||
}
|
}
|
||||||
cobArray = cobArrayRescaled;
|
cobArray = cobArrayRescaled;
|
||||||
|
}
|
||||||
|
if (!maxByScale.equals(maxDevValueFound)) {
|
||||||
|
List<DeviationDataPoint> devArrayRescaled = new ArrayList<>();
|
||||||
|
for (int ci = 0; ci < devArray.size(); ci++) {
|
||||||
|
devArrayRescaled.add(new DeviationDataPoint(devArray.get(ci).getX(), devArray.get(ci).getY() * maxByScale / maxDevValueFound, devArray.get(ci).color));
|
||||||
|
}
|
||||||
devArray = devArrayRescaled;
|
devArray = devArrayRescaled;
|
||||||
}
|
}
|
||||||
|
if (!maxByScale.equals(maxRatioValueFound)) {
|
||||||
|
List<DataPoint> ratioArrayRescaled = new ArrayList<>();
|
||||||
|
for (int ci = 0; ci < ratioArray.size(); ci++) {
|
||||||
|
ratioArrayRescaled.add(new DataPoint(ratioArray.get(ci).getX(), (ratioArray.get(ci).getY() - 1) * maxByScale / maxRatioValueFound));
|
||||||
|
}
|
||||||
|
ratioArray = ratioArrayRescaled;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// COB
|
// COB
|
||||||
DataPoint[] cobData = new DataPoint[cobArray.size()];
|
DataPoint[] cobData = new DataPoint[cobArray.size()];
|
||||||
cobData = cobArray.toArray(cobData);
|
cobData = cobArray.toArray(cobData);
|
||||||
|
@ -1374,9 +1397,13 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
return data.color;
|
return data.color;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
//devSeries.setBackgroundColor(0xB0FFFFFF & MainApp.sResources.getColor(R.color.cob)); //50%
|
|
||||||
//devSeries.setColor(MainApp.sResources.getColor(R.color.cob));
|
// RATIOS
|
||||||
//devSeries.setThickness(3);
|
DataPoint[] ratioData = new DataPoint[ratioArray.size()];
|
||||||
|
ratioData = ratioArray.toArray(ratioData);
|
||||||
|
ratioSeries = new LineGraphSeries<>(ratioData);
|
||||||
|
ratioSeries.setColor(MainApp.sResources.getColor(R.color.ratio));
|
||||||
|
ratioSeries.setThickness(3);
|
||||||
|
|
||||||
iobGraph.getSeries().clear();
|
iobGraph.getSeries().clear();
|
||||||
|
|
||||||
|
@ -1389,6 +1416,9 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
if (showDeviationsView.isChecked() && devData.length > 0) {
|
if (showDeviationsView.isChecked() && devData.length > 0) {
|
||||||
addSeriesWithoutInvalidate(devSeries, iobGraph);
|
addSeriesWithoutInvalidate(devSeries, iobGraph);
|
||||||
}
|
}
|
||||||
|
if (showRatiosView.isChecked() && ratioData.length > 0) {
|
||||||
|
addSeriesWithoutInvalidate(ratioSeries, iobGraph);
|
||||||
|
}
|
||||||
iobGraph.setVisibility(View.VISIBLE);
|
iobGraph.setVisibility(View.VISIBLE);
|
||||||
} else {
|
} else {
|
||||||
iobGraph.setVisibility(View.GONE);
|
iobGraph.setVisibility(View.GONE);
|
||||||
|
@ -1591,20 +1621,18 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
|
|
||||||
|
|
||||||
//Notifications
|
//Notifications
|
||||||
public static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.NotificationsViewHolder> {
|
static class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.NotificationsViewHolder> {
|
||||||
|
|
||||||
List<Notification> notificationsList;
|
List<Notification> notificationsList;
|
||||||
|
|
||||||
RecyclerViewAdapter(List<Notification> notificationsList) {
|
RecyclerViewAdapter(List<Notification> notificationsList) {
|
||||||
this.notificationsList = notificationsList;
|
this.notificationsList = notificationsList;
|
||||||
log.debug("RecyclerViewAdapter");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public NotificationsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
public NotificationsViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
|
||||||
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.overview_notification_item, viewGroup, false);
|
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.overview_notification_item, viewGroup, false);
|
||||||
NotificationsViewHolder notificationsViewHolder = new NotificationsViewHolder(v);
|
return new NotificationsViewHolder(v);
|
||||||
return notificationsViewHolder;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1635,7 +1663,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
|
||||||
super.onAttachedToRecyclerView(recyclerView);
|
super.onAttachedToRecyclerView(recyclerView);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class NotificationsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
static class NotificationsViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
|
||||||
CardView cv;
|
CardView cv;
|
||||||
TextView time;
|
TextView time;
|
||||||
TextView text;
|
TextView text;
|
||||||
|
|
|
@ -287,6 +287,22 @@
|
||||||
android:layout_marginBottom="-5dp"
|
android:layout_marginBottom="-5dp"
|
||||||
android:layout_marginTop="-9dp"
|
android:layout_marginTop="-9dp"
|
||||||
app:buttonTint="@color/deviations" />
|
app:buttonTint="@color/deviations" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:text="@string/ratio_short"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/overview_showratios"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="-5dp"
|
||||||
|
android:layout_marginTop="-9dp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
|
@ -286,6 +286,22 @@
|
||||||
android:layout_marginBottom="-5dp"
|
android:layout_marginBottom="-5dp"
|
||||||
android:layout_marginTop="-9dp"
|
android:layout_marginTop="-9dp"
|
||||||
app:buttonTint="@color/deviations" />
|
app:buttonTint="@color/deviations" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:text="@string/ratio_short"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/overview_showratios"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="-5dp"
|
||||||
|
android:layout_marginTop="-9dp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
|
@ -502,6 +502,22 @@
|
||||||
android:layout_marginBottom="-5dp"
|
android:layout_marginBottom="-5dp"
|
||||||
android:layout_marginTop="-9dp"
|
android:layout_marginTop="-9dp"
|
||||||
app:buttonTint="@color/deviations" />
|
app:buttonTint="@color/deviations" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:text="@string/ratio_short"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||||
|
android:textStyle="bold" />
|
||||||
|
|
||||||
|
<CheckBox
|
||||||
|
android:id="@+id/overview_showratios"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="-5dp"
|
||||||
|
android:layout_marginTop="-9dp" />
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
<color name="basal">#00ffff</color>
|
<color name="basal">#00ffff</color>
|
||||||
<color name="iob">#FFFB8C00</color>
|
<color name="iob">#FFFB8C00</color>
|
||||||
<color name="cob">#8BC34A</color>
|
<color name="cob">#8BC34A</color>
|
||||||
|
<color name="ratio">#FFFFFF</color>
|
||||||
<color name="inrange">#00FF00</color>
|
<color name="inrange">#00FF00</color>
|
||||||
<color name="low">#FF0000</color>
|
<color name="low">#FF0000</color>
|
||||||
<color name="high">#FFFF00</color>
|
<color name="high">#FFFF00</color>
|
||||||
|
|
|
@ -646,4 +646,8 @@
|
||||||
<string name="nsalarm_urgentstaledata">Urgent stale data</string>
|
<string name="nsalarm_urgentstaledata">Urgent stale data</string>
|
||||||
<string name="nsalarm_staledatavalue_label">Stale data threshold [min]</string>
|
<string name="nsalarm_staledatavalue_label">Stale data threshold [min]</string>
|
||||||
<string name="nsalarm_urgent_staledatavalue_label">Urgent stale data threshold [min]</string>
|
<string name="nsalarm_urgent_staledatavalue_label">Urgent stale data threshold [min]</string>
|
||||||
|
<string name="openapsama_autosens_period">Interval for autosens [h]</string>
|
||||||
|
<string name="openapsama_autosens_period_summary">Amount of hours in the past for sensitivity detection (carbs absorption time is excluded)</string>
|
||||||
|
<string name="key_openapsama_autosens_period" translatable="false">openapsama_autosens_period</string>
|
||||||
|
<string name="ratio_short">RAT</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:validate="http://schemas.android.com/apk/res-auto">
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="openapsama"
|
android:key="openapsama"
|
||||||
android:title="@string/openapsama">
|
android:title="@string/openapsama">
|
||||||
|
@ -9,6 +10,21 @@
|
||||||
android:key="openapsama_useautosens"
|
android:key="openapsama_useautosens"
|
||||||
android:title="@string/openapsama_useautosens" />
|
android:title="@string/openapsama_useautosens" />
|
||||||
|
|
||||||
|
<com.andreabaccega.widget.ValidatingEditTextPreference
|
||||||
|
validate:maxNumber="24"
|
||||||
|
validate:minNumber="4"
|
||||||
|
validate:testType="numericRange"
|
||||||
|
android:defaultValue="24"
|
||||||
|
android:dependency="openapsama_useautosens"
|
||||||
|
android:dialogMessage="@string/openapsama_autosens_period_summary"
|
||||||
|
android:digits="0123456789"
|
||||||
|
android:inputType="number"
|
||||||
|
android:key="@string/key_openapsama_autosens_period"
|
||||||
|
android:maxLines="20"
|
||||||
|
android:selectAllOnFocus="true"
|
||||||
|
android:singleLine="true"
|
||||||
|
android:title="@string/openapsama_autosens_period" />
|
||||||
|
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
|
|
||||||
</PreferenceScreen>
|
</PreferenceScreen>
|
Loading…
Reference in a new issue