Constraints logging
This commit is contained in:
parent
018a5f5e43
commit
0563420996
3 changed files with 25 additions and 10 deletions
|
@ -13,7 +13,7 @@ import info.nightscout.androidaps.logging.L;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Constraint<T extends Comparable> {
|
public class Constraint<T extends Comparable> {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.APS);
|
private static Logger log = LoggerFactory.getLogger(L.CONSTRAINTS);
|
||||||
|
|
||||||
T value;
|
T value;
|
||||||
T originalValue;
|
T originalValue;
|
||||||
|
@ -37,10 +37,14 @@ public class Constraint<T extends Comparable> {
|
||||||
public Constraint<T> set(T value) {
|
public Constraint<T> set(T value) {
|
||||||
this.value = value;
|
this.value = value;
|
||||||
this.originalValue = value;
|
this.originalValue = value;
|
||||||
|
if (L.isEnabled(L.CONSTRAINTS))
|
||||||
|
log.debug("Setting value " + value);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Constraint<T> set(T value, String reason, Object from) {
|
public Constraint<T> set(T value, String reason, Object from) {
|
||||||
|
if (L.isEnabled(L.CONSTRAINTS))
|
||||||
|
log.debug("Setting value " + this.value + " -> " + value + " (" + reason + ")[" + from + "]");
|
||||||
this.value = value;
|
this.value = value;
|
||||||
addReason(reason, from);
|
addReason(reason, from);
|
||||||
addMostLimingReason(reason, from);
|
addMostLimingReason(reason, from);
|
||||||
|
@ -49,6 +53,8 @@ public class Constraint<T extends Comparable> {
|
||||||
|
|
||||||
public Constraint<T> setIfDifferent(T value, String reason, Object from) {
|
public Constraint<T> setIfDifferent(T value, String reason, Object from) {
|
||||||
if (!this.value.equals(value)) {
|
if (!this.value.equals(value)) {
|
||||||
|
if (L.isEnabled(L.CONSTRAINTS))
|
||||||
|
log.debug("Setting because of different value " + this.value + " -> " + value + " (" + reason + ")[" + from + "]");
|
||||||
this.value = value;
|
this.value = value;
|
||||||
addReason(reason, from);
|
addReason(reason, from);
|
||||||
addMostLimingReason(reason, from);
|
addMostLimingReason(reason, from);
|
||||||
|
@ -58,6 +64,8 @@ public class Constraint<T extends Comparable> {
|
||||||
|
|
||||||
public Constraint<T> setIfSmaller(T value, String reason, Object from) {
|
public Constraint<T> setIfSmaller(T value, String reason, Object from) {
|
||||||
if (value.compareTo(this.value) < 0) {
|
if (value.compareTo(this.value) < 0) {
|
||||||
|
if (L.isEnabled(L.CONSTRAINTS))
|
||||||
|
log.debug("Setting because of smaller value " + this.value + " -> " + value + " (" + reason + ")[" + from + "]");
|
||||||
this.value = value;
|
this.value = value;
|
||||||
mostLimiting.clear();
|
mostLimiting.clear();
|
||||||
addMostLimingReason(reason, from);
|
addMostLimingReason(reason, from);
|
||||||
|
@ -70,6 +78,8 @@ public class Constraint<T extends Comparable> {
|
||||||
|
|
||||||
public Constraint<T> setIfGreater(T value, String reason, Object from) {
|
public Constraint<T> setIfGreater(T value, String reason, Object from) {
|
||||||
if (value.compareTo(this.value) > 0) {
|
if (value.compareTo(this.value) > 0) {
|
||||||
|
if (L.isEnabled(L.CONSTRAINTS))
|
||||||
|
log.debug("Setting because of greater value " + this.value + " -> " + value + " (" + reason + ")[" + from + "]");
|
||||||
this.value = value;
|
this.value = value;
|
||||||
mostLimiting.clear();
|
mostLimiting.clear();
|
||||||
addMostLimingReason(reason, from);
|
addMostLimingReason(reason, from);
|
||||||
|
@ -80,13 +90,17 @@ public class Constraint<T extends Comparable> {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String translateFrom(Object from) {
|
||||||
|
return from.getClass().getSimpleName().replace("Plugin", "");
|
||||||
|
}
|
||||||
|
|
||||||
public Constraint addReason(String reason, Object from) {
|
public Constraint addReason(String reason, Object from) {
|
||||||
reasons.add(from.getClass().getSimpleName().replace("Plugin", "") + ": " + reason);
|
reasons.add(translateFrom(from) + ": " + reason);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Constraint addMostLimingReason(String reason, Object from) {
|
public Constraint addMostLimingReason(String reason, Object from) {
|
||||||
mostLimiting.add(from.getClass().getSimpleName().replace("Plugin", "") + ": " + reason);
|
mostLimiting.add(translateFrom(from) + ": " + reason);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +111,7 @@ public class Constraint<T extends Comparable> {
|
||||||
if (count++ != 0) sb.append("\n");
|
if (count++ != 0) sb.append("\n");
|
||||||
sb.append(r);
|
sb.append(r);
|
||||||
}
|
}
|
||||||
if (L.isEnabled(L.APS))
|
if (L.isEnabled(L.CONSTRAINTS))
|
||||||
log.debug("Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString());
|
log.debug("Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString());
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
@ -113,6 +127,7 @@ public class Constraint<T extends Comparable> {
|
||||||
if (count++ != 0) sb.append("\n");
|
if (count++ != 0) sb.append("\n");
|
||||||
sb.append(r);
|
sb.append(r);
|
||||||
}
|
}
|
||||||
|
if (L.isEnabled(L.CONSTRAINTS))
|
||||||
log.debug("Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString());
|
log.debug("Limiting origial value: " + originalValue + " to " + value + ". Reason: " + sb.toString());
|
||||||
return sb.toString();
|
return sb.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -86,7 +86,7 @@ public class L {
|
||||||
public static final String DATAFOOD = "DATAFOOD";
|
public static final String DATAFOOD = "DATAFOOD";
|
||||||
public static final String DATATREATMENTS = "DATATREATMENTS";
|
public static final String DATATREATMENTS = "DATATREATMENTS";
|
||||||
public static final String NSCLIENT = "NSCLIENT";
|
public static final String NSCLIENT = "NSCLIENT";
|
||||||
public static final String OBJECTIVES = "OBJECTIVES";
|
public static final String CONSTRAINTS = "CONSTRAINTS";
|
||||||
public static final String PUMP = "PUMP";
|
public static final String PUMP = "PUMP";
|
||||||
public static final String PUMPQUEUE = "PUMPQUEUE";
|
public static final String PUMPQUEUE = "PUMPQUEUE";
|
||||||
public static final String PUMPCOMM = "PUMPCOMM";
|
public static final String PUMPCOMM = "PUMPCOMM";
|
||||||
|
@ -102,6 +102,7 @@ public class L {
|
||||||
logElements.add(new LogElement(AUTOSENS, true));
|
logElements.add(new LogElement(AUTOSENS, true));
|
||||||
logElements.add(new LogElement(BGSOURCE, true));
|
logElements.add(new LogElement(BGSOURCE, true));
|
||||||
logElements.add(new LogElement(CONFIGBUILDER, true));
|
logElements.add(new LogElement(CONFIGBUILDER, true));
|
||||||
|
logElements.add(new LogElement(CONSTRAINTS, true));
|
||||||
logElements.add(new LogElement(CORE, true));
|
logElements.add(new LogElement(CORE, true));
|
||||||
logElements.add(new LogElement(DATABASE, true));
|
logElements.add(new LogElement(DATABASE, true));
|
||||||
logElements.add(new LogElement(DATAFOOD, true));
|
logElements.add(new LogElement(DATAFOOD, true));
|
||||||
|
@ -110,7 +111,6 @@ public class L {
|
||||||
logElements.add(new LogElement(EVENTS, false, true));
|
logElements.add(new LogElement(EVENTS, false, true));
|
||||||
logElements.add(new LogElement(NOTIFICATION, true));
|
logElements.add(new LogElement(NOTIFICATION, true));
|
||||||
logElements.add(new LogElement(NSCLIENT, true));
|
logElements.add(new LogElement(NSCLIENT, true));
|
||||||
logElements.add(new LogElement(OBJECTIVES, false));
|
|
||||||
logElements.add(new LogElement(OVERVIEW, true));
|
logElements.add(new LogElement(OVERVIEW, true));
|
||||||
logElements.add(new LogElement(PROFILE, true));
|
logElements.add(new LogElement(PROFILE, true));
|
||||||
logElements.add(new LogElement(PUMP, true));
|
logElements.add(new LogElement(PUMP, true));
|
||||||
|
|
|
@ -33,7 +33,7 @@ import info.nightscout.utils.SP;
|
||||||
* Created by mike on 05.08.2016.
|
* Created by mike on 05.08.2016.
|
||||||
*/
|
*/
|
||||||
public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface {
|
public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface {
|
||||||
private static Logger log = LoggerFactory.getLogger(L.OBJECTIVES);
|
private static Logger log = LoggerFactory.getLogger(L.CONSTRAINTS);
|
||||||
|
|
||||||
private static ObjectivesPlugin objectivesPlugin;
|
private static ObjectivesPlugin objectivesPlugin;
|
||||||
|
|
||||||
|
@ -95,7 +95,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
|
||||||
SP.putBoolean("Objectives" + "bgIsAvailableInNS", bgIsAvailableInNS);
|
SP.putBoolean("Objectives" + "bgIsAvailableInNS", bgIsAvailableInNS);
|
||||||
SP.putBoolean("Objectives" + "pumpStatusIsAvailableInNS", pumpStatusIsAvailableInNS);
|
SP.putBoolean("Objectives" + "pumpStatusIsAvailableInNS", pumpStatusIsAvailableInNS);
|
||||||
SP.putString("Objectives" + "manualEnacts", Integer.toString(manualEnacts));
|
SP.putString("Objectives" + "manualEnacts", Integer.toString(manualEnacts));
|
||||||
if (L.isEnabled(L.OBJECTIVES))
|
if (L.isEnabled(L.CONSTRAINTS))
|
||||||
log.debug("Objectives stored");
|
log.debug("Objectives stored");
|
||||||
MainApp.bus().post(new EventObjectivesSaved());
|
MainApp.bus().post(new EventObjectivesSaved());
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ public class ObjectivesPlugin extends PluginBase implements ConstraintsInterface
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Unhandled exception", e);
|
log.error("Unhandled exception", e);
|
||||||
}
|
}
|
||||||
if (L.isEnabled(L.OBJECTIVES))
|
if (L.isEnabled(L.CONSTRAINTS))
|
||||||
log.debug("Objectives loaded");
|
log.debug("Objectives loaded");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue