remove old db code
This commit is contained in:
parent
91ad9a3ca9
commit
9d29cafbe6
74 changed files with 137 additions and 3184 deletions
|
@ -6,7 +6,6 @@ import android.content.IntentFilter
|
|||
import android.net.ConnectivityManager
|
||||
import android.net.wifi.WifiManager
|
||||
import android.os.Build
|
||||
import com.j256.ormlite.android.apptools.OpenHelperManager
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.DaggerApplication
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
|
@ -15,11 +14,10 @@ import info.nightscout.androidaps.database.entities.UserEntry
|
|||
import info.nightscout.androidaps.database.transactions.InsertIfNewByTimestampTherapyEventTransaction
|
||||
import info.nightscout.androidaps.database.transactions.VersionChangeTransaction
|
||||
import info.nightscout.androidaps.db.CompatDBHelper
|
||||
import info.nightscout.androidaps.db.DatabaseHelper
|
||||
import info.nightscout.androidaps.db.StaticInjector
|
||||
import info.nightscout.androidaps.di.StaticInjector
|
||||
import info.nightscout.androidaps.dependencyInjection.DaggerAppComponent
|
||||
import info.nightscout.androidaps.interfaces.ConfigBuilder
|
||||
import info.nightscout.androidaps.interfaces.Config
|
||||
import info.nightscout.androidaps.interfaces.ConfigBuilder
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
|
@ -63,7 +61,6 @@ class MainApp : DaggerApplication() {
|
|||
super.onCreate()
|
||||
aapsLogger.debug("onCreate")
|
||||
update(this)
|
||||
dbHelper = OpenHelperManager.getHelper(this, DatabaseHelper::class.java)
|
||||
|
||||
var gitRemote: String? = BuildConfig.REMOTE
|
||||
var commitHash: String? = BuildConfig.HEAD
|
||||
|
@ -134,9 +131,4 @@ class MainApp : DaggerApplication() {
|
|||
keepAliveManager.cancelAlarm(this)
|
||||
super.onTerminate()
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
lateinit var dbHelper: DatabaseHelper
|
||||
}
|
||||
}
|
|
@ -182,7 +182,7 @@ class MyPreferenceFragment : PreferenceFragmentCompat(), OnSharedPreferenceChang
|
|||
addPreferencesFromResourceIfEnabled(automationPlugin, rootKey)
|
||||
addPreferencesFromResourceIfEnabled(wearPlugin, rootKey)
|
||||
addPreferencesFromResourceIfEnabled(statusLinePlugin, rootKey)
|
||||
addPreferencesFromResource(R.xml.pref_alerts, rootKey) // TODO not organized well
|
||||
addPreferencesFromResource(R.xml.pref_alerts, rootKey)
|
||||
addPreferencesFromResource(R.xml.pref_datachoices, rootKey)
|
||||
addPreferencesFromResourceIfEnabled(maintenancePlugin, rootKey)
|
||||
addPreferencesFromResourceIfEnabled(openHumansUploader, rootKey)
|
||||
|
|
|
@ -31,7 +31,7 @@ import info.nightscout.androidaps.logging.LTag
|
|||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||
import info.nightscout.androidaps.plugins.treatments.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
|
|
|
@ -24,7 +24,7 @@ import info.nightscout.androidaps.logging.LTag
|
|||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||
import info.nightscout.androidaps.plugins.treatments.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsCareportalFragment.RecyclerViewAdapter.TherapyEventsViewHolder
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
|
|
|
@ -29,7 +29,7 @@ import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientR
|
|||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData
|
||||
import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin
|
||||
import info.nightscout.androidaps.plugins.profile.local.events.EventLocalProfileChanged
|
||||
import info.nightscout.androidaps.plugins.treatments.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsProfileSwitchFragment.RecyclerProfileViewAdapter.ProfileSwitchViewHolder
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
|
|
|
@ -28,7 +28,7 @@ import info.nightscout.androidaps.logging.LTag
|
|||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.events.EventNSClientRestart
|
||||
import info.nightscout.androidaps.plugins.treatments.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.activities.fragments.TreatmentsTempTargetFragment.RecyclerViewAdapter.TempTargetsViewHolder
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
|
|
|
@ -19,7 +19,7 @@ import info.nightscout.androidaps.interfaces.ImportExportPrefs
|
|||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.logging.UserEntryLogger
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.plugins.treatments.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.events.EventTreatmentUpdateGui
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.T
|
||||
|
|
|
@ -1,296 +0,0 @@
|
|||
package info.nightscout.androidaps.db;
|
||||
|
||||
import android.content.Context;
|
||||
import android.database.DatabaseUtils;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
|
||||
import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper;
|
||||
import com.j256.ormlite.dao.CloseableIterator;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.stmt.DeleteBuilder;
|
||||
import com.j256.ormlite.stmt.PreparedQuery;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.Where;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
import info.nightscout.androidaps.plugins.general.openhumans.OpenHumansUploader;
|
||||
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
|
||||
/**
|
||||
* This Helper contains all resource to provide a central DB management functionality. Only methods handling
|
||||
* data-structure (and not the DB content) should be contained in here (meaning DDL and not SQL).
|
||||
* <p>
|
||||
* This class can safely be called from Services, but should not call Services to avoid circular dependencies.
|
||||
* One major issue with this (right now) are the scheduled events, which are put into the service. Therefor all
|
||||
* direct calls to the corresponding methods (eg. resetDatabases) should be done by a central service.
|
||||
*/
|
||||
public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
||||
@Inject AAPSLogger aapsLogger;
|
||||
@Inject RxBusWrapper rxBus;
|
||||
@Inject VirtualPumpPlugin virtualPumpPlugin;
|
||||
@Inject OpenHumansUploader openHumansUploader;
|
||||
@Inject ActivePlugin activePlugin;
|
||||
@Inject DateUtil dateUtil;
|
||||
|
||||
public static final String DATABASE_NAME = "AndroidAPSDb";
|
||||
|
||||
private static final int DATABASE_VERSION = 13;
|
||||
|
||||
public static Long earliestDataChange = null;
|
||||
|
||||
private int oldVersion = 0;
|
||||
private int newVersion = 0;
|
||||
|
||||
public DatabaseHelper(Context context) {
|
||||
super(context, DATABASE_NAME, null, DATABASE_VERSION);
|
||||
StaticInjector.Companion.getInstance().androidInjector().inject(this);
|
||||
onCreate(getWritableDatabase(), getConnectionSource());
|
||||
//onUpgrade(getWritableDatabase(), getConnectionSource(), 1,1);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) {
|
||||
try {
|
||||
aapsLogger.info(LTag.DATABASE, "onCreate");
|
||||
TableUtils.createTableIfNotExists(connectionSource, OmnipodHistoryRecord.class);
|
||||
TableUtils.createTableIfNotExists(connectionSource, OHQueueItem.class);
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Can't create database", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) {
|
||||
try {
|
||||
this.oldVersion = oldVersion;
|
||||
this.newVersion = newVersion;
|
||||
|
||||
if (oldVersion < 7) {
|
||||
aapsLogger.info(LTag.DATABASE, "onUpgrade");
|
||||
onCreate(database, connectionSource);
|
||||
}
|
||||
TableUtils.createTableIfNotExists(connectionSource, OHQueueItem.class);
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Can't drop databases", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
aapsLogger.info(LTag.DATABASE, "Do nothing for downgrading...");
|
||||
aapsLogger.info(LTag.DATABASE, "oldVersion: {}, newVersion: {}", oldVersion, newVersion);
|
||||
}
|
||||
|
||||
public int getOldVersion() {
|
||||
return oldVersion;
|
||||
}
|
||||
|
||||
public int getNewVersion() {
|
||||
return newVersion;
|
||||
}
|
||||
|
||||
public long size(String database) {
|
||||
return DatabaseUtils.queryNumEntries(getReadableDatabase(), database);
|
||||
}
|
||||
|
||||
// --------------------- DB resets ---------------------
|
||||
|
||||
public void resetDatabases() {
|
||||
try {
|
||||
TableUtils.dropTable(connectionSource, OmnipodHistoryRecord.class, true);
|
||||
TableUtils.createTableIfNotExists(connectionSource, OmnipodHistoryRecord.class);
|
||||
updateEarliestDataChange(0);
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
virtualPumpPlugin.setFakingStatus(true);
|
||||
new java.util.Timer().schedule(
|
||||
new java.util.TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
rxBus.send(new EventRefreshOverview("resetDatabases", false));
|
||||
}
|
||||
},
|
||||
3000
|
||||
);
|
||||
}
|
||||
|
||||
// ------------------ getDao -------------------------------------------
|
||||
|
||||
private Dao<OmnipodHistoryRecord, Long> getDaoPodHistory() throws SQLException {
|
||||
return getDao(OmnipodHistoryRecord.class);
|
||||
}
|
||||
|
||||
private Dao<OHQueueItem, Long> getDaoOpenHumansQueue() throws SQLException {
|
||||
return getDao(OHQueueItem.class);
|
||||
}
|
||||
|
||||
public static void updateEarliestDataChange(long newDate) {
|
||||
if (earliestDataChange == null) {
|
||||
earliestDataChange = newDate;
|
||||
return;
|
||||
}
|
||||
if (newDate < earliestDataChange) {
|
||||
earliestDataChange = newDate;
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- Food handling ---------------
|
||||
|
||||
// ---------------- PodHistory handling ---------------
|
||||
|
||||
public void createOrUpdate(OmnipodHistoryRecord omnipodHistoryRecord) {
|
||||
try {
|
||||
getDaoPodHistory().createOrUpdate(omnipodHistoryRecord);
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<OmnipodHistoryRecord> getAllOmnipodHistoryRecordsFromTimeStamp(long from, boolean ascending) {
|
||||
try {
|
||||
Dao<OmnipodHistoryRecord, Long> daoPodHistory = getDaoPodHistory();
|
||||
List<OmnipodHistoryRecord> podHistories;
|
||||
QueryBuilder<OmnipodHistoryRecord, Long> queryBuilder = daoPodHistory.queryBuilder();
|
||||
queryBuilder.orderBy("date", ascending);
|
||||
//queryBuilder.limit(100L);
|
||||
Where where = queryBuilder.where();
|
||||
where.ge("date", from);
|
||||
PreparedQuery<OmnipodHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
podHistories = daoPodHistory.query(preparedQuery);
|
||||
return podHistories;
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return new ArrayList<>();
|
||||
}
|
||||
|
||||
public OmnipodHistoryRecord findOmnipodHistoryRecordByPumpId(long pumpId) {
|
||||
try {
|
||||
Dao<OmnipodHistoryRecord, Long> daoPodHistory = getDaoPodHistory();
|
||||
QueryBuilder<OmnipodHistoryRecord, Long> queryBuilder = daoPodHistory.queryBuilder();
|
||||
queryBuilder.orderBy("date", false);
|
||||
Where<OmnipodHistoryRecord, Long> where = queryBuilder.where();
|
||||
where.eq("pumpId", pumpId);
|
||||
PreparedQuery<OmnipodHistoryRecord> preparedQuery = queryBuilder.prepare();
|
||||
return daoPodHistory.queryForFirst(preparedQuery);
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/*
|
||||
TODO implement again for database branch // Copied from xDrip+
|
||||
String calculateDirection(BgReading bgReading) {
|
||||
// Rework to get bgreaings from internal DB and calculate on that base
|
||||
|
||||
List<BgReading> bgReadingsList = MainApp.getDbHelper().getAllBgreadingsDataFromTime(bgReading.date - T.mins(10).msecs(), false);
|
||||
if (bgReadingsList == null || bgReadingsList.size() < 2)
|
||||
return "NONE";
|
||||
BgReading current = bgReadingsList.get(1);
|
||||
BgReading previous = bgReadingsList.get(0);
|
||||
|
||||
if (bgReadingsList.get(1).date < bgReadingsList.get(0).date) {
|
||||
current = bgReadingsList.get(0);
|
||||
previous = bgReadingsList.get(1);
|
||||
}
|
||||
|
||||
double slope;
|
||||
|
||||
// Avoid division by 0
|
||||
if (current.date == previous.date)
|
||||
slope = 0;
|
||||
else
|
||||
slope = (previous.value - current.value) / (previous.date - current.date);
|
||||
|
||||
// aapsLogger.error(LTag.GLUCOSE, "Slope is :" + slope + " delta " + (previous.value - current.value) + " date difference " + (current.date - previous.date));
|
||||
|
||||
double slope_by_minute = slope * 60000;
|
||||
String arrow = "NONE";
|
||||
|
||||
if (slope_by_minute <= (-3.5)) {
|
||||
arrow = "DoubleDown";
|
||||
} else if (slope_by_minute <= (-2)) {
|
||||
arrow = "SingleDown";
|
||||
} else if (slope_by_minute <= (-1)) {
|
||||
arrow = "FortyFiveDown";
|
||||
} else if (slope_by_minute <= (1)) {
|
||||
arrow = "Flat";
|
||||
} else if (slope_by_minute <= (2)) {
|
||||
arrow = "FortyFiveUp";
|
||||
} else if (slope_by_minute <= (3.5)) {
|
||||
arrow = "SingleUp";
|
||||
} else if (slope_by_minute <= (40)) {
|
||||
arrow = "DoubleUp";
|
||||
}
|
||||
// aapsLogger.error(LTag.GLUCOSE, "Direction set to: " + arrow);
|
||||
return arrow;
|
||||
}
|
||||
*/
|
||||
// ---------------- Open Humans Queue handling ---------------
|
||||
|
||||
public void clearOpenHumansQueue() {
|
||||
try {
|
||||
TableUtils.clearTable(connectionSource, OHQueueItem.class);
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void createOrUpdate(OHQueueItem item) {
|
||||
try {
|
||||
getDaoOpenHumansQueue().createOrUpdate(item);
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeAllOHQueueItemsWithIdSmallerThan(long id) {
|
||||
try {
|
||||
DeleteBuilder<OHQueueItem, Long> deleteBuilder = getDaoOpenHumansQueue().deleteBuilder();
|
||||
deleteBuilder.where().le("id", id);
|
||||
deleteBuilder.delete();
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
|
||||
public List<OHQueueItem> getAllOHQueueItems(Long maxEntries) {
|
||||
try {
|
||||
return getDaoOpenHumansQueue()
|
||||
.queryBuilder()
|
||||
.orderBy("id", true)
|
||||
.limit(maxEntries)
|
||||
.query();
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
public long getOHQueueSize() {
|
||||
try {
|
||||
return getDaoOpenHumansQueue().countOf();
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
package info.nightscout.androidaps.db;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.j256.ormlite.dao.CloseableIterator;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||
|
||||
@Deprecated
|
||||
@Singleton
|
||||
public class DatabaseHelperProvider implements DatabaseHelperInterface {
|
||||
|
||||
@Inject DatabaseHelperProvider() {
|
||||
}
|
||||
|
||||
@Override public void createOrUpdate(@NonNull OmnipodHistoryRecord record) {
|
||||
MainApp.Companion.getDbHelper().createOrUpdate(record);
|
||||
}
|
||||
|
||||
@Override public boolean createOrUpdate(@NonNull TemporaryBasal tempBasal) {
|
||||
// return MainApp.Companion.getDbHelper().createOrUpdate(tempBasal);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Nullable @Override public TemporaryBasal findTempBasalByPumpId(long 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 null;
|
||||
}
|
||||
|
||||
@NonNull @Override public List<OmnipodHistoryRecord> getAllOmnipodHistoryRecordsFromTimestamp(long timestamp, boolean ascending) {
|
||||
return MainApp.Companion.getDbHelper().getAllOmnipodHistoryRecordsFromTimeStamp(timestamp, ascending);
|
||||
}
|
||||
|
||||
@Nullable @Override public OmnipodHistoryRecord findOmnipodHistoryRecordByPumpId(long pumpId) {
|
||||
return MainApp.Companion.getDbHelper().findOmnipodHistoryRecordByPumpId(pumpId);
|
||||
}
|
||||
|
||||
@Override public void delete(@NonNull ExtendedBolus extendedBolus) {
|
||||
// MainApp.Companion.getDbHelper().delete(extendedBolus);
|
||||
}
|
||||
|
||||
@Nullable @Override public ExtendedBolus getExtendedBolusByPumpId(long pumpId) {
|
||||
// return MainApp.Companion.getDbHelper().getExtendedBolusByPumpId(pumpId);
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override public void resetDatabases() {
|
||||
MainApp.Companion.getDbHelper().resetDatabases();
|
||||
}
|
||||
|
||||
@Override public void createOrUpdate(@NonNull OHQueueItem record) {
|
||||
MainApp.Companion.getDbHelper().createOrUpdate(record);
|
||||
}
|
||||
|
||||
@NonNull @Override public List<OHQueueItem> getAllOHQueueItems(long maxEntries) {
|
||||
return MainApp.Companion.getDbHelper().getAllOHQueueItems(maxEntries);
|
||||
}
|
||||
|
||||
@Override public long getOHQueueSize() {
|
||||
return MainApp.Companion.getDbHelper().getOHQueueSize();
|
||||
}
|
||||
|
||||
@Override public void clearOpenHumansQueue() {
|
||||
MainApp.Companion.getDbHelper().clearOpenHumansQueue();
|
||||
}
|
||||
|
||||
@Override public void removeAllOHQueueItemsWithIdSmallerThan(long id) {
|
||||
MainApp.Companion.getDbHelper().removeAllOHQueueItemsWithIdSmallerThan(id);
|
||||
}
|
||||
}
|
|
@ -1,2 +0,0 @@
|
|||
package info.nightscout.androidaps.db
|
||||
|
|
@ -8,7 +8,6 @@ import dagger.Provides
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.MainApp
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.db.DatabaseHelperProvider
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin
|
||||
|
@ -20,7 +19,6 @@ import info.nightscout.androidaps.plugins.general.nsclient.DataSyncSelectorImple
|
|||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin
|
||||
import info.nightscout.androidaps.plugins.pump.PumpSyncImplementation
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import info.nightscout.androidaps.queue.CommandQueue
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.androidNotification.NotificationHolderImpl
|
||||
|
@ -56,9 +54,7 @@ open class AppModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideStorage(): Storage {
|
||||
return FileStorage()
|
||||
}
|
||||
fun provideStorage(): Storage = FileStorage()
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
|
@ -66,9 +62,8 @@ open class AppModule {
|
|||
|
||||
@Provides
|
||||
@Singleton
|
||||
fun provideProfileFunction(aapsLogger: AAPSLogger, sp: SP, resourceHelper: ResourceHelper, activePlugin: ActivePlugin, repository: AppRepository, dateUtil: DateUtil): ProfileFunction {
|
||||
return ProfileFunctionImplementation(aapsLogger, sp, resourceHelper, activePlugin, repository, dateUtil)
|
||||
}
|
||||
fun provideProfileFunction(aapsLogger: AAPSLogger, sp: SP, resourceHelper: ResourceHelper, activePlugin: ActivePlugin, repository: AppRepository, dateUtil: DateUtil): ProfileFunction =
|
||||
ProfileFunctionImplementation(aapsLogger, sp, resourceHelper, activePlugin, repository, dateUtil)
|
||||
|
||||
@Module
|
||||
interface AppBindings {
|
||||
|
@ -79,11 +74,7 @@ open class AppModule {
|
|||
@Binds fun bindCommandQueueProvider(commandQueue: CommandQueue): CommandQueueProvider
|
||||
@Binds fun bindConfigInterface(config: ConfigImpl): Config
|
||||
|
||||
@Binds
|
||||
fun bindConfigBuilderInterface(configBuilderPlugin: ConfigBuilderPlugin): ConfigBuilder
|
||||
@Binds fun bindTreatmentsInterface(treatmentsPlugin: TreatmentsPlugin): TreatmentsInterface
|
||||
|
||||
@Binds fun bindDatabaseHelperInterface(databaseHelperProvider: DatabaseHelperProvider): DatabaseHelperInterface
|
||||
@Binds fun bindConfigBuilderInterface(configBuilderPlugin: ConfigBuilderPlugin): ConfigBuilder
|
||||
@Binds fun bindNotificationHolderInterface(notificationHolder: NotificationHolderImpl): NotificationHolder
|
||||
@Binds fun bindImportExportPrefsInterface(importExportPrefs: ImportExportPrefsImpl): ImportExportPrefs
|
||||
@Binds fun bindIconsProviderInterface(iconsProvider: IconsProviderImplementation): IconsProvider
|
||||
|
@ -93,7 +84,6 @@ open class AppModule {
|
|||
@Binds fun bindDataSyncSelector(dataSyncSelectorImplementation: DataSyncSelectorImplementation): DataSyncSelector
|
||||
|
||||
@Binds fun bindPumpSync(pumpSyncImplementation: PumpSyncImplementation): PumpSync
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2,9 +2,7 @@ package info.nightscout.androidaps.dependencyInjection
|
|||
|
||||
import dagger.Module
|
||||
import dagger.android.ContributesAndroidInjector
|
||||
import info.nightscout.androidaps.db.DatabaseHelper
|
||||
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentService
|
||||
import info.nightscout.androidaps.utils.wizard.BolusWizard
|
||||
import info.nightscout.androidaps.utils.wizard.QuickWizardEntry
|
||||
|
||||
|
@ -14,9 +12,6 @@ abstract class DataClassesModule {
|
|||
|
||||
@ContributesAndroidInjector abstract fun glucoseStatusInjector(): GlucoseStatus
|
||||
|
||||
@ContributesAndroidInjector abstract fun databaseHelperInjector(): DatabaseHelper
|
||||
@ContributesAndroidInjector abstract fun treatmentServiceInjector(): TreatmentService
|
||||
|
||||
@ContributesAndroidInjector abstract fun bolusWizardInjector(): BolusWizard
|
||||
@ContributesAndroidInjector abstract fun quickWizardEntryInjector(): QuickWizardEntry
|
||||
}
|
|
@ -25,7 +25,6 @@ import info.nightscout.androidaps.plugins.general.dataBroadcaster.DataBroadcastP
|
|||
import info.nightscout.androidaps.plugins.general.food.FoodPlugin
|
||||
import info.nightscout.androidaps.plugins.general.maintenance.MaintenancePlugin
|
||||
import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin
|
||||
import info.nightscout.androidaps.plugins.general.openhumans.OpenHumansUploader
|
||||
import info.nightscout.androidaps.plugins.general.overview.OverviewPlugin
|
||||
import info.nightscout.androidaps.plugins.general.persistentNotification.PersistentNotificationPlugin
|
||||
import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin
|
||||
|
@ -40,14 +39,11 @@ import info.nightscout.androidaps.plugins.profile.local.LocalProfilePlugin
|
|||
import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin
|
||||
import info.nightscout.androidaps.plugins.pump.insight.LocalInsightPlugin
|
||||
import info.nightscout.androidaps.plugins.pump.mdi.MDIPlugin
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.OmnipodErosPumpPlugin
|
||||
import info.nightscout.androidaps.plugins.pump.virtual.VirtualPumpPlugin
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin
|
||||
import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin
|
||||
import info.nightscout.androidaps.plugins.source.*
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentsPlugin
|
||||
import javax.inject.Qualifier
|
||||
|
||||
@Module
|
||||
|
@ -203,12 +199,6 @@ abstract class PluginsModule {
|
|||
@IntKey(250)
|
||||
abstract fun bindAutomationPlugin(plugin: AutomationPlugin): PluginBase
|
||||
|
||||
@Binds
|
||||
@AllConfigs
|
||||
@IntoMap
|
||||
@IntKey(260)
|
||||
abstract fun bindTreatmentsPlugin(plugin: TreatmentsPlugin): PluginBase
|
||||
|
||||
@Binds
|
||||
@AllConfigs
|
||||
@IntoMap
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
package info.nightscout.androidaps.events
|
||||
|
||||
class EventTreatmentUpdateGui : EventUpdateGui()
|
|
@ -1,6 +1,6 @@
|
|||
package info.nightscout.androidaps.plugins.aps.logger
|
||||
|
||||
import info.nightscout.androidaps.db.StaticInjector
|
||||
import info.nightscout.androidaps.di.StaticInjector
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import org.mozilla.javascript.ScriptableObject
|
||||
|
|
|
@ -114,7 +114,6 @@ class ConfigBuilderFragment : DaggerFragment() {
|
|||
createViewsForPlugins(R.string.configbuilder_loop, R.string.configbuilder_loop_description, PluginType.LOOP, activePlugin.getSpecificPluginsVisibleInList(PluginType.LOOP))
|
||||
createViewsForPlugins(R.string.constraints, R.string.configbuilder_constraints_description, PluginType.CONSTRAINTS, activePlugin.getSpecificPluginsVisibleInList(PluginType.CONSTRAINTS))
|
||||
}
|
||||
createViewsForPlugins(R.string.configbuilder_treatments, R.string.configbuilder_treatments_description, PluginType.TREATMENT, activePlugin.getSpecificPluginsVisibleInList(PluginType.TREATMENT))
|
||||
createViewsForPlugins(R.string.configbuilder_general, R.string.configbuilder_general_description, PluginType.GENERAL, activePlugin.getSpecificPluginsVisibleInList(PluginType.GENERAL))
|
||||
}
|
||||
|
||||
|
@ -139,22 +138,15 @@ class ConfigBuilderFragment : DaggerFragment() {
|
|||
|
||||
@Suppress("InflateParams")
|
||||
val baseView: LinearLayout = fragment.layoutInflater.inflate(R.layout.configbuilder_single_plugin, null) as LinearLayout
|
||||
private val enabledExclusive: RadioButton
|
||||
private val enabledInclusive: CheckBox
|
||||
private val pluginIcon: ImageView
|
||||
private val pluginName: TextView
|
||||
private val pluginDescription: TextView
|
||||
private val pluginPreferences: ImageButton
|
||||
private val pluginVisibility: CheckBox
|
||||
private val enabledExclusive: RadioButton = baseView.findViewById(R.id.plugin_enabled_exclusive)
|
||||
private val enabledInclusive: CheckBox = baseView.findViewById(R.id.plugin_enabled_inclusive)
|
||||
private val pluginIcon: ImageView = baseView.findViewById(R.id.plugin_icon)
|
||||
private val pluginName: TextView = baseView.findViewById(R.id.plugin_name)
|
||||
private val pluginDescription: TextView = baseView.findViewById(R.id.plugin_description)
|
||||
private val pluginPreferences: ImageButton = baseView.findViewById(R.id.plugin_preferences)
|
||||
private val pluginVisibility: CheckBox = baseView.findViewById(R.id.plugin_visibility)
|
||||
|
||||
init {
|
||||
enabledExclusive = baseView.findViewById(R.id.plugin_enabled_exclusive)
|
||||
enabledInclusive = baseView.findViewById(R.id.plugin_enabled_inclusive)
|
||||
pluginIcon = baseView.findViewById(R.id.plugin_icon)
|
||||
pluginName = baseView.findViewById(R.id.plugin_name)
|
||||
pluginDescription = baseView.findViewById(R.id.plugin_description)
|
||||
pluginPreferences = baseView.findViewById(R.id.plugin_preferences)
|
||||
pluginVisibility = baseView.findViewById(R.id.plugin_visibility)
|
||||
|
||||
pluginVisibility.setOnClickListener {
|
||||
plugin.setFragmentVisible(pluginType, pluginVisibility.isChecked)
|
||||
|
|
|
@ -120,7 +120,6 @@ class ConfigBuilderPlugin @Inject constructor(
|
|||
for (p in activePlugin.getPluginsList()) {
|
||||
aapsLogger.debug(LTag.CONFIGBUILDER, p.name + ":" +
|
||||
(if (p.isEnabled(PluginType.GENERAL)) " GENERAL" else "") +
|
||||
(if (p.isEnabled(PluginType.TREATMENT)) " TREATMENT" else "") +
|
||||
(if (p.isEnabled(PluginType.SENSITIVITY)) " SENSITIVITY" else "") +
|
||||
(if (p.isEnabled(PluginType.PROFILE)) " PROFILE" else "") +
|
||||
(if (p.isEnabled(PluginType.APS)) " APS" else "") +
|
||||
|
@ -185,7 +184,6 @@ class ConfigBuilderPlugin @Inject constructor(
|
|||
PluginType.APS -> pluginsInCategory = activePlugin.getSpecificPluginsListByInterface(APS::class.java)
|
||||
PluginType.PROFILE -> pluginsInCategory = activePlugin.getSpecificPluginsListByInterface(ProfileSource::class.java)
|
||||
PluginType.BGSOURCE -> pluginsInCategory = activePlugin.getSpecificPluginsListByInterface(BgSource::class.java)
|
||||
PluginType.TREATMENT -> pluginsInCategory = activePlugin.getSpecificPluginsListByInterface(TreatmentsInterface::class.java)
|
||||
PluginType.PUMP -> pluginsInCategory = activePlugin.getSpecificPluginsListByInterface(Pump::class.java)
|
||||
|
||||
else -> {
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
package info.nightscout.androidaps.plugins.configBuilder
|
||||
|
||||
import info.nightscout.androidaps.interfaces.Config
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
|
@ -21,7 +20,6 @@ class PluginStore @Inject constructor(
|
|||
private var activeAPSStore: APS? = null
|
||||
private var activeInsulinStore: Insulin? = null
|
||||
private var activeSensitivityStore: Sensitivity? = null
|
||||
private var activeTreatmentsStore: TreatmentsInterface? = null
|
||||
|
||||
fun loadDefaults() {
|
||||
verifySelectionInCategories()
|
||||
|
@ -121,16 +119,6 @@ class PluginStore @Inject constructor(
|
|||
aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting PumpInterface")
|
||||
}
|
||||
setFragmentVisibilities((activePumpStore as PluginBase).name, pluginsInCategory, PluginType.PUMP)
|
||||
|
||||
// PluginType.TREATMENT
|
||||
pluginsInCategory = getSpecificPluginsList(PluginType.TREATMENT)
|
||||
activeTreatmentsStore = getTheOneEnabledInArray(pluginsInCategory, PluginType.TREATMENT) as TreatmentsInterface?
|
||||
if (activeTreatmentsStore == null) {
|
||||
activeTreatmentsStore = getDefaultPlugin(PluginType.TREATMENT) as TreatmentsInterface
|
||||
(activeTreatmentsStore as PluginBase).setPluginEnabled(PluginType.TREATMENT, true)
|
||||
aapsLogger.debug(LTag.CONFIGBUILDER, "Defaulting PumpInterface")
|
||||
}
|
||||
setFragmentVisibilities((activeTreatmentsStore as PluginBase).name, pluginsInCategory, PluginType.TREATMENT)
|
||||
}
|
||||
|
||||
private fun setFragmentVisibilities(activePluginName: String, pluginsInCategory: ArrayList<PluginBase>,
|
||||
|
@ -175,10 +163,6 @@ class PluginStore @Inject constructor(
|
|||
get() = activeSensitivityStore
|
||||
?: checkNotNull(activeSensitivityStore) { "No sensitivity selected" }
|
||||
|
||||
override val activeTreatments: TreatmentsInterface
|
||||
get() = activeTreatmentsStore
|
||||
?: checkNotNull(activeTreatmentsStore) { "No treatments selected" }
|
||||
|
||||
override val activeOverview: Overview
|
||||
get() = getSpecificPluginsListByInterface(Overview::class.java).first() as Overview
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ class ObjectivesPlugin @Inject constructor(
|
|||
var objectives: MutableList<Objective> = ArrayList()
|
||||
|
||||
companion object {
|
||||
|
||||
const val FIRST_OBJECTIVE = 0
|
||||
@Suppress("unused") const val USAGE_OBJECTIVE = 1
|
||||
@Suppress("unused") const val EXAM_OBJECTIVE = 2
|
||||
|
@ -60,7 +61,6 @@ class ObjectivesPlugin @Inject constructor(
|
|||
|
||||
public override fun onStart() {
|
||||
super.onStart()
|
||||
convertSP()
|
||||
setupObjectives()
|
||||
}
|
||||
|
||||
|
@ -68,26 +68,6 @@ class ObjectivesPlugin @Inject constructor(
|
|||
return activePlugin.activePump.pumpDescription.isTempBasalCapable
|
||||
}
|
||||
|
||||
// convert 2.3 SP version
|
||||
private fun convertSP() {
|
||||
doConvertSP(0, "config")
|
||||
doConvertSP(1, "openloop")
|
||||
doConvertSP(2, "maxbasal")
|
||||
doConvertSP(3, "maxiobzero")
|
||||
doConvertSP(4, "maxiob")
|
||||
doConvertSP(5, "autosens")
|
||||
doConvertSP(6, "ama")
|
||||
doConvertSP(7, "smb")
|
||||
}
|
||||
|
||||
private fun doConvertSP(number: Int, name: String) {
|
||||
if (!sp.contains("Objectives_" + name + "_started")) {
|
||||
sp.putLong("Objectives_" + name + "_started", sp.getLong("Objectives" + number + "started", 0L))
|
||||
sp.putLong("Objectives_" + name + "_accomplished", sp.getLong("Objectives" + number + "accomplished", 0L))
|
||||
}
|
||||
// TODO: we can remove Objectives1accomplished sometimes later
|
||||
}
|
||||
|
||||
private fun setupObjectives() {
|
||||
objectives.clear()
|
||||
objectives.add(Objective0(injector))
|
||||
|
@ -125,7 +105,7 @@ class ObjectivesPlugin @Inject constructor(
|
|||
val requestCode = sp.getString(R.string.key_objectives_request_code, "")
|
||||
var url = sp.getString(R.string.key_nsclientinternal_url, "").lowercase(Locale.getDefault())
|
||||
if (!url.endsWith("/")) url = "$url/"
|
||||
@Suppress("DEPRECATION") val hashNS = Hashing.sha1().hashString(url + BuildConfig.APPLICATION_ID + "/" + requestCode, Charsets.UTF_8).toString()
|
||||
@Suppress("DEPRECATION", "UnstableApiUsage") val hashNS = Hashing.sha1().hashString(url + BuildConfig.APPLICATION_ID + "/" + requestCode, Charsets.UTF_8).toString()
|
||||
if (request.equals(hashNS.substring(0, 10), ignoreCase = true)) {
|
||||
sp.putLong("Objectives_" + "openloop" + "_started", dateUtil.now())
|
||||
sp.putLong("Objectives_" + "openloop" + "_accomplished", dateUtil.now())
|
||||
|
|
|
@ -72,7 +72,7 @@ class MaintenancePlugin @Inject constructor(
|
|||
}
|
||||
Arrays.sort(files) { f1: File, f2: File -> f1.name.compareTo(f2.name) }
|
||||
var delFiles = listOf(*files)
|
||||
val amount = sp.getInt(R.string.key_logshipper_amount, 2)
|
||||
val amount = sp.getInt(R.string.key_logshipper_amount, 5)
|
||||
val keepIndex = amount - 1
|
||||
if (keepIndex < delFiles.size) {
|
||||
delFiles = delFiles.subList(keepIndex, delFiles.size)
|
||||
|
|
|
@ -16,7 +16,6 @@ import info.nightscout.androidaps.events.EventConfigBuilderChange
|
|||
import info.nightscout.androidaps.events.EventPreferenceChange
|
||||
import info.nightscout.androidaps.interfaces.Config
|
||||
import info.nightscout.androidaps.interfaces.DataSyncSelector
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
|
@ -71,7 +70,6 @@ class NSClientService : DaggerService() {
|
|||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||
@Inject lateinit var nsSettingsStatus: NSSettingsStatus
|
||||
@Inject lateinit var nsDeviceStatus: NSDeviceStatus
|
||||
@Inject lateinit var databaseHelper: DatabaseHelperInterface
|
||||
@Inject lateinit var rxBus: RxBusWrapper
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var sp: SP
|
||||
|
@ -199,7 +197,7 @@ class NSClientService : DaggerService() {
|
|||
.build())
|
||||
}
|
||||
|
||||
fun processAuthAck(ack: NSAuthAck) {
|
||||
private fun processAuthAck(ack: NSAuthAck) {
|
||||
var connectionStatus = "Authenticated ("
|
||||
if (ack.read) connectionStatus += "R"
|
||||
if (ack.write) connectionStatus += "W"
|
||||
|
|
|
@ -29,7 +29,9 @@ class OHUploadWorker(context: Context, workerParameters: WorkerParameters)
|
|||
lateinit var resourceHelper: ResourceHelper
|
||||
|
||||
@kotlin.ExperimentalStdlibApi
|
||||
override fun createWork(): Single<Result> = Single.defer {
|
||||
override fun createWork(): Single<Result> =Single.just(Result.success())
|
||||
/*
|
||||
= Single.defer {
|
||||
|
||||
// Here we inject every time we create work
|
||||
// We could build our own WorkerFactory with dagger but this will create conflicts with other Workers
|
||||
|
@ -50,7 +52,7 @@ class OHUploadWorker(context: Context, workerParameters: WorkerParameters)
|
|||
Single.just(Result.retry())
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
private fun createForegroundInfo(): ForegroundInfo {
|
||||
val title = resourceHelper.gs(info.nightscout.androidaps.R.string.open_humans)
|
||||
|
||||
|
|
|
@ -11,7 +11,6 @@ import androidx.work.WorkManager
|
|||
import dagger.android.support.DaggerFragment
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.events.Event
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
|
@ -38,24 +37,23 @@ class OpenHumansFragment : DaggerFragment() {
|
|||
@Inject lateinit var openHumansUploader: OpenHumansUploader
|
||||
@Inject lateinit var resourceHelper: ResourceHelper
|
||||
@Inject lateinit var aapsSchedulers: AapsSchedulers
|
||||
@Inject lateinit var databaseHelper: DatabaseHelperInterface
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
compositeDisposable += Single.fromCallable { databaseHelper.getOHQueueSize() }
|
||||
.subscribeOn(aapsSchedulers.io)
|
||||
.repeatWhen {
|
||||
rxBus.toObservable(UpdateViewEvent::class.java)
|
||||
.cast(Any::class.java)
|
||||
.mergeWith(rxBus.toObservable(UpdateQueueEvent::class.java)
|
||||
.throttleLatest(5, TimeUnit.SECONDS))
|
||||
.toFlowable(BackpressureStrategy.LATEST)
|
||||
}
|
||||
.observeOn(aapsSchedulers.main)
|
||||
.subscribe({
|
||||
queueSizeValue = it
|
||||
updateGUI()
|
||||
}, {})
|
||||
// compositeDisposable += Single.fromCallable { databaseHelper.getOHQueueSize() }
|
||||
// .subscribeOn(aapsSchedulers.io)
|
||||
// .repeatWhen {
|
||||
// rxBus.toObservable(UpdateViewEvent::class.java)
|
||||
// .cast(Any::class.java)
|
||||
// .mergeWith(rxBus.toObservable(UpdateQueueEvent::class.java)
|
||||
// .throttleLatest(5, TimeUnit.SECONDS))
|
||||
// .toFlowable(BackpressureStrategy.LATEST)
|
||||
// }
|
||||
// .observeOn(aapsSchedulers.main)
|
||||
// .subscribe({
|
||||
// queueSizeValue = it
|
||||
// updateGUI()
|
||||
// }, {})
|
||||
context?.applicationContext?.let { appContext ->
|
||||
WorkManager.getInstance(appContext).getWorkInfosForUniqueWorkLiveData(OpenHumansUploader.WORK_NAME).observe(this, {
|
||||
val workInfo = it.lastOrNull()
|
||||
|
|
|
@ -21,14 +21,13 @@ import info.nightscout.androidaps.database.entities.TemporaryTarget
|
|||
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||
import info.nightscout.androidaps.db.*
|
||||
import info.nightscout.androidaps.events.EventPreferenceChange
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||
import info.nightscout.androidaps.extensions.toConstant
|
||||
import info.nightscout.androidaps.interfaces.PluginBase
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription
|
||||
import info.nightscout.androidaps.interfaces.PluginType
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.extensions.toConstant
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
|
@ -60,7 +59,6 @@ class OpenHumansUploader @Inject constructor(
|
|||
private val sp: SP,
|
||||
private val rxBus: RxBusWrapper,
|
||||
private val context: Context,
|
||||
private val databaseHelper: DatabaseHelperInterface,
|
||||
val repository: AppRepository
|
||||
) : PluginBase(
|
||||
PluginDescription()
|
||||
|
@ -306,11 +304,11 @@ class OpenHumansUploader @Inject constructor(
|
|||
jsonObject.put("structureVersion", structureVersion)
|
||||
jsonObject.put("queuedOn", System.currentTimeMillis())
|
||||
generator(jsonObject)
|
||||
val queueItem = OHQueueItem(
|
||||
file = file,
|
||||
content = jsonObject.toString()
|
||||
)
|
||||
databaseHelper.createOrUpdate(queueItem)
|
||||
// val queueItem = OHQueueItem(
|
||||
// file = file,
|
||||
// content = jsonObject.toString()
|
||||
// )
|
||||
// databaseHelper.createOrUpdate(queueItem)
|
||||
rxBus.send(OpenHumansFragment.UpdateQueueEvent)
|
||||
} catch (e: JSONException) {
|
||||
e.printStackTrace()
|
||||
|
@ -340,7 +338,7 @@ class OpenHumansUploader @Inject constructor(
|
|||
isSetup = false
|
||||
oAuthTokens = null
|
||||
projectMemberId = null
|
||||
databaseHelper.clearOpenHumansQueue()
|
||||
// databaseHelper.clearOpenHumansQueue()
|
||||
rxBus.send(OpenHumansFragment.UpdateViewEvent)
|
||||
}
|
||||
|
||||
|
@ -353,18 +351,18 @@ class OpenHumansUploader @Inject constructor(
|
|||
//Updating the notification for every item drastically slows down the operation
|
||||
if (currentProgress % 1000L == 0L) showOngoingNotification(maxProgress, currentProgress)
|
||||
}
|
||||
copyDisposable = Completable.fromCallable { databaseHelper.clearOpenHumansQueue() }
|
||||
// copyDisposable = Completable.fromCallable { databaseHelper.clearOpenHumansQueue() }
|
||||
// .andThen(Single.defer { Single.just(databaseHelper.getCountOfAllRows() + treatmentsPlugin.service.count()) })
|
||||
// .doOnSuccess { maxProgress = it }
|
||||
// .flatMapObservable { Observable.defer { Observable.fromIterable(treatmentsPlugin.service.getTreatmentData()) } }
|
||||
// .map { enqueueTreatment(it); increaseCounter() }
|
||||
// .ignoreElements()
|
||||
.andThen(Observable.defer { Observable.fromIterable(repository.compatGetBgReadingsDataFromTime(0, true).blockingGet()) })
|
||||
.map { enqueueBGReading(it); increaseCounter() }
|
||||
.ignoreElements()
|
||||
.andThen(Observable.defer { Observable.fromIterable(repository.compatGetTherapyEventDataFromTime(0, true).blockingGet()) })
|
||||
.map { enqueueTherapyEvent(it); increaseCounter() }
|
||||
.ignoreElements()
|
||||
// .andThen(Observable.defer { Observable.fromIterable(repository.compatGetBgReadingsDataFromTime(0, true).blockingGet()) })
|
||||
// .map { enqueueBGReading(it); increaseCounter() }
|
||||
// .ignoreElements()
|
||||
// .andThen(Observable.defer { Observable.fromIterable(repository.compatGetTherapyEventDataFromTime(0, true).blockingGet()) })
|
||||
// .map { enqueueTherapyEvent(it); increaseCounter() }
|
||||
// .ignoreElements()
|
||||
// .andThen(Observable.defer { Observable.fromIterable(databaseHelper.getAllExtendedBoluses()) })
|
||||
// .map { enqueueExtendedBolus(it); increaseCounter() }
|
||||
// .ignoreElements()
|
||||
|
@ -377,30 +375,30 @@ class OpenHumansUploader @Inject constructor(
|
|||
// .andThen(Observable.defer { Observable.fromIterable(databaseHelper.getAllTemporaryBasals()) })
|
||||
// .map { enqueueTemporaryBasal(it); increaseCounter() }
|
||||
// .ignoreElements()
|
||||
.andThen(Observable.defer { Observable.fromIterable(repository.compatGetTemporaryTargetData().blockingGet()) })
|
||||
.map { enqueueTempTarget(it); increaseCounter() }
|
||||
.ignoreElements()
|
||||
.doOnSubscribe {
|
||||
wakeLock.acquire(TimeUnit.MINUTES.toMillis(30))
|
||||
showOngoingNotification()
|
||||
}
|
||||
.doOnComplete {
|
||||
isSetup = true
|
||||
scheduleWorker(false)
|
||||
showSetupFinishedNotification()
|
||||
}
|
||||
.doOnError {
|
||||
logout()
|
||||
showSetupFailedNotification()
|
||||
}
|
||||
.doFinally {
|
||||
copyDisposable = null
|
||||
NotificationManagerCompat.from(context).cancel(COPY_NOTIFICATION_ID)
|
||||
wakeLock.release()
|
||||
}
|
||||
.onErrorComplete()
|
||||
.subscribeOn(aapsSchedulers.io)
|
||||
.subscribe()
|
||||
// .andThen(Observable.defer { Observable.fromIterable(repository.compatGetTemporaryTargetData().blockingGet()) })
|
||||
// .map { enqueueTempTarget(it); increaseCounter() }
|
||||
// .ignoreElements()
|
||||
// .doOnSubscribe {
|
||||
// wakeLock.acquire(TimeUnit.MINUTES.toMillis(30))
|
||||
// showOngoingNotification()
|
||||
// }
|
||||
// .doOnComplete {
|
||||
// isSetup = true
|
||||
// scheduleWorker(false)
|
||||
// showSetupFinishedNotification()
|
||||
// }
|
||||
// .doOnError {
|
||||
// logout()
|
||||
// showSetupFailedNotification()
|
||||
// }
|
||||
// .doFinally {
|
||||
// copyDisposable = null
|
||||
// NotificationManagerCompat.from(context).cancel(COPY_NOTIFICATION_ID)
|
||||
// wakeLock.release()
|
||||
// }
|
||||
// .onErrorComplete()
|
||||
// .subscribeOn(aapsSchedulers.io)
|
||||
// .subscribe()
|
||||
}
|
||||
|
||||
private fun showOngoingNotification(maxProgress: Long? = null, currentProgress: Long? = null) {
|
||||
|
@ -438,7 +436,7 @@ class OpenHumansUploader @Inject constructor(
|
|||
val notificationManager = NotificationManagerCompat.from(context)
|
||||
notificationManager.notify(FAILURE_NOTIFICATION_ID, notification)
|
||||
}
|
||||
|
||||
/*
|
||||
@kotlin.ExperimentalStdlibApi
|
||||
fun uploadDataSegmentally(): Completable =
|
||||
uploadData(UPLOAD_SEGMENT_SIZE)
|
||||
|
@ -478,7 +476,7 @@ class OpenHumansUploader @Inject constructor(
|
|||
.doOnSubscribe {
|
||||
aapsLogger.info(LTag.OHUPLOADER, "Starting upload")
|
||||
}
|
||||
|
||||
*/
|
||||
private fun uploadFile(accessToken: String, uploadData: UploadData) = Completable.defer {
|
||||
openHumansAPI.prepareFileUpload(accessToken, uploadData.fileName, uploadData.metadata)
|
||||
.flatMap { openHumansAPI.uploadFile(it.uploadURL, uploadData.content).andThen(Single.just(it.fileId)) }
|
||||
|
@ -495,7 +493,7 @@ class OpenHumansUploader @Inject constructor(
|
|||
Single.just(oAuthTokens.accessToken)
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
@kotlin.ExperimentalStdlibApi
|
||||
private fun gatherData(maxEntries: Long) = Single.defer {
|
||||
val items = databaseHelper.getAllOHQueueItems(maxEntries)
|
||||
|
@ -571,7 +569,7 @@ class OpenHumansUploader @Inject constructor(
|
|||
highestQueueId = items.map { it.id }.maxOrNull()
|
||||
))
|
||||
}
|
||||
|
||||
*/
|
||||
private fun ZipOutputStream.writeFile(name: String, bytes: ByteArray) {
|
||||
putNextEntry(ZipEntry(name))
|
||||
write(bytes)
|
||||
|
@ -579,7 +577,7 @@ class OpenHumansUploader @Inject constructor(
|
|||
}
|
||||
|
||||
private fun removeUploadedEntriesFromQueue(highestId: Long) = Completable.fromCallable {
|
||||
databaseHelper.removeAllOHQueueItemsWithIdSmallerThan(highestId)
|
||||
// databaseHelper.removeAllOHQueueItemsWithIdSmallerThan(highestId)
|
||||
}
|
||||
|
||||
private fun handleSignOut() {
|
||||
|
@ -649,4 +647,5 @@ class OpenHumansUploader @Inject constructor(
|
|||
private fun onSharedPreferenceChanged(event: EventPreferenceChange) {
|
||||
if (event.changedKey == "key_oh_charging_only" && isSetup) scheduleWorker(true)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,10 +3,8 @@ package info.nightscout.androidaps.plugins.general.overview.graphExtensions
|
|||
import android.graphics.Color
|
||||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.core.R
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.database.entities.TherapyEvent
|
||||
import info.nightscout.androidaps.interfaces.GlucoseUnit
|
||||
import info.nightscout.androidaps.interfaces.Interval
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.utils.Translator
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
|
@ -17,7 +15,7 @@ class TherapyEventDataPoint @Inject constructor(
|
|||
private val resourceHelper: ResourceHelper,
|
||||
private val profileFunction: ProfileFunction,
|
||||
private val translator: Translator
|
||||
) : DataPointWithLabelInterface, Interval {
|
||||
) : DataPointWithLabelInterface {
|
||||
|
||||
private var yValue = 0.0
|
||||
|
||||
|
@ -52,7 +50,7 @@ class TherapyEventDataPoint @Inject constructor(
|
|||
if (data.note != null) data.note
|
||||
else translator.translate(data.type)
|
||||
|
||||
override fun getDuration(): Long = end() - start()
|
||||
override fun getDuration(): Long = data.duration
|
||||
override fun getShape(): PointsWithLabelGraphSeries.Shape =
|
||||
when {
|
||||
data.type == TherapyEvent.Type.NS_MBG -> PointsWithLabelGraphSeries.Shape.MBG
|
||||
|
@ -74,22 +72,4 @@ class TherapyEventDataPoint @Inject constructor(
|
|||
TherapyEvent.Type.APS_OFFLINE -> Color.GRAY and -0x7f000001
|
||||
else -> Color.GRAY
|
||||
}
|
||||
|
||||
// Interval interface
|
||||
private var cutEnd: Long? = null
|
||||
|
||||
override fun durationInMsec(): Long = data.duration
|
||||
override fun start(): Long = data.timestamp
|
||||
override fun originalEnd(): Long = data.timestamp + durationInMsec()
|
||||
override fun end(): Long = cutEnd ?: originalEnd()
|
||||
override fun cutEndTo(end: Long) {
|
||||
cutEnd = end
|
||||
}
|
||||
|
||||
override fun match(time: Long): Boolean = start() <= time && end() >= time
|
||||
override fun before(time: Long): Boolean = end() < time
|
||||
override fun after(time: Long): Boolean = start() > time
|
||||
override val isInProgress: Boolean get() = match(System.currentTimeMillis())
|
||||
override val isEndingEvent: Boolean get() = durationInMsec() == 0L
|
||||
override val isValid: Boolean get() = data.type == TherapyEvent.Type.APS_OFFLINE
|
||||
}
|
|
@ -28,6 +28,8 @@ import info.nightscout.androidaps.utils.*
|
|||
import info.nightscout.androidaps.utils.alertDialogs.OKDialog
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers
|
||||
import info.nightscout.androidaps.utils.ui.SpinnerHelper
|
||||
import info.nightscout.androidaps.utils.ui.TimeListEdit
|
||||
import io.reactivex.disposables.CompositeDisposable
|
||||
import io.reactivex.rxkotlin.plusAssign
|
||||
import java.text.DecimalFormat
|
||||
|
|
|
@ -1,540 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.treatments;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.j256.ormlite.android.apptools.OpenHelperManager;
|
||||
import com.j256.ormlite.android.apptools.OrmLiteBaseService;
|
||||
import com.j256.ormlite.dao.Dao;
|
||||
import com.j256.ormlite.dao.DaoManager;
|
||||
import com.j256.ormlite.stmt.PreparedQuery;
|
||||
import com.j256.ormlite.stmt.QueryBuilder;
|
||||
import com.j256.ormlite.stmt.Where;
|
||||
import com.j256.ormlite.support.ConnectionSource;
|
||||
import com.j256.ormlite.table.TableUtils;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.db.DatabaseHelper;
|
||||
import info.nightscout.androidaps.db.Source;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||
import info.nightscout.androidaps.interfaces.TreatmentServiceInterface;
|
||||
import info.nightscout.androidaps.interfaces.UpdateReturn;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
import info.nightscout.androidaps.plugins.general.openhumans.OpenHumansUploader;
|
||||
import info.nightscout.androidaps.plugins.pump.medtronic.MedtronicPumpPlugin;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
|
||||
|
||||
|
||||
/**
|
||||
* Created by mike on 24.09.2017.
|
||||
*/
|
||||
|
||||
public class TreatmentService extends OrmLiteBaseService<DatabaseHelper> implements TreatmentServiceInterface {
|
||||
|
||||
@Inject AAPSLogger aapsLogger;
|
||||
@Inject FabricPrivacy fabricPrivacy;
|
||||
@Inject RxBusWrapper rxBus;
|
||||
@Inject MedtronicPumpPlugin medtronicPumpPlugin;
|
||||
@Inject DatabaseHelperInterface databaseHelper;
|
||||
@Inject OpenHumansUploader openHumansUploader;
|
||||
@Inject AapsSchedulers aapsSchedulers;
|
||||
|
||||
public TreatmentService(HasAndroidInjector injector) {
|
||||
injector.androidInjector().inject(this);
|
||||
onCreate();
|
||||
dbInitialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is a simple re-implementation of the database create and up/downgrade functionality
|
||||
* in SQLiteOpenHelper#getDatabaseLocked method.
|
||||
* <p>
|
||||
* It is implemented to be able to late initialize separate plugins of the application.
|
||||
*/
|
||||
protected void dbInitialize() {
|
||||
DatabaseHelper helper = OpenHelperManager.getHelper(this, DatabaseHelper.class);
|
||||
int newVersion = helper.getNewVersion();
|
||||
int oldVersion = helper.getOldVersion();
|
||||
|
||||
if (oldVersion > newVersion) {
|
||||
onDowngrade(this.getConnectionSource(), oldVersion, newVersion);
|
||||
} else {
|
||||
onUpgrade(this.getConnectionSource(), oldVersion, newVersion);
|
||||
}
|
||||
}
|
||||
|
||||
public TreatmentDaoWrapper getDao() {
|
||||
try {
|
||||
return new TreatmentDaoWrapper(DaoManager.createDao(this.getConnectionSource(), Treatment.class));
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Cannot create Dao for Treatment.class");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
class TreatmentDaoWrapper {
|
||||
private final Dao<Treatment, Long> wrapped;
|
||||
|
||||
TreatmentDaoWrapper(Dao<Treatment, Long> wrapped) {
|
||||
this.wrapped = wrapped;
|
||||
}
|
||||
|
||||
public void executeRaw(String statement, String... arguments) throws SQLException {
|
||||
wrapped.executeRaw(statement, arguments);
|
||||
}
|
||||
|
||||
public List<Treatment> queryForAll() throws SQLException {
|
||||
return wrapped.queryForAll();
|
||||
}
|
||||
|
||||
public Treatment queryForId(long id) throws SQLException {
|
||||
return wrapped.queryForId(id);
|
||||
}
|
||||
|
||||
public QueryBuilder<Treatment, Long> queryBuilder() {
|
||||
return wrapped.queryBuilder();
|
||||
}
|
||||
|
||||
public List<Treatment> query(PreparedQuery<Treatment> data) throws SQLException {
|
||||
return wrapped.query(data);
|
||||
}
|
||||
|
||||
public long countOf() throws SQLException {
|
||||
return wrapped.countOf();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
try {
|
||||
aapsLogger.info(LTag.DATATREATMENTS, "onCreate");
|
||||
TableUtils.createTableIfNotExists(this.getConnectionSource(), Treatment.class);
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Can't create database", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void onUpgrade(ConnectionSource connectionSource, int oldVersion, int newVersion) {
|
||||
if (oldVersion == 7 && newVersion == 8) {
|
||||
aapsLogger.debug("Upgrading database from v7 to v8");
|
||||
try {
|
||||
TableUtils.dropTable(connectionSource, Treatment.class, true);
|
||||
TableUtils.createTableIfNotExists(connectionSource, Treatment.class);
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Can't create database", e);
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
} else if (oldVersion == 8 && newVersion == 9) {
|
||||
aapsLogger.debug("Upgrading database from v8 to v9");
|
||||
try {
|
||||
getDao().executeRaw("ALTER TABLE `" + Treatment.TABLE_TREATMENTS + "` ADD COLUMN boluscalc STRING;");
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
} else {
|
||||
aapsLogger.info(LTag.DATATREATMENTS, "onUpgrade");
|
||||
// this.resetFood();
|
||||
}
|
||||
}
|
||||
|
||||
public void onDowngrade(ConnectionSource connectionSource, int oldVersion, int newVersion) {
|
||||
if (oldVersion == 9 && newVersion == 8) {
|
||||
try {
|
||||
getDao().executeRaw("ALTER TABLE `" + Treatment.TABLE_TREATMENTS + "` DROP COLUMN boluscalc STRING;");
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public long count() {
|
||||
try {
|
||||
return this.getDao().countOf();
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return 0L;
|
||||
}
|
||||
|
||||
/*
|
||||
{
|
||||
"_id": "551ee3ad368e06e80856e6a9",
|
||||
"type": "food",
|
||||
"category": "Zakladni",
|
||||
"subcategory": "Napoje",
|
||||
"name": "Mleko",
|
||||
"portion": 250,
|
||||
"carbs": 12,
|
||||
"gi": 1,
|
||||
"created_at": "2015-04-14T06:59:16.500Z",
|
||||
"unit": "ml"
|
||||
}
|
||||
*/
|
||||
// return true if new record is created
|
||||
public UpdateReturn createOrUpdate(Treatment treatment) {
|
||||
/*
|
||||
if (treatment != null && treatment.source == Source.NONE) {
|
||||
aapsLogger.error("Coder error: source is not set for treatment: " + treatment, new Exception());
|
||||
//FabricPrivacy.logException(new Exception("Coder error: source is not set for treatment: " + treatment));
|
||||
}
|
||||
try {
|
||||
Treatment old;
|
||||
treatment.date = databaseHelper.roundDateToSec(treatment.date);
|
||||
|
||||
if (treatment.source == Source.PUMP) {
|
||||
// check for changed from pump change in NS
|
||||
Treatment existingTreatment = getPumpRecordById(treatment.pumpId);
|
||||
if (existingTreatment != null) {
|
||||
boolean equalRePumpHistory = existingTreatment.equalsRePumpHistory(treatment);
|
||||
boolean sameSource = existingTreatment.source == treatment.source;
|
||||
if (!equalRePumpHistory) {
|
||||
// another treatment exists. Update it with the treatment coming from the pump
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString());
|
||||
long oldDate = existingTreatment.date;
|
||||
|
||||
//preserve carbs
|
||||
if (existingTreatment.isValid && existingTreatment.carbs > 0 && treatment.carbs == 0) {
|
||||
treatment.carbs = existingTreatment.carbs;
|
||||
// preserve insulin
|
||||
} else if (existingTreatment.isValid && existingTreatment.insulin > 0 && treatment.insulin == 0) {
|
||||
treatment.insulin = existingTreatment.insulin;
|
||||
}
|
||||
|
||||
getDao().delete(existingTreatment); // need to delete/create because date may change too
|
||||
existingTreatment.copyBasics(treatment);
|
||||
getDao().create(existingTreatment);
|
||||
DatabaseHelper.updateEarliestDataChange(oldDate);
|
||||
DatabaseHelper.updateEarliestDataChange(existingTreatment.date);
|
||||
scheduleTreatmentChange(treatment, true);
|
||||
return new UpdateReturn(sameSource, false); //updating a pump treatment with another one from the pump is not counted as clash
|
||||
}
|
||||
return new UpdateReturn(equalRePumpHistory, false);
|
||||
}
|
||||
existingTreatment = getDao().queryForId(treatment.date);
|
||||
if (existingTreatment != null) {
|
||||
// another treatment exists with different pumpID. Update it with the treatment coming from the pump
|
||||
boolean equalRePumpHistory = existingTreatment.equalsRePumpHistory(treatment);
|
||||
boolean sameSource = existingTreatment.source == treatment.source;
|
||||
long oldDate = existingTreatment.date;
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "Pump record already found in database: " + existingTreatment.toString() + " wanting to add " + treatment.toString());
|
||||
|
||||
//preserve carbs
|
||||
if (existingTreatment.isValid && existingTreatment.carbs > 0 && treatment.carbs == 0) {
|
||||
treatment.carbs = existingTreatment.carbs;
|
||||
}
|
||||
|
||||
getDao().delete(existingTreatment); // need to delete/create because date may change too
|
||||
existingTreatment.copyFrom(treatment);
|
||||
getDao().create(existingTreatment);
|
||||
DatabaseHelper.updateEarliestDataChange(oldDate);
|
||||
DatabaseHelper.updateEarliestDataChange(existingTreatment.date);
|
||||
scheduleTreatmentChange(treatment, true);
|
||||
return new UpdateReturn(equalRePumpHistory || sameSource, false);
|
||||
}
|
||||
getDao().create(treatment);
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||
DatabaseHelper.updateEarliestDataChange(treatment.date);
|
||||
scheduleTreatmentChange(treatment, true);
|
||||
return new UpdateReturn(true, true);
|
||||
}
|
||||
if (treatment.source == Source.NIGHTSCOUT) {
|
||||
old = getDao().queryForId(treatment.date);
|
||||
if (old != null) {
|
||||
if (!old.isEqual(treatment)) {
|
||||
boolean historyChange = old.isDataChanging(treatment);
|
||||
long oldDate = old.date;
|
||||
getDao().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(treatment);
|
||||
getDao().create(old);
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "Updating record by date from: " + Source.getString(treatment.source) + " " + old.toString());
|
||||
if (historyChange) {
|
||||
DatabaseHelper.updateEarliestDataChange(oldDate);
|
||||
DatabaseHelper.updateEarliestDataChange(old.date);
|
||||
}
|
||||
scheduleTreatmentChange(treatment, false);
|
||||
return new UpdateReturn(true, true);
|
||||
}
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "Equal record by date from: " + Source.getString(treatment.source) + " " + old.toString());
|
||||
return new UpdateReturn(true, false);
|
||||
}
|
||||
// find by NS _id
|
||||
if (treatment._id != null) {
|
||||
old = findByNSId(treatment._id);
|
||||
if (old != null) {
|
||||
if (!old.isEqual(treatment)) {
|
||||
boolean historyChange = old.isDataChanging(treatment);
|
||||
long oldDate = old.date;
|
||||
getDao().delete(old); // need to delete/create because date may change too
|
||||
old.copyFrom(treatment);
|
||||
getDao().create(old);
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "Updating record by _id from: " + Source.getString(treatment.source) + " " + old.toString());
|
||||
if (historyChange) {
|
||||
DatabaseHelper.updateEarliestDataChange(oldDate);
|
||||
DatabaseHelper.updateEarliestDataChange(old.date);
|
||||
}
|
||||
scheduleTreatmentChange(treatment, false);
|
||||
return new UpdateReturn(true, true);
|
||||
}
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "Equal record by _id from: " + Source.getString(treatment.source) + " " + old.toString());
|
||||
return new UpdateReturn(true, false);
|
||||
}
|
||||
}
|
||||
getDao().create(treatment);
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||
DatabaseHelper.updateEarliestDataChange(treatment.date);
|
||||
scheduleTreatmentChange(treatment, false);
|
||||
return new UpdateReturn(true, true);
|
||||
}
|
||||
if (treatment.source == Source.USER) {
|
||||
getDao().create(treatment);
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||
DatabaseHelper.updateEarliestDataChange(treatment.date);
|
||||
scheduleTreatmentChange(treatment, true);
|
||||
return new UpdateReturn(true, true);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
*/
|
||||
return new UpdateReturn(false, false);
|
||||
}
|
||||
|
||||
|
||||
@NotNull public UpdateReturn createOrUpdateMedtronic(@NotNull Treatment treatment, boolean fromNightScout) {
|
||||
/*
|
||||
if (MedtronicHistoryData.doubleBolusDebug)
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "DoubleBolusDebug: createOrUpdateMedtronic:: originalTreatment={}, fromNightScout={}", treatment, fromNightScout);
|
||||
|
||||
try {
|
||||
treatment.date = databaseHelper.roundDateToSec(treatment.date);
|
||||
|
||||
Treatment existingTreatment = getRecord(treatment.pumpId, treatment.date);
|
||||
|
||||
if (MedtronicHistoryData.doubleBolusDebug)
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "DoubleBolusDebug: createOrUpdateMedtronic:: existingTreatment={}", treatment);
|
||||
|
||||
if (existingTreatment == null) {
|
||||
getDao().create(treatment);
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "New record from: " + Source.getString(treatment.source) + " " + treatment.toString());
|
||||
DatabaseHelper.updateEarliestDataChange(treatment.date);
|
||||
scheduleTreatmentChange(treatment, true);
|
||||
return new UpdateReturn(true, true);
|
||||
} else {
|
||||
|
||||
if (existingTreatment.date == treatment.date) {
|
||||
if (MedtronicHistoryData.doubleBolusDebug)
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "DoubleBolusDebug: createOrUpdateMedtronic::(existingTreatment.date==treatment.date)");
|
||||
|
||||
// we will do update only, if entry changed
|
||||
if (!optionalTreatmentCopy(existingTreatment, treatment, fromNightScout)) {
|
||||
return new UpdateReturn(true, false);
|
||||
}
|
||||
getDao().update(existingTreatment);
|
||||
DatabaseHelper.updateEarliestDataChange(existingTreatment.date);
|
||||
scheduleTreatmentChange(treatment, true);
|
||||
return new UpdateReturn(true, false);
|
||||
} else {
|
||||
if (MedtronicHistoryData.doubleBolusDebug)
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "DoubleBolusDebug: createOrUpdateMedtronic::(existingTreatment.date != treatment.date)");
|
||||
|
||||
// date is different, we need to remove entry
|
||||
getDao().delete(existingTreatment);
|
||||
optionalTreatmentCopy(existingTreatment, treatment, fromNightScout);
|
||||
getDao().create(existingTreatment);
|
||||
DatabaseHelper.updateEarliestDataChange(existingTreatment.date);
|
||||
scheduleTreatmentChange(treatment, true);
|
||||
return new UpdateReturn(true, false); //updating a pump treatment with another one from the pump is not counted as clash
|
||||
}
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled SQL exception: {}", e.getMessage(), e);
|
||||
}
|
||||
|
||||
*/
|
||||
return new UpdateReturn(false, false);
|
||||
}
|
||||
|
||||
|
||||
private boolean optionalTreatmentCopy(Treatment oldTreatment, Treatment newTreatment, boolean fromNightScout) {
|
||||
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "optionalTreatmentCopy [old={}, new={}]", oldTreatment.toString(), newTreatment.toString());
|
||||
|
||||
boolean changed = false;
|
||||
|
||||
if (oldTreatment.date != newTreatment.date) {
|
||||
oldTreatment.date = newTreatment.date;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (oldTreatment.isSMB != newTreatment.isSMB) {
|
||||
if (!oldTreatment.isSMB) {
|
||||
oldTreatment.isSMB = newTreatment.isSMB;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isSame(oldTreatment.carbs, newTreatment.carbs)) {
|
||||
if (isSame(oldTreatment.carbs, 0.0d)) {
|
||||
oldTreatment.carbs = newTreatment.carbs;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (oldTreatment.mealBolus != (oldTreatment.carbs > 0)) {
|
||||
oldTreatment.mealBolus = (oldTreatment.carbs > 0);
|
||||
changed = true;
|
||||
}
|
||||
|
||||
if (!isSame(oldTreatment.insulin, newTreatment.insulin)) {
|
||||
if (!fromNightScout) {
|
||||
oldTreatment.insulin = newTreatment.insulin;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!StringUtils.equals(oldTreatment._id, newTreatment._id)) {
|
||||
if (StringUtils.isBlank(oldTreatment._id)) {
|
||||
oldTreatment._id = newTreatment._id;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
int source = Source.NONE;
|
||||
|
||||
if (oldTreatment.pumpId == 0) {
|
||||
if (newTreatment.pumpId > 0) {
|
||||
oldTreatment.pumpId = newTreatment.pumpId;
|
||||
source = Source.PUMP;
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (source == Source.NONE) {
|
||||
|
||||
if (oldTreatment.source == newTreatment.source) {
|
||||
source = oldTreatment.source;
|
||||
} else {
|
||||
source = (oldTreatment.source == Source.NIGHTSCOUT || newTreatment.source == Source.NIGHTSCOUT) ? Source.NIGHTSCOUT : Source.USER;
|
||||
}
|
||||
}
|
||||
|
||||
if (oldTreatment.source != source) {
|
||||
oldTreatment.source = source;
|
||||
changed = true;
|
||||
}
|
||||
|
||||
aapsLogger.debug(LTag.DATATREATMENTS, "optionalTreatmentCopy [changed={}, newAfterChange={}]", changed, oldTreatment.toString());
|
||||
return changed;
|
||||
}
|
||||
|
||||
|
||||
public static boolean isSame(Double d1, Double d2) {
|
||||
double diff = d1 - d2;
|
||||
|
||||
return (Math.abs(diff) <= 0.00001);
|
||||
}
|
||||
|
||||
public Treatment getRecord(long pumpId, long date) {
|
||||
|
||||
Treatment record = null;
|
||||
|
||||
if (pumpId > 0) {
|
||||
|
||||
record = getPumpRecordById(pumpId);
|
||||
|
||||
if (record != null) {
|
||||
return record;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
record = getDao().queryForId(date);
|
||||
} catch (SQLException ex) {
|
||||
aapsLogger.error("Error getting entry by id ({}", date);
|
||||
}
|
||||
|
||||
return record;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the record for the given id, null if none, throws RuntimeException
|
||||
* if multiple records with the same pump id exist.
|
||||
*/
|
||||
@Nullable
|
||||
public Treatment getPumpRecordById(long pumpId) {
|
||||
try {
|
||||
QueryBuilder<Treatment, Long> queryBuilder = getDao().queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("pumpId", pumpId);
|
||||
queryBuilder.orderBy("date", true);
|
||||
|
||||
List<Treatment> result = getDao().query(queryBuilder.prepare());
|
||||
if (result.isEmpty())
|
||||
return null;
|
||||
if (result.size() > 1)
|
||||
aapsLogger.warn(LTag.DATATREATMENTS, "Multiple records with the same pump id found (returning first one): " + result.toString());
|
||||
return result.get(0);
|
||||
} catch (SQLException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* finds treatment by its NS Id.
|
||||
*
|
||||
* @param _id
|
||||
* @return
|
||||
*/
|
||||
@Nullable
|
||||
public Treatment findByNSId(String _id) {
|
||||
try {
|
||||
TreatmentDaoWrapper daoTreatments = getDao();
|
||||
QueryBuilder<Treatment, Long> queryBuilder = daoTreatments.queryBuilder();
|
||||
Where where = queryBuilder.where();
|
||||
where.eq("_id", _id);
|
||||
queryBuilder.limit(10L);
|
||||
PreparedQuery<Treatment> preparedQuery = queryBuilder.prepare();
|
||||
List<Treatment> trList = daoTreatments.query(preparedQuery);
|
||||
if (trList.size() != 1) {
|
||||
//log.debug("Treatment findTreatmentById query size: " + trList.size());
|
||||
return null;
|
||||
} else {
|
||||
//log.debug("Treatment findTreatmentById found: " + trList.get(0).log());
|
||||
return trList.get(0);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
aapsLogger.error("Unhandled exception", e);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,306 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.treatments;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
import info.nightscout.androidaps.database.AppRepository;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin;
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||
import info.nightscout.androidaps.interfaces.PluginBase;
|
||||
import info.nightscout.androidaps.interfaces.PluginDescription;
|
||||
import info.nightscout.androidaps.interfaces.PluginType;
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
||||
import info.nightscout.androidaps.interfaces.TreatmentServiceInterface;
|
||||
import info.nightscout.androidaps.interfaces.TreatmentsInterface;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy;
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||
import info.nightscout.androidaps.utils.rx.AapsSchedulers;
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||
import io.reactivex.disposables.CompositeDisposable;
|
||||
|
||||
@Singleton
|
||||
public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface {
|
||||
|
||||
private final SP sp;
|
||||
private final RxBusWrapper rxBus;
|
||||
private final ProfileFunction profileFunction;
|
||||
private final ActivePlugin activePlugin;
|
||||
private final FabricPrivacy fabricPrivacy;
|
||||
private final DateUtil dateUtil;
|
||||
private final DatabaseHelperInterface databaseHelper;
|
||||
private final AppRepository repository;
|
||||
|
||||
private final CompositeDisposable disposable = new CompositeDisposable();
|
||||
|
||||
protected TreatmentServiceInterface service;
|
||||
|
||||
@Inject
|
||||
public TreatmentsPlugin(
|
||||
HasAndroidInjector injector,
|
||||
AAPSLogger aapsLogger,
|
||||
RxBusWrapper rxBus,
|
||||
AapsSchedulers aapsSchedulers,
|
||||
ResourceHelper resourceHelper,
|
||||
Context context,
|
||||
SP sp,
|
||||
ProfileFunction profileFunction,
|
||||
ActivePlugin activePlugin,
|
||||
FabricPrivacy fabricPrivacy,
|
||||
DateUtil dateUtil,
|
||||
DatabaseHelperInterface databaseHelper,
|
||||
AppRepository repository
|
||||
) {
|
||||
super(new PluginDescription()
|
||||
.mainType(PluginType.TREATMENT)
|
||||
.pluginIcon(R.drawable.ic_treatments)
|
||||
.pluginName(R.string.treatments)
|
||||
.shortName(R.string.treatments_shortname)
|
||||
.alwaysEnabled(true)
|
||||
.description(R.string.description_treatments)
|
||||
.setDefault(),
|
||||
aapsLogger, resourceHelper, injector
|
||||
);
|
||||
this.rxBus = rxBus;
|
||||
this.sp = sp;
|
||||
this.profileFunction = profileFunction;
|
||||
this.activePlugin = activePlugin;
|
||||
this.fabricPrivacy = fabricPrivacy;
|
||||
this.dateUtil = dateUtil;
|
||||
this.databaseHelper = databaseHelper;
|
||||
this.repository = repository;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
this.service = new TreatmentService(getInjector());
|
||||
super.onStart();
|
||||
// disposable.add(rxBus
|
||||
// .toObservable(EventReloadProfileSwitchData.class)
|
||||
// .observeOn(aapsSchedulers.getIo())
|
||||
// .subscribe(event -> initializeProfileSwitchData(range()),
|
||||
// fabricPrivacy::logException
|
||||
// ));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
disposable.clear();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
public TreatmentServiceInterface getService() {
|
||||
return this.service;
|
||||
}
|
||||
|
||||
protected long range() {
|
||||
double dia = Constants.defaultDIA;
|
||||
if (profileFunction.getProfile() != null)
|
||||
dia = profileFunction.getProfile().getDia();
|
||||
return (long) (60 * 60 * 1000L * (24 + dia));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns all Treatments after specified timestamp. Also returns invalid entries (required to
|
||||
* map "Fill Cannula" entries to history (and not to add double bolus for it)
|
||||
*
|
||||
* @param fromTimestamp
|
||||
* @return
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public List<Treatment> getTreatmentsFromHistoryAfterTimestamp(long fromTimestamp) {
|
||||
return repository.getBolusesIncludingInvalidFromTimeToTime(fromTimestamp, dateUtil.now(), true)
|
||||
.blockingGet()
|
||||
.stream()
|
||||
.map(bolus -> new Treatment(getInjector(), bolus))
|
||||
.collect(Collectors.toList());
|
||||
/*
|
||||
List<Treatment> in5minback = new ArrayList<>();
|
||||
|
||||
long time = System.currentTimeMillis();
|
||||
synchronized (treatments) {
|
||||
// getAapsLogger().debug(MedtronicHistoryData.doubleBolusDebug, LTag.DATATREATMENTS, "DoubleBolusDebug: AllTreatmentsInDb: " + new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(treatments));
|
||||
|
||||
for (Treatment t : treatments) {
|
||||
if (t.date >= fromTimestamp && t.date <= time)
|
||||
in5minback.add(t);
|
||||
}
|
||||
// getAapsLogger().debug(MedtronicHistoryData.doubleBolusDebug, LTag.DATATREATMENTS, "DoubleBolusDebug: FilteredTreatments: AfterTime={}, Items={} " + fromTimestamp + " " + new GsonBuilder().excludeFieldsWithoutExposeAnnotation().create().toJson(in5minback));
|
||||
return in5minback;
|
||||
}
|
||||
*/
|
||||
}
|
||||
/*
|
||||
@Override
|
||||
public long getLastBolusTime() {
|
||||
Treatment last = getService().getLastBolus(false);
|
||||
if (last == null) {
|
||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last bolus time: NOTHING FOUND");
|
||||
return 0;
|
||||
} else {
|
||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last bolus time: " + dateUtil.dateAndTimeString(last.date));
|
||||
return last.date;
|
||||
}
|
||||
}
|
||||
|
||||
public long getLastBolusTime(boolean excludeSMB) {
|
||||
Treatment last = getService().getLastBolus(excludeSMB);
|
||||
if (last == null) {
|
||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last manual bolus time: NOTHING FOUND");
|
||||
return 0;
|
||||
} else {
|
||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last manual bolus time: " + dateUtil.dateAndTimeString(last.date));
|
||||
return last.date;
|
||||
}
|
||||
}
|
||||
|
||||
public long getLastCarbTime() {
|
||||
Treatment last = getService().getLastCarb();
|
||||
if (last == null) {
|
||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last Carb time: NOTHING FOUND");
|
||||
return 0;
|
||||
} else {
|
||||
getAapsLogger().debug(LTag.DATATREATMENTS, "Last Carb time: " + dateUtil.dateAndTimeString(last.date));
|
||||
return last.date;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean addToHistoryExtendedBolus(ExtendedBolus extendedBolus) {
|
||||
throw new IllegalStateException("Migrate to new DB");
|
||||
//log.debug("Adding new ExtentedBolus record" + extendedBolus.log());
|
||||
/*
|
||||
boolean newRecordCreated = databaseHelper.createOrUpdate(extendedBolus);
|
||||
if (newRecordCreated) {
|
||||
if (extendedBolus.durationInMinutes == 0) {
|
||||
if (activePlugin.getActivePump().isFakingTempsByExtendedBoluses())
|
||||
nsUpload.uploadTempBasalEnd(extendedBolus.date, true, extendedBolus.pumpId);
|
||||
else
|
||||
nsUpload.uploadExtendedBolusEnd(extendedBolus.date, extendedBolus.pumpId);
|
||||
} else if (activePlugin.getActivePump().isFakingTempsByExtendedBoluses())
|
||||
nsUpload.uploadTempBasalStartAbsolute(new TemporaryBasal(extendedBolus), extendedBolus.insulin);
|
||||
else
|
||||
nsUpload.uploadExtendedBolus(extendedBolus);
|
||||
}
|
||||
return newRecordCreated;
|
||||
*/
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean addToHistoryTempBasal(TemporaryBasal tempBasal) {
|
||||
throw new IllegalStateException("Migrate to new DB");
|
||||
/*
|
||||
//log.debug("Adding new TemporaryBasal record" + tempBasal.toString());
|
||||
boolean newRecordCreated = databaseHelper.createOrUpdate(tempBasal);
|
||||
if (newRecordCreated) {
|
||||
if (tempBasal.durationInMinutes == 0)
|
||||
nsUpload.uploadTempBasalEnd(tempBasal.date, false, tempBasal.pumpId);
|
||||
else if (tempBasal.isAbsolute)
|
||||
nsUpload.uploadTempBasalStartAbsolute(tempBasal, null);
|
||||
else
|
||||
nsUpload.uploadTempBasalStartPercent(tempBasal, profileFunction.getProfile(tempBasal.date));
|
||||
}
|
||||
return newRecordCreated;
|
||||
*/
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public TreatmentUpdateReturn createOrUpdateMedtronic(Treatment treatment, boolean fromNightScout) {
|
||||
throw new IllegalStateException("Migrate to new DB");
|
||||
/*
|
||||
UpdateReturn resultRecord = getService().createOrUpdateMedtronic(treatment, fromNightScout);
|
||||
|
||||
return new TreatmentUpdateReturn(resultRecord.getSuccess(), resultRecord.getNewRecord());
|
||||
*/
|
||||
}
|
||||
|
||||
// return true if new record is created
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo, boolean allowUpdate) {
|
||||
throw new IllegalStateException("Migrate to new DB");
|
||||
/*
|
||||
boolean medtronicPump = activePlugin.getActivePump() instanceof MedtronicPumpPlugin;
|
||||
|
||||
getAapsLogger().debug(MedtronicHistoryData.doubleBolusDebug, LTag.DATATREATMENTS, "DoubleBolusDebug: addToHistoryTreatment::isMedtronicPump={} " + medtronicPump);
|
||||
|
||||
Treatment treatment = new Treatment();
|
||||
treatment.date = detailedBolusInfo.timestamp;
|
||||
treatment.source = (detailedBolusInfo.getPumpType() == PumpType.USER) ? Source.USER : Source.PUMP;
|
||||
treatment.pumpId = detailedBolusInfo.getBolusPumpId() != null ? detailedBolusInfo.getBolusPumpId() : 0;
|
||||
treatment.insulin = detailedBolusInfo.insulin;
|
||||
treatment.isValid = detailedBolusInfo.getBolusType() != DetailedBolusInfo.BolusType.PRIMING;
|
||||
treatment.isSMB = detailedBolusInfo.getBolusType() == DetailedBolusInfo.BolusType.SMB;
|
||||
if (detailedBolusInfo.carbTime == 0)
|
||||
treatment.carbs = detailedBolusInfo.carbs;
|
||||
treatment.mealBolus = treatment.carbs > 0;
|
||||
// treatment.boluscalc = detailedBolusInfo.boluscalc != null ? detailedBolusInfo.boluscalc.toString() : null;
|
||||
treatment.boluscalc = null;
|
||||
UpdateReturn creatOrUpdateResult;
|
||||
|
||||
getAapsLogger().debug(medtronicPump && MedtronicHistoryData.doubleBolusDebug, LTag.DATATREATMENTS, "DoubleBolusDebug: addToHistoryTreatment::treatment={} " + treatment);
|
||||
|
||||
if (!medtronicPump)
|
||||
creatOrUpdateResult = getService().createOrUpdate(treatment);
|
||||
else
|
||||
creatOrUpdateResult = getService().createOrUpdateMedtronic(treatment, false);
|
||||
|
||||
boolean newRecordCreated = creatOrUpdateResult.getNewRecord();
|
||||
//log.debug("Adding new Treatment record" + treatment.toString());
|
||||
if (detailedBolusInfo.carbTime != 0) {
|
||||
|
||||
Treatment carbsTreatment = new Treatment();
|
||||
carbsTreatment.source = (detailedBolusInfo.getPumpType() == PumpType.USER) ? Source.USER : Source.PUMP;
|
||||
carbsTreatment.pumpId = detailedBolusInfo.getCarbsPumpId() != null ? detailedBolusInfo.getCarbsPumpId() : 0; // but this should never happen
|
||||
carbsTreatment.date = detailedBolusInfo.timestamp + detailedBolusInfo.carbTime * 60 * 1000L + 1000L; // add 1 sec to make them different records
|
||||
carbsTreatment.carbs = detailedBolusInfo.carbs;
|
||||
|
||||
getAapsLogger().debug(medtronicPump && MedtronicHistoryData.doubleBolusDebug, LTag.DATATREATMENTS, "DoubleBolusDebug: carbTime!=0, creating second treatment. CarbsTreatment={}" + carbsTreatment);
|
||||
|
||||
if (!medtronicPump)
|
||||
getService().createOrUpdate(carbsTreatment);
|
||||
else
|
||||
getService().createOrUpdateMedtronic(carbsTreatment, false);
|
||||
//log.debug("Adding new Treatment record" + carbsTreatment);
|
||||
}
|
||||
if (newRecordCreated && detailedBolusInfo.getBolusType() != DetailedBolusInfo.BolusType.PRIMING)
|
||||
nsUpload.uploadTreatmentRecord(detailedBolusInfo);
|
||||
|
||||
if (!allowUpdate && !creatOrUpdateResult.getSuccess()) {
|
||||
getAapsLogger().error("Treatment could not be added to DB", new Exception());
|
||||
|
||||
String status = String.format(resourceHelper.gs(R.string.error_adding_treatment_message), treatment.insulin, (int) treatment.carbs, dateUtil.dateAndTimeString(treatment.date));
|
||||
|
||||
ErrorHelperActivity.Companion.runAlarm(context, status, resourceHelper.gs(R.string.error_adding_treatment_title), R.raw.error);
|
||||
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString(FirebaseAnalytics.Param.ITEM_LIST_ID, "TreatmentClash");
|
||||
bundle.putString(FirebaseAnalytics.Param.ITEM_LIST_NAME, status);
|
||||
fabricPrivacy.logCustom(bundle);
|
||||
}
|
||||
|
||||
return newRecordCreated;
|
||||
*/
|
||||
}
|
||||
}
|
|
@ -1,5 +0,0 @@
|
|||
package info.nightscout.androidaps.plugins.treatments.events
|
||||
|
||||
import info.nightscout.androidaps.events.EventUpdateGui
|
||||
|
||||
class EventTreatmentUpdateGui : EventUpdateGui()
|
|
@ -1,10 +1,9 @@
|
|||
package info.nightscout.androidaps.utils
|
||||
package info.nightscout.androidaps.utils.ui
|
||||
|
||||
import android.content.Context
|
||||
import android.util.AttributeSet
|
||||
import android.view.LayoutInflater
|
||||
import info.nightscout.androidaps.R
|
||||
import info.nightscout.androidaps.utils.ui.NumberPicker
|
||||
|
||||
class NumberPickerVertical : NumberPicker {
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.utils;
|
||||
package info.nightscout.androidaps.utils.ui;
|
||||
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.utils;
|
||||
package info.nightscout.androidaps.utils.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.Editable;
|
||||
|
@ -26,7 +26,10 @@ import java.util.List;
|
|||
|
||||
import info.nightscout.androidaps.R;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.SafeParse;
|
||||
import info.nightscout.androidaps.utils.ui.NumberPicker;
|
||||
import info.nightscout.androidaps.utils.ui.SpinnerHelper;
|
||||
|
||||
/**
|
||||
* Created by mike on 29.12.2016.
|
|
@ -20,13 +20,13 @@
|
|||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<info.nightscout.androidaps.utils.NumberPickerVertical
|
||||
<info.nightscout.androidaps.utils.ui.NumberPickerVertical
|
||||
android:id="@+id/timelistedit_edit1"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="100dp"
|
||||
android:layout_marginRight="5dp" />
|
||||
|
||||
<info.nightscout.androidaps.utils.NumberPickerVertical
|
||||
<info.nightscout.androidaps.utils.ui.NumberPickerVertical
|
||||
android:id="@+id/timelistedit_edit2"
|
||||
android:layout_width="60dp"
|
||||
android:layout_height="100dp" />
|
||||
|
|
|
@ -135,8 +135,6 @@
|
|||
|
||||
<string name="configbuilder_pump">Pump</string>
|
||||
<string name="configbuilder_pump_description">Which pump would you like to use with AndroidAPS?</string>
|
||||
<string name="configbuilder_treatments">Treatments</string>
|
||||
<string name="configbuilder_treatments_description">Which plugin should be used for treatment handling?</string>
|
||||
<string name="configbuilder_profile">Profile</string>
|
||||
<string name="configbuilder_profile_description">Which profile should AndroidAPS use?</string>
|
||||
<string name="configbuilder_aps">APS</string>
|
||||
|
|
|
@ -23,7 +23,6 @@ open class TestBaseWithProfile : TestBase() {
|
|||
|
||||
@Mock lateinit var activePluginProvider: ActivePlugin
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var treatmentsInterface: TreatmentsInterface
|
||||
@Mock lateinit var iobCobCalculator: IobCobCalculator
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
|
|
|
@ -4,9 +4,6 @@ import dagger.android.AndroidInjector
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.androidaps.database.AppRepository
|
||||
import info.nightscout.androidaps.db.TemporaryBasal
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.FabricPrivacy
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP
|
||||
import org.junit.Test
|
||||
|
@ -17,23 +14,14 @@ import org.powermock.modules.junit4.PowerMockRunner
|
|||
|
||||
@Suppress("SpellCheckingInspection")
|
||||
@RunWith(PowerMockRunner::class)
|
||||
@PrepareForTest(FabricPrivacy::class, DatabaseHelperInterface::class, AppRepository::class)
|
||||
@PrepareForTest(FabricPrivacy::class, AppRepository::class)
|
||||
class TreatmentsPluginTest : TestBaseWithProfile() {
|
||||
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var treatmentService: TreatmentService
|
||||
@Mock lateinit var repository: AppRepository
|
||||
@Mock lateinit var databaseHelper: DatabaseHelperInterface
|
||||
|
||||
val injector = HasAndroidInjector {
|
||||
AndroidInjector {
|
||||
if (it is TemporaryBasal) {
|
||||
it.aapsLogger = aapsLogger
|
||||
it.activePlugin = activePluginProvider
|
||||
it.profileFunction = profileFunction
|
||||
it.sp = sp
|
||||
it.dateUtil = DateUtil(context)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -66,7 +66,6 @@ class ActionStartTempTargetTest : ActionsTestBase() {
|
|||
}
|
||||
|
||||
val updated = mutableListOf<TemporaryTarget>().apply {
|
||||
// TODO insert all updated TTs
|
||||
}
|
||||
|
||||
`when`(
|
||||
|
|
|
@ -32,7 +32,6 @@ class ComboPluginTest : TestBase() {
|
|||
@Mock lateinit var pumpSync: PumpSync
|
||||
@Mock lateinit var sp: SP
|
||||
@Mock lateinit var context: Context
|
||||
@Mock lateinit var databaseHelper: DatabaseHelperInterface
|
||||
@Mock lateinit var dateUtil: DateUtil
|
||||
|
||||
val injector = HasAndroidInjector {
|
||||
|
|
|
@ -1,72 +0,0 @@
|
|||
package info.nightscout.androidaps.data
|
||||
|
||||
import androidx.collection.LongSparseArray
|
||||
import info.nightscout.androidaps.interfaces.Interval
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
* Created by mike on 09.05.2017.
|
||||
*/
|
||||
// Zero duration means end of interval
|
||||
abstract class Intervals<T : Interval> {
|
||||
|
||||
var rawData: LongSparseArray<T> = LongSparseArray()// oldest at index 0
|
||||
|
||||
@Synchronized fun reset(): Intervals<T> {
|
||||
rawData = LongSparseArray()
|
||||
return this
|
||||
}
|
||||
|
||||
protected abstract fun merge()
|
||||
|
||||
/**
|
||||
* The List must be sorted by `T.start()` in ascending order
|
||||
*/
|
||||
@Synchronized fun add(list: List<T>) {
|
||||
for (interval in list) {
|
||||
rawData.put(interval.start(), interval)
|
||||
}
|
||||
merge()
|
||||
}
|
||||
|
||||
@Synchronized fun add(interval: T) {
|
||||
rawData.put(interval.start(), interval)
|
||||
merge()
|
||||
}
|
||||
|
||||
@get:Synchronized val list: List<T>
|
||||
get() {
|
||||
val list: MutableList<T> = ArrayList()
|
||||
for (i in 0 until rawData.size()) list.add(rawData.valueAt(i))
|
||||
return list
|
||||
}
|
||||
@get:Synchronized val reversedList: List<T>
|
||||
get() {
|
||||
val list: MutableList<T> = ArrayList()
|
||||
for (i in rawData.size() - 1 downTo 0) list.add(rawData.valueAt(i))
|
||||
return list
|
||||
}
|
||||
|
||||
@Synchronized protected fun binarySearch(value: Long): Int {
|
||||
var lo = 0
|
||||
var hi = rawData.size() - 1
|
||||
while (lo <= hi) {
|
||||
val mid = lo + hi ushr 1
|
||||
val midVal: Interval = rawData.valueAt(mid)
|
||||
when {
|
||||
midVal.before(value) -> lo = mid + 1
|
||||
midVal.after(value) -> hi = mid - 1
|
||||
midVal.match(value) -> return mid // value found
|
||||
}
|
||||
}
|
||||
return lo.inv() // value not present
|
||||
}
|
||||
|
||||
abstract fun getValueByInterval(time: Long): T?
|
||||
|
||||
@Synchronized fun size(): Int = rawData.size()
|
||||
|
||||
@Synchronized operator fun get(index: Int): T? = rawData.valueAt(index)
|
||||
|
||||
@Synchronized fun getReversed(index: Int): T = rawData.valueAt(size() - 1 - index)
|
||||
}
|
|
@ -1,26 +0,0 @@
|
|||
package info.nightscout.androidaps.data
|
||||
|
||||
import info.nightscout.androidaps.interfaces.Interval
|
||||
|
||||
class NonOverlappingIntervals<T : Interval> : Intervals<T> {
|
||||
|
||||
constructor() : super()
|
||||
constructor(other: Intervals<T>) {
|
||||
rawData = other.rawData.clone()
|
||||
}
|
||||
|
||||
@Synchronized public override fun merge() {
|
||||
for (index in 0 until rawData.size() - 1) {
|
||||
val i: T = rawData.valueAt(index)
|
||||
val startOfNewer = rawData.valueAt(index + 1).start()
|
||||
if (i.originalEnd() > startOfNewer) {
|
||||
i.cutEndTo(startOfNewer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized override fun getValueByInterval(time: Long): T? {
|
||||
val index = binarySearch(time)
|
||||
return if (index >= 0) rawData.valueAt(index) else null
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package info.nightscout.androidaps.data
|
||||
|
||||
import info.nightscout.androidaps.interfaces.Interval
|
||||
|
||||
class OverlappingIntervals<T : Interval> : Intervals<T> {
|
||||
|
||||
constructor() : super()
|
||||
constructor(other: Intervals<T>) {
|
||||
rawData = other.rawData.clone()
|
||||
}
|
||||
|
||||
@Synchronized override fun merge() {
|
||||
var needToCut = false
|
||||
var cutTime: Long = 0
|
||||
for (index in rawData.size() - 1 downTo 0) { //begin with newest
|
||||
val cur: Interval = rawData.valueAt(index)
|
||||
if (cur.isEndingEvent) {
|
||||
needToCut = true
|
||||
cutTime = cur.start()
|
||||
} else {
|
||||
//event that is no EndingEvent might need to be stopped by an ending event
|
||||
if (needToCut && cur.end() > cutTime) {
|
||||
cur.cutEndTo(cutTime)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized override fun getValueByInterval(time: Long): T? {
|
||||
for (index in rawData.size() - 1 downTo 0) { //begin with newest
|
||||
val cur = rawData.valueAt(index)
|
||||
if (cur!!.match(time)) {
|
||||
return cur
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
|
@ -1,115 +0,0 @@
|
|||
package info.nightscout.androidaps.data
|
||||
|
||||
import androidx.collection.LongSparseArray
|
||||
import info.nightscout.androidaps.interfaces.Interval
|
||||
import java.util.*
|
||||
|
||||
// Zero duration means profile is valid until is changed
|
||||
// When no interval match the latest record without duration is used
|
||||
class ProfileIntervals<T : Interval> {
|
||||
|
||||
private var rawData: LongSparseArray<T> // oldest at index 0
|
||||
|
||||
constructor() {
|
||||
rawData = LongSparseArray()
|
||||
}
|
||||
|
||||
constructor(other: ProfileIntervals<T>) {
|
||||
rawData = other.rawData.clone()
|
||||
}
|
||||
|
||||
@Synchronized fun reset(): ProfileIntervals<T> {
|
||||
rawData = LongSparseArray()
|
||||
return this
|
||||
}
|
||||
|
||||
@Synchronized fun add(newInterval: T) {
|
||||
if (newInterval.isValid) {
|
||||
rawData.put(newInterval.start(), newInterval)
|
||||
merge()
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized fun add(list: List<T>) {
|
||||
for (interval in list) {
|
||||
if (interval.isValid) rawData.put(interval.start(), interval)
|
||||
}
|
||||
merge()
|
||||
}
|
||||
|
||||
@Synchronized private fun merge() {
|
||||
for (index in 0 until rawData.size() - 1) {
|
||||
val i: T = rawData.valueAt(index)
|
||||
val startOfNewer = rawData.valueAt(index + 1)!!.start()
|
||||
if (i.originalEnd() > startOfNewer) {
|
||||
i.cutEndTo(startOfNewer)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Synchronized fun getValueToTime(time: Long): Interval? {
|
||||
var index = binarySearch(time)
|
||||
if (index >= 0) return rawData.valueAt(index)
|
||||
// if we request data older than first record, use oldest with zero duration instead
|
||||
index = 0
|
||||
while (index < rawData.size()) {
|
||||
if (rawData.valueAt(index)!!.durationInMsec() == 0L) {
|
||||
//log.debug("Requested profile for time: " + DateUtil.dateAndTimeString(time) + ". Providing oldest record: " + rawData.valueAt(0).toString());
|
||||
return rawData.valueAt(index)
|
||||
}
|
||||
index++
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
@get:Synchronized val list: List<T>
|
||||
get() {
|
||||
val list: MutableList<T> = ArrayList()
|
||||
for (i in 0 until rawData.size()) list.add(rawData.valueAt(i))
|
||||
return list
|
||||
}
|
||||
@get:Synchronized val reversedList: List<T>
|
||||
get() {
|
||||
val list: MutableList<T> = ArrayList()
|
||||
for (i in rawData.size() - 1 downTo 0) list.add(rawData.valueAt(i))
|
||||
return list
|
||||
}
|
||||
|
||||
@Synchronized private fun binarySearch(value: Long): Int {
|
||||
if (rawData.size() == 0) return -1
|
||||
var lo = 0
|
||||
var hi = rawData.size() - 1
|
||||
while (lo <= hi) {
|
||||
val mid = lo + hi ushr 1
|
||||
val midVal: Interval = rawData.valueAt(mid)
|
||||
when {
|
||||
midVal.match(value) -> return mid // value found
|
||||
midVal.before(value) -> lo = mid + 1
|
||||
midVal.after(value) -> hi = mid - 1
|
||||
}
|
||||
}
|
||||
// not found, try nearest older with duration 0
|
||||
lo -= 1
|
||||
while (lo >= 0 && lo < rawData.size()) {
|
||||
if (rawData.valueAt(lo)!!.isEndingEvent) return lo
|
||||
lo--
|
||||
}
|
||||
return -1 // value not present
|
||||
}
|
||||
|
||||
@Synchronized fun size(): Int {
|
||||
return rawData.size()
|
||||
}
|
||||
|
||||
@Synchronized operator fun get(index: Int): T? {
|
||||
return rawData.valueAt(index)
|
||||
}
|
||||
|
||||
@Synchronized fun getReversed(index: Int): T {
|
||||
return rawData.valueAt(size() - 1 - index)
|
||||
}
|
||||
|
||||
override fun toString(): String {
|
||||
return rawData.toString()
|
||||
}
|
||||
}
|
|
@ -1,306 +0,0 @@
|
|||
package info.nightscout.androidaps.db;
|
||||
|
||||
/**
|
||||
* Created by mike on 21.05.2017.
|
||||
*/
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin;
|
||||
import info.nightscout.androidaps.interfaces.Insulin;
|
||||
import info.nightscout.androidaps.interfaces.Interval;
|
||||
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface;
|
||||
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.JsonHelper;
|
||||
import info.nightscout.androidaps.utils.Round;
|
||||
|
||||
/**
|
||||
* Created by mike on 21.05.2017.
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
@DatabaseTable(tableName = "ExtendedBoluses")
|
||||
public class ExtendedBolus implements Interval, DataPointWithLabelInterface {
|
||||
|
||||
@Inject ActivePlugin activePlugin;
|
||||
@Inject DateUtil dateUtil;
|
||||
|
||||
private HasAndroidInjector injector;
|
||||
|
||||
@DatabaseField(id = true)
|
||||
public long date;
|
||||
|
||||
@DatabaseField
|
||||
public boolean isValid = true;
|
||||
|
||||
@DatabaseField(index = true)
|
||||
public long pumpId = 0;
|
||||
|
||||
@DatabaseField
|
||||
public int source = Source.NONE;
|
||||
@DatabaseField
|
||||
public String _id = null; // NS _id
|
||||
|
||||
@DatabaseField
|
||||
public double insulin = 0d;
|
||||
@DatabaseField
|
||||
public int durationInMinutes = 0; // duration == 0 means end of extended bolus
|
||||
|
||||
@DatabaseField
|
||||
public int insulinInterfaceID = Insulin.InsulinType.OREF_RAPID_ACTING.getValue();
|
||||
|
||||
@DatabaseField
|
||||
public double dia = Constants.defaultDIA;
|
||||
|
||||
@Deprecated
|
||||
public ExtendedBolus() {
|
||||
injector = StaticInjector.Companion.getInstance();
|
||||
injector.androidInjector().inject(this);
|
||||
}
|
||||
|
||||
public ExtendedBolus(HasAndroidInjector injector) {
|
||||
this.injector = injector;
|
||||
injector.androidInjector().inject(this);
|
||||
}
|
||||
|
||||
public ExtendedBolus(HasAndroidInjector injector, long date) {
|
||||
this(injector);
|
||||
this.date = date;
|
||||
}
|
||||
|
||||
public ExtendedBolus date(long date) {
|
||||
this.date = date;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExtendedBolus insulin(double insulin) {
|
||||
this.insulin = insulin;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExtendedBolus pumpId(long pumpId) {
|
||||
this.pumpId = pumpId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExtendedBolus source(int source) {
|
||||
this.source = source;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExtendedBolus durationInMinutes(int durationInMinutes) {
|
||||
this.durationInMinutes = durationInMinutes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public ExtendedBolus _id(String _id) {
|
||||
this._id = _id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isEqual(ExtendedBolus other) {
|
||||
if (date != other.date) {
|
||||
return false;
|
||||
}
|
||||
if (durationInMinutes != other.durationInMinutes)
|
||||
return false;
|
||||
if (insulin != other.insulin)
|
||||
return false;
|
||||
if (pumpId != other.pumpId)
|
||||
return false;
|
||||
if (!Objects.equals(_id, other._id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void copyFrom(ExtendedBolus t) {
|
||||
date = t.date;
|
||||
_id = t._id;
|
||||
durationInMinutes = t.durationInMinutes;
|
||||
insulin = t.insulin;
|
||||
pumpId = t.pumpId;
|
||||
}
|
||||
|
||||
public static ExtendedBolus createFromJson(HasAndroidInjector injector, JSONObject json) {
|
||||
ExtendedBolus extendedBolus = new ExtendedBolus(injector)
|
||||
.source(Source.NIGHTSCOUT)
|
||||
.date(JsonHelper.safeGetLong(json, "mills"))
|
||||
.durationInMinutes(JsonHelper.safeGetInt(json, "duration"))
|
||||
.insulin(JsonHelper.safeGetDouble(json, "relative") / 60 * JsonHelper.safeGetInt(json, "duration"))
|
||||
._id(JsonHelper.safeGetString(json, "_id"))
|
||||
.pumpId(JsonHelper.safeGetLong(json, "pumpId"));
|
||||
return extendedBolus;
|
||||
}
|
||||
// -------- Interval interface ---------
|
||||
|
||||
Long cuttedEnd = null;
|
||||
|
||||
public long durationInMsec() {
|
||||
return durationInMinutes * 60 * 1000L;
|
||||
}
|
||||
|
||||
public long start() {
|
||||
return date;
|
||||
}
|
||||
|
||||
// planned end time at time of creation
|
||||
public long originalEnd() {
|
||||
return date + durationInMinutes * 60 * 1000L;
|
||||
}
|
||||
|
||||
// end time after cut
|
||||
public long end() {
|
||||
if (cuttedEnd != null)
|
||||
return cuttedEnd;
|
||||
return originalEnd();
|
||||
}
|
||||
|
||||
public void cutEndTo(long end) {
|
||||
cuttedEnd = end;
|
||||
}
|
||||
|
||||
public boolean match(long time) {
|
||||
if (start() <= time && end() >= time)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean before(long time) {
|
||||
if (end() < time)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean after(long time) {
|
||||
if (start() > time)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInProgress() {
|
||||
return match(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEndingEvent() {
|
||||
return durationInMinutes == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------- Interval interface end ---------
|
||||
|
||||
public String log() {
|
||||
return "ExtendedBolus{" +
|
||||
"date= " + date +
|
||||
", date= " + dateUtil.dateAndTimeString(date) +
|
||||
", isValid=" + isValid +
|
||||
", _id= " + _id +
|
||||
", pumpId= " + pumpId +
|
||||
", insulin= " + insulin +
|
||||
", durationInMinutes= " + durationInMinutes +
|
||||
"}";
|
||||
}
|
||||
|
||||
public double absoluteRate() {
|
||||
return Round.roundTo(insulin / durationInMinutes * 60, 0.01);
|
||||
}
|
||||
|
||||
public double insulinSoFar() {
|
||||
return absoluteRate() * getRealDuration() / 60d;
|
||||
}
|
||||
|
||||
public int getRealDuration() {
|
||||
return getDurationToTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
private int getDurationToTime(long time) {
|
||||
long endTime = Math.min(time, end());
|
||||
long msecs = endTime - date;
|
||||
return Math.round(msecs / 60f / 1000);
|
||||
}
|
||||
|
||||
public int getPlannedRemainingMinutes() {
|
||||
float remainingMin = (end() - System.currentTimeMillis()) / 1000f / 60;
|
||||
return (remainingMin < 0) ? 0 : Math.round(remainingMin);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "E " + DecimalFormatter.INSTANCE.to2Decimal(absoluteRate()) + "U/h @" +
|
||||
dateUtil.timeString(date) +
|
||||
" " + getRealDuration() + "/" + durationInMinutes + "min";
|
||||
}
|
||||
|
||||
public String toStringMedium() {
|
||||
return DecimalFormatter.INSTANCE.to2Decimal(absoluteRate()) + "U/h "
|
||||
+ getRealDuration() + "/" + durationInMinutes + "'";
|
||||
}
|
||||
|
||||
public String toStringTotal() {
|
||||
return DecimalFormatter.INSTANCE.to2Decimal(insulin) + "U ( " +
|
||||
DecimalFormatter.INSTANCE.to2Decimal(absoluteRate()) + " U/h )";
|
||||
}
|
||||
|
||||
// -------- DataPointWithLabelInterface --------
|
||||
@Override
|
||||
public double getX() {
|
||||
return date;
|
||||
}
|
||||
|
||||
// default when no sgv around available
|
||||
private double yValue = 0;
|
||||
|
||||
|
||||
@Override
|
||||
public double getY() {
|
||||
return yValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setY(double y) {
|
||||
yValue = y;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
return toStringTotal();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDuration() {
|
||||
return durationInMinutes * 60 * 1000L;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PointsWithLabelGraphSeries.Shape getShape() {
|
||||
return PointsWithLabelGraphSeries.Shape.EXTENDEDBOLUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSize() {
|
||||
return 10;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
return Color.CYAN;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package info.nightscout.androidaps.db;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
@DatabaseTable(tableName = "InsightBolusIDs")
|
||||
public class InsightBolusID {
|
||||
|
||||
@DatabaseField(generatedId = true)
|
||||
public Long id;
|
||||
|
||||
@DatabaseField
|
||||
public String pumpSerial;
|
||||
|
||||
@DatabaseField
|
||||
public Long timestamp;
|
||||
|
||||
@DatabaseField
|
||||
public Integer bolusID;
|
||||
|
||||
@DatabaseField
|
||||
public Long startID;
|
||||
|
||||
@DatabaseField
|
||||
public Long endID;
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package info.nightscout.androidaps.db;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
@DatabaseTable(tableName = "InsightHistoryOffsets")
|
||||
public class InsightHistoryOffset {
|
||||
|
||||
@DatabaseField(id = true, canBeNull = false)
|
||||
public String pumpSerial;
|
||||
|
||||
@DatabaseField
|
||||
public long offset;
|
||||
}
|
|
@ -1,24 +0,0 @@
|
|||
package info.nightscout.androidaps.db;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
@DatabaseTable(tableName = "InsightPumpIDs")
|
||||
public class InsightPumpID {
|
||||
|
||||
@DatabaseField(generatedId = true)
|
||||
public Long id;
|
||||
|
||||
@DatabaseField
|
||||
public long timestamp;
|
||||
|
||||
@DatabaseField
|
||||
public String eventType;
|
||||
|
||||
@DatabaseField
|
||||
public String pumpSerial;
|
||||
|
||||
@DatabaseField
|
||||
public long eventID;
|
||||
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package info.nightscout.androidaps.db
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField
|
||||
import com.j256.ormlite.table.DatabaseTable
|
||||
|
||||
@DatabaseTable(tableName = "OpenHumansQueue")
|
||||
data class OHQueueItem @JvmOverloads constructor(
|
||||
@DatabaseField(generatedId = true)
|
||||
val id: Long = 0,
|
||||
@DatabaseField
|
||||
val file: String = "",
|
||||
@DatabaseField
|
||||
val content: String = ""
|
||||
)
|
|
@ -1,24 +0,0 @@
|
|||
package info.nightscout.androidaps.db;
|
||||
|
||||
/**
|
||||
* Created by mike on 21.05.2017.
|
||||
*/
|
||||
|
||||
public class Source {
|
||||
public final static int NONE = 0;
|
||||
public final static int PUMP = 1; // Pump history
|
||||
public final static int NIGHTSCOUT = 2; // created in NS
|
||||
public final static int USER = 3; // created by user or driver not using history
|
||||
|
||||
public static String getString(int source) {
|
||||
switch (source) {
|
||||
case PUMP:
|
||||
return "PUMP";
|
||||
case NIGHTSCOUT:
|
||||
return "NIGHTSCOUT";
|
||||
case USER:
|
||||
return "USER";
|
||||
}
|
||||
return "NONE";
|
||||
}
|
||||
}
|
|
@ -1,370 +0,0 @@
|
|||
package info.nightscout.androidaps.db;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin;
|
||||
import info.nightscout.androidaps.interfaces.Interval;
|
||||
import info.nightscout.androidaps.interfaces.Profile;
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.sharedPreferences.SP;
|
||||
|
||||
/**
|
||||
* Created by mike on 21.05.2017.
|
||||
*/
|
||||
|
||||
@Deprecated
|
||||
@DatabaseTable(tableName = "TemporaryBasals")
|
||||
public class TemporaryBasal implements Interval {
|
||||
|
||||
@Inject public AAPSLogger aapsLogger;
|
||||
@Inject public ProfileFunction profileFunction;
|
||||
@Inject public ActivePlugin activePlugin;
|
||||
@Inject public SP sp;
|
||||
@Inject public DateUtil dateUtil;
|
||||
|
||||
private HasAndroidInjector injector;
|
||||
|
||||
@DatabaseField(id = true)
|
||||
public long date;
|
||||
|
||||
@DatabaseField
|
||||
public boolean isValid = true;
|
||||
|
||||
@DatabaseField(index = true)
|
||||
public long pumpId = 0;
|
||||
|
||||
@DatabaseField
|
||||
public int source = Source.NONE;
|
||||
@DatabaseField
|
||||
public String _id = null; // NS _id
|
||||
|
||||
@DatabaseField
|
||||
public int durationInMinutes = 0; // duration == 0 means end of temp basal
|
||||
@DatabaseField
|
||||
public boolean isAbsolute = false;
|
||||
|
||||
public boolean isFakeExtended = false;
|
||||
|
||||
@DatabaseField
|
||||
public int percentRate = 0;
|
||||
@DatabaseField
|
||||
public double absoluteRate = 0d;
|
||||
|
||||
public double netExtendedRate = 0d;
|
||||
|
||||
@Deprecated
|
||||
public TemporaryBasal() {
|
||||
injector = StaticInjector.Companion.getInstance();
|
||||
injector.androidInjector().inject(this);
|
||||
}
|
||||
|
||||
public TemporaryBasal(HasAndroidInjector injector) {
|
||||
this.injector = injector;
|
||||
injector.androidInjector().inject(this);
|
||||
}
|
||||
|
||||
public TemporaryBasal date(long date) {
|
||||
this.date = date;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TemporaryBasal duration(int durationInMinutes) {
|
||||
this.durationInMinutes = durationInMinutes;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TemporaryBasal absolute(double absoluteRate) {
|
||||
this.absoluteRate = absoluteRate;
|
||||
this.isAbsolute = true;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TemporaryBasal percent(int percentRate) {
|
||||
this.percentRate = percentRate;
|
||||
this.isAbsolute = false;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TemporaryBasal source(int source) {
|
||||
this.source = source;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TemporaryBasal pumpId(long pumpId) {
|
||||
this.pumpId = pumpId;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TemporaryBasal(ExtendedBolus extendedBolus) {
|
||||
injector = StaticInjector.Companion.getInstance();
|
||||
injector.androidInjector().inject(this);
|
||||
double basal = profileFunction.getProfile(extendedBolus.date).getBasal(extendedBolus.date);
|
||||
this.date = extendedBolus.date;
|
||||
this.isValid = extendedBolus.isValid;
|
||||
this.source = extendedBolus.source;
|
||||
this._id = extendedBolus._id;
|
||||
this.durationInMinutes = extendedBolus.durationInMinutes;
|
||||
this.isAbsolute = true;
|
||||
this.isFakeExtended = true;
|
||||
this.netExtendedRate = extendedBolus.absoluteRate();
|
||||
this.absoluteRate = basal + extendedBolus.absoluteRate();
|
||||
this.pumpId = extendedBolus.pumpId;
|
||||
}
|
||||
|
||||
public TemporaryBasal clone() {
|
||||
TemporaryBasal t = new TemporaryBasal(injector);
|
||||
t.date = date;
|
||||
t.isValid = isValid;
|
||||
t.source = source;
|
||||
t._id = _id;
|
||||
t.pumpId = pumpId;
|
||||
t.durationInMinutes = durationInMinutes;
|
||||
t.isAbsolute = isAbsolute;
|
||||
t.percentRate = percentRate;
|
||||
t.absoluteRate = absoluteRate;
|
||||
return t;
|
||||
}
|
||||
|
||||
public boolean isEqual(TemporaryBasal other) {
|
||||
if (date != other.date) {
|
||||
return false;
|
||||
}
|
||||
if (durationInMinutes != other.durationInMinutes)
|
||||
return false;
|
||||
if (isAbsolute != other.isAbsolute)
|
||||
return false;
|
||||
if (percentRate != other.percentRate)
|
||||
return false;
|
||||
if (absoluteRate != other.absoluteRate)
|
||||
return false;
|
||||
if (netExtendedRate != other.netExtendedRate)
|
||||
return false;
|
||||
if (isFakeExtended != other.isFakeExtended)
|
||||
return false;
|
||||
if (pumpId != other.pumpId)
|
||||
return false;
|
||||
if (!Objects.equals(_id, other._id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public void copyFrom(TemporaryBasal t) {
|
||||
date = t.date;
|
||||
_id = t._id;
|
||||
durationInMinutes = t.durationInMinutes;
|
||||
isAbsolute = t.isAbsolute;
|
||||
percentRate = t.percentRate;
|
||||
absoluteRate = t.absoluteRate;
|
||||
pumpId = t.pumpId;
|
||||
isFakeExtended = t.isFakeExtended;
|
||||
netExtendedRate = t.netExtendedRate;
|
||||
}
|
||||
|
||||
public void copyFromPump(TemporaryBasal t) {
|
||||
durationInMinutes = t.durationInMinutes;
|
||||
isAbsolute = t.isAbsolute;
|
||||
percentRate = t.percentRate;
|
||||
absoluteRate = t.absoluteRate;
|
||||
pumpId = t.pumpId;
|
||||
}
|
||||
|
||||
// -------- Interval interface ---------
|
||||
|
||||
Long cuttedEnd = null;
|
||||
|
||||
public long durationInMsec() {
|
||||
return durationInMinutes * 60 * 1000L;
|
||||
}
|
||||
|
||||
public long start() {
|
||||
return date;
|
||||
}
|
||||
|
||||
// planned end time at time of creation
|
||||
public long originalEnd() {
|
||||
return date + durationInMinutes * 60 * 1000L;
|
||||
}
|
||||
|
||||
// end time after cut
|
||||
public long end() {
|
||||
if (cuttedEnd != null)
|
||||
return cuttedEnd;
|
||||
return originalEnd();
|
||||
}
|
||||
|
||||
public void cutEndTo(long end) {
|
||||
cuttedEnd = end;
|
||||
}
|
||||
|
||||
public boolean match(long time) {
|
||||
if (start() <= time && end() >= time)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean before(long time) {
|
||||
if (end() < time)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean after(long time) {
|
||||
if (start() > time)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isInProgress() {
|
||||
return match(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEndingEvent() {
|
||||
return durationInMinutes == 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isValid() {
|
||||
return true;
|
||||
}
|
||||
|
||||
// -------- Interval interface end ---------
|
||||
|
||||
public int getRealDuration() {
|
||||
return getDurationToTime(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
private int getDurationToTime(long time) {
|
||||
long endTime = Math.min(time, end());
|
||||
long msecs = endTime - date;
|
||||
return Math.round(msecs / 60f / 1000);
|
||||
}
|
||||
|
||||
public int getPlannedRemainingMinutes() {
|
||||
float remainingMin = (end() - System.currentTimeMillis()) / 1000f / 60;
|
||||
return (remainingMin < 0) ? 0 : Math.round(remainingMin);
|
||||
}
|
||||
|
||||
public int getPlannedRemainingMinutesRoundedUp() {
|
||||
float remainingMin = (end() - System.currentTimeMillis()) / 1000f / 60;
|
||||
return (remainingMin < 0) ? 0 : (int) Math.ceil(remainingMin);
|
||||
}
|
||||
|
||||
|
||||
public double tempBasalConvertedToAbsolute(long time, Profile profile) {
|
||||
if (isFakeExtended) {
|
||||
return profile.getBasal(time) + netExtendedRate;
|
||||
} else if (isAbsolute) {
|
||||
return absoluteRate;
|
||||
} else {
|
||||
return profile.getBasal(time) * percentRate / 100;
|
||||
}
|
||||
}
|
||||
|
||||
public int tempBasalConvertedToPercent(long time, Profile profile) {
|
||||
if (isFakeExtended) {
|
||||
return (int) ((profile.getBasal(time) + netExtendedRate) / profile.getBasal(time)) * 100;
|
||||
} else if (isAbsolute) {
|
||||
return (int) (absoluteRate / profile.getBasal(time) * 100);
|
||||
} else {
|
||||
return percentRate;
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "TemporaryBasal{" +
|
||||
"date=" + date +
|
||||
", date=" + dateUtil.dateAndTimeString(date) +
|
||||
", isValid=" + isValid +
|
||||
", pumpId=" + pumpId +
|
||||
", _id=" + _id +
|
||||
", percentRate=" + percentRate +
|
||||
", absoluteRate=" + absoluteRate +
|
||||
", durationInMinutes=" + durationInMinutes +
|
||||
", isAbsolute=" + isAbsolute +
|
||||
", isFakeExtended=" + isFakeExtended +
|
||||
", netExtendedRate=" + netExtendedRate +
|
||||
'}';
|
||||
}
|
||||
|
||||
public String toStringFull() {
|
||||
if (isFakeExtended) {
|
||||
|
||||
Profile profile = profileFunction.getProfile();
|
||||
if (profile == null)
|
||||
return "null";
|
||||
Double currentBasalRate = profile.getBasal();
|
||||
double rate = currentBasalRate + netExtendedRate;
|
||||
return DecimalFormatter.INSTANCE.to2Decimal(rate) + "U/h (" + DecimalFormatter.INSTANCE.to2Decimal(netExtendedRate) + "E) @" +
|
||||
dateUtil.timeString(date) +
|
||||
" " + getRealDuration() + "/" + durationInMinutes + "'";
|
||||
} else if (isAbsolute) {
|
||||
return DecimalFormatter.INSTANCE.to2Decimal(absoluteRate) + "U/h @" +
|
||||
dateUtil.timeString(date) +
|
||||
" " + getRealDuration() + "/" + durationInMinutes + "'";
|
||||
} else { // percent
|
||||
return percentRate + "% @" +
|
||||
dateUtil.timeString(date) +
|
||||
" " + getRealDuration() + "/" + durationInMinutes + "'";
|
||||
}
|
||||
}
|
||||
|
||||
public String toStringShort() {
|
||||
if (isAbsolute || isFakeExtended) {
|
||||
|
||||
double rate;
|
||||
if (isFakeExtended) {
|
||||
Profile profile = profileFunction.getProfile();
|
||||
if (profile == null)
|
||||
return "null";
|
||||
double currentBasalRate = profile.getBasal();
|
||||
rate = currentBasalRate + netExtendedRate;
|
||||
} else {
|
||||
rate = absoluteRate;
|
||||
}
|
||||
|
||||
return DecimalFormatter.INSTANCE.to2Decimal(rate) + "U/h";
|
||||
} else { // percent
|
||||
return percentRate + "%";
|
||||
}
|
||||
}
|
||||
|
||||
public String toStringVeryShort() {
|
||||
Profile profile = profileFunction.getProfile();
|
||||
|
||||
if (profile == null)
|
||||
return "null";
|
||||
|
||||
if (isAbsolute || isFakeExtended) {
|
||||
|
||||
double rate;
|
||||
if (isFakeExtended) {
|
||||
double currentBasalRate = profile.getBasal();
|
||||
rate = currentBasalRate + netExtendedRate;
|
||||
} else {
|
||||
rate = absoluteRate;
|
||||
}
|
||||
return DecimalFormatter.INSTANCE.to2Decimal(rate) + "U/h";
|
||||
} else { // percent
|
||||
return percentRate + "%";
|
||||
}
|
||||
}
|
||||
|
||||
public long getDate() {
|
||||
return this.date;
|
||||
}
|
||||
|
||||
public long getPumpId() {
|
||||
return this.pumpId;
|
||||
}
|
||||
}
|
|
@ -1,280 +0,0 @@
|
|||
package info.nightscout.androidaps.db;
|
||||
|
||||
import android.graphics.Color;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.j256.ormlite.field.DatabaseField;
|
||||
import com.j256.ormlite.table.DatabaseTable;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.core.R;
|
||||
import info.nightscout.androidaps.database.entities.Bolus;
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin;
|
||||
import info.nightscout.androidaps.interfaces.Insulin;
|
||||
import info.nightscout.androidaps.interfaces.Profile;
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction;
|
||||
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.DataPointWithLabelInterface;
|
||||
import info.nightscout.androidaps.plugins.general.overview.graphExtensions.PointsWithLabelGraphSeries;
|
||||
import info.nightscout.androidaps.utils.DateUtil;
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter;
|
||||
import info.nightscout.androidaps.utils.DefaultValueHelper;
|
||||
import info.nightscout.androidaps.utils.JsonHelper;
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper;
|
||||
|
||||
@Deprecated
|
||||
@DatabaseTable(tableName = Treatment.TABLE_TREATMENTS)
|
||||
public class Treatment implements DataPointWithLabelInterface {
|
||||
@Inject public DefaultValueHelper defaultValueHelper;
|
||||
@Inject public ResourceHelper resourceHelper;
|
||||
@Inject public ProfileFunction profileFunction;
|
||||
@Inject public ActivePlugin activePlugin;
|
||||
@Inject public DateUtil dateUtil;
|
||||
|
||||
public static final String TABLE_TREATMENTS = "Treatments";
|
||||
|
||||
@DatabaseField(id = true)
|
||||
public long date;
|
||||
|
||||
@DatabaseField
|
||||
public boolean isValid = true;
|
||||
|
||||
@DatabaseField(index = true)
|
||||
public long pumpId = 0;
|
||||
|
||||
@DatabaseField
|
||||
public int source = Source.NONE;
|
||||
@DatabaseField
|
||||
public String _id;
|
||||
|
||||
@DatabaseField
|
||||
public double insulin = 0d;
|
||||
@DatabaseField
|
||||
public double carbs = 0d;
|
||||
@DatabaseField
|
||||
public boolean mealBolus = true; // true for meal bolus , false for correction bolus
|
||||
@DatabaseField
|
||||
public boolean isSMB = false;
|
||||
|
||||
@DatabaseField
|
||||
public int insulinInterfaceID = Insulin.InsulinType.OREF_RAPID_ACTING.getValue(); // currently unused, will be used in the future
|
||||
@DatabaseField
|
||||
public double dia = Constants.defaultDIA; // currently unused, will be used in the future
|
||||
@DatabaseField
|
||||
public String boluscalc;
|
||||
|
||||
public Treatment() {
|
||||
StaticInjector.Companion.getInstance().androidInjector().inject(this); // TODO it will be removed by new database
|
||||
}
|
||||
|
||||
public Treatment(HasAndroidInjector injector) {
|
||||
injector.androidInjector().inject(this);
|
||||
}
|
||||
|
||||
public Treatment(HasAndroidInjector injector, Bolus bolus) {
|
||||
this(injector);
|
||||
date = bolus.getTimestamp();
|
||||
isValid = bolus.isValid();
|
||||
pumpId = (bolus.getInterfaceIDs().getPumpId() != null) ? bolus.getInterfaceIDs().getPumpId() : 0;
|
||||
source = (bolus.getInterfaceIDs().getPumpId() != null) ? Source.PUMP : Source.USER;
|
||||
_id = bolus.getInterfaceIDs().getNightscoutId();
|
||||
insulin = bolus.getAmount();
|
||||
isSMB = bolus.getType() == Bolus.Type.SMB;
|
||||
}
|
||||
|
||||
@NonNull public String toString() {
|
||||
return "Treatment{" +
|
||||
"date= " + date +
|
||||
", date= " + dateUtil.dateAndTimeString(date) +
|
||||
", isValid= " + isValid +
|
||||
", isSMB= " + isSMB +
|
||||
", _id= " + _id +
|
||||
", pumpId= " + pumpId +
|
||||
", insulin= " + insulin +
|
||||
", carbs= " + carbs +
|
||||
", mealBolus= " + mealBolus +
|
||||
", source= " + source +
|
||||
"}";
|
||||
}
|
||||
|
||||
public boolean isDataChanging(Treatment other) {
|
||||
if (date != other.date)
|
||||
return true;
|
||||
if (!isSame(insulin, other.insulin))
|
||||
return true;
|
||||
if (!isSame(carbs, other.carbs))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isEqual(Treatment other) {
|
||||
if (date != other.date)
|
||||
return false;
|
||||
if (!isSame(insulin, other.insulin))
|
||||
return false;
|
||||
if (!isSame(carbs, other.carbs))
|
||||
return false;
|
||||
if (mealBolus != other.mealBolus)
|
||||
return false;
|
||||
if (pumpId != other.pumpId)
|
||||
return false;
|
||||
if (isSMB != other.isSMB)
|
||||
return false;
|
||||
if (!Objects.equals(_id, other._id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isEqualWithoutPumpId(Treatment other) {
|
||||
if (date != other.date)
|
||||
return false;
|
||||
if (!isSame(insulin, other.insulin))
|
||||
return false;
|
||||
if (!isSame(carbs, other.carbs))
|
||||
return false;
|
||||
if (mealBolus != other.mealBolus)
|
||||
return false;
|
||||
if (isSMB != other.isSMB)
|
||||
return false;
|
||||
if (!Objects.equals(_id, other._id))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean isSame(Double d1, Double d2) {
|
||||
double diff = d1 - d2;
|
||||
|
||||
return (Math.abs(diff) <= 0.000001);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JSONObject getBoluscalc() {
|
||||
try {
|
||||
if (boluscalc != null)
|
||||
return new JSONObject(boluscalc);
|
||||
} catch (JSONException ignored) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public double getIc() {
|
||||
JSONObject bw = getBoluscalc();
|
||||
if (bw == null || !bw.has("ic")) {
|
||||
Profile profile = profileFunction.getProfile(date);
|
||||
return profile.getIc(date);
|
||||
}
|
||||
return JsonHelper.safeGetDouble(bw, "ic");
|
||||
}
|
||||
|
||||
/*
|
||||
* mealBolus, _id and isSMB cannot be known coming from pump. Only compare rest
|
||||
* TODO: remove debug toasts
|
||||
*/
|
||||
public boolean equalsRePumpHistory(Treatment other) {
|
||||
if (date != other.date) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!isSame(insulin, other.insulin))
|
||||
return false;
|
||||
|
||||
if (!isSame(carbs, other.carbs))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void copyFrom(Treatment t) {
|
||||
date = t.date;
|
||||
_id = t._id;
|
||||
insulin = t.insulin;
|
||||
carbs = t.carbs;
|
||||
mealBolus = t.mealBolus;
|
||||
pumpId = t.pumpId;
|
||||
isSMB = t.isSMB;
|
||||
}
|
||||
|
||||
public void copyBasics(Treatment t) {
|
||||
date = t.date;
|
||||
insulin = t.insulin;
|
||||
carbs = t.carbs;
|
||||
pumpId = t.pumpId;
|
||||
source = t.source;
|
||||
}
|
||||
|
||||
// ----------------- DataPointInterface --------------------
|
||||
@Override
|
||||
public double getX() {
|
||||
return date;
|
||||
}
|
||||
|
||||
// default when no sgv around available
|
||||
private double yValue = 0;
|
||||
|
||||
@Override
|
||||
public double getY() {
|
||||
return isSMB ? defaultValueHelper.determineLowLine() : yValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getLabel() {
|
||||
String label = "";
|
||||
if (insulin > 0)
|
||||
label += DecimalFormatter.INSTANCE.toPumpSupportedBolus(insulin, activePlugin.getActivePump(), resourceHelper);
|
||||
if (carbs > 0)
|
||||
label += "~" + resourceHelper.gs(R.string.format_carbs, (int) carbs);
|
||||
return label;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getDuration() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PointsWithLabelGraphSeries.Shape getShape() {
|
||||
if (isSMB)
|
||||
return PointsWithLabelGraphSeries.Shape.SMB;
|
||||
else
|
||||
return PointsWithLabelGraphSeries.Shape.BOLUS;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSize() {
|
||||
return 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getColor() {
|
||||
if (isSMB)
|
||||
return resourceHelper.gc(R.color.tempbasal);
|
||||
else if (isValid)
|
||||
return Color.CYAN;
|
||||
else
|
||||
return resourceHelper.gc(android.R.color.holo_red_light);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setY(double y) {
|
||||
yValue = y;
|
||||
}
|
||||
|
||||
// ----------------- DataPointInterface end --------------------
|
||||
|
||||
public long getDate() {
|
||||
return this.date;
|
||||
}
|
||||
|
||||
public long getPumpId() {
|
||||
return this.pumpId;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package info.nightscout.androidaps.db
|
||||
package info.nightscout.androidaps.di
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
|
@ -40,11 +40,6 @@ interface ActivePlugin {
|
|||
*/
|
||||
val activeSensitivity: Sensitivity
|
||||
|
||||
/**
|
||||
* Currently selected Treatments plugin
|
||||
*/
|
||||
val activeTreatments: TreatmentsInterface
|
||||
|
||||
/**
|
||||
* Currently selected Overview plugin
|
||||
* Always OverviewPlugin
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
package info.nightscout.androidaps.interfaces
|
||||
|
||||
import info.nightscout.androidaps.db.*
|
||||
|
||||
interface DatabaseHelperInterface {
|
||||
|
||||
fun resetDatabases()
|
||||
|
||||
fun createOrUpdate(record: OmnipodHistoryRecord)
|
||||
fun createOrUpdate(record: OHQueueItem)
|
||||
fun delete(extendedBolus: ExtendedBolus)
|
||||
fun createOrUpdate(tempBasal: TemporaryBasal): Boolean
|
||||
@Deprecated("Use new DB")
|
||||
fun findTempBasalByPumpId(id: Long): TemporaryBasal?
|
||||
@Deprecated("Use new DB")
|
||||
fun getTemporaryBasalsDataFromTime(mills: Long, ascending: Boolean): List<TemporaryBasal>
|
||||
fun getAllOmnipodHistoryRecordsFromTimestamp(timestamp: Long, ascending: Boolean): List<OmnipodHistoryRecord>
|
||||
fun findOmnipodHistoryRecordByPumpId(pumpId: Long): OmnipodHistoryRecord?
|
||||
@Deprecated("Use new DB")
|
||||
fun getExtendedBolusByPumpId(pumpId: Long): ExtendedBolus?
|
||||
fun getAllOHQueueItems(maxEntries: Long): List<OHQueueItem>
|
||||
|
||||
// old DB model
|
||||
|
||||
fun getOHQueueSize(): Long
|
||||
fun clearOpenHumansQueue()
|
||||
fun removeAllOHQueueItemsWithIdSmallerThan(id: Long)
|
||||
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package info.nightscout.androidaps.interfaces
|
||||
|
||||
interface Interval {
|
||||
|
||||
fun durationInMsec(): Long
|
||||
fun start(): Long
|
||||
|
||||
// planned end time at time of creation
|
||||
fun originalEnd(): Long
|
||||
|
||||
// end time after cut
|
||||
fun end(): Long
|
||||
fun cutEndTo(end: Long)
|
||||
fun match(time: Long): Boolean
|
||||
fun before(time: Long): Boolean
|
||||
fun after(time: Long): Boolean
|
||||
val isInProgress: Boolean
|
||||
val isEndingEvent: Boolean
|
||||
val isValid: Boolean
|
||||
}
|
|
@ -6,5 +6,5 @@ package info.nightscout.androidaps.interfaces
|
|||
* set by [info.nightscout.androidaps.interfaces.PluginDescription.mainType]
|
||||
*/
|
||||
enum class PluginType {
|
||||
GENERAL, TREATMENT, SENSITIVITY, PROFILE, APS, PUMP, CONSTRAINTS, LOOP, BGSOURCE, INSULIN
|
||||
GENERAL, SENSITIVITY, PROFILE, APS, PUMP, CONSTRAINTS, LOOP, BGSOURCE, INSULIN
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package info.nightscout.androidaps.interfaces
|
||||
|
||||
import info.nightscout.androidaps.db.Treatment
|
||||
|
||||
interface TreatmentServiceInterface {
|
||||
|
||||
fun createOrUpdateMedtronic(treatment: Treatment, fromNightScout: Boolean): UpdateReturn
|
||||
fun createOrUpdate(treatment: Treatment): UpdateReturn
|
||||
}
|
|
@ -1,29 +0,0 @@
|
|||
package info.nightscout.androidaps.interfaces;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||
import info.nightscout.androidaps.db.Treatment;
|
||||
import info.nightscout.androidaps.plugins.treatments.TreatmentUpdateReturn;
|
||||
|
||||
/**
|
||||
* Created by mike on 14.06.2016.
|
||||
*/
|
||||
public interface TreatmentsInterface {
|
||||
|
||||
TreatmentServiceInterface getService();
|
||||
|
||||
@Deprecated
|
||||
List<Treatment> getTreatmentsFromHistoryAfterTimestamp(long timestamp);
|
||||
|
||||
boolean addToHistoryTempBasal(TemporaryBasal tempBasal);
|
||||
|
||||
boolean addToHistoryExtendedBolus(ExtendedBolus extendedBolus);
|
||||
|
||||
boolean addToHistoryTreatment(DetailedBolusInfo detailedBolusInfo, boolean allowUpdate);
|
||||
|
||||
TreatmentUpdateReturn createOrUpdateMedtronic(Treatment treatment, boolean fromNightScout);
|
||||
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package info.nightscout.androidaps.interfaces
|
||||
|
||||
class UpdateReturn(var success: Boolean, var newRecord: Boolean) {
|
||||
|
||||
override fun toString(): String {
|
||||
return "UpdateReturn [" +
|
||||
"newRecord=" + newRecord +
|
||||
", success=" + success +
|
||||
']'
|
||||
}
|
||||
}
|
|
@ -4,7 +4,11 @@ import dagger.android.AndroidInjector
|
|||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.data.ProfileSealed
|
||||
import info.nightscout.androidaps.extensions.pureProfileFromJson
|
||||
import info.nightscout.androidaps.interfaces.*
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.Config
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.interfaces.ProfileFunction
|
||||
import info.nightscout.androidaps.interfaces.ProfileStore
|
||||
import info.nightscout.androidaps.plugins.bus.RxBusWrapper
|
||||
import info.nightscout.androidaps.utils.DateUtil
|
||||
import info.nightscout.androidaps.utils.DefaultValueHelper
|
||||
|
@ -21,7 +25,6 @@ open class TestBaseWithProfile : TestBase() {
|
|||
|
||||
@Mock lateinit var activePluginProvider: ActivePlugin
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var treatmentsInterface: TreatmentsInterface
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||
|
|
|
@ -1,55 +0,0 @@
|
|||
package info.nightscout.androidaps.data
|
||||
|
||||
import dagger.android.AndroidInjector
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.TestBase
|
||||
import info.nightscout.androidaps.db.TemporaryBasal
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
class NonOverlappingIntervalsTest : TestBase() {
|
||||
|
||||
private val startDate = System.currentTimeMillis()
|
||||
var list = NonOverlappingIntervals<TemporaryBasal>()
|
||||
|
||||
val injector = HasAndroidInjector { AndroidInjector {} }
|
||||
|
||||
@Test
|
||||
fun doTests() {
|
||||
// create one 10h interval and test value in and out
|
||||
list.add(TemporaryBasal(injector).date(startDate).duration(T.hours(10).mins().toInt()).absolute(1.0))
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()))
|
||||
Assert.assertEquals(1.0, list.getValueByInterval(startDate)!!.absoluteRate, 0.01)
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1))
|
||||
|
||||
// stop temp after 5h
|
||||
list.add(TemporaryBasal(injector).date(startDate + T.hours(5).msecs()).duration(0))
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()))
|
||||
Assert.assertEquals(1.0, list.getValueByInterval(startDate)!!.absoluteRate, 0.01)
|
||||
Assert.assertEquals(1.0, list.getValueByInterval(startDate + T.hours(5).msecs() - 1)!!.absoluteRate, 0.01)
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1))
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1))
|
||||
|
||||
// insert 1h interval inside
|
||||
list.add(TemporaryBasal(injector).date(startDate + T.hours(3).msecs()).duration(T.hours(1).mins().toInt()).absolute(2.0))
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()))
|
||||
Assert.assertEquals(1.0, list.getValueByInterval(startDate)!!.absoluteRate, 0.01)
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() - 1))
|
||||
Assert.assertEquals(2.0, list.getValueByInterval(startDate + T.hours(3).msecs())!!.absoluteRate, 0.01)
|
||||
Assert.assertEquals(2.0, list.getValueByInterval(startDate + T.hours(4).msecs() - 1)!!.absoluteRate, 0.01)
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(4).msecs() + 1))
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCopyConstructor() {
|
||||
list.reset()
|
||||
list.add(TemporaryBasal(injector).date(startDate).duration(T.hours(10).mins().toInt()).absolute(1.0))
|
||||
val list2 = NonOverlappingIntervals(list)
|
||||
Assert.assertEquals(1, list2.list.size.toLong())
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package info.nightscout.androidaps.data
|
||||
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import org.junit.Assert
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
import java.util.*
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
class OverlappingIntervalsTest {
|
||||
|
||||
private val startDate = System.currentTimeMillis()
|
||||
private var list = OverlappingIntervals<TempTargetTest>()
|
||||
@Test fun doTests() {
|
||||
// create one 10h interval and test value in and out
|
||||
list.add(TempTargetTest().date(startDate).duration(T.hours(10).mins()).low(100.0).high(100.0))
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()))
|
||||
Assert.assertEquals(100.0, list.getValueByInterval(startDate)!!.target(), 0.01)
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1))
|
||||
|
||||
// stop temp target after 5h
|
||||
list.add(TempTargetTest().date(startDate + T.hours(5).msecs()).duration(0))
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()))
|
||||
Assert.assertEquals(100.0, list.getValueByInterval(startDate)!!.target(), 0.01)
|
||||
Assert.assertEquals(100.0, list.getValueByInterval(startDate + T.hours(5).msecs() - 1)!!.target(), 0.01)
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1))
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1))
|
||||
|
||||
// insert 1h interval inside
|
||||
list.add(TempTargetTest().date(startDate + T.hours(3).msecs()).duration(T.hours(1).mins()).low(200.0).high(200.0))
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate - T.secs(1).msecs()))
|
||||
Assert.assertEquals(100.0, list.getValueByInterval(startDate)!!.target(), 0.01)
|
||||
Assert.assertEquals(100.0, list.getValueByInterval(startDate + T.hours(5).msecs() - 1)!!.target(), 0.01)
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(5).msecs() + 1))
|
||||
Assert.assertEquals(200.0, list.getValueByInterval(startDate + T.hours(3).msecs())!!.target(), 0.01)
|
||||
Assert.assertEquals(100.0, list.getValueByInterval(startDate + T.hours(4).msecs() + 1)!!.target(), 0.01)
|
||||
Assert.assertEquals(null, list.getValueByInterval(startDate + T.hours(10).msecs() + 1))
|
||||
}
|
||||
|
||||
@Test fun testCopyConstructor() {
|
||||
list.reset()
|
||||
list.add(TempTargetTest().date(startDate).duration(T.hours(10).mins()).low(100.0).high(100.0))
|
||||
val list2 = OverlappingIntervals(list)
|
||||
Assert.assertEquals(1, list2.list.size.toLong())
|
||||
}
|
||||
|
||||
@Test fun testReversingArrays() {
|
||||
val someList: MutableList<TempTargetTest> = ArrayList()
|
||||
someList.add(TempTargetTest().date(startDate).duration(T.hours(3).mins()).low(200.0).high(200.0))
|
||||
someList.add(TempTargetTest().date(startDate + T.hours(1).msecs()).duration(T.hours(1).mins()).low(100.0).high(100.0))
|
||||
list.reset()
|
||||
list.add(someList)
|
||||
Assert.assertEquals(startDate, list[0]?.data?.timestamp)
|
||||
Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversed(0).data.timestamp)
|
||||
Assert.assertEquals(startDate + T.hours(1).msecs(), list.reversedList[0].data.timestamp)
|
||||
}
|
||||
}
|
|
@ -1,82 +0,0 @@
|
|||
package info.nightscout.androidaps.data
|
||||
|
||||
import info.nightscout.androidaps.TestBaseWithProfile
|
||||
import info.nightscout.androidaps.TestPumpPlugin
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import org.junit.Assert
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
import org.mockito.Mockito.`when`
|
||||
import org.powermock.modules.junit4.PowerMockRunner
|
||||
import java.util.*
|
||||
|
||||
@RunWith(PowerMockRunner::class)
|
||||
class ProfileIntervalsTest : TestBaseWithProfile() {
|
||||
@Test
|
||||
fun fake() {}
|
||||
/*
|
||||
lateinit var testPumpPlugin: TestPumpPlugin
|
||||
private val startDate = System.currentTimeMillis()
|
||||
var list = ProfileIntervals<ProfileSwitch>()
|
||||
|
||||
@Before
|
||||
fun mock() {
|
||||
testPumpPlugin = TestPumpPlugin(profileInjector)
|
||||
`when`(activePluginProvider.activePump).thenReturn(testPumpPlugin)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun doTests() {
|
||||
// create one 10h interval and test value in and out
|
||||
list.add(ProfileSwitch(profileInjector).date(startDate).duration(T.hours(10).mins().toInt()).profileName("1").profile(validProfile))
|
||||
// for older date first record should be returned only if has zero duration
|
||||
Assert.assertEquals(null, list.getValueToTime(startDate - T.secs(1).msecs()))
|
||||
Assert.assertEquals("1", (list.getValueToTime(startDate) as ProfileSwitch).profileName)
|
||||
Assert.assertEquals(null, list.getValueToTime(startDate + T.hours(10).msecs() + 1))
|
||||
list.reset()
|
||||
list.add(ProfileSwitch(profileInjector).date(startDate).profileName("1").profile(validProfile))
|
||||
Assert.assertEquals("1", (list.getValueToTime(startDate - T.secs(1).msecs()) as ProfileSwitch?)!!.profileName)
|
||||
Assert.assertEquals("1", (list.getValueToTime(startDate) as ProfileSwitch).profileName)
|
||||
Assert.assertEquals("1", (list.getValueToTime(startDate + T.hours(10).msecs() + 1) as ProfileSwitch?)!!.profileName)
|
||||
|
||||
// switch to different profile after 5h
|
||||
list.add(ProfileSwitch(profileInjector).date(startDate + T.hours(5).msecs()).duration(0).profileName("2").profile(validProfile))
|
||||
Assert.assertEquals("1", (list.getValueToTime(startDate - T.secs(1).msecs()) as ProfileSwitch?)!!.profileName)
|
||||
Assert.assertEquals("1", (list.getValueToTime(startDate + T.hours(5).msecs() - 1) as ProfileSwitch?)!!.profileName)
|
||||
Assert.assertEquals("2", (list.getValueToTime(startDate + T.hours(5).msecs() + 1) as ProfileSwitch?)!!.profileName)
|
||||
|
||||
// insert 1h interval inside
|
||||
list.add(ProfileSwitch(profileInjector).date(startDate + T.hours(6).msecs()).duration(T.hours(1).mins().toInt()).profileName("3").profile(validProfile))
|
||||
Assert.assertEquals("2", (list.getValueToTime(startDate + T.hours(6).msecs() - 1) as ProfileSwitch?)!!.profileName)
|
||||
Assert.assertEquals("3", (list.getValueToTime(startDate + T.hours(6).msecs() + 1) as ProfileSwitch?)!!.profileName)
|
||||
Assert.assertEquals("2", (list.getValueToTime(startDate + T.hours(7).msecs() + 1) as ProfileSwitch?)!!.profileName)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testCopyConstructor() {
|
||||
list.reset()
|
||||
list.add(ProfileSwitch(profileInjector).date(startDate).duration(T.hours(10).mins().toInt()).profileName("4").profile(validProfile))
|
||||
val list2 = ProfileIntervals(list)
|
||||
Assert.assertEquals(1, list2.list.size.toLong())
|
||||
}
|
||||
|
||||
@Test fun invalidProfilesShouldNotBeReturned() {
|
||||
list.reset()
|
||||
list.add(ProfileSwitch(profileInjector).date(startDate + T.hours(1).msecs()).profileName("6"))
|
||||
Assert.assertEquals(null, list[0])
|
||||
}
|
||||
|
||||
@Test fun testReversingArrays() {
|
||||
val someList: MutableList<ProfileSwitch> = ArrayList()
|
||||
someList.add(ProfileSwitch(profileInjector).date(startDate).duration(T.hours(3).mins().toInt()).profileName("5").profile(validProfile))
|
||||
someList.add(ProfileSwitch(profileInjector).date(startDate + T.hours(1).msecs()).duration(T.hours(1).mins().toInt()).profileName("6").profile(validProfile))
|
||||
list.reset()
|
||||
list.add(someList)
|
||||
Assert.assertEquals(startDate, list[0]?.date)
|
||||
Assert.assertEquals(startDate + T.hours(1).msecs(), list.getReversed(0).date)
|
||||
Assert.assertEquals(startDate + T.hours(1).msecs(), list.reversedList[0].date)
|
||||
}
|
||||
|
||||
*/
|
||||
}
|
|
@ -1,86 +0,0 @@
|
|||
package info.nightscout.androidaps.data
|
||||
|
||||
import info.nightscout.androidaps.Constants
|
||||
import info.nightscout.androidaps.core.R
|
||||
import info.nightscout.androidaps.database.entities.TemporaryTarget
|
||||
import info.nightscout.androidaps.database.interfaces.end
|
||||
import info.nightscout.androidaps.interfaces.GlucoseUnit
|
||||
import info.nightscout.androidaps.interfaces.Interval
|
||||
import info.nightscout.androidaps.interfaces.Profile
|
||||
import info.nightscout.androidaps.utils.DecimalFormatter
|
||||
import info.nightscout.androidaps.utils.T
|
||||
import info.nightscout.androidaps.utils.resources.ResourceHelper
|
||||
import java.util.concurrent.TimeUnit
|
||||
|
||||
class TempTargetTest(
|
||||
var data: TemporaryTarget = TemporaryTarget(
|
||||
timestamp = 0,
|
||||
utcOffset = 0,
|
||||
reason = TemporaryTarget.Reason.CUSTOM,
|
||||
highTarget = 0.0,
|
||||
lowTarget = 0.0,
|
||||
duration = 0
|
||||
)
|
||||
) : Interval {
|
||||
|
||||
fun date(timestamp: Long): TempTargetTest {
|
||||
data.timestamp = timestamp
|
||||
return this
|
||||
}
|
||||
|
||||
fun duration(duration: Long): TempTargetTest {
|
||||
data.duration = T.mins(duration).msecs()
|
||||
return this
|
||||
}
|
||||
|
||||
fun low(low: Double): TempTargetTest {
|
||||
data.lowTarget = low
|
||||
return this
|
||||
}
|
||||
|
||||
fun high(high: Double): TempTargetTest {
|
||||
data.highTarget = high
|
||||
return this
|
||||
}
|
||||
|
||||
fun target(): Double {
|
||||
return (data.lowTarget + data.highTarget) / 2
|
||||
}
|
||||
|
||||
// -------- Interval interface ---------
|
||||
|
||||
private var cuttedEnd: Long? = null
|
||||
|
||||
override fun durationInMsec(): Long = data.duration
|
||||
override fun start(): Long = data.timestamp
|
||||
override fun originalEnd(): Long = data.end // planned end time at time of creation
|
||||
override fun end(): Long = cuttedEnd ?: originalEnd() // end time after cut
|
||||
override fun cutEndTo(end: Long) {
|
||||
cuttedEnd = end
|
||||
}
|
||||
|
||||
override fun match(time: Long): Boolean = start() <= time && end() >= time
|
||||
override fun before(time: Long): Boolean = end() < time
|
||||
override fun after(time: Long): Boolean = start() > time
|
||||
override val isInProgress: Boolean get() = match(System.currentTimeMillis())
|
||||
override val isEndingEvent: Boolean get() = data.duration == 0L
|
||||
override val isValid: Boolean get() = true
|
||||
|
||||
// -------- Interval interface end ---------
|
||||
/*
|
||||
fun lowValueToUnitsToString(units: String): String =
|
||||
if (units == Constants.MGDL) DecimalFormatter.to0Decimal(data.lowTarget)
|
||||
else DecimalFormatter.to1Decimal(data.lowTarget * Constants.MGDL_TO_MMOLL)
|
||||
|
||||
fun highValueToUnitsToString(units: String): String =
|
||||
if (units == Constants.MGDL) DecimalFormatter.to0Decimal(data.highTarget)
|
||||
else DecimalFormatter.to1Decimal(data.highTarget * Constants.MGDL_TO_MMOLL)
|
||||
|
||||
override fun toString(): String = data.toString()
|
||||
|
||||
fun friendlyDescription(units: String, resourceHelper: ResourceHelper): String =
|
||||
Profile.toTargetRangeString(data.lowTarget, data.highTarget, GlucoseUnit.MGDL, units) +
|
||||
units +
|
||||
"@" + resourceHelper.gs(R.string.format_mins, TimeUnit.MILLISECONDS.toMinutes(data.duration)) + "(" + data.reason.text + ")"
|
||||
*/
|
||||
}
|
|
@ -21,7 +21,6 @@ open class TestBaseWithProfile : TestBase() {
|
|||
|
||||
@Mock lateinit var activePluginProvider: ActivePlugin
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var treatmentsInterface: TreatmentsInterface
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||
|
|
|
@ -21,7 +21,6 @@ import info.nightscout.androidaps.danar.DanaRPlugin;
|
|||
import info.nightscout.androidaps.interfaces.ActivePlugin;
|
||||
import info.nightscout.androidaps.interfaces.CommandQueueProvider;
|
||||
import info.nightscout.androidaps.interfaces.ConfigBuilder;
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||
import info.nightscout.androidaps.interfaces.PumpSync;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
|
|
|
@ -21,7 +21,6 @@ open class TestBaseWithProfile : TestBase() {
|
|||
|
||||
@Mock lateinit var activePluginProvider: ActivePlugin
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var treatmentsInterface: TreatmentsInterface
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||
|
|
|
@ -21,7 +21,6 @@ open class TestBaseWithProfile : TestBase() {
|
|||
|
||||
@Mock lateinit var activePluginProvider: ActivePlugin
|
||||
@Mock lateinit var resourceHelper: ResourceHelper
|
||||
@Mock lateinit var treatmentsInterface: TreatmentsInterface
|
||||
@Mock lateinit var fabricPrivacy: FabricPrivacy
|
||||
@Mock lateinit var profileFunction: ProfileFunction
|
||||
@Mock lateinit var defaultValueHelper: DefaultValueHelper
|
||||
|
|
|
@ -852,7 +852,7 @@ class MedtronicPumpPlugin @Inject constructor(
|
|||
|
||||
//aapsLogger.debug(LTag.PUMP, "HST: Target Date: " + targetDate);
|
||||
val responseTask2 = rileyLinkMedtronicService.medtronicUIComm.executeCommand(MedtronicCommandType.GetHistoryData,
|
||||
arrayListOf(/*lastPumpHistoryEntry*/ null, targetDate) as ArrayList<Any>?)
|
||||
arrayListOf(/*lastPumpHistoryEntry*/ null, targetDate) as? ArrayList<Any>?)
|
||||
if (debugHistory) aapsLogger.debug(LTag.PUMP, "HST: After task")
|
||||
val historyResult = responseTask2.result as PumpHistoryResult?
|
||||
if (debugHistory) aapsLogger.debug(LTag.PUMP, "HST: History Result: " + historyResult.toString())
|
||||
|
|
|
@ -4,9 +4,7 @@ import com.google.gson.Gson
|
|||
import com.google.gson.GsonBuilder
|
||||
import dagger.android.HasAndroidInjector
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo
|
||||
import info.nightscout.androidaps.db.*
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface
|
||||
import info.nightscout.androidaps.interfaces.PumpSync
|
||||
import info.nightscout.androidaps.logging.AAPSLogger
|
||||
import info.nightscout.androidaps.logging.LTag
|
||||
|
@ -49,7 +47,6 @@ class MedtronicHistoryData @Inject constructor(
|
|||
val medtronicUtil: MedtronicUtil,
|
||||
val medtronicPumpHistoryDecoder: MedtronicPumpHistoryDecoder,
|
||||
val medtronicPumpStatus: MedtronicPumpStatus,
|
||||
val databaseHelper: DatabaseHelperInterface,
|
||||
val pumpSync: PumpSync,
|
||||
val pumpSyncStorage: info.nightscout.androidaps.plugins.pump.common.sync.PumpSyncStorage
|
||||
) {
|
||||
|
@ -81,7 +78,7 @@ class MedtronicHistoryData @Inject constructor(
|
|||
if (entryByPumpId != null && entryByPumpId.hasBolusChanged(validEntry)) {
|
||||
newEntries.add(validEntry)
|
||||
allHistory.remove(entryByPumpId)
|
||||
allPumpIds.remove(validEntry.pumpId);
|
||||
allPumpIds.remove(validEntry.pumpId)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -479,11 +476,11 @@ class MedtronicHistoryData @Inject constructor(
|
|||
|
||||
if (bolusDTO.bolusType == PumpBolusType.Extended) {
|
||||
addExtendedBolus(bolus, bolusDTO, multiwave)
|
||||
continue;
|
||||
continue
|
||||
} else if (bolusDTO.bolusType == PumpBolusType.Multiwave) {
|
||||
multiwave = true
|
||||
aapsLogger.debug(LTag.PUMP, String.format(Locale.ENGLISH, "Multiwave bolus from pump, extended bolus and normal bolus will be added."))
|
||||
addExtendedBolus(bolus, bolusDTO, multiwave);
|
||||
addExtendedBolus(bolus, bolusDTO, multiwave)
|
||||
}
|
||||
|
||||
val deliveredAmount: Double = if (multiwave) bolusDTO.immediateAmount!! else bolusDTO.deliveredAmount
|
||||
|
|
|
@ -648,10 +648,12 @@ public class OmnipodErosPumpPlugin extends PumpPluginBase implements Pump, Riley
|
|||
return deliverBolus(detailedBolusInfo);
|
||||
} else {
|
||||
// no bolus required, carb only treatment
|
||||
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
|
||||
// activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, true);
|
||||
|
||||
return new PumpEnactResult(getInjector()).success(true).enacted(true).bolusDelivered(0d)
|
||||
.carbsDelivered(detailedBolusInfo.carbs);
|
||||
// return new PumpEnactResult(getInjector()).success(true).enacted(true).bolusDelivered(0d)
|
||||
// .carbsDelivered(detailedBolusInfo.carbs);
|
||||
// Needs refactor
|
||||
throw new IllegalStateException("Not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -16,14 +16,13 @@ import javax.inject.Singleton;
|
|||
import dagger.android.HasAndroidInjector;
|
||||
import info.nightscout.androidaps.activities.ErrorHelperActivity;
|
||||
import info.nightscout.androidaps.data.DetailedBolusInfo;
|
||||
import info.nightscout.androidaps.interfaces.Profile;
|
||||
import info.nightscout.androidaps.data.PumpEnactResult;
|
||||
import info.nightscout.androidaps.db.OmnipodHistoryRecord;
|
||||
import info.nightscout.androidaps.events.Event;
|
||||
import info.nightscout.androidaps.events.EventRefreshOverview;
|
||||
import info.nightscout.androidaps.extensions.PumpStateExtensionKt;
|
||||
import info.nightscout.androidaps.interfaces.ActivePlugin;
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||
import info.nightscout.androidaps.interfaces.Profile;
|
||||
import info.nightscout.androidaps.interfaces.PumpSync;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
|
@ -97,7 +96,6 @@ public class AapsOmnipodErosManager {
|
|||
private final ActivePlugin activePlugin;
|
||||
private final SP sp;
|
||||
private final OmnipodManager delegate;
|
||||
private final DatabaseHelperInterface databaseHelper;
|
||||
private final OmnipodAlertUtil omnipodAlertUtil;
|
||||
private final Context context;
|
||||
private final PumpSync pumpSync;
|
||||
|
@ -128,7 +126,6 @@ public class AapsOmnipodErosManager {
|
|||
ResourceHelper resourceHelper,
|
||||
HasAndroidInjector injector,
|
||||
ActivePlugin activePlugin,
|
||||
DatabaseHelperInterface databaseHelper,
|
||||
OmnipodAlertUtil omnipodAlertUtil,
|
||||
Context context,
|
||||
PumpSync pumpSync) {
|
||||
|
@ -141,7 +138,6 @@ public class AapsOmnipodErosManager {
|
|||
this.resourceHelper = resourceHelper;
|
||||
this.injector = injector;
|
||||
this.activePlugin = activePlugin;
|
||||
this.databaseHelper = databaseHelper;
|
||||
this.omnipodAlertUtil = omnipodAlertUtil;
|
||||
this.context = context;
|
||||
this.pumpSync = pumpSync;
|
||||
|
@ -704,13 +700,15 @@ public class AapsOmnipodErosManager {
|
|||
carbInfo.setCarbsTimestamp(detailedBolusInfo.getCarbsTimestamp());
|
||||
carbInfo.carbs = detailedBolusInfo.carbs;
|
||||
carbInfo.setPumpType(PumpType.USER);
|
||||
activePlugin.getActiveTreatments().addToHistoryTreatment(carbInfo, false);
|
||||
|
||||
// activePlugin.getActiveTreatments().addToHistoryTreatment(carbInfo, false);
|
||||
// Needs refactor
|
||||
// remove carbs from bolusInfo to not trigger any unwanted code paths in
|
||||
// TreatmentsPlugin.addToHistoryTreatment() method
|
||||
detailedBolusInfo.carbs = 0;
|
||||
}
|
||||
activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false);
|
||||
// activePlugin.getActiveTreatments().addToHistoryTreatment(detailedBolusInfo, false);
|
||||
// Needs refactor
|
||||
throw new IllegalStateException("Not implemented");
|
||||
}
|
||||
|
||||
public synchronized void createSuspendedFakeTbrIfNotExists() {
|
||||
|
@ -749,8 +747,9 @@ public class AapsOmnipodErosManager {
|
|||
public boolean hasSuspendedFakeTbr() {
|
||||
PumpSync.PumpState pumpState = pumpSync.expectedPumpState();
|
||||
if (pumpState.getTemporaryBasal() != null && pumpState.getTemporaryBasal().getPumpId() != null) {
|
||||
OmnipodHistoryRecord historyRecord = databaseHelper.findOmnipodHistoryRecordByPumpId(pumpState.getTemporaryBasal().getPumpId());
|
||||
return historyRecord != null && PodHistoryEntryType.getByCode(historyRecord.getPodEntryTypeCode()).equals(PodHistoryEntryType.SET_FAKE_SUSPENDED_TEMPORARY_BASAL);
|
||||
// OmnipodHistoryRecord historyRecord = databaseHelper.findOmnipodHistoryRecordByPumpId(pumpState.getTemporaryBasal().getPumpId());
|
||||
// return historyRecord != null && PodHistoryEntryType.getByCode(historyRecord.getPodEntryTypeCode()).equals(PodHistoryEntryType.SET_FAKE_SUSPENDED_TEMPORARY_BASAL);
|
||||
throw new IllegalStateException("Not implemented");
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
@ -853,9 +852,9 @@ public class AapsOmnipodErosManager {
|
|||
omnipodHistoryRecord.setSuccess(success);
|
||||
omnipodHistoryRecord.setPodSerial(podStateManager.hasPodState() ? String.valueOf(podStateManager.getAddress()) : "None");
|
||||
|
||||
databaseHelper.createOrUpdate(omnipodHistoryRecord);
|
||||
|
||||
return omnipodHistoryRecord.getPumpId();
|
||||
// databaseHelper.createOrUpdate(omnipodHistoryRecord);
|
||||
// return omnipodHistoryRecord.getPumpId();
|
||||
throw new IllegalStateException("Not implemented");
|
||||
}
|
||||
|
||||
private void executeCommand(Runnable runnable) {
|
||||
|
|
|
@ -9,7 +9,6 @@ import org.apache.commons.lang3.StringUtils;
|
|||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpDeviceState;
|
||||
import info.nightscout.androidaps.plugins.pump.common.hw.rileylink.RileyLinkCommunicationManager;
|
||||
|
@ -37,7 +36,6 @@ public class RileyLinkOmnipodService extends RileyLinkService {
|
|||
@Inject OmnipodErosPumpPlugin omnipodErosPumpPlugin;
|
||||
@Inject AapsOmnipodUtil aapsOmnipodUtil;
|
||||
@Inject PodStateManager podStateManager;
|
||||
@Inject DatabaseHelperInterface databaseHelper;
|
||||
@Inject AapsOmnipodErosManager aapsOmnipodErosManager;
|
||||
@Inject OmnipodRileyLinkCommunicationManager omnipodRileyLinkCommunicationManager;
|
||||
|
||||
|
|
|
@ -10,11 +10,10 @@ import android.widget.ArrayAdapter;
|
|||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
|
@ -24,14 +23,13 @@ import java.util.List;
|
|||
import javax.inject.Inject;
|
||||
|
||||
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity;
|
||||
import info.nightscout.androidaps.interfaces.Profile;
|
||||
import info.nightscout.androidaps.db.OmnipodHistoryRecord;
|
||||
import info.nightscout.androidaps.interfaces.DatabaseHelperInterface;
|
||||
import info.nightscout.androidaps.interfaces.Profile;
|
||||
import info.nightscout.androidaps.logging.AAPSLogger;
|
||||
import info.nightscout.androidaps.logging.LTag;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.TempBasalPair;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpHistoryEntryGroup;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.PumpType;
|
||||
import info.nightscout.androidaps.plugins.pump.common.defs.TempBasalPair;
|
||||
import info.nightscout.androidaps.plugins.pump.common.utils.ProfileUtil;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.R;
|
||||
import info.nightscout.androidaps.plugins.pump.omnipod.eros.definition.PodHistoryEntryType;
|
||||
|
@ -43,7 +41,6 @@ public class ErosPodHistoryActivity extends NoSplashAppCompatActivity {
|
|||
@Inject AAPSLogger aapsLogger;
|
||||
@Inject AapsOmnipodUtil aapsOmnipodUtil;
|
||||
@Inject ResourceHelper resourceHelper;
|
||||
@Inject DatabaseHelperInterface databaseHelper;
|
||||
|
||||
private Spinner historyTypeSpinner;
|
||||
private TextView statusView;
|
||||
|
@ -69,9 +66,9 @@ public class ErosPodHistoryActivity extends NoSplashAppCompatActivity {
|
|||
GregorianCalendar gc = new GregorianCalendar();
|
||||
gc.add(Calendar.HOUR_OF_DAY, -24);
|
||||
|
||||
databaseHelper.getAllOmnipodHistoryRecordsFromTimestamp(gc.getTimeInMillis(), false);
|
||||
|
||||
fullHistoryList.addAll(databaseHelper.getAllOmnipodHistoryRecordsFromTimestamp(gc.getTimeInMillis(), true));
|
||||
// databaseHelper.getAllOmnipodHistoryRecordsFromTimestamp(gc.getTimeInMillis(), false);
|
||||
// fullHistoryList.addAll(databaseHelper.getAllOmnipodHistoryRecordsFromTimestamp(gc.getTimeInMillis(), true));
|
||||
throw new IllegalStateException("Not implemented");
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue