DanaHistoryDatabase
This commit is contained in:
parent
26c29b7185
commit
5747f97201
|
@ -4,8 +4,6 @@ import android.content.Context;
|
|||
import android.database.DatabaseUtils;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
|
||||
import com.j256.ormlite.dao.CloseableIterator;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
|
@ -20,9 +18,6 @@ import java.sql.SQLException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
|
@ -76,10 +71,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
|
||||
try {
|
||||
aapsLogger.info(LTag.DATABASE, "onCreate");
|
||||
TableUtils.createTableIfNotExists(connectionSource, DanaRHistoryRecord.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, DbRequest.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, InsightBolusID.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, InsightPumpID.class);
|
||||
|
@ -103,10 +95,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
|
||||
if (oldVersion < 7) {
|
||||
aapsLogger.info(LTag.DATABASE, "onUpgrade");
|
||||
TableUtils.dropTable(connectionSource, DanaRHistoryRecord.class, true);
|
||||
TableUtils.dropTable(connectionSource, DbRequest.class, true);
|
||||
TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
|
||||
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
|
||||
onCreate(database, connectionSource);
|
||||
} else if (oldVersion < 10) {
|
||||
TableUtils.createTableIfNotExists(connectionSource, InsightHistoryOffset.class);
|
||||
|
@ -149,15 +138,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
|
||||
public void resetDatabases() {
|
||||
try {
|
||||
TableUtils.dropTable(connectionSource, DanaRHistoryRecord.class, true);
|
||||
TableUtils.dropTable(connectionSource, DbRequest.class, true);
|
||||
TableUtils.dropTable(connectionSource, TemporaryBasal.class, true);
|
||||
TableUtils.dropTable(connectionSource, ExtendedBolus.class, true);
|
||||
TableUtils.dropTable(connectionSource, OmnipodHistoryRecord.class, true);
|
||||
TableUtils.createTableIfNotExists(connectionSource, DanaRHistoryRecord.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, DbRequest.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, TemporaryBasal.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, ExtendedBolus.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, OmnipodHistoryRecord.class);
|
||||
updateEarliestDataChange(0);
|
||||
} catch (SQLException e) {
|
||||
|
@ -177,22 +160,10 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
|
||||
// ------------------ getDao -------------------------------------------
|
||||
|
||||
private Dao<DanaRHistoryRecord, String> getDaoDanaRHistory() throws SQLException {
|
||||
return getDao(DanaRHistoryRecord.class);
|
||||
}
|
||||
|
||||
private Dao<DbRequest, String> getDaoDbRequest() throws SQLException {
|
||||
return getDao(DbRequest.class);
|
||||
}
|
||||
|
||||
private Dao<TemporaryBasal, Long> getDaoTemporaryBasal() throws SQLException {
|
||||
return getDao(TemporaryBasal.class);
|
||||
}
|
||||
|
||||
private Dao<ExtendedBolus, Long> getDaoExtendedBolus() throws SQLException {
|
||||
return getDao(ExtendedBolus.class);
|
||||
}
|
||||
|
||||
private Dao<InsightPumpID, Long> getDaoInsightPumpID() throws SQLException {
|
||||
return getDao(InsightPumpID.class);
|
||||
}
|
||||
|
@ -293,433 +264,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
}
|
||||
}
|
||||
|
||||
// ----------------- DanaRHistory handling --------------------
|
||||
|
||||
public void createOrUpdate(DanaRHistoryRecord record) {
|
||||
try {
|
||||
getDaoDanaRHistory().createOrUpdate(record);
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<DanaRHistoryRecord> getDanaRHistoryRecordsByType(byte type) {
|
||||
List<DanaRHistoryRecord> historyList;
|
||||
try {
|
||||
QueryBuilder<DanaRHistoryRecord, String> queryBuilder = getDaoDanaRHistory().queryBuilder();
|
||||
queryBuilder.orderBy("recordDate", false);
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("recordCode", type);
|
||||
queryBuilder.limit(200L);
|
||||
PreparedQuery<DanaRHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
historyList = getDaoDanaRHistory().query(preparedQuery);
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
historyList = new ArrayList<>();
|
||||
}
|
||||
return historyList;
|
||||
}
|
||||
|
||||
// ------------ TemporaryBasal handling ---------------
|
||||
|
||||
//return true if new record was created
|
||||
public boolean createOrUpdate(TemporaryBasal tempBasal) {
|
||||
try {
|
||||
TemporaryBasal old;
|
||||
tempBasal.date = roundDateToSec(tempBasal.date);
|
||||
|
||||
if (tempBasal.source == Source.PUMP) {
|
||||
// check for changed from pump change in NS
|
||||
QueryBuilder<TemporaryBasal, Long> queryBuilder = getDaoTemporaryBasal().queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("pumpId", tempBasal.pumpId);
|
||||
PreparedQuery<TemporaryBasal> preparedQuery = queryBuilder.prepare();
|
||||
List<TemporaryBasal> trList = getDaoTemporaryBasal().query(preparedQuery);
|
||||
if (trList.size() > 0) {
|
||||
// do nothing, pump history record cannot be changed
|
||||
aapsLogger.debug(LTag.DATABASE, "TEMPBASAL: Already exists from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
|
||||
return false;
|
||||
}
|
||||
|
||||
// search by date (in case its standard record that has become pump record)
|
||||
QueryBuilder<TemporaryBasal, Long> queryBuilder2 = getDaoTemporaryBasal().queryBuilder();
|
||||
Where where2 = queryBuilder2.where();
|
||||
where2.eq("date", tempBasal.date);
|
||||
PreparedQuery<TemporaryBasal> preparedQuery2 = queryBuilder2.prepare();
|
||||
List<TemporaryBasal> trList2 = getDaoTemporaryBasal().query(preparedQuery2);
|
||||
|
||||
if (trList2.size() > 0) {
|
||||
old = trList2.get(0);
|
||||
|
||||
old.copyFromPump(tempBasal);
|
||||
old.source = Source.PUMP;
|
||||
|
||||
aapsLogger.debug(LTag.DATABASE, "TEMPBASAL: Updated record with Pump Data : " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
|
||||
|
||||
getDaoTemporaryBasal().update(old);
|
||||
openHumansUploader.enqueueTemporaryBasal(old);
|
||||
|
||||
updateEarliestDataChange(tempBasal.date);
|
||||
// scheduleTemporaryBasalChange();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
getDaoTemporaryBasal().create(tempBasal);
|
||||
openHumansUploader.enqueueTemporaryBasal(tempBasal);
|
||||
aapsLogger.debug(LTag.DATABASE, "TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
|
||||
updateEarliestDataChange(tempBasal.date);
|
||||
// scheduleTemporaryBasalChange();
|
||||
return true;
|
||||
}
|
||||
if (tempBasal.source == Source.NIGHTSCOUT) {
|
||||
old = getDaoTemporaryBasal().queryForId(tempBasal.date);
|
||||
if (old != null) {
|
||||
if (!old.isAbsolute && tempBasal.isAbsolute) { // converted to absolute by "ns_sync_use_absolute"
|
||||
// so far ignore, do not convert back because it may not be accurate
|
||||
return false;
|
||||
}
|
||||
if (!old.isEqual(tempBasal)) {
|
||||
long oldDate = old.date;
|
||||
getDaoTemporaryBasal().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(tempBasal);
|
||||
getDaoTemporaryBasal().create(old);
|
||||
openHumansUploader.enqueueTemporaryBasal(old);
|
||||
aapsLogger.debug(LTag.DATABASE, "TEMPBASAL: Updating record by date from: " + Source.getString(tempBasal.source) + " " + old.toString());
|
||||
updateEarliestDataChange(oldDate);
|
||||
updateEarliestDataChange(old.date);
|
||||
// scheduleTemporaryBasalChange();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// find by NS _id
|
||||
if (tempBasal._id != null) {
|
||||
QueryBuilder<TemporaryBasal, Long> queryBuilder = getDaoTemporaryBasal().queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("_id", tempBasal._id);
|
||||
PreparedQuery<TemporaryBasal> preparedQuery = queryBuilder.prepare();
|
||||
List<TemporaryBasal> trList = getDaoTemporaryBasal().query(preparedQuery);
|
||||
if (trList.size() > 0) {
|
||||
old = trList.get(0);
|
||||
if (!old.isEqual(tempBasal)) {
|
||||
long oldDate = old.date;
|
||||
getDaoTemporaryBasal().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(tempBasal);
|
||||
getDaoTemporaryBasal().create(old);
|
||||
openHumansUploader.enqueueTemporaryBasal(old);
|
||||
aapsLogger.debug(LTag.DATABASE, "TEMPBASAL: Updating record by _id from: " + Source.getString(tempBasal.source) + " " + old.toString());
|
||||
updateEarliestDataChange(oldDate);
|
||||
updateEarliestDataChange(old.date);
|
||||
// scheduleTemporaryBasalChange();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
getDaoTemporaryBasal().create(tempBasal);
|
||||
openHumansUploader.enqueueTemporaryBasal(tempBasal);
|
||||
aapsLogger.debug(LTag.DATABASE, "TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
|
||||
updateEarliestDataChange(tempBasal.date);
|
||||
// scheduleTemporaryBasalChange();
|
||||
return true;
|
||||
}
|
||||
if (tempBasal.source == Source.USER) {
|
||||
getDaoTemporaryBasal().create(tempBasal);
|
||||
openHumansUploader.enqueueTemporaryBasal(tempBasal);
|
||||
aapsLogger.debug(LTag.DATABASE, "TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
|
||||
updateEarliestDataChange(tempBasal.date);
|
||||
// scheduleTemporaryBasalChange();
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void delete(TemporaryBasal tempBasal) {
|
||||
try {
|
||||
getDaoTemporaryBasal().delete(tempBasal);
|
||||
openHumansUploader.enqueueTemporaryBasal(tempBasal, true);
|
||||
updateEarliestDataChange(tempBasal.date);
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
// scheduleTemporaryBasalChange();
|
||||
}
|
||||
|
||||
public List<TemporaryBasal> getTemporaryBasalsDataFromTime(long mills, boolean ascending) {
|
||||
try {
|
||||
List<TemporaryBasal> tempbasals;
|
||||
QueryBuilder<TemporaryBasal, Long> queryBuilder = getDaoTemporaryBasal().queryBuilder();
|
||||
queryBuilder.orderBy("date", ascending);
|
||||
Where where = queryBuilder.where();
|
||||
where.ge("date", mills);
|
||||
PreparedQuery<TemporaryBasal> preparedQuery = queryBuilder.prepare();
|
||||
tempbasals = getDaoTemporaryBasal().query(preparedQuery);
|
||||
return tempbasals;
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return new ArrayList<TemporaryBasal>();
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"_id": "59232e1ddd032d04218dab00",
|
||||
"eventType": "Temp Basal",
|
||||
"duration": 60,
|
||||
"percent": -50,
|
||||
"created_at": "2017-05-22T18:29:57Z",
|
||||
"enteredBy": "AndroidAPS",
|
||||
"notes": "Basal Temp Start 50% 60.0 min",
|
||||
"NSCLIENT_ID": 1495477797863,
|
||||
"mills": 1495477797000,
|
||||
"mgdl": 194.5,
|
||||
"endmills": 1495481397000
|
||||
}
|
||||
*/
|
||||
|
||||
public TemporaryBasal findTempBasalByPumpId(Long pumpId) {
|
||||
try {
|
||||
QueryBuilder<TemporaryBasal, Long> queryBuilder = null;
|
||||
queryBuilder = getDaoTemporaryBasal().queryBuilder();
|
||||
queryBuilder.orderBy("date", false);
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("pumpId", pumpId);
|
||||
PreparedQuery<TemporaryBasal> preparedQuery = queryBuilder.prepare();
|
||||
List<TemporaryBasal> list = getDaoTemporaryBasal().query(preparedQuery);
|
||||
|
||||
if (list.size() > 0)
|
||||
return list.get(0);
|
||||
else
|
||||
return null;
|
||||
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
// ------------ ExtendedBolus handling ---------------
|
||||
|
||||
public ExtendedBolus getExtendedBolusByPumpId(long pumpId) {
|
||||
try {
|
||||
return getDaoExtendedBolus().queryBuilder()
|
||||
.where().eq("pumpId", pumpId)
|
||||
.queryForFirst();
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void delete(ExtendedBolus extendedBolus) {
|
||||
try {
|
||||
getDaoExtendedBolus().delete(extendedBolus);
|
||||
openHumansUploader.enqueueExtendedBolus(extendedBolus, true);
|
||||
updateEarliestDataChange(extendedBolus.date);
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
// scheduleExtendedBolusChange();
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"_id": "5924898d577eb0880e355337",
|
||||
"eventType": "Combo Bolus",
|
||||
"duration": 120,
|
||||
"splitNow": 0,
|
||||
"splitExt": 100,
|
||||
"enteredinsulin": 1,
|
||||
"relative": 1,
|
||||
"created_at": "2017-05-23T19:12:14Z",
|
||||
"enteredBy": "AndroidAPS",
|
||||
"NSCLIENT_ID": 1495566734628,
|
||||
"mills": 1495566734000,
|
||||
"mgdl": 106
|
||||
}
|
||||
*/
|
||||
|
||||
// ---------------- ProfileSwitch handling ---------------
|
||||
|
||||
/*
|
||||
public boolean createOrUpdate(ProfileSwitch profileSwitch) {
|
||||
try {
|
||||
ProfileSwitch old;
|
||||
profileSwitch.date = roundDateToSec(profileSwitch.date);
|
||||
|
||||
if (profileSwitch.source == Source.NIGHTSCOUT) {
|
||||
old = getDaoProfileSwitch().queryForId(profileSwitch.date);
|
||||
if (old != null) {
|
||||
if (!old.isEqual(profileSwitch)) {
|
||||
profileSwitch.source = old.source;
|
||||
profileSwitch.profileName = old.profileName; // preserver profileName to prevent multiple CPP extension
|
||||
getDaoProfileSwitch().delete(old); // need to delete/create because date may change too
|
||||
getDaoProfileSwitch().create(profileSwitch);
|
||||
aapsLogger.debug(LTag.DATABASE, "PROFILESWITCH: Updating record by date from: " + Source.getString(profileSwitch.source) + " " + old.toString());
|
||||
openHumansUploader.enqueueProfileSwitch(profileSwitch);
|
||||
scheduleProfileSwitchChange();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
// find by NS _id
|
||||
if (profileSwitch._id != null) {
|
||||
QueryBuilder<ProfileSwitch, Long> queryBuilder = getDaoProfileSwitch().queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("_id", profileSwitch._id);
|
||||
PreparedQuery<ProfileSwitch> preparedQuery = queryBuilder.prepare();
|
||||
List<ProfileSwitch> trList = getDaoProfileSwitch().query(preparedQuery);
|
||||
if (trList.size() > 0) {
|
||||
old = trList.get(0);
|
||||
if (!old.isEqual(profileSwitch)) {
|
||||
getDaoProfileSwitch().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(profileSwitch);
|
||||
getDaoProfileSwitch().create(old);
|
||||
aapsLogger.debug(LTag.DATABASE, "PROFILESWITCH: Updating record by _id from: " + Source.getString(profileSwitch.source) + " " + old.toString());
|
||||
openHumansUploader.enqueueProfileSwitch(old);
|
||||
scheduleProfileSwitchChange();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
// look for already added percentage from NS
|
||||
profileSwitch.profileName = PercentageSplitter.INSTANCE.pureName(profileSwitch.profileName);
|
||||
getDaoProfileSwitch().create(profileSwitch);
|
||||
aapsLogger.debug(LTag.DATABASE, "PROFILESWITCH: New record from: " + Source.getString(profileSwitch.source) + " " + profileSwitch.toString());
|
||||
openHumansUploader.enqueueProfileSwitch(profileSwitch);
|
||||
scheduleProfileSwitchChange();
|
||||
return true;
|
||||
}
|
||||
if (profileSwitch.source == Source.USER) {
|
||||
getDaoProfileSwitch().create(profileSwitch);
|
||||
aapsLogger.debug(LTag.DATABASE, "PROFILESWITCH: New record from: " + Source.getString(profileSwitch.source) + " " + profileSwitch.toString());
|
||||
openHumansUploader.enqueueProfileSwitch(profileSwitch);
|
||||
scheduleProfileSwitchChange();
|
||||
return true;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void delete(ProfileSwitch profileSwitch) {
|
||||
try {
|
||||
getDaoProfileSwitch().delete(profileSwitch);
|
||||
openHumansUploader.enqueueProfileSwitch(profileSwitch, true);
|
||||
scheduleProfileSwitchChange();
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
private void scheduleProfileSwitchChange() {
|
||||
class PostRunnable implements Runnable {
|
||||
public void run() {
|
||||
aapsLogger.debug(LTag.DATABASE, "Firing EventProfileNeedsUpdate");
|
||||
rxBus.send(new EventReloadProfileSwitchData());
|
||||
rxBus.send(new EventProfileNeedsUpdate());
|
||||
scheduledProfileSwitchEventPost = null;
|
||||
}
|
||||
}
|
||||
// prepare task for execution in 1 sec
|
||||
// cancel waiting task to prevent sending multiple posts
|
||||
if (scheduledProfileSwitchEventPost != null)
|
||||
scheduledProfileSwitchEventPost.cancel(false);
|
||||
Runnable task = new PostRunnable();
|
||||
final int sec = 1;
|
||||
scheduledProfileSwitchEventPost = profileSwitchEventWorker.schedule(task, sec, TimeUnit.SECONDS);
|
||||
|
||||
}
|
||||
*/
|
||||
/*
|
||||
{
|
||||
"_id":"592fa43ed97496a80da913d2",
|
||||
"created_at":"2017-06-01T05:20:06Z",
|
||||
"eventType":"Profile Switch",
|
||||
"profile":"2016 +30%",
|
||||
"units":"mmol",
|
||||
"enteredBy":"sony",
|
||||
"NSCLIENT_ID":1496294454309,
|
||||
}
|
||||
*/
|
||||
/*
|
||||
|
||||
public void createProfileSwitchFromJsonIfNotExists(JSONObject trJson) {
|
||||
try {
|
||||
ProfileSwitch profileSwitch = new ProfileSwitch(StaticInjector.Companion.getInstance());
|
||||
profileSwitch.date = trJson.getLong("mills");
|
||||
if (trJson.has("duration"))
|
||||
profileSwitch.durationInMinutes = trJson.getInt("duration");
|
||||
profileSwitch._id = trJson.getString("_id");
|
||||
profileSwitch.profileName = trJson.getString("profile");
|
||||
profileSwitch.isCPP = trJson.has("CircadianPercentageProfile");
|
||||
profileSwitch.source = Source.NIGHTSCOUT;
|
||||
if (trJson.has("timeshift"))
|
||||
profileSwitch.timeshift = trJson.getInt("timeshift");
|
||||
if (trJson.has("percentage"))
|
||||
profileSwitch.percentage = trJson.getInt("percentage");
|
||||
if (trJson.has("profileJson"))
|
||||
profileSwitch.profileJson = trJson.getString("profileJson");
|
||||
else {
|
||||
ProfileSource profileSource = activePlugin.getActiveProfileSource();
|
||||
ProfileStore store = profileSource.getProfile();
|
||||
if (store != null) {
|
||||
PureProfile profile = store.getSpecificProfile(profileSwitch.profileName);
|
||||
if (profile != null) {
|
||||
profileSwitch.profileJson = profile.getJsonObject().toString();
|
||||
aapsLogger.debug(LTag.DATABASE, "Profile switch prefilled with JSON from local store");
|
||||
// Update data in NS
|
||||
nsUpload.updateProfileSwitch(profileSwitch, dateUtil);
|
||||
} else {
|
||||
aapsLogger.debug(LTag.DATABASE, "JSON for profile switch doesn't exist. Ignoring: " + trJson.toString());
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
aapsLogger.debug(LTag.DATABASE, "Store for profile switch doesn't exist. Ignoring: " + trJson.toString());
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (trJson.has("profilePlugin"))
|
||||
profileSwitch.profilePlugin = trJson.getString("profilePlugin");
|
||||
createOrUpdate(profileSwitch);
|
||||
} catch (JSONException e) {
|
||||
aapsLogger.error("Unhandled exception: " + trJson.toString(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteProfileSwitchById(String _id) {
|
||||
ProfileSwitch stored = findProfileSwitchById(_id);
|
||||
if (stored != null) {
|
||||
aapsLogger.debug(LTag.DATABASE, "PROFILESWITCH: Removing ProfileSwitch record from database: " + stored.toString());
|
||||
delete(stored);
|
||||
scheduleProfileSwitchChange();
|
||||
}
|
||||
}
|
||||
|
||||
public ProfileSwitch findProfileSwitchById(String _id) {
|
||||
try {
|
||||
QueryBuilder<ProfileSwitch, Long> queryBuilder = getDaoProfileSwitch().queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("_id", _id);
|
||||
PreparedQuery<ProfileSwitch> preparedQuery = queryBuilder.prepare();
|
||||
List<ProfileSwitch> list = getDaoProfileSwitch().query(preparedQuery);
|
||||
|
||||
if (list.size() == 1) {
|
||||
return list.get(0);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
*/
|
||||
// ---------------- Insight history handling ---------------
|
||||
|
||||
public void createOrUpdate(InsightHistoryOffset offset) {
|
||||
|
@ -924,14 +468,4 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
public long getCountOfAllRows() {
|
||||
try {
|
||||
return getDaoExtendedBolus().countOf()
|
||||
+ getDaoTemporaryBasal().countOf();
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,8 +5,6 @@ import androidx.annotation.Nullable;
|
|||
|
||||
import com.j256.ormlite.dao.CloseableIterator;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -23,18 +21,10 @@ public class DatabaseHelperProvider implements DatabaseHelperInterface {
|
|||
@Inject DatabaseHelperProvider() {
|
||||
}
|
||||
|
||||
@Override public void createOrUpdate(@NonNull DanaRHistoryRecord record) {
|
||||
MainApp.Companion.getDbHelper().createOrUpdate(record);
|
||||
}
|
||||
|
||||
@Override public void createOrUpdate(@NonNull OmnipodHistoryRecord record) {
|
||||
MainApp.Companion.getDbHelper().createOrUpdate(record);
|
||||
}
|
||||
|
||||
@NonNull @Override public List<DanaRHistoryRecord> getDanaRHistoryRecordsByType(byte type) {
|
||||
return MainApp.Companion.getDbHelper().getDanaRHistoryRecordsByType(type);
|
||||
}
|
||||
|
||||
@Override public long size(@NonNull String table) {
|
||||
return MainApp.Companion.getDbHelper().size(table);
|
||||
}
|
||||
|
@ -68,16 +58,19 @@ public class DatabaseHelperProvider implements DatabaseHelperInterface {
|
|||
}
|
||||
|
||||
@Override public boolean createOrUpdate(@NonNull TemporaryBasal tempBasal) {
|
||||
return MainApp.Companion.getDbHelper().createOrUpdate(tempBasal);
|
||||
// return MainApp.Companion.getDbHelper().createOrUpdate(tempBasal);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable @Override public TemporaryBasal findTempBasalByPumpId(long id) {
|
||||
return MainApp.Companion.getDbHelper().findTempBasalByPumpId(id);
|
||||
// return MainApp.Companion.getDbHelper().findTempBasalByPumpId(id);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@NonNull @Override public List<TemporaryBasal> getTemporaryBasalsDataFromTime(long mills, boolean ascending) {
|
||||
return MainApp.Companion.getDbHelper().getTemporaryBasalsDataFromTime(mills, ascending);
|
||||
// return MainApp.Companion.getDbHelper().getTemporaryBasalsDataFromTime(mills, ascending);
|
||||
return null;
|
||||
}
|
||||
|
||||
@NonNull @Override public List<OmnipodHistoryRecord> getAllOmnipodHistoryRecordsFromTimestamp(long timestamp, boolean ascending) {
|
||||
|
@ -101,11 +94,12 @@ public class DatabaseHelperProvider implements DatabaseHelperInterface {
|
|||
}
|
||||
|
||||
@Override public void delete(@NonNull ExtendedBolus extendedBolus) {
|
||||
MainApp.Companion.getDbHelper().delete(extendedBolus);
|
||||
// MainApp.Companion.getDbHelper().delete(extendedBolus);
|
||||
}
|
||||
|
||||
@Nullable @Override public ExtendedBolus getExtendedBolusByPumpId(long pumpId) {
|
||||
return MainApp.Companion.getDbHelper().getExtendedBolusByPumpId(pumpId);
|
||||
// return MainApp.Companion.getDbHelper().getExtendedBolusByPumpId(pumpId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable @Override public InsightBolusID getInsightBolusID(@NonNull String pumpSerial, int bolusID, long timestamp) {
|
||||
|
@ -140,10 +134,6 @@ public class DatabaseHelperProvider implements DatabaseHelperInterface {
|
|||
MainApp.Companion.getDbHelper().clearOpenHumansQueue();
|
||||
}
|
||||
|
||||
@Override public long getCountOfAllRows() {
|
||||
return MainApp.Companion.getDbHelper().getCountOfAllRows();
|
||||
}
|
||||
|
||||
@Override public void removeAllOHQueueItemsWithIdSmallerThan(long id) {
|
||||
MainApp.Companion.getDbHelper().removeAllOHQueueItemsWithIdSmallerThan(id);
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ import dagger.android.AndroidInjector
|
|||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.automation.di.AutomationModule
|
||||
import info.nightscout.androidaps.combo.di.ComboModule
|
||||
import info.nightscout.androidaps.dana.di.DanaHistoryModule
|
||||
import info.nightscout.androidaps.di.CoreModule
|
||||
import info.nightscout.androidaps.dana.di.DanaModule
|
||||
import info.nightscout.androidaps.danar.di.DanaRModule
|
||||
|
@ -45,6 +46,7 @@ import javax.inject.Singleton
|
|||
UIModule::class,
|
||||
CoreModule::class,
|
||||
DanaModule::class,
|
||||
DanaHistoryModule::class,
|
||||
DanaRModule::class,
|
||||
DanaRSModule::class,
|
||||
ComboModule::class,
|
||||
|
|
|
@ -6,7 +6,6 @@ import dagger.Lazy
|
|||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.interfaces.Config
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.db.DatabaseHelperProvider
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
|
@ -32,6 +31,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP
|
|||
import info.nightscout.androidaps.utils.storage.FileStorage
|
||||
import info.nightscout.androidaps.utils.storage.Storage
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Suppress("unused")
|
||||
@Module(includes = [
|
||||
AppModule.AppBindings::class
|
||||
|
@ -70,7 +70,7 @@ open class AppModule {
|
|||
context: Context,
|
||||
sp: SP,
|
||||
rxBus: RxBusWrapper
|
||||
): UploadQueueAdminInterface = UploadQueue(aapsLogger, databaseHelper, context, sp, rxBus)
|
||||
): UploadQueueInterface = UploadQueue(aapsLogger, databaseHelper, context, sp, rxBus)
|
||||
|
||||
@Module
|
||||
interface AppBindings {
|
||||
|
@ -88,7 +88,6 @@ open class AppModule {
|
|||
@Binds fun bindLoopInterface(loopPlugin: LoopPlugin): LoopInterface
|
||||
@Binds fun bindIobCobCalculatorInterface(iobCobCalculatorPlugin: IobCobCalculatorPlugin): IobCobCalculator
|
||||
@Binds fun bindSmsCommunicatorInterface(smsCommunicatorPlugin: SmsCommunicatorPlugin): SmsCommunicator
|
||||
@Binds fun bindUploadQueueAdminInterfaceToUploadQueue(uploadQueueAdminInterface: UploadQueueAdminInterface) : UploadQueueInterface
|
||||
@Binds fun bindDataSyncSelector(dataSyncSelectorImplementation: DataSyncSelectorImplementation): DataSyncSelector
|
||||
@Binds fun bindPumpSync(pumpSyncImplementation: PumpSyncImplementation): PumpSync
|
||||
|
||||
|
|
|
@ -7,13 +7,13 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.dana.database.DanaHistoryDatabase
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Action
|
||||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||
import info.nightscout.androidaps.databinding.MaintenanceFragmentBinding
|
||||
import info.nightscout.androidaps.events.EventNewBG
|
||||
import info.nightscout.androidaps.interfaces.DataSyncSelector
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||
import info.nightscout.androidaps.interfaces.ImportExportPrefs
|
||||
import info.nightscout.androidaps.interfaces.PumpSync
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
|
@ -38,7 +38,7 @@ class MaintenanceFragment : DaggerFragment() {
|
|||
@Inject lateinit var importExportPrefs: ImportExportPrefs
|
||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||
@Inject lateinit var repository: AppRepository
|
||||
@Inject lateinit var databaseHelper: DatabaseHelperInterface
|
||||
@Inject lateinit var danaHistoryDatabase: DanaHistoryDatabase
|
||||
@Inject lateinit var uel: UserEntryLogger
|
||||
@Inject lateinit var dataSyncSelector: DataSyncSelector
|
||||
@Inject lateinit var pumpSync: PumpSync
|
||||
|
@ -68,8 +68,8 @@ class MaintenanceFragment : DaggerFragment() {
|
|||
OKDialog.showConfirmation(activity, resourceHelper.gs(R.string.maintenance), resourceHelper.gs(R.string.reset_db_confirm), Runnable {
|
||||
compositeDisposable.add(
|
||||
fromAction {
|
||||
databaseHelper.resetDatabases()
|
||||
repository.clearDatabases()
|
||||
danaHistoryDatabase.clearAllTables()
|
||||
dataSyncSelector.resetToNextFullSync()
|
||||
pumpSync.connectNewPump()
|
||||
}
|
||||
|
|
|
@ -12,14 +12,11 @@ import info.nightscout.androidaps.database.entities.UserEntry.Action
|
|||
import info.nightscout.androidaps.database.entities.UserEntry.Sources
|
||||
import info.nightscout.androidaps.databinding.NsClientFragmentBinding
|
||||
import info.nightscout.androidaps.interfaces.DataSyncSelector
|
||||
import info.nightscout.androidaps.interfaces.UploadQueueAdminInterface
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientNewLog
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientUpdateGUI
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.HtmlHelper.fromHtml
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
|
@ -33,7 +30,6 @@ class NSClientFragment : DaggerFragment() {
|
|||
@Inject lateinit var sp: SP
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var rxBus: RxBusWrapper
|
||||
@Inject lateinit var uploadQueue: UploadQueueAdminInterface
|
||||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||
@Inject lateinit var dataSyncSelector: DataSyncSelector
|
||||
|
@ -72,18 +68,6 @@ class NSClientFragment : DaggerFragment() {
|
|||
binding.restart.paintFlags = binding.restart.paintFlags or Paint.UNDERLINE_TEXT_FLAG
|
||||
binding.deliverNow.setOnClickListener { nsClientPlugin.resend("GUI") }
|
||||
binding.deliverNow.paintFlags = binding.deliverNow.paintFlags or Paint.UNDERLINE_TEXT_FLAG
|
||||
binding.clearQueue.setOnClickListener {
|
||||
context?.let { context ->
|
||||
OKDialog.showConfirmation(context, resourceHelper.gs(R.string.nsclientinternal), resourceHelper.gs(R.string.clearqueueconfirm), Runnable {
|
||||
uel.log(Action.NS_QUEUE_CLEARED, Sources.NSClient)
|
||||
uploadQueue.clearQueue()
|
||||
updateGui()
|
||||
})
|
||||
}
|
||||
}
|
||||
binding.clearQueue.paintFlags = binding.clearQueue.paintFlags or Paint.UNDERLINE_TEXT_FLAG
|
||||
binding.showQueue.setOnClickListener { rxBus.send(EventNSClientNewLog("QUEUE", uploadQueue.textList())) }
|
||||
binding.showQueue.paintFlags = binding.showQueue.paintFlags or Paint.UNDERLINE_TEXT_FLAG
|
||||
binding.fullSync.setOnClickListener {
|
||||
context?.let { context ->
|
||||
OKDialog.showConfirmation(context, resourceHelper.gs(R.string.nsclientinternal), resourceHelper.gs(R.string.full_sync), Runnable {
|
||||
|
@ -116,7 +100,6 @@ class NSClientFragment : DaggerFragment() {
|
|||
binding.log.text = nsClientPlugin.textLog
|
||||
if (nsClientPlugin.autoscroll) binding.logScrollview.fullScroll(ScrollView.FOCUS_DOWN)
|
||||
binding.url.text = nsClientPlugin.url()
|
||||
binding.queue.text = fromHtml(resourceHelper.gs(R.string.queue) + " <b>" + uploadQueue.size() + "</b>")
|
||||
binding.status.text = nsClientPlugin.status
|
||||
}
|
||||
}
|
|
@ -4,18 +4,10 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.os.SystemClock;
|
||||
|
||||
import com.j256.ormlite.dao.CloseableIterator;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.db.DbRequest;
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||
import info.nightscout.androidaps.interfaces.UploadQueueAdminInterface;
|
||||
import info.nightscout.androidaps.interfaces.UploadQueueInterface;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
|
@ -27,7 +19,7 @@ import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
|||
/**
|
||||
* Created by mike on 21.02.2016.
|
||||
*/
|
||||
public class UploadQueue implements UploadQueueAdminInterface {
|
||||
public class UploadQueue implements UploadQueueInterface {
|
||||
private final AAPSLogger aapsLogger;
|
||||
private final DatabaseHelperInterface databaseHelper;
|
||||
private final Context context;
|
||||
|
@ -75,50 +67,4 @@ public class UploadQueue implements UploadQueueAdminInterface {
|
|||
rxBus.send(new EventNSClientResend("newdata"));
|
||||
}
|
||||
|
||||
@Override public void clearQueue() {
|
||||
startService();
|
||||
if (NSClientService.handler != null) {
|
||||
NSClientService.handler.post(() -> {
|
||||
aapsLogger.debug(LTag.NSCLIENT, "ClearQueue");
|
||||
databaseHelper.deleteAllDbRequests();
|
||||
aapsLogger.debug(LTag.NSCLIENT, status());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeByMongoId(final String action, final String _id) {
|
||||
if (_id == null || _id.equals(""))
|
||||
return;
|
||||
startService();
|
||||
if (NSClientService.handler != null) {
|
||||
NSClientService.handler.post(() -> {
|
||||
databaseHelper.deleteDbRequestbyMongoId(action, _id);
|
||||
aapsLogger.debug(LTag.NSCLIENT, "Removing " + _id + " from UploadQueue. " + status());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override public String textList() {
|
||||
String result = "";
|
||||
CloseableIterator<DbRequest> iterator;
|
||||
try {
|
||||
iterator = databaseHelper.getDbRequestIterator();
|
||||
try {
|
||||
while (iterator.hasNext()) {
|
||||
DbRequest dbr = iterator.next();
|
||||
result += "<br>";
|
||||
result += dbr.action.toUpperCase() + " ";
|
||||
result += dbr.collection + ": ";
|
||||
result += dbr.data;
|
||||
}
|
||||
} finally {
|
||||
iterator.close();
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -178,24 +178,24 @@ class OpenHumansUploader @Inject constructor(
|
|||
}
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun enqueueTreatment(treatment: Treatment?, deleted: Boolean = false) = treatment?.let {
|
||||
insertQueueItem("Treatments") {
|
||||
put("date", treatment.date)
|
||||
put("isValid", treatment.isValid)
|
||||
put("source", treatment.source)
|
||||
put("nsId", treatment._id)
|
||||
put("boluscalc", treatment.boluscalc)
|
||||
put("carbs", treatment.carbs)
|
||||
put("dia", treatment.dia)
|
||||
put("insulin", treatment.insulin)
|
||||
put("insulinInterfaceID", treatment.insulinInterfaceID)
|
||||
put("isSMB", treatment.isSMB)
|
||||
put("mealBolus", treatment.mealBolus)
|
||||
put("bolusCalcJson", treatment.getBoluscalc())
|
||||
put("isDeletion", deleted)
|
||||
}
|
||||
}
|
||||
// @JvmOverloads
|
||||
// fun enqueueTreatment(treatment: Treatment?, deleted: Boolean = false) = treatment?.let {
|
||||
// insertQueueItem("Treatments") {
|
||||
// put("date", treatment.date)
|
||||
// put("isValid", treatment.isValid)
|
||||
// put("source", treatment.source)
|
||||
// put("nsId", treatment._id)
|
||||
// put("boluscalc", treatment.boluscalc)
|
||||
// put("carbs", treatment.carbs)
|
||||
// put("dia", treatment.dia)
|
||||
// put("insulin", treatment.insulin)
|
||||
// put("insulinInterfaceID", treatment.insulinInterfaceID)
|
||||
// put("isSMB", treatment.isSMB)
|
||||
// put("mealBolus", treatment.mealBolus)
|
||||
// put("bolusCalcJson", treatment.getBoluscalc())
|
||||
// put("isDeletion", deleted)
|
||||
// }
|
||||
// }
|
||||
|
||||
@JvmOverloads
|
||||
fun enqueueTherapyEvent(therapyEvent: TherapyEvent, deleted: Boolean = false) = insertQueueItem("TherapyEvents") {
|
||||
|
@ -210,17 +210,17 @@ class OpenHumansUploader @Inject constructor(
|
|||
put("isDeletion", deleted)
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
fun enqueueExtendedBolus(extendedBolus: ExtendedBolus, deleted: Boolean = false) = insertQueueItem("ExtendedBoluses") {
|
||||
put("date", extendedBolus.date)
|
||||
put("isValid", extendedBolus.isValid)
|
||||
put("source", extendedBolus.source)
|
||||
put("nsId", extendedBolus._id)
|
||||
put("pumpId", extendedBolus.pumpId)
|
||||
put("insulin", extendedBolus.insulin)
|
||||
put("durationInMinutes", extendedBolus.durationInMinutes)
|
||||
put("isDeletion", deleted)
|
||||
}
|
||||
// @JvmOverloads
|
||||
// fun enqueueExtendedBolus(extendedBolus: ExtendedBolus, deleted: Boolean = false) = insertQueueItem("ExtendedBoluses") {
|
||||
// put("date", extendedBolus.date)
|
||||
// put("isValid", extendedBolus.isValid)
|
||||
// put("source", extendedBolus.source)
|
||||
// put("nsId", extendedBolus._id)
|
||||
// put("pumpId", extendedBolus.pumpId)
|
||||
// put("insulin", extendedBolus.insulin)
|
||||
// put("durationInMinutes", extendedBolus.durationInMinutes)
|
||||
// put("isDeletion", deleted)
|
||||
// }
|
||||
|
||||
// @JvmOverloads
|
||||
// fun enqueueProfileSwitch(profileSwitch: ProfileSwitch, deleted: Boolean = false) = insertQueueItem("ProfileSwitches") {
|
||||
|
@ -244,22 +244,22 @@ class OpenHumansUploader @Inject constructor(
|
|||
// put("double", tdd.total)
|
||||
// }
|
||||
|
||||
@JvmOverloads
|
||||
fun enqueueTemporaryBasal(temporaryBasal: TemporaryBasal?, deleted: Boolean = false) = temporaryBasal?.let {
|
||||
insertQueueItem("TemporaryBasals") {
|
||||
put("date", temporaryBasal.date)
|
||||
put("isValid", temporaryBasal.isValid)
|
||||
put("source", temporaryBasal.source)
|
||||
put("nsId", temporaryBasal._id)
|
||||
put("pumpId", temporaryBasal.pumpId)
|
||||
put("durationInMinutes", temporaryBasal.durationInMinutes)
|
||||
put("durationInMinutes", temporaryBasal.durationInMinutes)
|
||||
put("isAbsolute", temporaryBasal.isAbsolute)
|
||||
put("percentRate", temporaryBasal.percentRate)
|
||||
put("absoluteRate", temporaryBasal.absoluteRate)
|
||||
put("isDeletion", deleted)
|
||||
}
|
||||
}
|
||||
// @JvmOverloads
|
||||
// fun enqueueTemporaryBasal(temporaryBasal: TemporaryBasal?, deleted: Boolean = false) = temporaryBasal?.let {
|
||||
// insertQueueItem("TemporaryBasals") {
|
||||
// put("date", temporaryBasal.date)
|
||||
// put("isValid", temporaryBasal.isValid)
|
||||
// put("source", temporaryBasal.source)
|
||||
// put("nsId", temporaryBasal._id)
|
||||
// put("pumpId", temporaryBasal.pumpId)
|
||||
// put("durationInMinutes", temporaryBasal.durationInMinutes)
|
||||
// put("durationInMinutes", temporaryBasal.durationInMinutes)
|
||||
// put("isAbsolute", temporaryBasal.isAbsolute)
|
||||
// put("percentRate", temporaryBasal.percentRate)
|
||||
// put("absoluteRate", temporaryBasal.absoluteRate)
|
||||
// put("isDeletion", deleted)
|
||||
// }
|
||||
// }
|
||||
|
||||
@JvmOverloads
|
||||
fun enqueueTempTarget(tempTarget: TemporaryTarget?, deleted: Boolean = false) = tempTarget?.let {
|
||||
|
|
|
@ -400,9 +400,8 @@ class GraphData(
|
|||
time += 5 * 60 * 1000L
|
||||
continue
|
||||
}
|
||||
var iob = 0.0
|
||||
var absIob = 0.0
|
||||
iob = iobCobCalculator.calculateFromTreatmentsAndTemps(time, profile).iob
|
||||
val iob: Double = iobCobCalculator.calculateFromTreatmentsAndTemps(time, profile).iob
|
||||
if (absScale) absIob = iobCobCalculator.calculateAbsInsulinFromTreatmentsAndTemps(time).iob
|
||||
if (abs(lastIob - iob) > 0.02) {
|
||||
if (abs(lastIob - iob) > 0.2) iobArray.add(ScaledDataPoint(time, lastIob, iobScale))
|
||||
|
@ -461,8 +460,7 @@ class GraphData(
|
|||
time += 5 * 60 * 1000L
|
||||
continue
|
||||
}
|
||||
var iob = 0.0
|
||||
iob = iobCobCalculator.calculateAbsInsulinFromTreatmentsAndTemps(time).iob
|
||||
val iob: Double = iobCobCalculator.calculateAbsInsulinFromTreatmentsAndTemps(time).iob
|
||||
if (abs(lastIob - iob) > 0.02) {
|
||||
if (abs(lastIob - iob) > 0.2) iobArray.add(ScaledDataPoint(time, lastIob, iobScale))
|
||||
iobArray.add(ScaledDataPoint(time, iob, iobScale))
|
||||
|
|
|
@ -105,25 +105,10 @@ public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> impleme
|
|||
return wrapped.queryForAll();
|
||||
}
|
||||
|
||||
public void delete(Treatment data) throws SQLException {
|
||||
wrapped.delete(data);
|
||||
openHumansUploader.enqueueTreatment(data, true);
|
||||
}
|
||||
|
||||
public void create(Treatment data) throws SQLException {
|
||||
wrapped.create(data);
|
||||
openHumansUploader.enqueueTreatment(data);
|
||||
}
|
||||
|
||||
public Treatment queryForId(long id) throws SQLException {
|
||||
return wrapped.queryForId(id);
|
||||
}
|
||||
|
||||
public void update(Treatment data) throws SQLException {
|
||||
wrapped.update(data);
|
||||
openHumansUploader.enqueueTreatment(data);
|
||||
}
|
||||
|
||||
public QueryBuilder<Treatment, Long> queryBuilder() {
|
||||
return wrapped.queryBuilder();
|
||||
}
|
||||
|
|
|
@ -75,15 +75,6 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:textStyle="normal|bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/queue"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginRight="5dp"
|
||||
android:text="@string/queue"
|
||||
android:textAlignment="viewEnd"
|
||||
tools:ignore="RtlHardcoded" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
|
@ -125,26 +116,6 @@
|
|||
android:textColor="@android:color/holo_orange_light"
|
||||
android:textStyle="normal|bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/clear_queue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/clear_queue"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/holo_orange_light"
|
||||
android:textStyle="normal|bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/show_queue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_weight="1"
|
||||
android:text="@string/show_queue"
|
||||
android:textAlignment="center"
|
||||
android:textColor="@android:color/holo_orange_light"
|
||||
android:textStyle="normal|bold" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/full_sync"
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -1,77 +0,0 @@
|
|||
package info.nightscout.androidaps.db;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
@DatabaseTable(tableName = "DanaRHistory")
|
||||
public class DanaRHistoryRecord {
|
||||
|
||||
@DatabaseField
|
||||
public String _id;
|
||||
|
||||
@DatabaseField
|
||||
public byte recordCode;
|
||||
|
||||
@DatabaseField(id = true)
|
||||
public String bytes;
|
||||
|
||||
@DatabaseField
|
||||
public long recordDate;
|
||||
|
||||
@DatabaseField
|
||||
public double recordValue;
|
||||
|
||||
@DatabaseField
|
||||
public String bolusType;
|
||||
|
||||
@DatabaseField
|
||||
public String stringRecordValue;
|
||||
|
||||
@DatabaseField
|
||||
public int recordDuration;
|
||||
|
||||
@DatabaseField
|
||||
public double recordDailyBasal;
|
||||
|
||||
@DatabaseField
|
||||
public double recordDailyBolus;
|
||||
|
||||
@DatabaseField
|
||||
public String recordAlarm;
|
||||
|
||||
public DanaRHistoryRecord() {
|
||||
this.recordDate = 0;
|
||||
this.recordValue = 0.0;
|
||||
this.bolusType = "None";
|
||||
this.recordCode = 0x0F;
|
||||
this.bytes = new String();
|
||||
this._id = null;
|
||||
}
|
||||
|
||||
public int getRecordLevel(double dExLow, double dLow, double dHigh, double dExHigh) {
|
||||
if (this.recordValue < dExLow)
|
||||
return 0;
|
||||
if (this.recordValue < dLow)
|
||||
return 1;
|
||||
if (this.recordValue < dHigh)
|
||||
return 2;
|
||||
return this.recordValue < dExHigh ? 3 : 4;
|
||||
}
|
||||
|
||||
public void setBytes(byte[] raw) {
|
||||
this.bytes = bytesToHex(raw);
|
||||
}
|
||||
|
||||
final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
|
||||
|
||||
public static String bytesToHex(byte[] bytes) {
|
||||
char[] hexChars = new char[bytes.length * 2];
|
||||
for (int j = 0; j < bytes.length; j++) {
|
||||
int v = bytes[j] & 0xFF;
|
||||
hexChars[j * 2] = hexArray[v >>> 4];
|
||||
hexChars[j * 2 + 1] = hexArray[v & 0x0F];
|
||||
}
|
||||
return new String(hexChars);
|
||||
}
|
||||
}
|
||||
|
|
@ -4,9 +4,6 @@ import dagger.Module
|
|||
import dagger.android.ContributesAndroidInjector
|
||||
import info.nightscout.androidaps.data.ProfileImplOld
|
||||
import info.nightscout.androidaps.data.PumpEnactResult
|
||||
import info.nightscout.androidaps.db.ExtendedBolus
|
||||
import info.nightscout.androidaps.db.TemporaryBasal
|
||||
import info.nightscout.androidaps.db.Treatment
|
||||
import info.nightscout.androidaps.interfaces.ProfileStore
|
||||
import info.nightscout.androidaps.plugins.aps.loop.APSResult
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.data.NSMbg
|
||||
|
@ -24,7 +21,4 @@ abstract class CoreDataClassesModule {
|
|||
|
||||
@ContributesAndroidInjector abstract fun profileInjector(): ProfileImplOld
|
||||
@ContributesAndroidInjector abstract fun profileStoreInjector(): ProfileStore
|
||||
@ContributesAndroidInjector abstract fun treatmentInjector(): Treatment
|
||||
@ContributesAndroidInjector abstract fun temporaryBasalInjector(): TemporaryBasal
|
||||
@ContributesAndroidInjector abstract fun extendedBolusInjector(): ExtendedBolus
|
||||
}
|
||||
|
|
|
@ -8,14 +8,12 @@ interface DatabaseHelperInterface {
|
|||
|
||||
fun resetDatabases()
|
||||
|
||||
fun createOrUpdate(record: DanaRHistoryRecord)
|
||||
fun createOrUpdate(record: OmnipodHistoryRecord)
|
||||
fun createOrUpdate(record: InsightBolusID)
|
||||
fun createOrUpdate(record: InsightPumpID)
|
||||
fun createOrUpdate(record: InsightHistoryOffset)
|
||||
fun createOrUpdate(record: OHQueueItem)
|
||||
fun create(record: DbRequest)
|
||||
fun getDanaRHistoryRecordsByType(type: Byte): List<DanaRHistoryRecord>
|
||||
fun size(table: String): Long
|
||||
fun deleteAllDbRequests()
|
||||
fun deleteDbRequest(id: String): Int
|
||||
|
@ -41,7 +39,6 @@ interface DatabaseHelperInterface {
|
|||
|
||||
fun getOHQueueSize(): Long
|
||||
fun clearOpenHumansQueue()
|
||||
fun getCountOfAllRows(): Long
|
||||
fun removeAllOHQueueItemsWithIdSmallerThan(id: Long)
|
||||
|
||||
companion object {
|
||||
|
|
|
@ -20,7 +20,7 @@ interface IobCobCalculator {
|
|||
fun getLastAutosensDataWithWaitForCalculationFinish(reason: String): AutosensData?
|
||||
|
||||
fun calculateAbsInsulinFromTreatmentsAndTemps(fromTime: Long): IobTotal
|
||||
fun calculateFromTreatmentsAndTemps(time: Long, profile: Profile): IobTotal
|
||||
fun calculateFromTreatmentsAndTemps(fromTime: Long, profile: Profile): IobTotal
|
||||
|
||||
fun getBasalData(profile: Profile, fromTime: Long): BasalData
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package info.nightscout.androidaps.interfaces
|
|||
|
||||
import androidx.collection.ArrayMap
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.data.ProfileImplOld
|
||||
import info.nightscout.androidaps.data.PureProfile
|
||||
import info.nightscout.androidaps.extensions.pureProfileFromJson
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
|
@ -67,8 +66,7 @@ class ProfileStore(val injector: HasAndroidInjector, val data: JSONObject, val d
|
|||
return profile
|
||||
}
|
||||
|
||||
fun getSpecificProfileJson(profileName: String): JSONObject? {
|
||||
var profile: PureProfile? = null
|
||||
private fun getSpecificProfileJson(profileName: String): JSONObject? {
|
||||
getStore()?.let { store ->
|
||||
if (store.has(profileName))
|
||||
return JsonHelper.safeGetJSONObject(store, profileName, null)
|
||||
|
|
|
@ -1,6 +0,0 @@
|
|||
package info.nightscout.androidaps.interfaces
|
||||
|
||||
interface UploadQueueAdminInterface : UploadQueueInterface {
|
||||
|
||||
fun clearQueue()
|
||||
}
|
|
@ -9,8 +9,4 @@ public interface UploadQueueInterface {
|
|||
long size();
|
||||
|
||||
void add(DbRequest dbRequest);
|
||||
|
||||
void removeByMongoId(final String action, final String _id);
|
||||
|
||||
String textList();
|
||||
}
|
||||
|
|
|
@ -31,62 +31,10 @@ public class NSUpload {
|
|||
this.sp = sp;
|
||||
this.uploadQueue = uploadQueue;
|
||||
}
|
||||
/*
|
||||
public void uploadProfileSwitch(ProfileSwitch profileSwitch, long nsClientId, DateUtil dateUtil) {
|
||||
try {
|
||||
JSONObject data = getJson(profileSwitch, dateUtil);
|
||||
DbRequest dbr = new DbRequest("dbAdd", "treatments", data, nsClientId);
|
||||
aapsLogger.debug("Prepared: " + dbr.log());
|
||||
uploadQueue.add(dbr);
|
||||
} catch (JSONException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateProfileSwitch(ProfileSwitch profileSwitch, DateUtil dateUtil) {
|
||||
try {
|
||||
JSONObject data = getJson(profileSwitch, dateUtil);
|
||||
if (profileSwitch._id != null) {
|
||||
uploadQueue.add(new DbRequest("dbUpdate", "treatments", profileSwitch._id, data, profileSwitch.date));
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
private static JSONObject getJson(ProfileSwitch profileSwitch, DateUtil dateUtil) throws JSONException {
|
||||
JSONObject data = new JSONObject();
|
||||
data.put("eventType", TherapyEvent.Type.PROFILE_SWITCH.getText());
|
||||
data.put("duration", profileSwitch.durationInMinutes);
|
||||
data.put("profile", profileSwitch.getCustomizedName());
|
||||
data.put("profileJson", profileSwitch.profileJson);
|
||||
data.put("profilePlugin", profileSwitch.profilePlugin);
|
||||
if (profileSwitch.isCPP) {
|
||||
data.put("CircadianPercentageProfile", true);
|
||||
data.put("timeshift", profileSwitch.timeshift);
|
||||
data.put("percentage", profileSwitch.percentage);
|
||||
}
|
||||
data.put("created_at", dateUtil.toISOString(profileSwitch.date));
|
||||
data.put("enteredBy", "AndroidAPS");
|
||||
|
||||
return data;
|
||||
}
|
||||
*/
|
||||
// TODO replace with setting isValid = false
|
||||
public void removeCareportalEntryFromNS(String _id) {
|
||||
uploadQueue.add(new DbRequest("dbRemove", "treatments", _id, System.currentTimeMillis()));
|
||||
}
|
||||
|
||||
public void uploadProfileStore(JSONObject profileStore) {
|
||||
if (sp.getBoolean(R.string.key_ns_uploadlocalprofile, false)) {
|
||||
uploadQueue.add(new DbRequest("dbAdd", "profile", profileStore, System.currentTimeMillis()));
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isIdValid(String _id) {
|
||||
if (_id == null)
|
||||
return false;
|
||||
return _id.length() == 24;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -17,4 +17,10 @@ android {
|
|||
|
||||
dependencies {
|
||||
implementation project(':core')
|
||||
|
||||
api "androidx.room:room-ktx:$room_version"
|
||||
api "androidx.room:room-runtime:$room_version"
|
||||
api "androidx.room:room-rxjava2:$room_version"
|
||||
kapt "androidx.room:room-compiler:$room_version"
|
||||
kapt "android.arch.persistence.room:compiler:$room_version"
|
||||
}
|
|
@ -6,21 +6,21 @@ import android.view.View
|
|||
import android.view.ViewGroup
|
||||
import android.widget.AdapterView
|
||||
import android.widget.ArrayAdapter
|
||||
import android.widget.TextView
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
|
||||
import info.nightscout.androidaps.dana.R
|
||||
import info.nightscout.androidaps.dana.comm.RecordTypes
|
||||
import info.nightscout.androidaps.dana.database.DanaHistoryRecord
|
||||
import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao
|
||||
import info.nightscout.androidaps.dana.databinding.DanarHistoryActivityBinding
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord
|
||||
import info.nightscout.androidaps.dana.databinding.DanarHistoryItemBinding
|
||||
import info.nightscout.androidaps.events.EventDanaRSyncStatus
|
||||
import info.nightscout.androidaps.events.EventPumpStatusChanged
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
|
@ -30,6 +30,7 @@ import info.nightscout.androidaps.queue.Callback
|
|||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
|
@ -44,14 +45,13 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() {
|
|||
@Inject lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Inject lateinit var activePlugin: ActivePlugin
|
||||
@Inject lateinit var commandQueue: CommandQueueProvider
|
||||
@Inject lateinit var databaseHelper: DatabaseHelperInterface
|
||||
@Inject lateinit var danaHistoryRecordDao: DanaHistoryRecordDao
|
||||
@Inject lateinit var dateUtil: DateUtil
|
||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||
|
||||
private val disposable = CompositeDisposable()
|
||||
|
||||
private var showingType = RecordTypes.RECORD_TYPE_ALARM
|
||||
private var historyList: List<DanaRHistoryRecord> = ArrayList()
|
||||
|
||||
class TypeList internal constructor(var type: Byte, var name: String) {
|
||||
|
||||
|
@ -73,6 +73,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() {
|
|||
aapsLogger.debug(LTag.PUMP, "EventDanaRSyncStatus: " + it.message)
|
||||
binding.status.text = it.message
|
||||
}, fabricPrivacy::logException)
|
||||
swapAdapter(showingType)
|
||||
}
|
||||
|
||||
override fun onPause() {
|
||||
|
@ -87,7 +88,6 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() {
|
|||
|
||||
binding.recyclerview.setHasFixedSize(true)
|
||||
binding.recyclerview.layoutManager = LinearLayoutManager(this)
|
||||
binding.recyclerview.adapter = RecyclerViewAdapter(historyList)
|
||||
binding.status.visibility = View.GONE
|
||||
|
||||
val pump = activePlugin.activePump
|
||||
|
@ -115,14 +115,12 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() {
|
|||
binding.reload.setOnClickListener {
|
||||
val selected = binding.spinner.selectedItem as TypeList?
|
||||
?: return@setOnClickListener
|
||||
runOnUiThread {
|
||||
binding.reload.visibility = View.GONE
|
||||
binding.status.visibility = View.VISIBLE
|
||||
}
|
||||
binding.reload.visibility = View.GONE
|
||||
binding.status.visibility = View.VISIBLE
|
||||
clearCardView()
|
||||
commandQueue.loadHistory(selected.type, object : Callback() {
|
||||
override fun run() {
|
||||
loadDataFromDB(selected.type)
|
||||
swapAdapter(selected.type)
|
||||
runOnUiThread {
|
||||
binding.reload.visibility = View.VISIBLE
|
||||
binding.status.visibility = View.GONE
|
||||
|
@ -133,7 +131,7 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() {
|
|||
binding.spinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
|
||||
override fun onItemSelected(parent: AdapterView<*>?, view: View?, position: Int, id: Long) {
|
||||
val selected = typeList[position]
|
||||
loadDataFromDB(selected.type)
|
||||
swapAdapter(selected.type)
|
||||
showingType = selected.type
|
||||
}
|
||||
|
||||
|
@ -143,95 +141,95 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
inner class RecyclerViewAdapter internal constructor(private var historyList: List<DanaRHistoryRecord>) : RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder>() {
|
||||
inner class RecyclerViewAdapter internal constructor(private var historyList: List<DanaHistoryRecord>) : RecyclerView.Adapter<RecyclerViewAdapter.HistoryViewHolder>() {
|
||||
|
||||
override fun onCreateViewHolder(viewGroup: ViewGroup, viewType: Int): HistoryViewHolder =
|
||||
HistoryViewHolder(LayoutInflater.from(viewGroup.context).inflate(R.layout.danar_history_item, viewGroup, false))
|
||||
|
||||
override fun onBindViewHolder(holder: HistoryViewHolder, position: Int) {
|
||||
val record = historyList[position]
|
||||
holder.time.text = dateUtil.dateAndTimeString(record.recordDate)
|
||||
holder.value.text = DecimalFormatter.to2Decimal(record.recordValue)
|
||||
holder.stringValue.text = record.stringRecordValue
|
||||
holder.bolusType.text = record.bolusType
|
||||
holder.duration.text = DecimalFormatter.to0Decimal(record.recordDuration.toDouble())
|
||||
holder.alarm.text = record.recordAlarm
|
||||
holder.binding.time.text = dateUtil.dateAndTimeString(record.timestamp)
|
||||
holder.binding.value.text = DecimalFormatter.to2Decimal(record.value)
|
||||
holder.binding.stringValue.text = record.stringValue
|
||||
holder.binding.bolusType.text = record.bolusType
|
||||
holder.binding.duration.text = record.duration.toString()
|
||||
holder.binding.alarm.text = record.alarm
|
||||
when (showingType) {
|
||||
RecordTypes.RECORD_TYPE_ALARM -> {
|
||||
holder.time.visibility = View.VISIBLE
|
||||
holder.value.visibility = View.VISIBLE
|
||||
holder.stringValue.visibility = View.GONE
|
||||
holder.bolusType.visibility = View.GONE
|
||||
holder.duration.visibility = View.GONE
|
||||
holder.dailyBasal.visibility = View.GONE
|
||||
holder.dailyBolus.visibility = View.GONE
|
||||
holder.dailyTotal.visibility = View.GONE
|
||||
holder.alarm.visibility = View.VISIBLE
|
||||
RecordTypes.RECORD_TYPE_ALARM -> {
|
||||
holder.binding.time.visibility = View.VISIBLE
|
||||
holder.binding.value.visibility = View.VISIBLE
|
||||
holder.binding.stringValue.visibility = View.GONE
|
||||
holder.binding.bolusType.visibility = View.GONE
|
||||
holder.binding.duration.visibility = View.GONE
|
||||
holder.binding.dailyBasal.visibility = View.GONE
|
||||
holder.binding.dailyBolus.visibility = View.GONE
|
||||
holder.binding.dailyTotal.visibility = View.GONE
|
||||
holder.binding.alarm.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
RecordTypes.RECORD_TYPE_BOLUS -> {
|
||||
holder.time.visibility = View.VISIBLE
|
||||
holder.value.visibility = View.VISIBLE
|
||||
holder.stringValue.visibility = View.GONE
|
||||
holder.bolusType.visibility = View.VISIBLE
|
||||
holder.duration.visibility = View.VISIBLE
|
||||
holder.dailyBasal.visibility = View.GONE
|
||||
holder.dailyBolus.visibility = View.GONE
|
||||
holder.dailyTotal.visibility = View.GONE
|
||||
holder.alarm.visibility = View.GONE
|
||||
RecordTypes.RECORD_TYPE_BOLUS -> {
|
||||
holder.binding.time.visibility = View.VISIBLE
|
||||
holder.binding.value.visibility = View.VISIBLE
|
||||
holder.binding.stringValue.visibility = View.GONE
|
||||
holder.binding.bolusType.visibility = View.VISIBLE
|
||||
holder.binding.duration.visibility = View.VISIBLE
|
||||
holder.binding.dailyBasal.visibility = View.GONE
|
||||
holder.binding.dailyBolus.visibility = View.GONE
|
||||
holder.binding.dailyTotal.visibility = View.GONE
|
||||
holder.binding.alarm.visibility = View.GONE
|
||||
}
|
||||
|
||||
RecordTypes.RECORD_TYPE_DAILY -> {
|
||||
holder.dailyBasal.text = resourceHelper.gs(R.string.formatinsulinunits, record.recordDailyBasal)
|
||||
holder.dailyBolus.text = resourceHelper.gs(R.string.formatinsulinunits, record.recordDailyBolus)
|
||||
holder.dailyTotal.text = resourceHelper.gs(R.string.formatinsulinunits, record.recordDailyBolus + record.recordDailyBasal)
|
||||
holder.time.text = dateUtil.dateString(record.recordDate)
|
||||
holder.time.visibility = View.VISIBLE
|
||||
holder.value.visibility = View.GONE
|
||||
holder.stringValue.visibility = View.GONE
|
||||
holder.bolusType.visibility = View.GONE
|
||||
holder.duration.visibility = View.GONE
|
||||
holder.dailyBasal.visibility = View.VISIBLE
|
||||
holder.dailyBolus.visibility = View.VISIBLE
|
||||
holder.dailyTotal.visibility = View.VISIBLE
|
||||
holder.alarm.visibility = View.GONE
|
||||
RecordTypes.RECORD_TYPE_DAILY -> {
|
||||
holder.binding.dailyBasal.text = resourceHelper.gs(R.string.formatinsulinunits, record.dailyBasal)
|
||||
holder.binding.dailyBolus.text = resourceHelper.gs(R.string.formatinsulinunits, record.dailyBolus)
|
||||
holder.binding.dailyTotal.text = resourceHelper.gs(R.string.formatinsulinunits, record.dailyBolus + record.dailyBasal)
|
||||
holder.binding.time.text = dateUtil.dateString(record.timestamp)
|
||||
holder.binding.time.visibility = View.VISIBLE
|
||||
holder.binding.value.visibility = View.GONE
|
||||
holder.binding.stringValue.visibility = View.GONE
|
||||
holder.binding.bolusType.visibility = View.GONE
|
||||
holder.binding.duration.visibility = View.GONE
|
||||
holder.binding.dailyBasal.visibility = View.VISIBLE
|
||||
holder.binding.dailyBolus.visibility = View.VISIBLE
|
||||
holder.binding.dailyTotal.visibility = View.VISIBLE
|
||||
holder.binding.alarm.visibility = View.GONE
|
||||
}
|
||||
|
||||
RecordTypes.RECORD_TYPE_GLUCOSE -> {
|
||||
holder.value.text = Profile.toUnitsString(record.recordValue, record.recordValue * Constants.MGDL_TO_MMOLL, profileFunction.getUnits())
|
||||
holder.time.visibility = View.VISIBLE
|
||||
holder.value.visibility = View.VISIBLE
|
||||
holder.stringValue.visibility = View.GONE
|
||||
holder.bolusType.visibility = View.GONE
|
||||
holder.duration.visibility = View.GONE
|
||||
holder.dailyBasal.visibility = View.GONE
|
||||
holder.dailyBolus.visibility = View.GONE
|
||||
holder.dailyTotal.visibility = View.GONE
|
||||
holder.alarm.visibility = View.GONE
|
||||
RecordTypes.RECORD_TYPE_GLUCOSE -> {
|
||||
holder.binding.value.text = Profile.toUnitsString(record.value, record.value * Constants.MGDL_TO_MMOLL, profileFunction.getUnits())
|
||||
holder.binding.time.visibility = View.VISIBLE
|
||||
holder.binding.value.visibility = View.VISIBLE
|
||||
holder.binding.stringValue.visibility = View.GONE
|
||||
holder.binding.bolusType.visibility = View.GONE
|
||||
holder.binding.duration.visibility = View.GONE
|
||||
holder.binding.dailyBasal.visibility = View.GONE
|
||||
holder.binding.dailyBolus.visibility = View.GONE
|
||||
holder.binding.dailyTotal.visibility = View.GONE
|
||||
holder.binding.alarm.visibility = View.GONE
|
||||
}
|
||||
|
||||
RecordTypes.RECORD_TYPE_CARBO, RecordTypes.RECORD_TYPE_BASALHOUR, RecordTypes.RECORD_TYPE_ERROR, RecordTypes.RECORD_TYPE_PRIME, RecordTypes.RECORD_TYPE_REFILL, RecordTypes.RECORD_TYPE_TB -> {
|
||||
holder.time.visibility = View.VISIBLE
|
||||
holder.value.visibility = View.VISIBLE
|
||||
holder.stringValue.visibility = View.GONE
|
||||
holder.bolusType.visibility = View.GONE
|
||||
holder.duration.visibility = View.GONE
|
||||
holder.dailyBasal.visibility = View.GONE
|
||||
holder.dailyBolus.visibility = View.GONE
|
||||
holder.dailyTotal.visibility = View.GONE
|
||||
holder.alarm.visibility = View.GONE
|
||||
holder.binding.time.visibility = View.VISIBLE
|
||||
holder.binding.value.visibility = View.VISIBLE
|
||||
holder.binding.stringValue.visibility = View.GONE
|
||||
holder.binding.bolusType.visibility = View.GONE
|
||||
holder.binding.duration.visibility = View.GONE
|
||||
holder.binding.dailyBasal.visibility = View.GONE
|
||||
holder.binding.dailyBolus.visibility = View.GONE
|
||||
holder.binding.dailyTotal.visibility = View.GONE
|
||||
holder.binding.alarm.visibility = View.GONE
|
||||
}
|
||||
|
||||
RecordTypes.RECORD_TYPE_SUSPEND -> {
|
||||
holder.time.visibility = View.VISIBLE
|
||||
holder.value.visibility = View.GONE
|
||||
holder.stringValue.visibility = View.VISIBLE
|
||||
holder.bolusType.visibility = View.GONE
|
||||
holder.duration.visibility = View.GONE
|
||||
holder.dailyBasal.visibility = View.GONE
|
||||
holder.dailyBolus.visibility = View.GONE
|
||||
holder.dailyTotal.visibility = View.GONE
|
||||
holder.alarm.visibility = View.GONE
|
||||
RecordTypes.RECORD_TYPE_SUSPEND -> {
|
||||
holder.binding.time.visibility = View.VISIBLE
|
||||
holder.binding.value.visibility = View.GONE
|
||||
holder.binding.stringValue.visibility = View.VISIBLE
|
||||
holder.binding.bolusType.visibility = View.GONE
|
||||
holder.binding.duration.visibility = View.GONE
|
||||
holder.binding.dailyBasal.visibility = View.GONE
|
||||
holder.binding.dailyBolus.visibility = View.GONE
|
||||
holder.binding.dailyTotal.visibility = View.GONE
|
||||
holder.binding.alarm.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -242,25 +240,17 @@ class DanaHistoryActivity : NoSplashAppCompatActivity() {
|
|||
|
||||
inner class HistoryViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
var time: TextView = itemView.findViewById(R.id.danar_history_time)
|
||||
var value: TextView = itemView.findViewById(R.id.danar_history_value)
|
||||
var bolusType: TextView = itemView.findViewById(R.id.danar_history_bolustype)
|
||||
var stringValue: TextView = itemView.findViewById(R.id.danar_history_stringvalue)
|
||||
var duration: TextView = itemView.findViewById(R.id.danar_history_duration)
|
||||
var dailyBasal: TextView = itemView.findViewById(R.id.danar_history_dailybasal)
|
||||
var dailyBolus: TextView = itemView.findViewById(R.id.danar_history_dailybolus)
|
||||
var dailyTotal: TextView = itemView.findViewById(R.id.danar_history_dailytotal)
|
||||
var alarm: TextView = itemView.findViewById(R.id.danar_history_alarm)
|
||||
val binding = DanarHistoryItemBinding.bind(itemView)
|
||||
}
|
||||
}
|
||||
|
||||
private fun loadDataFromDB(type: Byte) {
|
||||
historyList = databaseHelper.getDanaRHistoryRecordsByType(type)
|
||||
runOnUiThread { binding.recyclerview.swapAdapter(RecyclerViewAdapter(historyList), false) }
|
||||
private fun swapAdapter(type: Byte) {
|
||||
disposable += danaHistoryRecordDao
|
||||
.allFromByType(dateUtil.now() - T.months(1).msecs(), type)
|
||||
.subscribeOn(aapsSchedulers.io)
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe { historyList -> binding.recyclerview.swapAdapter(RecyclerViewAdapter(historyList), false) }
|
||||
}
|
||||
|
||||
private fun clearCardView() {
|
||||
historyList = ArrayList()
|
||||
runOnUiThread { binding.recyclerview.swapAdapter(RecyclerViewAdapter(historyList), false) }
|
||||
}
|
||||
private fun clearCardView() = binding.recyclerview.swapAdapter(RecyclerViewAdapter(ArrayList()), false)
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
package info.nightscout.androidaps.dana.database
|
||||
|
||||
import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.TypeConverters
|
||||
|
||||
const val TABLE_DANA_HISTORY = "danaHistory"
|
||||
|
||||
@Database(
|
||||
entities = [DanaHistoryRecord::class],
|
||||
exportSchema = true,
|
||||
version = DanaHistoryDatabase.VERSION
|
||||
)
|
||||
abstract class DanaHistoryDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun historyRecordDao(): DanaHistoryRecordDao
|
||||
|
||||
companion object {
|
||||
|
||||
const val VERSION = 1
|
||||
|
||||
fun build(context: Context) =
|
||||
Room.databaseBuilder(
|
||||
context.applicationContext,
|
||||
DanaHistoryDatabase::class.java,
|
||||
"dana_database.db"
|
||||
)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
}
|
|
@ -0,0 +1,19 @@
|
|||
package info.nightscout.androidaps.dana.database
|
||||
|
||||
import androidx.room.Entity
|
||||
import androidx.room.Index
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = TABLE_DANA_HISTORY,
|
||||
indices = [Index("code", "timestamp")])
|
||||
data class DanaHistoryRecord(
|
||||
@PrimaryKey var timestamp: Long,
|
||||
var code: Byte = 0x0F,
|
||||
var value: Double = 0.0,
|
||||
var bolusType: String = "None",
|
||||
var stringValue: String = "",
|
||||
var duration: Long = 0,
|
||||
var dailyBasal: Double = 0.0,
|
||||
var dailyBolus: Double = 0.0,
|
||||
var alarm: String = ""
|
||||
)
|
|
@ -0,0 +1,17 @@
|
|||
package info.nightscout.androidaps.dana.database
|
||||
|
||||
import androidx.room.Dao
|
||||
import androidx.room.Insert
|
||||
import androidx.room.OnConflictStrategy
|
||||
import androidx.room.Query
|
||||
import io.reactivex.Single
|
||||
|
||||
@Dao
|
||||
abstract class DanaHistoryRecordDao {
|
||||
|
||||
@Query("SELECT * from $TABLE_DANA_HISTORY WHERE timestamp >= :timestamp AND code = :type")
|
||||
abstract fun allFromByType(timestamp: Long, type: Byte): Single<List<DanaHistoryRecord>>
|
||||
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
abstract fun createOrUpdate(danaHistoryRecord: DanaHistoryRecord)
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
package info.nightscout.androidaps.dana.di
|
||||
|
||||
import android.content.Context
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import info.nightscout.androidaps.dana.database.DanaHistoryDatabase
|
||||
import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
class DanaHistoryModule {
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
internal fun provideDatabase(context: Context): DanaHistoryDatabase = DanaHistoryDatabase.build(context)
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
internal fun provideHistoryRecordDao(danaHistoryDatabase: DanaHistoryDatabase): DanaHistoryRecordDao =
|
||||
danaHistoryDatabase.historyRecordDao()
|
||||
}
|
|
@ -1,10 +1,15 @@
|
|||
package info.nightscout.androidaps.dana.di
|
||||
|
||||
import android.content.Context
|
||||
import dagger.Module
|
||||
import dagger.Provides
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import info.nightscout.androidaps.dana.DanaFragment
|
||||
import info.nightscout.androidaps.dana.activities.DanaHistoryActivity
|
||||
import info.nightscout.androidaps.dana.activities.DanaUserOptionsActivity
|
||||
import info.nightscout.androidaps.dana.database.DanaHistoryDatabase
|
||||
import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao
|
||||
import javax.inject.Singleton
|
||||
|
||||
@Module
|
||||
@Suppress("unused")
|
||||
|
|
|
@ -1,94 +1,110 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@+id/relativeLayout"
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="fill_parent"
|
||||
tools:context="info.nightscout.androidaps.dana.activities.DanaHistoryActivity">
|
||||
|
||||
|
||||
<RelativeLayout
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:id="@+id/header"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentTop="true"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginBottom="10dp"
|
||||
android:background="@color/activity_title_background"
|
||||
android:orientation="horizontal"
|
||||
android:padding="5dp">
|
||||
android:padding="5dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/spinner"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:contentDescription="@string/pumphistory"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:srcCompat="@drawable/ic_danarhistory" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView2"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerInParent="true"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_gravity="center"
|
||||
android:layout_marginLeft="10dp"
|
||||
android:layout_marginRight="10dp"
|
||||
android:text="@string/pumphistory"
|
||||
android:textAlignment="center"
|
||||
android:textAppearance="?android:attr/textAppearanceLarge" />
|
||||
android:textAppearance="?android:attr/textAppearanceLarge"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
</RelativeLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/spacer"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
<TextView
|
||||
android:id="@+id/textView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/header"
|
||||
android:orientation="horizontal"
|
||||
android:padding="5dp" />
|
||||
android:layout_marginStart="10dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:text="@string/eventtype"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall"
|
||||
app:layout_constraintBottom_toBottomOf="@+id/spinner"
|
||||
app:layout_constraintEnd_toStartOf="@+id/spinner"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="@+id/spinner" />
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/spinner_layout"
|
||||
android:layout_width="match_parent"
|
||||
<Spinner
|
||||
android:id="@+id/spinner"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@+id/spacer"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="15dp"
|
||||
android:layout_marginEnd="20dp"
|
||||
android:text="@string/eventtype"
|
||||
android:textAppearance="?android:attr/textAppearanceSmall" />
|
||||
|
||||
<Spinner
|
||||
android:id="@+id/spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="20dp" />
|
||||
|
||||
</LinearLayout>
|
||||
android:layout_marginEnd="10dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/status"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@+id/textView"
|
||||
app:layout_constraintTop_toBottomOf="@+id/header" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/status"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/spinner_layout"
|
||||
android:layout_gravity="center_horizontal"
|
||||
android:gravity="center_horizontal" />
|
||||
android:layout_marginTop="10dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:gravity="center_horizontal"
|
||||
app:layout_constraintBottom_toTopOf="@+id/recyclerview"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/textView" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
android:id="@+id/recyclerview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_above="@id/reload"
|
||||
android:layout_below="@+id/status" />
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintBottom_toTopOf="@+id/reload"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/status" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/reload"
|
||||
style="@style/Widget.AppCompat.Button"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_marginBottom="1dp"
|
||||
android:drawableStart="@drawable/ic_actions_refill"
|
||||
android:text="@string/reload" />
|
||||
android:text="@string/reload"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/recyclerview" />
|
||||
|
||||
</RelativeLayout>
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
|
|
|
@ -1,89 +1,109 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:card_view="http://schemas.android.com/apk/res-auto"
|
||||
android:id="@+id/danar_history_cardview"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
card_view:cardBackgroundColor="@color/cardColorBackground"
|
||||
card_view:cardCornerRadius="6dp"
|
||||
card_view:cardUseCompatPadding="true"
|
||||
card_view:contentPadding="6dp">
|
||||
card_view:cardBackgroundColor="?android:colorBackground">
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:baselineAligned="true"
|
||||
android:orientation="horizontal">
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="vertical">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:baselineAligned="true"
|
||||
android:orientation="horizontal">
|
||||
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_time"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="27.06.2016 18:00" />
|
||||
<TextView
|
||||
android:id="@+id/time"
|
||||
android:layout_width="120dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="27.06.2016 18:00"
|
||||
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_value"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="0.25"
|
||||
android:gravity="right" />
|
||||
<TextView
|
||||
android:id="@+id/value"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="0.25"
|
||||
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_bolustype"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="E"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/bolus_type"
|
||||
android:layout_width="20dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="E"
|
||||
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_stringvalue"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="XXXXXXX"
|
||||
/>
|
||||
<TextView
|
||||
android:id="@+id/string_value"
|
||||
android:layout_width="150dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text=""
|
||||
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_duration"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="30"
|
||||
android:gravity="right" />
|
||||
<TextView
|
||||
android:id="@+id/duration"
|
||||
android:layout_width="30dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:paddingLeft="5dp"
|
||||
android:text="30"
|
||||
tools:ignore="HardcodedText,RtlHardcoded,RtlSymmetry" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_dailybasal"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:gravity="right" />
|
||||
<TextView
|
||||
android:id="@+id/daily_basal"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:paddingLeft="5dp"
|
||||
tools:ignore="RtlHardcoded,RtlSymmetry" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_dailybolus"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
android:gravity="right" />
|
||||
<TextView
|
||||
android:id="@+id/daily_bolus"
|
||||
android:layout_width="50dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:paddingLeft="5dp"
|
||||
tools:ignore="RtlHardcoded,RtlSymmetry" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_dailytotal"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="10dp"
|
||||
android:gravity="right"
|
||||
android:visibility="gone"/>
|
||||
<TextView
|
||||
android:id="@+id/daily_total"
|
||||
android:layout_width="56dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:gravity="right"
|
||||
android:paddingLeft="10dp"
|
||||
android:visibility="gone"
|
||||
tools:ignore="RtlHardcoded,RtlSymmetry" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/danar_history_alarm"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp" />
|
||||
<TextView
|
||||
android:id="@+id/alarm"
|
||||
android:layout_width="100dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingLeft="5dp"
|
||||
tools:ignore="RtlHardcoded,RtlSymmetry" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
<View
|
||||
android:layout_width="fill_parent"
|
||||
android:layout_height="2dip"
|
||||
android:layout_marginLeft="5dp"
|
||||
android:layout_marginTop="5dp"
|
||||
android:layout_marginRight="5dp"
|
||||
android:layout_marginBottom="5dp"
|
||||
android:background="@color/list_delimiter" />
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
|
|
@ -14,6 +14,7 @@ import javax.inject.Inject;
|
|||
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.dana.DanaPump;
|
||||
import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao;
|
||||
import info.nightscout.androidaps.danaRKorean.DanaRKoreanPlugin;
|
||||
import info.nightscout.androidaps.danaRv2.DanaRv2Plugin;
|
||||
import info.nightscout.androidaps.danar.DanaRPlugin;
|
||||
|
@ -54,7 +55,7 @@ public class MessageBase {
|
|||
@Inject public TemporaryBasalStorage temporaryBasalStorage;
|
||||
@Inject public ConstraintChecker constraintChecker;
|
||||
@Inject public PumpSync pumpSync;
|
||||
@Inject public DatabaseHelperInterface databaseHelper;
|
||||
@Inject public DanaHistoryRecordDao danaHistoryRecordDao;
|
||||
HasAndroidInjector injector;
|
||||
|
||||
public byte[] buffer = new byte[512];
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package info.nightscout.androidaps.danar.comm
|
||||
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord
|
||||
import info.nightscout.androidaps.dana.comm.RecordTypes
|
||||
import info.nightscout.androidaps.dana.database.DanaHistoryRecord
|
||||
import info.nightscout.androidaps.events.EventDanaRSyncStatus
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.utils.T
|
||||
|
||||
open class MsgHistoryAll(
|
||||
injector: HasAndroidInjector
|
||||
|
@ -24,101 +26,102 @@ open class MsgHistoryAll(
|
|||
val paramByte7 = intFromBuff(bytes, 6, 1).toByte()
|
||||
val paramByte8 = intFromBuff(bytes, 7, 1).toByte()
|
||||
val value = intFromBuff(bytes, 8, 2).toDouble()
|
||||
val danaRHistoryRecord = DanaRHistoryRecord()
|
||||
danaRHistoryRecord.recordCode = recordCode
|
||||
danaRHistoryRecord.setBytes(bytes)
|
||||
val danaHistoryRecord = DanaHistoryRecord(
|
||||
timestamp = date,
|
||||
code = recordCode
|
||||
)
|
||||
var messageType = ""
|
||||
when (recordCode) {
|
||||
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_BOLUS -> {
|
||||
val datetime = dateTimeFromBuff(bytes, 1) // 5 bytes
|
||||
danaRHistoryRecord.recordDate = datetime
|
||||
danaHistoryRecord.timestamp = datetime
|
||||
when (0xF0 and paramByte8.toInt()) {
|
||||
0xA0 -> {
|
||||
danaRHistoryRecord.bolusType = "DS"
|
||||
danaHistoryRecord.bolusType = "DS"
|
||||
messageType += "DS bolus"
|
||||
}
|
||||
|
||||
0xC0 -> {
|
||||
danaRHistoryRecord.bolusType = "E"
|
||||
danaHistoryRecord.bolusType = "E"
|
||||
messageType += "E bolus"
|
||||
}
|
||||
|
||||
0x80 -> {
|
||||
danaRHistoryRecord.bolusType = "S"
|
||||
danaHistoryRecord.bolusType = "S"
|
||||
messageType += "S bolus"
|
||||
}
|
||||
|
||||
0x90 -> {
|
||||
danaRHistoryRecord.bolusType = "DE"
|
||||
danaHistoryRecord.bolusType = "DE"
|
||||
messageType += "DE bolus"
|
||||
}
|
||||
|
||||
else -> danaRHistoryRecord.bolusType = "None"
|
||||
else -> danaHistoryRecord.bolusType = "None"
|
||||
}
|
||||
danaRHistoryRecord.recordDuration = (paramByte8.toInt() and 0x0F) * 60 + paramByte7.toInt()
|
||||
danaRHistoryRecord.recordValue = value * 0.01
|
||||
danaHistoryRecord.duration = T.mins((paramByte8.toInt() and 0x0F) * 60 + paramByte7.toLong()).msecs()
|
||||
danaHistoryRecord.value = value * 0.01
|
||||
}
|
||||
|
||||
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_DAILY -> {
|
||||
messageType += "dailyinsulin"
|
||||
danaRHistoryRecord.recordDate = date
|
||||
danaRHistoryRecord.recordDailyBasal = dailyBasal
|
||||
danaRHistoryRecord.recordDailyBolus = dailyBolus
|
||||
danaHistoryRecord.timestamp = date
|
||||
danaHistoryRecord.dailyBasal = dailyBasal
|
||||
danaHistoryRecord.dailyBolus = dailyBolus
|
||||
}
|
||||
|
||||
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_PRIME -> {
|
||||
messageType += "prime"
|
||||
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec
|
||||
danaRHistoryRecord.recordValue = value * 0.01
|
||||
danaHistoryRecord.timestamp = datetimewihtsec
|
||||
danaHistoryRecord.value = value * 0.01
|
||||
}
|
||||
|
||||
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_ERROR -> {
|
||||
messageType += "error"
|
||||
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec
|
||||
danaRHistoryRecord.recordValue = value * 0.01
|
||||
danaHistoryRecord.timestamp = datetimewihtsec
|
||||
danaHistoryRecord.value = value * 0.01
|
||||
}
|
||||
|
||||
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_REFILL -> {
|
||||
messageType += "refill"
|
||||
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec
|
||||
danaRHistoryRecord.recordValue = value * 0.01
|
||||
danaHistoryRecord.timestamp = datetimewihtsec
|
||||
danaHistoryRecord.value = value * 0.01
|
||||
}
|
||||
|
||||
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_BASALHOUR -> {
|
||||
messageType += "basal hour"
|
||||
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec
|
||||
danaRHistoryRecord.recordValue = value * 0.01
|
||||
danaHistoryRecord.timestamp = datetimewihtsec
|
||||
danaHistoryRecord.value = value * 0.01
|
||||
}
|
||||
|
||||
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_TB -> {
|
||||
messageType += "tb"
|
||||
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec
|
||||
danaRHistoryRecord.recordValue = value * 0.01
|
||||
danaHistoryRecord.timestamp = datetimewihtsec
|
||||
danaHistoryRecord.value = value * 0.01
|
||||
}
|
||||
|
||||
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_GLUCOSE -> {
|
||||
messageType += "glucose"
|
||||
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec
|
||||
danaRHistoryRecord.recordValue = value
|
||||
danaHistoryRecord.timestamp = datetimewihtsec
|
||||
danaHistoryRecord.value = value
|
||||
}
|
||||
|
||||
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_CARBO -> {
|
||||
messageType += "carbo"
|
||||
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec
|
||||
danaRHistoryRecord.recordValue = value
|
||||
danaHistoryRecord.timestamp = datetimewihtsec
|
||||
danaHistoryRecord.value = value
|
||||
}
|
||||
|
||||
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_ALARM -> {
|
||||
messageType += "alarm"
|
||||
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec
|
||||
danaHistoryRecord.timestamp = datetimewihtsec
|
||||
var strAlarm = "None"
|
||||
when (paramByte8.toInt()) {
|
||||
67 -> strAlarm = "Check"
|
||||
|
@ -126,22 +129,22 @@ open class MsgHistoryAll(
|
|||
66 -> strAlarm = "Low Battery"
|
||||
83 -> strAlarm = "Shutdown"
|
||||
}
|
||||
danaRHistoryRecord.recordAlarm = strAlarm
|
||||
danaRHistoryRecord.recordValue = value * 0.01
|
||||
danaHistoryRecord.alarm = strAlarm
|
||||
danaHistoryRecord.value = value * 0.01
|
||||
}
|
||||
|
||||
info.nightscout.androidaps.dana.comm.RecordTypes.RECORD_TYPE_SUSPEND -> {
|
||||
RecordTypes.RECORD_TYPE_SUSPEND -> {
|
||||
messageType += "suspend"
|
||||
val datetimewihtsec = dateTimeSecFromBuff(bytes, 1) // 6 bytes
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec
|
||||
danaHistoryRecord.timestamp = datetimewihtsec
|
||||
var strRecordValue = "Off"
|
||||
if (paramByte8.toInt() == 79) strRecordValue = "On"
|
||||
danaRHistoryRecord.stringRecordValue = strRecordValue
|
||||
danaHistoryRecord.stringValue = strRecordValue
|
||||
}
|
||||
|
||||
17.toByte() -> failed = true
|
||||
}
|
||||
databaseHelper.createOrUpdate(danaRHistoryRecord)
|
||||
rxBus.send(EventDanaRSyncStatus(dateUtil.dateAndTimeString(danaRHistoryRecord.recordDate) + " " + messageType))
|
||||
danaHistoryRecordDao.createOrUpdate(danaHistoryRecord)
|
||||
rxBus.send(EventDanaRSyncStatus(dateUtil.dateAndTimeString(danaHistoryRecord.timestamp) + " " + messageType))
|
||||
}
|
||||
}
|
|
@ -3,13 +3,14 @@ package info.nightscout.androidaps.danars.comm
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.dana.DanaPump
|
||||
import info.nightscout.androidaps.dana.comm.RecordTypes
|
||||
import info.nightscout.androidaps.db.DanaRHistoryRecord
|
||||
import info.nightscout.androidaps.dana.database.DanaHistoryRecord
|
||||
import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao
|
||||
import info.nightscout.androidaps.events.EventDanaRSyncStatus
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||
import info.nightscout.androidaps.interfaces.PumpSync
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import org.joda.time.DateTime
|
||||
import java.util.*
|
||||
import javax.inject.Inject
|
||||
|
@ -20,7 +21,7 @@ abstract class DanaRS_Packet_History_(
|
|||
) : DanaRS_Packet(injector) {
|
||||
|
||||
@Inject lateinit var rxBus: RxBusWrapper
|
||||
@Inject lateinit var databaseHelper: DatabaseHelperInterface
|
||||
@Inject lateinit var danaHistoryRecordDao: DanaHistoryRecordDao
|
||||
@Inject lateinit var pumpSync: PumpSync
|
||||
@Inject lateinit var danaPump: DanaPump
|
||||
|
||||
|
@ -33,7 +34,7 @@ abstract class DanaRS_Packet_History_(
|
|||
|
||||
var done = false
|
||||
var totalCount = 0
|
||||
val danaRHistoryRecord = DanaRHistoryRecord()
|
||||
val danaRHistoryRecord = DanaHistoryRecord(0)
|
||||
|
||||
init {
|
||||
val cal = GregorianCalendar()
|
||||
|
@ -91,15 +92,14 @@ abstract class DanaRS_Packet_History_(
|
|||
val historyCode = byteArrayToInt(getBytes(data, DATA_START + 7, 1))
|
||||
val paramByte8 = historyCode.toByte()
|
||||
val value: Int = (data[DATA_START + 8].toInt() and 0xFF shl 8) + (data[DATA_START + 9].toInt() and 0xFF)
|
||||
danaRHistoryRecord.setBytes(data)
|
||||
// danaRHistoryRecord.recordCode is different from DanaR codes
|
||||
// danaRHistoryRecord.code is different from DanaR codes
|
||||
// set in switch for every type
|
||||
var messageType = ""
|
||||
when (recordCode) {
|
||||
0x02 -> {
|
||||
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_BOLUS
|
||||
danaRHistoryRecord.code = RecordTypes.RECORD_TYPE_BOLUS
|
||||
val datetime = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute)
|
||||
danaRHistoryRecord.recordDate = datetime.millis
|
||||
danaRHistoryRecord.timestamp = datetime.millis
|
||||
when (0xF0 and paramByte8.toInt()) {
|
||||
0xA0 -> {
|
||||
danaRHistoryRecord.bolusType = "DS"
|
||||
|
@ -123,80 +123,80 @@ abstract class DanaRS_Packet_History_(
|
|||
|
||||
else -> danaRHistoryRecord.bolusType = "None"
|
||||
}
|
||||
danaRHistoryRecord.recordDuration = (paramByte8.toInt() and 0x0F) * 60 + paramByte7.toInt()
|
||||
danaRHistoryRecord.recordValue = value * 0.01
|
||||
danaRHistoryRecord.duration = T.mins((paramByte8.toInt() and 0x0F) * 60 + paramByte7.toLong()).msecs()
|
||||
danaRHistoryRecord.value = value * 0.01
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetime.millis) + " Code: " + historyCode + " Value: " + value)
|
||||
}
|
||||
|
||||
0x03 -> {
|
||||
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_DAILY
|
||||
danaRHistoryRecord.code = RecordTypes.RECORD_TYPE_DAILY
|
||||
messageType += "dailyinsulin"
|
||||
val date = DateTime(2000 + historyYear, historyMonth, historyDay, 0, 0)
|
||||
danaRHistoryRecord.recordDate = date.millis
|
||||
danaRHistoryRecord.recordDailyBasal = dailyBasal
|
||||
danaRHistoryRecord.recordDailyBolus = dailyBolus
|
||||
danaRHistoryRecord.timestamp = date.millis
|
||||
danaRHistoryRecord.dailyBasal = dailyBasal
|
||||
danaRHistoryRecord.dailyBolus = dailyBolus
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(date.millis) + " Code: " + historyCode + " Value: " + value)
|
||||
}
|
||||
|
||||
0x04 -> {
|
||||
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_PRIME
|
||||
danaRHistoryRecord.code = RecordTypes.RECORD_TYPE_PRIME
|
||||
messageType += "prime"
|
||||
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec.millis
|
||||
danaRHistoryRecord.recordValue = value * 0.01
|
||||
danaRHistoryRecord.timestamp = datetimewihtsec.millis
|
||||
danaRHistoryRecord.value = value * 0.01
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
|
||||
}
|
||||
|
||||
0x05 -> {
|
||||
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_REFILL
|
||||
danaRHistoryRecord.code = RecordTypes.RECORD_TYPE_REFILL
|
||||
messageType += "refill"
|
||||
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec.millis
|
||||
danaRHistoryRecord.recordValue = value * 0.01
|
||||
danaRHistoryRecord.timestamp = datetimewihtsec.millis
|
||||
danaRHistoryRecord.value = value * 0.01
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
|
||||
}
|
||||
|
||||
0x0b -> {
|
||||
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_BASALHOUR
|
||||
danaRHistoryRecord.code = RecordTypes.RECORD_TYPE_BASALHOUR
|
||||
messageType += "basal hour"
|
||||
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec.millis
|
||||
danaRHistoryRecord.recordValue = value * 0.01
|
||||
danaRHistoryRecord.timestamp = datetimewihtsec.millis
|
||||
danaRHistoryRecord.value = value * 0.01
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
|
||||
}
|
||||
|
||||
0x99 -> {
|
||||
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_TEMP_BASAL
|
||||
danaRHistoryRecord.code = RecordTypes.RECORD_TYPE_TEMP_BASAL
|
||||
messageType += "tb"
|
||||
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec.millis
|
||||
danaRHistoryRecord.recordValue = value * 0.01
|
||||
danaRHistoryRecord.timestamp = datetimewihtsec.millis
|
||||
danaRHistoryRecord.value = value * 0.01
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
|
||||
}
|
||||
|
||||
0x06 -> {
|
||||
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_GLUCOSE
|
||||
danaRHistoryRecord.code = RecordTypes.RECORD_TYPE_GLUCOSE
|
||||
messageType += "glucose"
|
||||
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec.millis
|
||||
danaRHistoryRecord.recordValue = value.toDouble()
|
||||
danaRHistoryRecord.timestamp = datetimewihtsec.millis
|
||||
danaRHistoryRecord.value = value.toDouble()
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
|
||||
}
|
||||
|
||||
0x07 -> {
|
||||
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_CARBO
|
||||
danaRHistoryRecord.code = RecordTypes.RECORD_TYPE_CARBO
|
||||
messageType += "carbo"
|
||||
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec.millis
|
||||
danaRHistoryRecord.recordValue = value.toDouble()
|
||||
danaRHistoryRecord.timestamp = datetimewihtsec.millis
|
||||
danaRHistoryRecord.value = value.toDouble()
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
|
||||
}
|
||||
|
||||
0x0a -> {
|
||||
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_ALARM
|
||||
danaRHistoryRecord.code = RecordTypes.RECORD_TYPE_ALARM
|
||||
messageType += "alarm"
|
||||
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec.millis
|
||||
danaRHistoryRecord.timestamp = datetimewihtsec.millis
|
||||
var strAlarm = "None"
|
||||
when (paramByte8) {
|
||||
'P'.toByte() -> strAlarm = "Basal Compare"
|
||||
|
@ -208,36 +208,36 @@ abstract class DanaRS_Packet_History_(
|
|||
'B'.toByte() -> strAlarm = "Low Battery"
|
||||
'S'.toByte() -> strAlarm = "Shutdown"
|
||||
}
|
||||
danaRHistoryRecord.recordAlarm = strAlarm
|
||||
danaRHistoryRecord.recordValue = value * 0.01
|
||||
danaRHistoryRecord.alarm = strAlarm
|
||||
danaRHistoryRecord.value = value * 0.01
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
|
||||
}
|
||||
|
||||
0x09 -> {
|
||||
danaRHistoryRecord.recordCode = RecordTypes.RECORD_TYPE_SUSPEND
|
||||
danaRHistoryRecord.code = RecordTypes.RECORD_TYPE_SUSPEND
|
||||
messageType += "suspend"
|
||||
val datetimewihtsec = DateTime(2000 + historyYear, historyMonth, historyDay, historyHour, historyMinute, historySecond)
|
||||
danaRHistoryRecord.recordDate = datetimewihtsec.millis
|
||||
danaRHistoryRecord.timestamp = datetimewihtsec.millis
|
||||
var strRecordValue = "Off"
|
||||
if (paramByte8.toInt() == 79) strRecordValue = "On"
|
||||
danaRHistoryRecord.stringRecordValue = strRecordValue
|
||||
danaRHistoryRecord.stringValue = strRecordValue
|
||||
aapsLogger.debug(LTag.PUMPCOMM, "History packet: " + recordCode + " Date: " + dateUtil.dateAndTimeString(datetimewihtsec.millis) + " Code: " + historyCode + " Value: " + value)
|
||||
}
|
||||
}
|
||||
databaseHelper.createOrUpdate(danaRHistoryRecord)
|
||||
danaHistoryRecordDao.createOrUpdate(danaRHistoryRecord)
|
||||
//If it is a TDD, store it for stats also.
|
||||
if (danaRHistoryRecord.recordCode == RecordTypes.RECORD_TYPE_DAILY) {
|
||||
if (danaRHistoryRecord.code == RecordTypes.RECORD_TYPE_DAILY) {
|
||||
pumpSync.createOrUpdateTotalDailyDose(
|
||||
timestamp = danaRHistoryRecord.recordDate,
|
||||
bolusAmount = danaRHistoryRecord.recordDailyBolus,
|
||||
basalAmount = danaRHistoryRecord.recordDailyBasal,
|
||||
timestamp = danaRHistoryRecord.timestamp,
|
||||
bolusAmount = danaRHistoryRecord.dailyBolus,
|
||||
basalAmount = danaRHistoryRecord.dailyBasal,
|
||||
totalAmount = 0.0,
|
||||
pumpId = null,
|
||||
pumpType = PumpType.DANA_RS,
|
||||
danaPump.serialNumber
|
||||
)
|
||||
}
|
||||
rxBus.send(EventDanaRSyncStatus(dateUtil.dateAndTimeString(danaRHistoryRecord.recordDate) + " " + messageType))
|
||||
rxBus.send(EventDanaRSyncStatus(dateUtil.dateAndTimeString(danaRHistoryRecord.timestamp) + " " + messageType))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,9 +3,8 @@ package info.nightscout.androidaps.danars.comm
|
|||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.dana.comm.RecordTypes
|
||||
import info.nightscout.androidaps.dana.database.DanaHistoryRecordDao
|
||||
import info.nightscout.androidaps.danars.DanaRSTestBase
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSUpload
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
@ -16,8 +15,7 @@ import java.util.*
|
|||
@RunWith(PowerMockRunner::class)
|
||||
class DanaRSPacketHistoryAlarmTest : DanaRSTestBase() {
|
||||
|
||||
@Mock lateinit var databaseHelper: DatabaseHelperInterface
|
||||
@Mock lateinit var nsUpload: NSUpload
|
||||
@Mock lateinit var danaHistoryRecordDao: DanaHistoryRecordDao
|
||||
|
||||
private val packetInjector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
|
@ -27,7 +25,7 @@ class DanaRSPacketHistoryAlarmTest : DanaRSTestBase() {
|
|||
}
|
||||
if (it is DanaRS_Packet_History_Alarm) {
|
||||
it.rxBus = rxBus
|
||||
it.databaseHelper = databaseHelper
|
||||
it.danaHistoryRecordDao = danaHistoryRecordDao
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -49,14 +47,14 @@ class DanaRSPacketHistoryAlarmTest : DanaRSTestBase() {
|
|||
putByteToArray(array, 9, 100) // value
|
||||
|
||||
packet.handleMessage(array)
|
||||
Assert.assertEquals(RecordTypes.RECORD_TYPE_ALARM, packet.danaRHistoryRecord.recordCode)
|
||||
Assert.assertEquals(RecordTypes.RECORD_TYPE_ALARM, packet.danaRHistoryRecord.code)
|
||||
val date = GregorianCalendar().also {
|
||||
it.clear()
|
||||
it.set(2019, 1, 4, 20, 11, 35)
|
||||
}
|
||||
Assert.assertEquals(date.timeInMillis, packet.danaRHistoryRecord.recordDate)
|
||||
Assert.assertEquals("Occlusion", packet.danaRHistoryRecord.recordAlarm)
|
||||
Assert.assertEquals(3.56, packet.danaRHistoryRecord.recordValue, 0.01)
|
||||
Assert.assertEquals(date.timeInMillis, packet.danaRHistoryRecord.timestamp)
|
||||
Assert.assertEquals("Occlusion", packet.danaRHistoryRecord.alarm)
|
||||
Assert.assertEquals(3.56, packet.danaRHistoryRecord.value, 0.01)
|
||||
Assert.assertEquals("REVIEW__ALARM", packet.friendlyName)
|
||||
}
|
||||
}
|
|
@ -922,9 +922,9 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
|||
extendedBolus.durationInMinutes = (int) ((System.currentTimeMillis() - extendedBolus.date) / 60000);
|
||||
if (extendedBolus.durationInMinutes <= 0) {
|
||||
final String _id = extendedBolus._id;
|
||||
if (NSUpload.isIdValid(_id))
|
||||
nsUpload.removeCareportalEntryFromNS(_id);
|
||||
else uploadQueue.removeByMongoId("dbAdd", _id);
|
||||
// if (NSUpload.isIdValid(_id))
|
||||
// nsUpload.removeCareportalEntryFromNS(_id);
|
||||
// else uploadQueue.removeByMongoId("dbAdd", _id);
|
||||
databaseHelper.delete(extendedBolus);
|
||||
} else
|
||||
treatmentsPlugin.addToHistoryExtendedBolus(extendedBolus);
|
||||
|
@ -1436,8 +1436,8 @@ public class LocalInsightPlugin extends PumpPluginBase implements Pump, Constrai
|
|||
ExtendedBolus extendedBolus = databaseHelper.getExtendedBolusByPumpId(bolusID.id);
|
||||
if (extendedBolus != null) {
|
||||
final String _id = extendedBolus._id;
|
||||
if (NSUpload.isIdValid(_id)) nsUpload.removeCareportalEntryFromNS(_id);
|
||||
else uploadQueue.removeByMongoId("dbAdd", _id);
|
||||
// if (NSUpload.isIdValid(_id)) nsUpload.removeCareportalEntryFromNS(_id);
|
||||
// else uploadQueue.removeByMongoId("dbAdd", _id);
|
||||
databaseHelper.delete(extendedBolus);
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue