db index change and ver=2
This commit is contained in:
parent
120341b706
commit
275c5f5664
6 changed files with 20 additions and 25 deletions
|
@ -120,10 +120,10 @@ public class DataService extends IntentService {
|
||||||
bgReading.value = bundle.getDouble(Intents.EXTRA_BG_ESTIMATE);
|
bgReading.value = bundle.getDouble(Intents.EXTRA_BG_ESTIMATE);
|
||||||
bgReading.slope = bundle.getDouble(Intents.EXTRA_BG_SLOPE);
|
bgReading.slope = bundle.getDouble(Intents.EXTRA_BG_SLOPE);
|
||||||
bgReading.battery_level = bundle.getInt(Intents.EXTRA_SENSOR_BATTERY);
|
bgReading.battery_level = bundle.getInt(Intents.EXTRA_SENSOR_BATTERY);
|
||||||
bgReading.timestamp = bundle.getLong(Intents.EXTRA_TIMESTAMP);
|
bgReading.timeIndex = bundle.getLong(Intents.EXTRA_TIMESTAMP);
|
||||||
bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW);
|
bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW);
|
||||||
|
|
||||||
if (bgReading.timestamp < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
|
if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
|
||||||
if (Config.logIncommingBG)
|
if (Config.logIncommingBG)
|
||||||
log.debug("Ignoring old XDRIPREC BG " + bgReading.toString());
|
log.debug("Ignoring old XDRIPREC BG " + bgReading.toString());
|
||||||
return;
|
return;
|
||||||
|
@ -320,7 +320,7 @@ public class DataService extends IntentService {
|
||||||
JSONObject sgvJson = new JSONObject(sgvstring);
|
JSONObject sgvJson = new JSONObject(sgvstring);
|
||||||
NSSgv nsSgv = new NSSgv(sgvJson);
|
NSSgv nsSgv = new NSSgv(sgvJson);
|
||||||
BgReading bgReading = new BgReading(nsSgv);
|
BgReading bgReading = new BgReading(nsSgv);
|
||||||
if (bgReading.timestamp < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
|
if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
log.debug("Ignoring old BG: " + bgReading.toString());
|
log.debug("Ignoring old BG: " + bgReading.toString());
|
||||||
return;
|
return;
|
||||||
|
@ -337,7 +337,7 @@ public class DataService extends IntentService {
|
||||||
JSONObject sgvJson = jsonArray.getJSONObject(i);
|
JSONObject sgvJson = jsonArray.getJSONObject(i);
|
||||||
NSSgv nsSgv = new NSSgv(sgvJson);
|
NSSgv nsSgv = new NSSgv(sgvJson);
|
||||||
BgReading bgReading = new BgReading(nsSgv);
|
BgReading bgReading = new BgReading(nsSgv);
|
||||||
if (bgReading.timestamp < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
|
if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
log.debug("Ignoring old BG: " + bgReading.toString());
|
log.debug("Ignoring old BG: " + bgReading.toString());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -22,19 +22,16 @@ public class BgReading implements DataPointInterface {
|
||||||
public static final DecimalFormat mgdlFormat = new DecimalFormat("0");
|
public static final DecimalFormat mgdlFormat = new DecimalFormat("0");
|
||||||
|
|
||||||
public long getTimeIndex() {
|
public long getTimeIndex() {
|
||||||
return (long) Math.ceil(timestamp / 60000d);
|
return timeIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimeIndex(long timeIndex) {
|
public void setTimeIndex(long timeIndex) {
|
||||||
this.timestamp = timeIndex;
|
this.timeIndex = timeIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@DatabaseField(id = true, useGetSet = true)
|
@DatabaseField(id = true, useGetSet = true)
|
||||||
public long timeIndex;
|
public long timeIndex;
|
||||||
|
|
||||||
@DatabaseField
|
|
||||||
public long timestamp;
|
|
||||||
|
|
||||||
@DatabaseField
|
@DatabaseField
|
||||||
public double value;
|
public double value;
|
||||||
|
|
||||||
|
@ -52,7 +49,7 @@ public class BgReading implements DataPointInterface {
|
||||||
public BgReading() {}
|
public BgReading() {}
|
||||||
|
|
||||||
public BgReading(NSSgv sgv) {
|
public BgReading(NSSgv sgv) {
|
||||||
timestamp = sgv.getMills();
|
timeIndex = sgv.getMills();
|
||||||
value = sgv.getMgdl();
|
value = sgv.getMgdl();
|
||||||
raw = sgv.getFiltered();
|
raw = sgv.getFiltered();
|
||||||
}
|
}
|
||||||
|
@ -73,8 +70,7 @@ public class BgReading implements DataPointInterface {
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "BgReading{" +
|
return "BgReading{" +
|
||||||
"timeIndex=" + timeIndex +
|
"timeIndex=" + timeIndex +
|
||||||
", timestamp=" + timestamp +
|
", date=" + new Date(timeIndex) +
|
||||||
", date=" + new Date(timestamp) +
|
|
||||||
", value=" + value +
|
", value=" + value +
|
||||||
", slope=" + slope +
|
", slope=" + slope +
|
||||||
", raw=" + raw +
|
", raw=" + raw +
|
||||||
|
@ -84,7 +80,7 @@ public class BgReading implements DataPointInterface {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getX() {
|
public double getX() {
|
||||||
return timestamp;
|
return timeIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
|
|
||||||
public static final String DATABASE_NAME = "AndroidAPSDb";
|
public static final String DATABASE_NAME = "AndroidAPSDb";
|
||||||
|
|
||||||
private static final int DATABASE_VERSION = 1;
|
private static final int DATABASE_VERSION = 2;
|
||||||
|
|
||||||
public DatabaseHelper(Context context) {
|
public DatabaseHelper(Context context) {
|
||||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
|
@ -83,15 +83,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
public void cleanUpDatabases() {
|
public void cleanUpDatabases() {
|
||||||
// TODO: call it somewhere
|
// TODO: call it somewhere
|
||||||
log.debug("Before BgReadings size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "BgReadings"));
|
log.debug("Before BgReadings size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "BgReadings"));
|
||||||
getWritableDatabase().delete("BgReadings", "timeIndex" + " < '" + Math.ceil((new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) / 60000d) + "'", null);
|
getWritableDatabase().delete("BgReadings", "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
|
||||||
log.debug("After BgReadings size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "BgReadings"));
|
log.debug("After BgReadings size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "BgReadings"));
|
||||||
|
|
||||||
log.debug("Before TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "TempBasals"));
|
log.debug("Before TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "TempBasals"));
|
||||||
getWritableDatabase().delete("TempBasals", "timeIndex" + " < '" + Math.ceil((new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) / 60000d) + "'", null);
|
getWritableDatabase().delete("TempBasals", "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
|
||||||
log.debug("After TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "TempBasals"));
|
log.debug("After TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "TempBasals"));
|
||||||
|
|
||||||
log.debug("Before Treatments size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "Treatments"));
|
log.debug("Before Treatments size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "Treatments"));
|
||||||
getWritableDatabase().delete("Treatments", "timeIndex" + " < '" + Math.ceil((new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) / 60000d) + "'", null);
|
getWritableDatabase().delete("Treatments", "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
|
||||||
log.debug("After Treatments size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "Treatments"));
|
log.debug("After Treatments size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "Treatments"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -146,14 +146,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
Dao<BgReading, Long> daoBgReadings = MainApp.getDbHelper().getDaoBgReadings();
|
Dao<BgReading, Long> daoBgReadings = MainApp.getDbHelper().getDaoBgReadings();
|
||||||
QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder();
|
QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder();
|
||||||
queryBuilder.orderBy("timeIndex", false);
|
queryBuilder.orderBy("timeIndex", false);
|
||||||
queryBuilder.limit(1l);
|
queryBuilder.limit(1L);
|
||||||
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
|
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
|
||||||
bgList = daoBgReadings.query(preparedQuery);
|
bgList = daoBgReadings.query(preparedQuery);
|
||||||
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.debug(e.getMessage(), e);
|
log.debug(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
if (bgList.size() > 0)
|
if (bgList != null && bgList.size() > 0)
|
||||||
return bgList.get(0);
|
return bgList.get(0);
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
|
@ -170,7 +170,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
if (lastBg == null)
|
if (lastBg == null)
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
if (lastBg.timestamp > new Date().getTime() - 9 * 60 * 1000)
|
if (lastBg.timeIndex > new Date().getTime() - 9 * 60 * 1000)
|
||||||
return lastBg;
|
return lastBg;
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -271,7 +271,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
|
|
||||||
int sizeRecords = bgReadings.size();
|
int sizeRecords = bgReadings.size();
|
||||||
|
|
||||||
if (sizeRecords < 4 || bgReadings.get(sizeRecords - 4).timestamp < new Date().getTime() - 7 * 60 * 1000l) {
|
if (sizeRecords < 4 || bgReadings.get(sizeRecords - 4).timeIndex < new Date().getTime() - 7 * 60 * 1000L) {
|
||||||
if (Config.fakeGlucoseData) {
|
if (Config.fakeGlucoseData) {
|
||||||
return new GlucoseStatus(Math.random() * 400 + 40, (Math. random() - 0.5)* 18, (Math. random() - 0.5)* 18);
|
return new GlucoseStatus(Math.random() * 400 + 40, (Math. random() - 0.5)* 18, (Math. random() - 0.5)* 18);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class TempBasal {
|
||||||
private static Logger log = LoggerFactory.getLogger(TempBasal.class);
|
private static Logger log = LoggerFactory.getLogger(TempBasal.class);
|
||||||
|
|
||||||
public long getTimeIndex() {
|
public long getTimeIndex() {
|
||||||
return (long) Math.ceil(timeStart.getTime() / 60000d);
|
return timeStart.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimeIndex(long timeIndex) {
|
public void setTimeIndex(long timeIndex) {
|
||||||
|
@ -34,7 +34,6 @@ public class TempBasal {
|
||||||
@DatabaseField(id = true, useGetSet = true)
|
@DatabaseField(id = true, useGetSet = true)
|
||||||
public long timeIndex;
|
public long timeIndex;
|
||||||
|
|
||||||
|
|
||||||
@DatabaseField
|
@DatabaseField
|
||||||
public Date timeStart;
|
public Date timeStart;
|
||||||
|
|
||||||
|
|
|
@ -28,7 +28,7 @@ public class Treatment {
|
||||||
private static Logger log = LoggerFactory.getLogger(Treatment.class);
|
private static Logger log = LoggerFactory.getLogger(Treatment.class);
|
||||||
|
|
||||||
public long getTimeIndex() {
|
public long getTimeIndex() {
|
||||||
return (long) Math.ceil(created_at.getTime() / 60000d);
|
return created_at.getTime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTimeIndex(long timeIndex) {
|
public void setTimeIndex(long timeIndex) {
|
||||||
|
|
|
@ -318,7 +318,7 @@ public class OverviewFragment extends Fragment implements PluginBase {
|
||||||
flag &= ~Paint.STRIKE_THRU_TEXT_FLAG;
|
flag &= ~Paint.STRIKE_THRU_TEXT_FLAG;
|
||||||
bgView.setPaintFlags(flag);
|
bgView.setPaintFlags(flag);
|
||||||
|
|
||||||
Long agoMsec = new Date().getTime() - lastBG.timestamp;
|
Long agoMsec = new Date().getTime() - lastBG.timeIndex;
|
||||||
int agoMin = (int) (agoMsec / 60d / 1000d);
|
int agoMin = (int) (agoMsec / 60d / 1000d);
|
||||||
timeAgoView.setText(agoMin + " " + getString(R.string.minago));
|
timeAgoView.setText(agoMin + " " + getString(R.string.minago));
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue