Merge remote-tracking branch 'milosremote/dev' into cob-rework
This commit is contained in:
commit
d8180cc52b
|
@ -28,6 +28,7 @@ import java.util.concurrent.ScheduledFuture;
|
|||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import info.nightscout.androidaps.Config;
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.MainApp;
|
||||
import info.nightscout.androidaps.data.Profile;
|
||||
import info.nightscout.androidaps.data.ProfileStore;
|
||||
|
@ -45,6 +46,7 @@ import info.nightscout.androidaps.plugins.IobCobCalculator.events.EventNewHistor
|
|||
import info.nightscout.androidaps.plugins.PumpDanaR.activities.DanaRNSHistorySync;
|
||||
import info.nightscout.androidaps.plugins.PumpDanaR.comm.RecordTypes;
|
||||
import info.nightscout.androidaps.plugins.PumpVirtual.VirtualPumpPlugin;
|
||||
import info.nightscout.utils.JsonHelper;
|
||||
import info.nightscout.utils.NSUpload;
|
||||
import info.nightscout.utils.PercentageSplitter;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
@ -662,12 +664,12 @@ public class DatabaseHelper extends OrmLiteSqliteOpenHelper {
|
|||
|
||||
public void createTemptargetFromJsonIfNotExists(JSONObject trJson) {
|
||||
try {
|
||||
String units = MainApp.getConfigBuilder().getProfileUnits();
|
||||
String units = JsonHelper.safeGetString(trJson, "units", MainApp.getConfigBuilder().getProfileUnits());
|
||||
TempTarget tempTarget = new TempTarget()
|
||||
.date(trJson.getLong("mills"))
|
||||
.duration(trJson.getInt("duration"))
|
||||
.low(trJson.getDouble("targetBottom"))
|
||||
.high(trJson.getDouble("targetTop"))
|
||||
.low(Profile.toMgdl(trJson.getDouble("targetBottom"), units))
|
||||
.high(Profile.toMgdl(trJson.getDouble("targetTop"), units))
|
||||
.reason(trJson.getString("reason"))
|
||||
._id(trJson.getString("_id"))
|
||||
.source(Source.NIGHTSCOUT);
|
||||
|
|
|
@ -51,6 +51,7 @@ import info.nightscout.androidaps.db.TempTarget;
|
|||
import info.nightscout.androidaps.plugins.Careportal.OptionsToShow;
|
||||
import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DefaultValueHelper;
|
||||
import info.nightscout.utils.FabricPrivacy;
|
||||
import info.nightscout.utils.HardLimits;
|
||||
import info.nightscout.utils.JsonHelper;
|
||||
|
@ -210,19 +211,22 @@ public class NewNSTreatmentDialog extends DialogFragment implements View.OnClick
|
|||
}
|
||||
boolean erase = false;
|
||||
|
||||
String units = MainApp.getConfigBuilder().getProfileUnits();
|
||||
DefaultValueHelper helper = new DefaultValueHelper();
|
||||
if (MainApp.gs(R.string.eatingsoon).equals(reasonList.get(position))) {
|
||||
defaultDuration = SP.getDouble(R.string.key_eatingsoon_duration, 0d);
|
||||
defaultTarget = SP.getDouble(R.string.key_eatingsoon_target, 0d);
|
||||
defaultDuration = helper.determineEatingSoonTTDuration();
|
||||
defaultTarget = helper.determineEatingSoonTT(units);
|
||||
} else if (MainApp.gs(R.string.activity).equals(reasonList.get(position))) {
|
||||
defaultDuration = SP.getDouble(R.string.key_activity_duration, 0d);
|
||||
defaultTarget = SP.getDouble(R.string.key_activity_target, 0d);
|
||||
defaultDuration = helper.determineActivityTTDuration();
|
||||
defaultTarget = helper.determineActivityTT(units);
|
||||
} else if (MainApp.gs(R.string.hypo).equals(reasonList.get(position))) {
|
||||
defaultDuration = SP.getDouble(R.string.key_hypo_duration, 0d);
|
||||
defaultTarget = SP.getDouble(R.string.key_hypo_target, 0d);
|
||||
defaultDuration = helper.determineHypoTTDuration();
|
||||
defaultTarget = helper.determineHypoTT(units);
|
||||
} else {
|
||||
defaultDuration = 0;
|
||||
erase = true;
|
||||
}
|
||||
|
||||
if (defaultTarget != 0 || erase) {
|
||||
editTemptarget.setValue(defaultTarget);
|
||||
}
|
||||
|
|
|
@ -44,6 +44,7 @@ import info.nightscout.androidaps.plugins.Treatments.TreatmentsPlugin;
|
|||
import info.nightscout.androidaps.queue.Callback;
|
||||
import info.nightscout.utils.DateUtil;
|
||||
import info.nightscout.utils.DecimalFormatter;
|
||||
import info.nightscout.utils.DefaultValueHelper;
|
||||
import info.nightscout.utils.NumberPicker;
|
||||
import info.nightscout.utils.SP;
|
||||
import info.nightscout.utils.ToastUtils;
|
||||
|
@ -290,28 +291,27 @@ public class NewCarbsDialog extends DialogFragment implements OnClickListener, C
|
|||
int carbs = editCarbs.getValue().intValue();
|
||||
Integer carbsAfterConstraints = MainApp.getConstraintChecker().applyCarbsConstraints(new Constraint<>(carbs)).value();
|
||||
|
||||
int activityTTDuration = SP.getInt(R.string.key_activity_duration, Constants.defaultActivityTTDuration);
|
||||
activityTTDuration = activityTTDuration > 0 ? activityTTDuration : Constants.defaultActivityTTDuration;
|
||||
double activityTT = SP.getDouble(R.string.key_activity_target, currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultActivityTTmmol : Constants.defaultActivityTTmgdl);
|
||||
activityTT = activityTT > 0 ? activityTT : currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultActivityTTmmol : Constants.defaultActivityTTmgdl;
|
||||
final String units = currentProfile.getUnits();
|
||||
DefaultValueHelper helper = new DefaultValueHelper();
|
||||
|
||||
int eatingSoonTTDuration = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration);
|
||||
eatingSoonTTDuration = eatingSoonTTDuration > 0 ? eatingSoonTTDuration : Constants.defaultEatingSoonTTDuration;
|
||||
double eatingSoonTT = SP.getDouble(R.string.key_eatingsoon_target, currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl);
|
||||
eatingSoonTT = eatingSoonTT > 0 ? eatingSoonTT : currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultEatingSoonTTmmol : Constants.defaultEatingSoonTTmgdl;
|
||||
int activityTTDuration = helper.determineActivityTTDuration();
|
||||
double activityTT = helper.determineActivityTT(units);
|
||||
|
||||
int hypoTTDuration = SP.getInt(R.string.key_hypo_duration, Constants.defaultHypoTTDuration);
|
||||
hypoTTDuration = hypoTTDuration > 0 ? hypoTTDuration : Constants.defaultHypoTTDuration;
|
||||
double hypoTT = SP.getDouble(R.string.key_hypo_target, currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultHypoTTmmol : Constants.defaultHypoTTmgdl);
|
||||
hypoTT = hypoTT > 0 ? hypoTT : currentProfile.getUnits().equals(Constants.MMOL) ? Constants.defaultHypoTTmmol : Constants.defaultHypoTTmgdl;
|
||||
int eatingSoonTTDuration = helper.determineEatingSoonTTDuration();
|
||||
double eatingSoonTT = helper.determineEatingSoonTT(units);
|
||||
|
||||
int hypoTTDuration = helper.determineHypoTTDuration();
|
||||
double hypoTT = helper.determineHypoTT(units);
|
||||
|
||||
List<String> actions = new LinkedList<>();
|
||||
|
||||
if (startActivityTTCheckbox.isChecked()) {
|
||||
String unitLabel = "mg/dl";
|
||||
if (currentProfile.getUnits().equals(Constants.MMOL)) {
|
||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.high) + "'>" + DecimalFormatter.to1Decimal(activityTT) + " mmol/l (" + activityTTDuration + " min)</font>");
|
||||
} else
|
||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.high) + "'>" + DecimalFormatter.to0Decimal(activityTT) + " mg/dl (" + activityTTDuration + " min)</font>");
|
||||
unitLabel = "mmol/l";
|
||||
}
|
||||
|
||||
actions.add(MainApp.gs(R.string.temptargetshort) + ": " + "<font color='" + MainApp.gc(R.color.high) + "'>" + DecimalFormatter.to1Decimal(activityTT) + " " + unitLabel + " (" + activityTTDuration + " min)</font>");
|
||||
|
||||
}
|
||||
if (startEatingSoonTTCheckbox.isChecked()) {
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
package info.nightscout.utils;
|
||||
|
||||
import info.nightscout.androidaps.Constants;
|
||||
import info.nightscout.androidaps.R;
|
||||
|
||||
public class DefaultValueHelper {
|
||||
|
||||
/**
|
||||
* returns the corresponding EatingSoon TempTarget based on the given units (MMOL / MGDL)
|
||||
*
|
||||
* @param units
|
||||
* @return
|
||||
*/
|
||||
public double getDefaultEatingSoonTT(String units) {
|
||||
return Constants.MMOL.equals(units) ? Constants.defaultEatingSoonTTmmol
|
||||
: Constants.defaultEatingSoonTTmgdl;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the corresponding Activity TempTarget based on the given units (MMOL / MGDL)
|
||||
*
|
||||
* @param units
|
||||
* @return
|
||||
*/
|
||||
public double getDefaultActivityTT(String units) {
|
||||
return Constants.MMOL.equals(units) ? Constants.defaultActivityTTmmol
|
||||
: Constants.defaultActivityTTmgdl;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the corresponding Hypo TempTarget based on the given units (MMOL / MGDL)
|
||||
*
|
||||
* @param units
|
||||
* @return
|
||||
*/
|
||||
public double getDefaultHypoTT(String units) {
|
||||
return Constants.MMOL.equals(units) ? Constants.defaultHypoTTmmol
|
||||
: Constants.defaultHypoTTmgdl;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the configured EatingSoon TempTarget, if this is set to 0, the Default-Value is returned.
|
||||
*
|
||||
* @param units
|
||||
* @return
|
||||
*/
|
||||
public double determineEatingSoonTT(String units) {
|
||||
double value = SP.getDouble(R.string.key_eatingsoon_target, this.getDefaultEatingSoonTT(units));
|
||||
return value > 0 ? value : this.getDefaultEatingSoonTT(units);
|
||||
}
|
||||
|
||||
public int determineEatingSoonTTDuration() {
|
||||
int value = SP.getInt(R.string.key_eatingsoon_duration, Constants.defaultEatingSoonTTDuration);
|
||||
return value > 0 ? value : Constants.defaultEatingSoonTTDuration;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* returns the configured Activity TempTarget, if this is set to 0, the Default-Value is returned.
|
||||
*
|
||||
* @param units
|
||||
* @return
|
||||
*/
|
||||
public double determineActivityTT(String units) {
|
||||
double value = SP.getDouble(R.string.key_activity_target, this.getDefaultActivityTT(units));
|
||||
return value > 0 ? value : this.getDefaultActivityTT(units);
|
||||
}
|
||||
|
||||
public int determineActivityTTDuration() {
|
||||
int value = SP.getInt(R.string.key_activity_duration, Constants.defaultActivityTTDuration);
|
||||
return value > 0 ? value : Constants.defaultActivityTTDuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the configured Hypo TempTarget, if this is set to 0, the Default-Value is returned.
|
||||
*
|
||||
* @param units
|
||||
* @return
|
||||
*/
|
||||
public double determineHypoTT(String units) {
|
||||
double value = SP.getDouble(R.string.key_hypo_target, this.getDefaultHypoTT(units));
|
||||
return value > 0 ? value : this.getDefaultHypoTT(units);
|
||||
}
|
||||
|
||||
public int determineHypoTTDuration() {
|
||||
int value = SP.getInt(R.string.key_hypo_duration, Constants.defaultHypoTTDuration);
|
||||
return value > 0 ? value : Constants.defaultHypoTTDuration;
|
||||
}
|
||||
|
||||
}
|
|
@ -14,10 +14,9 @@ import info.nightscout.androidaps.db.DatabaseHelper;
|
|||
import info.nightscout.androidaps.interfaces.PumpInterface;
|
||||
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
||||
import info.nightscout.androidaps.plugins.Loop.LoopPlugin;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventDismissNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.events.EventNewNotification;
|
||||
import info.nightscout.androidaps.plugins.Overview.notifications.Notification;
|
||||
import info.nightscout.androidaps.receivers.KeepAliveReceiver;
|
||||
import info.nightscout.utils.NSUpload;
|
||||
|
||||
/**
|
||||
* Created by adrian on 17/12/17.
|
||||
|
@ -26,12 +25,12 @@ import info.nightscout.utils.NSUpload;
|
|||
public class LocalAlertUtils {
|
||||
private static Logger log = LoggerFactory.getLogger(LocalAlertUtils.class);
|
||||
|
||||
public static int missedReadingsThreshold() {
|
||||
return SP.getInt(MainApp.sResources.getString(R.string.key_missed_bg_readings_threshold), 30) * 60 * 1000;
|
||||
public static long missedReadingsThreshold() {
|
||||
return T.mins(SP.getInt(MainApp.sResources.getString(R.string.key_missed_bg_readings_threshold), 30)).msecs();
|
||||
}
|
||||
|
||||
private static int pumpUnreachableThreshold() {
|
||||
return SP.getInt(MainApp.sResources.getString(R.string.key_pump_unreachable_threshold), 30) * 60 * 1000;
|
||||
private static long pumpUnreachableThreshold() {
|
||||
return T.mins(SP.getInt(MainApp.sResources.getString(R.string.key_pump_unreachable_threshold), 30)).msecs();
|
||||
}
|
||||
|
||||
public static void checkPumpUnreachableAlarm(Date lastConnection, boolean isStatusOutdated) {
|
||||
|
@ -49,11 +48,13 @@ public class LocalAlertUtils {
|
|||
NSUpload.uploadError(n.text);
|
||||
}
|
||||
}
|
||||
if (!isStatusOutdated && !alarmTimeoutExpired)
|
||||
MainApp.bus().post(new EventDismissNotification(Notification.PUMP_UNREACHABLE));
|
||||
}
|
||||
|
||||
/*Presnoozes the alarms with 5 minutes if no snooze exists.
|
||||
* Call only at startup!
|
||||
*/
|
||||
* Call only at startup!
|
||||
*/
|
||||
public static void presnoozeAlarms() {
|
||||
if (SP.getLong("nextMissedReadingsAlarm", 0l) < System.currentTimeMillis()) {
|
||||
SP.putLong("nextMissedReadingsAlarm", System.currentTimeMillis() + 5 * 60 * 1000);
|
||||
|
@ -74,7 +75,7 @@ public class LocalAlertUtils {
|
|||
SP.putLong("nextPumpDisconnectedAlarm", nextPumpDisconnectedAlarm);
|
||||
}
|
||||
|
||||
public static void notifyPumpStatusRead(){
|
||||
public static void notifyPumpStatusRead() {
|
||||
//TODO: persist the actual time the pump is read and simplify the whole logic when to alarm
|
||||
|
||||
final PumpInterface pump = ConfigBuilderPlugin.getActivePump();
|
||||
|
|
|
@ -310,13 +310,21 @@ public class NSUpload {
|
|||
|
||||
public static void uploadTempTarget(TempTarget tempTarget) {
|
||||
try {
|
||||
Profile profile = MainApp.getConfigBuilder().getProfile();
|
||||
|
||||
if (profile == null) {
|
||||
log.error("Profile is null. Skipping upload");
|
||||
return;
|
||||
}
|
||||
|
||||
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("targetBottom", Profile.fromMgdlToUnits(tempTarget.low, profile.getUnits()));
|
||||
data.put("targetTop", Profile.fromMgdlToUnits(tempTarget.high, profile.getUnits()));
|
||||
data.put("created_at", DateUtil.toISOString(tempTarget.date));
|
||||
data.put("units", profile.getUnits());
|
||||
data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
|
||||
uploadCareportalEntryToNS(data);
|
||||
} catch (JSONException e) {
|
||||
|
|
Loading…
Reference in a new issue