use absolute in upload based on preference

This commit is contained in:
Milos Kozak 2016-07-11 23:21:20 +02:00
parent efa2944c4c
commit ae1a4b38dd

View file

@ -374,7 +374,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
request.rate = applyBasalConstraints(request.rate); request.rate = applyBasalConstraints(request.rate);
PumpEnactResult result; PumpEnactResult result;
if (request.rate == getBaseBasalRate()) { if (Math.abs(request.rate - getBaseBasalRate()) < 0.1) {
if (isTempBasalInProgress()) { if (isTempBasalInProgress()) {
result = cancelTempBasal(); result = cancelTempBasal();
} else { } else {
@ -385,7 +385,7 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
result.comment = "Basal set correctly"; result.comment = "Basal set correctly";
result.success = true; result.success = true;
} }
} else if (isTempBasalInProgress() && Math.abs(request.rate - getTempBasalAbsoluteRate()) < 0.05) { } else if (isTempBasalInProgress() && Math.abs(request.rate - getTempBasalAbsoluteRate()) < 0.1) {
result = new PumpEnactResult(); result = new PumpEnactResult();
result.absolute = getTempBasalAbsoluteRate(); result.absolute = getTempBasalAbsoluteRate();
result.duration = activePump.getTempBasal().getPlannedRemainingMinutes(); result.duration = activePump.getTempBasal().getPlannedRemainingMinutes();
@ -863,23 +863,29 @@ public class ConfigBuilderFragment extends Fragment implements PluginBase, PumpI
public static void uploadTempBasalStartPercent(Integer percent, double durationInMinutes) { public static void uploadTempBasalStartPercent(Integer percent, double durationInMinutes) {
try { try {
// TODO: upload as absolute if in settings SharedPreferences SP = PreferenceManager.getDefaultSharedPreferences(MainApp.instance().getApplicationContext());
Context context = MainApp.instance().getApplicationContext(); boolean useAbsolute = SP.getBoolean("ns_sync_use_absolute", false);
JSONObject data = new JSONObject(); if (useAbsolute) {
data.put("eventType", "Temp Basal"); double absolute = MainApp.getConfigBuilder().getActivePump().getBaseBasalRate() * percent / 100d;
data.put("duration", durationInMinutes); uploadTempBasalStartAbsolute(absolute, durationInMinutes);
data.put("percent", percent - 100); } else {
data.put("created_at", DateUtil.toISOString(new Date())); Context context = MainApp.instance().getApplicationContext();
data.put("enteredBy", MainApp.instance().getString(R.string.app_name)); JSONObject data = new JSONObject();
Bundle bundle = new Bundle(); data.put("eventType", "Temp Basal");
bundle.putString("action", "dbAdd"); data.put("duration", durationInMinutes);
bundle.putString("collection", "treatments"); data.put("percent", percent - 100);
bundle.putString("data", data.toString()); data.put("created_at", DateUtil.toISOString(new Date()));
Intent intent = new Intent(Intents.ACTION_DATABASE); data.put("enteredBy", MainApp.instance().getString(R.string.app_name));
intent.putExtras(bundle); Bundle bundle = new Bundle();
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES); bundle.putString("action", "dbAdd");
context.sendBroadcast(intent); bundle.putString("collection", "treatments");
DbLogger.dbAdd(intent, data.toString(), ConfigBuilderFragment.class); bundle.putString("data", data.toString());
Intent intent = new Intent(Intents.ACTION_DATABASE);
intent.putExtras(bundle);
intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
context.sendBroadcast(intent);
DbLogger.dbAdd(intent, data.toString(), ConfigBuilderFragment.class);
}
} catch (JSONException e) { } catch (JSONException e) {
} }
} }