better indicator coloring on monitoring

This commit is contained in:
anhefti 2019-11-06 15:11:59 +01:00
parent 38442dda25
commit 0d4e5c419a
4 changed files with 26 additions and 33 deletions

View file

@ -153,9 +153,9 @@ public class ClientConnectionDetails {
form.setFieldValue(indData.indicator.name, Constants.EMPTY_NOTE);
form.setFieldColor(indData.indicator.name, indData.defaultColor);
} else {
final int colorIndex = IndicatorData.getColorIndex(indData, value);
final Color color = (colorIndex >= 0)
? indData.thresholdColor[colorIndex].color
final int weight = IndicatorData.getWeight(indData, value);
final Color color = (weight >= 0 && weight < indData.thresholdColor.length)
? indData.thresholdColor[weight].color
: indData.defaultColor;
form.setFieldValue(indData.indicator.name, String.valueOf(value));
form.setFieldColor(indData.indicator.name, color);

View file

@ -260,7 +260,8 @@ public final class ClientConnectionTable {
final Long connectionId;
private boolean changed = false;
private ClientConnectionData connectionData;
private int[] thresholdColorIndices;
private int indicatorWeight;
//private int[] thresholdColorIndices;
private boolean duplicateChecked = false;
UpdatableTableItem(final Long connectionId) {
@ -331,9 +332,10 @@ public final class ClientConnectionTable {
indicatorData.defaultColor);
} else {
tableItem.setText(indicatorData.index, getDisplayValue(indicatorValue));
final Color color = (this.thresholdColorIndices[i] >= 0)
? indicatorData.thresholdColor[this.thresholdColorIndices[i]].color
: indicatorData.defaultColor;
final Color color =
(this.indicatorWeight >= 0 && this.indicatorWeight < indicatorData.thresholdColor.length)
? indicatorData.thresholdColor[this.indicatorWeight].color
: indicatorData.defaultColor;
tableItem.setBackground(indicatorData.index, color);
}
}
@ -352,15 +354,7 @@ public final class ClientConnectionTable {
}
int thresholdsWeight() {
if (this.thresholdColorIndices == null) {
return 100;
}
int weight = 0;
for (int i = 0; i < this.thresholdColorIndices.length; i++) {
weight += this.thresholdColorIndices[i];
}
return 100 - weight;
return this.indicatorWeight;
}
String getStatusName() {
@ -396,21 +390,17 @@ public final class ClientConnectionTable {
ClientConnectionTable.this.needsSort = true;
}
if (this.thresholdColorIndices == null) {
this.thresholdColorIndices = new int[connectionData.indicatorValues.size()];
}
for (int i = 0; i < connectionData.indicatorValues.size(); i++) {
final IndicatorValue indicatorValue = connectionData.indicatorValues.get(i);
final IndicatorData indicatorData =
ClientConnectionTable.this.indicatorMapping.get(indicatorValue.getType());
final double value = indicatorValue.getValue();
final int colorIndex = IndicatorData.getColorIndex(indicatorData, value);
if (this.thresholdColorIndices[i] != colorIndex) {
final int indicatorWeight = IndicatorData.getWeight(indicatorData, value);
if (this.indicatorWeight != indicatorWeight) {
ClientConnectionTable.this.needsSort = true;
}
this.thresholdColorIndices[i] = colorIndex;
this.indicatorWeight = indicatorWeight;
}
this.connectionData = connectionData;

View file

@ -50,15 +50,18 @@ final class IndicatorData {
return indicatorMapping;
}
static final int getColorIndex(final IndicatorData indicatorData, final double value) {
final int top = indicatorData.thresholdColor.length - 1;
for (int j = 0; j < top; j++) {
if (value > indicatorData.thresholdColor[j].value && value < indicatorData.thresholdColor[j + 1].value) {
return j;
static final int getWeight(final IndicatorData indicatorData, final double value) {
for (int j = 0; j < indicatorData.thresholdColor.length; j++) {
if (value < indicatorData.thresholdColor[j].value) {
if (j == 0) {
return -1;
} else {
return j - 1;
}
}
}
return top;
return indicatorData.thresholdColor.length - 1;
}
static final class ThresholdColor {

View file

@ -78,8 +78,8 @@ public class HTTPClientBot {
public HTTPClientBot(final Map<String, String> args) {
//this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://ralph.ethz.ch:8080");
this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://localhost:8080");
this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://ralph.ethz.ch:8080");
//this.webserviceAddress = args.getOrDefault("webserviceAddress", "http://localhost:8080");
//this.webserviceAddress = args.getOrDefault("webserviceAddress", "https://seb.test-swissmooc.ch");
this.accessTokenEndpoint = args.getOrDefault("accessTokenEndpoint", "/oauth/token");
@ -91,10 +91,10 @@ public class HTTPClientBot {
// args.getOrDefault("clientSecret", "CSXh6tQ^fdi00(XdL%6xic{q-5YlEE@Yc$Rg}H1f}JPt=P5PGH+KOhCW}oYSiC3L");
this.apiPath = args.getOrDefault("apiPath", "/exam-api");
this.apiVersion = args.getOrDefault("apiVersion", "v1");
// this.examId = args.getOrDefault("examId", "2");
// this.institutionId = args.getOrDefault("institutionId", "1");
this.examId = args.getOrDefault("examId", "2");
this.institutionId = args.getOrDefault("institutionId", "1");
// this.examId = args.getOrDefault("examId", "1");
// this.institutionId = args.getOrDefault("institutionId", "2");
this.numberOfConnections = Integer.parseInt(args.getOrDefault("numberOfConnections", "4"));
this.pingInterval = Long.parseLong(args.getOrDefault("pingInterval", "200"));
this.errorInterval = Long.parseLong(args.getOrDefault("errorInterval", String.valueOf(TEN_SECONDS)));