From 46b7a35134b15146d84ac91cf173b4739b056f92 Mon Sep 17 00:00:00 2001 From: Jonathan Sanchez Date: Tue, 7 Aug 2012 14:50:15 -0500 Subject: [PATCH] Issue #883 Sorted warning records and prevented altered entries to be in the same frame as new entries. Former-commit-id: 457cbcdf9540f7f767bbbf13d67dcd03d7424487 [formerly 4f2d6630c18c7cb71d9af2de91e390952bcb0876] [formerly 6507a97665adf8b6ba63577b65926d7e95b5492d] [formerly fa7795d17feb60867c6b2008cab2595522620fc5 [formerly 6507a97665adf8b6ba63577b65926d7e95b5492d [formerly 5c8c0783c8e054792ac38b4487188495dd0b0319]]] Former-commit-id: fa7795d17feb60867c6b2008cab2595522620fc5 Former-commit-id: faff7eb8279d6805bdc05f6ec705924a3bd4c05e [formerly 7ad6329fe041c7959c91d8d101d6177b4ee2ddc3] Former-commit-id: 3952dfc7ac47ba8029ee4cd767f8614a67e3b62e --- .../viz/warnings/rsc/AbstractWWAResource.java | 4 +- .../warnings/rsc/AbstractWarningResource.java | 33 ++++++----- .../warnings/rsc/WarningRecordComparator.java | 24 ++++++-- .../viz/warnings/rsc/WarningsResource.java | 57 ++++++++++++++----- .../viz/warnings/rsc/WatchesResource.java | 2 - 5 files changed, 83 insertions(+), 37 deletions(-) diff --git a/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/AbstractWWAResource.java b/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/AbstractWWAResource.java index 4d4d745e22..266fb382aa 100644 --- a/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/AbstractWWAResource.java +++ b/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/AbstractWWAResource.java @@ -31,7 +31,7 @@ import com.raytheon.viz.warnings.DateUtil; * Aug 5, 2011 njensen Refactored maps * Aug 22, 2011 10631 njensen Major refactor * May 31, 2012 DR14992 mgamazaychikov Changed the order of strings in the - * String array returned from getText method + * String array returned from getText method * Jun 04, 2012 DR14992 mgamazaychikov Reversed the previous changes * * @@ -62,6 +62,8 @@ public abstract class AbstractWWAResource extends this.recordsToLoad = new ArrayList(); } + protected final WarningRecordComparator comparator = new WarningRecordComparator(); + /* * (non-Javadoc) * diff --git a/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/AbstractWarningResource.java b/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/AbstractWarningResource.java index 01c2c12ded..792db841d0 100644 --- a/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/AbstractWarningResource.java +++ b/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/AbstractWarningResource.java @@ -236,6 +236,8 @@ public abstract class AbstractWarningResource extends AbstractWWAResource protected Date timeAltered; + protected Date frameAltered; + /** * was the alter a partial cancel? if it was then a matching CON should * be processed and added @@ -364,7 +366,7 @@ public abstract class AbstractWarningResource extends AbstractWWAResource int frameIdx = framesInfo.getFrameIndex(); DataTime[] frameTimes = framesInfo.getFrameTimes(); if (frameIdx < 0 || frameIdx >= frameTimes.length) - return "NO DATA"; + return "NO DATA"; DataTime time = frameTimes[frameIdx]; TimeRange framePeriod = null; @@ -580,9 +582,9 @@ public abstract class AbstractWarningResource extends AbstractWWAResource // DR14992: reverse the textToPrint array to plot the strings in correct order String [] textToPrintReversed = new String[textToPrint.length]; for(int i = 0; i < textToPrint.length; i++) { - textToPrintReversed[i] = textToPrint[textToPrint.length - - i - 1]; - } + textToPrintReversed[i] = textToPrint[textToPrint.length + - i - 1]; + } DrawableString params = new DrawableString(textToPrintReversed, color); @@ -627,18 +629,19 @@ public abstract class AbstractWarningResource extends AbstractWWAResource // check if the warning is cancelled WarningAction action = WarningAction.valueOf(entry.record.getAct()); - if (action == WarningAction.CAN - && refTime.equals(paintTime)) { + if (action == WarningAction.CAN && refTime.equals(paintTime)) { return false; - // If this entry has been altered/updated, display its pre-altered version - // only in the frames prior to the time it was altered - } else if (entry.altered){ - if (frameStart.getTime() >= refTime.getTime() && - frameStart.getTime() < (entry.timeAltered.getTime())) - return true; - if (frameStart.getTime() >= (entry.timeAltered.getTime())) - return false; - + // If this entry has been altered/updated, display its pre-altered + // version + // only in the frames prior to the time it was altered + } else if (entry.altered) { + if (frameStart.getTime() >= refTime.getTime() + && frameStart.getTime() < (entry.timeAltered.getTime()) + && frameStart.getTime() < entry.frameAltered.getTime()) + return true; + if (frameStart.getTime() >= (entry.timeAltered.getTime())) + return false; + } else if (refTime.equals(paintTime) || recordPeriod.contains(frameTime) || (framePeriod.contains(centerTime) && (!lastFrame || !entry.altered))) { diff --git a/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/WarningRecordComparator.java b/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/WarningRecordComparator.java index 00bda74ed1..e36b291b9b 100644 --- a/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/WarningRecordComparator.java +++ b/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/WarningRecordComparator.java @@ -3,11 +3,12 @@ package com.raytheon.viz.warnings.rsc; import java.util.Comparator; import com.raytheon.uf.common.dataplugin.warning.AbstractWarningRecord; +import com.raytheon.uf.common.dataplugin.warning.WarningRecord.WarningAction; /** * - * Sorts the WarningRecords by phenSig, ETN, starttime (descending order), then - * action + * Compares the WarningRecords by phenSig, ETN, action, then starttime + * (descending order) * *
  * 
@@ -24,6 +25,11 @@ import com.raytheon.uf.common.dataplugin.warning.AbstractWarningRecord;
  */
 public class WarningRecordComparator implements
         Comparator {
+
+    /**
+     * Compares the WarningRecords by phenSig, ETN, action, then starttime
+     * (descending order)
+     */
     public int compare(AbstractWarningRecord wr1, AbstractWarningRecord wr2) {
         int rval = 0;
 
@@ -33,10 +39,20 @@ public class WarningRecordComparator implements
             rval = Double.compare(Double.parseDouble(wr1.getEtn()),
                     Double.parseDouble(wr2.getEtn()));
             if (rval == 0) {
-                rval = -1 * wr1.getStartTime().compareTo(wr2.getStartTime());
-                if (rval == 0) {
+                if (wr1.getAct().equals(wr2.getAct())) {
+                    rval = 0;
+                } else if (wr1.getAct().equals(WarningAction.NEW.toString())) {
+                    rval = -1;
+                } else if (wr2.getAct().equals(WarningAction.NEW.toString())) {
+                    rval = 1;
+                } else {
                     rval = wr1.getAct().compareTo(wr2.getAct());
                 }
+
+                if (rval == 0) {
+                    rval = -1
+                            * wr1.getStartTime().compareTo(wr2.getStartTime());
+                }
             }
         }
         return rval;
diff --git a/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/WarningsResource.java b/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/WarningsResource.java
index 3c7e317401..586cd0750d 100644
--- a/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/WarningsResource.java
+++ b/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/WarningsResource.java
@@ -20,7 +20,9 @@
 
 package com.raytheon.viz.warnings.rsc;
 
+import java.util.ArrayList;
 import java.util.Calendar;
+import java.util.Collections;
 import java.util.Map;
 
 import com.raytheon.uf.common.dataplugin.PluginDataObject;
@@ -35,6 +37,7 @@ import com.raytheon.uf.common.time.DataTime;
 import com.raytheon.uf.viz.core.IGraphicsTarget;
 import com.raytheon.uf.viz.core.catalog.LayerProperty;
 import com.raytheon.uf.viz.core.datastructure.DataCubeContainer;
+import com.raytheon.uf.viz.core.drawables.IDescriptor.FramesInfo;
 import com.raytheon.uf.viz.core.drawables.IWireframeShape;
 import com.raytheon.uf.viz.core.exception.VizException;
 import com.raytheon.uf.viz.core.rsc.LoadProperties;
@@ -53,10 +56,10 @@ import com.vividsolutions.jts.geom.Geometry;
  * ------------ ---------- ----------- --------------------------
  * Sep 1, 2010            jsanchez     Initial creation
  * Aug 22, 2011  10631   njensen  Major refactor
- * May 3, 2012	DR 14741  porricel	   Stop setting end time of orig.
+ * May 3, 2012  DR 14741  porricel     Stop setting end time of orig.
  *                                     warning to start time of update.
  * Jun 04, 2012 DR14992  mgamazaychikov Fix the problem with plotting expiration time for 
- *										NEW warning when CAN warning is issued 
+ *                                  NEW warning when CAN warning is issued
  * 
  * 
* @@ -78,6 +81,8 @@ public class WarningsResource extends AbstractWarningResource { @Override protected synchronized void updateDisplay(IGraphicsTarget target) { if (!this.recordsToLoad.isEmpty()) { + FramesInfo info = getDescriptor().getFramesInfo(); + DataTime[] frames = info.getFrameTimes(); for (AbstractWarningRecord warnrec : recordsToLoad) { WarningAction act = WarningAction.valueOf(warnrec.getAct()); if (act == WarningAction.CON || act == WarningAction.CAN @@ -93,19 +98,26 @@ public class WarningsResource extends AbstractWarningResource { if (!entry.altered) { // if it's a con, can, exp, or ext mark the - // original one as altered + // original one as altered entry.altered = true; - //make note of alteration time without - //changing end time - entry.timeAltered = warnrec.getStartTime().getTime(); - - //if cancellation, set end time to start time - //of this action - - // DR14992: fix the problem with plotting expiration time for - // NEW warning when CAN warning is issued - if(act == WarningAction.CAN && - WarningAction.valueOf(entry.record.getAct()) == WarningAction.CAN) { + // make note of alteration time without + // changing end time + entry.timeAltered = warnrec.getStartTime() + .getTime(); + // prevents the original entry and the modified + // entry to be displayed in the same frame + entry.frameAltered = frames[info + .getFrameIndex()].getRefTime(); + + // if cancellation, set end time to start time + // of this action + + // DR14992: fix the problem with plotting + // expiration time for + // NEW warning when CAN warning is issued + if (act == WarningAction.CAN + && WarningAction.valueOf(entry.record + .getAct()) == WarningAction.CAN) { entry.record.setEndTime((Calendar) warnrec .getStartTime().clone()); } @@ -235,7 +247,22 @@ public class WarningsResource extends AbstractWarningResource { arr[i] = (PluginDataObject) o; i++; } - addRecord(arr); + addRecord(sort(arr)); + } + + private PluginDataObject[] sort(PluginDataObject[] pdos) { + ArrayList sortedWarnings = new ArrayList(); + for (Object o : pdos) { + if (((PluginDataObject) o) instanceof AbstractWarningRecord) { + AbstractWarningRecord record = (AbstractWarningRecord) o; + sortedWarnings.add(record); + } + } + + /* Sorts by phensig, etn, starttime (descending), act */ + Collections.sort(sortedWarnings, comparator); + return sortedWarnings.toArray(new AbstractWarningRecord[sortedWarnings + .size()]); } } diff --git a/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/WatchesResource.java b/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/WatchesResource.java index 0e5762b4c4..ddd7f78d08 100644 --- a/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/WatchesResource.java +++ b/cave/com.raytheon.viz.warnings/src/com/raytheon/viz/warnings/rsc/WatchesResource.java @@ -42,8 +42,6 @@ public class WatchesResource extends AbstractWatchesResource { private Map> geometryMap = new HashMap>(); - private final WarningRecordComparator comparator = new WarningRecordComparator(); - public WatchesResource(WWAResourceData data, LoadProperties props) { super(data, props); }