AS value in %

This commit is contained in:
Roumen Georgiev 2019-05-15 14:52:17 +03:00
parent e220a42e4b
commit 5d86ca742a
3 changed files with 29 additions and 24 deletions

View file

@ -10,19 +10,18 @@ import info.nightscout.androidaps.utils.NumberPicker;
import info.nightscout.androidaps.utils.SP; import info.nightscout.androidaps.utils.SP;
public class InputAutosens extends Element { public class InputAutosens extends Element {
private int value;
private double value; int minValue = (int) (SP.getDouble("openapsama_autosens_min", 0.7d) * 100);
double minValue = SP.getDouble("key_openapsama_autosens_min", 0.7d); int maxValue = (int) (SP.getDouble("openapsama_autosens_max", 1.2d) * 100);
double maxValue = SP.getDouble("key_openapsama_autosens_max", 1.2d); private double step = 1;
private double step = 0.01d; private DecimalFormat decimalFormat = new DecimalFormat("1");;
private DecimalFormat decimalFormat = new DecimalFormat("0.00");;
NumberPicker numberPicker; NumberPicker numberPicker;
final TextWatcher textWatcher = new TextWatcher() { final TextWatcher textWatcher = new TextWatcher() {
@Override @Override
public void afterTextChanged(Editable s) { public void afterTextChanged(Editable s) {
value = Math.max(value, 0.7d); value = Math.max(value, 70);
value = Math.min(value, 2d); value = Math.min(value, 200);
} }
@Override @Override
@ -43,9 +42,9 @@ public class InputAutosens extends Element {
public InputAutosens(double value, double minValue, double maxValue, double step, DecimalFormat decimalFormat) { public InputAutosens(double value, double minValue, double maxValue, double step, DecimalFormat decimalFormat) {
super(); super();
this.value = value; this.value = (int) value;
this.minValue = minValue; this.minValue = (int) ( minValue * 100 );
this.maxValue = maxValue; this.maxValue = (int) (maxValue * 100 );
this.step = step; this.step = step;
this.decimalFormat = decimalFormat; this.decimalFormat = decimalFormat;
} }
@ -62,26 +61,32 @@ public class InputAutosens extends Element {
@Override @Override
public void addToLayout(LinearLayout root) { public void addToLayout(LinearLayout root) {
minValue = (int) (SP.getDouble("openapsama_autosens_min", 0.7d) * 100);
maxValue = (int) (SP.getDouble("openapsama_autosens_max", 1.2d) * 100);
if (value > maxValue)
value = Math.max(value, this.maxValue);
if (value < minValue)
value = minValue;
numberPicker = new NumberPicker(root.getContext(), null); numberPicker = new NumberPicker(root.getContext(), null);
numberPicker.setParams(value, minValue, maxValue, step, decimalFormat, true, textWatcher); numberPicker.setParams((double) value, (double) minValue, (double) maxValue, step, decimalFormat, true, textWatcher);
numberPicker.setOnValueChangedListener(value -> this.value = value); numberPicker.setOnValueChangedListener(value -> this.value = (int) value);
root.addView(numberPicker); root.addView(numberPicker);
} }
public InputAutosens setValue(double value) { public InputAutosens setValue(int value) {
minValue = SP.getDouble("key_openapsama_autosens_min", 0.7d); minValue = (int) (SP.getDouble("openapsama_autosens_min", 0.7d) * 100);
maxValue = SP.getDouble("key_openapsama_autosens_max", 1.2d); maxValue = (int) (SP.getDouble("openapsama_autosens_max", 1.2d) * 100);
if (value > maxValue) if (value > maxValue)
value = Math.max(value, this.maxValue); value = Math.max(value, this.maxValue);
if (value < minValue) if (value < minValue)
value = minValue; value = minValue;
this.value = value; this.value = value;
if (numberPicker != null) if (numberPicker != null)
numberPicker.setValue(value); numberPicker.setValue((double) value);
return this; return this;
} }
public double getValue() { public int getValue() {
return value; return value;
} }

View file

@ -41,7 +41,7 @@ public class TriggerAutosensValue extends Trigger {
lastRun = triggerAutosensValue.lastRun; lastRun = triggerAutosensValue.lastRun;
} }
public double getValue() { public int getValue() {
return value.getValue(); return value.getValue();
} }
@ -64,7 +64,7 @@ public class TriggerAutosensValue extends Trigger {
return true; return true;
} }
boolean doRun = comparator.getValue().check((autosensData.autosensResult.ratio), getValue()); boolean doRun = comparator.getValue().check((autosensData.autosensResult.ratio), (double) (getValue() / 100d));
if (doRun) { if (doRun) {
if (L.isEnabled(L.AUTOMATION)) if (L.isEnabled(L.AUTOMATION))
log.debug("Ready for execution: " + friendlyDescription()); log.debug("Ready for execution: " + friendlyDescription());
@ -93,7 +93,7 @@ public class TriggerAutosensValue extends Trigger {
Trigger fromJSON(String data) { Trigger fromJSON(String data) {
try { try {
JSONObject d = new JSONObject(data); JSONObject d = new JSONObject(data);
value.setValue(JsonHelper.safeGetDouble(d, "value")); value.setValue(JsonHelper.safeGetInt(d, "value"));
lastRun = JsonHelper.safeGetLong(d, "lastRun"); lastRun = JsonHelper.safeGetLong(d, "lastRun");
comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator"))); comparator.setValue(Comparator.Compare.valueOf(JsonHelper.safeGetString(d, "comparator")));
} catch (Exception e) { } catch (Exception e) {
@ -122,7 +122,7 @@ public class TriggerAutosensValue extends Trigger {
return new TriggerAutosensValue(this); return new TriggerAutosensValue(this);
} }
TriggerAutosensValue setValue(double requestedValue) { TriggerAutosensValue setValue(int requestedValue) {
this.value.setValue(requestedValue); this.value.setValue(requestedValue);
return this; return this;
} }

View file

@ -1400,8 +1400,8 @@
<string name="notexists">not exists</string> <string name="notexists">not exists</string>
<string name="temptargetcompared">Temp target %1$s</string> <string name="temptargetcompared">Temp target %1$s</string>
<string name="wifissidcompared">WiFi SSID %1$s %2$s</string> <string name="wifissidcompared">WiFi SSID %1$s %2$s</string>
<string name="autosenscompared">Autosens %1$s %2$s</string> <string name="autosenscompared">Autosens %1$s %2$s %%</string>
<string name="autosenslabel">Autosens ratio</string> <string name="autosenslabel">Autosens %</string>
<string name="currentlocation">Current Location</string> <string name="currentlocation">Current Location</string>
<string name="location">Location</string> <string name="location">Location</string>
<string name="latitude_short">Lat:</string> <string name="latitude_short">Lat:</string>