From c7f6eb79f04ec52914a4776d63ed3b9006f25c8e Mon Sep 17 00:00:00 2001 From: Andy Rozman Date: Fri, 12 Apr 2019 21:20:09 +0100 Subject: [PATCH] - fixes for Bolus problems --- app/build.gradle | 2 +- .../activities/PreferencesActivity.java | 53 +-- .../androidaps/db/DatabaseHelper.java | 356 ++++++------------ .../pump/MedtronicPumpHistoryDecoder.java | 76 ++-- .../medtronic/data/MedtronicHistoryData.java | 24 +- .../pump/medtronic/data/dto/BolusDTO.java | 28 +- .../plugins/treatments/Treatment.java | 26 +- 7 files changed, 210 insertions(+), 355 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index a3bdbe891b..45ca9219ba 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -65,7 +65,7 @@ android { multiDexEnabled true versionCode 1500 // dev_version: 2.2.3-dev - version "medtronic-0.9.2-SNAPSHOT" + version "medtronic-0.9.3-SNAPSHOT" buildConfigField "String", "VERSION", '"' + version + '"' buildConfigField "String", "BUILDVERSION", '"' + generateGitBuild() + '-' + generateDate() + '"' buildConfigField "String", "HEAD", '"' + generateGitBuild() + '"' diff --git a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java index 97df05142c..51428f52e0 100644 --- a/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java +++ b/app/src/main/java/info/nightscout/androidaps/activities/PreferencesActivity.java @@ -19,17 +19,14 @@ import info.nightscout.androidaps.events.EventPreferenceChange; import info.nightscout.androidaps.events.EventRefreshGui; import info.nightscout.androidaps.interfaces.PluginBase; import info.nightscout.androidaps.interfaces.PluginType; +import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin; +import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin; +import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin; import info.nightscout.androidaps.plugins.aps.loop.LoopPlugin; +import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin; import info.nightscout.androidaps.plugins.aps.openAPSAMA.OpenAPSAMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSMA.OpenAPSMAPlugin; import info.nightscout.androidaps.plugins.aps.openAPSSMB.OpenAPSSMBPlugin; -import info.nightscout.androidaps.plugins.constraints.safety.SafetyPlugin; -import info.nightscout.androidaps.plugins.general.careportal.CareportalPlugin; -import info.nightscout.androidaps.plugins.general.nsclient.NSClientPlugin; -import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin; -import info.nightscout.androidaps.plugins.general.wear.WearPlugin; -import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin; -import info.nightscout.androidaps.plugins.insulin.InsulinOrefFreePeakPlugin; import info.nightscout.androidaps.plugins.pump.combo.ComboPlugin; import info.nightscout.androidaps.plugins.pump.danaR.DanaRPlugin; import info.nightscout.androidaps.plugins.pump.danaRKorean.DanaRKoreanPlugin; @@ -42,16 +39,17 @@ import info.nightscout.androidaps.plugins.sensitivity.SensitivityAAPSPlugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref0Plugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityOref1Plugin; import info.nightscout.androidaps.plugins.sensitivity.SensitivityWeightedAveragePlugin; +import info.nightscout.androidaps.plugins.general.smsCommunicator.SmsCommunicatorPlugin; import info.nightscout.androidaps.plugins.source.SourceDexcomG5Plugin; +import info.nightscout.androidaps.plugins.general.wear.WearPlugin; +import info.nightscout.androidaps.plugins.general.xdripStatusline.StatuslinePlugin; import info.nightscout.androidaps.utils.LocaleHelper; import info.nightscout.androidaps.utils.OKDialog; import info.nightscout.androidaps.utils.SP; public class PreferencesActivity extends PreferenceActivity implements SharedPreferences.OnSharedPreferenceChangeListener { - MyPreferenceFragment myPreferenceFragment; - @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -63,7 +61,6 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); } - @Override public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { MainApp.bus().post(new EventPreferenceChange(key)); @@ -71,21 +68,18 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre String lang = sharedPreferences.getString("language", "en"); LocaleHelper.setLocale(getApplicationContext(), lang); MainApp.bus().post(new EventRefreshGui(true)); - // recreate() does not update language so better close settings + //recreate() does not update language so better close settings finish(); } if (key.equals("short_tabtitles")) { MainApp.bus().post(new EventRefreshGui()); } - if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens)) - && SP.getBoolean(R.string.key_openapsama_useautosens, false)) { - OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity), - MainApp.gs(R.string.sensitivity_warning), null); + if (key.equals(MainApp.gs(R.string.key_openapsama_useautosens)) && SP.getBoolean(R.string.key_openapsama_useautosens, false)) { + OKDialog.show(this, MainApp.gs(R.string.configbuilder_sensitivity), MainApp.gs(R.string.sensitivity_warning), null); } updatePrefSummary(myPreferenceFragment.getPreference(key)); } - private static void updatePrefSummary(Preference pref) { if (pref instanceof ListPreference) { ListPreference listPref = (ListPreference) pref; @@ -100,14 +94,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre } else if (editTextPref.getText() != null) { ((EditTextPreference) pref).setDialogMessage(editTextPref.getDialogMessage()); pref.setSummary(editTextPref.getText()); - } else if (pref.getKey().contains("smscommunicator_allowednumbers") - && TextUtils.isEmpty(editTextPref.getText().trim())) { + } else if (pref.getKey().contains("smscommunicator_allowednumbers") && TextUtils.isEmpty(editTextPref.getText().trim())) { pref.setSummary(MainApp.gs(R.string.smscommunicator_allowednumbers_summary)); } } } - public static void initSummary(Preference p) { if (p instanceof PreferenceGroup) { PreferenceGroup pGrp = (PreferenceGroup) p; @@ -120,23 +112,19 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre } public static class MyPreferenceFragment extends PreferenceFragment { - private Integer id; - @Override public void setArguments(Bundle args) { super.setArguments(args); id = args.getInt("id"); } - void addPreferencesFromResourceIfEnabled(PluginBase p, PluginType type) { if (p.isEnabled(type) && p.getPreferencesId() != -1) addPreferencesFromResource(p.getPreferencesId()); } - @Override public void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -168,8 +156,7 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre } addPreferencesFromResourceIfEnabled(SensitivityAAPSPlugin.getPlugin(), PluginType.SENSITIVITY); - addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), - PluginType.SENSITIVITY); + addPreferencesFromResourceIfEnabled(SensitivityWeightedAveragePlugin.getPlugin(), PluginType.SENSITIVITY); addPreferencesFromResourceIfEnabled(SensitivityOref0Plugin.getPlugin(), PluginType.SENSITIVITY); addPreferencesFromResourceIfEnabled(SensitivityOref1Plugin.getPlugin(), PluginType.SENSITIVITY); @@ -207,16 +194,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre } if (Config.NSCLIENT) { - PreferenceScreen scrnAdvancedSettings = (PreferenceScreen) findPreference(getString(R.string.key_advancedsettings)); + PreferenceScreen scrnAdvancedSettings = (PreferenceScreen)findPreference(getString(R.string.key_advancedsettings)); if (scrnAdvancedSettings != null) { - scrnAdvancedSettings - .removePreference(getPreference(getString(R.string.key_statuslights_res_warning))); - scrnAdvancedSettings - .removePreference(getPreference(getString(R.string.key_statuslights_res_critical))); - scrnAdvancedSettings - .removePreference(getPreference(getString(R.string.key_statuslights_bat_warning))); - scrnAdvancedSettings - .removePreference(getPreference(getString(R.string.key_statuslights_bat_critical))); + scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_res_warning))); + scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_res_critical))); + scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_warning))); + scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_statuslights_bat_critical))); scrnAdvancedSettings.removePreference(getPreference(getString(R.string.key_show_statuslights))); } } @@ -224,14 +207,12 @@ public class PreferencesActivity extends PreferenceActivity implements SharedPre initSummary(getPreferenceScreen()); } - @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); outState.putInt("id", id); } - public Preference getPreference(String key) { return findPreference(key); } diff --git a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java index 0d57a547ea..8bcf767afb 100644 --- a/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java +++ b/app/src/main/java/info/nightscout/androidaps/db/DatabaseHelper.java @@ -4,7 +4,6 @@ import android.content.Context; import android.database.DatabaseUtils; import android.database.sqlite.SQLiteDatabase; import android.support.annotation.Nullable; -import android.util.Log; import com.j256.ormlite.android.apptools.OrmLiteSqliteOpenHelper; import com.j256.ormlite.dao.CloseableIterator; @@ -49,9 +48,9 @@ import info.nightscout.androidaps.events.EventTempTargetChange; import info.nightscout.androidaps.interfaces.ProfileInterface; import info.nightscout.androidaps.logging.L; import info.nightscout.androidaps.plugins.configBuilder.ConfigBuilderPlugin; -import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.IobCobCalculatorPlugin; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.events.EventNewHistoryData; +import info.nightscout.androidaps.plugins.general.nsclient.NSUpload; import info.nightscout.androidaps.plugins.pump.danaR.activities.DanaRNSHistorySync; import info.nightscout.androidaps.plugins.pump.danaR.comm.RecordTypes; import info.nightscout.androidaps.plugins.pump.insight.database.InsightBolusID; @@ -66,12 +65,11 @@ import info.nightscout.androidaps.utils.ToastUtils; * 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). *

- * 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. + * 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 { - private static Logger log = LoggerFactory.getLogger(L.DATABASE); public static final String DATABASE_NAME = "AndroidAPSDb"; @@ -107,21 +105,18 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { private static final ScheduledExecutorService careportalEventWorker = Executors.newSingleThreadScheduledExecutor(); private static ScheduledFuture scheduledCareportalEventPost = null; - private static final ScheduledExecutorService profileSwitchEventWorker = Executors - .newSingleThreadScheduledExecutor(); + private static final ScheduledExecutorService profileSwitchEventWorker = Executors.newSingleThreadScheduledExecutor(); private static ScheduledFuture scheduledProfileSwitchEventPost = null; private int oldVersion = 0; private int newVersion = 0; - public DatabaseHelper(Context context) { super(context, DATABASE_NAME, null, DATABASE_VERSION); onCreate(getWritableDatabase(), getConnectionSource()); - // onUpgrade(getWritableDatabase(), getConnectionSource(), 1,1); + //onUpgrade(getWritableDatabase(), getConnectionSource(), 1,1); } - @Override public void onCreate(SQLiteDatabase database, ConnectionSource connectionSource) { try { @@ -145,7 +140,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - @Override public void onUpgrade(SQLiteDatabase database, ConnectionSource connectionSource, int oldVersion, int newVersion) { try { @@ -178,24 +172,20 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - @Override public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) { log.info("Do nothing for downgrading..."); log.debug("oldVersion: {}, newVersion: {}", oldVersion, newVersion); } - public int getOldVersion() { return oldVersion; } - public int getNewVersion() { return newVersion; } - /** * Close the database connections and clear any cached DAOs. */ @@ -209,7 +199,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return DatabaseUtils.queryNumEntries(getReadableDatabase(), database); } - // --------------------- DB resets --------------------- public void resetDatabases() { @@ -243,16 +232,17 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleTemporaryTargetChange(); scheduleCareportalEventChange(); scheduleProfileSwitchChange(); - new java.util.Timer().schedule(new java.util.TimerTask() { - - @Override - public void run() { - MainApp.bus().post(new EventRefreshOverview("resetDatabases")); - } - }, 3000); + new java.util.Timer().schedule( + new java.util.TimerTask() { + @Override + public void run() { + MainApp.bus().post(new EventRefreshOverview("resetDatabases")); + } + }, + 3000 + ); } - public void resetTempTargets() { try { TableUtils.dropTable(connectionSource, TempTarget.class, true); @@ -263,7 +253,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleTemporaryTargetChange(); } - public void resetTemporaryBasals() { try { TableUtils.dropTable(connectionSource, TemporaryBasal.class, true); @@ -276,7 +265,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleTemporaryBasalChange(); } - public void resetExtededBoluses() { try { TableUtils.dropTable(connectionSource, ExtendedBolus.class, true); @@ -288,7 +276,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleExtendedBolusChange(); } - public void resetCareportalEvents() { try { TableUtils.dropTable(connectionSource, CareportalEvent.class, true); @@ -299,7 +286,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleCareportalEventChange(); } - public void resetProfileSwitch() { try { TableUtils.dropTable(connectionSource, ProfileSwitch.class, true); @@ -310,7 +296,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleProfileSwitchChange(); } - public void resetTDDs() { try { TableUtils.dropTable(connectionSource, TDD.class, true); @@ -320,69 +305,56 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - // ------------------ getDao ------------------------------------------- private Dao getDaoTempTargets() throws SQLException { return getDao(TempTarget.class); } - private Dao getDaoBgReadings() throws SQLException { return getDao(BgReading.class); } - private Dao getDaoDanaRHistory() throws SQLException { return getDao(DanaRHistoryRecord.class); } - private Dao getDaoTDD() throws SQLException { return getDao(TDD.class); } - private Dao getDaoDbRequest() throws SQLException { return getDao(DbRequest.class); } - private Dao getDaoTemporaryBasal() throws SQLException { return getDao(TemporaryBasal.class); } - private Dao getDaoExtendedBolus() throws SQLException { return getDao(ExtendedBolus.class); } - private Dao getDaoCareportalEvents() throws SQLException { return getDao(CareportalEvent.class); } - private Dao getDaoProfileSwitch() throws SQLException { return getDao(ProfileSwitch.class); } - private Dao getDaoInsightPumpID() throws SQLException { return getDao(InsightPumpID.class); } - private Dao getDaoInsightBolusID() throws SQLException { return getDao(InsightBolusID.class); } - private Dao getDaoInsightHistoryOffset() throws SQLException { return getDao(InsightHistoryOffset.class); } - public static long roundDateToSec(long date) { long rounded = date - date % 1000; if (rounded != date) @@ -390,9 +362,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { log.debug("Rounding " + date + " to " + rounded); return rounded; } - - - // ------------------- BgReading handling ----------------------- + // ------------------- BgReading handling ----------------------- public boolean createIfNotExists(BgReading bgReading, String from) { try { @@ -421,7 +391,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return false; } - public void update(BgReading bgReading) { bgReading.date = roundDateToSec(bgReading.date); try { @@ -431,14 +400,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - private static void scheduleBgChange(@Nullable final BgReading bgReading) { class PostRunnable implements Runnable { - public void run() { if (L.isEnabled(L.DATABASE)) log.debug("Firing EventNewBg"); - Log.d("DatabaseHelper", "WR: Firing EventNewBg"); MainApp.bus().post(new EventNewBG(bgReading)); scheduledBgPost = null; } @@ -453,7 +419,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } - /* * Return last BgReading from database or null if db is empty */ @@ -470,7 +435,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } - /* * Return bg reading if not old ( <9 min ) * or null if older @@ -506,7 +470,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList<>(); } - public List getBgreadingsDataFromTime(long start, long end, boolean ascending) { try { Dao daoBgreadings = getDaoBgReadings(); @@ -524,7 +487,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList<>(); } - public List getAllBgreadingsDataFromTime(long mills, boolean ascending) { try { Dao daoBgreadings = getDaoBgReadings(); @@ -542,8 +504,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList(); } - - // ------------------- TDD handling ----------------------- + // ------------------- TDD handling ----------------------- public void createOrUpdateTDD(TDD tdd) { try { Dao dao = getDaoTDD(); @@ -554,7 +515,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public List getTDDs() { List tddList; try { @@ -570,8 +530,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return tddList; } - - // FIXME public List getTDDsForLastXDays(int days) { List tddList; GregorianCalendar gc = new GregorianCalendar(); @@ -594,7 +552,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return tddList; } - // ------------- DbRequests handling ------------------- public void create(DbRequest dbr) { @@ -605,7 +562,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public int delete(DbRequest dbr) { try { return getDaoDbRequest().delete(dbr); @@ -615,7 +571,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return 0; } - public int deleteDbRequest(String nsClientId) { try { return getDaoDbRequest().deleteById(nsClientId); @@ -625,7 +580,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return 0; } - public void deleteDbRequestbyMongoId(String action, String id) { try { QueryBuilder queryBuilder = getDaoDbRequest().queryBuilder(); @@ -642,7 +596,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public void deleteAllDbRequests() { try { TableUtils.clearTable(connectionSource, DbRequest.class); @@ -651,7 +604,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public CloseableIterator getDbRequestInterator() { try { return getDaoDbRequest().closeableIterator(); @@ -661,8 +613,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - - // -------------------- TREATMENT HANDLING ------------------- + // -------------------- TREATMENT HANDLING ------------------- public static void updateEarliestDataChange(long newDate) { if (earliestDataChange == null) { @@ -674,7 +625,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - // ---------------- TempTargets handling --------------- public List getTemptargetsDataFromTime(long mills, boolean ascending) { @@ -694,7 +644,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList(); } - public boolean createOrUpdate(TempTarget tempTarget) { try { TempTarget old; @@ -708,8 +657,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { old.copyFrom(tempTarget); getDaoTempTargets().create(old); if (L.isEnabled(L.DATABASE)) - log.debug("TEMPTARGET: Updating record by date from: " - + Source.getString(tempTarget.source) + " " + old.toString()); + log.debug("TEMPTARGET: Updating record by date from: " + Source.getString(tempTarget.source) + " " + old.toString()); scheduleTemporaryTargetChange(); return true; } @@ -729,8 +677,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { old.copyFrom(tempTarget); getDaoTempTargets().create(old); if (L.isEnabled(L.DATABASE)) - log.debug("TEMPTARGET: Updating record by _id from: " - + Source.getString(tempTarget.source) + " " + old.toString()); + log.debug("TEMPTARGET: Updating record by _id from: " + Source.getString(tempTarget.source) + " " + old.toString()); scheduleTemporaryTargetChange(); return true; } @@ -738,16 +685,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } getDaoTempTargets().create(tempTarget); if (L.isEnabled(L.DATABASE)) - log.debug("TEMPTARGET: New record from: " + Source.getString(tempTarget.source) + " " - + tempTarget.toString()); + log.debug("TEMPTARGET: New record from: " + Source.getString(tempTarget.source) + " " + tempTarget.toString()); scheduleTemporaryTargetChange(); return true; } if (tempTarget.source == Source.USER) { getDaoTempTargets().create(tempTarget); if (L.isEnabled(L.DATABASE)) - log.debug("TEMPTARGET: New record from: " + Source.getString(tempTarget.source) + " " - + tempTarget.toString()); + log.debug("TEMPTARGET: New record from: " + Source.getString(tempTarget.source) + " " + tempTarget.toString()); scheduleTemporaryTargetChange(); return true; } @@ -757,7 +702,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return false; } - public void delete(TempTarget tempTarget) { try { getDaoTempTargets().delete(tempTarget); @@ -767,10 +711,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - private static void scheduleTemporaryTargetChange() { class PostRunnable implements Runnable { - public void run() { if (L.isEnabled(L.DATABASE)) log.debug("Firing EventTempTargetChange"); @@ -788,29 +730,31 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } - - /* - * { - * "_id": "58795998aa86647ba4d68ce7", - * "enteredBy": "", - * "eventType": "Temporary Target", - * "reason": "Eating Soon", - * "targetTop": 80, - * "targetBottom": 80, - * "duration": 120, - * "created_at": "2017-01-13T22:50:00.782Z", - * "carbs": null, - * "insulin": null - * } - */ + /* + { + "_id": "58795998aa86647ba4d68ce7", + "enteredBy": "", + "eventType": "Temporary Target", + "reason": "Eating Soon", + "targetTop": 80, + "targetBottom": 80, + "duration": 120, + "created_at": "2017-01-13T22:50:00.782Z", + "carbs": null, + "insulin": null +} + */ public void createTemptargetFromJsonIfNotExists(JSONObject trJson) { try { String units = JsonHelper.safeGetString(trJson, "units", Constants.MGDL); - TempTarget tempTarget = new TempTarget().date(trJson.getLong("mills")).duration(trJson.getInt("duration")) + TempTarget tempTarget = new TempTarget() + .date(trJson.getLong("mills")) + .duration(JsonHelper.safeGetInt(trJson, "duration")) .low(Profile.toMgdl(trJson.getDouble("targetBottom"), units)) .high(Profile.toMgdl(trJson.getDouble("targetTop"), units)) - .reason(JsonHelper.safeGetString(trJson, "reason", ""))._id(trJson.getString("_id")) + .reason(JsonHelper.safeGetString(trJson, "reason", "")) + ._id(trJson.getString("_id")) .source(Source.NIGHTSCOUT); createOrUpdate(tempTarget); } catch (JSONException e) { @@ -818,7 +762,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public void deleteTempTargetById(String _id) { TempTarget stored = findTempTargetById(_id); if (stored != null) { @@ -828,7 +771,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public TempTarget findTempTargetById(String _id) { try { QueryBuilder queryBuilder = getDaoTempTargets().queryBuilder(); @@ -848,14 +790,13 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } - // ----------------- DanaRHistory handling -------------------- public void createOrUpdate(DanaRHistoryRecord record) { try { getDaoDanaRHistory().createOrUpdate(record); - // If it is a TDD, store it for stats also. + //If it is a TDD, store it for stats also. if (record.recordCode == RecordTypes.RECORD_TYPE_DAILY) { createOrUpdateTDD(new TDD(record.recordDate, record.recordDailyBolus, record.recordDailyBasal, 0)); } @@ -865,7 +806,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public List getDanaRHistoryRecordsByType(byte type) { List historyList; try { @@ -883,7 +823,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return historyList; } - public void updateDanaRHistoryRecordId(JSONObject trJson) { try { QueryBuilder queryBuilder = getDaoDanaRHistory().queryBuilder(); @@ -909,10 +848,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - // ------------ TemporaryBasal handling --------------- - // return true if new record was created + //return true if new record was created public boolean createOrUpdate(TemporaryBasal tempBasal) { try { TemporaryBasal old; @@ -928,14 +866,12 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { if (trList.size() > 0) { // do nothing, pump history record cannot be changed if (L.isEnabled(L.DATABASE)) - log.debug("TEMPBASAL: Already exists from: " + Source.getString(tempBasal.source) + " " - + tempBasal.toString()); + log.debug("TEMPBASAL: Already exists from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString()); return false; } getDaoTemporaryBasal().create(tempBasal); if (L.isEnabled(L.DATABASE)) - log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " - + tempBasal.toString()); + log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString()); updateEarliestDataChange(tempBasal.date); scheduleTemporaryBasalChange(); return true; @@ -953,8 +889,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { old.copyFrom(tempBasal); getDaoTemporaryBasal().create(old); if (L.isEnabled(L.DATABASE)) - log.debug("TEMPBASAL: Updating record by date from: " + Source.getString(tempBasal.source) - + " " + old.toString()); + log.debug("TEMPBASAL: Updating record by date from: " + Source.getString(tempBasal.source) + " " + old.toString()); updateEarliestDataChange(oldDate); updateEarliestDataChange(old.date); scheduleTemporaryBasalChange(); @@ -977,8 +912,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { old.copyFrom(tempBasal); getDaoTemporaryBasal().create(old); if (L.isEnabled(L.DATABASE)) - log.debug("TEMPBASAL: Updating record by _id from: " - + Source.getString(tempBasal.source) + " " + old.toString()); + log.debug("TEMPBASAL: Updating record by _id from: " + Source.getString(tempBasal.source) + " " + old.toString()); updateEarliestDataChange(oldDate); updateEarliestDataChange(old.date); scheduleTemporaryBasalChange(); @@ -988,8 +922,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } getDaoTemporaryBasal().create(tempBasal); if (L.isEnabled(L.DATABASE)) - log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " - + tempBasal.toString()); + log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString()); updateEarliestDataChange(tempBasal.date); scheduleTemporaryBasalChange(); return true; @@ -997,8 +930,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { if (tempBasal.source == Source.USER) { getDaoTemporaryBasal().create(tempBasal); if (L.isEnabled(L.DATABASE)) - log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " - + tempBasal.toString()); + log.debug("TEMPBASAL: New record from: " + Source.getString(tempBasal.source) + " " + tempBasal.toString()); updateEarliestDataChange(tempBasal.date); scheduleTemporaryBasalChange(); return true; @@ -1009,7 +941,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return false; } - public void delete(TemporaryBasal tempBasal) { try { getDaoTemporaryBasal().delete(tempBasal); @@ -1020,7 +951,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleTemporaryBasalChange(); } - public List getTemporaryBasalsDataFromTime(long mills, boolean ascending) { try { List tempbasals; @@ -1037,10 +967,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList(); } - private static void scheduleTemporaryBasalChange() { class PostRunnable implements Runnable { - public void run() { if (L.isEnabled(L.DATABASE)) log.debug("Firing EventTempBasalChange"); @@ -1062,29 +990,31 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } - /* - * { - * "_id": "59232e1ddd032d04218dab00", - * "eventType": "Temp Basal", - * "duration": 60, - * "percent": -50, - * "created_at": "2017-05-22T18:29:57Z", - * "enteredBy": "AndroidAPS", - * "notes": "Basal Temp Start 50% 60.0 min", - * "NSCLIENT_ID": 1495477797863, - * "mills": 1495477797000, - * "mgdl": 194.5, - * "endmills": 1495481397000 - * } - */ + { + "_id": "59232e1ddd032d04218dab00", + "eventType": "Temp Basal", + "duration": 60, + "percent": -50, + "created_at": "2017-05-22T18:29:57Z", + "enteredBy": "AndroidAPS", + "notes": "Basal Temp Start 50% 60.0 min", + "NSCLIENT_ID": 1495477797863, + "mills": 1495477797000, + "mgdl": 194.5, + "endmills": 1495481397000 + } + */ public void createTempBasalFromJsonIfNotExists(JSONObject trJson) { try { if (trJson.has("originalExtendedAmount")) { // extended bolus uploaded as temp basal - ExtendedBolus extendedBolus = new ExtendedBolus().source(Source.NIGHTSCOUT) - .date(trJson.getLong("mills")).pumpId(trJson.has("pumpId") ? trJson.getLong("pumpId") : 0) - .durationInMinutes(trJson.getInt("duration")).insulin(trJson.getDouble("originalExtendedAmount")) + ExtendedBolus extendedBolus = new ExtendedBolus() + .source(Source.NIGHTSCOUT) + .date(trJson.getLong("mills")) + .pumpId(trJson.has("pumpId") ? trJson.getLong("pumpId") : 0) + .durationInMinutes(trJson.getInt("duration")) + .insulin(trJson.getDouble("originalExtendedAmount")) ._id(trJson.getString("_id")); // if faking found in NS, adapt AAPS to use it too if (!VirtualPumpPlugin.getPlugin().getFakingStatus()) { @@ -1109,7 +1039,9 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } createOrUpdate(extendedBolus); } else { - TemporaryBasal tempBasal = new TemporaryBasal().date(trJson.getLong("mills")).source(Source.NIGHTSCOUT) + TemporaryBasal tempBasal = new TemporaryBasal() + .date(trJson.getLong("mills")) + .source(Source.NIGHTSCOUT) .pumpId(trJson.has("pumpId") ? trJson.getLong("pumpId") : 0); if (trJson.has("duration")) { tempBasal.durationInMinutes = trJson.getInt("duration"); @@ -1130,7 +1062,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public void deleteTempBasalById(String _id) { TemporaryBasal stored = findTempBasalById(_id); if (stored != null) { @@ -1142,7 +1073,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public TemporaryBasal findTempBasalById(String _id) { try { QueryBuilder queryBuilder = null; @@ -1163,14 +1093,12 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } - // ------------ ExtendedBolus handling --------------- public boolean createOrUpdate(ExtendedBolus extendedBolus) { try { if (L.isEnabled(L.DATABASE)) - log.debug("EXTENDEDBOLUS: createOrUpdate: " + Source.getString(extendedBolus.source) + " " - + extendedBolus.log()); + log.debug("EXTENDEDBOLUS: createOrUpdate: " + Source.getString(extendedBolus.source) + " " + extendedBolus.log()); ExtendedBolus old; extendedBolus.date = roundDateToSec(extendedBolus.date); @@ -1195,8 +1123,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { getDaoExtendedBolus().createOrUpdate(extendedBolus); } if (L.isEnabled(L.DATABASE)) - log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " - + extendedBolus.log()); + log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.log()); updateEarliestDataChange(extendedBolus.date); scheduleExtendedBolusChange(); return true; @@ -1210,8 +1137,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { old.copyFrom(extendedBolus); getDaoExtendedBolus().create(old); if (L.isEnabled(L.DATABASE)) - log.debug("EXTENDEDBOLUS: Updating record by date from: " - + Source.getString(extendedBolus.source) + " " + old.log()); + log.debug("EXTENDEDBOLUS: Updating record by date from: " + Source.getString(extendedBolus.source) + " " + old.log()); updateEarliestDataChange(oldDate); updateEarliestDataChange(old.date); scheduleExtendedBolusChange(); @@ -1234,8 +1160,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { old.copyFrom(extendedBolus); getDaoExtendedBolus().create(old); if (L.isEnabled(L.DATABASE)) - log.debug("EXTENDEDBOLUS: Updating record by _id from: " - + Source.getString(extendedBolus.source) + " " + old.log()); + log.debug("EXTENDEDBOLUS: Updating record by _id from: " + Source.getString(extendedBolus.source) + " " + old.log()); updateEarliestDataChange(oldDate); updateEarliestDataChange(old.date); scheduleExtendedBolusChange(); @@ -1245,8 +1170,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } getDaoExtendedBolus().create(extendedBolus); if (L.isEnabled(L.DATABASE)) - log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " - + extendedBolus.log()); + log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.log()); updateEarliestDataChange(extendedBolus.date); scheduleExtendedBolusChange(); return true; @@ -1254,8 +1178,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { if (extendedBolus.source == Source.USER) { getDaoExtendedBolus().create(extendedBolus); if (L.isEnabled(L.DATABASE)) - log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " - + extendedBolus.log()); + log.debug("EXTENDEDBOLUS: New record from: " + Source.getString(extendedBolus.source) + " " + extendedBolus.log()); updateEarliestDataChange(extendedBolus.date); scheduleExtendedBolusChange(); return true; @@ -1266,17 +1189,17 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return false; } - public ExtendedBolus getExtendedBolusByPumpId(long pumpId) { try { - return getDaoExtendedBolus().queryBuilder().where().eq("pumpId", pumpId).queryForFirst(); + return getDaoExtendedBolus().queryBuilder() + .where().eq("pumpId", pumpId) + .queryForFirst(); } catch (SQLException e) { log.error("Unhandled exception", e); } return null; } - public void delete(ExtendedBolus extendedBolus) { try { getDaoExtendedBolus().delete(extendedBolus); @@ -1287,7 +1210,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleExtendedBolusChange(); } - public List getExtendedBolusDataFromTime(long mills, boolean ascending) { try { List extendedBoluses; @@ -1304,7 +1226,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList(); } - public void deleteExtendedBolusById(String _id) { ExtendedBolus stored = findExtendedBolusById(_id); if (stored != null) { @@ -1316,7 +1237,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public ExtendedBolus findExtendedBolusById(String _id) { try { QueryBuilder queryBuilder = null; @@ -1337,22 +1257,21 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } - /* - * { - * "_id": "5924898d577eb0880e355337", - * "eventType": "Combo Bolus", - * "duration": 120, - * "splitNow": 0, - * "splitExt": 100, - * "enteredinsulin": 1, - * "relative": 1, - * "created_at": "2017-05-23T19:12:14Z", - * "enteredBy": "AndroidAPS", - * "NSCLIENT_ID": 1495566734628, - * "mills": 1495566734000, - * "mgdl": 106 - * } +{ + "_id": "5924898d577eb0880e355337", + "eventType": "Combo Bolus", + "duration": 120, + "splitNow": 0, + "splitExt": 100, + "enteredinsulin": 1, + "relative": 1, + "created_at": "2017-05-23T19:12:14Z", + "enteredBy": "AndroidAPS", + "NSCLIENT_ID": 1495566734628, + "mills": 1495566734000, + "mgdl": 106 +} */ public void createExtendedBolusFromJsonIfNotExists(JSONObject json) { @@ -1361,10 +1280,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { createOrUpdate(extendedBolus); } - private static void scheduleExtendedBolusChange() { class PostRunnable implements Runnable { - public void run() { if (L.isEnabled(L.DATABASE)) log.debug("Firing EventExtendedBolusChange"); @@ -1398,7 +1315,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleCareportalEventChange(); } - public void delete(CareportalEvent careportalEvent) { try { getDaoCareportalEvents().delete(careportalEvent); @@ -1408,7 +1324,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { scheduleCareportalEventChange(); } - public CareportalEvent getCareportalEventFromTimestamp(long timestamp) { try { return getDaoCareportalEvents().queryForId(timestamp); @@ -1418,7 +1333,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } - @Nullable public CareportalEvent getLastCareportalEvent(String event) { try { @@ -1440,7 +1354,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } - public List getCareportalEventsFromTime(long mills, boolean ascending) { try { List careportalEvents; @@ -1458,19 +1371,16 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList<>(); } - public void preprocessOpenAPSOfflineEvents(List list) { OverlappingIntervals offlineEvents = new OverlappingIntervals(); for (int i = 0; i < list.size(); i++) { CareportalEvent event = list.get(i); - if (!event.eventType.equals(CareportalEvent.OPENAPSOFFLINE)) - continue; + if (!event.eventType.equals(CareportalEvent.OPENAPSOFFLINE)) continue; offlineEvents.add(event); } } - public List getCareportalEventsFromTime(long mills, String type, boolean ascending) { try { List careportalEvents; @@ -1488,7 +1398,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList<>(); } - public List getCareportalEvents(boolean ascending) { try { List careportalEvents; @@ -1504,7 +1413,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList<>(); } - public void deleteCareportalEventById(String _id) { try { QueryBuilder queryBuilder; @@ -1528,7 +1436,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public void createCareportalEventFromJsonIfNotExists(JSONObject trJson) { try { QueryBuilder queryBuilder; @@ -1562,10 +1469,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - private static void scheduleCareportalEventChange() { class PostRunnable implements Runnable { - public void run() { if (L.isEnabled(L.DATABASE)) log.debug("Firing scheduleCareportalEventChange"); @@ -1583,7 +1488,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } - // ---------------- ProfileSwitch handling --------------- public List getProfileSwitchData(boolean ascending) { @@ -1602,7 +1506,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList<>(); } - public List getProfileSwitchEventsFromTime(long mills, boolean ascending) { try { Dao daoProfileSwitch = getDaoProfileSwitch(); @@ -1621,7 +1524,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return new ArrayList<>(); } - public boolean createOrUpdate(ProfileSwitch profileSwitch) { try { ProfileSwitch old; @@ -1632,13 +1534,11 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { if (old != null) { if (!old.isEqual(profileSwitch)) { profileSwitch.source = old.source; - profileSwitch.profileName = old.profileName; // preserver profileName to prevent multiple CPP - // extension + profileSwitch.profileName = old.profileName; // preserver profileName to prevent multiple CPP extension getDaoProfileSwitch().delete(old); // need to delete/create because date may change too getDaoProfileSwitch().create(profileSwitch); if (L.isEnabled(L.DATABASE)) - log.debug("PROFILESWITCH: Updating record by date from: " - + Source.getString(profileSwitch.source) + " " + old.toString()); + log.debug("PROFILESWITCH: Updating record by date from: " + Source.getString(profileSwitch.source) + " " + old.toString()); scheduleProfileSwitchChange(); return true; } @@ -1658,8 +1558,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { old.copyFrom(profileSwitch); getDaoProfileSwitch().create(old); if (L.isEnabled(L.DATABASE)) - log.debug("PROFILESWITCH: Updating record by _id from: " - + Source.getString(profileSwitch.source) + " " + old.toString()); + log.debug("PROFILESWITCH: Updating record by _id from: " + Source.getString(profileSwitch.source) + " " + old.toString()); scheduleProfileSwitchChange(); return true; } @@ -1669,16 +1568,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { profileSwitch.profileName = PercentageSplitter.pureName(profileSwitch.profileName); getDaoProfileSwitch().create(profileSwitch); if (L.isEnabled(L.DATABASE)) - log.debug("PROFILESWITCH: New record from: " + Source.getString(profileSwitch.source) + " " - + profileSwitch.toString()); + log.debug("PROFILESWITCH: New record from: " + Source.getString(profileSwitch.source) + " " + profileSwitch.toString()); scheduleProfileSwitchChange(); return true; } if (profileSwitch.source == Source.USER) { getDaoProfileSwitch().create(profileSwitch); if (L.isEnabled(L.DATABASE)) - log.debug("PROFILESWITCH: New record from: " + Source.getString(profileSwitch.source) + " " - + profileSwitch.toString()); + log.debug("PROFILESWITCH: New record from: " + Source.getString(profileSwitch.source) + " " + profileSwitch.toString()); scheduleProfileSwitchChange(); return true; } @@ -1688,7 +1585,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return false; } - public void delete(ProfileSwitch profileSwitch) { try { getDaoProfileSwitch().delete(profileSwitch); @@ -1698,10 +1594,8 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - private static void scheduleProfileSwitchChange() { class PostRunnable implements Runnable { - public void run() { if (L.isEnabled(L.DATABASE)) log.debug("Firing EventProfileSwitchChange"); @@ -1720,18 +1614,17 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } - - /* - * { - * "_id":"592fa43ed97496a80da913d2", - * "created_at":"2017-06-01T05:20:06Z", - * "eventType":"Profile Switch", - * "profile":"2016 +30%", - * "units":"mmol", - * "enteredBy":"sony", - * "NSCLIENT_ID":1496294454309, - * } - */ + /* +{ + "_id":"592fa43ed97496a80da913d2", + "created_at":"2017-06-01T05:20:06Z", + "eventType":"Profile Switch", + "profile":"2016 +30%", + "units":"mmol", + "enteredBy":"sony", + "NSCLIENT_ID":1496294454309, +} + */ public void createProfileSwitchFromJsonIfNotExists(JSONObject trJson) { try { @@ -1785,7 +1678,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public void deleteProfileSwitchById(String _id) { ProfileSwitch stored = findProfileSwitchById(_id); if (stored != null) { @@ -1796,7 +1688,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public ProfileSwitch findProfileSwitchById(String _id) { try { QueryBuilder queryBuilder = getDaoProfileSwitch().queryBuilder(); @@ -1816,7 +1707,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } - // ---------------- Insight history handling --------------- public void createOrUpdate(InsightHistoryOffset offset) { @@ -1827,7 +1717,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public InsightHistoryOffset getInsightHistoryOffset(String pumpSerial) { try { return getDaoInsightHistoryOffset().queryForId(pumpSerial); @@ -1837,7 +1726,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } - public void createOrUpdate(InsightBolusID bolusID) { try { getDaoInsightBolusID().createOrUpdate(bolusID); @@ -1846,11 +1734,12 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public InsightBolusID getInsightBolusID(String pumpSerial, int bolusID, long timestamp) { try { - return getDaoInsightBolusID().queryBuilder().where().eq("pumpSerial", pumpSerial).and() - .eq("bolusID", bolusID).and().between("timestamp", timestamp - 259200000, timestamp + 259200000) + return getDaoInsightBolusID().queryBuilder() + .where().eq("pumpSerial", pumpSerial) + .and().eq("bolusID", bolusID) + .and().between("timestamp", timestamp - 259200000, timestamp + 259200000) .queryForFirst(); } catch (SQLException e) { log.error("Unhandled exception", e); @@ -1858,7 +1747,6 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { return null; } - public void createOrUpdate(InsightPumpID pumpID) { try { getDaoInsightPumpID().createOrUpdate(pumpID); @@ -1867,12 +1755,14 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } } - public InsightPumpID getPumpStoppedEvent(String pumpSerial, long before) { try { - return getDaoInsightPumpID().queryBuilder().orderBy("timestamp", false).where() - .eq("pumpSerial", pumpSerial).and().in("eventType", "PumpStopped", "PumpPaused").and() - .lt("timestamp", before).queryForFirst(); + return getDaoInsightPumpID().queryBuilder() + .orderBy("timestamp", false) + .where().eq("pumpSerial", pumpSerial) + .and().in("eventType", "PumpStopped", "PumpPaused") + .and().lt("timestamp", before) + .queryForFirst(); } catch (SQLException e) { log.error("Unhandled exception", e); } @@ -1880,4 +1770,4 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper { } // ---------------- Food handling --------------- -} +} \ No newline at end of file diff --git a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java index 9deb8c95a6..9bbb51cf4a 100644 --- a/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java +++ b/app/src/main/java/info/nightscout/androidaps/plugins/pump/medtronic/comm/history/pump/MedtronicPumpHistoryDecoder.java @@ -1,12 +1,12 @@ package info.nightscout.androidaps.plugins.pump.medtronic.comm.history.pump; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.ArrayList; import java.util.List; import java.util.Locale; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import info.nightscout.androidaps.plugins.pump.common.utils.ByteUtil; import info.nightscout.androidaps.plugins.pump.common.utils.DateTimeUtil; import info.nightscout.androidaps.plugins.pump.common.utils.HexDump; @@ -23,7 +23,7 @@ import info.nightscout.androidaps.plugins.pump.medtronic.util.MedtronicUtil; /** * This file was taken from GGC - GNU Gluco Control and modified/extended for AAPS. - * + *

* Author: Andy {andy.rozman@gmail.com} */ @@ -94,17 +94,17 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder listRawData = new ArrayList(); - listRawData.add((byte)opCode); + listRawData.add((byte) opCode); if (entryType == PumpHistoryEntryType.UnabsorbedInsulin) { int elements = dataClear.get(counter); - listRawData.add((byte)elements); + listRawData.add((byte) elements); counter++; int els = getUnsignedInt(elements); for (int k = 0; k < (els - 2); k++) { - listRawData.add((byte)dataClear.get(counter)); + listRawData.add((byte) dataClear.get(counter)); counter++; } @@ -117,8 +117,8 @@ public class MedtronicPumpHistoryDecoder extends MedtronicHistoryDecoder