Add Last Carb Time
This commit is contained in:
parent
15717f0271
commit
04bd98e0e5
|
@ -613,6 +613,29 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the newest record with carbs > 0
|
||||||
|
*/
|
||||||
|
@Nullable
|
||||||
|
public Treatment getLastCarb() {
|
||||||
|
try {
|
||||||
|
QueryBuilder<Treatment, Long> queryBuilder = getDao().queryBuilder();
|
||||||
|
Where where = queryBuilder.where();
|
||||||
|
where.gt("carbs", 0);
|
||||||
|
where.and().le("date", DateUtil.now());
|
||||||
|
where.and().eq("isValid", true);
|
||||||
|
queryBuilder.orderBy("date", false);
|
||||||
|
queryBuilder.limit(1L);
|
||||||
|
|
||||||
|
List<Treatment> result = getDao().query(queryBuilder.prepare());
|
||||||
|
if (result.isEmpty())
|
||||||
|
return null;
|
||||||
|
return result.get(0);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
throw new RuntimeException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void deleteNS(JSONObject json) {
|
public void deleteNS(JSONObject json) {
|
||||||
String _id = JsonHelper.safeGetString(json, "_id");
|
String _id = JsonHelper.safeGetString(json, "_id");
|
||||||
if (_id != null && !_id.isEmpty())
|
if (_id != null && !_id.isEmpty())
|
||||||
|
|
|
@ -358,6 +358,19 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long getLastCarbTime() {
|
||||||
|
Treatment last = getService().getLastCarb();
|
||||||
|
if (last == null) {
|
||||||
|
getAapsLogger().debug(LTag.DATATREATMENTS, "Last Carb time: NOTHING FOUND");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
getAapsLogger().debug(LTag.DATATREATMENTS, "Last Carb time: " + dateUtil.dateAndTimeString(last.date));
|
||||||
|
return last.date;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isInHistoryRealTempBasalInProgress() {
|
public boolean isInHistoryRealTempBasalInProgress() {
|
||||||
return getRealTempBasalFromHistory(System.currentTimeMillis()) != null;
|
return getRealTempBasalFromHistory(System.currentTimeMillis()) != null;
|
||||||
|
|
Loading…
Reference in a new issue