Also upload APS data

This commit is contained in:
TebbeUbben 2020-05-26 01:42:33 +02:00
parent 3fc2aede23
commit 5533f87bbc
8 changed files with 100 additions and 82 deletions

View file

@ -379,7 +379,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
BgReading old = getDaoBgReadings().queryForId(bgReading.date); BgReading old = getDaoBgReadings().queryForId(bgReading.date);
if (old == null) { if (old == null) {
getDaoBgReadings().create(bgReading); getDaoBgReadings().create(bgReading);
OpenHumansUploader.INSTANCE.queueBGReading(bgReading); OpenHumansUploader.INSTANCE.enqueueBGReading(bgReading);
if (L.isEnabled(L.DATABASE)) if (L.isEnabled(L.DATABASE))
log.debug("BG: New record from: " + from + " " + bgReading.toString()); log.debug("BG: New record from: " + from + " " + bgReading.toString());
scheduleBgChange(bgReading); scheduleBgChange(bgReading);
@ -390,7 +390,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
log.debug("BG: Similiar found: " + old.toString()); log.debug("BG: Similiar found: " + old.toString());
old.copyFrom(bgReading); old.copyFrom(bgReading);
getDaoBgReadings().update(old); getDaoBgReadings().update(old);
OpenHumansUploader.INSTANCE.queueBGReading(old); OpenHumansUploader.INSTANCE.enqueueBGReading(old);
if (L.isEnabled(L.DATABASE)) if (L.isEnabled(L.DATABASE))
log.debug("BG: Updating record from: " + from + " New data: " + old.toString()); log.debug("BG: Updating record from: " + from + " New data: " + old.toString());
scheduleBgChange(bgReading); scheduleBgChange(bgReading);
@ -406,7 +406,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
bgReading.date = roundDateToSec(bgReading.date); bgReading.date = roundDateToSec(bgReading.date);
try { try {
getDaoBgReadings().update(bgReading); getDaoBgReadings().update(bgReading);
OpenHumansUploader.INSTANCE.queueBGReading(bgReading); OpenHumansUploader.INSTANCE.enqueueBGReading(bgReading);
} catch (SQLException e) { } catch (SQLException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }
@ -530,7 +530,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
try { try {
Dao<TDD, String> dao = getDaoTDD(); Dao<TDD, String> dao = getDaoTDD();
dao.createOrUpdate(tdd); dao.createOrUpdate(tdd);
OpenHumansUploader.INSTANCE.queueTotalDailyDose(tdd); OpenHumansUploader.INSTANCE.enqueueTotalDailyDose(tdd);
} catch (SQLException e) { } catch (SQLException e) {
ToastUtils.showToastInUiThread(MainApp.instance(), "createOrUpdate-Exception"); ToastUtils.showToastInUiThread(MainApp.instance(), "createOrUpdate-Exception");
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
@ -706,7 +706,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
getDaoTempTargets().delete(old); // need to delete/create because date may change too getDaoTempTargets().delete(old); // need to delete/create because date may change too
old.copyFrom(tempTarget); old.copyFrom(tempTarget);
getDaoTempTargets().create(old); getDaoTempTargets().create(old);
OpenHumansUploader.INSTANCE.queueTempTarget(old); OpenHumansUploader.INSTANCE.enqueueTempTarget(old);
if (L.isEnabled(L.DATABASE)) 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(); scheduleTemporaryTargetChange();
@ -727,7 +727,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
getDaoTempTargets().delete(old); // need to delete/create because date may change too getDaoTempTargets().delete(old); // need to delete/create because date may change too
old.copyFrom(tempTarget); old.copyFrom(tempTarget);
getDaoTempTargets().create(old); getDaoTempTargets().create(old);
OpenHumansUploader.INSTANCE.queueTempTarget(old); OpenHumansUploader.INSTANCE.enqueueTempTarget(old);
if (L.isEnabled(L.DATABASE)) 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(); scheduleTemporaryTargetChange();
@ -743,7 +743,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} }
if (tempTarget.source == Source.USER) { if (tempTarget.source == Source.USER) {
getDaoTempTargets().create(tempTarget); getDaoTempTargets().create(tempTarget);
OpenHumansUploader.INSTANCE.queueTempTarget(tempTarget); OpenHumansUploader.INSTANCE.enqueueTempTarget(tempTarget);
if (L.isEnabled(L.DATABASE)) 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(); scheduleTemporaryTargetChange();
@ -758,7 +758,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void delete(TempTarget tempTarget) { public void delete(TempTarget tempTarget) {
try { try {
getDaoTempTargets().delete(tempTarget); getDaoTempTargets().delete(tempTarget);
OpenHumansUploader.INSTANCE.queueTempTarget(tempTarget, true); OpenHumansUploader.INSTANCE.enqueueTempTarget(tempTarget, true);
scheduleTemporaryTargetChange(); scheduleTemporaryTargetChange();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
@ -941,7 +941,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
log.debug("TEMPBASAL: Updated record with Pump Data : " + Source.getString(tempBasal.source) + " " + tempBasal.toString()); log.debug("TEMPBASAL: Updated record with Pump Data : " + Source.getString(tempBasal.source) + " " + tempBasal.toString());
getDaoTemporaryBasal().update(old); getDaoTemporaryBasal().update(old);
OpenHumansUploader.INSTANCE.queueTemporaryBasal(old); OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(old);
updateEarliestDataChange(tempBasal.date); updateEarliestDataChange(tempBasal.date);
scheduleTemporaryBasalChange(); scheduleTemporaryBasalChange();
@ -950,7 +950,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} }
getDaoTemporaryBasal().create(tempBasal); getDaoTemporaryBasal().create(tempBasal);
OpenHumansUploader.INSTANCE.queueTemporaryBasal(tempBasal); OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(tempBasal);
if (L.isEnabled(L.DATABASE)) 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); updateEarliestDataChange(tempBasal.date);
@ -969,7 +969,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
getDaoTemporaryBasal().delete(old); // need to delete/create because date may change too getDaoTemporaryBasal().delete(old); // need to delete/create because date may change too
old.copyFrom(tempBasal); old.copyFrom(tempBasal);
getDaoTemporaryBasal().create(old); getDaoTemporaryBasal().create(old);
OpenHumansUploader.INSTANCE.queueTemporaryBasal(old); OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(old);
if (L.isEnabled(L.DATABASE)) 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(oldDate);
@ -993,7 +993,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
getDaoTemporaryBasal().delete(old); // need to delete/create because date may change too getDaoTemporaryBasal().delete(old); // need to delete/create because date may change too
old.copyFrom(tempBasal); old.copyFrom(tempBasal);
getDaoTemporaryBasal().create(old); getDaoTemporaryBasal().create(old);
OpenHumansUploader.INSTANCE.queueTemporaryBasal(old); OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(old);
if (L.isEnabled(L.DATABASE)) 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(oldDate);
@ -1004,7 +1004,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} }
} }
getDaoTemporaryBasal().create(tempBasal); getDaoTemporaryBasal().create(tempBasal);
OpenHumansUploader.INSTANCE.queueTemporaryBasal(tempBasal); OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(tempBasal);
if (L.isEnabled(L.DATABASE)) 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); updateEarliestDataChange(tempBasal.date);
@ -1013,7 +1013,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} }
if (tempBasal.source == Source.USER) { if (tempBasal.source == Source.USER) {
getDaoTemporaryBasal().create(tempBasal); getDaoTemporaryBasal().create(tempBasal);
OpenHumansUploader.INSTANCE.queueTemporaryBasal(tempBasal); OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(tempBasal);
if (L.isEnabled(L.DATABASE)) 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); updateEarliestDataChange(tempBasal.date);
@ -1029,7 +1029,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void delete(TemporaryBasal tempBasal) { public void delete(TemporaryBasal tempBasal) {
try { try {
getDaoTemporaryBasal().delete(tempBasal); getDaoTemporaryBasal().delete(tempBasal);
OpenHumansUploader.INSTANCE.queueTemporaryBasal(tempBasal, true); OpenHumansUploader.INSTANCE.enqueueTemporaryBasal(tempBasal, true);
updateEarliestDataChange(tempBasal.date); updateEarliestDataChange(tempBasal.date);
} catch (SQLException e) { } catch (SQLException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
@ -1244,7 +1244,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
// and then is record updated with pumpId // and then is record updated with pumpId
if (extendedBolus.pumpId == 0) { if (extendedBolus.pumpId == 0) {
getDaoExtendedBolus().createOrUpdate(extendedBolus); getDaoExtendedBolus().createOrUpdate(extendedBolus);
OpenHumansUploader.INSTANCE.queueExtendedBolus(extendedBolus); OpenHumansUploader.INSTANCE.enqueueExtendedBolus(extendedBolus);
} else { } else {
QueryBuilder<ExtendedBolus, Long> queryBuilder = getDaoExtendedBolus().queryBuilder(); QueryBuilder<ExtendedBolus, Long> queryBuilder = getDaoExtendedBolus().queryBuilder();
Where where = queryBuilder.where(); Where where = queryBuilder.where();
@ -1256,7 +1256,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
return false; return false;
} }
getDaoExtendedBolus().createOrUpdate(extendedBolus); getDaoExtendedBolus().createOrUpdate(extendedBolus);
OpenHumansUploader.INSTANCE.queueExtendedBolus(extendedBolus); OpenHumansUploader.INSTANCE.enqueueExtendedBolus(extendedBolus);
} }
if (L.isEnabled(L.DATABASE)) 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());
@ -1272,7 +1272,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
getDaoExtendedBolus().delete(old); // need to delete/create because date may change too getDaoExtendedBolus().delete(old); // need to delete/create because date may change too
old.copyFrom(extendedBolus); old.copyFrom(extendedBolus);
getDaoExtendedBolus().create(old); getDaoExtendedBolus().create(old);
OpenHumansUploader.INSTANCE.queueExtendedBolus(old); OpenHumansUploader.INSTANCE.enqueueExtendedBolus(old);
if (L.isEnabled(L.DATABASE)) 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(oldDate);
@ -1296,7 +1296,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
getDaoExtendedBolus().delete(old); // need to delete/create because date may change too getDaoExtendedBolus().delete(old); // need to delete/create because date may change too
old.copyFrom(extendedBolus); old.copyFrom(extendedBolus);
getDaoExtendedBolus().create(old); getDaoExtendedBolus().create(old);
OpenHumansUploader.INSTANCE.queueExtendedBolus(old); OpenHumansUploader.INSTANCE.enqueueExtendedBolus(old);
if (L.isEnabled(L.DATABASE)) 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(oldDate);
@ -1307,7 +1307,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} }
} }
getDaoExtendedBolus().create(extendedBolus); getDaoExtendedBolus().create(extendedBolus);
OpenHumansUploader.INSTANCE.queueExtendedBolus(extendedBolus); OpenHumansUploader.INSTANCE.enqueueExtendedBolus(extendedBolus);
if (L.isEnabled(L.DATABASE)) 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); updateEarliestDataChange(extendedBolus.date);
@ -1316,7 +1316,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} }
if (extendedBolus.source == Source.USER) { if (extendedBolus.source == Source.USER) {
getDaoExtendedBolus().create(extendedBolus); getDaoExtendedBolus().create(extendedBolus);
OpenHumansUploader.INSTANCE.queueExtendedBolus(extendedBolus); OpenHumansUploader.INSTANCE.enqueueExtendedBolus(extendedBolus);
if (L.isEnabled(L.DATABASE)) 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); updateEarliestDataChange(extendedBolus.date);
@ -1352,7 +1352,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void delete(ExtendedBolus extendedBolus) { public void delete(ExtendedBolus extendedBolus) {
try { try {
getDaoExtendedBolus().delete(extendedBolus); getDaoExtendedBolus().delete(extendedBolus);
OpenHumansUploader.INSTANCE.queueExtendedBolus(extendedBolus, true); OpenHumansUploader.INSTANCE.enqueueExtendedBolus(extendedBolus, true);
updateEarliestDataChange(extendedBolus.date); updateEarliestDataChange(extendedBolus.date);
} catch (SQLException e) { } catch (SQLException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
@ -1459,7 +1459,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
careportalEvent.date = careportalEvent.date - careportalEvent.date % 1000; careportalEvent.date = careportalEvent.date - careportalEvent.date % 1000;
try { try {
getDaoCareportalEvents().createOrUpdate(careportalEvent); getDaoCareportalEvents().createOrUpdate(careportalEvent);
OpenHumansUploader.INSTANCE.queueCareportalEvent(careportalEvent); OpenHumansUploader.INSTANCE.enqueueCareportalEvent(careportalEvent);
} catch (SQLException e) { } catch (SQLException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }
@ -1469,7 +1469,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void delete(CareportalEvent careportalEvent) { public void delete(CareportalEvent careportalEvent) {
try { try {
getDaoCareportalEvents().delete(careportalEvent); getDaoCareportalEvents().delete(careportalEvent);
OpenHumansUploader.INSTANCE.queueCareportalEvent(careportalEvent, true); OpenHumansUploader.INSTANCE.enqueueCareportalEvent(careportalEvent, true);
} catch (SQLException e) { } catch (SQLException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }
@ -1776,7 +1776,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
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().delete(old); // need to delete/create because date may change too
getDaoProfileSwitch().create(profileSwitch); getDaoProfileSwitch().create(profileSwitch);
OpenHumansUploader.INSTANCE.queueProfileSwitch(profileSwitch); OpenHumansUploader.INSTANCE.enqueueProfileSwitch(profileSwitch);
if (L.isEnabled(L.DATABASE)) 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(); scheduleProfileSwitchChange();
@ -1797,7 +1797,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
getDaoProfileSwitch().delete(old); // need to delete/create because date may change too getDaoProfileSwitch().delete(old); // need to delete/create because date may change too
old.copyFrom(profileSwitch); old.copyFrom(profileSwitch);
getDaoProfileSwitch().create(old); getDaoProfileSwitch().create(old);
OpenHumansUploader.INSTANCE.queueProfileSwitch(old); OpenHumansUploader.INSTANCE.enqueueProfileSwitch(old);
if (L.isEnabled(L.DATABASE)) 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(); scheduleProfileSwitchChange();
@ -1808,7 +1808,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
// look for already added percentage from NS // look for already added percentage from NS
profileSwitch.profileName = PercentageSplitter.pureName(profileSwitch.profileName); profileSwitch.profileName = PercentageSplitter.pureName(profileSwitch.profileName);
getDaoProfileSwitch().create(profileSwitch); getDaoProfileSwitch().create(profileSwitch);
OpenHumansUploader.INSTANCE.queueProfileSwitch(profileSwitch); OpenHumansUploader.INSTANCE.enqueueProfileSwitch(profileSwitch);
if (L.isEnabled(L.DATABASE)) 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(); scheduleProfileSwitchChange();
@ -1816,7 +1816,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
} }
if (profileSwitch.source == Source.USER) { if (profileSwitch.source == Source.USER) {
getDaoProfileSwitch().create(profileSwitch); getDaoProfileSwitch().create(profileSwitch);
OpenHumansUploader.INSTANCE.queueProfileSwitch(profileSwitch); OpenHumansUploader.INSTANCE.enqueueProfileSwitch(profileSwitch);
if (L.isEnabled(L.DATABASE)) 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(); scheduleProfileSwitchChange();
@ -1831,7 +1831,7 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
public void delete(ProfileSwitch profileSwitch) { public void delete(ProfileSwitch profileSwitch) {
try { try {
getDaoProfileSwitch().delete(profileSwitch); getDaoProfileSwitch().delete(profileSwitch);
OpenHumansUploader.INSTANCE.queueProfileSwitch(profileSwitch, true); OpenHumansUploader.INSTANCE.enqueueProfileSwitch(profileSwitch, true);
scheduleProfileSwitchChange(); scheduleProfileSwitchChange();
} catch (SQLException e) { } catch (SQLException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);

View file

@ -24,6 +24,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.openhumans.OpenHumansUploader;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.MealData;
@ -127,7 +128,9 @@ public class DetermineBasalAdapterAMAJS {
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug("Result: " + result); log.debug("Result: " + result);
try { try {
determineBasalResultAMA = new DetermineBasalResultAMA(jsResult, new JSONObject(result)); JSONObject resultJson = new JSONObject(result);
OpenHumansUploader.INSTANCE.enqueueAMAData(mProfile, mGlucoseStatus, mIobData, mMealData, mCurrentTemp, mAutosensData, resultJson);
determineBasalResultAMA = new DetermineBasalResultAMA(jsResult, resultJson);
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }

View file

@ -21,6 +21,7 @@ import javax.annotation.Nullable;
import info.nightscout.androidaps.Constants; import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.openhumans.OpenHumansUploader;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.MealData;
@ -104,7 +105,9 @@ public class DetermineBasalAdapterMAJS {
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug("Result: " + result); log.debug("Result: " + result);
try { try {
determineBasalResultMA = new DetermineBasalResultMA(jsResult, new JSONObject(result)); JSONObject resultJson = new JSONObject(result);
OpenHumansUploader.INSTANCE.enqueueAMAData(mProfile, mGlucoseStatus, mIobData, mMealData, mCurrentTemp, resultJson);
determineBasalResultMA = new DetermineBasalResultMA(jsResult, resultJson);
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }

View file

@ -24,6 +24,7 @@ import info.nightscout.androidaps.Constants;
import info.nightscout.androidaps.MainApp; import info.nightscout.androidaps.MainApp;
import info.nightscout.androidaps.R; import info.nightscout.androidaps.R;
import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions; import info.nightscout.androidaps.plugins.configBuilder.ProfileFunctions;
import info.nightscout.androidaps.plugins.general.openhumans.OpenHumansUploader;
import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus; import info.nightscout.androidaps.plugins.iob.iobCobCalculator.GlucoseStatus;
import info.nightscout.androidaps.data.IobTotal; import info.nightscout.androidaps.data.IobTotal;
import info.nightscout.androidaps.data.MealData; import info.nightscout.androidaps.data.MealData;
@ -144,7 +145,9 @@ public class DetermineBasalAdapterSMBJS {
if (L.isEnabled(L.APS)) if (L.isEnabled(L.APS))
log.debug("Result: " + result); log.debug("Result: " + result);
try { try {
determineBasalResultSMB = new DetermineBasalResultSMB(new JSONObject(result)); JSONObject resultJson = new JSONObject(result);
OpenHumansUploader.INSTANCE.enqueueSMBData(mProfile, mGlucoseStatus, mIobData, mMealData, mCurrentTemp, mAutosensData, mMicrobolusAllowed, mSMBAlwaysAllowed, resultJson);
determineBasalResultSMB = new DetermineBasalResultSMB(resultJson);
} catch (JSONException e) { } catch (JSONException e) {
log.error("Unhandled exception", e); log.error("Unhandled exception", e);
} }

View file

@ -14,11 +14,13 @@ class OHUploadWorker(
override fun createWork() = Single.defer { override fun createWork() = Single.defer {
val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
if (SP.getBoolean("key_oh_wifi_only", true) && wifiManager.isWifiEnabled && wifiManager.connectionInfo.networkId != -1) if (SP.getBoolean("key_oh_wifi_only", true) && wifiManager.isWifiEnabled && wifiManager.connectionInfo.networkId != -1) {
OpenHumansUploader.uploadData() OpenHumansUploader.uploadData()
.andThen(Single.just(Result.success())) .andThen(Single.just(Result.success()))
.onErrorResumeNext { Single.just(Result.retry()) } .onErrorResumeNext { Single.just(Result.retry()) }
else Single.just(Result.retry()) } else {
Single.just(Result.retry())
}
} }
} }

View file

@ -11,7 +11,6 @@ import org.json.JSONObject
import java.io.IOException import java.io.IOException
import java.text.SimpleDateFormat import java.text.SimpleDateFormat
import java.util.* import java.util.*
import okhttp3.RequestBody.Companion
import okio.BufferedSink import okio.BufferedSink
class OpenHumansAPI( class OpenHumansAPI(
@ -24,13 +23,13 @@ class OpenHumansAPI(
private val authHeader = "Basic " + Base64.encodeToString("$clientId:$clientSecret".toByteArray(), Base64.NO_WRAP) private val authHeader = "Basic " + Base64.encodeToString("$clientId:$clientSecret".toByteArray(), Base64.NO_WRAP)
private val client = OkHttpClient() private val client = OkHttpClient()
fun exchangeAuthToken(code: String) = sendTokenRequest(FormBody.Builder() fun exchangeAuthToken(code: String): Single<OAuthTokens> = sendTokenRequest(FormBody.Builder()
.add("grant_type", "authorization_code") .add("grant_type", "authorization_code")
.add("redirect_uri", redirectUri) .add("redirect_uri", redirectUri)
.add("code", code) .add("code", code)
.build()) .build())
fun refreshAccessToken(refreshToken: String) = sendTokenRequest(FormBody.Builder() fun refreshAccessToken(refreshToken: String): Single<OAuthTokens> = sendTokenRequest(FormBody.Builder()
.add("grant_type", "refresh_token") .add("grant_type", "refresh_token")
.add("redirect_uri", redirectUri) .add("redirect_uri", redirectUri)
.add("code", refreshToken) .add("code", refreshToken)
@ -57,14 +56,14 @@ class OpenHumansAPI(
} }
} }
fun getProjectMemberId(accessToken: String) = Request.Builder() fun getProjectMemberId(accessToken: String): Single<String> = Request.Builder()
.url("$baseUrl/api/direct-sharing/project/exchange-member/?access_token=$accessToken") .url("$baseUrl/api/direct-sharing/project/exchange-member/?access_token=$accessToken")
.get() .get()
.build() .build()
.toSingle() .toSingle()
.map { it.jsonBody.getString("project_member_id") ?: throw OHMissingFieldException("project_member_id") } .map { it.jsonBody.getString("project_member_id") ?: throw OHMissingFieldException("project_member_id") }
fun prepareFileUpload(accessToken: String, fileName: String, metadata: FileMetadata) = Request.Builder() fun prepareFileUpload(accessToken: String, fileName: String, metadata: FileMetadata): Single<PreparedUpload> = Request.Builder()
.url("$baseUrl/api/direct-sharing/project/files/upload/direct/?access_token=$accessToken") .url("$baseUrl/api/direct-sharing/project/files/upload/direct/?access_token=$accessToken")
.post(FormBody.Builder() .post(FormBody.Builder()
.add("filename", fileName) .add("filename", fileName)
@ -80,7 +79,7 @@ class OpenHumansAPI(
) )
} }
fun uploadFile(url: String, content: ByteArray) = Request.Builder() fun uploadFile(url: String, content: ByteArray): Completable = Request.Builder()
.url(url) .url(url)
.put(object : RequestBody() { .put(object : RequestBody() {
override fun contentType(): MediaType? = null override fun contentType(): MediaType? = null
@ -100,7 +99,7 @@ class OpenHumansAPI(
} }
.ignoreElement() .ignoreElement()
fun completeFileUpload(accessToken: String, fileId: String) = Request.Builder() fun completeFileUpload(accessToken: String, fileId: String): Completable = Request.Builder()
.url("$baseUrl/api/direct-sharing/project/files/upload/complete/?access_token=$accessToken") .url("$baseUrl/api/direct-sharing/project/files/upload/complete/?access_token=$accessToken")
.post(FormBody.Builder() .post(FormBody.Builder()
.add("file_id", fileId) .add("file_id", fileId)

View file

@ -2,7 +2,6 @@ package info.nightscout.androidaps.plugins.general.openhumans
import android.app.Activity import android.app.Activity
import android.app.Dialog import android.app.Dialog
import android.content.ComponentName
import android.content.Intent import android.content.Intent
import android.net.Uri import android.net.Uri
import android.os.Bundle import android.os.Bundle
@ -10,11 +9,7 @@ import android.widget.Button
import android.widget.CheckBox import android.widget.CheckBox
import android.widget.Toast import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.browser.customtabs.CustomTabsCallback
import androidx.browser.customtabs.CustomTabsClient
import androidx.browser.customtabs.CustomTabsIntent import androidx.browser.customtabs.CustomTabsIntent
import androidx.browser.customtabs.CustomTabsServiceConnection
import androidx.browser.customtabs.CustomTabsSession
import androidx.fragment.app.DialogFragment import androidx.fragment.app.DialogFragment
import info.nightscout.androidaps.R import info.nightscout.androidaps.R
import info.nightscout.androidaps.activities.NoSplashAppCompatActivity import info.nightscout.androidaps.activities.NoSplashAppCompatActivity
@ -22,32 +17,16 @@ import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers import io.reactivex.schedulers.Schedulers
class OpenHumansLoginActivity : NoSplashAppCompatActivity() { class OpenHumansLoginActivity : NoSplashAppCompatActivity() {
/*
private lateinit var customTabsClient: CustomTabsClient
private lateinit var customTabsSession: CustomTabsSession
private val connection = object : CustomTabsServiceConnection() {
override fun onCustomTabsServiceConnected(name: ComponentName, client: CustomTabsClient) {
customTabsClient = client
customTabsClient.warmup(0)
customTabsSession = customTabsClient.newSession(CustomTabsCallback())!!
customTabsSession.mayLaunchUrl(Uri.parse(OpenHumansUploader.AUTH_URL), null, null)
}
override fun onServiceDisconnected(name: ComponentName?) {
}
}
*/
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState) super.onCreate(savedInstanceState)
//CustomTabsClient.bindCustomTabsService(this, "com.android.chrome", connection)
setContentView(R.layout.activity_open_humans_login) setContentView(R.layout.activity_open_humans_login)
val button = findViewById<Button>(R.id.button) val button = findViewById<Button>(R.id.button)
val checkbox = findViewById<CheckBox>(R.id.checkbox) val checkbox = findViewById<CheckBox>(R.id.checkbox)
button.setOnClickListener { _ -> button.setOnClickListener { _ ->
if (checkbox.isChecked) { if (checkbox.isChecked) {
CustomTabsIntent.Builder()/*.setSession(customTabsSession)*/.build().launchUrl(this, Uri.parse(OpenHumansUploader.AUTH_URL)) CustomTabsIntent.Builder().build().launchUrl(this, Uri.parse(OpenHumansUploader.AUTH_URL))
} else { } else {
Toast.makeText(this, R.string.you_need_to_accept_the_of_use_first, Toast.LENGTH_SHORT).show() Toast.makeText(this, R.string.you_need_to_accept_the_of_use_first, Toast.LENGTH_SHORT).show()
} }
@ -62,7 +41,6 @@ class OpenHumansLoginActivity : NoSplashAppCompatActivity() {
} }
} }
class ExchangeAuthTokenDialog : DialogFragment() { class ExchangeAuthTokenDialog : DialogFragment() {
private var disposable: Disposable? = null private var disposable: Disposable? = null
@ -89,7 +67,6 @@ class OpenHumansLoginActivity : NoSplashAppCompatActivity() {
}) })
} }
override fun onDestroy() { override fun onDestroy() {
disposable?.dispose() disposable?.dispose()
super.onDestroy() super.onDestroy()
@ -108,8 +85,6 @@ class OpenHumansLoginActivity : NoSplashAppCompatActivity() {
} }
} }
class ErrorDialog : DialogFragment() { class ErrorDialog : DialogFragment() {
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {

View file

@ -39,7 +39,6 @@ import java.util.*
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
import java.util.zip.ZipOutputStream import java.util.zip.ZipOutputStream
import kotlin.math.max
object OpenHumansUploader : PluginBase( object OpenHumansUploader : PluginBase(
PluginDescription() PluginDescription()
@ -134,7 +133,7 @@ object OpenHumansUploader : PluginBase(
super.onStop() super.onStop()
} }
fun queueBGReading(bgReading: BgReading) = insertQueueItem("BgReadings") { fun enqueueBGReading(bgReading: BgReading) = insertQueueItem("BgReadings") {
put("date", bgReading.date) put("date", bgReading.date)
put("isValid", bgReading.isValid) put("isValid", bgReading.isValid)
put("value", bgReading.value) put("value", bgReading.value)
@ -145,7 +144,7 @@ object OpenHumansUploader : PluginBase(
} }
@JvmOverloads @JvmOverloads
fun queueCareportalEvent(careportalEvent: CareportalEvent, deleted: Boolean = false) = insertQueueItem("CareportalEvents") { fun enqueueCareportalEvent(careportalEvent: CareportalEvent, deleted: Boolean = false) = insertQueueItem("CareportalEvents") {
put("date", careportalEvent.date) put("date", careportalEvent.date)
put("isValid", careportalEvent.isValid) put("isValid", careportalEvent.isValid)
put("source", careportalEvent.source) put("source", careportalEvent.source)
@ -166,7 +165,7 @@ object OpenHumansUploader : PluginBase(
} }
@JvmOverloads @JvmOverloads
fun queueExtendedBolus(extendedBolus: ExtendedBolus, deleted: Boolean = false) = insertQueueItem("ExtendedBoluses") { fun enqueueExtendedBolus(extendedBolus: ExtendedBolus, deleted: Boolean = false) = insertQueueItem("ExtendedBoluses") {
put("date", extendedBolus.date) put("date", extendedBolus.date)
put("isValid", extendedBolus.isValid) put("isValid", extendedBolus.isValid)
put("source", extendedBolus.source) put("source", extendedBolus.source)
@ -178,7 +177,7 @@ object OpenHumansUploader : PluginBase(
} }
@JvmOverloads @JvmOverloads
fun queueProfileSwitch(profileSwitch: ProfileSwitch, deleted: Boolean = false) = insertQueueItem("ProfileSwitches") { fun enqueueProfileSwitch(profileSwitch: ProfileSwitch, deleted: Boolean = false) = insertQueueItem("ProfileSwitches") {
put("date", profileSwitch.date) put("date", profileSwitch.date)
put("isValid", profileSwitch.isValid) put("isValid", profileSwitch.isValid)
put("source", profileSwitch.source) put("source", profileSwitch.source)
@ -192,7 +191,7 @@ object OpenHumansUploader : PluginBase(
put("isDeletion", deleted) put("isDeletion", deleted)
} }
fun queueTotalDailyDose(tdd: TDD) = insertQueueItem("TotalDailyDoses") { fun enqueueTotalDailyDose(tdd: TDD) = insertQueueItem("TotalDailyDoses") {
put("double", tdd.date) put("double", tdd.date)
put("double", tdd.bolus) put("double", tdd.bolus)
put("double", tdd.basal) put("double", tdd.basal)
@ -200,7 +199,7 @@ object OpenHumansUploader : PluginBase(
} }
@JvmOverloads @JvmOverloads
fun queueTemporaryBasal(temporaryBasal: TemporaryBasal, deleted: Boolean = false) = insertQueueItem("TemporaryBasals") { fun enqueueTemporaryBasal(temporaryBasal: TemporaryBasal, deleted: Boolean = false) = insertQueueItem("TemporaryBasals") {
put("date", temporaryBasal.date) put("date", temporaryBasal.date)
put("isValid", temporaryBasal.isValid) put("isValid", temporaryBasal.isValid)
put("source", temporaryBasal.source) put("source", temporaryBasal.source)
@ -215,7 +214,7 @@ object OpenHumansUploader : PluginBase(
} }
@JvmOverloads @JvmOverloads
fun queueTempTarget(tempTarget: TempTarget, deleted: Boolean = false) = insertQueueItem("TempTargets") { fun enqueueTempTarget(tempTarget: TempTarget, deleted: Boolean = false) = insertQueueItem("TempTargets") {
put("date", tempTarget.date) put("date", tempTarget.date)
put("isValid", tempTarget.isValid) put("isValid", tempTarget.isValid)
put("source", tempTarget.source) put("source", tempTarget.source)
@ -227,6 +226,40 @@ object OpenHumansUploader : PluginBase(
put("isDeletion", deleted) put("isDeletion", deleted)
} }
fun enqueueSMBData(profile: JSONObject, glucoseStatus: JSONObject, iobData: JSONArray, mealData: JSONObject, currentTemp: JSONObject, autosensData: JSONObject, smbAllowed: Boolean, smbAlwaysAllowed: Boolean, result: JSONObject) = insertQueueItem("APSData") {
put("algorithm", "SMB")
put("profile", profile)
put("glucoseStatus", glucoseStatus)
put("iobData", iobData)
put("mealData", mealData)
put("currentTemp", currentTemp)
put("autosensData", autosensData)
put("smbAllowed", smbAllowed)
put("smbAlwaysAllowed", smbAlwaysAllowed)
put("result", result)
}
fun enqueueAMAData(profile: JSONObject, glucoseStatus: JSONObject, iobData: JSONArray, mealData: JSONObject, currentTemp: JSONObject, autosensData: JSONObject, result: JSONObject) = insertQueueItem("APSData") {
put("algorithm", "AMA")
put("profile", profile)
put("glucoseStatus", glucoseStatus)
put("iobData", iobData)
put("mealData", mealData)
put("currentTemp", currentTemp)
put("autosensData", autosensData)
put("result", result)
}
fun enqueueAMAData(profile: JSONObject, glucoseStatus: JSONObject, iobData: JSONObject, mealData: JSONObject, currentTemp: JSONObject, result: JSONObject) = insertQueueItem("APSData") {
put("algorithm", "MA")
put("profile", profile)
put("glucoseStatus", glucoseStatus)
put("iobData", iobData)
put("mealData", mealData)
put("currentTemp", currentTemp)
put("result", result)
}
private fun insertQueueItem(file: String, structureVersion: Int = 1, generator: JSONObject.() -> Unit) { private fun insertQueueItem(file: String, structureVersion: Int = 1, generator: JSONObject.() -> Unit) {
if (oAuthTokens != null && this.isEnabled(PluginType.GENERAL)) { if (oAuthTokens != null && this.isEnabled(PluginType.GENERAL)) {
try { try {
@ -282,25 +315,25 @@ object OpenHumansUploader : PluginBase(
.andThen(Single.defer { Single.just(MainApp.getDbHelper().countOfAllRows) }) .andThen(Single.defer { Single.just(MainApp.getDbHelper().countOfAllRows) })
.doOnSuccess { maxProgress = it } .doOnSuccess { maxProgress = it }
.flatMapObservable { Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allBgReadings) } } .flatMapObservable { Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allBgReadings) } }
.map { queueBGReading(it); increaseCounter() } .map { enqueueBGReading(it); increaseCounter() }
.ignoreElements() .ignoreElements()
.andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allCareportalEvents) }) .andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allCareportalEvents) })
.map { queueCareportalEvent(it); increaseCounter() } .map { enqueueCareportalEvent(it); increaseCounter() }
.ignoreElements() .ignoreElements()
.andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allExtendedBoluses) }) .andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allExtendedBoluses) })
.map { queueExtendedBolus(it); increaseCounter() } .map { enqueueExtendedBolus(it); increaseCounter() }
.ignoreElements() .ignoreElements()
.andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allProfileSwitches) }) .andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allProfileSwitches) })
.map { queueProfileSwitch(it); increaseCounter() } .map { enqueueProfileSwitch(it); increaseCounter() }
.ignoreElements() .ignoreElements()
.andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allTDDs) }) .andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allTDDs) })
.map { queueTotalDailyDose(it); increaseCounter() } .map { enqueueTotalDailyDose(it); increaseCounter() }
.ignoreElements() .ignoreElements()
.andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allTemporaryBasals) }) .andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allTemporaryBasals) })
.map { queueTemporaryBasal(it); increaseCounter() } .map { enqueueTemporaryBasal(it); increaseCounter() }
.ignoreElements() .ignoreElements()
.andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allTempTargets) }) .andThen(Observable.defer { Observable.fromIterable(MainApp.getDbHelper().allTempTargets) })
.map { queueTempTarget(it); increaseCounter() } .map { enqueueTempTarget(it); increaseCounter() }
.ignoreElements() .ignoreElements()
.doOnSubscribe { .doOnSubscribe {
wakeLock.acquire(TimeUnit.MINUTES.toMillis(20)) wakeLock.acquire(TimeUnit.MINUTES.toMillis(20))