diff --git a/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/StatsControlDlg.java b/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/StatsControlDlg.java index f0e6940301..21a58bfe03 100644 --- a/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/StatsControlDlg.java +++ b/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/StatsControlDlg.java @@ -378,6 +378,7 @@ public class StatsControlDlg extends CaveSWTDialog implements IStatsControl, displayBtn.setLayoutData(btnData); displayBtn.setText("Display"); displayBtn.setToolTipText("Display the Statistical Data"); + displayBtn.setEnabled(false); displayBtn.addSelectionListener(new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { diff --git a/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/StatsDisplayCanvas.java b/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/StatsDisplayCanvas.java index 8839bbe745..cb1b43e1ba 100644 --- a/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/StatsDisplayCanvas.java +++ b/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/StatsDisplayCanvas.java @@ -53,6 +53,7 @@ import org.eclipse.swt.widgets.Shell; import com.raytheon.uf.common.stats.data.DataPoint; import com.raytheon.uf.common.stats.data.GraphData; import com.raytheon.uf.common.stats.data.StatsData; +import com.raytheon.uf.common.stats.util.DataViewUtils; import com.raytheon.uf.common.time.TimeRange; import com.raytheon.uf.common.time.util.TimeUtil; import com.raytheon.uf.viz.core.RGBColors; @@ -193,6 +194,9 @@ public class StatsDisplayCanvas extends Canvas { /** Largest value in the data set */ private double maxValue; + private String view = DataViewUtils.DataView.AVG.getView(); // Defaults to + // average + /** * Constructor * @@ -565,20 +569,19 @@ public class StatsDisplayCanvas extends Canvas { Map groupSettings = callback.getGroupSettings(); - double minVal = graphData.getMinValue(groupSettings.keySet()); - double maxVal = graphData.getMaxValue(groupSettings.keySet()); + double minVal = graphData.getMinValue(groupSettings.keySet(), view); + double maxVal = graphData.getMaxValue(groupSettings.keySet(), view); int numberTicks = 4; double inc = 5; double minScaleVal = 0; double maxScaleVal = 10; - if (minVal != minValue || maxVal != maxValue) { - scalingManager = new ScaleManager(minVal, maxVal); - numberTicks = scalingManager.getMajorTickCount(); - inc = scalingManager.getMajorTickIncrement(); + scalingManager = new ScaleManager(minVal, maxVal); + numberTicks = scalingManager.getMajorTickCount(); + inc = scalingManager.getMajorTickIncrement(); + + minScaleVal = scalingManager.getMinScaleValue(); + maxScaleVal = scalingManager.getMaxScaleValue(); - minScaleVal = scalingManager.getMinScaleValue(); - maxScaleVal = scalingManager.getMaxScaleValue(); - } double yVal = minScaleVal; // Draw the axis tick marks @@ -612,7 +615,8 @@ public class StatsDisplayCanvas extends Canvas { String unit = this.graphData.getDisplayUnit(); StringBuilder yAxisLabel = new StringBuilder(graphTitle); - if (unit != null && !unit.equalsIgnoreCase(COUNT) && unit.length() > 0) { + if (unit != null && !unit.equalsIgnoreCase(COUNT) && unit.length() > 0 + && !view.equals(DataViewUtils.DataView.COUNT.getView())) { yAxisLabel.append(" (").append(unit).append(")"); } @@ -668,7 +672,23 @@ public class StatsDisplayCanvas extends Canvas { int lastYpix = -999; for (DataPoint point : dataMap) { long x = point.getX(); - double y = point.getY(); + double y; + + if (view.equals(DataViewUtils.DataView.AVG + .getView())) { + y = point.getAvg(); + } else if (view.equals(DataViewUtils.DataView.MIN + .getView())) { + y = point.getMin(); + } else if (view.equals(DataViewUtils.DataView.MAX + .getView())) { + y = point.getMax(); + } else if (view.equals(DataViewUtils.DataView.SUM + .getView())) { + y = point.getSum(); + } else { + y = point.getCount(); + } int yPix = y2pixel(minScaleVal, maxScaleVal, y); int xPix = (int) ((x - startMillis) / millisPerPixelX + GRAPH_BORDER); @@ -750,7 +770,7 @@ public class StatsDisplayCanvas extends Canvas { sb.append(key).append(colon); DataPoint point = graphData.getStatsData(key) .getData(key).get(idx); - sb.append(point.getSampleText()); + sb.append(point.getSampleText(view)); } } idx++; @@ -823,4 +843,12 @@ public class StatsDisplayCanvas extends Canvas { public void setGraphData(GraphData graphData) { this.graphData = graphData; } + + /** + * Set the view type. + * @param view The view type + */ + public void setView(String view) { + this.view = view; + } } diff --git a/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/StatsGraphDlg.java b/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/StatsGraphDlg.java index 38bef14d5c..1a9e209d87 100644 --- a/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/StatsGraphDlg.java +++ b/cave/com.raytheon.uf.viz.stats/src/com/raytheon/uf/viz/stats/ui/StatsGraphDlg.java @@ -19,6 +19,7 @@ **/ package com.raytheon.uf.viz.stats.ui; +import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -33,9 +34,11 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Combo; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.FileDialog; +import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Layout; import org.eclipse.swt.widgets.Menu; import org.eclipse.swt.widgets.MenuItem; @@ -45,6 +48,7 @@ import org.eclipse.swt.widgets.Shell; import com.raytheon.uf.common.stats.GraphDataRequest; import com.raytheon.uf.common.stats.GraphDataResponse; import com.raytheon.uf.common.stats.data.GraphData; +import com.raytheon.uf.common.stats.util.DataViewUtils; import com.raytheon.uf.common.status.IUFStatusHandler; import com.raytheon.uf.common.status.UFStatus; import com.raytheon.uf.common.status.UFStatus.Priority; @@ -136,6 +140,9 @@ public class StatsGraphDlg extends CaveSWTDialog implements IStatsDisplay, /** Data type (field) of the data */ private String dataTypeID; + /** Data view combo */ + private Combo viewCombo; + /** * Constructor. * @@ -197,9 +204,43 @@ public class StatsGraphDlg extends CaveSWTDialog implements IStatsDisplay, groupComp.setLayout(gl); groupComp.setLayoutData(gd); - gd = new GridData(SWT.CENTER, SWT.DEFAULT, false, true); + gd = new GridData(SWT.FILL, SWT.DEFAULT, false, true); + gl = new GridLayout(2, false); + Composite ctrlComp = new Composite(leftComp, SWT.NONE); + ctrlComp.setLayout(gl); + ctrlComp.setLayoutData(gd); + + gd = new GridData(SWT.LEFT, SWT.DEFAULT, false, true); + gl = new GridLayout(2, false); + Composite dataComp = new Composite(ctrlComp, SWT.NONE); + dataComp.setLayout(gl); + dataComp.setLayoutData(gd); + + Label graphLabel = new Label(dataComp, SWT.NONE); + graphLabel.setText("Graph: "); + + List viewList = new ArrayList(); + viewList.add(DataViewUtils.DataView.AVG.getView()); + viewList.add(DataViewUtils.DataView.MIN.getView()); + viewList.add(DataViewUtils.DataView.MAX.getView()); + viewList.add(DataViewUtils.DataView.SUM.getView()); + viewList.add(DataViewUtils.DataView.COUNT.getView()); + + gd = new GridData(SWT.LEFT, SWT.CENTER, true, false); + viewCombo = new Combo(dataComp, SWT.READ_ONLY); + viewCombo.setLayoutData(gd); + viewCombo.setItems(viewList.toArray(new String[viewList.size()])); + viewCombo.select(0); + viewCombo.addSelectionListener(new SelectionAdapter() { + @Override + public void widgetSelected(SelectionEvent e) { + handleDataViewChange(); + } + }); + + gd = new GridData(SWT.CENTER, SWT.DEFAULT, true, true); gl = new GridLayout(4, false); - Composite btnComp = new Composite(leftComp, SWT.NONE); + Composite btnComp = new Composite(ctrlComp, SWT.NONE); btnComp.setLayout(gl); btnComp.setLayoutData(gd); @@ -511,6 +552,15 @@ public class StatsGraphDlg extends CaveSWTDialog implements IStatsDisplay, } } + /** + * Handler for data view combo box change. + */ + private void handleDataViewChange() { + String view = viewCombo.getText(); + this.displayCanvas.setView(view); + this.displayCanvas.redraw(); + } + /** * {@inheritDoc} */ diff --git a/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/data/DataPoint.java b/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/data/DataPoint.java index 5fc6e2f8ae..569bd719cd 100644 --- a/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/data/DataPoint.java +++ b/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/data/DataPoint.java @@ -19,6 +19,7 @@ **/ package com.raytheon.uf.common.stats.data; +import java.math.BigDecimal; import java.text.DecimalFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -30,21 +31,22 @@ import javax.xml.bind.annotation.XmlRootElement; import com.raytheon.uf.common.serialization.annotations.DynamicSerialize; import com.raytheon.uf.common.serialization.annotations.DynamicSerializeElement; +import com.raytheon.uf.common.stats.util.DataViewUtils; /** * Class holding an x,y data point and other associated information for the * point. - * + * *
- *
+ * 
  * SOFTWARE HISTORY
- *
+ * 
  * Date         Ticket#    Engineer    Description
  * ------------ ---------- ----------- --------------------------
  * Sep 7, 2012            mpduff     Initial creation
- *
+ * 
  * 
- * + * * @author mpduff * @version 1.0 */ @@ -78,12 +80,6 @@ public class DataPoint implements Comparable { @DynamicSerializeElement private long x; - /** - * Y value - */ - @DynamicSerializeElement - protected double y = 0.0; - /** * Text display for the sampling of this point */ @@ -92,38 +88,26 @@ public class DataPoint implements Comparable { /** Min value */ @DynamicSerializeElement - private double min = Integer.MAX_VALUE; + private BigDecimal min = new BigDecimal(Integer.MAX_VALUE); /** Max value */ @DynamicSerializeElement - private double max = Integer.MIN_VALUE; + private BigDecimal max = new BigDecimal(Integer.MIN_VALUE); /** Count */ @DynamicSerializeElement - private double count = 0; + private BigDecimal count = new BigDecimal(0); /** Sum */ @DynamicSerializeElement - private double sum; + private BigDecimal sum = new BigDecimal(0); /** Constructor */ public DataPoint() { - - } - - /** - * @return the y - */ - public double getY() { - return this.getAvg(); - } - - /** - * @param y - * the y to set - */ - public void setY(double y) { - this.y += y; + sum = sum.setScale(1, BigDecimal.ROUND_HALF_UP); + min = min.setScale(1, BigDecimal.ROUND_HALF_UP); + max = max.setScale(1, BigDecimal.ROUND_HALF_UP); + count = count.setScale(1, BigDecimal.ROUND_HALF_UP); } /** @@ -136,15 +120,15 @@ public class DataPoint implements Comparable { /** * Get the sample text for this point object - * + * * @return the sample text string */ - public String getSampleText() { + public String getSampleText(String view) { SimpleDateFormat dateFormat = sdf.get(); DecimalFormat decimalFormat = decFormat.get(); return dateFormat.format(new Date(x)) + "Z, " - + decimalFormat.format(getAvg()); + + decimalFormat.format(getValue(view)); } /** @@ -182,18 +166,20 @@ public class DataPoint implements Comparable { * @return the min */ public double getMin() { - return min; + return min.doubleValue(); } /** * Set the min value if it is less than the current min. - * + * * @param min * the min to set */ public void setMin(double min) { - if (this.min > min) { - this.min = min; + if (this.min.doubleValue() > min) { + BigDecimal m = new BigDecimal(min); + m = m.setScale(1, BigDecimal.ROUND_HALF_UP); + this.min = m; } } @@ -201,18 +187,19 @@ public class DataPoint implements Comparable { * @return the max */ public double getMax() { - return max; + return max.doubleValue(); } /** * Set the max value if it is greater than the current max. - * + * * @param max * the max to set */ public void setMax(double max) { - if (this.max < max) { - this.max = max; + if (this.max.doubleValue() < max) { + this.max = new BigDecimal(max); + this.max = this.max.setScale(1, BigDecimal.ROUND_HALF_UP); } } @@ -220,7 +207,7 @@ public class DataPoint implements Comparable { * @return the count */ public double getCount() { - return count; + return count.doubleValue(); } /** @@ -228,23 +215,26 @@ public class DataPoint implements Comparable { * the count to set */ public void setCount(double count) { - this.count = count; + this.count = new BigDecimal(count); + this.count = this.count.setScale(1, BigDecimal.ROUND_HALF_UP); } /** - * + * * @param count * the count to add */ public void addToCount(double count) { - this.count += count; + BigDecimal cnt = new BigDecimal(count); + cnt = cnt.setScale(1, BigDecimal.ROUND_HALF_UP); + this.count = this.count.add(cnt); } /** * @return the sum */ public double getSum() { - return sum; + return sum.doubleValue(); } /** @@ -252,17 +242,39 @@ public class DataPoint implements Comparable { * the sum to set */ public void setSum(double sum) { - this.sum += sum; + BigDecimal s = new BigDecimal(sum); + s = s.setScale(1, BigDecimal.ROUND_HALF_UP); + this.sum = this.sum.add(s); } /** * @return the avg */ public double getAvg() { - if (count > 0) { - return this.sum / count; + if (count.doubleValue() > 0) { + return sum.divide(count, BigDecimal.ROUND_HALF_UP).doubleValue(); } return 0; } + + /** + * Get the value for the provided data view type. + * + * @param view + * the view type + */ + public double getValue(String view) { + if (view.equals(DataViewUtils.DataView.AVG.getView())) { + return getAvg(); + } else if (view.equals(DataViewUtils.DataView.MIN.getView())) { + return getMin(); + } else if (view.equals(DataViewUtils.DataView.MAX.getView())) { + return getMax(); + } else if (view.equals(DataViewUtils.DataView.SUM.getView())) { + return getSum(); + } else { + return getCount(); + } + } } diff --git a/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/data/GraphData.java b/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/data/GraphData.java index f7f6b52b48..6e2cd9663c 100644 --- a/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/data/GraphData.java +++ b/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/data/GraphData.java @@ -197,11 +197,11 @@ public class GraphData { * * @return */ - public double getMinValue(Set visibleDataSet) { + public double getMinValue(Set visibleDataSet, String view) { double min = Double.MAX_VALUE; for (String key : statsDataMap.keySet()) { if (visibleDataSet.contains(key)) { - double minVal = statsDataMap.get(key).getMinValue(); + double minVal = statsDataMap.get(key).getMinValue(view); if (minVal < min) { min = minVal; } @@ -216,11 +216,11 @@ public class GraphData { * * @return */ - public double getMaxValue(Set visibleDataSet) { + public double getMaxValue(Set visibleDataSet, String view) { double max = Double.MIN_VALUE; for (String key : statsDataMap.keySet()) { if (visibleDataSet.contains(key)) { - double maxVal = statsDataMap.get(key).getMaxValue(); + double maxVal = statsDataMap.get(key).getMaxValue(view); if (maxVal > max) { max = maxVal; } diff --git a/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/data/StatsData.java b/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/data/StatsData.java index 19c3675ad6..f4677b1092 100644 --- a/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/data/StatsData.java +++ b/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/data/StatsData.java @@ -127,6 +127,36 @@ public class StatsData { return minValue; } + /** + * @return the minValue + */ + public Double getMinValue(String view) { + double minValue = Integer.MAX_VALUE; + + for (DataPoint point : pointList) { + if (point.getValue(view) < minValue) { + minValue = point.getValue(view); + } + } + + return minValue; + } + + /** + * @return the minValue + */ + public Double getMaxValue(String view) { + double maxValue = Integer.MIN_VALUE; + + for (DataPoint point : pointList) { + if (point.getValue(view) > maxValue) { + maxValue = point.getValue(view); + } + } + + return maxValue; + } + /** * @return the maxValue */ diff --git a/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/util/DataViewUtils.java b/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/util/DataViewUtils.java new file mode 100644 index 0000000000..a9566df815 --- /dev/null +++ b/edexOsgi/com.raytheon.uf.common.stats/src/com/raytheon/uf/common/stats/util/DataViewUtils.java @@ -0,0 +1,54 @@ +/** + * This software was developed and / or modified by Raytheon Company, + * pursuant to Contract DG133W-05-CQ-1067 with the US Government. + * + * U.S. EXPORT CONTROLLED TECHNICAL DATA + * This software product contains export-restricted data whose + * export/transfer/disclosure is restricted by U.S. law. Dissemination + * to non-U.S. persons whether in the United States or abroad requires + * an export license or other authorization. + * + * Contractor Name: Raytheon Company + * Contractor Address: 6825 Pine Street, Suite 340 + * Mail Stop B8 + * Omaha, NE 68106 + * 402.291.0100 + * + * See the AWIPS II Master Rights File ("Master Rights File.pdf") for + * further licensing information. + **/ +package com.raytheon.uf.common.stats.util; + +/** + * TODO Add Description + * + *
+ *
+ * SOFTWARE HISTORY
+ *
+ * Date         Ticket#    Engineer    Description
+ * ------------ ---------- ----------- --------------------------
+ * Nov 27, 2012            mpduff     Initial creation
+ *
+ * 
+ * + * @author mpduff + * @version 1.0 + */ + +public class DataViewUtils { + public enum DataView { + AVG("Average"), MIN("Minimum"), MAX("Maximum"), + SUM("Sum"), COUNT("Count"); + + private final String view; + + private DataView(String view) { + this.view = view; + } + + public String getView() { + return view; + } + } +}