careportal cage, sage, iage
This commit is contained in:
parent
87993c6163
commit
5fb72181ee
14 changed files with 722 additions and 217 deletions
|
@ -23,6 +23,7 @@ import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.db.BgReading;
|
import info.nightscout.androidaps.db.BgReading;
|
||||||
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.Treatment;
|
import info.nightscout.androidaps.db.Treatment;
|
||||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||||
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
import info.nightscout.androidaps.interfaces.InsulinInterface;
|
||||||
|
@ -404,6 +405,7 @@ public class DataService extends IntentService {
|
||||||
MainApp.getDbHelper().deleteTempTargetById(trJson.getString("_id"));
|
MainApp.getDbHelper().deleteTempTargetById(trJson.getString("_id"));
|
||||||
MainApp.getDbHelper().deleteTempBasalById(trJson.getString("_id"));
|
MainApp.getDbHelper().deleteTempBasalById(trJson.getString("_id"));
|
||||||
MainApp.getDbHelper().deleteExtendedBolusById(trJson.getString("_id"));
|
MainApp.getDbHelper().deleteExtendedBolusById(trJson.getString("_id"));
|
||||||
|
MainApp.getDbHelper().deleteCareportalEventById(trJson.getString("_id"));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (bundles.containsKey("treatments")) {
|
if (bundles.containsKey("treatments")) {
|
||||||
|
@ -416,6 +418,7 @@ public class DataService extends IntentService {
|
||||||
MainApp.getDbHelper().deleteTempTargetById(trJson.getString("_id"));
|
MainApp.getDbHelper().deleteTempTargetById(trJson.getString("_id"));
|
||||||
MainApp.getDbHelper().deleteTempBasalById(trJson.getString("_id"));
|
MainApp.getDbHelper().deleteTempBasalById(trJson.getString("_id"));
|
||||||
MainApp.getDbHelper().deleteExtendedBolusById(trJson.getString("_id"));
|
MainApp.getDbHelper().deleteExtendedBolusById(trJson.getString("_id"));
|
||||||
|
MainApp.getDbHelper().deleteCareportalEventById(trJson.getString("_id"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -473,6 +476,7 @@ public class DataService extends IntentService {
|
||||||
handleAddChangeTempTargetRecord(trJson);
|
handleAddChangeTempTargetRecord(trJson);
|
||||||
handleAddChangeTempBasalRecord(trJson);
|
handleAddChangeTempBasalRecord(trJson);
|
||||||
handleAddChangeExtendedBolusRecord(trJson);
|
handleAddChangeExtendedBolusRecord(trJson);
|
||||||
|
handleAddChangeCareportalEventRecord(trJson);
|
||||||
if (!trJson.has("insulin") && !trJson.has("carbs")) {
|
if (!trJson.has("insulin") && !trJson.has("carbs")) {
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
log.debug("Ignoring non insulin/carbs record: " + trstring);
|
log.debug("Ignoring non insulin/carbs record: " + trstring);
|
||||||
|
@ -533,6 +537,9 @@ public class DataService extends IntentService {
|
||||||
JSONObject trJson = new JSONObject(trstring);
|
JSONObject trJson = new JSONObject(trstring);
|
||||||
handleDanaRHistoryRecords(trJson); // update record _id in history
|
handleDanaRHistoryRecords(trJson); // update record _id in history
|
||||||
handleAddChangeTempTargetRecord(trJson);
|
handleAddChangeTempTargetRecord(trJson);
|
||||||
|
handleAddChangeTempBasalRecord(trJson);
|
||||||
|
handleAddChangeExtendedBolusRecord(trJson);
|
||||||
|
handleAddChangeCareportalEventRecord(trJson);
|
||||||
if (!trJson.has("insulin") && !trJson.has("carbs")) {
|
if (!trJson.has("insulin") && !trJson.has("carbs")) {
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
log.debug("CHANGE: Uninterested treatment: " + trstring);
|
log.debug("CHANGE: Uninterested treatment: " + trstring);
|
||||||
|
@ -594,7 +601,7 @@ public class DataService extends IntentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleAddChangeTempTargetRecord(JSONObject trJson) throws JSONException, SQLException {
|
public void handleAddChangeTempTargetRecord(JSONObject trJson) throws JSONException, SQLException {
|
||||||
if (trJson.has("eventType") && trJson.getString("eventType").equals("Temporary Target")) {
|
if (trJson.has("eventType") && trJson.getString("eventType").equals(CareportalEvent.TEMPORARYTARGET)) {
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
log.debug("Processing TempTarget record: " + trJson.toString());
|
log.debug("Processing TempTarget record: " + trJson.toString());
|
||||||
MainApp.getDbHelper().createTemptargetFromJsonIfNotExists(trJson);
|
MainApp.getDbHelper().createTemptargetFromJsonIfNotExists(trJson);
|
||||||
|
@ -602,7 +609,7 @@ public class DataService extends IntentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleAddChangeTempBasalRecord(JSONObject trJson) throws JSONException, SQLException {
|
public void handleAddChangeTempBasalRecord(JSONObject trJson) throws JSONException, SQLException {
|
||||||
if (trJson.has("eventType") && trJson.getString("eventType").equals("Temp Basal")) {
|
if (trJson.has("eventType") && trJson.getString("eventType").equals(CareportalEvent.TEMPBASAL)) {
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
log.debug("Processing TempBasal record: " + trJson.toString());
|
log.debug("Processing TempBasal record: " + trJson.toString());
|
||||||
MainApp.getDbHelper().createTempBasalFromJsonIfNotExists(trJson);
|
MainApp.getDbHelper().createTempBasalFromJsonIfNotExists(trJson);
|
||||||
|
@ -610,13 +617,25 @@ public class DataService extends IntentService {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void handleAddChangeExtendedBolusRecord(JSONObject trJson) throws JSONException, SQLException {
|
public void handleAddChangeExtendedBolusRecord(JSONObject trJson) throws JSONException, SQLException {
|
||||||
if (trJson.has("eventType") && trJson.getString("eventType").equals("Combo Bolus")) {
|
if (trJson.has("eventType") && trJson.getString("eventType").equals(CareportalEvent.COMBOBOLUS)) {
|
||||||
if (Config.logIncommingData)
|
if (Config.logIncommingData)
|
||||||
log.debug("Processing Extended Bolus record: " + trJson.toString());
|
log.debug("Processing Extended Bolus record: " + trJson.toString());
|
||||||
MainApp.getDbHelper().createExtendedBolusFromJsonIfNotExists(trJson);
|
MainApp.getDbHelper().createExtendedBolusFromJsonIfNotExists(trJson);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void handleAddChangeCareportalEventRecord(JSONObject trJson) throws JSONException, SQLException {
|
||||||
|
if (trJson.has("eventType") && (
|
||||||
|
trJson.getString("eventType").equals(CareportalEvent.SITECHANGE) ||
|
||||||
|
trJson.getString("eventType").equals(CareportalEvent.INSULINCHANGE) ||
|
||||||
|
trJson.getString("eventType").equals(CareportalEvent.SENSORCHANGE)
|
||||||
|
)) {
|
||||||
|
if (Config.logIncommingData)
|
||||||
|
log.debug("Processing CareportalEvent record: " + trJson.toString());
|
||||||
|
MainApp.getDbHelper().createCareportalEventFromJsonIfNotExists(trJson);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void handleNewSMS(Intent intent) {
|
private void handleNewSMS(Intent intent) {
|
||||||
Bundle bundle = intent.getExtras();
|
Bundle bundle = intent.getExtras();
|
||||||
if (bundle == null) return;
|
if (bundle == null) return;
|
||||||
|
|
|
@ -0,0 +1,93 @@
|
||||||
|
package info.nightscout.androidaps.db;
|
||||||
|
|
||||||
|
import com.j256.ormlite.field.DatabaseField;
|
||||||
|
import com.j256.ormlite.table.DatabaseTable;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.EnumSet;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.utils.DateUtil;
|
||||||
|
|
||||||
|
@DatabaseTable(tableName = DatabaseHelper.DATABASE_CAREPORTALEVENTS)
|
||||||
|
public class CareportalEvent {
|
||||||
|
private static Logger log = LoggerFactory.getLogger(CareportalEvent.class);
|
||||||
|
|
||||||
|
@DatabaseField(id = true)
|
||||||
|
public long date;
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public boolean isValid = true;
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public int source = Source.NONE;
|
||||||
|
@DatabaseField
|
||||||
|
public String _id;
|
||||||
|
|
||||||
|
@DatabaseField
|
||||||
|
public String eventType;
|
||||||
|
@DatabaseField
|
||||||
|
public String json;
|
||||||
|
|
||||||
|
public static final String COMBOBOLUS = "Combo Bolus";
|
||||||
|
public static final String TEMPBASAL = "Temp Basal";
|
||||||
|
public static final String TEMPORARYTARGET = "Temporary Target";
|
||||||
|
public static final String PROFILESWITCH = "Profile Switch";
|
||||||
|
public static final String SITECHANGE = "Site Change";
|
||||||
|
public static final String INSULINCHANGE = "Insulin Change";
|
||||||
|
public static final String SENSORCHANGE = "Sensor Change";
|
||||||
|
|
||||||
|
public CareportalEvent() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getMillisecondsFromStart() {
|
||||||
|
return new Date().getTime() - date;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getHoursFromStart() {
|
||||||
|
return (new Date().getTime() - date) / (60 * 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String age() {
|
||||||
|
Map<TimeUnit,Long> diff = computeDiff(date, new Date().getTime());
|
||||||
|
return diff.get(TimeUnit.DAYS) + " " + MainApp.sResources.getString(R.string.days) + " " + diff.get(TimeUnit.HOURS) + " " + MainApp.sResources.getString(R.string.hours);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String log() {
|
||||||
|
return "CareportalEvent{" +
|
||||||
|
"date= " + date +
|
||||||
|
", date= " + DateUtil.dateAndTimeString(date) +
|
||||||
|
", isValid= " + isValid +
|
||||||
|
", _id= " + _id +
|
||||||
|
", eventType= " + eventType +
|
||||||
|
", json= " + json +
|
||||||
|
"}";
|
||||||
|
}
|
||||||
|
|
||||||
|
//Map:{DAYS=1, HOURS=3, MINUTES=46, SECONDS=40, MILLISECONDS=0, MICROSECONDS=0, NANOSECONDS=0}
|
||||||
|
public static Map<TimeUnit,Long> computeDiff(long date1, long date2) {
|
||||||
|
long diffInMillies = date2 - date1;
|
||||||
|
List<TimeUnit> units = new ArrayList<TimeUnit>(EnumSet.allOf(TimeUnit.class));
|
||||||
|
Collections.reverse(units);
|
||||||
|
Map<TimeUnit,Long> result = new LinkedHashMap<TimeUnit,Long>();
|
||||||
|
long milliesRest = diffInMillies;
|
||||||
|
for ( TimeUnit unit : units ) {
|
||||||
|
long diff = unit.convert(milliesRest,TimeUnit.MILLISECONDS);
|
||||||
|
long diffInMilliesForUnit = unit.toMillis(diff);
|
||||||
|
milliesRest = milliesRest - diffInMilliesForUnit;
|
||||||
|
result.put(unit,diff);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
|
@ -31,6 +31,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
import info.nightscout.androidaps.Config;
|
import info.nightscout.androidaps.Config;
|
||||||
import info.nightscout.androidaps.Constants;
|
import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
|
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
||||||
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
import info.nightscout.androidaps.events.EventExtendedBolusChange;
|
||||||
import info.nightscout.androidaps.events.EventNewBG;
|
import info.nightscout.androidaps.events.EventNewBG;
|
||||||
import info.nightscout.androidaps.events.EventTempBasalChange;
|
import info.nightscout.androidaps.events.EventTempBasalChange;
|
||||||
|
@ -51,6 +52,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
public static final String DATABASE_TREATMENTS = "Treatments";
|
public static final String DATABASE_TREATMENTS = "Treatments";
|
||||||
public static final String DATABASE_DANARHISTORY = "DanaRHistory";
|
public static final String DATABASE_DANARHISTORY = "DanaRHistory";
|
||||||
public static final String DATABASE_DBREQUESTS = "DBRequests";
|
public static final String DATABASE_DBREQUESTS = "DBRequests";
|
||||||
|
public static final String DATABASE_CAREPORTALEVENTS = "CareportalEvents";
|
||||||
|
|
||||||
private static final int DATABASE_VERSION = 7;
|
private static final int DATABASE_VERSION = 7;
|
||||||
|
|
||||||
|
@ -71,6 +73,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
private static final ScheduledExecutorService extendedBolusWorker = Executors.newSingleThreadScheduledExecutor();
|
private static final ScheduledExecutorService extendedBolusWorker = Executors.newSingleThreadScheduledExecutor();
|
||||||
private static ScheduledFuture<?> scheduledExtendedBolusPost = null;
|
private static ScheduledFuture<?> scheduledExtendedBolusPost = null;
|
||||||
|
|
||||||
|
private static final ScheduledExecutorService careportalEventWorker = Executors.newSingleThreadScheduledExecutor();
|
||||||
|
private static ScheduledFuture<?> scheduledCareportalEventPost = null;
|
||||||
|
|
||||||
public DatabaseHelper(Context context) {
|
public DatabaseHelper(Context context) {
|
||||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||||
onCreate(getWritableDatabase(), getConnectionSource());
|
onCreate(getWritableDatabase(), getConnectionSource());
|
||||||
|
@ -87,6 +92,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
TableUtils.createTableIfNotExists(connectionSource, DbRequest.class);
|
TableUtils.createTableIfNotExists(connectionSource, DbRequest.class);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class);
|
TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
|
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
|
||||||
|
TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Can't create database", e);
|
log.error("Can't create database", e);
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
|
@ -104,6 +110,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
TableUtils.dropTable(connectionSource, DbRequest.class, true);
|
TableUtils.dropTable(connectionSource, DbRequest.class, true);
|
||||||
TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
|
TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
|
||||||
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
|
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
|
||||||
|
TableUtils.dropTable(connectionSource, CareportalEvent.class, true);
|
||||||
onCreate(database, connectionSource);
|
onCreate(database, connectionSource);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.error("Can't drop databases", e);
|
log.error("Can't drop databases", e);
|
||||||
|
@ -144,6 +151,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
log.debug("Before ExtendedBoluses size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_EXTENDEDBOLUSES));
|
log.debug("Before ExtendedBoluses size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_EXTENDEDBOLUSES));
|
||||||
getWritableDatabase().delete(DATABASE_EXTENDEDBOLUSES, "recordDate" + " < '" + (new Date().getTime() - Constants.daysToKeepHistoryInDatabase * 24 * 60 * 60 * 1000L) + "'", null);
|
getWritableDatabase().delete(DATABASE_EXTENDEDBOLUSES, "recordDate" + " < '" + (new Date().getTime() - Constants.daysToKeepHistoryInDatabase * 24 * 60 * 60 * 1000L) + "'", null);
|
||||||
log.debug("After ExtendedBoluses size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_EXTENDEDBOLUSES));
|
log.debug("After ExtendedBoluses size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_EXTENDEDBOLUSES));
|
||||||
|
|
||||||
|
log.debug("Before CareportalEvent size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_CAREPORTALEVENTS));
|
||||||
|
getWritableDatabase().delete(DATABASE_CAREPORTALEVENTS, "recordDate" + " < '" + (new Date().getTime() - Constants.daysToKeepHistoryInDatabase * 24 * 60 * 60 * 1000L) + "'", null);
|
||||||
|
log.debug("After CareportalEvent size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_CAREPORTALEVENTS));
|
||||||
}
|
}
|
||||||
|
|
||||||
public long size(String database) {
|
public long size(String database) {
|
||||||
|
@ -161,6 +172,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
TableUtils.dropTable(connectionSource, DbRequest.class, true);
|
TableUtils.dropTable(connectionSource, DbRequest.class, true);
|
||||||
TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
|
TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
|
||||||
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
|
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
|
||||||
|
TableUtils.dropTable(connectionSource, CareportalEvent.class, true);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, TempTarget.class);
|
TableUtils.createTableIfNotExists(connectionSource, TempTarget.class);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
|
TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, BgReading.class);
|
TableUtils.createTableIfNotExists(connectionSource, BgReading.class);
|
||||||
|
@ -168,6 +180,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
TableUtils.createTableIfNotExists(connectionSource, DbRequest.class);
|
TableUtils.createTableIfNotExists(connectionSource, DbRequest.class);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class);
|
TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class);
|
||||||
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
|
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
|
||||||
|
TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class);
|
||||||
latestTreatmentChange = 0L;
|
latestTreatmentChange = 0L;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -177,6 +190,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
scheduleTreatmentChange();
|
scheduleTreatmentChange();
|
||||||
scheduleExtendedBolusChange();
|
scheduleExtendedBolusChange();
|
||||||
scheduleTemporaryTargetChange();
|
scheduleTemporaryTargetChange();
|
||||||
|
scheduleCareportalEventChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetTreatments() {
|
public void resetTreatments() {
|
||||||
|
@ -220,6 +234,16 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
scheduleExtendedBolusChange();
|
scheduleExtendedBolusChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void resetCareportalEvents() {
|
||||||
|
try {
|
||||||
|
TableUtils.dropTable(connectionSource, CareportalEvent.class, true);
|
||||||
|
TableUtils.createTableIfNotExists(connectionSource, CareportalEvent.class);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
scheduleCareportalEventChange();
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------ getDao -------------------------------------------
|
// ------------------ getDao -------------------------------------------
|
||||||
|
|
||||||
private Dao<TempTarget, Long> getDaoTempTargets() throws SQLException {
|
private Dao<TempTarget, Long> getDaoTempTargets() throws SQLException {
|
||||||
|
@ -250,6 +274,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
return getDao(ExtendedBolus.class);
|
return getDao(ExtendedBolus.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Dao<CareportalEvent, Long> getDaoCareportalEvents() throws SQLException {
|
||||||
|
return getDao(CareportalEvent.class);
|
||||||
|
}
|
||||||
|
|
||||||
// ------------------- BgReading handling -----------------------
|
// ------------------- BgReading handling -----------------------
|
||||||
|
|
||||||
public void createIfNotExists(BgReading bgReading) {
|
public void createIfNotExists(BgReading bgReading) {
|
||||||
|
@ -1053,4 +1081,135 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ------------ CareportalEvent handling ---------------
|
||||||
|
|
||||||
|
public int update(CareportalEvent careportalEvent) {
|
||||||
|
int updated = 0;
|
||||||
|
try {
|
||||||
|
updated = getDaoCareportalEvents().update(careportalEvent);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
scheduleCareportalEventChange();
|
||||||
|
return updated;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createOrUpdate(CareportalEvent careportalEvent) {
|
||||||
|
careportalEvent.date = careportalEvent.date - careportalEvent.date % 1000;
|
||||||
|
try {
|
||||||
|
getDaoCareportalEvents().createOrUpdate(careportalEvent);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
scheduleCareportalEventChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete(CareportalEvent careportalEvent) {
|
||||||
|
try {
|
||||||
|
getDaoCareportalEvents().delete(careportalEvent);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
scheduleCareportalEventChange();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public CareportalEvent getLastCareportalEvent(String event) {
|
||||||
|
try {
|
||||||
|
List<CareportalEvent> careportalEvents;
|
||||||
|
QueryBuilder<CareportalEvent, Long> queryBuilder = getDaoCareportalEvents().queryBuilder();
|
||||||
|
queryBuilder.orderBy("date", false);
|
||||||
|
Where where = queryBuilder.where();
|
||||||
|
where.eq("eventType", event);
|
||||||
|
queryBuilder.limit(1L);
|
||||||
|
PreparedQuery<CareportalEvent> preparedQuery = queryBuilder.prepare();
|
||||||
|
careportalEvents = getDaoCareportalEvents().query(preparedQuery);
|
||||||
|
if (careportalEvents.size() == 1)
|
||||||
|
return careportalEvents.get(0);
|
||||||
|
else
|
||||||
|
return null;
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteCareportalEventById(String _id) {
|
||||||
|
try {
|
||||||
|
QueryBuilder<CareportalEvent, Long> queryBuilder = null;
|
||||||
|
queryBuilder = getDaoCareportalEvents().queryBuilder();
|
||||||
|
Where where = queryBuilder.where();
|
||||||
|
where.eq("_id", _id);
|
||||||
|
PreparedQuery<CareportalEvent> preparedQuery = queryBuilder.prepare();
|
||||||
|
List<CareportalEvent> list = getDaoCareportalEvents().query(preparedQuery);
|
||||||
|
|
||||||
|
if (list.size() == 1) {
|
||||||
|
CareportalEvent record = list.get(0);
|
||||||
|
if (Config.logIncommingData)
|
||||||
|
log.debug("Removing CareportalEvent record from database: " + record.log());
|
||||||
|
getDaoCareportalEvents().delete(record);
|
||||||
|
scheduleCareportalEventChange();
|
||||||
|
} else {
|
||||||
|
if (Config.logIncommingData)
|
||||||
|
log.debug("CareportalEvent not found database: " + _id);
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void createCareportalEventFromJsonIfNotExists(JSONObject trJson) {
|
||||||
|
try {
|
||||||
|
QueryBuilder<CareportalEvent, Long> queryBuilder = null;
|
||||||
|
queryBuilder = getDaoCareportalEvents().queryBuilder();
|
||||||
|
Where where = queryBuilder.where();
|
||||||
|
where.eq("_id", trJson.getString("_id")).or().eq("date", trJson.getLong("mills"));
|
||||||
|
PreparedQuery<CareportalEvent> preparedQuery = queryBuilder.prepare();
|
||||||
|
List<CareportalEvent> list = getDaoCareportalEvents().query(preparedQuery);
|
||||||
|
CareportalEvent careportalEvent;
|
||||||
|
if (list.size() == 0) {
|
||||||
|
careportalEvent = new CareportalEvent();
|
||||||
|
careportalEvent.source = Source.NIGHTSCOUT;
|
||||||
|
if (Config.logIncommingData)
|
||||||
|
log.debug("Adding CareportalEvent record to database: " + trJson.toString());
|
||||||
|
// Record does not exists. add
|
||||||
|
} else if (list.size() == 1) {
|
||||||
|
careportalEvent = list.get(0);
|
||||||
|
if (Config.logIncommingData)
|
||||||
|
log.debug("Updating CareportalEvent record in database: " + trJson.toString());
|
||||||
|
} else {
|
||||||
|
log.error("Something went wrong");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
careportalEvent.date = trJson.getLong("mills");
|
||||||
|
careportalEvent.eventType = trJson.getString("eventType");
|
||||||
|
careportalEvent.json = trJson.toString();
|
||||||
|
careportalEvent._id = trJson.getString("_id");
|
||||||
|
createOrUpdate(careportalEvent);
|
||||||
|
scheduleCareportalEventChange();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static public void scheduleCareportalEventChange() {
|
||||||
|
class PostRunnable implements Runnable {
|
||||||
|
public void run() {
|
||||||
|
MainApp.bus().post(new EventCareportalEventChange());
|
||||||
|
scheduledCareportalEventPost = null;
|
||||||
|
log.debug("Firing scheduleCareportalEventChange");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// prepare task for execution in 1 sec
|
||||||
|
// cancel waiting task to prevent sending multiple posts
|
||||||
|
if (scheduledCareportalEventPost != null)
|
||||||
|
scheduledCareportalEventPost.cancel(false);
|
||||||
|
Runnable task = new PostRunnable();
|
||||||
|
final int sec = 1;
|
||||||
|
scheduledCareportalEventPost = careportalEventWorker.schedule(task, sec, TimeUnit.SECONDS);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,8 @@
|
||||||
|
package info.nightscout.androidaps.events;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by mike on 25.05.2017.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class EventCareportalEventChange {
|
||||||
|
}
|
|
@ -1,20 +1,31 @@
|
||||||
package info.nightscout.androidaps.plugins.Careportal;
|
package info.nightscout.androidaps.plugins.Careportal;
|
||||||
|
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import com.squareup.otto.Subscribe;
|
||||||
|
|
||||||
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
|
import info.nightscout.androidaps.events.EventCareportalEventChange;
|
||||||
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
import info.nightscout.androidaps.plugins.Careportal.Dialogs.NewNSTreatmentDialog;
|
||||||
|
|
||||||
public class CareportalFragment extends Fragment implements View.OnClickListener {
|
public class CareportalFragment extends Fragment implements View.OnClickListener {
|
||||||
|
|
||||||
static CareportalPlugin careportalPlugin;
|
static CareportalPlugin careportalPlugin;
|
||||||
|
|
||||||
|
TextView iage;
|
||||||
|
TextView cage;
|
||||||
|
TextView sage;
|
||||||
|
|
||||||
static public CareportalPlugin getPlugin() {
|
static public CareportalPlugin getPlugin() {
|
||||||
if (careportalPlugin == null) {
|
if (careportalPlugin == null) {
|
||||||
careportalPlugin = new CareportalPlugin();
|
careportalPlugin = new CareportalPlugin();
|
||||||
|
@ -67,6 +78,12 @@ public class CareportalFragment extends Fragment implements View.OnClickListener
|
||||||
view.findViewById(R.id.careportal_tempbasalstart).setOnClickListener(this);
|
view.findViewById(R.id.careportal_tempbasalstart).setOnClickListener(this);
|
||||||
view.findViewById(R.id.careportal_openapsoffline).setOnClickListener(this);
|
view.findViewById(R.id.careportal_openapsoffline).setOnClickListener(this);
|
||||||
view.findViewById(R.id.careportal_temporarytarget).setOnClickListener(this);
|
view.findViewById(R.id.careportal_temporarytarget).setOnClickListener(this);
|
||||||
|
|
||||||
|
iage = (TextView) view.findViewById(R.id.careportal_insulinage);
|
||||||
|
cage = (TextView) view.findViewById(R.id.careportal_canulaage);
|
||||||
|
sage = (TextView) view.findViewById(R.id.careportal_sensorage);
|
||||||
|
|
||||||
|
updateGUI();
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,4 +156,41 @@ public class CareportalFragment extends Fragment implements View.OnClickListener
|
||||||
newDialog.show(manager, "NewNSTreatmentDialog");
|
newDialog.show(manager, "NewNSTreatmentDialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onPause() {
|
||||||
|
super.onPause();
|
||||||
|
MainApp.bus().unregister(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onResume() {
|
||||||
|
super.onResume();
|
||||||
|
MainApp.bus().register(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe
|
||||||
|
public void onStatusEvent(final EventCareportalEventChange c) {
|
||||||
|
updateGUI();
|
||||||
|
}
|
||||||
|
|
||||||
|
void updateGUI() {
|
||||||
|
Activity activity = getActivity();
|
||||||
|
if (activity != null) {
|
||||||
|
activity.runOnUiThread(
|
||||||
|
new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
CareportalEvent careportalEvent;
|
||||||
|
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SENSORCHANGE);
|
||||||
|
sage.setText(careportalEvent != null ? careportalEvent.age() : MainApp.sResources.getString(R.string.notavailable));
|
||||||
|
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.INSULINCHANGE);
|
||||||
|
iage.setText(careportalEvent != null ? careportalEvent.age() : MainApp.sResources.getString(R.string.notavailable));
|
||||||
|
careportalEvent = MainApp.getDbHelper().getLastCareportalEvent(CareportalEvent.SITECHANGE);
|
||||||
|
cage.setText(careportalEvent != null ? careportalEvent.age() : MainApp.sResources.getString(R.string.notavailable));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,6 +44,7 @@ import info.nightscout.androidaps.Constants;
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
import info.nightscout.androidaps.data.GlucoseStatus;
|
import info.nightscout.androidaps.data.GlucoseStatus;
|
||||||
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
import info.nightscout.androidaps.events.EventNewBasalProfile;
|
||||||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||||
|
@ -407,7 +408,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
data.put("isAnnouncement", true);
|
data.put("isAnnouncement", true);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_cgmsensorinsert:
|
case R.id.careportal_cgmsensorinsert:
|
||||||
data.put("eventType", "Sensor Change");
|
data.put("eventType", CareportalEvent.SENSORCHANGE);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_cgmsensorstart:
|
case R.id.careportal_cgmsensorstart:
|
||||||
data.put("eventType", "Sensor Start");
|
data.put("eventType", "Sensor Start");
|
||||||
|
@ -415,7 +416,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
case R.id.careportal_combobolus:
|
case R.id.careportal_combobolus:
|
||||||
data.put("splitNow", SafeParse.stringToDouble(splitEdit.getText().toString()));
|
data.put("splitNow", SafeParse.stringToDouble(splitEdit.getText().toString()));
|
||||||
data.put("splitExt", 100 - SafeParse.stringToDouble(splitEdit.getText().toString()));
|
data.put("splitExt", 100 - SafeParse.stringToDouble(splitEdit.getText().toString()));
|
||||||
data.put("eventType", "Combo Bolus");
|
data.put("eventType", CareportalEvent.COMBOBOLUS);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_correctionbolus:
|
case R.id.careportal_correctionbolus:
|
||||||
data.put("eventType", "Correction Bolus");
|
data.put("eventType", "Correction Bolus");
|
||||||
|
@ -427,7 +428,7 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
data.put("eventType", "Exercise");
|
data.put("eventType", "Exercise");
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_insulincartridgechange:
|
case R.id.careportal_insulincartridgechange:
|
||||||
data.put("eventType", "Insulin Change");
|
data.put("eventType", CareportalEvent.INSULINCHANGE);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_mealbolus:
|
case R.id.careportal_mealbolus:
|
||||||
data.put("eventType", "Meal Bolus");
|
data.put("eventType", "Meal Bolus");
|
||||||
|
@ -436,10 +437,10 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
data.put("eventType", "Note");
|
data.put("eventType", "Note");
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_profileswitch:
|
case R.id.careportal_profileswitch:
|
||||||
data.put("eventType", "Profile Switch");
|
data.put("eventType", CareportalEvent.PROFILESWITCH);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_pumpsitechange:
|
case R.id.careportal_pumpsitechange:
|
||||||
data.put("eventType", "Site Change");
|
data.put("eventType", CareportalEvent.SITECHANGE);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_question:
|
case R.id.careportal_question:
|
||||||
data.put("eventType", "Question");
|
data.put("eventType", "Question");
|
||||||
|
@ -448,10 +449,10 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
data.put("eventType", "Snack Bolus");
|
data.put("eventType", "Snack Bolus");
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_tempbasalstart:
|
case R.id.careportal_tempbasalstart:
|
||||||
data.put("eventType", "Temp Basal");
|
data.put("eventType", CareportalEvent.TEMPBASAL);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_tempbasalend:
|
case R.id.careportal_tempbasalend:
|
||||||
data.put("eventType", "Temp Basal");
|
data.put("eventType", CareportalEvent.TEMPBASAL);
|
||||||
break;
|
break;
|
||||||
case R.id.careportal_openapsoffline:
|
case R.id.careportal_openapsoffline:
|
||||||
data.put("eventType", "OpenAPS Offline");
|
data.put("eventType", "OpenAPS Offline");
|
||||||
|
|
|
@ -25,6 +25,7 @@ import info.nightscout.androidaps.Services.Intents;
|
||||||
import info.nightscout.androidaps.data.IobTotal;
|
import info.nightscout.androidaps.data.IobTotal;
|
||||||
import info.nightscout.androidaps.data.MealData;
|
import info.nightscout.androidaps.data.MealData;
|
||||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||||
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.TempTarget;
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
|
@ -834,7 +835,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
try {
|
try {
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
data.put("eventType", "Temp Basal");
|
data.put("eventType", CareportalEvent.TEMPBASAL);
|
||||||
data.put("duration", durationInMinutes);
|
data.put("duration", durationInMinutes);
|
||||||
data.put("absolute", absolute);
|
data.put("absolute", absolute);
|
||||||
data.put("created_at", DateUtil.toISOString(new Date()));
|
data.put("created_at", DateUtil.toISOString(new Date()));
|
||||||
|
@ -886,7 +887,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
} else {
|
} else {
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
data.put("eventType", "Temp Basal");
|
data.put("eventType", CareportalEvent.TEMPBASAL);
|
||||||
data.put("duration", durationInMinutes);
|
data.put("duration", durationInMinutes);
|
||||||
data.put("percent", percent - 100);
|
data.put("percent", percent - 100);
|
||||||
data.put("created_at", DateUtil.toISOString(new Date()));
|
data.put("created_at", DateUtil.toISOString(new Date()));
|
||||||
|
@ -911,7 +912,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
try {
|
try {
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
data.put("eventType", "Temp Basal");
|
data.put("eventType", CareportalEvent.TEMPBASAL);
|
||||||
data.put("created_at", DateUtil.toISOString(new Date()));
|
data.put("created_at", DateUtil.toISOString(new Date()));
|
||||||
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
|
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
|
||||||
data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalendnote)); // ECOR
|
data.put("notes", MainApp.sResources.getString(R.string.androidaps_tempbasalendnote)); // ECOR
|
||||||
|
@ -933,7 +934,7 @@ public class ConfigBuilderPlugin implements PluginBase, PumpInterface, Constrain
|
||||||
try {
|
try {
|
||||||
Context context = MainApp.instance().getApplicationContext();
|
Context context = MainApp.instance().getApplicationContext();
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
data.put("eventType", "Combo Bolus");
|
data.put("eventType", CareportalEvent.COMBOBOLUS);
|
||||||
data.put("duration", durationInMinutes);
|
data.put("duration", durationInMinutes);
|
||||||
data.put("splitNow", 0);
|
data.put("splitNow", 0);
|
||||||
data.put("splitExt", 100);
|
data.put("splitExt", 100);
|
||||||
|
|
|
@ -89,7 +89,7 @@ public class NSClientService extends Service {
|
||||||
static public String nsURL = "";
|
static public String nsURL = "";
|
||||||
private String nsAPISecret = "";
|
private String nsAPISecret = "";
|
||||||
private String nsDevice = "";
|
private String nsDevice = "";
|
||||||
private Integer nsHours = 24;
|
private Integer nsHours = 48;
|
||||||
|
|
||||||
private final Integer timeToWaitForResponseInMs = 30000;
|
private final Integer timeToWaitForResponseInMs = 30000;
|
||||||
private boolean uploading = false;
|
private boolean uploading = false;
|
||||||
|
|
|
@ -229,7 +229,7 @@ public class DanaRFragment extends Fragment {
|
||||||
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
|
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
|
||||||
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
|
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
|
||||||
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h");
|
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(getPlugin().getBaseBasalRate()) + " U/h");
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
if (MainApp.getConfigBuilder().isRealTempBasalInProgress()) {
|
||||||
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString());
|
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString());
|
||||||
} else {
|
} else {
|
||||||
tempBasalView.setText("");
|
tempBasalView.setText("");
|
||||||
|
|
|
@ -10,6 +10,7 @@ import java.util.List;
|
||||||
|
|
||||||
import info.nightscout.androidaps.MainApp;
|
import info.nightscout.androidaps.MainApp;
|
||||||
import info.nightscout.androidaps.R;
|
import info.nightscout.androidaps.R;
|
||||||
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
import info.nightscout.androidaps.db.DanaRHistoryRecord;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||||
|
@ -81,7 +82,7 @@ public class DanaRNSHistorySync {
|
||||||
if (record.recordDuration > 0) {
|
if (record.recordDuration > 0) {
|
||||||
log.debug("Syncing extended bolus record " + record.recordValue + "U " + DateUtil.toISOString(record.recordDate));
|
log.debug("Syncing extended bolus record " + record.recordValue + "U " + DateUtil.toISOString(record.recordDate));
|
||||||
nsrec.put(DANARSIGNATURE, record.bytes);
|
nsrec.put(DANARSIGNATURE, record.bytes);
|
||||||
nsrec.put("eventType", "Combo Bolus");
|
nsrec.put("eventType", CareportalEvent.COMBOBOLUS);
|
||||||
nsrec.put("insulin", 0);
|
nsrec.put("insulin", 0);
|
||||||
nsrec.put("duration", record.recordDuration);
|
nsrec.put("duration", record.recordDuration);
|
||||||
nsrec.put("relative", record.recordValue / record.recordDuration * 60);
|
nsrec.put("relative", record.recordValue / record.recordDuration * 60);
|
||||||
|
@ -101,7 +102,7 @@ public class DanaRNSHistorySync {
|
||||||
case "DS":
|
case "DS":
|
||||||
log.debug("Syncing dual(S) bolus record " + record.recordValue + "U " + DateUtil.toISOString(record.recordDate));
|
log.debug("Syncing dual(S) bolus record " + record.recordValue + "U " + DateUtil.toISOString(record.recordDate));
|
||||||
nsrec.put(DANARSIGNATURE, record.bytes);
|
nsrec.put(DANARSIGNATURE, record.bytes);
|
||||||
nsrec.put("eventType", "Combo Bolus");
|
nsrec.put("eventType", CareportalEvent.COMBOBOLUS);
|
||||||
nsrec.put("insulin", record.recordValue);
|
nsrec.put("insulin", record.recordValue);
|
||||||
nsrec.put("splitNow", 100);
|
nsrec.put("splitNow", 100);
|
||||||
nsrec.put("splitExt", 0);
|
nsrec.put("splitExt", 0);
|
||||||
|
@ -114,7 +115,7 @@ public class DanaRNSHistorySync {
|
||||||
case "DE":
|
case "DE":
|
||||||
log.debug("Syncing dual(E) bolus record " + record.recordValue + "U " + DateUtil.toISOString(record.recordDate));
|
log.debug("Syncing dual(E) bolus record " + record.recordValue + "U " + DateUtil.toISOString(record.recordDate));
|
||||||
nsrec.put(DANARSIGNATURE, record.bytes);
|
nsrec.put(DANARSIGNATURE, record.bytes);
|
||||||
nsrec.put("eventType", "Combo Bolus");
|
nsrec.put("eventType", CareportalEvent.COMBOBOLUS);
|
||||||
nsrec.put("duration", record.recordDuration);
|
nsrec.put("duration", record.recordDuration);
|
||||||
nsrec.put("relative", record.recordValue / record.recordDuration * 60);
|
nsrec.put("relative", record.recordValue / record.recordDuration * 60);
|
||||||
nsrec.put("splitNow", 0);
|
nsrec.put("splitNow", 0);
|
||||||
|
@ -160,7 +161,7 @@ public class DanaRNSHistorySync {
|
||||||
if ((what & SYNC_BASALHOURS) == 0) break;
|
if ((what & SYNC_BASALHOURS) == 0) break;
|
||||||
log.debug("Syncing basal hour record " + record.recordValue + " " + DateUtil.toISOString(record.recordDate));
|
log.debug("Syncing basal hour record " + record.recordValue + " " + DateUtil.toISOString(record.recordDate));
|
||||||
nsrec.put(DANARSIGNATURE, record.bytes);
|
nsrec.put(DANARSIGNATURE, record.bytes);
|
||||||
nsrec.put("eventType", "Temp Basal");
|
nsrec.put("eventType", CareportalEvent.TEMPBASAL);
|
||||||
nsrec.put("absolute", record.recordValue);
|
nsrec.put("absolute", record.recordValue);
|
||||||
nsrec.put("duration", 60);
|
nsrec.put("duration", 60);
|
||||||
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
|
nsrec.put("created_at", DateUtil.toISOString(record.recordDate));
|
||||||
|
|
|
@ -228,7 +228,7 @@ public class DanaRKoreanFragment extends Fragment {
|
||||||
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
|
dailyUnitsView.setText(DecimalFormatter.to0Decimal(pump.dailyTotalUnits) + " / " + pump.maxDailyTotalUnits + " U");
|
||||||
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
|
SetWarnColor.setColor(dailyUnitsView, pump.dailyTotalUnits, pump.maxDailyTotalUnits * 0.75d, pump.maxDailyTotalUnits * 0.9d);
|
||||||
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(danaRKoreanPlugin.getBaseBasalRate()) + " U/h");
|
basaBasalRateView.setText("( " + (pump.activeProfile + 1) + " ) " + DecimalFormatter.to2Decimal(danaRKoreanPlugin.getBaseBasalRate()) + " U/h");
|
||||||
if (MainApp.getConfigBuilder().isTempBasalInProgress()) {
|
if (MainApp.getConfigBuilder().isRealTempBasalInProgress()) {
|
||||||
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString());
|
tempBasalView.setText(MainApp.getConfigBuilder().getRealTempBasal(new Date().getTime()).toString());
|
||||||
} else {
|
} else {
|
||||||
tempBasalView.setText("");
|
tempBasalView.setText("");
|
||||||
|
|
|
@ -10,6 +10,17 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<include
|
||||||
|
layout="@layout/careportal_stats_fragment"
|
||||||
|
layout_width="match_parent"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content" />
|
||||||
|
|
||||||
<android.support.v7.widget.GridLayout
|
<android.support.v7.widget.GridLayout
|
||||||
android:layout_width="fill_parent"
|
android:layout_width="fill_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
@ -227,5 +238,6 @@
|
||||||
app:layout_row="6" />
|
app:layout_row="6" />
|
||||||
|
|
||||||
</android.support.v7.widget.GridLayout>
|
</android.support.v7.widget.GridLayout>
|
||||||
|
</LinearLayout>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
</FrameLayout>
|
</FrameLayout>
|
||||||
|
|
153
app/src/main/res/layout/careportal_stats_fragment.xml
Normal file
153
app/src/main/res/layout/careportal_stats_fragment.xml
Normal file
|
@ -0,0 +1,153 @@
|
||||||
|
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
tools:context="info.nightscout.androidaps.plugins.Careportal.CareportalFragment">
|
||||||
|
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginTop="20dp"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="end"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:text="@string/careportal_sensorage_label"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="5dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:paddingEnd="2dp"
|
||||||
|
android:paddingStart="2dp"
|
||||||
|
android:text=":"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/careportal_sensorage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="start"
|
||||||
|
android:paddingLeft="5dp"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="2dip"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:layout_marginLeft="20dp"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:background="@color/listdelimiter" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="end"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:text="@string/careportal_insulinage_label"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="5dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:paddingEnd="2dp"
|
||||||
|
android:paddingStart="2dp"
|
||||||
|
android:text=":"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/careportal_insulinage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="start"
|
||||||
|
android:paddingLeft="5dp"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="2dip"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:layout_marginLeft="20dp"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:background="@color/listdelimiter" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="end"
|
||||||
|
android:paddingRight="5dp"
|
||||||
|
android:text="@string/careportal_canulaage_label"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:layout_width="5dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="0"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:paddingEnd="2dp"
|
||||||
|
android:paddingStart="2dp"
|
||||||
|
android:text=":"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/careportal_canulaage"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="start"
|
||||||
|
android:paddingLeft="5dp"
|
||||||
|
android:textColor="@android:color/white"
|
||||||
|
android:textSize="14sp" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="fill_parent"
|
||||||
|
android:layout_height="2dip"
|
||||||
|
android:layout_marginBottom="5dp"
|
||||||
|
android:layout_marginLeft="20dp"
|
||||||
|
android:layout_marginRight="20dp"
|
||||||
|
android:layout_marginTop="5dp"
|
||||||
|
android:background="@color/listdelimiter" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</FrameLayout>
|
|
@ -615,4 +615,8 @@
|
||||||
<string name="extendedbolus">ExtendedBolus</string>
|
<string name="extendedbolus">ExtendedBolus</string>
|
||||||
<string name="temptarget">TempTarget</string>
|
<string name="temptarget">TempTarget</string>
|
||||||
<string name="overview_extendedbolus_cancel_button">Cancel Extended Bolus</string>
|
<string name="overview_extendedbolus_cancel_button">Cancel Extended Bolus</string>
|
||||||
|
<string name="careportal_sensorage_label">Sensor age</string>
|
||||||
|
<string name="careportal_canulaage_label">Canula age</string>
|
||||||
|
<string name="careportal_insulinage_label">Insulin age</string>
|
||||||
|
<string name="hours">hours</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue