Merge pull request #876 from MilosKozak/temptargetfix
upload temptargets to NS properly
This commit is contained in:
commit
c573bcc277
7 changed files with 48 additions and 27 deletions
|
@ -55,6 +55,7 @@ public interface TreatmentsInterface {
|
||||||
TempTarget getTempTargetFromHistory();
|
TempTarget getTempTargetFromHistory();
|
||||||
TempTarget getTempTargetFromHistory(long time);
|
TempTarget getTempTargetFromHistory(long time);
|
||||||
Intervals<TempTarget> getTempTargetsFromHistory();
|
Intervals<TempTarget> getTempTargetsFromHistory();
|
||||||
|
void addToHistoryTempTarget(TempTarget tempTarget);
|
||||||
|
|
||||||
ProfileSwitch getProfileSwitchFromHistory(long time);
|
ProfileSwitch getProfileSwitchFromHistory(long time);
|
||||||
ProfileIntervals<ProfileSwitch> getProfileSwitchesFromHistory();
|
ProfileIntervals<ProfileSwitch> getProfileSwitchesFromHistory();
|
||||||
|
|
|
@ -54,6 +54,7 @@ import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||||
import info.nightscout.utils.DateUtil;
|
import info.nightscout.utils.DateUtil;
|
||||||
import info.nightscout.utils.FabricPrivacy;
|
import info.nightscout.utils.FabricPrivacy;
|
||||||
import info.nightscout.utils.HardLimits;
|
import info.nightscout.utils.HardLimits;
|
||||||
|
import info.nightscout.utils.JsonHelper;
|
||||||
import info.nightscout.utils.NSUpload;
|
import info.nightscout.utils.NSUpload;
|
||||||
import info.nightscout.utils.NumberPicker;
|
import info.nightscout.utils.NumberPicker;
|
||||||
import info.nightscout.utils.SP;
|
import info.nightscout.utils.SP;
|
||||||
|
@ -694,27 +695,25 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (options.executeTempTarget) {
|
} else if (options.executeTempTarget) {
|
||||||
try {
|
final int duration = JsonHelper.safeGetInt(data, "duration");
|
||||||
if ((data.has("targetBottom") && data.has("targetTop")) || (data.has("duration") && data.getInt("duration") == 0)) {
|
final double targetBottom = JsonHelper.safeGetDouble(data, "targetBottom");
|
||||||
|
final double targetTop = JsonHelper.safeGetDouble(data, "targetTop");
|
||||||
|
final String reason = JsonHelper.safeGetString(data, "reason", "");
|
||||||
|
if ((targetBottom != 0d && targetTop != 0d) || duration == 0) {
|
||||||
TempTarget tempTarget = new TempTarget()
|
TempTarget tempTarget = new TempTarget()
|
||||||
.date(eventTime.getTime())
|
.date(eventTime.getTime())
|
||||||
.duration(data.getInt("duration"))
|
.duration(duration)
|
||||||
.reason(data.getString("reason"))
|
.reason(reason)
|
||||||
.source(Source.USER);
|
.source(Source.USER);
|
||||||
if (tempTarget.durationInMinutes != 0) {
|
if (tempTarget.durationInMinutes != 0) {
|
||||||
tempTarget.low(Profile.toMgdl(data.getDouble("targetBottom"), profile.getUnits()))
|
tempTarget.low(Profile.toMgdl(targetBottom, profile.getUnits()))
|
||||||
.high(Profile.toMgdl(data.getDouble("targetTop"), profile.getUnits()));
|
.high(Profile.toMgdl(targetTop, profile.getUnits()));
|
||||||
} else {
|
} else {
|
||||||
tempTarget.low(0).high(0);
|
tempTarget.low(0).high(0);
|
||||||
}
|
}
|
||||||
log.debug("Creating new TempTarget db record: " + tempTarget.toString());
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
MainApp.getDbHelper().createOrUpdate(tempTarget);
|
|
||||||
NSUpload.uploadCareportalEntryToNS(data);
|
|
||||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("TempTarget"));
|
FabricPrivacy.getInstance().logCustom(new CustomEvent("TempTarget"));
|
||||||
}
|
}
|
||||||
} catch (JSONException e) {
|
|
||||||
log.error("Unhandled exception", e);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
NSUpload.uploadCareportalEntryToNS(data);
|
NSUpload.uploadCareportalEntryToNS(data);
|
||||||
FabricPrivacy.getInstance().logCustom(new CustomEvent("NSTreatment"));
|
FabricPrivacy.getInstance().logCustom(new CustomEvent("NSTreatment"));
|
||||||
|
|
|
@ -388,7 +388,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(finalActivityTT, currentProfile.getUnits()))
|
.low(Profile.toMgdl(finalActivityTT, currentProfile.getUnits()))
|
||||||
.high(Profile.toMgdl(finalActivityTT, currentProfile.getUnits()));
|
.high(Profile.toMgdl(finalActivityTT, currentProfile.getUnits()));
|
||||||
MainApp.getDbHelper().createOrUpdate(tempTarget);
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
} else if (startEatingSoonTTCheckbox.isChecked()) {
|
} else if (startEatingSoonTTCheckbox.isChecked()) {
|
||||||
TempTarget tempTarget = new TempTarget()
|
TempTarget tempTarget = new TempTarget()
|
||||||
.date(System.currentTimeMillis())
|
.date(System.currentTimeMillis())
|
||||||
|
@ -397,7 +397,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()))
|
.low(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()))
|
||||||
.high(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()));
|
.high(Profile.toMgdl(finalEatigSoonTT, currentProfile.getUnits()));
|
||||||
MainApp.getDbHelper().createOrUpdate(tempTarget);
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
} else if (startHypoTTCheckbox.isChecked()) {
|
} else if (startHypoTTCheckbox.isChecked()) {
|
||||||
TempTarget tempTarget = new TempTarget()
|
TempTarget tempTarget = new TempTarget()
|
||||||
.date(System.currentTimeMillis())
|
.date(System.currentTimeMillis())
|
||||||
|
@ -406,7 +406,7 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, D
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low(Profile.toMgdl(finalHypoTT, currentProfile.getUnits()))
|
.low(Profile.toMgdl(finalHypoTT, currentProfile.getUnits()))
|
||||||
.high(Profile.toMgdl(finalHypoTT, currentProfile.getUnits()));
|
.high(Profile.toMgdl(finalHypoTT, currentProfile.getUnits()));
|
||||||
MainApp.getDbHelper().createOrUpdate(tempTarget);
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finalCarbsAfterConstraints > 0) {
|
if (finalCarbsAfterConstraints > 0) {
|
||||||
|
|
|
@ -288,7 +288,7 @@ public class NewInsulinDialog extends DialogFragment implements OnClickListener,
|
||||||
.source(Source.USER)
|
.source(Source.USER)
|
||||||
.low((int) finalTT)
|
.low((int) finalTT)
|
||||||
.high((int) finalTT);
|
.high((int) finalTT);
|
||||||
MainApp.getDbHelper().createOrUpdate(tempTarget);
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (finalInsulinAfterConstraints <= 0.01) {
|
if (finalInsulinAfterConstraints <= 0.01) {
|
||||||
|
|
|
@ -505,6 +505,13 @@ public class TreatmentsPlugin extends PluginBase implements TreatmentsInterface
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addToHistoryTempTarget(TempTarget tempTarget) {
|
||||||
|
//log.debug("Adding new TemporaryBasal record" + profileSwitch.log());
|
||||||
|
MainApp.getDbHelper().createOrUpdate(tempTarget);
|
||||||
|
NSUpload.uploadTempTarget(tempTarget);
|
||||||
|
}
|
||||||
|
|
||||||
// Profile Switch
|
// Profile Switch
|
||||||
@Subscribe
|
@Subscribe
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
|
|
|
@ -622,10 +622,7 @@ public class ActionStringHandler {
|
||||||
} else {
|
} else {
|
||||||
tempTarget.low(0).high(0);
|
tempTarget.low(0).high(0);
|
||||||
}
|
}
|
||||||
MainApp.getDbHelper().createOrUpdate(tempTarget);
|
TreatmentsPlugin.getPlugin().addToHistoryTempTarget(tempTarget);
|
||||||
|
|
||||||
//TODO: Nightscout-Treatment for Temp-Target!
|
|
||||||
//ConfigBuilderPlugin.uploadCareportalEntryToNS(data);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void doFillBolus(final Double amount) {
|
private static void doFillBolus(final Double amount) {
|
||||||
|
|
|
@ -28,6 +28,7 @@ import info.nightscout.androidaps.db.BgReading;
|
||||||
import info.nightscout.androidaps.db.CareportalEvent;
|
import info.nightscout.androidaps.db.CareportalEvent;
|
||||||
import info.nightscout.androidaps.db.ExtendedBolus;
|
import info.nightscout.androidaps.db.ExtendedBolus;
|
||||||
import info.nightscout.androidaps.db.ProfileSwitch;
|
import info.nightscout.androidaps.db.ProfileSwitch;
|
||||||
|
import info.nightscout.androidaps.db.TempTarget;
|
||||||
import info.nightscout.androidaps.db.TemporaryBasal;
|
import info.nightscout.androidaps.db.TemporaryBasal;
|
||||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||||
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
import info.nightscout.androidaps.plugins.Loop.APSResult;
|
||||||
|
@ -302,6 +303,22 @@ public class NSUpload {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void uploadTempTarget(TempTarget tempTarget) {
|
||||||
|
try {
|
||||||
|
JSONObject data = new JSONObject();
|
||||||
|
data.put("eventType", CareportalEvent.TEMPORARYTARGET);
|
||||||
|
data.put("duration", tempTarget.durationInMinutes);
|
||||||
|
data.put("reason", tempTarget.reason);
|
||||||
|
data.put("targetBottom", tempTarget.low);
|
||||||
|
data.put("targetTop", tempTarget.high);
|
||||||
|
data.put("created_at", DateUtil.toISOString(tempTarget.date));
|
||||||
|
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
|
||||||
|
uploadCareportalEntryToNS(data);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.error("Unhandled exception", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void updateProfileSwitch(ProfileSwitch profileSwitch) {
|
public static void updateProfileSwitch(ProfileSwitch profileSwitch) {
|
||||||
try {
|
try {
|
||||||
JSONObject data = new JSONObject();
|
JSONObject data = new JSONObject();
|
||||||
|
|
Loading…
Reference in a new issue