danar history db support

This commit is contained in:
Milos Kozak 2016-07-21 15:10:42 +02:00
parent 1c0edb151e
commit 73ef2d7684
9 changed files with 80 additions and 86 deletions

View file

@ -20,6 +20,7 @@ public class Constants {
public static final Integer notificationID = 556677; public static final Integer notificationID = 556677;
public static final int hoursToKeepInDatabase = 72; public static final int hoursToKeepInDatabase = 72;
public static final int daysToKeepHistoryInDatabase = 30;
public static final long keepAliveMsecs = 30 * 60 * 1000L; public static final long keepAliveMsecs = 30 * 60 * 1000L;

View file

@ -13,7 +13,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.client.data.NSSgv; import info.nightscout.client.data.NSSgv;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
@DatabaseTable(tableName = "BgReadings") @DatabaseTable(tableName = DatabaseHelper.DATABASE_BGREADINGS)
public class BgReading implements DataPointInterface { public class BgReading implements DataPointInterface {
private static Logger log = LoggerFactory.getLogger(BgReading.class); private static Logger log = LoggerFactory.getLogger(BgReading.class);

View file

@ -5,8 +5,8 @@ import com.j256.ormlite.table.DatabaseTable;
import java.util.Date; import java.util.Date;
@DatabaseTable(tableName = "History") @DatabaseTable(tableName = DatabaseHelper.DATABASE_DANARHISTORY)
public class HistoryRecord { public class DanaRHistoryRecord {
@DatabaseField(useGetSet = true) @DatabaseField(useGetSet = true)
private String _id; private String _id;
@ -41,7 +41,7 @@ public class HistoryRecord {
@DatabaseField(useGetSet = true) @DatabaseField(useGetSet = true)
private String recordAlarm; private String recordAlarm;
public HistoryRecord() { public DanaRHistoryRecord() {
this.recordDate = 0; this.recordDate = 0;
this.recordValue = 0.0; this.recordValue = 0.0;
this.bolusType = "None"; this.bolusType = "None";

View file

@ -38,6 +38,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
private static Logger log = LoggerFactory.getLogger(DatabaseHelper.class); private static Logger log = LoggerFactory.getLogger(DatabaseHelper.class);
public static final String DATABASE_NAME = "AndroidAPSDb"; 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_TREATMENTS = "Treatments";
public static final String DATABASE_DANARHISTORY = "DanaRHistory";
private static final int DATABASE_VERSION = 2; private static final int DATABASE_VERSION = 2;
@ -53,7 +57,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
TableUtils.createTableIfNotExists(connectionSource, TempBasal.class); TableUtils.createTableIfNotExists(connectionSource, TempBasal.class);
TableUtils.createTableIfNotExists(connectionSource, Treatment.class); TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
TableUtils.createTableIfNotExists(connectionSource, BgReading.class); TableUtils.createTableIfNotExists(connectionSource, BgReading.class);
TableUtils.createTableIfNotExists(connectionSource, HistoryRecord.class); TableUtils.createTableIfNotExists(connectionSource, DanaRHistoryRecord.class);
} catch (SQLException e) { } catch (SQLException e) {
log.error(DatabaseHelper.class.getName(), "Can't create database", e); log.error(DatabaseHelper.class.getName(), "Can't create database", e);
throw new RuntimeException(e); throw new RuntimeException(e);
@ -67,7 +71,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
TableUtils.dropTable(connectionSource, TempBasal.class, true); TableUtils.dropTable(connectionSource, TempBasal.class, true);
TableUtils.dropTable(connectionSource, Treatment.class, true); TableUtils.dropTable(connectionSource, Treatment.class, true);
TableUtils.dropTable(connectionSource, BgReading.class, true); TableUtils.dropTable(connectionSource, BgReading.class, true);
TableUtils.dropTable(connectionSource, HistoryRecord.class, true); TableUtils.dropTable(connectionSource, DanaRHistoryRecord.class, true);
onCreate(database, connectionSource); onCreate(database, connectionSource);
} catch (SQLException e) { } catch (SQLException e) {
log.error(DatabaseHelper.class.getName(), "Can't drop databases", e); log.error(DatabaseHelper.class.getName(), "Can't drop databases", e);
@ -85,21 +89,21 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void cleanUpDatabases() { public void cleanUpDatabases() {
// TODO: call it somewhere // TODO: call it somewhere
log.debug("Before BgReadings size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "BgReadings")); log.debug("Before BgReadings size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_BGREADINGS));
getWritableDatabase().delete("BgReadings", "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null); getWritableDatabase().delete("BgReadings", "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
log.debug("After BgReadings size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "BgReadings")); log.debug("After BgReadings size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_BGREADINGS));
log.debug("Before TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "TempBasals")); log.debug("Before TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TEMPBASALS));
getWritableDatabase().delete("TempBasals", "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null); getWritableDatabase().delete("TempBasals", "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
log.debug("After TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "TempBasals")); log.debug("After TempBasals size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TEMPBASALS));
log.debug("Before Treatments size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "Treatments")); log.debug("Before Treatments size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TREATMENTS));
getWritableDatabase().delete("Treatments", "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null); getWritableDatabase().delete("Treatments", "timeIndex" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null);
log.debug("After Treatments size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "Treatments")); log.debug("After Treatments size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_TREATMENTS));
log.debug("Before History size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "History")); log.debug("Before History size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_DANARHISTORY));
getWritableDatabase().delete("History", "recordDate" + " < '" + (new Date().getTime() - Constants.hoursToKeepInDatabase * 60 * 60 * 1000L) + "'", null); getWritableDatabase().delete("History", "recordDate" + " < '" + (new Date().getTime() - Constants.daysToKeepHistoryInDatabase * 24 * 60 * 60 * 1000L) + "'", null);
log.debug("After History size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), "History")); log.debug("After History size: " + DatabaseUtils.queryNumEntries(getReadableDatabase(), DATABASE_DANARHISTORY));
} }
public void resetDatabases() { public void resetDatabases() {
@ -107,11 +111,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
TableUtils.dropTable(connectionSource, TempBasal.class, true); TableUtils.dropTable(connectionSource, TempBasal.class, true);
TableUtils.dropTable(connectionSource, Treatment.class, true); TableUtils.dropTable(connectionSource, Treatment.class, true);
TableUtils.dropTable(connectionSource, BgReading.class, true); TableUtils.dropTable(connectionSource, BgReading.class, true);
TableUtils.dropTable(connectionSource, HistoryRecord.class, true); TableUtils.dropTable(connectionSource, DanaRHistoryRecord.class, true);
TableUtils.createTableIfNotExists(connectionSource, TempBasal.class); TableUtils.createTableIfNotExists(connectionSource, TempBasal.class);
TableUtils.createTableIfNotExists(connectionSource, Treatment.class); TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
TableUtils.createTableIfNotExists(connectionSource, BgReading.class); TableUtils.createTableIfNotExists(connectionSource, BgReading.class);
TableUtils.createTableIfNotExists(connectionSource, HistoryRecord.class); TableUtils.createTableIfNotExists(connectionSource, DanaRHistoryRecord.class);
MainApp.bus().post(new EventNewBG()); MainApp.bus().post(new EventNewBG());
MainApp.bus().post(new EventTreatmentChange()); MainApp.bus().post(new EventTreatmentChange());
MainApp.bus().post(new EventTempBasalChange()); MainApp.bus().post(new EventTempBasalChange());
@ -142,8 +146,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return getDao(BgReading.class); return getDao(BgReading.class);
} }
public Dao<HistoryRecord, String> getDaoHistory() throws SQLException { public Dao<DanaRHistoryRecord, String> getDaoHistory() throws SQLException {
return getDao(HistoryRecord.class); return getDao(DanaRHistoryRecord.class);
} }
/* /*

View file

@ -16,7 +16,7 @@ import info.nightscout.androidaps.plugins.OpenAPSMA.IobTotal;
import info.nightscout.client.data.NSProfile; import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
@DatabaseTable(tableName = "TempBasals") @DatabaseTable(tableName = DatabaseHelper.DATABASE_TEMPBASALS)
public class TempBasal { public class TempBasal {
private static Logger log = LoggerFactory.getLogger(TempBasal.class); private static Logger log = LoggerFactory.getLogger(TempBasal.class);

View file

@ -19,7 +19,7 @@ import info.nightscout.client.data.NSProfile;
import info.nightscout.utils.DateUtil; import info.nightscout.utils.DateUtil;
import info.nightscout.utils.DecimalFormatter; import info.nightscout.utils.DecimalFormatter;
@DatabaseTable(tableName = "Treatments") @DatabaseTable(tableName = DatabaseHelper.DATABASE_TREATMENTS)
public class Treatment implements DataPointWithLabelInterface { public class Treatment implements DataPointWithLabelInterface {
private static Logger log = LoggerFactory.getLogger(Treatment.class); private static Logger log = LoggerFactory.getLogger(Treatment.class);

View file

@ -1,12 +1,5 @@
package info.nightscout.androidaps.plugins.DanaR.History; package info.nightscout.androidaps.plugins.DanaR.History;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.ResolveInfo;
import android.os.Bundle;
import android.preference.PreferenceManager;
import com.j256.ormlite.dao.Dao; import com.j256.ormlite.dao.Dao;
import org.json.JSONException; import org.json.JSONException;
@ -15,13 +8,11 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.sql.SQLException; import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.Calendar; import java.util.Calendar;
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.HistoryRecord; import info.nightscout.androidaps.db.DanaRHistoryRecord;
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment; import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderFragment;
import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes; import info.nightscout.androidaps.plugins.DanaR.comm.RecordTypes;
import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus; import info.nightscout.androidaps.plugins.DanaR.events.EventDanaRSyncStatus;
@ -35,7 +26,7 @@ import info.nightscout.utils.ToastUtils;
public class NSHistorySync { public class NSHistorySync {
private static Logger log = LoggerFactory.getLogger(NSHistorySync.class); private static Logger log = LoggerFactory.getLogger(NSHistorySync.class);
private Dao<HistoryRecord, String> daoHistoryRecords; private Dao<DanaRHistoryRecord, String> daoHistoryRecords;
public final int SYNC_BOLUS = 0b00000001; public final int SYNC_BOLUS = 0b00000001;
public final int SYNC_ERROR = 0b00000010; public final int SYNC_ERROR = 0b00000010;
@ -46,7 +37,7 @@ public class NSHistorySync {
public final int SYNC_BASALOURS = 0b01000000; public final int SYNC_BASALOURS = 0b01000000;
public final int SYNC_ALL = 0b11111111; public final int SYNC_ALL = 0b11111111;
public NSHistorySync(Dao<HistoryRecord, String> daoHistoryRecords) { public NSHistorySync(Dao<DanaRHistoryRecord, String> daoHistoryRecords) {
this.daoHistoryRecords = daoHistoryRecords; this.daoHistoryRecords = daoHistoryRecords;
} }
@ -65,7 +56,7 @@ public class NSHistorySync {
long uploaded = 0; long uploaded = 0;
log.debug("Database contains " + records + " records"); log.debug("Database contains " + records + " records");
EventDanaRSyncStatus ev = new EventDanaRSyncStatus(); EventDanaRSyncStatus ev = new EventDanaRSyncStatus();
for (HistoryRecord record : daoHistoryRecords) { for (DanaRHistoryRecord record : daoHistoryRecords) {
processing++; processing++;
if (record.get_id() != null) continue; if (record.get_id() != null) continue;
//log.debug(record.getBytes()); //log.debug(record.getBytes());
@ -77,19 +68,19 @@ public class NSHistorySync {
switch (record.getBolusType()) { switch (record.getBolusType()) {
case "S": case "S":
log.debug("Syncing standard bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate())); log.debug("Syncing standard bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put("danarMessage", record.getBytes()); nsrec.put("DANARMESSAGE", record.getBytes());
nsrec.put("eventType", "Meal Bolus"); nsrec.put("eventType", "Meal Bolus");
nsrec.put("insulin", record.getRecordValue()); nsrec.put("insulin", record.getRecordValue());
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate())); nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name)); nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
configBuilderFragment.uploadCareportalEntryToNS(nsrec); ConfigBuilderFragment.uploadCareportalEntryToNS(nsrec);
uploaded++; uploaded++;
ev.message += "S bolus"; ev.message += "S bolus";
break; break;
case "E": case "E":
if (record.getRecordDuration() > 0) { if (record.getRecordDuration() > 0) {
log.debug("Syncing extended bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate())); log.debug("Syncing extended bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put("danarMessage", record.getBytes()); nsrec.put("DANARMESSAGE", record.getBytes());
nsrec.put("eventType", "Combo Bolus"); nsrec.put("eventType", "Combo Bolus");
nsrec.put("insulin", 0); nsrec.put("insulin", 0);
nsrec.put("duration", record.getRecordDuration()); nsrec.put("duration", record.getRecordDuration());
@ -100,7 +91,7 @@ public class NSHistorySync {
cal.add(Calendar.MINUTE, -1 * record.getRecordDuration()); cal.add(Calendar.MINUTE, -1 * record.getRecordDuration());
nsrec.put("created_at", DateUtil.toISOString(cal.getTime())); nsrec.put("created_at", DateUtil.toISOString(cal.getTime()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name)); nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
configBuilderFragment.uploadCareportalEntryToNS(nsrec); ConfigBuilderFragment.uploadCareportalEntryToNS(nsrec);
uploaded++; uploaded++;
ev.message += "E bolus"; ev.message += "E bolus";
} else { } else {
@ -109,20 +100,20 @@ public class NSHistorySync {
break; break;
case "DS": case "DS":
log.debug("Syncing dual(S) bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate())); log.debug("Syncing dual(S) bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put("danarMessage", record.getBytes()); nsrec.put("DANARMESSAGE", record.getBytes());
nsrec.put("eventType", "Combo Bolus"); nsrec.put("eventType", "Combo Bolus");
nsrec.put("insulin", record.getRecordValue()); nsrec.put("insulin", record.getRecordValue());
nsrec.put("splitNow", 100); nsrec.put("splitNow", 100);
nsrec.put("splitExt", 0); nsrec.put("splitExt", 0);
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate())); nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name)); nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
configBuilderFragment.uploadCareportalEntryToNS(nsrec); ConfigBuilderFragment.uploadCareportalEntryToNS(nsrec);
uploaded++; uploaded++;
ev.message += "DS bolus"; ev.message += "DS bolus";
break; break;
case "DE": case "DE":
log.debug("Syncing dual(E) bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate())); log.debug("Syncing dual(E) bolus record " + record.getRecordValue() + "U " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put("danarMessage", record.getBytes()); nsrec.put("DANARMESSAGE", record.getBytes());
nsrec.put("eventType", "Combo Bolus"); nsrec.put("eventType", "Combo Bolus");
nsrec.put("duration", record.getRecordDuration()); nsrec.put("duration", record.getRecordDuration());
nsrec.put("relative", record.getRecordValue() / record.getRecordDuration() * 60); nsrec.put("relative", record.getRecordValue() / record.getRecordDuration() * 60);
@ -132,7 +123,7 @@ public class NSHistorySync {
cal.add(Calendar.MINUTE, -1 * record.getRecordDuration()); cal.add(Calendar.MINUTE, -1 * record.getRecordDuration());
nsrec.put("created_at", DateUtil.toISOString(cal.getTime())); nsrec.put("created_at", DateUtil.toISOString(cal.getTime()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name)); nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
configBuilderFragment.uploadCareportalEntryToNS(nsrec); ConfigBuilderFragment.uploadCareportalEntryToNS(nsrec);
uploaded++; uploaded++;
ev.message += "DE bolus"; ev.message += "DE bolus";
break; break;
@ -144,37 +135,37 @@ public class NSHistorySync {
case RecordTypes.RECORD_TYPE_ERROR: case RecordTypes.RECORD_TYPE_ERROR:
if ((what & SYNC_ERROR) == 0) break; if ((what & SYNC_ERROR) == 0) break;
log.debug("Syncing error record " + DateUtil.toISOString(record.getRecordDate())); log.debug("Syncing error record " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put("danarMessage", record.getBytes()); nsrec.put("DANARMESSAGE", record.getBytes());
nsrec.put("eventType", "Note"); nsrec.put("eventType", "Note");
nsrec.put("notes", "Error"); nsrec.put("notes", "Error");
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate())); nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name)); nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
configBuilderFragment.uploadCareportalEntryToNS(nsrec); ConfigBuilderFragment.uploadCareportalEntryToNS(nsrec);
uploaded++; uploaded++;
ev.message += "error"; ev.message += "error";
break; break;
case RecordTypes.RECORD_TYPE_REFILL: case RecordTypes.RECORD_TYPE_REFILL:
if ((what & SYNC_REFILL) == 0) break; if ((what & SYNC_REFILL) == 0) break;
log.debug("Syncing refill record " + record.getRecordValue() + " " + DateUtil.toISOString(record.getRecordDate())); log.debug("Syncing refill record " + record.getRecordValue() + " " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put("danarMessage", record.getBytes()); nsrec.put("DANARMESSAGE", record.getBytes());
nsrec.put("eventType", "Insulin Change"); nsrec.put("eventType", "Insulin Change");
nsrec.put("notes", "Refill " + record.getRecordValue() + "U"); nsrec.put("notes", "Refill " + record.getRecordValue() + "U");
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate())); nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name)); nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
configBuilderFragment.uploadCareportalEntryToNS(nsrec); ConfigBuilderFragment.uploadCareportalEntryToNS(nsrec);
uploaded++; uploaded++;
ev.message += "refill"; ev.message += "refill";
break; break;
case RecordTypes.RECORD_TYPE_BASALHOUR: case RecordTypes.RECORD_TYPE_BASALHOUR:
if ((what & SYNC_BASALOURS) == 0) break; if ((what & SYNC_BASALOURS) == 0) break;
log.debug("Syncing basal hour record " + record.getRecordValue() + " " + DateUtil.toISOString(record.getRecordDate())); log.debug("Syncing basal hour record " + record.getRecordValue() + " " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put("danarMessage", record.getBytes()); nsrec.put("DANARMESSAGE", record.getBytes());
nsrec.put("eventType", "Temp Basal"); nsrec.put("eventType", "Temp Basal");
nsrec.put("absolute", record.getRecordValue()); nsrec.put("absolute", record.getRecordValue());
nsrec.put("duration", 60); nsrec.put("duration", 60);
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate())); nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name)); nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
configBuilderFragment.uploadCareportalEntryToNS(nsrec); ConfigBuilderFragment.uploadCareportalEntryToNS(nsrec);
uploaded++; uploaded++;
ev.message += "basal hour"; ev.message += "basal hour";
break; break;
@ -184,43 +175,43 @@ public class NSHistorySync {
case RecordTypes.RECORD_TYPE_GLUCOSE: case RecordTypes.RECORD_TYPE_GLUCOSE:
if ((what & SYNC_GLUCOSE) == 0) break; if ((what & SYNC_GLUCOSE) == 0) break;
log.debug("Syncing glucose record " + record.getRecordValue() + " " + DateUtil.toISOString(record.getRecordDate())); log.debug("Syncing glucose record " + record.getRecordValue() + " " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put("danarMessage", record.getBytes()); nsrec.put("DANARMESSAGE", record.getBytes());
nsrec.put("eventType", "BG Check"); nsrec.put("eventType", "BG Check");
nsrec.put("glucose", NSProfile.fromMgdlToUnits(record.getRecordValue(), profile.getUnits())); nsrec.put("glucose", NSProfile.fromMgdlToUnits(record.getRecordValue(), profile.getUnits()));
nsrec.put("glucoseType", "Finger"); nsrec.put("glucoseType", "Finger");
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate())); nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name)); nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
configBuilderFragment.uploadCareportalEntryToNS(nsrec); ConfigBuilderFragment.uploadCareportalEntryToNS(nsrec);
uploaded++; uploaded++;
ev.message += "glucose"; ev.message += "glucose";
break; break;
case RecordTypes.RECORD_TYPE_CARBO: case RecordTypes.RECORD_TYPE_CARBO:
if ((what & SYNC_CARBO) == 0) break; if ((what & SYNC_CARBO) == 0) break;
log.debug("Syncing carbo record " + record.getRecordValue() + "g " + DateUtil.toISOString(record.getRecordDate())); log.debug("Syncing carbo record " + record.getRecordValue() + "g " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put("danarMessage", record.getBytes()); nsrec.put("DANARMESSAGE", record.getBytes());
nsrec.put("eventType", "Meal Bolus"); nsrec.put("eventType", "Meal Bolus");
nsrec.put("carbs", record.getRecordValue()); nsrec.put("carbs", record.getRecordValue());
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate())); nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name)); nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
configBuilderFragment.uploadCareportalEntryToNS(nsrec); ConfigBuilderFragment.uploadCareportalEntryToNS(nsrec);
uploaded++; uploaded++;
ev.message += "carbo"; ev.message += "carbo";
break; break;
case RecordTypes.RECORD_TYPE_ALARM: case RecordTypes.RECORD_TYPE_ALARM:
if ((what & SYNC_ALARM) == 0) break; if ((what & SYNC_ALARM) == 0) break;
log.debug("Syncing alarm record " + record.getRecordAlarm() + " " + DateUtil.toISOString(record.getRecordDate())); log.debug("Syncing alarm record " + record.getRecordAlarm() + " " + DateUtil.toISOString(record.getRecordDate()));
nsrec.put("danarMessage", record.getBytes()); nsrec.put("DANARMESSAGE", record.getBytes());
nsrec.put("eventType", "Note"); nsrec.put("eventType", "Note");
nsrec.put("notes", "Alarm: " + record.getRecordAlarm()); nsrec.put("notes", "Alarm: " + record.getRecordAlarm());
nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate())); nsrec.put("created_at", DateUtil.toISOString(record.getRecordDate()));
nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name)); nsrec.put("enteredBy", MainApp.sResources.getString(R.string.app_name));
configBuilderFragment.uploadCareportalEntryToNS(nsrec); ConfigBuilderFragment.uploadCareportalEntryToNS(nsrec);
uploaded++; uploaded++;
ev.message += "alarm"; ev.message += "alarm";
break; break;
case RecordTypes.RECORD_TYPE_SUSPEND: // TODO: this too
case RecordTypes.RECORD_TYPE_DAILY: case RecordTypes.RECORD_TYPE_DAILY:
case RecordTypes.RECORD_TYPE_PRIME: case RecordTypes.RECORD_TYPE_PRIME:
case RecordTypes.RECORD_TYPE_SUSPEND:
// Ignore // Ignore
break; break;
default: default:
@ -232,10 +223,8 @@ public class NSHistorySync {
ev.message = "Total " + uploaded + " records uploaded"; ev.message = "Total " + uploaded + " records uploaded";
MainApp.bus().post(ev); MainApp.bus().post(ev);
} catch (JSONException e) { } catch (JSONException | SQLException e) {
log.error(e.getMessage(), e); e.printStackTrace();
} catch (SQLException e) {
log.error(e.getMessage(), e);
} }
} }
} }

View file

@ -9,7 +9,7 @@ import java.sql.SQLException;
import java.util.Date; import java.util.Date;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.db.HistoryRecord; import info.nightscout.androidaps.db.DanaRHistoryRecord;
public class MsgHistoryAll extends MessageBase { public class MsgHistoryAll extends MessageBase {
private static Logger log = LoggerFactory.getLogger(MsgHistoryAll.class); private static Logger log = LoggerFactory.getLogger(MsgHistoryAll.class);
@ -31,54 +31,54 @@ public class MsgHistoryAll extends MessageBase {
byte paramByte8 = (byte) intFromBuff(bytes, 7, 1); byte paramByte8 = (byte) intFromBuff(bytes, 7, 1);
double value = (double) intFromBuff(bytes, 8, 2); double value = (double) intFromBuff(bytes, 8, 2);
HistoryRecord historyRecord = new HistoryRecord(); DanaRHistoryRecord danaRHistoryRecord = new DanaRHistoryRecord();
historyRecord.setRecordCode(recordCode); danaRHistoryRecord.setRecordCode(recordCode);
historyRecord.setBytes(bytes); danaRHistoryRecord.setBytes(bytes);
switch (recordCode) { switch (recordCode) {
case RecordTypes.RECORD_TYPE_BOLUS: case RecordTypes.RECORD_TYPE_BOLUS:
historyRecord.setRecordDate(datetime); danaRHistoryRecord.setRecordDate(datetime);
switch (0xF0 & paramByte8) { switch (0xF0 & paramByte8) {
case 0xA0: case 0xA0:
historyRecord.setBolusType("DS"); danaRHistoryRecord.setBolusType("DS");
break; break;
case 0xC0: case 0xC0:
historyRecord.setBolusType("E"); danaRHistoryRecord.setBolusType("E");
break; break;
case 0x80: case 0x80:
historyRecord.setBolusType("S"); danaRHistoryRecord.setBolusType("S");
break; break;
case 0x90: case 0x90:
historyRecord.setBolusType("DE"); danaRHistoryRecord.setBolusType("DE");
break; break;
default: default:
historyRecord.setBolusType("None"); danaRHistoryRecord.setBolusType("None");
break; break;
} }
historyRecord.setRecordDuration(((int) paramByte8 & 0x0F) * 60 + (int) paramByte7); danaRHistoryRecord.setRecordDuration(((int) paramByte8 & 0x0F) * 60 + (int) paramByte7);
historyRecord.setRecordValue(value * 0.01); danaRHistoryRecord.setRecordValue(value * 0.01);
break; break;
case RecordTypes.RECORD_TYPE_DAILY: case RecordTypes.RECORD_TYPE_DAILY:
historyRecord.setRecordDate(date); danaRHistoryRecord.setRecordDate(date);
historyRecord.setRecordDailyBasal((double) ((int) paramByte5 * 0xFF + (int) paramByte6) * 0.01); danaRHistoryRecord.setRecordDailyBasal((double) ((int) paramByte5 * 0xFF + (int) paramByte6) * 0.01);
historyRecord.setRecordDailyBolus((double) ((int) paramByte7 * 0xFF + (int) paramByte8) / 0.01); danaRHistoryRecord.setRecordDailyBolus((double) ((int) paramByte7 * 0xFF + (int) paramByte8) / 0.01);
break; break;
case RecordTypes.RECORD_TYPE_PRIME: case RecordTypes.RECORD_TYPE_PRIME:
case RecordTypes.RECORD_TYPE_ERROR: case RecordTypes.RECORD_TYPE_ERROR:
case RecordTypes.RECORD_TYPE_REFILL: case RecordTypes.RECORD_TYPE_REFILL:
case RecordTypes.RECORD_TYPE_BASALHOUR: case RecordTypes.RECORD_TYPE_BASALHOUR:
case RecordTypes.RECORD_TYPE_TB: case RecordTypes.RECORD_TYPE_TB:
historyRecord.setRecordDate(datetimewihtsec); danaRHistoryRecord.setRecordDate(datetimewihtsec);
historyRecord.setRecordValue(value * 0.01); danaRHistoryRecord.setRecordValue(value * 0.01);
break; break;
case RecordTypes.RECORD_TYPE_GLUCOSE: case RecordTypes.RECORD_TYPE_GLUCOSE:
case RecordTypes.RECORD_TYPE_CARBO: case RecordTypes.RECORD_TYPE_CARBO:
historyRecord.setRecordDate(datetimewihtsec); danaRHistoryRecord.setRecordDate(datetimewihtsec);
historyRecord.setRecordValue(value); danaRHistoryRecord.setRecordValue(value);
break; break;
case RecordTypes.RECORD_TYPE_ALARM: case RecordTypes.RECORD_TYPE_ALARM:
historyRecord.setRecordDate(datetimewihtsec); danaRHistoryRecord.setRecordDate(datetimewihtsec);
String strAlarm = "None"; String strAlarm = "None";
switch ((int) paramByte8) { switch ((int) paramByte8) {
case 67: case 67:
@ -94,21 +94,21 @@ public class MsgHistoryAll extends MessageBase {
strAlarm = "Shutdown"; strAlarm = "Shutdown";
break; break;
} }
historyRecord.setRecordAlarm(strAlarm); danaRHistoryRecord.setRecordAlarm(strAlarm);
historyRecord.setRecordValue(value * 0.01); danaRHistoryRecord.setRecordValue(value * 0.01);
break; break;
case RecordTypes.RECORD_TYPE_SUSPEND: case RecordTypes.RECORD_TYPE_SUSPEND:
historyRecord.setRecordDate(datetimewihtsec); danaRHistoryRecord.setRecordDate(datetimewihtsec);
String strRecordValue = "Off"; String strRecordValue = "Off";
if ((int) paramByte8 == 79) if ((int) paramByte8 == 79)
strRecordValue = "On"; strRecordValue = "On";
historyRecord.setStringRecordValue(strRecordValue); danaRHistoryRecord.setStringRecordValue(strRecordValue);
break; break;
} }
try { try {
Dao<HistoryRecord, String> daoHistoryRecords = MainApp.getDbHelper().getDaoHistory(); Dao<DanaRHistoryRecord, String> daoHistoryRecords = MainApp.getDbHelper().getDaoHistory();
daoHistoryRecords.createIfNotExists(historyRecord); daoHistoryRecords.createIfNotExists(danaRHistoryRecord);
} catch (SQLException e) { } catch (SQLException e) {
log.error(e.getMessage(), e); log.error(e.getMessage(), e);
} }

View file

@ -4,7 +4,7 @@ package info.nightscout.androidaps.plugins.DanaR.events;
* Created by mike on 20.07.2016. * Created by mike on 20.07.2016.
*/ */
public class EventDanaRSyncStatus { public class EventDanaRSyncStatus {
public static String message; public String message;
public EventDanaRSyncStatus() { public EventDanaRSyncStatus() {
} }