Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
[BZ 1080470] - The unit in the new d3 charts is not refreshed correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtho11 committed Apr 17, 2014
1 parent 0209557 commit 82b9324
Showing 1 changed file with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
import org.rhq.coregui.client.inventory.common.graph.graphtype.StackedBarMetricGraphImpl;
import org.rhq.coregui.client.util.Log;
import org.rhq.coregui.client.util.MeasurementConverterClient;
import org.rhq.coregui.client.util.MeasurementUtility;


/**
Expand Down Expand Up @@ -358,7 +357,6 @@ public String getXAxisTimeFormatHoursMinutes() {
*/
public String getJsonMetrics() {
StringBuilder sb = new StringBuilder();
boolean gotAdjustedMeasurementUnits = false;
if (null != metricData) {
sb = new StringBuilder("[");
long firstBarTime = metricData.get(0).getTimestamp();
Expand All @@ -369,6 +367,21 @@ public String getJsonMetrics() {

calculateOOB();

// find the lowest value and use it's UOM to translated everything else into
MeasurementDataNumericHighLowComposite lowestValue = null;
for (MeasurementDataNumericHighLowComposite measurement : metricData) {
if(!Double.isNaN(measurement.getValue())) {
if(null == lowestValue){
lowestValue = measurement;
}
if (measurement.getLowValue() < lowestValue.getLowValue()) {
lowestValue = measurement;
}
}
}
MeasurementNumericValueAndUnits adjustedMeasurementUnitsAndValue = MeasurementConverterClient.fit(lowestValue.getLowValue(), definition.getUnits());
adjustedMeasurementUnits = adjustedMeasurementUnitsAndValue.getUnits();

for (MeasurementDataNumericHighLowComposite measurement : metricData) {
sb.append("{ \"x\":" + measurement.getTimestamp() + ",");

Expand All @@ -379,14 +392,10 @@ public String getJsonMetrics() {

if (!Double.isNaN(measurement.getValue())) {

MeasurementNumericValueAndUnits newHigh = normalizeUnitsAndValues(measurement.getHighValue(), definition.getUnits());
MeasurementNumericValueAndUnits newAvg = normalizeUnitsAndValues(measurement.getValue(), definition.getUnits());
MeasurementNumericValueAndUnits newLow = normalizeUnitsAndValues(measurement.getLowValue(), definition.getUnits());
MeasurementNumericValueAndUnits newHigh = normalizeUnitsAndValues(measurement.getHighValue(), adjustedMeasurementUnits);
MeasurementNumericValueAndUnits newAvg = normalizeUnitsAndValues(measurement.getValue(), adjustedMeasurementUnits);
MeasurementNumericValueAndUnits newLow = normalizeUnitsAndValues(measurement.getLowValue(), adjustedMeasurementUnits);

if (!gotAdjustedMeasurementUnits) {
adjustedMeasurementUnits = newHigh.getUnits();
gotAdjustedMeasurementUnits = true;
}
sb.append(" \"barDuration\": \"" + barDurationString + "\", ");
sb.append(" \"high\":" + newHigh.getValue() + ",");
sb.append(" \"low\":" + cleanseLow(newLow.getValue(), newAvg.getValue(), newHigh.getValue()) + ",");
Expand All @@ -411,20 +420,10 @@ public String getJsonMetrics() {
}

public static MeasurementNumericValueAndUnits normalizeUnitsAndValues(double value, MeasurementUnits measurementUnits) {
MeasurementNumericValueAndUnits newValue = MeasurementConverterClient.fit(value, measurementUnits);
MeasurementNumericValueAndUnits returnValue;

// adjust for percentage numbers
if (measurementUnits.equals(MeasurementUnits.PERCENTAGE)) {
returnValue = new MeasurementNumericValueAndUnits(newValue.getValue() * 100, newValue.getUnits());
} else {
returnValue = new MeasurementNumericValueAndUnits(newValue.getValue(), newValue.getUnits());
}

return returnValue;
double adjustedValue = measurementUnits == MeasurementUnits.PERCENTAGE ? value * 100 : value;
return new MeasurementNumericValueAndUnits(MeasurementConverterClient.scale(adjustedValue, measurementUnits),measurementUnits);
}


/**
* This is cleaning the data as sometimes the data coming from the metric query
* is erroneous: for instance the low is greater than the high. This causes the
Expand Down

0 comments on commit 82b9324

Please sign in to comment.