Merge branch 'dev' into automatic-careportal-events

This commit is contained in:
Milos Kozak 2018-04-08 23:53:04 +02:00 committed by GitHub
commit 9b91b4ab93
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 64 additions and 66 deletions

View file

@ -280,7 +280,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return getDao(TempTarget.class);
}
private Dao<BgReading, Long> getDaoBgReadings() throws SQLException {
private Dao<BgReading, Long> getDaoBgReadings() throws SQLException {
return getDao(BgReading.class);
}
@ -369,8 +369,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
/*
* Return last BgReading from database or null if db is empty
*/
* Return last BgReading from database or null if db is empty
*/
@Nullable
public static BgReading lastBg() {
List<BgReading> bgList = null;
@ -394,9 +394,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
/*
* Return bg reading if not old ( <9 min )
* or null if older
*/
* Return bg reading if not old ( <9 min )
* or null if older
*/
@Nullable
public static BgReading actualBg() {
BgReading lastBg = lastBg();
@ -446,7 +446,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
// ------------------- TDD handling -----------------------
public void createOrUpdateTDD(TDD tdd){
public void createOrUpdateTDD(TDD tdd) {
try {
Dao<TDD, String> dao = getDaoTDD();
dao.createOrUpdate(tdd);
@ -472,7 +472,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
// ------------- DbRequests handling -------------------
public void create(DbRequest dbr) {
@ -509,7 +508,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
queryBuilder.limit(10L);
PreparedQuery<DbRequest> preparedQuery = queryBuilder.prepare();
List<DbRequest> dbList = getDaoDbRequest().query(preparedQuery);
log.error("deleteDbRequestbyMongoId query size: " + dbList.size());
for (DbRequest r : dbList) {
delete(r);
}
@ -714,7 +712,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
getDaoDanaRHistory().createOrUpdate(record);
//If it is a TDD, store it for stats also.
if(record.recordCode == RecordTypes.RECORD_TYPE_DAILY){
if (record.recordCode == RecordTypes.RECORD_TYPE_DAILY) {
createOrUpdateTDD(new TDD(record.recordDate, record.recordDailyBolus, record.recordDailyBasal, 0));
}
@ -1154,37 +1152,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
*/
public void createExtendedBolusFromJsonIfNotExists(JSONObject trJson) {
try {
QueryBuilder<ExtendedBolus, Long> queryBuilder = 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");
public void createExtendedBolusFromJsonIfNotExists(JSONObject json) {
ExtendedBolus extendedBolus = ExtendedBolus.createFromJson(json);
if (extendedBolus != null)
createOrUpdate(extendedBolus);
} catch (SQLException | JSONException e) {
log.error("Unhandled exception", e);
}
}
private static void scheduleExtendedBolusChange() {

View file

@ -9,6 +9,8 @@ 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;
@ -25,6 +27,7 @@ import info.nightscout.androidaps.plugins.Overview.graphExtensions.PointsWithLab
import info.nightscout.androidaps.plugins.Treatments.Treatment;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.JsonHelper;
import info.nightscout.utils.Round;
/**
@ -89,6 +92,16 @@ public class ExtendedBolus implements Interval, DataPointWithLabelInterface {
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 ---------
Long cuttedEnd = null;

View file

@ -150,13 +150,10 @@ public abstract class PluginBase {
protected void onStart() {
if (getType() == PluginType.PUMP) {
try {
new Thread(() -> {
SystemClock.sleep(3000);
ConfigBuilderPlugin.getCommandQueue().readStatus("Pump driver changed.", null);
}).start();
} catch (Exception ignored) { // Thread fail to start in tests
}
new Thread(() -> {
SystemClock.sleep(3000);
ConfigBuilderPlugin.getCommandQueue().readStatus("Pump driver changed.", null);
}).start();
}
}

View file

@ -169,7 +169,11 @@ public class SafetyPlugin extends PluginBase implements ConstraintsInterface {
@Override
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);
if (OpenAPSMAPlugin.getPlugin().isEnabled(PluginType.APS))

View file

@ -242,7 +242,6 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
// TODO review
if (!Config.NSCLIENT && !Config.G5UPLOADER)
NSUpload.uploadDeviceStatus();
lastDataTime = new Date();
}
@Override
@ -283,7 +282,6 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
public void getPumpStatus() {
log("getPumpStatus");
lastDataTime = new Date();
if (Connector.get().isPumpConnected()) {
log("is connected.. requesting status");
final UUID uuid = aSyncTaskRunner(new StatusTaskRunner(connector.getServiceConnector()), "Status");
@ -439,7 +437,6 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
updateGui();
connector.tryToGetPumpStatusAgain();
lastDataTime = new Date();
connector.requestHistorySync(30000);
if (result.success) while (true) {
@ -538,8 +535,6 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
if (Config.logPumpComm)
log.debug("Setting temp basal absolute: " + pumpEnactResult.success);
lastDataTime = new Date();
updateGui();
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);
TreatmentsPlugin.getPlugin().addToHistoryTempBasal(tempStop);
}
lastDataTime = new Date();
updateGui();
if (Config.logPumpComm)
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() {
@Override
public void onResult(Object o) {
lastDataTime = new Date();
log(name + " success");
event.response_object = o;
if (o instanceof BolusMessage) {
@ -988,6 +983,7 @@ public class InsightPlugin extends PluginBase implements PumpInterface, Constrai
task.fetch(new TaskRunner.ResultCallback() {
@Override
public void onResult(Object o) {
lastDataTime = new Date();
log(name + " success");
event.response_object = o;
event.success = true;

View file

@ -125,7 +125,8 @@ public class SensitivityOref0Plugin extends PluginBase implements SensitivityInt
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) {
log.debug(Math.round(100 * i) + "% of non-meal deviations negative (target 45%-50%)");
if (Config.logAutosensData)
log.debug(Math.round(100 * i) + "% of non-meal deviations negative (target 45%-50%)");
}
}
double pSensitive = IobCobCalculatorPlugin.percentile(deviations, 0.50);

View file

@ -203,7 +203,7 @@
<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_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="dismiss">DISMISS</string>
<string name="language">Language</string>
@ -991,4 +991,7 @@
<string name="loopdisconnectedfor">Disconnected (%d m)</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="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>

View file

@ -11,11 +11,11 @@
android:dialogMessage="@string/openapsma_maxbasal_summary"
android:title="@string/openapsma_maxbasal_title" />
<EditTextPreference
android:defaultValue="1.5"
android:key="@string/key_openapsma_max_iob"
android:defaultValue="3"
android:key="@string/key_openapssmb_max_iob"
android:numeric="decimal"
android:dialogMessage="@string/openapsma_maxiob_summary"
android:title="@string/openapsma_maxiob_title" />
android:dialogMessage="@string/openapssmb_maxiob_summary"
android:title="@string/openapssmb_maxiob_title" />
<SwitchPreference
android:defaultValue="false"
android:key="openapsama_useautosens"

View file

@ -229,22 +229,36 @@ public class ConstraintsCheckerTest {
// applyMaxIOBConstraints tests
@Test
public void iobShouldBeLimited() throws Exception {
public void iobAMAShouldBeLimited() {
// No limit by default
when(SP.getDouble(R.string.key_openapsma_max_iob, 1.5d)).thenReturn(1.5d);
when(SP.getString(R.string.key_age, "")).thenReturn("teenage");
OpenAPSMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
OpenAPSAMAPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
OpenAPSSMBPlugin.getPlugin().setPluginEnabled(PluginType.APS, true);
// Apply all limits
Constraint<Double> d = constraintChecker.getMaxIOBAllowed();
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());
}
@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
public void prepareMock() throws Exception {

View file

@ -210,7 +210,7 @@ public class SafetyPluginTest {
when(SP.getString(R.string.key_age, "")).thenReturn("teenage");
OpenAPSMAPlugin.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
Constraint<Double> d = new Constraint<>(Constants.REALLYHIGHIOB);
@ -218,8 +218,7 @@ public class SafetyPluginTest {
Assert.assertEquals(1.5d, d.value());
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 12.0 U because of hard limit", d.getReasons());
"Safety: Limiting IOB to 7.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());
}