extended boluses NS sync fix
This commit is contained in:
parent
a609d806d1
commit
4663bb3cf6
2 changed files with 24 additions and 40 deletions
|
@ -280,7 +280,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
return getDao(TempTarget.class);
|
return getDao(TempTarget.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dao<BgReading, Long> getDaoBgReadings() throws SQLException {
|
private Dao<BgReading, Long> getDaoBgReadings() throws SQLException {
|
||||||
return getDao(BgReading.class);
|
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
|
@Nullable
|
||||||
public static BgReading lastBg() {
|
public static BgReading lastBg() {
|
||||||
List<BgReading> bgList = null;
|
List<BgReading> bgList = null;
|
||||||
|
@ -394,9 +394,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Return bg reading if not old ( <9 min )
|
* Return bg reading if not old ( <9 min )
|
||||||
* or null if older
|
* or null if older
|
||||||
*/
|
*/
|
||||||
@Nullable
|
@Nullable
|
||||||
public static BgReading actualBg() {
|
public static BgReading actualBg() {
|
||||||
BgReading lastBg = lastBg();
|
BgReading lastBg = lastBg();
|
||||||
|
@ -446,7 +446,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
// ------------------- TDD handling -----------------------
|
// ------------------- TDD handling -----------------------
|
||||||
public void createOrUpdateTDD(TDD tdd){
|
public void createOrUpdateTDD(TDD tdd) {
|
||||||
try {
|
try {
|
||||||
Dao<TDD, String> dao = getDaoTDD();
|
Dao<TDD, String> dao = getDaoTDD();
|
||||||
dao.createOrUpdate(tdd);
|
dao.createOrUpdate(tdd);
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -714,7 +712,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
getDaoDanaRHistory().createOrUpdate(record);
|
getDaoDanaRHistory().createOrUpdate(record);
|
||||||
|
|
||||||
//If it is a TDD, store it for stats also.
|
//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));
|
createOrUpdateTDD(new TDD(record.recordDate, record.recordDailyBolus, record.recordDailyBasal, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue