Merge branch 'dev' into automatic-careportal-events
This commit is contained in:
commit
9b91b4ab93
10 changed files with 64 additions and 66 deletions
|
@ -472,7 +472,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ------------- DbRequests handling -------------------
|
// ------------- DbRequests handling -------------------
|
||||||
|
|
||||||
public void create(DbRequest dbr) {
|
public void create(DbRequest dbr) {
|
||||||
|
@ -509,7 +508,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
queryBuilder.limit(10L);
|
queryBuilder.limit(10L);
|
||||||
PreparedQuery<DbRequest> preparedQuery = queryBuilder.prepare();
|
PreparedQuery<DbRequest> preparedQuery = queryBuilder.prepare();
|
||||||
List<DbRequest> dbList = getDaoDbRequest().query(preparedQuery);
|
List<DbRequest> dbList = getDaoDbRequest().query(preparedQuery);
|
||||||
log.error("deleteDbRequestbyMongoId query size: " + dbList.size());
|
|
||||||
for (DbRequest r : dbList) {
|
for (DbRequest r : dbList) {
|
||||||
delete(r);
|
delete(r);
|
||||||
}
|
}
|
||||||
|
@ -1154,37 +1152,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public void createExtendedBolusFromJsonIfNotExists(JSONObject trJson) {
|
public void createExtendedBolusFromJsonIfNotExists(JSONObject json) {
|
||||||
try {
|
ExtendedBolus extendedBolus = ExtendedBolus.createFromJson(json);
|
||||||
QueryBuilder<ExtendedBolus, Long> queryBuilder = null;
|
if (extendedBolus != null)
|
||||||
queryBuilder = getDaoExtendedBolus().queryBuilder();
|
|
||||||
Where where = queryBuilder.where();
|
|
||||||
where.eq("_id", trJson.getString("_id")).or().eq("date", trJson.getLong("mills"));
|
|
||||||
PreparedQuery<ExtendedBolus> preparedQuery = queryBuilder.prepare();
|
|
||||||
List<ExtendedBolus> list = getDaoExtendedBolus().query(preparedQuery);
|
|
||||||
ExtendedBolus extendedBolus;
|
|
||||||
if (list.size() == 0) {
|
|
||||||
extendedBolus = new ExtendedBolus();
|
|
||||||
extendedBolus.source = Source.NIGHTSCOUT;
|
|
||||||
if (Config.logIncommingData)
|
|
||||||
log.debug("Adding ExtendedBolus record to database: " + trJson.toString());
|
|
||||||
// Record does not exists. add
|
|
||||||
} else if (list.size() == 1) {
|
|
||||||
extendedBolus = list.get(0);
|
|
||||||
if (Config.logIncommingData)
|
|
||||||
log.debug("Updating ExtendedBolus record in database: " + trJson.toString());
|
|
||||||
} else {
|
|
||||||
log.error("Something went wrong");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
extendedBolus.date = trJson.getLong("mills");
|
|
||||||
extendedBolus.durationInMinutes = trJson.has("duration") ? trJson.getInt("duration") : 0;
|
|
||||||
extendedBolus.insulin = trJson.getDouble("relative");
|
|
||||||
extendedBolus._id = trJson.getString("_id");
|
|
||||||
createOrUpdate(extendedBolus);
|
createOrUpdate(extendedBolus);
|
||||||
} catch (SQLException | JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void scheduleExtendedBolusChange() {
|
private static void scheduleExtendedBolusChange() {
|
||||||
|
|
|
@ -9,6 +9,8 @@ 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;
|
||||||
|
|
||||||
|
@ -25,6 +27,7 @@ import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLab
|
||||||
import info.nightscout.androidaps.plugins.Treatments.Treatment;
|
import info.nightscout.androidaps.plugins.Treatments.Treatment;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.DecimalFormatter;
|
import info.nightscout.utils.DecimalFormatter;
|
||||||
|
import info.nightscout.utils.JsonHelper;
|
||||||
import info.nightscout.utils.Round;
|
import info.nightscout.utils.Round;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -89,6 +92,16 @@ public class ExtendedBolus implements Interval, DataPointWithLabelInterface {
|
||||||
pumpId = t.pumpId;
|
pumpId = t.pumpId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ExtendedBolus createFromJson(JSONObject json) {
|
||||||
|
ExtendedBolus extendedBolus = new ExtendedBolus();
|
||||||
|
extendedBolus.source = Source.NIGHTSCOUT;
|
||||||
|
extendedBolus.date = JsonHelper.safeGetLong(json, "mills");
|
||||||
|
extendedBolus.durationInMinutes = JsonHelper.safeGetInt(json, "duration");
|
||||||
|
extendedBolus.insulin = JsonHelper.safeGetDouble(json, "relative") / 60 * extendedBolus.durationInMinutes;
|
||||||
|
extendedBolus._id = JsonHelper.safeGetString(json, "_id");
|
||||||
|
extendedBolus.pumpId = JsonHelper.safeGetLong(json, "pumpId");
|
||||||
|
return extendedBolus;
|
||||||
|
}
|
||||||
// -------- Interval interface ---------
|
// -------- Interval interface ---------
|
||||||
|
|
||||||
Long cuttedEnd = null;
|
Long cuttedEnd = null;
|
||||||
|
|
|
@ -150,13 +150,10 @@ public abstract class PluginBase {
|
||||||
|
|
||||||
protected void onStart() {
|
protected void onStart() {
|
||||||
if (getType() == PluginType.PUMP) {
|
if (getType() == PluginType.PUMP) {
|
||||||
try {
|
|
||||||
new Thread(() -> {
|
new Thread(() -> {
|
||||||
SystemClock.sleep(3000);
|
SystemClock.sleep(3000);
|
||||||
ConfigBuilderPlugin.getCommandQueue().readStatus("Pump driver changed.", null);
|
ConfigBuilderPlugin.getCommandQueue().readStatus("Pump driver changed.", null);
|
||||||
}).start();
|
}).start();
|
||||||
} catch (Exception ignored) { // Thread fail to start in tests
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -169,7 +169,11 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Constraint<Double> applyMaxIOBConstraints(Constraint<Double> maxIob) {
|
public Constraint<Double> applyMaxIOBConstraints(Constraint<Double> maxIob) {
|
||||||
double maxIobPref = SP.getDouble(R.string.key_openapsma_max_iob, 1.5d);
|
double maxIobPref;
|
||||||
|
if (OpenAPSSMBPlugin.getPlugin().isEnabled(PluginType.APS))
|
||||||
|
maxIobPref = SP.getDouble(R.string.key_openapssmb_max_iob, 3d);
|
||||||
|
else
|
||||||
|
maxIobPref = SP.getDouble(R.string.key_openapsma_max_iob, 1.5d);
|
||||||
maxIob.setIfSmaller(maxIobPref, String.format(MainApp.gs(R.string.limitingiob), maxIobPref, MainApp.gs(R.string.maxvalueinpreferences)), this);
|
maxIob.setIfSmaller(maxIobPref, String.format(MainApp.gs(R.string.limitingiob), maxIobPref, MainApp.gs(R.string.maxvalueinpreferences)), this);
|
||||||
|
|
||||||
if (OpenAPSMAPlugin.getPlugin().isEnabled(PluginType.APS))
|
if (OpenAPSMAPlugin.getPlugin().isEnabled(PluginType.APS))
|
||||||
|
|
|
@ -242,7 +242,6 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
|
||||||
// TODO review
|
// TODO review
|
||||||
if (!Config.NSCLIENT && !Config.G5UPLOADER)
|
if (!Config.NSCLIENT && !Config.G5UPLOADER)
|
||||||
NSUpload.uploadDeviceStatus();
|
NSUpload.uploadDeviceStatus();
|
||||||
lastDataTime = new Date();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -283,7 +282,6 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
|
||||||
public void getPumpStatus() {
|
public void getPumpStatus() {
|
||||||
|
|
||||||
log("getPumpStatus");
|
log("getPumpStatus");
|
||||||
lastDataTime = new Date();
|
|
||||||
if (Connector.get().isPumpConnected()) {
|
if (Connector.get().isPumpConnected()) {
|
||||||
log("is connected.. requesting status");
|
log("is connected.. requesting status");
|
||||||
final UUID uuid = aSyncTaskRunner(new StatusTaskRunner(connector.getServiceConnector()), "Status");
|
final UUID uuid = aSyncTaskRunner(new StatusTaskRunner(connector.getServiceConnector()), "Status");
|
||||||
|
@ -439,7 +437,6 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
|
||||||
updateGui();
|
updateGui();
|
||||||
connector.tryToGetPumpStatusAgain();
|
connector.tryToGetPumpStatusAgain();
|
||||||
|
|
||||||
lastDataTime = new Date();
|
|
||||||
connector.requestHistorySync(30000);
|
connector.requestHistorySync(30000);
|
||||||
|
|
||||||
if (result.success) while (true) {
|
if (result.success) while (true) {
|
||||||
|
@ -538,8 +535,6 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
|
||||||
if (Config.logPumpComm)
|
if (Config.logPumpComm)
|
||||||
log.debug("Setting temp basal absolute: " + pumpEnactResult.success);
|
log.debug("Setting temp basal absolute: " + pumpEnactResult.success);
|
||||||
|
|
||||||
lastDataTime = new Date();
|
|
||||||
|
|
||||||
updateGui();
|
updateGui();
|
||||||
|
|
||||||
connector.requestHistorySync(5000);
|
connector.requestHistorySync(5000);
|
||||||
|
@ -621,7 +616,6 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
|
||||||
TemporaryBasal tempStop = new TemporaryBasal().date(System.currentTimeMillis()).source(Source.USER);
|
TemporaryBasal tempStop = new TemporaryBasal().date(System.currentTimeMillis()).source(Source.USER);
|
||||||
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop);
|
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop);
|
||||||
}
|
}
|
||||||
lastDataTime = new Date();
|
|
||||||
updateGui();
|
updateGui();
|
||||||
if (Config.logPumpComm)
|
if (Config.logPumpComm)
|
||||||
log.debug("Canceling temp basal: "); // TODO get more info
|
log.debug("Canceling temp basal: "); // TODO get more info
|
||||||
|
@ -950,6 +944,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
|
||||||
singleMessageTaskRunner.fetch(new TaskRunner.ResultCallback() {
|
singleMessageTaskRunner.fetch(new TaskRunner.ResultCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onResult(Object o) {
|
public void onResult(Object o) {
|
||||||
|
lastDataTime = new Date();
|
||||||
log(name + " success");
|
log(name + " success");
|
||||||
event.response_object = o;
|
event.response_object = o;
|
||||||
if (o instanceof BolusMessage) {
|
if (o instanceof BolusMessage) {
|
||||||
|
@ -988,6 +983,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
|
||||||
task.fetch(new TaskRunner.ResultCallback() {
|
task.fetch(new TaskRunner.ResultCallback() {
|
||||||
@Override
|
@Override
|
||||||
public void onResult(Object o) {
|
public void onResult(Object o) {
|
||||||
|
lastDataTime = new Date();
|
||||||
log(name + " success");
|
log(name + " success");
|
||||||
event.response_object = o;
|
event.response_object = o;
|
||||||
event.success = true;
|
event.success = true;
|
||||||
|
|
|
@ -125,6 +125,7 @@ public class SensitivityOref0Plugin extends PluginBase implements SensitivityInt
|
||||||
|
|
||||||
for (double i = 0.9; i > 0.1; i = i - 0.02) {
|
for (double i = 0.9; i > 0.1; i = i - 0.02) {
|
||||||
if (IobCobCalculatorPlugin.percentile(deviations, (i + 0.02)) >= 0 && IobCobCalculatorPlugin.percentile(deviations, i) < 0) {
|
if (IobCobCalculatorPlugin.percentile(deviations, (i + 0.02)) >= 0 && IobCobCalculatorPlugin.percentile(deviations, i) < 0) {
|
||||||
|
if (Config.logAutosensData)
|
||||||
log.debug(Math.round(100 * i) + "% of non-meal deviations negative (target 45%-50%)");
|
log.debug(Math.round(100 * i) + "% of non-meal deviations negative (target 45%-50%)");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -203,7 +203,7 @@
|
||||||
<string name="openapsma_maxbasal_title">Max U/hr a Temp Basal can be set to</string>
|
<string name="openapsma_maxbasal_title">Max U/hr a Temp Basal can be set to</string>
|
||||||
<string name="openapsma_maxbasal_summary">This value is called max basal in OpenAPS context</string>
|
<string name="openapsma_maxbasal_summary">This value is called max basal in OpenAPS context</string>
|
||||||
<string name="openapsma_maxiob_title">Maximum basal IOB OpenAPS can deliver [U]</string>
|
<string name="openapsma_maxiob_title">Maximum basal IOB OpenAPS can deliver [U]</string>
|
||||||
<string name="openapsma_maxiob_summary">This value is called Max IOB in OpenAPS context\nThis will default to zero. After several days or weeks, depending on your comfort level, you may choose to adjust this number.</string>
|
<string name="openapsma_maxiob_summary">This value is called Max IOB in OpenAPS context\nThis is maximal insulin in [U] APS can deliver at once.</string>
|
||||||
<string name="bg_lang">Bulgarian</string>
|
<string name="bg_lang">Bulgarian</string>
|
||||||
<string name="dismiss">DISMISS</string>
|
<string name="dismiss">DISMISS</string>
|
||||||
<string name="language">Language</string>
|
<string name="language">Language</string>
|
||||||
|
@ -991,4 +991,7 @@
|
||||||
<string name="loopdisconnectedfor">Disconnected (%d m)</string>
|
<string name="loopdisconnectedfor">Disconnected (%d m)</string>
|
||||||
<string name="automatic_careportal_events">Automatic careportal events</string>
|
<string name="automatic_careportal_events">Automatic careportal events</string>
|
||||||
<string name="automatically_upload_insulin_cannula_and_battery_changes_to_nightscout">Automatically upload insulin, cannula and battery changes and pump alarms to Nightscout</string>
|
<string name="automatically_upload_insulin_cannula_and_battery_changes_to_nightscout">Automatically upload insulin, cannula and battery changes and pump alarms to Nightscout</string>
|
||||||
|
<string name="key_openapssmb_max_iob" translatable="false">openapsmb_max_iob</string>
|
||||||
|
<string name="openapssmb_maxiob_title">Maximum total IOB OpenAPS can\'t go over [U]</string>
|
||||||
|
<string name="openapssmb_maxiob_summary">This value is called Max IOB in OpenAPS context\nOpenAPS will not add more insulin if current IOB is greater than this value</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
|
@ -11,11 +11,11 @@
|
||||||
android:dialogMessage="@string/openapsma_maxbasal_summary"
|
android:dialogMessage="@string/openapsma_maxbasal_summary"
|
||||||
android:title="@string/openapsma_maxbasal_title" />
|
android:title="@string/openapsma_maxbasal_title" />
|
||||||
<EditTextPreference
|
<EditTextPreference
|
||||||
android:defaultValue="1.5"
|
android:defaultValue="3"
|
||||||
android:key="@string/key_openapsma_max_iob"
|
android:key="@string/key_openapssmb_max_iob"
|
||||||
android:numeric="decimal"
|
android:numeric="decimal"
|
||||||
android:dialogMessage="@string/openapsma_maxiob_summary"
|
android:dialogMessage="@string/openapssmb_maxiob_summary"
|
||||||
android:title="@string/openapsma_maxiob_title" />
|
android:title="@string/openapssmb_maxiob_title" />
|
||||||
<SwitchPreference
|
<SwitchPreference
|
||||||
android:defaultValue="false"
|
android:defaultValue="false"
|
||||||
android:key="openapsama_useautosens"
|
android:key="openapsama_useautosens"
|
||||||
|
|
|
@ -229,22 +229,36 @@ public class ConstraintsCheckerTest {
|
||||||
|
|
||||||
// applyMaxIOBConstraints tests
|
// applyMaxIOBConstraints tests
|
||||||
@Test
|
@Test
|
||||||
public void iobShouldBeLimited() throws Exception {
|
public void iobAMAShouldBeLimited() {
|
||||||
// No limit by default
|
// No limit by default
|
||||||
when(SP.getDouble(R.string.key_openapsma_max_iob, 1.5d)).thenReturn(1.5d);
|
when(SP.getDouble(R.string.key_openapsma_max_iob, 1.5d)).thenReturn(1.5d);
|
||||||
when(SP.getString(R.string.key_age, "")).thenReturn("teenage");
|
when(SP.getString(R.string.key_age, "")).thenReturn("teenage");
|
||||||
OpenAPSMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
|
OpenAPSMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
|
||||||
OpenAPSAMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
|
OpenAPSAMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
|
||||||
OpenAPSSMBPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
|
|
||||||
|
|
||||||
// Apply all limits
|
// Apply all limits
|
||||||
Constraint<Double> d = constraintChecker.getMaxIOBAllowed();
|
Constraint<Double> d = constraintChecker.getMaxIOBAllowed();
|
||||||
Assert.assertEquals(1.5d, d.value());
|
Assert.assertEquals(1.5d, d.value());
|
||||||
Assert.assertEquals(true, d.getReasonList().size() == 4);
|
Assert.assertEquals(3, d.getReasonList().size());
|
||||||
Assert.assertEquals("Safety: Limiting IOB to 1.5 U because of max value in preferences", d.getMostLimitedReasons());
|
Assert.assertEquals("Safety: Limiting IOB to 1.5 U because of max value in preferences", d.getMostLimitedReasons());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void iobSMBShouldBeLimited() {
|
||||||
|
// No limit by default
|
||||||
|
when(SP.getDouble(R.string.key_openapssmb_max_iob, 3d)).thenReturn(3d);
|
||||||
|
when(SP.getString(R.string.key_age, "")).thenReturn("teenage");
|
||||||
|
OpenAPSSMBPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
|
||||||
|
|
||||||
|
// Apply all limits
|
||||||
|
Constraint<Double> d = constraintChecker.getMaxIOBAllowed();
|
||||||
|
Assert.assertEquals(3d, d.value());
|
||||||
|
Assert.assertEquals(4, d.getReasonList().size());
|
||||||
|
Assert.assertEquals("Safety: Limiting IOB to 3.0 U because of max value in preferences", d.getMostLimitedReasons());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void prepareMock() throws Exception {
|
public void prepareMock() throws Exception {
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ public class SafetyPluginTest {
|
||||||
when(SP.getString(R.string.key_age, "")).thenReturn("teenage");
|
when(SP.getString(R.string.key_age, "")).thenReturn("teenage");
|
||||||
OpenAPSMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
|
OpenAPSMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
|
||||||
OpenAPSAMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
|
OpenAPSAMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
|
||||||
OpenAPSSMBPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
|
//OpenAPSSMBPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
|
||||||
|
|
||||||
// Apply all limits
|
// Apply all limits
|
||||||
Constraint<Double> d = new Constraint<>(Constants.REALLYHIGHIOB);
|
Constraint<Double> d = new Constraint<>(Constants.REALLYHIGHIOB);
|
||||||
|
@ -218,8 +218,7 @@ public class SafetyPluginTest {
|
||||||
Assert.assertEquals(1.5d, d.value());
|
Assert.assertEquals(1.5d, d.value());
|
||||||
Assert.assertEquals("Safety: Limiting IOB to 1.5 U because of max value in preferences\n" +
|
Assert.assertEquals("Safety: Limiting IOB to 1.5 U because of max value in preferences\n" +
|
||||||
"Safety: Limiting IOB to 7.0 U because of hard limit\n" +
|
"Safety: Limiting IOB to 7.0 U because of hard limit\n" +
|
||||||
"Safety: Limiting IOB to 7.0 U because of hard limit\n" +
|
"Safety: Limiting IOB to 7.0 U because of hard limit", d.getReasons());
|
||||||
"Safety: Limiting IOB to 12.0 U because of hard limit", d.getReasons());
|
|
||||||
Assert.assertEquals("Safety: Limiting IOB to 1.5 U because of max value in preferences", d.getMostLimitedReasons());
|
Assert.assertEquals("Safety: Limiting IOB to 1.5 U because of max value in preferences", d.getMostLimitedReasons());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue