change database structures

This commit is contained in:
Milos Kozak 2017-05-21 22:05:03 +02:00
parent 3330c6a3fd
commit 6004a17594
52 changed files with 937 additions and 668 deletions

View file

@ -43,7 +43,7 @@ android {
applicationId "info.nightscout.androidaps"
minSdkVersion 21
targetSdkVersion 23
versionCode 1400
versionCode 1450
version "1.45"
buildConfigField "String", "VERSION", '"' + version + '"'
buildConfigField "String", "BUILDVERSION", generateGitBuild()

View file

@ -180,11 +180,10 @@ public class DataService extends IntentService {
bgReading.value = bundle.getDouble(Intents.EXTRA_BG_ESTIMATE);
bgReading.direction = bundle.getString(Intents.EXTRA_BG_SLOPE_NAME);
bgReading.battery_level = bundle.getInt(Intents.EXTRA_SENSOR_BATTERY);
bgReading.timeIndex = bundle.getLong(Intents.EXTRA_TIMESTAMP);
bgReading.date = bundle.getLong(Intents.EXTRA_TIMESTAMP);
bgReading.raw = bundle.getDouble(Intents.EXTRA_RAW);
if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) {
if (bgReading.date < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) {
if (Config.logIncommingBG)
log.debug("Ignoring old XDRIPREC BG " + bgReading.toString());
return;
@ -209,8 +208,7 @@ public class DataService extends IntentService {
bgReading.value = bundle.getDouble("mySGV");
bgReading.direction = bundle.getString("myTrend");
bgReading.battery_level = bundle.getInt("myBatLvl");
bgReading.timeIndex = bundle.getLong("myTimestamp");
bgReading.date = bundle.getLong("myTimestamp");
bgReading.raw = 0;
if (Config.logIncommingBG)
@ -247,10 +245,10 @@ public class DataService extends IntentService {
bgReading.value = json_object.getDouble("sgv");
bgReading.direction = json_object.getString("direction");
bgReading.timeIndex = json_object.getLong("date");
bgReading.date = json_object.getLong("date");
bgReading.raw = json_object.getDouble("sgv");
if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) {
if (bgReading.date < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) {
if (Config.logIncommingBG)
log.debug("Ignoring old MM640g BG " + bgReading.toString());
return;
@ -451,7 +449,7 @@ public class DataService extends IntentService {
JSONObject sgvJson = new JSONObject(sgvstring);
NSSgv nsSgv = new NSSgv(sgvJson);
BgReading bgReading = new BgReading(nsSgv);
if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
if (bgReading.date < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
if (Config.logIncommingData)
log.debug("Ignoring old BG: " + bgReading.toString());
return;
@ -468,7 +466,7 @@ public class DataService extends IntentService {
JSONObject sgvJson = jsonArray.getJSONObject(i);
NSSgv nsSgv = new NSSgv(sgvJson);
BgReading bgReading = new BgReading(nsSgv);
if (bgReading.timeIndex < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
if (bgReading.date < new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000l) {
if (Config.logIncommingData)
log.debug("Ignoring old BG: " + bgReading.toString());
} else {
@ -502,10 +500,10 @@ public class DataService extends IntentService {
Treatment stored = null;
String _id = trJson.getString("_id");
if (trJson.has("timeIndex")) {
if (trJson.has("date")) {
if (Config.logIncommingData)
log.debug("ADD: timeIndex found: " + trstring);
stored = MainApp.getDbHelper().findTreatmentByTimeIndex(trJson.getLong("timeIndex"));
log.debug("ADD: date found: " + trstring);
stored = MainApp.getDbHelper().findTreatmentByTimeIndex(trJson.getLong("date"));
} else {
stored = MainApp.getDbHelper().findTreatmentById(_id);
}
@ -513,7 +511,7 @@ public class DataService extends IntentService {
if (stored != null) {
if (Config.logIncommingData)
log.debug("ADD: Existing treatment: " + trstring);
if (trJson.has("timeIndex")) {
if (trJson.has("date")) {
stored._id = _id;
int updated = MainApp.getDbHelper().update(stored);
if (Config.logIncommingData)
@ -528,7 +526,7 @@ public class DataService extends IntentService {
treatment._id = _id;
treatment.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0;
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
treatment.created_at = new Date(trJson.getLong("mills"));
treatment.date = trJson.getLong("mills");
if (trJson.has("eventType")) {
treatment.mealBolus = true;
if (trJson.get("eventType").equals("Correction Bolus"))
@ -543,7 +541,6 @@ public class DataService extends IntentService {
if (carbs <= 0)
treatment.mealBolus = false;
}
treatment.setTimeIndex(treatment.getTimeIndex());
MainApp.getDbHelper().createOrUpdate(treatment);
if (Config.logIncommingData)
log.debug("ADD: Stored treatment: " + treatment.log());
@ -563,10 +560,10 @@ public class DataService extends IntentService {
Treatment stored;
if (trJson.has("timeIndex")) {
if (trJson.has("date")) {
if (Config.logIncommingData)
log.debug("ADD: timeIndex found: " + trstring);
stored = MainApp.getDbHelper().findTreatmentByTimeIndex(trJson.getLong("timeIndex"));
log.debug("ADD: date found: " + trstring);
stored = MainApp.getDbHelper().findTreatmentByTimeIndex(trJson.getLong("date"));
} else {
stored = MainApp.getDbHelper().findTreatmentById(_id);
}
@ -586,7 +583,7 @@ public class DataService extends IntentService {
treatment.carbs = trJson.has("carbs") ? trJson.getDouble("carbs") : 0;
treatment.insulin = trJson.has("insulin") ? trJson.getDouble("insulin") : 0d;
//treatment.created_at = DateUtil.fromISODateString(trJson.getString("created_at"));
treatment.created_at = new Date(trJson.getLong("mills"));
treatment.date = trJson.getLong("mills");
if (trJson.has("eventType")) {
treatment.mealBolus = true;
if (trJson.get("eventType").equals("Correction Bolus"))
@ -601,7 +598,6 @@ public class DataService extends IntentService {
if (carbs <= 0)
treatment.mealBolus = false;
}
treatment.setTimeIndex(treatment.getTimeIndex());
Dao.CreateOrUpdateStatus status = MainApp.getDbHelper().createOrUpdate(treatment);
if (Config.logIncommingData)
log.debug("Records updated: " + status.getNumLinesChanged());
@ -621,10 +617,10 @@ public class DataService extends IntentService {
// Record does not exists. Ignore
} else if (list.size() == 1) {
DanaRHistoryRecord record = list.get(0);
if (record.get_id() == null || record.get_id() != trJson.getString("_id")) {
if (record._id == null || !record._id.equals(trJson.getString("_id"))) {
if (Config.logIncommingData)
log.debug("Updating _id in DanaR history database: " + trJson.getString("_id"));
record.set_id(trJson.getString("_id"));
record._id = trJson.getString("_id");
daoHistoryRecords.update(record);
} else {
// already set
@ -655,7 +651,7 @@ public class DataService extends IntentService {
Dao<TempTarget, Long> daoTempTargets = MainApp.getDbHelper().getDaoTempTargets();
QueryBuilder<TempTarget, Long> queryBuilder = daoTempTargets.queryBuilder();
Where where = queryBuilder.where();
where.eq("_id", trJson.getString("_id")).or().eq("timeIndex", trJson.getLong("mills"));
where.eq("_id", trJson.getString("_id")).or().eq("date", trJson.getLong("mills"));
PreparedQuery<TempTarget> preparedQuery = queryBuilder.prepare();
List<TempTarget> list = daoTempTargets.query(preparedQuery);
NSProfile profile = MainApp.getConfigBuilder().getActiveProfile().getProfile();
@ -664,13 +660,12 @@ public class DataService extends IntentService {
if (list.size() == 0) {
// Record does not exists. add
TempTarget newRecord = new TempTarget();
newRecord.timeStart = new Date(trJson.getLong("mills"));
newRecord.duration = trJson.getInt("duration");
newRecord.date = trJson.getLong("mills");
newRecord.durationInMinutes = trJson.getInt("duration");
newRecord.low = NSProfile.toMgdl(trJson.getDouble("targetBottom"), units);
newRecord.high = NSProfile.toMgdl(trJson.getDouble("targetTop"), units);
newRecord.reason = trJson.getString("reason");
newRecord._id = trJson.getString("_id");
newRecord.setTimeIndex(newRecord.getTimeIndex());
daoTempTargets.createIfNotExists(newRecord);
if (Config.logIncommingData)
log.debug("Adding TempTarget record to database: " + newRecord.log());
@ -679,8 +674,8 @@ public class DataService extends IntentService {
if (Config.logIncommingData)
log.debug("Updating TempTarget record in database: " + trJson.getString("_id"));
TempTarget record = list.get(0);
record.timeStart = new Date(trJson.getLong("mills"));
record.duration = trJson.getInt("duration");
record.date = trJson.getLong("mills");
record.durationInMinutes = trJson.getInt("duration");
record.low = NSProfile.toMgdl(trJson.getDouble("targetBottom"), units);
record.high = NSProfile.toMgdl(trJson.getDouble("targetTop"), units);
record.reason = trJson.getString("reason");

View file

@ -73,12 +73,12 @@ public class GlucoseStatus {
List<BgReading> data = MainApp.getDbHelper().getBgreadingsDataFromTime(fromtime, false);
int sizeRecords = data.size();
if (sizeRecords < 1 || data.get(0).timeIndex < new Date().getTime() - 7 * 60 * 1000L) {
if (sizeRecords < 1 || data.get(0).date < new Date().getTime() - 7 * 60 * 1000L) {
return null;
}
BgReading now = data.get(0);
long now_date = now.timeIndex;
long now_date = now.date;
double change;
if (sizeRecords < 2) {
@ -98,7 +98,7 @@ public class GlucoseStatus {
for (int i = 1; i < data.size(); i++) {
if (data.get(i).value > 38) {
BgReading then = data.get(i);
long then_date = then.timeIndex;
long then_date = then.date;
double avgdelta = 0;
long minutesago;
@ -153,7 +153,7 @@ public class GlucoseStatus {
try {
Dao<BgReading, Long> daoBgReadings = MainApp.getDbHelper().getDaoBgReadings();
QueryBuilder<BgReading, Long> queryBuilder = daoBgReadings.queryBuilder();
queryBuilder.orderBy("timeIndex", false);
queryBuilder.orderBy("date", false);
queryBuilder.limit(1L);
queryBuilder.where().gt("value", 38);
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
@ -179,7 +179,7 @@ public class GlucoseStatus {
if (lastBg == null)
return null;
if (lastBg.timeIndex > new Date().getTime() - 9 * 60 * 1000)
if (lastBg.date > new Date().getTime() - 9 * 60 * 1000)
return lastBg;
return null;

View file

@ -11,41 +11,38 @@ import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSSgv;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
@DatabaseTable(tableName = DatabaseHelper.DATABASE_BGREADINGS)
public class BgReading implements DataPointInterface {
private static Logger log = LoggerFactory.getLogger(BgReading.class);
public long getTimeIndex() {
return timeIndex;
}
@DatabaseField(id = true)
public long date;
public void setTimeIndex(long timeIndex) {
this.timeIndex = timeIndex;
}
@DatabaseField(id = true, useGetSet = true)
public long timeIndex;
@DatabaseField
public boolean isValid = true;
@DatabaseField
public double value;
@DatabaseField
public String direction;
@DatabaseField
public double raw;
@DatabaseField
public int battery_level;
public int source = Source.NONE;
@DatabaseField
public String _id = null; // NS _id
public static String units = Constants.MGDL;
public BgReading() {}
public BgReading(NSSgv sgv) {
timeIndex = sgv.getMills();
date = sgv.getMills();
value = sgv.getMgdl();
raw = sgv.getFiltered() != null ? sgv.getFiltered() : value;
direction = sgv.getDirection();
@ -101,18 +98,17 @@ public class BgReading implements DataPointInterface {
@Override
public String toString() {
return "BgReading{" +
"timeIndex=" + timeIndex +
", date=" + new Date(timeIndex) +
"date=" + date +
", date=" + DateUtil.dateAndTimeString(date) +
", value=" + value +
", direction=" + direction +
", raw=" + raw +
", battery_level=" + battery_level +
'}';
}
@Override
public double getX() {
return timeIndex;
return date;
}
@Override

View file

@ -8,38 +8,38 @@ import java.util.Date;
@DatabaseTable(tableName = DatabaseHelper.DATABASE_DANARHISTORY)
public class DanaRHistoryRecord {
@DatabaseField(useGetSet = true)
private String _id;
@DatabaseField
public String _id;
@DatabaseField(useGetSet = true)
private byte recordCode;
@DatabaseField
public byte recordCode;
@DatabaseField(id = true, useGetSet = true)
private String bytes;
@DatabaseField(id = true)
public String bytes;
@DatabaseField(useGetSet = true)
private long recordDate;
@DatabaseField
public long recordDate;
@DatabaseField(useGetSet = true)
private double recordValue;
@DatabaseField
public double recordValue;
@DatabaseField(useGetSet = true)
private String bolusType;
@DatabaseField
public String bolusType;
@DatabaseField(useGetSet = true)
private String stringRecordValue;
@DatabaseField
public String stringRecordValue;
@DatabaseField(useGetSet = true)
private int recordDuration;
@DatabaseField
public int recordDuration;
@DatabaseField(useGetSet = true)
private double recordDailyBasal;
@DatabaseField
public double recordDailyBasal;
@DatabaseField(useGetSet = true)
private double recordDailyBolus;
@DatabaseField
public double recordDailyBolus;
@DatabaseField(useGetSet = true)
private String recordAlarm;
@DatabaseField
public String recordAlarm;
public DanaRHistoryRecord() {
this.recordDate = 0;
@ -50,74 +50,6 @@ public class DanaRHistoryRecord {
this._id = null;
}
public void setRecordDate(Date dtRecordDate) {
this.recordDate = dtRecordDate.getTime();
}
public long getRecordDate() {
return this.recordDate;
}
public void setRecordDate(long dtRecordDate) {
this.recordDate = dtRecordDate;
}
public double getRecordValue() {
return this.recordValue;
}
public void setRecordValue(double dRecordValue) {
this.recordValue = dRecordValue;
}
public String getBolusType() {
return this.bolusType;
}
public void setBolusType(String strRecordType) {
this.bolusType = strRecordType;
}
public String getStringRecordValue() {
return this.stringRecordValue;
}
public void setStringRecordValue(String strRecordValue) {
this.stringRecordValue = strRecordValue;
}
public byte getRecordCode() {
return this.recordCode;
}
public void setRecordCode(byte cRecordCode) {
this.recordCode = cRecordCode;
}
public int getRecordDuration() {
return this.recordDuration;
}
public void setRecordDuration(int dRecordDuraion) {
this.recordDuration = dRecordDuraion;
}
public double getRecordDailyBasal() {
return this.recordDailyBasal;
}
public void setRecordDailyBasal(double dRecordDailyBasal) {
this.recordDailyBasal = dRecordDailyBasal;
}
public double getRecordDailyBolus() {
return this.recordDailyBolus;
}
public void setRecordDailyBolus(double dRecordDailyBolus) {
this.recordDailyBolus = dRecordDailyBolus;
}
public int getRecordLevel(double dExLow, double dLow, double dHigh, double dExHigh) {
if (this.recordValue < dExLow)
return 0;
@ -128,34 +60,10 @@ public class DanaRHistoryRecord {
return this.recordValue < dExHigh ? 3 : 4;
}
public String getRecordAlarm() {
return this.recordAlarm;
}
public void setRecordAlarm(String strAlarm) {
this.recordAlarm = strAlarm;
}
public String get_id() {
return this._id;
}
public void set_id(String _id) {
this._id = _id;
}
public void setBytes(byte[] raw) {
this.bytes = bytesToHex(raw);
}
public void setBytes(String bytes) {
this.bytes = bytes;
}
public String getBytes() {
return this.bytes;
}
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {

View file

@ -36,13 +36,15 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public static final String DATABASE_NAME = "AndroidAPSDb";
public static final String DATABASE_BGREADINGS = "BgReadings";
public static final String DATABASE_TEMPBASALS = "TempBasals";
public static final String DATABASE_TEMPEXBASALS = "TempBasals";
public static final String DATABASE_TEMPORARYBASALS = "TemporaryBasals";
public static final String DATABASE_EXTENDEDBOLUSES = "ExtendedBoluses";
public static final String DATABASE_TEMPTARGETS = "TempTargets";
public static final String DATABASE_TREATMENTS = "Treatments";
public static final String DATABASE_DANARHISTORY = "DanaRHistory";
public static final String DATABASE_DBREQUESTS = "DBRequests";
private static final int DATABASE_VERSION = 6;
private static final int DATABASE_VERSION = 7;
private static Long latestTreatmentChange = null;
@ -59,7 +61,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
try {
log.info("onCreate");
TableUtils.createTableIfNotExists(connectionSource, TempBasal.class);
TableUtils.createTableIfNotExists(connectionSource, TempExBasal.class);
TableUtils.createTableIfNotExists(connectionSource, TempTarget.class);
TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
TableUtils.createTableIfNotExists(connectionSource, BgReading.class);
@ -75,7 +77,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
try {
log.info(DatabaseHelper.class.getName(), "onUpgrade");
TableUtils.dropTable(connectionSource, TempBasal.class, true);
TableUtils.dropTable(connectionSource, TempExBasal.class, true);
TableUtils.dropTable(connectionSource, TempTarget.class, true);
TableUtils.dropTable(connectionSource, Treatment.class, true);
TableUtils.dropTable(connectionSource, BgReading.class, true);
@ -99,19 +101,19 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void cleanUpDatabases() {
// TODO: call it somewhere
log.debug("Before BgReadings size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_BGREADINGS));
getWritableDatabase().delete(DATABASE_BGREADINGS, "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
getWritableDatabase().delete(DATABASE_BGREADINGS, "date" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
log.debug("After BgReadings size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_BGREADINGS));
log.debug("Before TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TEMPBASALS));
getWritableDatabase().delete(DATABASE_TEMPBASALS, "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
log.debug("After TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TEMPBASALS));
log.debug("Before TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TEMPEXBASALS));
getWritableDatabase().delete(DATABASE_TEMPEXBASALS, "date" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
log.debug("After TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TEMPEXBASALS));
log.debug("Before TempTargets size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TEMPTARGETS));
getWritableDatabase().delete(DATABASE_TEMPTARGETS, "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
getWritableDatabase().delete(DATABASE_TEMPTARGETS, "date" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
log.debug("After TempTargets size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TEMPTARGETS));
log.debug("Before Treatments size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TREATMENTS));
getWritableDatabase().delete(DATABASE_TREATMENTS, "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
getWritableDatabase().delete(DATABASE_TREATMENTS, "date" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
log.debug("After Treatments size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TREATMENTS));
log.debug("Before History size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_DANARHISTORY));
@ -121,13 +123,13 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void resetDatabases() {
try {
TableUtils.dropTable(connectionSource, TempBasal.class, true);
TableUtils.dropTable(connectionSource, TempExBasal.class, true);
TableUtils.dropTable(connectionSource, TempTarget.class, true);
TableUtils.dropTable(connectionSource, Treatment.class, true);
TableUtils.dropTable(connectionSource, BgReading.class, true);
TableUtils.dropTable(connectionSource, DanaRHistoryRecord.class, true);
//DbRequests can be cleared from NSClient fragment
TableUtils.createTableIfNotExists(connectionSource, TempBasal.class);
TableUtils.createTableIfNotExists(connectionSource, TempExBasal.class);
TableUtils.createTableIfNotExists(connectionSource, TempTarget.class);
TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
TableUtils.createTableIfNotExists(connectionSource, BgReading.class);
@ -157,8 +159,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
}
public Dao<TempBasal, Long> getDaoTempBasals() throws SQLException {
return getDao(TempBasal.class);
public Dao<TempExBasal, Long> getDaoTempBasals() throws SQLException {
return getDao(TempExBasal.class);
}
public Dao<TempTarget, Long> getDaoTempTargets() throws SQLException {
@ -190,9 +192,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
Dao<BgReading, Long> daoBgreadings = getDaoBgReadings();
List<BgReading> bgReadings;
QueryBuilder<BgReading, Long> queryBuilder = daoBgreadings.queryBuilder();
queryBuilder.orderBy("timeIndex", ascending);
queryBuilder.orderBy("date", ascending);
Where where = queryBuilder.where();
where.ge("timeIndex", mills).and().gt("value", 38);
where.ge("date", mills).and().gt("value", 38);
PreparedQuery<BgReading> preparedQuery = queryBuilder.prepare();
bgReadings = daoBgreadings.query(preparedQuery);
return bgReadings;
@ -261,7 +263,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
// TREATMENT HANDLING
public boolean affectingIobCob(Treatment t) {
Treatment existing = findTreatmentByTimeIndex(t.timeIndex);
Treatment existing = findTreatmentByTimeIndex(t.date);
if (existing == null)
return true;
if (existing.insulin == t.insulin && existing.carbs == t.carbs)
@ -275,7 +277,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
boolean historyChange = affectingIobCob(treatment);
updated = getDaoTreatments().update(treatment);
if (historyChange)
latestTreatmentChange = treatment.getTimeIndex();
latestTreatmentChange = treatment.date;
} catch (SQLException e) {
e.printStackTrace();
}
@ -289,7 +291,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
boolean historyChange = affectingIobCob(treatment);
status = getDaoTreatments().createOrUpdate(treatment);
if (historyChange)
latestTreatmentChange = treatment.getTimeIndex();
latestTreatmentChange = treatment.date;
} catch (SQLException e) {
e.printStackTrace();
}
@ -300,7 +302,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void create(Treatment treatment) {
try {
getDaoTreatments().create(treatment);
latestTreatmentChange = treatment.getTimeIndex();
latestTreatmentChange = treatment.date;
} catch (SQLException e) {
e.printStackTrace();
}
@ -310,7 +312,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void delete(Treatment treatment) {
try {
getDaoTreatments().delete(treatment);
latestTreatmentChange = treatment.getTimeIndex();
latestTreatmentChange = treatment.date;
} catch (SQLException e) {
e.printStackTrace();
}
@ -329,7 +331,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
if (Config.logIncommingData)
log.debug("Records removed: " + removed);
latestTreatmentChange = stored.getTimeIndex();
latestTreatmentChange = stored.date;
scheduleTreatmentChange();
} else {
log.debug("REMOVE: Not stored treatment (ignoring): " + _id);
@ -367,7 +369,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
Dao<Treatment, Long> daoTreatments = getDaoTreatments();
QueryBuilder<Treatment, Long> queryBuilder = daoTreatments.queryBuilder();
Where where = queryBuilder.where();
where.eq("timeIndex", timeIndex);
where.eq("date", timeIndex);
queryBuilder.limit(10L);
PreparedQuery<Treatment> preparedQuery = queryBuilder.prepare();
List<Treatment> trList = daoTreatments.query(preparedQuery);
@ -409,9 +411,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
Dao<Treatment, Long> daoTreatments = getDaoTreatments();
List<Treatment> treatments;
QueryBuilder<Treatment, Long> queryBuilder = daoTreatments.queryBuilder();
queryBuilder.orderBy("timeIndex", ascending);
queryBuilder.orderBy("date", ascending);
Where where = queryBuilder.where();
where.ge("timeIndex", mills);
where.ge("date", mills);
PreparedQuery<Treatment> preparedQuery = queryBuilder.prepare();
treatments = daoTreatments.query(preparedQuery);
return treatments;
@ -421,11 +423,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return new ArrayList<Treatment>();
}
public int update(TempBasal tempBasal) {
public int update(TempExBasal tempBasal) {
int updated = 0;
try {
updated = getDaoTempBasals().update(tempBasal);
latestTreatmentChange = tempBasal.getTimeIndex();
latestTreatmentChange = tempBasal.timeIndex;
} catch (SQLException e) {
e.printStackTrace();
}
@ -433,20 +435,20 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return updated;
}
public void create(TempBasal tempBasal) {
public void create(TempExBasal tempBasal) {
try {
getDaoTempBasals().create(tempBasal);
latestTreatmentChange = tempBasal.getTimeIndex();
latestTreatmentChange = tempBasal.timeIndex;
} catch (SQLException e) {
e.printStackTrace();
}
scheduleTreatmentChange();
}
public void delete(TempBasal tempBasal) {
public void delete(TempExBasal tempBasal) {
try {
getDaoTempBasals().delete(tempBasal);
latestTreatmentChange = tempBasal.getTimeIndex();
latestTreatmentChange = tempBasal.timeIndex;
} catch (SQLException e) {
e.printStackTrace();
}
@ -458,9 +460,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
Dao<TempTarget, Long> daoTempTargets = getDaoTempTargets();
List<TempTarget> tempTargets;
QueryBuilder<TempTarget, Long> queryBuilder = daoTempTargets.queryBuilder();
queryBuilder.orderBy("timeIndex", ascending);
queryBuilder.orderBy("date", ascending);
Where where = queryBuilder.where();
where.ge("timeIndex", mills);
where.ge("date", mills);
PreparedQuery<TempTarget> preparedQuery = queryBuilder.prepare();
tempTargets = daoTempTargets.query(preparedQuery);
return tempTargets;
@ -471,21 +473,21 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
}
public List<TempBasal> getTempbasalsDataFromTime(long mills, boolean ascending, boolean isExtended) {
public List<TempExBasal> getTempbasalsDataFromTime(long mills, boolean ascending, boolean isExtended) {
try {
Dao<TempBasal, Long> daoTempbasals = getDaoTempBasals();
List<TempBasal> tempbasals;
QueryBuilder<TempBasal, Long> queryBuilder = daoTempbasals.queryBuilder();
queryBuilder.orderBy("timeIndex", ascending);
Dao<TempExBasal, Long> daoTempbasals = getDaoTempBasals();
List<TempExBasal> tempbasals;
QueryBuilder<TempExBasal, Long> queryBuilder = daoTempbasals.queryBuilder();
queryBuilder.orderBy("date", ascending);
Where where = queryBuilder.where();
where.ge("timeIndex", mills).and().eq("isExtended", isExtended);
PreparedQuery<TempBasal> preparedQuery = queryBuilder.prepare();
where.ge("date", mills).and().eq("isExtended", isExtended);
PreparedQuery<TempExBasal> preparedQuery = queryBuilder.prepare();
tempbasals = daoTempbasals.query(preparedQuery);
return tempbasals;
} catch (SQLException e) {
e.printStackTrace();
}
return new ArrayList<TempBasal>();
return new ArrayList<TempExBasal>();
}
}

View file

@ -19,15 +19,7 @@ import org.slf4j.LoggerFactory;
public class DbRequest {
private static Logger log = LoggerFactory.getLogger(DbRequest.class);
public String getNsClientID() {
return nsClientID;
}
public void setNsClientID(String nsClientID) {
this.nsClientID = nsClientID;
}
@DatabaseField(id = true, useGetSet = true)
@DatabaseField(id = true)
public String nsClientID = null;
@DatabaseField

View file

@ -0,0 +1,187 @@
package info.nightscout.androidaps.db;
/**
* Created by mike on 21.05.2017.
*/
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.Interval;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
import info.nightscout.utils.Round;
/**
* Created by mike on 21.05.2017.
*/
@DatabaseTable(tableName = DatabaseHelper.DATABASE_EXTENDEDBOLUSES)
public class ExtendedBolus implements Interval {
private static Logger log = LoggerFactory.getLogger(ExtendedBolus.class);
@DatabaseField(id = true)
public long date;
@DatabaseField
public boolean isValid = true;
@DatabaseField
public int source = Source.NONE;
@DatabaseField
public String _id = null; // NS _id
@DatabaseField
public double insulin = 0d;
@DatabaseField
public int durationInMinutes = 0; // duration == 0 means end of temp basal
@DatabaseField
public int insulinInterfaceID = InsulinInterface.FASTACTINGINSULIN;
@DatabaseField
public double dia = Constants.defaultDIA;
// -------- Interval interface ---------
Long cuttedEnd = null;
public long durationInMsec() {
return durationInMinutes * 60 * 1000L;
}
public long start() {
return date;
}
// planned end time at time of creation
public long originalEnd() {
return date + durationInMinutes * 60 * 1000L;
}
// end time after cut
public long end() {
if (cuttedEnd != null)
return cuttedEnd;
return originalEnd();
}
public void cutEndTo(long end) {
cuttedEnd = end;
}
public boolean match(long time) {
if (start() <= time && end() >= time)
return true;
return false;
}
public boolean before(long time) {
if (end() < time)
return true;
return false;
}
public boolean after(long time) {
if (start() > time)
return true;
return false;
}
// -------- Interval interface end ---------
public String log() {
return "Bolus{" +
"date= " + date +
", date= " + DateUtil.dateAndTimeString(date) +
", isValid=" + isValid +
", _id= " + _id +
", insulin= " + insulin +
", durationInMinutes= " + durationInMinutes +
"}";
}
double absoluteRate() {
return Round.roundTo(insulin / durationInMinutes * 60, 0.01);
}
public IobTotal iobCalc(long time) {
IobTotal result = new IobTotal(time);
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
if (profile == null)
return result;
int realDuration = getDurationToTime(time);
if (realDuration > 0) {
Double dia_ago = time - profile.getDia() * 60 * 60 * 1000;
int aboutFiveMinIntervals = (int) Math.ceil(realDuration / 5d);
double spacing = realDuration / aboutFiveMinIntervals;
for (Long j = 0L; j < aboutFiveMinIntervals; j++) {
// find middle of the interval
Long calcdate = (long) (date + j * spacing * 60 * 1000 + 0.5d * spacing * 60 * 1000);
if (calcdate > dia_ago && calcdate <= time) {
double tempBolusSize = absoluteRate() * spacing / 60d;
Treatment tempBolusPart = new Treatment(insulinInterface);
tempBolusPart.insulin = tempBolusSize;
tempBolusPart.date = calcdate;
Iob aIOB = insulinInterface.iobCalcForTreatment(tempBolusPart, time, profile.getDia());
result.iob += aIOB.iobContrib;
result.activity += aIOB.activityContrib;
}
}
}
return result;
}
public int getRealDuration() {
return getDurationToTime(new Date().getTime());
}
private int getDurationToTime(long time) {
long endTime = Math.min(time, end());
long msecs = endTime - date;
return Math.round(msecs / 60f / 1000);
}
public int getPlannedRemainingMinutes() {
float remainingMin = (end() - new Date().getTime()) / 1000f / 60;
return (remainingMin < 0) ? 0 : Math.round(remainingMin);
}
public boolean isInProgress() {
return match(new Date().getTime());
}
public String toString() {
return "E " + DecimalFormatter.to2Decimal(absoluteRate()) + "U/h @" +
DateUtil.timeString(date) +
" " + getRealDuration() + "/" + durationInMinutes + "min";
}
public String toStringShort() {
return "E " + DecimalFormatter.to2Decimal(absoluteRate()) + "U/h ";
}
public String toStringMedium() {
return "E " + DecimalFormatter.to2Decimal(absoluteRate()) + "U/h ("
+ getRealDuration() + "/" + durationInMinutes + ") ";
}
}

View file

@ -0,0 +1,11 @@
package info.nightscout.androidaps.db;
/**
* Created by mike on 21.05.2017.
*/
public class Source {
public final static int NONE = 0;
public final static int PUMP = 1;
public final static int NIGHTSCOUT = 2;
}

View file

@ -8,7 +8,6 @@ import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.interfaces.InsulinInterface;
@ -17,19 +16,11 @@ import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
@DatabaseTable(tableName = DatabaseHelper.DATABASE_TEMPBASALS)
public class TempBasal {
private static Logger log = LoggerFactory.getLogger(TempBasal.class);
@DatabaseTable(tableName = DatabaseHelper.DATABASE_TEMPEXBASALS)
public class TempExBasal {
private static Logger log = LoggerFactory.getLogger(TempExBasal.class);
public long getTimeIndex() {
return timeStart.getTime();
}
public void setTimeIndex(long timeIndex) {
this.timeIndex = timeIndex;
}
@DatabaseField(id = true, useGetSet = true)
@DatabaseField(id = true)
public long timeIndex;
@DatabaseField
@ -96,7 +87,7 @@ public class TempBasal {
Treatment tempBolusPart = new Treatment(insulinInterface);
tempBolusPart.insulin = tempBolusSize;
tempBolusPart.created_at = new Date(date);
tempBolusPart.date = date;
Iob aIOB = insulinInterface.iobCalcForTreatment(tempBolusPart, time, profile.getDia());
result.basaliob += aIOB.iobContrib;
@ -184,7 +175,7 @@ public class TempBasal {
}
public String log() {
return "TempBasal{" +
return "TempExBasal{" +
"timeIndex=" + timeIndex +
", timeStart=" + timeStart +
", timeEnd=" + timeEnd +

View file

@ -10,26 +10,25 @@ import java.util.Date;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.interfaces.Interval;
import info.nightscout.androidaps.plugins.TempTargetRange.TempTargetRangePlugin;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
@DatabaseTable(tableName = DatabaseHelper.DATABASE_TEMPTARGETS)
public class TempTarget {
public class TempTarget implements Interval {
private static Logger log = LoggerFactory.getLogger(TempTarget.class);
public long getTimeIndex() {
return timeStart.getTime() - timeStart.getTime() % 1000;
}
public void setTimeIndex(long timeIndex) {
this.timeIndex = timeIndex;
}
@DatabaseField(id = true, useGetSet = true)
public long timeIndex;
@DatabaseField(id = true)
public long date;
@DatabaseField
public Date timeStart;
public boolean isValid = true;
@DatabaseField
public int source = Source.NONE;
@DatabaseField
public String _id = null; // NS _id
@DatabaseField
public double low; // in mgdl
@ -41,15 +40,56 @@ public class TempTarget {
public String reason;
@DatabaseField
public int duration; // in minutes
public int durationInMinutes;
@DatabaseField
public String _id; // NS _id
// -------- Interval interface ---------
public Date getPlannedTimeEnd() {
return new Date(timeStart.getTime() + 60 * 1_000 * duration);
Long cuttedEnd = null;
public long durationInMsec() {
return durationInMinutes * 60 * 1000L;
}
public long start() {
return date;
}
// planned end time at time of creation
public long originalEnd() {
return date + durationInMinutes * 60 * 1000L;
}
// end time after cut
public long end() {
if (cuttedEnd != null)
return cuttedEnd;
return originalEnd();
}
public void cutEndTo(long end) {
cuttedEnd = end;
}
public boolean match(long time) {
if (start() <= time && end() >= time)
return true;
return false;
}
public boolean before(long time) {
if (end() < time)
return true;
return false;
}
public boolean after(long time) {
if (start() > time)
return true;
return false;
}
// -------- Interval interface end ---------
public String lowValueToUnitsToString(String units) {
if (units.equals(Constants.MGDL)) return DecimalFormatter.to0Decimal(low);
else return DecimalFormatter.to1Decimal(low * Constants.MGDL_TO_MMOLL);
@ -61,14 +101,15 @@ public class TempTarget {
}
public boolean isInProgress() {
return ((TempTargetRangePlugin) MainApp.getSpecificPlugin(TempTargetRangePlugin.class)).getTempTargetInProgress(new Date().getTime()) == this;
return match(new Date().getTime());
}
public String log() {
return "TempTarget{" +
"timeIndex=" + timeIndex +
", timeStart=" + timeStart +
", duration=" + duration +
return "TemporaryTarget{" +
"date=" + date +
"date=" + DateUtil.dateAndTimeString(date) +
", isValid=" + isValid +
", duration=" + durationInMinutes +
", reason=" + reason +
", low=" + low +
", high=" + high +

View file

@ -0,0 +1,220 @@
package info.nightscout.androidaps.db;
import com.j256.ormlite.field.DatabaseField;
import com.j256.ormlite.table.DatabaseTable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Date;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.Interval;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter;
/**
* Created by mike on 21.05.2017.
*/
@DatabaseTable(tableName = DatabaseHelper.DATABASE_TEMPORARYBASALS)
public class TemporaryBasal implements Interval {
private static Logger log = LoggerFactory.getLogger(TemporaryBasal.class);
@DatabaseField(id = true)
public long date;
@DatabaseField
public boolean isValid = true;
@DatabaseField
public int source = Source.NONE;
@DatabaseField
public String _id = null; // NS _id
@DatabaseField
public int durationInMinutes = 0; // duration == 0 means end of temp basal
@DatabaseField
public boolean isAbsolute = false;
@DatabaseField
public int percentRate = 0;
@DatabaseField
public double absoluteRate = 0d;
// -------- Interval interface ---------
Long cuttedEnd = null;
public long durationInMsec() {
return durationInMinutes * 60 * 1000L;
}
public long start() {
return date;
}
// planned end time at time of creation
public long originalEnd() {
return date + durationInMinutes * 60 * 1000L;
}
// end time after cut
public long end() {
if (cuttedEnd != null)
return cuttedEnd;
return originalEnd();
}
public void cutEndTo(long end) {
cuttedEnd = end;
}
public boolean match(long time) {
if (start() <= time && end() >= time)
return true;
return false;
}
public boolean before(long time) {
if (end() < time)
return true;
return false;
}
public boolean after(long time) {
if (start() > time)
return true;
return false;
}
// -------- Interval interface end ---------
public IobTotal iobCalc(long time) {
IobTotal result = new IobTotal(time);
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
InsulinInterface insulinInterface = ConfigBuilderPlugin.getActiveInsulin();
if (profile == null)
return result;
int realDuration = getDurationToTime(time);
Double netBasalAmount = 0d;
if (realDuration > 0) {
Double netBasalRate = 0d;
Double dia_ago = time - profile.getDia() * 60 * 60 * 1000;
int aboutFiveMinIntervals = (int) Math.ceil(realDuration / 5d);
double tempBolusSpacing = realDuration / aboutFiveMinIntervals;
for (Long j = 0L; j < aboutFiveMinIntervals; j++) {
// find middle of the interval
Long calcdate = (long) (date + j * tempBolusSpacing * 60 * 1000 + 0.5d * tempBolusSpacing * 60 * 1000);
Double basalRate = profile.getBasal(NSProfile.secondsFromMidnight(calcdate));
if (basalRate == null)
continue;
if (isAbsolute) {
netBasalRate = absoluteRate - basalRate;
} else {
netBasalRate = (percentRate - 100) / 100d * basalRate;
}
if (calcdate > dia_ago && calcdate <= time) {
double tempBolusSize = netBasalRate * tempBolusSpacing / 60d;
netBasalAmount += tempBolusSize;
Treatment tempBolusPart = new Treatment(insulinInterface);
tempBolusPart.insulin = tempBolusSize;
tempBolusPart.date = calcdate;
Iob aIOB = insulinInterface.iobCalcForTreatment(tempBolusPart, time, profile.getDia());
result.basaliob += aIOB.iobContrib;
result.activity += aIOB.activityContrib;
result.netbasalinsulin += tempBolusPart.insulin;
if (tempBolusPart.insulin > 0) {
result.hightempinsulin += tempBolusPart.insulin;
}
}
result.netRatio = netBasalRate; // ratio at the end of interval
}
}
result.netInsulin = netBasalAmount;
return result;
}
public int getRealDuration() {
return getDurationToTime(new Date().getTime());
}
private int getDurationToTime(long time) {
long endTime = Math.min(time, end());
long msecs = endTime - date;
return Math.round(msecs / 60f / 1000);
}
public int getPlannedRemainingMinutes() {
float remainingMin = (end() - new Date().getTime()) / 1000f / 60;
return (remainingMin < 0) ? 0 : Math.round(remainingMin);
}
public boolean isInProgress() {
return match(new Date().getTime());
}
public double tempBasalConvertedToAbsolute(Date time) {
if (isAbsolute) return absoluteRate;
else {
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
return profile.getBasal(NSProfile.secondsFromMidnight(time)) * percentRate / 100;
}
}
public String log() {
return "TemporaryBasal{" +
"date=" + date +
", date=" + DateUtil.dateAndTimeString(date) +
", isValid=" + isValid +
", _id=" + _id +
", percentRate=" + percentRate +
", absoluteRate=" + absoluteRate +
", durationInMinutes=" + durationInMinutes +
", isAbsolute=" + isAbsolute +
'}';
}
public String toString() {
if (isAbsolute) {
return DecimalFormatter.to2Decimal(absoluteRate) + "U/h @" +
DateUtil.timeString(date) +
" " + getRealDuration() + "/" + durationInMinutes + "min";
} else { // percent
return percentRate + "% @" +
DateUtil.timeString(date) +
" " + getRealDuration() + "/" + durationInMinutes + "min";
}
}
public String toStringShort() {
if (isAbsolute) {
return DecimalFormatter.to2Decimal(absoluteRate) + "U/h ";
} else { // percent
return percentRate + "% ";
}
}
public String toStringMedium() {
if (isAbsolute) {
return DecimalFormatter.to2Decimal(absoluteRate) + "U/h ("
+ getRealDuration() + "/" + durationInMinutes + ") ";
} else { // percent
return percentRate + "% (" + getRealDuration() + "/" + durationInMinutes + ") ";
}
}
}

View file

@ -14,7 +14,6 @@ import java.util.List;
import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.DataPointWithLabelInterface;
@ -26,81 +25,67 @@ import info.nightscout.utils.DecimalFormatter;
public class Treatment implements DataPointWithLabelInterface {
private static Logger log = LoggerFactory.getLogger(Treatment.class);
public long getTimeIndex() {
return created_at.getTime();
}
@DatabaseField(id = true)
public long date;
public void setTimeIndex(long timeIndex) {
this.timeIndex = timeIndex;
}
@DatabaseField(id = true, useGetSet = true)
public long timeIndex;
@DatabaseField
public boolean isValid = true;
@DatabaseField
public int source = Source.NONE;
@DatabaseField
public String _id;
@DatabaseField
public Date created_at;
@DatabaseField
public Double insulin = 0d;
@DatabaseField
public int insulinType = InsulinInterface.FASTACTINGINSULIN;
@DatabaseField
public double dia = Constants.defaultDIA;
@DatabaseField
public Double carbs = 0d;
@DatabaseField
public boolean mealBolus = true; // true for meal bolus , false for correction bolus
@DatabaseField
public int insulinInterfaceID = InsulinInterface.FASTACTINGINSULIN;
@DatabaseField
public double dia = Constants.defaultDIA;
public Treatment() {
InsulinInterface insulin = MainApp.getConfigBuilder().getActiveInsulin();
if (insulin != null) {
insulinType = insulin.getId();
dia = insulin.getDia();
} else {
insulinType = InsulinInterface.FASTACTINGINSULIN;
dia = Constants.defaultDIA;
}
}
public Treatment(InsulinInterface insulin) {
insulinType = insulin.getId();
insulinInterfaceID = insulin.getId();
dia = insulin.getDia();
}
public void copyFrom(Treatment t) {
this.date = t.date;
this.isValid = t.isValid;
this.source = t.source;
this._id = t._id;
this.created_at = t.created_at;
this.insulin = t.insulin;
this.carbs = t.carbs;
this.mealBolus = t.mealBolus;
}
public long getMillisecondsFromStart() {
return new Date().getTime() - created_at.getTime();
return new Date().getTime() - date;
}
public String log() {
return "Treatment{" +
"timeIndex: " + timeIndex +
", _id: " + _id +
", insulin: " + insulin +
", carbs: " + carbs +
", mealBolus: " + mealBolus +
", created_at: " +
"date= " + date +
"date= " + DateUtil.dateAndTimeString(date) +
", isValid= " + isValid +
", _id= " + _id +
", insulin= " + insulin +
", carbs= " + carbs +
", mealBolus= " + mealBolus +
"}";
}
// DataPointInterface
// ----------------- DataPointInterface --------------------
@Override
public double getX() {
return timeIndex;
return date;
}
// default when no sgv around available
@ -125,12 +110,14 @@ public class Treatment implements DataPointWithLabelInterface {
if (profile == null) return;
for (int r = bgReadingsArray.size() - 1; r >= 0; r--) {
BgReading reading = bgReadingsArray.get(r);
if (reading.timeIndex > timeIndex) continue;
if (reading.date > date) continue;
yValue = NSProfile.fromMgdlToUnits(reading.value, profile.getUnits());
break;
}
}
// ----------------- DataPointInterface end --------------------
public void sendToNSClient() {
JSONObject data = new JSONObject();
try {
@ -140,8 +127,8 @@ public class Treatment implements DataPointWithLabelInterface {
data.put("eventType", "Correction Bolus");
if (insulin != 0d) data.put("insulin", insulin);
if (carbs != 0d) data.put("carbs", carbs.intValue());
data.put("created_at", DateUtil.toISOString(created_at));
data.put("timeIndex", timeIndex);
data.put("created_at", DateUtil.toISOString(date));
data.put("timeIndex", date);
} catch (JSONException e) {
e.printStackTrace();
}
@ -149,7 +136,7 @@ public class Treatment implements DataPointWithLabelInterface {
}
public Iob iobCalc(long time, double dia) {
InsulinInterface insulinInterface = MainApp.getInsulinIterfaceById(insulinType);
InsulinInterface insulinInterface = MainApp.getInsulinIterfaceById(insulinInterfaceID);
if (insulinInterface == null)
insulinInterface = ConfigBuilderPlugin.getActiveInsulin();

View file

@ -0,0 +1,21 @@
package info.nightscout.androidaps.interfaces;
/**
* Created by mike on 21.05.2017.
*/
public interface Interval {
long durationInMsec();
long start();
// planned end time at time of creation
long originalEnd();
// end time after cut
long end();
void cutEndTo(long end);
boolean match(long time);
boolean before(long time);
boolean after(long time);
}

View file

@ -7,7 +7,6 @@ import org.json.JSONObject;
import java.util.Date;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
/**

View file

@ -1,10 +1,9 @@
package info.nightscout.androidaps.interfaces;
import java.util.Date;
import java.util.List;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.data.IobTotal;
@ -28,20 +27,20 @@ public interface TreatmentsInterface {
// real basals on pump
boolean isRealTempBasalInProgress();
TempBasal getRealTempBasal (long time);
TempExBasal getRealTempBasal (long time);
void tempBasalStart(TempBasal tempBasal);
void tempBasalStart(TempExBasal tempBasal);
void tempBasalStop(long time);
// basal that can be faked by extended boluses
boolean isTempBasalInProgress();
TempBasal getTempBasal (long time);
TempExBasal getTempBasal (long time);
double getTempBasalAbsoluteRate();
double getTempBasalRemainingMinutes();
boolean isExtendedBoluslInProgress();
TempBasal getExtendedBolus (long time);
void extendedBolusStart(TempBasal extendedBolus);
TempExBasal getExtendedBolus (long time);
void extendedBolusStart(TempExBasal extendedBolus);
void extendedBolusStop(long time);
long oldestDataAvaialable();

View file

@ -649,17 +649,16 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
public void run() {
try {
TempTarget tempTarget = new TempTarget();
tempTarget.timeStart = eventTime;
tempTarget.duration = data.getInt("duration");
tempTarget.date = eventTime.getTime();
tempTarget.durationInMinutes = data.getInt("duration");
tempTarget.reason = data.getString("reason");
if(tempTarget.duration != 0) {
if(tempTarget.durationInMinutes != 0) {
tempTarget.low = NSProfile.toMgdl(data.getDouble("targetBottom"), ConfigBuilderPlugin.getActiveProfile().getProfile().getUnits());
tempTarget.high = NSProfile.toMgdl(data.getDouble("targetTop"), ConfigBuilderPlugin.getActiveProfile().getProfile().getUnits());
} else {
tempTarget.low = 0;
tempTarget.high = 0;
}
tempTarget.setTimeIndex(tempTarget.getTimeIndex());
Dao<TempTarget, Long> dao = MainApp.getDbHelper().getDaoTempTargets();
log.debug("Creating new TempTarget db record: " + tempTarget.log());
dao.createIfNotExists(tempTarget);

View file

@ -25,7 +25,7 @@ import info.nightscout.androidaps.Services.Intents;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventBolusRequested;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
@ -54,7 +54,6 @@ import info.nightscout.androidaps.plugins.Overview.events.EventDismissBolusprogr
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
import info.nightscout.androidaps.plugins.PumpDanaR.comm.MsgError;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.BatteryLevel;
import info.nightscout.utils.DateUtil;
import info.nightscout.utils.SP;
@ -440,10 +439,9 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
t.insulin = result.bolusDelivered;
if (carbTime == 0)
t.carbs = (double) result.carbsDelivered; // with different carbTime record will come back from nightscout
t.created_at = new Date();
t.date = new Date().getDate();
t.mealBolus = result.carbsDelivered > 0;
MainApp.getDbHelper().create(t);
t.setTimeIndex(t.getTimeIndex());
t.carbs = (double) result.carbsDelivered;
uploadBolusWizardRecord(t, glucose, glucoseType, carbTime, boluscalc);
}
@ -453,10 +451,9 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
Treatment t = new Treatment(insulinType);
t.insulin = insulin;
t.carbs = (double) carbs;
t.created_at = new Date();
t.date = new Date().getDate();
t.mealBolus = t.carbs > 0;
MainApp.getDbHelper().create(t);
t.setTimeIndex(t.getTimeIndex());
t.sendToNSClient();
result = new PumpEnactResult();
result.success = true;
@ -507,10 +504,9 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
Treatment t = new Treatment(insulinType);
t.insulin = result.bolusDelivered;
t.carbs = (double) result.carbsDelivered;
t.created_at = new Date();
t.date = new Date().getDate();
t.mealBolus = t.carbs > 0;
MainApp.getDbHelper().create(t);
t.setTimeIndex(t.getTimeIndex());
t.sendToNSClient();
}
} else {
@ -519,10 +515,9 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
Treatment t = new Treatment(insulinType);
t.insulin = insulin;
t.carbs = (double) carbs;
t.created_at = new Date();
t.date = new Date().getDate();
t.mealBolus = t.carbs > 0;
MainApp.getDbHelper().create(t);
t.setTimeIndex(t.getTimeIndex());
t.sendToNSClient();
result = new PumpEnactResult();
result.success = true;
@ -1027,8 +1022,8 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
data.put("eventType", "Bolus Wizard");
if (t.insulin != 0d) data.put("insulin", t.insulin);
if (t.carbs != 0d) data.put("carbs", t.carbs.intValue());
data.put("created_at", DateUtil.toISOString(t.created_at));
data.put("timeIndex", t.timeIndex);
data.put("created_at", DateUtil.toISOString(t.date));
data.put("date", t.date);
if (glucose != 0d) data.put("glucose", glucose);
data.put("glucoseType", glucoseType);
data.put("boluscalc", boluscalc);
@ -1184,7 +1179,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
}
@Override
public TempBasal getRealTempBasal(long time) {
public TempExBasal getRealTempBasal(long time) {
return activeTreatments.getRealTempBasal(time);
}
@ -1194,7 +1189,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
}
@Override
public TempBasal getTempBasal(long time) {
public TempExBasal getTempBasal(long time) {
return activeTreatments.getTempBasal(time);
}
@ -1209,7 +1204,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
}
@Override
public void tempBasalStart(TempBasal tempBasal) {
public void tempBasalStart(TempExBasal tempBasal) {
activeTreatments.tempBasalStart(tempBasal);
MainApp.bus().post(new EventTempBasalChange());
}
@ -1226,12 +1221,12 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
}
@Override
public TempBasal getExtendedBolus(long time) {
public TempExBasal getExtendedBolus(long time) {
return activeTreatments.getExtendedBolus(time);
}
@Override
public void extendedBolusStart(TempBasal tempBasal) {
public void extendedBolusStart(TempExBasal tempBasal) {
activeTreatments.extendedBolusStart(tempBasal);
MainApp.bus().post(new EventExtendedBolusChange());
}

View file

@ -15,7 +15,6 @@ import java.util.List;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.plugins.Overview.graphExtensions.TimeAsXAxisLabelFormatter;
/**
* Created by mike on 21.04.2017.
@ -40,8 +39,7 @@ public class ActivityGraph extends GraphView {
int hours = (int) Math.floor(dia + 1);
Treatment t = new Treatment(insulin);
t.created_at = new Date(0);
t.timeIndex = 0;
t.date = 0;
t.insulin = 1d;
LineGraphSeries<DataPoint> activitySeries = null;

View file

@ -103,22 +103,22 @@ public class InsulinFastactingPlugin implements PluginBase, InsulinInterface {
public Iob iobCalcForTreatment(Treatment treatment, long time, Double dia) {
Iob result = new Iob();
Double scaleFactor = 3.0 / dia;
Double peak = 75d;
Double end = 180d;
double scaleFactor = 3.0 / dia;
double peak = 75d;
double end = 180d;
if (treatment.insulin != 0d) {
Long bolusTime = treatment.created_at.getTime();
Double minAgo = scaleFactor * (time - bolusTime) / 1000d / 60d;
long bolusTime = treatment.date;
double minAgo = scaleFactor * (time - bolusTime) / 1000d / 60d;
if (minAgo < peak) {
Double x1 = minAgo / 5d + 1;
double x1 = minAgo / 5d + 1;
result.iobContrib = treatment.insulin * (1 - 0.001852 * x1 * x1 + 0.001852 * x1);
// units: BG (mg/dL) = (BG/U) * U insulin * scalar
result.activityContrib = treatment.insulin * (2 / dia / 60 / peak) * minAgo;
} else if (minAgo < end) {
Double x2 = (minAgo - 75) / 5;
double x2 = (minAgo - 75) / 5;
result.iobContrib = treatment.insulin * (0.001323 * x2 * x2 - 0.054233 * x2 + 0.55556);
result.activityContrib = treatment.insulin * (2 / dia / 60 - (minAgo - peak) * 2 / dia / 60 / (60 * 3 - peak));
}

View file

@ -104,26 +104,26 @@ public class InsulinFastactingProlongedPlugin implements PluginBase, InsulinInte
Iob result = new Iob();
//Double scaleFactor = 3.0 / dia;
Double peak = 75d * dia / 6.0;
Double tail = 180d * dia / 6.0;
Double end = 360d * dia / 6.0;
Double Total = 2 * peak + (tail - peak) * 5 / 2 + (end - tail) / 2;
double peak = 75d * dia / 6.0;
double tail = 180d * dia / 6.0;
double end = 360d * dia / 6.0;
double Total = 2 * peak + (tail - peak) * 5 / 2 + (end - tail) / 2;
if (treatment.insulin != 0d) {
Long bolusTime = treatment.created_at.getTime();
Double minAgo = (time - bolusTime) / 1000d / 60d;
long bolusTime = treatment.date;
double minAgo = (time - bolusTime) / 1000d / 60d;
if (minAgo < peak) {
Double x1 = 6 / dia * minAgo / 5d + 1;
double x1 = 6 / dia * minAgo / 5d + 1;
result.iobContrib = treatment.insulin * (1 - 0.0012595 * x1 * x1 + 0.0012595 * x1);
// units: BG (mg/dL) = (BG/U) * U insulin * scalar
result.activityContrib = treatment.insulin * ((2 * peak / Total) * 2 / peak / peak * minAgo);
} else if (minAgo < tail) {
Double x2 = (6 / dia * (minAgo - peak)) / 5;
double x2 = (6 / dia * (minAgo - peak)) / 5;
result.iobContrib = treatment.insulin * (0.00074 * x2 * x2 - 0.0403 * x2 + 0.69772);
result.activityContrib = treatment.insulin * (-((2 * peak / Total) * 2 / peak * 3 / 4) / (tail - peak) * (minAgo - peak) + (2 * peak / Total) * 2 / peak);
} else if (minAgo < end) {
Double x3 = (6 / dia * (minAgo - tail)) / 5;
double x3 = (6 / dia * (minAgo - tail)) / 5;
result.iobContrib = treatment.insulin * (0.0001323 * x3 * x3 - 0.0097 * x3 + 0.17776);
result.activityContrib = treatment.insulin * (-((2 * peak / Total) * 2 / peak * 1 / 4) / (end - tail) * (minAgo - tail) + (2 * peak / Total) * 2 / peak / 4);
}

View file

@ -24,7 +24,6 @@ import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventNewBasalProfile;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventAutosensCalculationFinished;
import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistoryData;
@ -139,7 +138,7 @@ public class IobCobCalculatorPlugin implements PluginBase {
private static int indexNewerThan(long time) {
for (int index = 0; index < bucketed_data.size(); index++) {
if (bucketed_data.get(index).timeIndex < time)
if (bucketed_data.get(index).date < time)
return index - 1;
}
return -1;
@ -174,8 +173,8 @@ public class IobCobCalculatorPlugin implements PluginBase {
bucketed_data.add(bgReadings.get(0));
int j = 0;
for (int i = 1; i < bgReadings.size(); ++i) {
long bgTime = bgReadings.get(i).getTimeIndex();
long lastbgTime = bgReadings.get(i - 1).getTimeIndex();
long bgTime = bgReadings.get(i).date;
long lastbgTime = bgReadings.get(i - 1).date;
//log.error("Processing " + i + ": " + new Date(bgTime).toString() + " " + bgReadings.get(i).value + " Previous: " + new Date(lastbgTime).toString() + " " + bgReadings.get(i - 1).value);
if (bgReadings.get(i).value < 39 || bgReadings.get(i - 1).value < 39) {
continue;
@ -192,14 +191,14 @@ public class IobCobCalculatorPlugin implements PluginBase {
nextbgTime = lastbgTime - 5 * 60 * 1000;
j++;
BgReading newBgreading = new BgReading();
newBgreading.timeIndex = nextbgTime;
newBgreading.date = nextbgTime;
double gapDelta = bgReadings.get(i).value - lastbg;
//console.error(gapDelta, lastbg, elapsed_minutes);
double nextbg = lastbg + (5d / elapsed_minutes * gapDelta);
newBgreading.value = Math.round(nextbg);
//console.error("Interpolated", bucketed_data[j]);
bucketed_data.add(newBgreading);
//log.error("******************************************************************************************************* Adding:" + new Date(newBgreading.timeIndex).toString() + " " + newBgreading.value);
//log.error("******************************************************************************************************* Adding:" + new Date(newBgreading.date).toString() + " " + newBgreading.value);
elapsed_minutes = elapsed_minutes - 5;
lastbg = nextbg;
@ -208,16 +207,16 @@ public class IobCobCalculatorPlugin implements PluginBase {
j++;
BgReading newBgreading = new BgReading();
newBgreading.value = bgReadings.get(i).value;
newBgreading.timeIndex = bgTime;
newBgreading.date = bgTime;
bucketed_data.add(newBgreading);
//log.error("******************************************************************************************************* Copying:" + new Date(newBgreading.timeIndex).toString() + " " + newBgreading.value);
//log.error("******************************************************************************************************* Copying:" + new Date(newBgreading.date).toString() + " " + newBgreading.value);
} else if (Math.abs(elapsed_minutes) > 2) {
j++;
BgReading newBgreading = new BgReading();
newBgreading.value = bgReadings.get(i).value;
newBgreading.timeIndex = bgTime;
newBgreading.date = bgTime;
bucketed_data.add(newBgreading);
//log.error("******************************************************************************************************* Copying:" + new Date(newBgreading.timeIndex).toString() + " " + newBgreading.value);
//log.error("******************************************************************************************************* Copying:" + new Date(newBgreading.date).toString() + " " + newBgreading.value);
} else {
bucketed_data.get(j).value = (bucketed_data.get(j).value + bgReadings.get(i).value) / 2;
//log.error("***** Average");
@ -243,13 +242,13 @@ public class IobCobCalculatorPlugin implements PluginBase {
return;
}
long prevDataTime = roundUpTime(bucketed_data.get(bucketed_data.size() - 3).timeIndex);
long prevDataTime = roundUpTime(bucketed_data.get(bucketed_data.size() - 3).date);
log.debug("Prev data time: " + new Date(prevDataTime).toLocaleString());
AutosensData previous = autosensDataTable.get(prevDataTime);
// start from oldest to be able sub cob
for (int i = bucketed_data.size() - 4; i >= 0; i--) {
// check if data already exists
long bgTime = bucketed_data.get(i).timeIndex;
long bgTime = bucketed_data.get(i).date;
bgTime = roundUpTime(bgTime);
AutosensData existing;
@ -350,8 +349,8 @@ public class IobCobCalculatorPlugin implements PluginBase {
if (bucketed_data == null)
return null;
for (int index = 0; index < bucketed_data.size(); index++) {
if (bucketed_data.get(index).timeIndex < time)
return bucketed_data.get(index).timeIndex;
if (bucketed_data.get(index).date < time)
return bucketed_data.get(index).date;
}
return null;
}

View file

@ -17,7 +17,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.Loop.ScriptReader;
@ -232,7 +232,7 @@ public class DetermineBasalAdapterAMAJS {
mCurrentTemp.add("rate", MainApp.getConfigBuilder().getTempBasalAbsoluteRate());
// as we have non default temps longer than 30 mintues
TempBasal tempBasal = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
TempExBasal tempBasal = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
if(tempBasal != null){
mCurrentTemp.add("minutesrunning", tempBasal.getRealDuration());
}

View file

@ -1,8 +1,5 @@
package info.nightscout.androidaps.plugins.OpenAPSAMA;
import android.os.Parcel;
import android.os.Parcelable;
import com.eclipsesource.v8.V8Object;
import org.json.JSONArray;
@ -102,7 +99,7 @@ public class DetermineBasalResultAMA extends APSResult {
for (int i = 1; i < iob.length(); i ++) {
BgReading bg = new BgReading();
bg.value = iob.getInt(i);
bg.timeIndex = startTime + i * 5 * 60 * 1000L;
bg.date = startTime + i * 5 * 60 * 1000L;
array.add(bg);
}
}
@ -111,7 +108,7 @@ public class DetermineBasalResultAMA extends APSResult {
for (int i = 1; i < iob.length(); i ++) {
BgReading bg = new BgReading();
bg.value = iob.getInt(i);
bg.timeIndex = startTime + i * 5 * 60 * 1000L;
bg.date = startTime + i * 5 * 60 * 1000L;
array.add(bg);
}
}
@ -120,7 +117,7 @@ public class DetermineBasalResultAMA extends APSResult {
for (int i = 1; i < iob.length(); i ++) {
BgReading bg = new BgReading();
bg.value = iob.getInt(i);
bg.timeIndex = startTime + i * 5 * 60 * 1000L;
bg.date = startTime + i * 5 * 60 * 1000L;
array.add(bg);
}
}

View file

@ -66,7 +66,7 @@ import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.db.TempTarget;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
@ -897,7 +897,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
calibrationButton.setVisibility(View.GONE);
}
TempBasal activeTemp = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
TempExBasal activeTemp = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
cancelTempButton.setVisibility(View.VISIBLE);
cancelTempButton.setText(MainApp.instance().getString(R.string.cancel) + "\n" + activeTemp.toStringShort());
@ -1007,7 +1007,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
flag &= ~Paint.STRIKE_THRU_TEXT_FLAG;
bgView.setPaintFlags(flag);
Long agoMsec = new Date().getTime() - lastBG.timeIndex;
Long agoMsec = new Date().getTime() - lastBG.date;
int agoMin = (int) (agoMsec / 60d / 1000d);
timeAgoView.setText(String.format(MainApp.sResources.getString(R.string.minago), agoMin));
@ -1083,7 +1083,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
double lastBaseBasal = 0;
double lastTempBasal = 0;
for (long time = fromTime; time < now; time += 5 * 60 * 1000L) {
TempBasal tb = MainApp.getConfigBuilder().getTempBasal(time);
TempExBasal tb = MainApp.getConfigBuilder().getTempBasal(time);
double baseBasalValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(time)));
double baseLineValue = baseBasalValue;
double tempBasalValue = 0;
@ -1377,7 +1377,7 @@ public class OverviewFragment extends Fragment implements View.OnClickListener,
for (int tx = 0; tx < treatments.size(); tx++) {
Treatment t = treatments.get(tx);
if (t.getTimeIndex() < fromTime || t.getTimeIndex() > now) continue;
if (t.date < fromTime || t.date > now) continue;
t.setYValue(bgReadingsArray);
filteredTreatments.add(t);
}

View file

@ -19,7 +19,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventInitializationChanged;
import info.nightscout.androidaps.events.EventNewBG;
@ -31,7 +31,6 @@ import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.utils.DecimalFormatter;
@ -140,7 +139,7 @@ public class PersistentNotificationPlugin implements PluginBase{
PumpInterface pump = MainApp.getConfigBuilder();
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
TempBasal activeTemp = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
TempExBasal activeTemp = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
line1 += " " + activeTemp.toStringShort();
}

View file

@ -25,7 +25,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange;
@ -35,7 +35,6 @@ import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.ProfileInterface;
import info.nightscout.androidaps.interfaces.PumpDescription;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.Overview.Notification;
@ -671,7 +670,7 @@ public class DanaRPlugin implements PluginBase, PumpInterface, ConstraintsInterf
extended.put("PumpIOB", getDanaRPump().iob);
extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString());
extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount);
TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
TempExBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
if (tb != null) {
extended.put("TempBasalAbsoluteRate", MainApp.getConfigBuilder().getTempBasalAbsoluteRate());
extended.put("TempBasalStart", tb.timeStart.toLocaleString());

View file

@ -273,12 +273,12 @@ public class DanaRHistoryActivity extends Activity {
@Override
public void onBindViewHolder(HistoryViewHolder holder, int position) {
DanaRHistoryRecord record = historyList.get(position);
holder.time.setText(DateUtil.dateAndTimeString(record.getRecordDate()));
holder.value.setText(DecimalFormatter.to2Decimal(record.getRecordValue()));
holder.stringvalue.setText(record.getStringRecordValue());
holder.bolustype.setText(record.getBolusType());
holder.duration.setText(DecimalFormatter.to0Decimal(record.getRecordDuration()));
holder.alarm.setText(record.getRecordAlarm());
holder.time.setText(DateUtil.dateAndTimeString(record.recordDate));
holder.value.setText(DecimalFormatter.to2Decimal(record.recordValue));
holder.stringvalue.setText(record.stringRecordValue);
holder.bolustype.setText(record.bolusType);
holder.duration.setText(DecimalFormatter.to0Decimal(record.recordDuration));
holder.alarm.setText(record.recordAlarm);
switch (showingType) {
case RecordTypes.RECORD_TYPE_ALARM:
holder.time.setVisibility(View.VISIBLE);
@ -303,10 +303,10 @@ public class DanaRHistoryActivity extends Activity {
holder.alarm.setVisibility(View.GONE);
break;
case RecordTypes.RECORD_TYPE_DAILY:
holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + "U");
holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + "U");
holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus() + record.getRecordDailyBasal()) + "U");
holder.time.setText(DateUtil.dateString(record.getRecordDate()));
holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.recordDailyBasal) + "U");
holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus) + "U");
holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus + record.recordDailyBasal) + "U");
holder.time.setText(DateUtil.dateString(record.recordDate));
holder.time.setVisibility(View.VISIBLE);
holder.value.setVisibility(View.GONE);
holder.stringvalue.setVisibility(View.GONE);
@ -318,7 +318,7 @@ public class DanaRHistoryActivity extends Activity {
holder.alarm.setVisibility(View.GONE);
break;
case RecordTypes.RECORD_TYPE_GLUCOSE:
holder.value.setText(NSProfile.toUnitsString(record.getRecordValue(), record.getRecordValue() * Constants.MGDL_TO_MMOLL, profile.getUnits()));
holder.value.setText(NSProfile.toUnitsString(record.recordValue, record.recordValue * Constants.MGDL_TO_MMOLL, profile.getUnits()));
// rest is the same
case RecordTypes.RECORD_TYPE_CARBO:
case RecordTypes.RECORD_TYPE_BASALHOUR:

View file

@ -58,69 +58,69 @@ public class DanaRNSHistorySync {
EventDanaRSyncStatus ev = new EventDanaRSyncStatus();
for (DanaRHistoryRecord record : historyRecords) {
processing++;
if (record.get_id() != null) continue;
//log.debug(record.getBytes());
if (record._id != null) continue;
//log.debug(record.bytes);
JSONObject nsrec = new JSONObject();
ev.message = MainApp.sResources.getString(R.string.uploading) + " " + processing + "/" + records + " "; // TODO: translations
switch (record.getRecordCode()) {
switch (record.recordCode) {
case RecordTypes.RECORD_TYPE_BOLUS:
if ((what & SYNC_BOLUS) == 0) break;
switch (record.getBolusType()) {
switch (record.bolusType) {
case "S":
log.debug("Syncing standard bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put(DANARSIGNATURE, record.getBytes());
log.debug("Syncing standard bolus record " + record.recordValue + "U " + DateUtil.toISOString(record.recordDate));
nsrec.put(DANARSIGNATURE, record.bytes);
nsrec.put("eventType", "Meal Bolus");
nsrec.put("insulin", record.getRecordValue());
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("insulin", record.recordValue);
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
ConfigBuilderPlugin.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_sbolus);
break;
case "E":
if (record.getRecordDuration() > 0) {
log.debug("Syncing extended bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put(DANARSIGNATURE, record.getBytes());
if (record.recordDuration > 0) {
log.debug("Syncing extended bolus record " + record.recordValue + "U " + DateUtil.toISOString(record.recordDate));
nsrec.put(DANARSIGNATURE, record.bytes);
nsrec.put("eventType", "Combo Bolus");
nsrec.put("insulin", 0);
nsrec.put("duration", record.getRecordDuration());
nsrec.put("relative", record.getRecordValue() / record.getRecordDuration() * 60);
nsrec.put("duration", record.recordDuration);
nsrec.put("relative", record.recordValue / record.recordDuration * 60);
nsrec.put("splitNow", 0);
nsrec.put("splitExt", 100);
cal.setTimeInMillis(record.getRecordDate());
cal.add(Calendar.MINUTE, -1 * record.getRecordDuration());
cal.setTimeInMillis(record.recordDate);
cal.add(Calendar.MINUTE, -1 * record.recordDuration);
nsrec.put("created_at", DateUtil.toISOString(cal.getTime()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
ConfigBuilderPlugin.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_ebolus);
} else {
log.debug("NOT Syncing extended bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate()) + " zero duration");
log.debug("NOT Syncing extended bolus record " + record.recordValue + "U " + DateUtil.toISOString(record.recordDate) + " zero duration");
}
break;
case "DS":
log.debug("Syncing dual(S) bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put(DANARSIGNATURE, record.getBytes());
log.debug("Syncing dual(S) bolus record " + record.recordValue + "U " + DateUtil.toISOString(record.recordDate));
nsrec.put(DANARSIGNATURE, record.bytes);
nsrec.put("eventType", "Combo Bolus");
nsrec.put("insulin", record.getRecordValue());
nsrec.put("insulin", record.recordValue);
nsrec.put("splitNow", 100);
nsrec.put("splitExt", 0);
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
ConfigBuilderPlugin.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_dsbolus);
break;
case "DE":
log.debug("Syncing dual(E) bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put(DANARSIGNATURE, record.getBytes());
log.debug("Syncing dual(E) bolus record " + record.recordValue + "U " + DateUtil.toISOString(record.recordDate));
nsrec.put(DANARSIGNATURE, record.bytes);
nsrec.put("eventType", "Combo Bolus");
nsrec.put("duration", record.getRecordDuration());
nsrec.put("relative", record.getRecordValue() / record.getRecordDuration() * 60);
nsrec.put("duration", record.recordDuration);
nsrec.put("relative", record.recordValue / record.recordDuration * 60);
nsrec.put("splitNow", 0);
nsrec.put("splitExt", 100);
cal.setTimeInMillis(record.getRecordDate());
cal.add(Calendar.MINUTE, -1 * record.getRecordDuration());
cal.setTimeInMillis(record.recordDate);
cal.add(Calendar.MINUTE, -1 * record.recordDuration);
nsrec.put("created_at", DateUtil.toISOString(cal.getTime()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
ConfigBuilderPlugin.uploadCareportalEntryToNS(nsrec);
@ -134,11 +134,11 @@ public class DanaRNSHistorySync {
break;
case RecordTypes.RECORD_TYPE_ERROR:
if ((what & SYNC_ERROR) == 0) break;
log.debug("Syncing error record " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put(DANARSIGNATURE, record.getBytes());
log.debug("Syncing error record " + DateUtil.toISOString(record.recordDate));
nsrec.put(DANARSIGNATURE, record.bytes);
nsrec.put("eventType", "Note");
nsrec.put("notes", "Error");
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
ConfigBuilderPlugin.uploadCareportalEntryToNS(nsrec);
uploaded++;
@ -146,11 +146,11 @@ public class DanaRNSHistorySync {
break;
case RecordTypes.RECORD_TYPE_REFILL:
if ((what & SYNC_REFILL) == 0) break;
log.debug("Syncing refill record " + record.getRecordValue() + " " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put(DANARSIGNATURE, record.getBytes());
log.debug("Syncing refill record " + record.recordValue + " " + DateUtil.toISOString(record.recordDate));
nsrec.put(DANARSIGNATURE, record.bytes);
nsrec.put("eventType", "Insulin Change");
nsrec.put("notes", "Refill " + record.getRecordValue() + "U");
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("notes", "Refill " + record.recordValue + "U");
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
ConfigBuilderPlugin.uploadCareportalEntryToNS(nsrec);
uploaded++;
@ -158,28 +158,28 @@ public class DanaRNSHistorySync {
break;
case RecordTypes.RECORD_TYPE_BASALHOUR:
if ((what & SYNC_BASALHOURS) == 0) break;
log.debug("Syncing basal hour record " + record.getRecordValue() + " " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put(DANARSIGNATURE, record.getBytes());
log.debug("Syncing basal hour record " + record.recordValue + " " + DateUtil.toISOString(record.recordDate));
nsrec.put(DANARSIGNATURE, record.bytes);
nsrec.put("eventType", "Temp Basal");
nsrec.put("absolute", record.getRecordValue());
nsrec.put("absolute", record.recordValue);
nsrec.put("duration", 60);
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
ConfigBuilderPlugin.uploadCareportalEntryToNS(nsrec);
uploaded++;
ev.message += MainApp.sResources.getString(R.string.danar_basalhour);
break;
case RecordTypes.RECORD_TYPE_TB:
//log.debug("Ignoring TB record " + record.getBytes() + " " + DateUtil.toISOString(record.getRecordDate()));
//log.debug("Ignoring TB record " + record.bytes + " " + DateUtil.toISOString(record.recordDate));
break;
case RecordTypes.RECORD_TYPE_GLUCOSE:
if ((what & SYNC_GLUCOSE) == 0) break;
log.debug("Syncing glucose record " + record.getRecordValue() + " " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put(DANARSIGNATURE, record.getBytes());
log.debug("Syncing glucose record " + record.recordValue + " " + DateUtil.toISOString(record.recordDate));
nsrec.put(DANARSIGNATURE, record.bytes);
nsrec.put("eventType", "BG Check");
nsrec.put("glucose", NSProfile.fromMgdlToUnits(record.getRecordValue(), profile.getUnits()));
nsrec.put("glucose", NSProfile.fromMgdlToUnits(record.recordValue, profile.getUnits()));
nsrec.put("glucoseType", "Finger");
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
ConfigBuilderPlugin.uploadCareportalEntryToNS(nsrec);
uploaded++;
@ -187,11 +187,11 @@ public class DanaRNSHistorySync {
break;
case RecordTypes.RECORD_TYPE_CARBO:
if ((what & SYNC_CARBO) == 0) break;
log.debug("Syncing carbo record " + record.getRecordValue() + "g " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put(DANARSIGNATURE, record.getBytes());
log.debug("Syncing carbo record " + record.recordValue + "g " + DateUtil.toISOString(record.recordDate));
nsrec.put(DANARSIGNATURE, record.bytes);
nsrec.put("eventType", "Meal Bolus");
nsrec.put("carbs", record.getRecordValue());
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("carbs", record.recordValue);
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
ConfigBuilderPlugin.uploadCareportalEntryToNS(nsrec);
uploaded++;
@ -199,11 +199,11 @@ public class DanaRNSHistorySync {
break;
case RecordTypes.RECORD_TYPE_ALARM:
if ((what & SYNC_ALARM) == 0) break;
log.debug("Syncing alarm record " + record.getRecordAlarm() + " " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put(DANARSIGNATURE, record.getBytes());
log.debug("Syncing alarm record " + record.recordAlarm + " " + DateUtil.toISOString(record.recordDate));
nsrec.put(DANARSIGNATURE, record.bytes);
nsrec.put("eventType", "Note");
nsrec.put("notes", "Alarm: " + record.getRecordAlarm());
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("notes", "Alarm: " + record.recordAlarm);
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
ConfigBuilderPlugin.uploadCareportalEntryToNS(nsrec);
uploaded++;

View file

@ -379,7 +379,7 @@ public class DanaRStatsActivity extends Activity {
double weighted07 = 0d;
for (DanaRHistoryRecord record : historyList) {
double tdd = record.getRecordDailyBolus() + record.getRecordDailyBasal();
double tdd = record.recordDailyBolus + record.recordDailyBasal;
// Create the table row
TableRow tr = new TableRow(DanaRStatsActivity.this);
@ -392,19 +392,19 @@ public class DanaRStatsActivity extends Activity {
// Here create the TextView dynamically
TextView labelDATE = new TextView(DanaRStatsActivity.this);
labelDATE.setId(200 + i);
labelDATE.setText(df.format(new Date(record.getRecordDate())));
labelDATE.setText(df.format(new Date(record.recordDate)));
labelDATE.setTextColor(Color.WHITE);
tr.addView(labelDATE);
TextView labelBASAL = new TextView(DanaRStatsActivity.this);
labelBASAL.setId(300 + i);
labelBASAL.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + " U");
labelBASAL.setText(DecimalFormatter.to2Decimal(record.recordDailyBasal) + " U");
labelBASAL.setTextColor(Color.WHITE);
tr.addView(labelBASAL);
TextView labelBOLUS = new TextView(DanaRStatsActivity.this);
labelBOLUS.setId(400 + i);
labelBOLUS.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + " U");
labelBOLUS.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus) + " U");
labelBOLUS.setTextColor(Color.WHITE);
tr.addView(labelBOLUS);
@ -461,7 +461,7 @@ public class DanaRStatsActivity extends Activity {
TableLayout.LayoutParams.WRAP_CONTENT));
}
if (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).getRecordDate())).equals(df.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24))))) {
if (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).recordDate)).equals(df.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24))))) {
statsMessage.setVisibility(View.VISIBLE);
statsMessage.setText(getString(R.string.danar_stats_olddata_Message));
@ -474,7 +474,7 @@ public class DanaRStatsActivity extends Activity {
i = 0;
for (DanaRHistoryRecord record : historyList) {
double tdd = record.getRecordDailyBolus() + record.getRecordDailyBasal();
double tdd = record.recordDailyBolus + record.recordDailyBasal;
if (i == 0) {
weighted03 = tdd;
weighted05 = tdd;

View file

@ -39,82 +39,82 @@ public class MsgHistoryAll extends MessageBase {
DanaRHistoryRecord danaRHistoryRecord = new DanaRHistoryRecord();
danaRHistoryRecord.setRecordCode(recordCode);
danaRHistoryRecord.recordCode = recordCode;
danaRHistoryRecord.setBytes(bytes);
String messageType = "";
switch (recordCode) {
case RecordTypes.RECORD_TYPE_BOLUS:
danaRHistoryRecord.setRecordDate(datetime);
danaRHistoryRecord.recordDate = datetime.getTime();
switch (0xF0 & paramByte8) {
case 0xA0:
danaRHistoryRecord.setBolusType("DS");
danaRHistoryRecord.bolusType = "DS";
messageType += "DS bolus";
break;
case 0xC0:
danaRHistoryRecord.setBolusType("E");
danaRHistoryRecord.bolusType = "E";
messageType += "E bolus";
break;
case 0x80:
danaRHistoryRecord.setBolusType("S");
danaRHistoryRecord.bolusType = "S";
messageType += "S bolus";
break;
case 0x90:
danaRHistoryRecord.setBolusType("DE");
danaRHistoryRecord.bolusType = "DE";
messageType += "DE bolus";
break;
default:
danaRHistoryRecord.setBolusType("None");
danaRHistoryRecord.bolusType = "None";
break;
}
danaRHistoryRecord.setRecordDuration(((int) paramByte8 & 0x0F) * 60 + (int) paramByte7);
danaRHistoryRecord.setRecordValue(value * 0.01);
danaRHistoryRecord.recordDuration = ((int) paramByte8 & 0x0F) * 60 + (int) paramByte7;
danaRHistoryRecord.recordValue = value * 0.01;
break;
case RecordTypes.RECORD_TYPE_DAILY:
messageType += "dailyinsulin";
danaRHistoryRecord.setRecordDate(date);
danaRHistoryRecord.setRecordDailyBasal(dailyBasal);
danaRHistoryRecord.setRecordDailyBolus(dailyBolus);
danaRHistoryRecord.recordDate = date.getTime();
danaRHistoryRecord.recordDailyBasal = dailyBasal;
danaRHistoryRecord.recordDailyBolus = dailyBolus;
break;
case RecordTypes.RECORD_TYPE_PRIME:
messageType += "prime";
danaRHistoryRecord.setRecordDate(datetimewihtsec);
danaRHistoryRecord.setRecordValue(value * 0.01);
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordValue = value * 0.01;
break;
case RecordTypes.RECORD_TYPE_ERROR:
messageType += "error";
danaRHistoryRecord.setRecordDate(datetimewihtsec);
danaRHistoryRecord.setRecordValue(value * 0.01);
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordValue = value * 0.01;
break;
case RecordTypes.RECORD_TYPE_REFILL:
messageType += "refill";
danaRHistoryRecord.setRecordDate(datetimewihtsec);
danaRHistoryRecord.setRecordValue(value * 0.01);
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordValue = value * 0.01;
break;
case RecordTypes.RECORD_TYPE_BASALHOUR:
messageType += "basal hour";
danaRHistoryRecord.setRecordDate(datetimewihtsec);
danaRHistoryRecord.setRecordValue(value * 0.01);
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordValue = value * 0.01;
break;
case RecordTypes.RECORD_TYPE_TB:
messageType += "tb";
danaRHistoryRecord.setRecordDate(datetimewihtsec);
danaRHistoryRecord.setRecordValue(value * 0.01);
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordValue = value * 0.01;
break;
case RecordTypes.RECORD_TYPE_GLUCOSE:
messageType += "glucose";
danaRHistoryRecord.setRecordDate(datetimewihtsec);
danaRHistoryRecord.setRecordValue(value);
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordValue = value;
break;
case RecordTypes.RECORD_TYPE_CARBO:
messageType += "carbo";
danaRHistoryRecord.setRecordDate(datetimewihtsec);
danaRHistoryRecord.setRecordValue(value);
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
danaRHistoryRecord.recordValue = value;
break;
case RecordTypes.RECORD_TYPE_ALARM:
messageType += "alarm";
danaRHistoryRecord.setRecordDate(datetimewihtsec);
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
String strAlarm = "None";
switch ((int) paramByte8) {
case 67:
@ -130,16 +130,16 @@ public class MsgHistoryAll extends MessageBase {
strAlarm = "Shutdown";
break;
}
danaRHistoryRecord.setRecordAlarm(strAlarm);
danaRHistoryRecord.setRecordValue(value * 0.01);
danaRHistoryRecord.recordAlarm = strAlarm;
danaRHistoryRecord.recordValue = value * 0.01;
break;
case RecordTypes.RECORD_TYPE_SUSPEND:
messageType += "suspend";
danaRHistoryRecord.setRecordDate(datetimewihtsec);
danaRHistoryRecord.recordDate = datetimewihtsec.getTime();
String strRecordValue = "Off";
if ((int) paramByte8 == 79)
strRecordValue = "On";
danaRHistoryRecord.setStringRecordValue(strRecordValue);
danaRHistoryRecord.stringRecordValue = strRecordValue;
break;
}
@ -150,7 +150,7 @@ public class MsgHistoryAll extends MessageBase {
log.error(e.getMessage(), e);
}
ev.message = DateUtil.dateAndTimeString(danaRHistoryRecord.getRecordDate());
ev.message = DateUtil.dateAndTimeString(danaRHistoryRecord.recordDate);
ev.message += " " + messageType;
MainApp.bus().post(ev);

View file

@ -9,7 +9,7 @@ import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
@ -69,13 +69,13 @@ public class MsgStatusBolusExtended extends MessageBase {
long now = new Date().getTime();
if (treatmentsInterface.isExtendedBoluslInProgress()) {
TempBasal extendedBolus = treatmentsInterface.getExtendedBolus(new Date().getTime());
TempExBasal extendedBolus = treatmentsInterface.getExtendedBolus(new Date().getTime());
if (pump.isExtendedInProgress) {
if (extendedBolus.absolute != pump.extendedBolusAbsoluteRate) {
// Close current extended
treatmentsInterface.extendedBolusStop(now);
// Create new
TempBasal newExtended = new TempBasal();
TempExBasal newExtended = new TempExBasal();
newExtended.timeStart = new Date(now);
newExtended.absolute = pump.extendedBolusAbsoluteRate;
newExtended.isAbsolute = true;
@ -90,7 +90,7 @@ public class MsgStatusBolusExtended extends MessageBase {
} else {
if (pump.isExtendedInProgress) {
// Create new
TempBasal newExtended = new TempBasal();
TempExBasal newExtended = new TempExBasal();
newExtended.timeStart = new Date(now);
newExtended.absolute = pump.extendedBolusAbsoluteRate;
newExtended.isAbsolute = true;

View file

@ -9,7 +9,7 @@ import java.util.Date;
import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.PumpDanaR.DanaRPump;
@ -63,13 +63,13 @@ public class MsgStatusTempBasal extends MessageBase {
long now = new Date().getTime();
if (treatmentsInterface.isTempBasalInProgress()) {
TempBasal tempBasal = treatmentsInterface.getTempBasal(new Date().getTime());
TempExBasal tempBasal = treatmentsInterface.getTempBasal(new Date().getTime());
if (danaRPump.isTempBasalInProgress) {
if (tempBasal.percent != danaRPump.tempBasalPercent) {
// Close current temp basal
treatmentsInterface.tempBasalStop(now);
// Create new
TempBasal newTempBasal = new TempBasal();
TempExBasal newTempBasal = new TempExBasal();
newTempBasal.timeStart = new Date(now);
newTempBasal.percent = danaRPump.tempBasalPercent;
newTempBasal.isAbsolute = false;
@ -84,7 +84,7 @@ public class MsgStatusTempBasal extends MessageBase {
} else {
if (danaRPump.isTempBasalInProgress) {
// Create new
TempBasal newTempBasal = new TempBasal();
TempExBasal newTempBasal = new TempExBasal();
newTempBasal.timeStart = new Date(now);
newTempBasal.percent = danaRPump.tempBasalPercent;
newTempBasal.isAbsolute = false;

View file

@ -25,7 +25,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.events.EventPreferenceChange;
@ -306,8 +306,8 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
return pump.currentBasal;
}
public TempBasal getTempBasal(long time) {
TempBasal temp = MainApp.getConfigBuilder().getTempBasal(time);
public TempExBasal getTempBasal(long time) {
TempExBasal temp = MainApp.getConfigBuilder().getTempBasal(time);
if (temp != null) return temp;
if (useExtendedBoluses)
return MainApp.getConfigBuilder().getExtendedBolus(time);
@ -681,7 +681,7 @@ public class DanaRKoreanPlugin implements PluginBase, PumpInterface, Constraints
extended.put("PumpIOB", pump.iob);
// extended.put("LastBolus", pump.lastBolusTime.toLocaleString());
// extended.put("LastBolusAmount", pump.lastBolusAmount);
TempBasal tb = getTempBasal(new Date().getTime());
TempExBasal tb = getTempBasal(new Date().getTime());
if (tb != null) {
extended.put("TempBasalAbsoluteRate", MainApp.getConfigBuilder().getTempBasalAbsoluteRate());
extended.put("TempBasalStart", tb.timeStart.toLocaleString());

View file

@ -272,12 +272,12 @@ public class DanaRHistoryActivity extends Activity {
@Override
public void onBindViewHolder(HistoryViewHolder holder, int position) {
DanaRHistoryRecord record = historyList.get(position);
holder.time.setText(DateUtil.dateAndTimeString(record.getRecordDate()));
holder.value.setText(DecimalFormatter.to2Decimal(record.getRecordValue()));
holder.stringvalue.setText(record.getStringRecordValue());
holder.bolustype.setText(record.getBolusType());
holder.duration.setText(DecimalFormatter.to0Decimal(record.getRecordDuration()));
holder.alarm.setText(record.getRecordAlarm());
holder.time.setText(DateUtil.dateAndTimeString(record.recordDate));
holder.value.setText(DecimalFormatter.to2Decimal(record.recordValue));
holder.stringvalue.setText(record.stringRecordValue);
holder.bolustype.setText(record.bolusType);
holder.duration.setText(DecimalFormatter.to0Decimal(record.recordDuration));
holder.alarm.setText(record.recordAlarm);
switch (showingType) {
case RecordTypes.RECORD_TYPE_ALARM:
holder.time.setVisibility(View.VISIBLE);
@ -302,10 +302,10 @@ public class DanaRHistoryActivity extends Activity {
holder.alarm.setVisibility(View.GONE);
break;
case RecordTypes.RECORD_TYPE_DAILY:
holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + "U");
holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + "U");
holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus() + record.getRecordDailyBasal()) + "U");
holder.time.setText(DateUtil.dateString(record.getRecordDate()));
holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.recordDailyBasal) + "U");
holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus) + "U");
holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus + record.recordDailyBasal) + "U");
holder.time.setText(DateUtil.dateString(record.recordDate));
holder.time.setVisibility(View.VISIBLE);
holder.value.setVisibility(View.GONE);
holder.stringvalue.setVisibility(View.GONE);
@ -317,7 +317,7 @@ public class DanaRHistoryActivity extends Activity {
holder.alarm.setVisibility(View.GONE);
break;
case RecordTypes.RECORD_TYPE_GLUCOSE:
holder.value.setText(NSProfile.toUnitsString(record.getRecordValue(), record.getRecordValue() * Constants.MGDL_TO_MMOLL, profile.getUnits()));
holder.value.setText(NSProfile.toUnitsString(record.recordValue, record.recordValue * Constants.MGDL_TO_MMOLL, profile.getUnits()));
// rest is the same
case RecordTypes.RECORD_TYPE_CARBO:
case RecordTypes.RECORD_TYPE_BASALHOUR:

View file

@ -379,7 +379,7 @@ public class DanaRStatsActivity extends Activity {
double weighted07 = 0d;
for (DanaRHistoryRecord record : historyList) {
double tdd = record.getRecordDailyBolus() + record.getRecordDailyBasal();
double tdd = record.recordDailyBolus + record.recordDailyBasal;
// Create the table row
TableRow tr = new TableRow(DanaRStatsActivity.this);
@ -392,19 +392,19 @@ public class DanaRStatsActivity extends Activity {
// Here create the TextView dynamically
TextView labelDATE = new TextView(DanaRStatsActivity.this);
labelDATE.setId(200 + i);
labelDATE.setText(df.format(new Date(record.getRecordDate())));
labelDATE.setText(df.format(new Date(record.recordDate)));
labelDATE.setTextColor(Color.WHITE);
tr.addView(labelDATE);
TextView labelBASAL = new TextView(DanaRStatsActivity.this);
labelBASAL.setId(300 + i);
labelBASAL.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + " U");
labelBASAL.setText(DecimalFormatter.to2Decimal(record.recordDailyBasal) + " U");
labelBASAL.setTextColor(Color.WHITE);
tr.addView(labelBASAL);
TextView labelBOLUS = new TextView(DanaRStatsActivity.this);
labelBOLUS.setId(400 + i);
labelBOLUS.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + " U");
labelBOLUS.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus) + " U");
labelBOLUS.setTextColor(Color.WHITE);
tr.addView(labelBOLUS);
@ -461,7 +461,7 @@ public class DanaRStatsActivity extends Activity {
TableLayout.LayoutParams.WRAP_CONTENT));
}
if (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).getRecordDate())).equals(df.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24))))) {
if (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).recordDate)).equals(df.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24))))) {
statsMessage.setVisibility(View.VISIBLE);
statsMessage.setText(getString(R.string.danar_stats_olddata_Message));
@ -474,7 +474,7 @@ public class DanaRStatsActivity extends Activity {
i = 0;
for (DanaRHistoryRecord record : historyList) {
double tdd = record.getRecordDailyBolus() + record.getRecordDailyBasal();
double tdd = record.recordDailyBolus + record.recordDailyBasal;
if (i == 0) {
weighted03 = tdd;
weighted05 = tdd;

View file

@ -25,7 +25,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventAppExit;
import info.nightscout.androidaps.interfaces.ConstraintsInterface;
@ -591,7 +591,7 @@ public class DanaRv2Plugin implements PluginBase, PumpInterface, ConstraintsInte
extended.put("PumpIOB", getDanaRPump().iob);
extended.put("LastBolus", getDanaRPump().lastBolusTime.toLocaleString());
extended.put("LastBolusAmount", getDanaRPump().lastBolusAmount);
TempBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
TempExBasal tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime());
if (tb != null) {
extended.put("TempBasalAbsoluteRate", MainApp.getConfigBuilder().getTempBasalAbsoluteRate());
extended.put("TempBasalStart", tb.timeStart.toLocaleString());

View file

@ -273,12 +273,12 @@ public class DanaRHistoryActivity extends Activity {
@Override
public void onBindViewHolder(HistoryViewHolder holder, int position) {
DanaRHistoryRecord record = historyList.get(position);
holder.time.setText(DateUtil.dateAndTimeString(record.getRecordDate()));
holder.value.setText(DecimalFormatter.to2Decimal(record.getRecordValue()));
holder.stringvalue.setText(record.getStringRecordValue());
holder.bolustype.setText(record.getBolusType());
holder.duration.setText(DecimalFormatter.to0Decimal(record.getRecordDuration()));
holder.alarm.setText(record.getRecordAlarm());
holder.time.setText(DateUtil.dateAndTimeString(record.recordDate));
holder.value.setText(DecimalFormatter.to2Decimal(record.recordValue));
holder.stringvalue.setText(record.stringRecordValue);
holder.bolustype.setText(record.bolusType);
holder.duration.setText(DecimalFormatter.to0Decimal(record.recordDuration));
holder.alarm.setText(record.recordAlarm);
switch (showingType) {
case RecordTypes.RECORD_TYPE_ALARM:
holder.time.setVisibility(View.VISIBLE);
@ -303,10 +303,10 @@ public class DanaRHistoryActivity extends Activity {
holder.alarm.setVisibility(View.GONE);
break;
case RecordTypes.RECORD_TYPE_DAILY:
holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + "U");
holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + "U");
holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus() + record.getRecordDailyBasal()) + "U");
holder.time.setText(DateUtil.dateString(record.getRecordDate()));
holder.dailybasal.setText(DecimalFormatter.to2Decimal(record.recordDailyBasal) + "U");
holder.dailybolus.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus) + "U");
holder.dailytotal.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus + record.recordDailyBasal) + "U");
holder.time.setText(DateUtil.dateString(record.recordDate));
holder.time.setVisibility(View.VISIBLE);
holder.value.setVisibility(View.GONE);
holder.stringvalue.setVisibility(View.GONE);
@ -318,7 +318,7 @@ public class DanaRHistoryActivity extends Activity {
holder.alarm.setVisibility(View.GONE);
break;
case RecordTypes.RECORD_TYPE_GLUCOSE:
holder.value.setText(NSProfile.toUnitsString(record.getRecordValue(), record.getRecordValue() * Constants.MGDL_TO_MMOLL, profile.getUnits()));
holder.value.setText(NSProfile.toUnitsString(record.recordValue, record.recordValue * Constants.MGDL_TO_MMOLL, profile.getUnits()));
// rest is the same
case RecordTypes.RECORD_TYPE_CARBO:
case RecordTypes.RECORD_TYPE_BASALHOUR:

View file

@ -379,7 +379,7 @@ public class DanaRStatsActivity extends Activity {
double weighted07 = 0d;
for (DanaRHistoryRecord record : historyList) {
double tdd = record.getRecordDailyBolus() + record.getRecordDailyBasal();
double tdd = record.recordDailyBolus + record.recordDailyBasal;
// Create the table row
TableRow tr = new TableRow(DanaRStatsActivity.this);
@ -392,19 +392,19 @@ public class DanaRStatsActivity extends Activity {
// Here create the TextView dynamically
TextView labelDATE = new TextView(DanaRStatsActivity.this);
labelDATE.setId(200 + i);
labelDATE.setText(df.format(new Date(record.getRecordDate())));
labelDATE.setText(df.format(new Date(record.recordDate)));
labelDATE.setTextColor(Color.WHITE);
tr.addView(labelDATE);
TextView labelBASAL = new TextView(DanaRStatsActivity.this);
labelBASAL.setId(300 + i);
labelBASAL.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBasal()) + " U");
labelBASAL.setText(DecimalFormatter.to2Decimal(record.recordDailyBasal) + " U");
labelBASAL.setTextColor(Color.WHITE);
tr.addView(labelBASAL);
TextView labelBOLUS = new TextView(DanaRStatsActivity.this);
labelBOLUS.setId(400 + i);
labelBOLUS.setText(DecimalFormatter.to2Decimal(record.getRecordDailyBolus()) + " U");
labelBOLUS.setText(DecimalFormatter.to2Decimal(record.recordDailyBolus) + " U");
labelBOLUS.setTextColor(Color.WHITE);
tr.addView(labelBOLUS);
@ -461,7 +461,7 @@ public class DanaRStatsActivity extends Activity {
TableLayout.LayoutParams.WRAP_CONTENT));
}
if (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).getRecordDate())).equals(df.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24))))) {
if (historyList.size() < 3 || !(df.format(new Date(historyList.get(0).recordDate)).equals(df.format(new Date(System.currentTimeMillis() - 1000 * 60 * 60 * 24))))) {
statsMessage.setVisibility(View.VISIBLE);
statsMessage.setText(getString(R.string.danar_stats_olddata_Message));
@ -474,7 +474,7 @@ public class DanaRStatsActivity extends Activity {
i = 0;
for (DanaRHistoryRecord record : historyList) {
double tdd = record.getRecordDailyBolus() + record.getRecordDailyBasal();
double tdd = record.recordDailyBolus + record.recordDailyBasal;
if (i == 0) {
weighted03 = tdd;
weighted05 = tdd;

View file

@ -14,7 +14,6 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpDescription;

View file

@ -9,7 +9,6 @@ import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.Date;
import info.nightscout.androidaps.BuildConfig;
@ -17,7 +16,7 @@ import info.nightscout.androidaps.Config;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.PumpEnactResult;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpDescription;
@ -240,7 +239,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
PumpEnactResult result = cancelTempBasal();
if (!result.success)
return result;
TempBasal tempBasal = new TempBasal();
TempExBasal tempBasal = new TempExBasal();
tempBasal.timeStart = new Date();
tempBasal.isAbsolute = true;
tempBasal.absolute = absoluteRate;
@ -268,7 +267,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
if (!result.success)
return result;
}
TempBasal tempBasal = new TempBasal();
TempExBasal tempBasal = new TempExBasal();
tempBasal.timeStart = new Date();
tempBasal.isAbsolute = false;
tempBasal.percent = percent;
@ -294,7 +293,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
PumpEnactResult result = cancelExtendedBolus();
if (!result.success)
return result;
TempBasal extendedBolus = new TempBasal();
TempExBasal extendedBolus = new TempExBasal();
extendedBolus.timeStart = new Date();
extendedBolus.isExtended = true;
extendedBolus.absolute = insulin * 60d / durationInMinutes;
@ -368,7 +367,7 @@ public class VirtualPumpPlugin implements PluginBase, PumpInterface {
try {
extended.put("ActiveProfile", MainApp.getConfigBuilder().getActiveProfile().getProfile().getActiveProfile());
} catch (Exception e) {}
TempBasal tb;
TempExBasal tb;
if ((tb = MainApp.getConfigBuilder().getTempBasal(new Date().getTime())) != null) {
status.put("tempbasalpct", tb.percent);
status.put("tempbasalstart", DateUtil.toISOString(tb.timeStart));

View file

@ -246,7 +246,7 @@ public class SmsCommunicatorPlugin implements PluginBase {
if (actualBG != null) {
reply = MainApp.sResources.getString(R.string.sms_actualbg) + " " + actualBG.valueToUnitsToString(units) + ", ";
} else if (lastBG != null) {
Long agoMsec = new Date().getTime() - lastBG.timeIndex;
Long agoMsec = new Date().getTime() - lastBG.date;
int agoMin = (int) (agoMsec / 60d / 1000d);
reply = MainApp.sResources.getString(R.string.sms_lastbg) + " " + lastBG.valueToUnitsToString(units) + " " + String.format(MainApp.sResources.getString(R.string.sms_minago), agoMin) + ", ";
}

View file

@ -77,14 +77,14 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
if (profile == null) return;
TempTarget tempTarget = tempTargetList.get(position);
if (tempTarget.duration != 0) {
holder.date.setText(DateUtil.dateAndTimeString(tempTarget.timeStart) + " - " + DateUtil.timeString(tempTargetList.get(position).getPlannedTimeEnd()));
holder.duration.setText(DecimalFormatter.to0Decimal(tempTarget.duration) + " min");
if (tempTarget.durationInMinutes != 0) {
holder.date.setText(DateUtil.dateAndTimeString(tempTarget.date) + " - " + DateUtil.timeString(tempTargetList.get(position).originalEnd()));
holder.duration.setText(DecimalFormatter.to0Decimal(tempTarget.durationInMinutes) + " min");
holder.low.setText(tempTarget.lowValueToUnitsToString(profile.getUnits()));
holder.high.setText(tempTarget.highValueToUnitsToString(profile.getUnits()));
holder.reason.setText(tempTarget.reason);
} else {
holder.date.setText(DateUtil.dateAndTimeString(tempTarget.timeStart));
holder.date.setText(DateUtil.dateAndTimeString(tempTarget.date));
holder.duration.setText(R.string.cancel);
holder.low.setText("");
holder.high.setText("");
@ -145,7 +145,7 @@ public class TempTargetRangeFragment extends Fragment implements View.OnClickLis
case R.id.temptargetrange_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(tempTarget.timeStart));
builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(tempTarget.date));
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
final String _id = tempTarget._id;

View file

@ -114,10 +114,10 @@ public class TempTargetRangePlugin implements PluginBase {
public TempTarget getTempTargetInProgress(long time) {
for (int i = 0; i < tempTargets.size(); i++) {
// a zero-duration temp target will cancel all prior targets
if (tempTargets.get(i).duration == 0) return null;
if (tempTargets.get(i).durationInMinutes == 0) return null;
if (tempTargets.get(i).timeStart.getTime() > time) continue;
if (tempTargets.get(i).getPlannedTimeEnd().getTime() >= time) return tempTargets.get(i);
if (tempTargets.get(i).date > time) continue;
if (tempTargets.get(i).date >= time) return tempTargets.get(i);
}
return null;
}

View file

@ -2,13 +2,11 @@ package info.nightscout.androidaps.plugins.Treatments;
import android.support.annotation.Nullable;
import com.j256.ormlite.dao.Dao;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
@ -22,13 +20,12 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
@ -48,8 +45,8 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
public static IobTotal lastTempBasalsCalculation;
public static List<Treatment> treatments;
private static List<TempBasal> tempBasals;
private static List<TempBasal> extendedBoluses;
private static List<TempExBasal> tempBasals;
private static List<TempExBasal> extendedBoluses;
private static boolean useExtendedBoluses = false;
@ -156,10 +153,10 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
checkForExpired(extendedBoluses);
}
private static void checkForExpired(List<TempBasal> list) {
private static void checkForExpired(List<TempExBasal> list) {
long now = new Date().getTime();
for (int position = list.size() - 1; position >= 0; position--) {
TempBasal t = list.get(position);
TempExBasal t = list.get(position);
boolean update = false;
if (t.timeEnd == null && t.getPlannedTimeEnd() < now) {
t.timeEnd = new Date(t.getPlannedTimeEnd());
@ -209,7 +206,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
for (Integer pos = 0; pos < treatments.size(); pos++) {
Treatment t = treatments.get(pos);
if (t.created_at.getTime() > time) continue;
if (t.date > time) continue;
Iob tIOB = t.iobCalc(time, dia);
total.iob += tIOB.iobContrib;
total.activity += tIOB.activityContrib;
@ -237,7 +234,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
long dia_ago = now - (new Double(1.5d * profile.getDia() * 60 * 60 * 1000l)).longValue();
for (Treatment treatment : treatments) {
long t = treatment.created_at.getTime();
long t = treatment.date;
if (t > dia_ago && t <= now) {
if (treatment.carbs >= 1) {
result.carbs += treatment.carbs;
@ -265,7 +262,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
List<Treatment> in5minback = new ArrayList<>();
for (Integer pos = 0; pos < treatments.size(); pos++) {
Treatment t = treatments.get(pos);
if (t.created_at.getTime() <= time && t.created_at.getTime() > time - 5 * 60 * 1000)
if (t.date <= time && t.date > time - 5 * 60 * 1000)
in5minback.add(t);
}
return in5minback;
@ -288,7 +285,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
checkForExpired(extendedBoluses);
IobTotal total = new IobTotal(time);
for (Integer pos = 0; pos < tempBasals.size(); pos++) {
TempBasal t = tempBasals.get(pos);
TempExBasal t = tempBasals.get(pos);
if (t.timeStart.getTime() > time) continue;
IobTotal calc = t.iobCalc(time);
//log.debug("BasalIOB " + new Date(time) + " >>> " + calc.basaliob);
@ -296,7 +293,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
}
if (useExtendedBoluses) {
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
TempBasal t = extendedBoluses.get(pos);
TempExBasal t = extendedBoluses.get(pos);
if (t.timeStart.getTime() > time) continue;
IobTotal calc = t.iobCalc(time);
total.plus(calc);
@ -322,9 +319,9 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
}
@Nullable
public TempBasal getRealTempBasal(long time) {
public TempExBasal getRealTempBasal(long time) {
checkForExpired(tempBasals);
for (TempBasal t : tempBasals) {
for (TempExBasal t : tempBasals) {
if (t.isInProgress(time)) return t;
}
return null;
@ -332,7 +329,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Nullable
@Override
public TempBasal getTempBasal(long time) {
public TempExBasal getTempBasal(long time) {
if (isRealTempBasalInProgress())
return getRealTempBasal(time);
if (isExtendedBoluslInProgress() && useExtendedBoluses)
@ -347,22 +344,22 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
@Nullable
@Override
public TempBasal getExtendedBolus(long time) {
public TempExBasal getExtendedBolus(long time) {
checkForExpired(extendedBoluses);
for (TempBasal t : extendedBoluses) {
for (TempExBasal t : extendedBoluses) {
if (t.isInProgress(time)) return t;
}
return null;
}
@Override
public void extendedBolusStart(TempBasal extendedBolus) {
public void extendedBolusStart(TempExBasal extendedBolus) {
MainApp.getDbHelper().create(extendedBolus);
}
@Override
public void extendedBolusStop(long time) {
TempBasal extendedBolus = getExtendedBolus(time);
TempExBasal extendedBolus = getExtendedBolus(time);
if (extendedBolus != null) {
extendedBolus.timeEnd = new Date(time);
MainApp.getDbHelper().update(extendedBolus);
@ -373,7 +370,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
public double getTempBasalAbsoluteRate() {
PumpInterface pump = MainApp.getConfigBuilder();
TempBasal tb = getTempBasal(new Date().getTime());
TempExBasal tb = getTempBasal(new Date().getTime());
if (tb != null) {
if (tb.isAbsolute) {
return tb.absolute;
@ -383,7 +380,7 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
return tempRate;
}
}
TempBasal eb = getExtendedBolus(new Date().getTime());
TempExBasal eb = getExtendedBolus(new Date().getTime());
if (eb != null && useExtendedBoluses) {
return pump.getBaseBasalRate() + eb.absolute;
}
@ -400,13 +397,13 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
}
@Override
public void tempBasalStart(TempBasal tempBasal) {
public void tempBasalStart(TempExBasal tempBasal) {
MainApp.getDbHelper().create(tempBasal);
}
@Override
public void tempBasalStop(long time) {
TempBasal tempBasal = getTempBasal(time);
TempExBasal tempBasal = getTempBasal(time);
if (tempBasal != null) {
tempBasal.timeEnd = new Date(time);
MainApp.getDbHelper().update(tempBasal);
@ -425,15 +422,15 @@ public class TreatmentsPlugin implements PluginBase, TreatmentsInterface {
return oldestTemp;
}
public static List<TempBasal> getMergedList() {
public static List<TempExBasal> getMergedList() {
if (useExtendedBoluses) {
List<TempBasal> merged = new ArrayList<TempBasal>();
List<TempExBasal> merged = new ArrayList<TempExBasal>();
merged.addAll(tempBasals);
if (useExtendedBoluses)
merged.addAll(extendedBoluses);
class CustomComparator implements Comparator<TempBasal> {
public int compare(TempBasal object1, TempBasal object2) {
class CustomComparator implements Comparator<TempExBasal> {
public int compare(TempExBasal object1, TempExBasal object2) {
return (int) (object2.timeIndex - object1.timeIndex);
}
}

View file

@ -77,7 +77,7 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
NSProfile profile = ConfigBuilderPlugin.getActiveProfile().getProfile();
if (profile == null)
return;
holder.date.setText(DateUtil.dateAndTimeString(treatments.get(position).created_at));
holder.date.setText(DateUtil.dateAndTimeString(treatments.get(position).date));
holder.insulin.setText(DecimalFormatter.to2Decimal(treatments.get(position).insulin) + " U");
holder.carbs.setText(DecimalFormatter.to0Decimal(treatments.get(position).carbs) + " g");
Iob iob = treatments.get(position).iobCalc(new Date().getTime(), profile.getDia());
@ -134,7 +134,7 @@ public class TreatmentsBolusFragment extends Fragment implements View.OnClickLis
case R.id.treatments_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setTitle(MainApp.sResources.getString(R.string.confirmation));
builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(treatment.created_at));
builder.setMessage(MainApp.sResources.getString(R.string.removerecord) + "\n" + DateUtil.dateAndTimeString(treatment.date));
builder.setPositiveButton(MainApp.sResources.getString(R.string.ok), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
final String _id = treatment._id;

View file

@ -30,7 +30,7 @@ import java.util.List;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
import info.nightscout.utils.DateUtil;
@ -49,9 +49,9 @@ public class TreatmentsTempBasalsFragment extends Fragment {
public class RecyclerViewAdapter extends RecyclerView.Adapter<RecyclerViewAdapter.TempBasalsViewHolder> {
List<TempBasal> tempBasalList;
List<TempExBasal> tempBasalList;
RecyclerViewAdapter(List<TempBasal> tempBasalList) {
RecyclerViewAdapter(List<TempExBasal> tempBasalList) {
this.tempBasalList = tempBasalList;
}
@ -63,7 +63,7 @@ public class TreatmentsTempBasalsFragment extends Fragment {
@Override
public void onBindViewHolder(TempBasalsViewHolder holder, int position) {
TempBasal tempBasal = tempBasalList.get(position);
TempExBasal tempBasal = tempBasalList.get(position);
if (tempBasal.timeEnd != null) {
holder.date.setText(DateUtil.dateAndTimeString(tempBasal.timeStart) + " - " + DateUtil.timeString(tempBasalList.get(position).timeEnd));
} else {
@ -138,7 +138,7 @@ public class TreatmentsTempBasalsFragment extends Fragment {
@Override
public void onClick(View v) {
final TempBasal tempBasal = (TempBasal) v.getTag();
final TempExBasal tempBasal = (TempExBasal) v.getTag();
switch (v.getId()) {
case R.id.tempbasals_remove:
AlertDialog.Builder builder = new AlertDialog.Builder(context);

View file

@ -2,16 +2,12 @@ package info.nightscout.androidaps.plugins.TreatmentsFromHistory;
import android.support.annotation.Nullable;
import com.j256.ormlite.dao.Dao;
import com.squareup.otto.Subscribe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
@ -22,12 +18,9 @@ import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.Iob;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.db.Treatment;
import info.nightscout.androidaps.events.EventPreferenceChange;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.InsulinInterface;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
@ -35,7 +28,6 @@ import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
import info.nightscout.androidaps.plugins.IobCobCalculator.AutosensData;
import info.nightscout.androidaps.plugins.IobCobCalculator.IobCobCalculatorPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
import info.nightscout.androidaps.plugins.Treatments.TreatmentsFragment;
import info.nightscout.utils.SP;
/**
@ -48,8 +40,8 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
public static IobTotal lastTempBasalsCalculation;
public static List<Treatment> treatments;
private static List<TempBasal> tempBasals;
private static List<TempBasal> extendedBoluses;
private static List<TempExBasal> tempBasals;
private static List<TempExBasal> extendedBoluses;
private static boolean fragmentEnabled = true;
private static boolean fragmentVisible = true;
@ -153,10 +145,10 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
checkForExpired(extendedBoluses);
}
private static void checkForExpired(List<TempBasal> list) {
private static void checkForExpired(List<TempExBasal> list) {
long now = new Date().getTime();
for (int position = list.size() - 1; position >= 0; position--) {
TempBasal t = list.get(position);
TempExBasal t = list.get(position);
boolean update = false;
if (t.timeEnd == null && t.getPlannedTimeEnd() < now) {
t.timeEnd = new Date(t.getPlannedTimeEnd());
@ -206,7 +198,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
for (Integer pos = 0; pos < treatments.size(); pos++) {
Treatment t = treatments.get(pos);
if (t.created_at.getTime() > time) continue;
if (t.date > time) continue;
Iob tIOB = t.iobCalc(time, dia);
total.iob += tIOB.iobContrib;
total.activity += tIOB.activityContrib;
@ -216,7 +208,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
checkForExpired(extendedBoluses);
for (Integer pos = 0; pos < extendedBoluses.size(); pos++) {
TempBasal t = extendedBoluses.get(pos);
TempExBasal t = extendedBoluses.get(pos);
if (t.timeStart.getTime() > time) continue;
IobTotal calc = t.iobCalc(time);
total.plus(calc);
@ -242,7 +234,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
long dia_ago = now - (new Double(1.5d * profile.getDia() * 60 * 60 * 1000l)).longValue();
for (Treatment treatment : treatments) {
long t = treatment.created_at.getTime();
long t = treatment.date;
if (t > dia_ago && t <= now) {
if (treatment.carbs >= 1) {
result.carbs += treatment.carbs;
@ -270,7 +262,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
List<Treatment> in5minback = new ArrayList<>();
for (Integer pos = 0; pos < treatments.size(); pos++) {
Treatment t = treatments.get(pos);
if (t.created_at.getTime() <= time && t.created_at.getTime() > time - 5 * 60 * 1000)
if (t.date <= time && t.date > time - 5 * 60 * 1000)
in5minback.add(t);
}
return in5minback;
@ -282,7 +274,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
}
@Override
public TempBasal getRealTempBasal(long time) {
public TempExBasal getRealTempBasal(long time) {
return null;
}
@ -312,7 +304,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
checkForExpired(tempBasals);
IobTotal total = new IobTotal(time);
for (Integer pos = 0; pos < tempBasals.size(); pos++) {
TempBasal t = tempBasals.get(pos);
TempExBasal t = tempBasals.get(pos);
if (t.timeStart.getTime() > time) continue;
IobTotal calc = t.iobCalc(time);
//log.debug("BasalIOB " + new Date(time) + " >>> " + calc.basaliob);
@ -330,25 +322,25 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
@Nullable
@Override
public TempBasal getTempBasal(long time) {
public TempExBasal getTempBasal(long time) {
checkForExpired(tempBasals);
for (TempBasal t : tempBasals) {
for (TempExBasal t : tempBasals) {
if (t.isInProgress(time)) return t;
}
return null;
}
@Override
public TempBasal getExtendedBolus(long time) {
public TempExBasal getExtendedBolus(long time) {
checkForExpired(extendedBoluses);
for (TempBasal t : extendedBoluses) {
for (TempExBasal t : extendedBoluses) {
if (t.isInProgress(time)) return t;
}
return null;
}
@Override
public void extendedBolusStart(TempBasal extendedBolus) {
public void extendedBolusStart(TempExBasal extendedBolus) {
}
@ -361,7 +353,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
public double getTempBasalAbsoluteRate() {
PumpInterface pump = MainApp.getConfigBuilder();
TempBasal tb = getTempBasal(new Date().getTime());
TempExBasal tb = getTempBasal(new Date().getTime());
if (tb != null) {
if (tb.isAbsolute) {
return tb.absolute;
@ -382,7 +374,7 @@ public class TreatmentsFromHistoryPlugin implements PluginBase, TreatmentsInterf
}
@Override
public void tempBasalStart(TempBasal tempBasal) {
public void tempBasalStart(TempExBasal tempBasal) {
}

View file

@ -285,7 +285,7 @@ public class ActionStringHandler {
TempTarget tempTarget = tempTargetRangePlugin.getTempTargetInProgress(new Date().getTime());
if (tempTarget != null) {
ret += "Temp Target: " + NSProfile.toUnitsString(tempTarget.low, NSProfile.fromMgdlToUnits(tempTarget.low, profile.getUnits()), profile.getUnits()) + " - " + NSProfile.toUnitsString(tempTarget.high, NSProfile.fromMgdlToUnits(tempTarget.high, profile.getUnits()), profile.getUnits());
ret += "\nuntil: " + DateUtil.timeString(tempTarget.getPlannedTimeEnd());
ret += "\nuntil: " + DateUtil.timeString(tempTarget.originalEnd());
ret += "\n\n";
}
}
@ -354,17 +354,16 @@ public class ActionStringHandler {
private static void generateTempTarget(int duration, double low, double high) {
TempTarget tempTarget = new TempTarget();
tempTarget.timeStart = new Date();
tempTarget.duration = duration;
tempTarget.date = new Date().getTime();
tempTarget.durationInMinutes = duration;
tempTarget.reason = "WearPlugin";
if(tempTarget.duration != 0) {
if(tempTarget.durationInMinutes != 0) {
tempTarget.low = low;
tempTarget.high = high;
} else {
tempTarget.low = 0;
tempTarget.high = 0;
}
tempTarget.setTimeIndex(tempTarget.getTimeIndex());
Dao<TempTarget, Long> dao = null;
try {
dao = MainApp.getDbHelper().getDaoTempTargets();

View file

@ -28,7 +28,7 @@ import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.GlucoseStatus;
import info.nightscout.androidaps.db.BgReading;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.data.IobTotal;
@ -237,7 +237,7 @@ public class WatchUpdaterService extends WearableListenerService implements
int battery = getBatteryLevel(getApplicationContext());
dataMap.putString("sgvString", lastBG.valueToUnitsToString(profile.getUnits()));
dataMap.putDouble("timestamp", lastBG.getTimeIndex());
dataMap.putDouble("timestamp", lastBG.date);
if(glucoseStatus == null) {
dataMap.putString("slopeArrow", "" );
dataMap.putString("delta", "");
@ -346,8 +346,8 @@ public class WatchUpdaterService extends WearableListenerService implements
double beginBasalValue = profile.getBasal(NSProfile.secondsFromMidnight(new Date(beginBasalSegmentTime)));
double endBasalValue = beginBasalValue;
TempBasal tb1 = MainApp.getConfigBuilder().getTempBasal(runningTime);
TempBasal tb2 = MainApp.getConfigBuilder().getTempBasal(runningTime);
TempExBasal tb1 = MainApp.getConfigBuilder().getTempBasal(runningTime);
TempExBasal tb2 = MainApp.getConfigBuilder().getTempBasal(runningTime);
double tb_before = beginBasalValue;
double tb_amount = beginBasalValue;
long tb_start = runningTime;
@ -536,7 +536,7 @@ public class WatchUpdaterService extends WearableListenerService implements
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
if (treatmentsInterface.isTempBasalInProgress()) {
TempBasal activeTemp = treatmentsInterface.getTempBasal(new Date().getTime());
TempExBasal activeTemp = treatmentsInterface.getTempBasal(new Date().getTime());
if (shortString) {
status += activeTemp.toStringShort();
} else {

View file

@ -14,7 +14,7 @@ import java.util.Date;
import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R;
import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.db.TempBasal;
import info.nightscout.androidaps.db.TempExBasal;
import info.nightscout.androidaps.events.EventExtendedBolusChange;
import info.nightscout.androidaps.events.EventNewBG;
import info.nightscout.androidaps.events.EventPreferenceChange;
@ -22,7 +22,6 @@ import info.nightscout.androidaps.events.EventRefreshGui;
import info.nightscout.androidaps.events.EventTempBasalChange;
import info.nightscout.androidaps.events.EventTreatmentChange;
import info.nightscout.androidaps.interfaces.PluginBase;
import info.nightscout.androidaps.interfaces.PumpInterface;
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
import info.nightscout.androidaps.plugins.NSClientInternal.data.NSProfile;
@ -165,7 +164,7 @@ public class StatuslinePlugin implements PluginBase {
TreatmentsInterface treatmentsInterface = MainApp.getConfigBuilder();
if (treatmentsInterface.isTempBasalInProgress()) {
TempBasal activeTemp = treatmentsInterface.getTempBasal(new Date().getTime());
TempExBasal activeTemp = treatmentsInterface.getTempBasal(new Date().getTime());
if (shortString) {
status += activeTemp.toStringShort();
} else {

View file

@ -8,6 +8,8 @@ import android.support.v4.util.LongSparseArray;
import java.util.ArrayList;
import java.util.List;
import info.nightscout.androidaps.interfaces.Interval;
/**
* Created by mike on 09.05.2017.
*/
@ -19,59 +21,6 @@ public class OverlappingIntervals {
private Object dataLock = new Object();
public abstract class Interval {
Long start = null;
Long duration = null;
Long cuttedEnd = null;
public Interval(long start, long duration) {
this.start = start;
this.duration = duration;
}
long durationInMsec() {
return duration;
}
long start() {
return start;
}
// planned end time at time of creation
long originalEnd() {
return start + duration;
}
// end time after cut
long end() {
if (cuttedEnd != null)
return cuttedEnd;
return originalEnd();
}
void cutEndTo(long end) {
cuttedEnd = end;
}
boolean match(long time) {
if (start() <= time && end() >= time)
return true;
return false;
}
boolean before(long time) {
if (end() < time)
return true;
return false;
}
boolean after(long time) {
if (start() > time)
return true;
return false;
}
}
private static LongSparseArray<Interval> rawData = new LongSparseArray<>(); // oldest at index 0
public OverlappingIntervals() {
@ -142,4 +91,4 @@ public class OverlappingIntervals {
return ~lo; // value not present
}
}
}