diff --git a/RadarServer/build.rcm/cfgbits/data/config/drop-ins/cronOTRs.xml b/RadarServer/build.rcm/cfgbits/data/config/drop-ins/cronOTRs.xml index 8d07fc9780..0c532c4fb2 100644 --- a/RadarServer/build.rcm/cfgbits/data/config/drop-ins/cronOTRs.xml +++ b/RadarServer/build.rcm/cfgbits/data/config/drop-ins/cronOTRs.xml @@ -30,4 +30,6 @@ 34 16 34 32 + + \ No newline at end of file diff --git a/cave/build/static/common/cave/etc/bundles/DefaultRadarFourPanelBlendedBestRes.xml b/cave/build/static/common/cave/etc/bundles/DefaultRadarFourPanelBlendedBestRes.xml index dd08b6641a..6806261a7d 100644 --- a/cave/build/static/common/cave/etc/bundles/DefaultRadarFourPanelBlendedBestRes.xml +++ b/cave/build/static/common/cave/etc/bundles/DefaultRadarFourPanelBlendedBestRes.xml @@ -68,9 +68,9 @@ - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -224,9 +102,9 @@ - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -400,9 +156,9 @@ - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -574,9 +190,9 @@ - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -754,264 +230,70 @@ - + - + - - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1045,9 +327,9 @@ - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -1219,9 +361,9 @@ - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/cave/build/static/common/cave/etc/gfe/userPython/procedures/BOIVerifySave.py b/cave/build/static/common/cave/etc/gfe/userPython/procedures/BOIVerifySave.py index 4372cb3b3a..ed335f7835 100644 --- a/cave/build/static/common/cave/etc/gfe/userPython/procedures/BOIVerifySave.py +++ b/cave/build/static/common/cave/etc/gfe/userPython/procedures/BOIVerifySave.py @@ -485,18 +485,16 @@ class Procedure (SmartScript.SmartScript): # # get History of last time this grid was modified # + username = "" + updtime = None historyList=self.getGridHistory(dbid,parm,"SFC",gridTR) for hists in historyList: for hist in hists: if hist[4] not in [None, "None"]: username=hist[4].split(':')[1] - else: - username="" if hist[5] is not None: updtime=hist[5].unixTime() - else: - updtime = None if self.VU.getDebug()>=1: t2=self.gstring1(time.gmtime(updtime)) @@ -830,6 +828,7 @@ class Procedure (SmartScript.SmartScript): # different values from getComposite after IFPS16. # def getBetterComposite(self,parmName, timeRange): + from com.raytheon.uf.common.dataplugin.gfe.db.objects import GFERecord_GridType as GridType # # Get the type, rateParm flag, and limits # for the parameter name passed in. @@ -864,7 +863,7 @@ class Procedure (SmartScript.SmartScript): sum=self._empty+150.0 else: sum=self._empty - if (wxType==1): + if GridType.VECTOR.equals(wxType): sumv=self._empty cnt = zeros_like(self._empty) all = ones_like(self._empty) @@ -880,7 +879,7 @@ class Procedure (SmartScript.SmartScript): # # Add to sums, or min/max # - if wxType==0: # SCALAR + if GridType.SCALAR.equals(wxType): # SCALAR bits,isc=comp #isc=self.getGrids("ISC",parmName,"SFC",tr) # @@ -904,14 +903,14 @@ class Procedure (SmartScript.SmartScript): else: sum=where(bits,sum+isc,sum) cnt[bits] += 1 - if wxType==1: # VECTOR + if GridType.VECTOR.equals(wxType): # VECTOR bits,mag,direc=comp #(mag,dir)=self.getGrids("ISC",parmName,"SFC",tr) (u,v)=self.MagDirToUV(mag,direc) sum=where(bits,sum+u,sum) sumv=where(bits,sumv+v,sumv) cnt[bits] += 1 - if wxType==2: # WEATHER + if GridType.WEATHER.equals(wxType): # WEATHER bits,keys,strings=comp #(keys,strings)=self.getGrids("ISC",parmName,"SFC",tr) # @@ -920,9 +919,9 @@ class Procedure (SmartScript.SmartScript): # noISC=less(cnt,0.5) bits=greater(cnt,0.5) - if ((wxType==0)or(wxType==1)): + if GridType.SCALAR.equals(wxType) or GridType.VECTOR.equals(wxType): cnt[less(cnt,1)] = 1 - if (wxType==1): + if GridType.VECTOR.equals(wxType): sum=where(noISC,minlimit,sum/cnt) sumv=where(noISC,minlimit,sumv/cnt) (mag,direc)=self.UVToMagDir(sum,sumv) diff --git a/cave/build/static/common/cave/etc/gfe/userPython/procedures/PWS_Procedure.py b/cave/build/static/common/cave/etc/gfe/userPython/procedures/PWS_Procedure.py index 4d5baf8fbf..1ba41d4ae4 100644 --- a/cave/build/static/common/cave/etc/gfe/userPython/procedures/PWS_Procedure.py +++ b/cave/build/static/common/cave/etc/gfe/userPython/procedures/PWS_Procedure.py @@ -97,8 +97,8 @@ class Procedure (SmartScript.SmartScript): trList = [] for g in gridInfo: - start = g.gridTime().startTime().unixTime() - end = g.gridTime().endTime().unixTime() + start = g.gridTime().startTime().unixTime() * 1000 + end = g.gridTime().endTime().unixTime() * 1000 tr = TimeRange.TimeRange(start,end) if tr.overlaps(timeRange): trList.append(tr) @@ -243,7 +243,8 @@ class Procedure (SmartScript.SmartScript): modelTR_cum = self.getModelTimeRange(modelID, "prob34", weNames) weNames = ["pwsD34", "pwsD64", "pwsN34", "pwsN64"] modelTR_inc = self.getModelTimeRange(modelID, "pws34", weNames) - + if modelTR_cum is None or len(modelTR_cum) < 3: + return timeRange = modelTR_cum[0] minTime = modelTR_cum[1] maxTime = modelTR_cum[2] diff --git a/cave/build/static/common/cave/etc/gfe/userPython/utilities/BOIVerifyUtility.py b/cave/build/static/common/cave/etc/gfe/userPython/utilities/BOIVerifyUtility.py index c34271829b..09a02e0037 100644 --- a/cave/build/static/common/cave/etc/gfe/userPython/utilities/BOIVerifyUtility.py +++ b/cave/build/static/common/cave/etc/gfe/userPython/utilities/BOIVerifyUtility.py @@ -4367,13 +4367,13 @@ class BOIVerifyUtility(SmartScript.SmartScript): recmatch=logical_and(recbase,recfit) recnumbers=compress(recmatch,self.fncRecs) recList=list(recnumbers) - recList.sort(lambda x,y: cmp(self.fncStime[x],self.fncStime[y])) + recList.sort(lambda x,y: cmp(self.fncStime[int(x)],self.fncStime[int(y)])) else: recmatch=logical_and(greater(self.oncEtime,stime), less(self.oncStime,etime)) recnumbers=compress(recmatch,self.oncRecs) recList=list(recnumbers) - recList.sort(lambda x,y: cmp(self.oncStime[x],self.oncStime[y])) + recList.sort(lambda x,y: cmp(self.oncStime[int(x)],self.oncStime[int(y)])) self.logMsg("number of intersecting grids:%d"%len(recList),10) if len(recList)<1: return retVal diff --git a/cave/build/static/common/cave/etc/gfe/userPython/utilities/ProcessVariableList.py b/cave/build/static/common/cave/etc/gfe/userPython/utilities/ProcessVariableList.py index b0aed174cc..2e06dff604 100644 --- a/cave/build/static/common/cave/etc/gfe/userPython/utilities/ProcessVariableList.py +++ b/cave/build/static/common/cave/etc/gfe/userPython/utilities/ProcessVariableList.py @@ -54,10 +54,9 @@ class ProcessVariableList: ## The following arguments are no longer used but remain part of the signature for compatibility reasons ## * parent - not needed ## * modal - similar functionality is achieved by setting or not setting a callback - ## * dbSubsystem - not needed, see TODO + ## * dataMgr - required for model and D2D_model widgets ## * cmdLineVarDict - not needed, see TODO ## - ## TODO evaluate cmdLineVarDict and determine if it is really not needed ## TODO dbSubsytem may be needed when implementing the model and D2D_model widgets ## ## @param title: str() of the title of the dialog that will appear @@ -68,7 +67,7 @@ class ProcessVariableList: ## @param argList: list() of arguments to pass to the callback function ## def __init__(self, title, varList, varDict=None, parent=None, - dbSubsystem=None, modal=1, runCB=None, argList=[], + dataMgr=None, modal=1, runCB=None, argList=[], cmdLineVarDict=None): self.__varDict = varDict @@ -80,7 +79,7 @@ class ProcessVariableList: widgetList = buildWidgetList(varList) # Construct the dialog - self.__dialog = ValuesDialog.openDialog(title, widgetList) + self.__dialog = ValuesDialog.openDialog(title, widgetList, dataMgr) #self.__dialog = ValuesDialog(title,widgetList) # since ValuesDialog blocks on open() we can set status and varDict here diff --git a/cave/build/static/common/cave/etc/gfe/userPython/utilities/SmartScript.py b/cave/build/static/common/cave/etc/gfe/userPython/utilities/SmartScript.py index 9cd6a4cd40..2018230417 100644 --- a/cave/build/static/common/cave/etc/gfe/userPython/utilities/SmartScript.py +++ b/cave/build/static/common/cave/etc/gfe/userPython/utilities/SmartScript.py @@ -1838,12 +1838,8 @@ class SmartScript(BaseTool.BaseTool): # @rtype: list of strings def getDiscreteKeys(self, elementName): parm = self.getParm("Fcst", elementName, "SFC") - keyList = [] - inventory = parm.getGridInventory() - for gridData in inventory: - slice = gridData.getGridSlice() - for discreteKey in slice.getKey(): - keyList.append(discreteKey.toString()) + keyList = parm.getGridInfo().getDiscreteKeys() + keyList = JUtil.javaStringListToPylist(keyList) return keyList ######################################################################### diff --git a/cave/build/static/common/cave/etc/menus/upperair/baseUSEastern.xml b/cave/build/static/common/cave/etc/menus/upperair/baseUSEastern.xml index 70de133c32..cf8cccd01d 100644 --- a/cave/build/static/common/cave/etc/menus/upperair/baseUSEastern.xml +++ b/cave/build/static/common/cave/etc/menus/upperair/baseUSEastern.xml @@ -107,7 +107,7 @@ - + + + + diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/catalog/ScriptCreator.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/catalog/ScriptCreator.java index cbb4e4447e..94052790a2 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/catalog/ScriptCreator.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/catalog/ScriptCreator.java @@ -25,9 +25,9 @@ import java.io.IOException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.WeakHashMap; import org.eclipse.core.runtime.FileLocator; import org.eclipse.core.runtime.IConfigurationElement; @@ -48,7 +48,6 @@ import com.raytheon.uf.common.util.FileUtil; import com.raytheon.uf.viz.core.Activator; import com.raytheon.uf.viz.core.exception.VizException; import com.raytheon.uf.viz.core.localization.LocalizationManager; -import com.raytheon.uf.viz.core.status.StatusConstants; /** * Creates uEngine scripts on the fly. @@ -75,7 +74,8 @@ import com.raytheon.uf.viz.core.status.StatusConstants; * @version 1 */ public class ScriptCreator { - private static final transient IUFStatusHandler statusHandler = UFStatus.getHandler(ScriptCreator.class); + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(ScriptCreator.class); private static final String DEFAULT_SCRIPT_LIBRARY = "BaseRequest"; @@ -99,10 +99,10 @@ public class ScriptCreator { new Path("scriptTemplates/standardTemplate.vm"), null)).getPath()); } catch (IOException e) { - statusHandler.handle( - Priority.CRITICAL, - "Unable to load the standard script template. Requesting products will not work until this is fixed.", - e); + statusHandler + .handle(Priority.CRITICAL, + "Unable to load the standard script template. Requesting products will not work until this is fixed.", + e); } } @@ -148,7 +148,7 @@ public class ScriptCreator { return; } - pluginToLibraryMap = new WeakHashMap(); + pluginToLibraryMap = new HashMap(); IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtensionPoint point = registry.getExtensionPoint(RESOURCE_EXTENSION); diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapParameters.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapParameters.java index c3cd3ee7bc..3be9fb188e 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapParameters.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/drawables/ColorMapParameters.java @@ -938,7 +938,7 @@ public class ColorMapParameters implements Cloneable, ISerializableObject { index = 1.0f; } return colorToRGB(colorMap.getColors().get( - (int) (index * colorMap.getSize()))); + (int) (index * (colorMap.getSize()-1)))); } /** @@ -954,7 +954,7 @@ public class ColorMapParameters implements Cloneable, ISerializableObject { } else if (index > 1.0f) { index = 1.0f; } - return colorMap.getColors().get((int) (index * colorMap.getSize())); + return colorMap.getColors().get((int) (index * (colorMap.getSize()-1))); } public static RGB colorToRGB(Color c) { diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/capabilities/DisplayTypeCapability.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/capabilities/DisplayTypeCapability.java index 2fcb9d1f81..1e74333482 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/capabilities/DisplayTypeCapability.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/rsc/capabilities/DisplayTypeCapability.java @@ -19,6 +19,9 @@ **/ package com.raytheon.uf.viz.core.rsc.capabilities; +import java.util.Collections; +import java.util.List; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlAttribute; @@ -46,6 +49,8 @@ public class DisplayTypeCapability extends AbstractCapability { @XmlAttribute private DisplayType displayType = DisplayType.CONTOUR; + private transient List alternativeDisplayTypes; + public DisplayType getDisplayType() { return displayType; } @@ -54,6 +59,18 @@ public class DisplayTypeCapability extends AbstractCapability { this.displayType = displayType; } + public List getAlternativeDisplayTypes() { + if (alternativeDisplayTypes == null) { + return Collections.emptyList(); + } + return alternativeDisplayTypes; + } + + public void setAlternativeDisplayTypes( + List alternativeDisplayTypes) { + this.alternativeDisplayTypes = alternativeDisplayTypes; + } + /* * (non-Javadoc) * diff --git a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/style/StyleManager.java b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/style/StyleManager.java index d0d1f289df..fffc05d083 100644 --- a/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/style/StyleManager.java +++ b/cave/com.raytheon.uf.viz.core/src/com/raytheon/uf/viz/core/style/StyleManager.java @@ -41,7 +41,7 @@ import com.raytheon.uf.common.status.UFStatus.Priority; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * Sep 24, 2007 njensen Initial creation - * + * May 21, 2012 DR 14833 gzhang Adding a getter for StyleRuleset * * * @author njensen @@ -149,5 +149,24 @@ public class StyleManager { return new double[] { vmin, vmax }; } - + + /**2012-05-21 + * DR 14833: FFMP uses this getter to find the color + * map if a user modified ffmpImageryStlyeRules.xml + * incorrectly. + * + * @param st: StyleType + * @return: StyleRuleset related to the StyleType + */ + public StyleRuleset getStyleRuleSet(StyleType st){ + + synchronized(st){ + + if( ! rules.containsKey(st)){ + loadRules(st); + } + } + + return rules.get(st); + } } diff --git a/cave/com.raytheon.uf.viz.cwat/plugin.xml b/cave/com.raytheon.uf.viz.cwat/plugin.xml index c58dfe0aa0..09880f3eee 100644 --- a/cave/com.raytheon.uf.viz.cwat/plugin.xml +++ b/cave/com.raytheon.uf.viz.cwat/plugin.xml @@ -35,4 +35,17 @@ scriptLibrary="BaseRequest"> + + + + + + + diff --git a/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/sampling/D2DSamplingResource.java b/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/sampling/D2DSamplingResource.java index 937b4503de..255d055963 100644 --- a/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/sampling/D2DSamplingResource.java +++ b/cave/com.raytheon.uf.viz.d2d.core/src/com/raytheon/uf/viz/d2d/core/sampling/D2DSamplingResource.java @@ -140,7 +140,6 @@ public class D2DSamplingResource extends SamplingResource implements inspectForced = false; setSampling(false); issueRefresh(); - return true; } return false; } diff --git a/cave/com.raytheon.uf.viz.d2d.nsharp/src/com/raytheon/uf/viz/d2d/nsharp/display/D2DNSharpDescriptor.java b/cave/com.raytheon.uf.viz.d2d.nsharp/src/com/raytheon/uf/viz/d2d/nsharp/display/D2DNSharpDescriptor.java index 5b93ad130a..8f991be196 100644 --- a/cave/com.raytheon.uf.viz.d2d.nsharp/src/com/raytheon/uf/viz/d2d/nsharp/display/D2DNSharpDescriptor.java +++ b/cave/com.raytheon.uf.viz.d2d.nsharp/src/com/raytheon/uf/viz/d2d/nsharp/display/D2DNSharpDescriptor.java @@ -102,7 +102,18 @@ public class D2DNSharpDescriptor extends NsharpSkewTDescriptor { IDescriptor.FrameChangeMode dmode = IDescriptor.FrameChangeMode .valueOf(mode.name()); // Just hand this off to the resource. - getSkewtResource().setSteppingTimeLine(dop, dmode); + switch (dmode) { + case TIME_ONLY: + getSkewtResource().setSteppingTimeLine(dop, dmode /*ignored*/); + break; + case SPACE_ONLY: + // noop for now + break; + case TIME_AND_SPACE: + // same as TIME_ONLY for now + getSkewtResource().setSteppingTimeLine(dop, dmode /*ignored*/); + break; + } } }; } diff --git a/cave/com.raytheon.uf.viz.d2d.nsharp/src/com/raytheon/uf/viz/d2d/nsharp/rsc/D2DNSharpResource.java b/cave/com.raytheon.uf.viz.d2d.nsharp/src/com/raytheon/uf/viz/d2d/nsharp/rsc/D2DNSharpResource.java index 2ad57c617b..b6ac9b30c4 100644 --- a/cave/com.raytheon.uf.viz.d2d.nsharp/src/com/raytheon/uf/viz/d2d/nsharp/rsc/D2DNSharpResource.java +++ b/cave/com.raytheon.uf.viz.d2d.nsharp/src/com/raytheon/uf/viz/d2d/nsharp/rsc/D2DNSharpResource.java @@ -152,10 +152,25 @@ public class D2DNSharpResource extends skewRsc.addRsc(myDataMap, stnInfo); // Adding to nsharp changes the frame but in D2D we like to keep the // current frame. - while (picked != null + backToPicked : while (picked != null && !skewRsc.getPickedStnInfoStr().equals(picked)) { - skewRsc.setSteppingTimeLine(FrameChangeOperation.NEXT, - FrameChangeMode.TIME_AND_SPACE); + String initStn = skewRsc.getPickedStnInfoStr().substring(0, 4); + do { // for each station... + String initTimePickedStnInfoStr = skewRsc.getPickedStnInfoStr(); + do { // ...for each time + skewRsc.setSteppingTimeLine(FrameChangeOperation.NEXT, FrameChangeMode.TIME_ONLY); + // see if we're back home; if so, success + if (skewRsc.getPickedStnInfoStr().equals(picked)) { + break backToPicked; + } + // if we've cycled through all times for this station... + } while (!skewRsc.getPickedStnInfoStr().equals(initTimePickedStnInfoStr)); + // ...then go to the next station + skewRsc.setSteppingStnIdList(FrameChangeOperation.NEXT); + // if we've cycled through all stations without a station/time match... + } while (!skewRsc.getPickedStnInfoStr().substring(0, 4).equals(initStn)); + // ...then something is wrong + //TODO: consider logging internal error here? -- original "picked" station/time not found } issueRefresh(); } diff --git a/cave/com.raytheon.uf.viz.d2d.nsharp/src/com/raytheon/uf/viz/d2d/nsharp/rsc/D2DNSharpResourceData.java b/cave/com.raytheon.uf.viz.d2d.nsharp/src/com/raytheon/uf/viz/d2d/nsharp/rsc/D2DNSharpResourceData.java index 2faea2e9e8..e629f4381f 100644 --- a/cave/com.raytheon.uf.viz.d2d.nsharp/src/com/raytheon/uf/viz/d2d/nsharp/rsc/D2DNSharpResourceData.java +++ b/cave/com.raytheon.uf.viz.d2d.nsharp/src/com/raytheon/uf/viz/d2d/nsharp/rsc/D2DNSharpResourceData.java @@ -178,8 +178,8 @@ public abstract class D2DNSharpResourceData extends stnInfo.setRangestarttime(fcstTime); } if (coordinate != null) { - stnInfo.setLongitude((float) coordinate.x); - stnInfo.setLatitude((float) coordinate.y); + stnInfo.setLongitude(coordinate.x); + stnInfo.setLatitude(coordinate.y); } if (pointName != null) { stnInfo.setStnDisplayInfo(pointName + " " diff --git a/cave/com.raytheon.uf.viz.d2d.ui/localization/styleRules/d2dArrowStyleRules.xml b/cave/com.raytheon.uf.viz.d2d.ui/localization/styleRules/d2dArrowStyleRules.xml index 9da60120be..1daeeb5004 100644 --- a/cave/com.raytheon.uf.viz.d2d.ui/localization/styleRules/d2dArrowStyleRules.xml +++ b/cave/com.raytheon.uf.viz.d2d.ui/localization/styleRules/d2dArrowStyleRules.xml @@ -108,6 +108,7 @@ Wind + Gust kts diff --git a/cave/com.raytheon.uf.viz.d2d.xy.adapters/src/com/raytheon/uf/viz/d2d/xy/adapters/crosssection/GribCSAdapter.java b/cave/com.raytheon.uf.viz.d2d.xy.adapters/src/com/raytheon/uf/viz/d2d/xy/adapters/crosssection/GribCSAdapter.java index 403aa100f1..3845575adf 100644 --- a/cave/com.raytheon.uf.viz.d2d.xy.adapters/src/com/raytheon/uf/viz/d2d/xy/adapters/crosssection/GribCSAdapter.java +++ b/cave/com.raytheon.uf.viz.d2d.xy.adapters/src/com/raytheon/uf/viz/d2d/xy/adapters/crosssection/GribCSAdapter.java @@ -32,6 +32,7 @@ import javax.measure.unit.Unit; import org.geotools.coverage.grid.GridGeometry2D; import org.geotools.geometry.DirectPosition2D; +import org.opengis.referencing.crs.CoordinateReferenceSystem; import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.grib.GribModel; @@ -87,6 +88,8 @@ public class GribCSAdapter extends AbstractCrossSectionAdapter { private Unit unit; + private CoordinateReferenceSystem crs; + /* * (non-Javadoc) * @@ -250,21 +253,6 @@ public class GribCSAdapter extends AbstractCrossSectionAdapter { if (xVal <= -9999) { continue; } - // these cases handle rotating a vector to be oriented - // towards the north pole rather than the up direction of a - // grid. - if (c == 0) { - speed = xVal; - } else if (c == 1) { - direction = xVal - 180 - + MapUtil.rotation(coordinates[i], area); - xVal = (float) direction; - direction = Math.toRadians(direction); - } else if (c == 2) { - xVal = (float) (-speed * Math.sin(direction)); - } else if (c == 3) { - xVal = (float) (-speed * Math.cos(direction)); - } dataLists.get(c).add(new XYData(xVal, yVal)); } } @@ -292,6 +280,7 @@ public class GribCSAdapter extends AbstractCrossSectionAdapter { super.addRecord(pdo); if (pdo != null && pdo instanceof GribRecord) { unit = ((GribRecord) pdo).getModelInfo().getParameterUnitObject(); + crs = ((GribRecord) pdo).getSpatialObject().getCrs(); } yRecords.remove(pdo.getDataTime()); } @@ -355,4 +344,12 @@ public class GribCSAdapter extends AbstractCrossSectionAdapter { } } + @Override + public CoordinateReferenceSystem getDataCoordinateReferenceSystem() { + if (crs == null) { + return super.getDataCoordinateReferenceSystem(); + } + return crs; + } + } diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/Gust.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/Gust.xml index 02fe4fbb87..183a92be33 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/Gust.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/Gust.xml @@ -1,27 +1,27 @@ - + - - + + - + - + - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG.xml index d8b1850f29..0ad2b56c64 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG.xml @@ -18,4 +18,8 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + + + + + \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG518E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG518E2.xml index 054bffba28..ebdd0a8578 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG518E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG518E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG549E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG549E2.xml index abf232406b..d1fb02333e 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG549E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG549E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG579E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG579E2.xml index 773c339bdf..46ad357b8d 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG579E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG579E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_122E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_122E2.xml index 373394b2b4..691388e4f4 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_122E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_122E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_152E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_152E2.xml index b4a1d1c77c..2745c39c74 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_152E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_152E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_183E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_183E2.xml index 388c725074..b0b0205820 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_183E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_183E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_20.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_20.xml index 97da9bc504..7952865b21 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_20.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_20.xml @@ -18,4 +18,8 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_213E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_213E2.xml index 608d572421..2c15e924de 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_213E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_213E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_244E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_244E2.xml index c3af811360..fb48c2a1aa 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_244E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_244E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_274E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_274E2.xml index 50bc944df4..38138938c7 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_274E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_274E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_30.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_30.xml index 2aa0753163..81ee8bdbc7 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_30.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_30.xml @@ -18,4 +18,8 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_305E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_305E2.xml index 722e5d2830..8ed7433086 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_305E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_305E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_335E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_335E2.xml index 9f781e96e6..6166e42aeb 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_335E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_335E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_366E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_366E2.xml index 1f4970b4e5..7bff2e52df 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_366E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_366E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_396E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_396E2.xml index cab6263956..54ca63edac 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_396E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_396E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_40.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_40.xml index 6982a409f3..ceae2c8037 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_40.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_40.xml @@ -18,4 +18,8 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_427E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_427E2.xml index ba78776425..5f96368f4a 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_427E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_427E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_457E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_457E2.xml index 886e268aeb..b7d989aab6 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_457E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_457E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_488E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_488E2.xml index 8af64e7d3f..a458389fc5 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_488E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_488E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_50.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_50.xml index e3bafbc288..cb0d74025c 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_50.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_50.xml @@ -18,4 +18,8 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_60.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_60.xml index 5cde84cf80..8add6a3fff 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_60.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_60.xml @@ -18,4 +18,8 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_610E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_610E2.xml index 08f2ada08c..81e0972501 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_610E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_610E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_61E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_61E2.xml index 9a57727604..0623653e1d 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_61E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_61E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_640E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_640E2.xml index 4c03295afd..18f5e3038b 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_640E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_640E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_671E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_671E2.xml index fc5a63ce44..e134f228a0 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_671E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_671E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_70.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_70.xml index db9174ac58..378ff7f39d 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_70.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_70.xml @@ -18,4 +18,8 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_701E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_701E2.xml index fd0d8661e8..df59ed1bb0 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_701E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_701E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_732E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_732E2.xml index 68a86e4c8d..a10d1f2f01 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_732E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_732E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_762E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_762E2.xml index ee69ea9452..cdce81ef5d 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_762E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_762E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_80.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_80.xml index 3f5343ca20..b2171a23e5 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_80.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_80.xml @@ -18,4 +18,8 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_90.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_90.xml index ae6dfce072..39eec0498d 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_90.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_90.xml @@ -18,4 +18,8 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_91E2.xml b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_91E2.xml index 46ba838cac..8da6ab8b3b 100644 --- a/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_91E2.xml +++ b/cave/com.raytheon.uf.viz.derivparam/localization/derivedParameters/definitions/TPCSG_91E2.xml @@ -18,7 +18,7 @@ See_the_AWIPS_II_Master_Rights_File_("Master_Rights_File.pdf")_for further_licensing_information. --> - + diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/META-INF/MANIFEST.MF b/cave/com.raytheon.uf.viz.monitor.ffmp/META-INF/MANIFEST.MF index 67dbd582dc..e9786c74cd 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/META-INF/MANIFEST.MF +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/META-INF/MANIFEST.MF @@ -19,7 +19,8 @@ Require-Bundle: org.eclipse.ui, com.raytheon.uf.viz.d2d.core;bundle-version="1.11.15", com.raytheon.uf.viz.localization, javax.measure;bundle-version="1.0.0", - com.raytheon.uf.common.ohd;bundle-version="1.12.1174" + com.raytheon.uf.common.ohd;bundle-version="1.12.1174", + com.raytheon.uf.common.cache;bundle-version="1.12.1174" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-ActivationPolicy: lazy Import-Package: com.raytheon.uf.common.colormap, diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/FFMPMonitor.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/FFMPMonitor.java index ed8500c198..dbf1221d70 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/FFMPMonitor.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/FFMPMonitor.java @@ -28,6 +28,7 @@ import org.eclipse.ui.PlatformUI; import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasin; import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasinData; +import com.raytheon.uf.common.dataplugin.ffmp.FFMPCacheRecord; import com.raytheon.uf.common.dataplugin.ffmp.FFMPGuidanceBasin; import com.raytheon.uf.common.dataplugin.ffmp.FFMPGuidanceInterpolation; import com.raytheon.uf.common.dataplugin.ffmp.FFMPRecord; @@ -95,2491 +96,2517 @@ import com.raytheon.uf.viz.monitor.listeners.IMonitorListener; */ public class FFMPMonitor extends ResourceMonitor implements - IFFMPMonitorListener { - private static long SECONDS_PER_HOUR = 60 * 60; + IFFMPMonitorListener { + private static long SECONDS_PER_HOUR = 60 * 60; - /** boolean for initialization **/ - public static boolean isInitialized = false; + /** boolean for initialization **/ + public static boolean isInitialized = false; - /** Singleton instance of this class */ - private static FFMPMonitor monitor = null; + /** Singleton instance of this class */ + private static FFMPMonitor monitor = null; - /** Array of scan listeners **/ - private ArrayList resourceListeners = new ArrayList(); + /** Array of scan listeners **/ + private ArrayList resourceListeners = new ArrayList(); - public FFMPSplash ffmpSplash; + public FFMPSplash ffmpSplash; - private String wfo = null; + private String wfo = null; - /** Pattern for dates in radar */ - public static String datePattern = "yyyy-MM-dd HH:mm:ss"; + /** Pattern for dates in radar */ + public static String datePattern = "yyyy-MM-dd HH:mm:ss"; - /** FFMP Records indexed by site, times and field **/ - public ConcurrentHashMap> ffmpData = null; + /** FFMP Records indexed by site, times and field **/ + public ConcurrentHashMap> ffmpData = null; - // list of earliest available date queried by site, sourceName - public ConcurrentHashMap> ffmpAvailableUriQueryDates = null; + // list of earliest available date queried by site, sourceName + public ConcurrentHashMap> ffmpAvailableUriQueryDates = null; - // map by site, sourceName, Date - public ConcurrentHashMap>>> ffmpAvailableUris = null; + // map by site, sourceName, Date + public ConcurrentHashMap>>> ffmpAvailableUris = null; - // map by field, huc, and the URIs that have been loaded for - public ConcurrentHashMap>>> ffmpLoadedUris = null; + // map by field, huc, and the URIs that have been loaded for + public ConcurrentHashMap>>> ffmpLoadedUris = null; - // Interpolation Guidance Sources - public FFMPGuidanceInterpolation interpolation = null; + // Interpolation Guidance Sources + public FFMPGuidanceInterpolation interpolation = null; - /** config manager **/ - public FFMPSourceConfigurationManager fscm = null; + /** config manager **/ + public FFMPSourceConfigurationManager fscm = null; - /** config manager **/ - public FFMPConfig ffmpConfig = null; + /** config manager **/ + public FFMPConfig ffmpConfig = null; - public ArrayList dataTimes = null; + public ArrayList dataTimes = null; - private FFMPTimeWindow qpfWindow = null; + private FFMPTimeWindow qpfWindow = null; + + private FFMPTimeWindow qpeWindow = null; - private FFMPTimeWindow qpeWindow = null; + /** The infamous templates **/ + private FFMPTemplates templates = null; + + private FFMPRunConfigurationManager frcm = null; - /** The infamous templates **/ - private FFMPTemplates templates = null; + private FFFGDataMgr fffg = null; - private FFMPRunConfigurationManager frcm = null; - - private FFFGDataMgr fffg = null; - - private static final transient IUFStatusHandler statusHandler = UFStatus - .getHandler(FFMPMonitor.class); - - @Override - public void nullifyMonitor() { - - if (resourceListeners != null) { - for (IFFMPResourceListener listener : resourceListeners) { - if (listener instanceof FFMPResource) { - FFMPResource res = (FFMPResource) listener; - if (res.basinTableDlg != null) { - closeDialog(res); - } - - // will kill any loaders running - if (res.getResourceData().floader != null) { - res.getResourceData().floader.kill(); - res.getResourceData().floader = null; - } - } - } - - // clear the resource list - resourceListeners.clear(); - } - - ffmpData = null; - ffmpAvailableUriQueryDates = null; - ffmpAvailableUris = null; - ffmpLoadedUris = null; - - // kill this monitor - monitor = null; - System.gc(); - } - - @Override - public void thresholdUpdate(IMonitorThresholdEvent me) { - // TODO Auto-generated method stub - } - - @Override - public void configUpdate(IMonitorConfigurationEvent me) { - // updates the config - getSourceConfig().readConfigXml(); - boolean isLinkToFrame = getConfig().getFFMPConfigData() - .getLinkToFrame(); - - for (IFFMPResourceListener listener : resourceListeners) { - - listener.setLinkToFrame(isLinkToFrame); - - if (listener.isAutoRefresh()) { - listener.setQuery(true); - fireRefresh(listener); - } - - listener.updateDialog(); - } - } - - /** - * Actual initialization if necessary - * - * @return - */ - public static synchronized FFMPMonitor getInstance() { - if (monitor == null) { - monitor = new FFMPMonitor(); - monitor.createDataStructures(); - isInitialized = true; - } - - return monitor; - } - - /** - * check for life - * - * @return - */ - public static boolean isRunning() { - - if (monitor == null) { - return false; - } - - return true; - } - - /** - * get a ref to the config - * - * @return - */ - public FFMPSourceConfigurationManager getSourceConfig() { - if (fscm == null) { - fscm = FFMPSourceConfigurationManager.getInstance(); - fscm.readConfigXml(); - } - - return fscm; - } - - /** - * Gets the FFFG manager - * - * @return - */ - public FFFGDataMgr getFFFGConfig() { - if (fffg == null) { - fffg = FFFGDataMgr.getInstance(); - } - - return fffg; - } - - /** - * Gets the dialog config - * - * @return - */ - public FFMPConfig getConfig() { - if (ffmpConfig == null) { - ffmpConfig = FFMPConfig.getInstance(); - } - return ffmpConfig; - } - - /** - * Creates the linked maps - */ - private void createDataStructures() { - ffmpData = new ConcurrentHashMap>(); - ffmpAvailableUris = new ConcurrentHashMap>>>(); - ffmpAvailableUriQueryDates = new ConcurrentHashMap>(); - ffmpLoadedUris = new ConcurrentHashMap>>>(); - } - - /** - * gets the URI's by field type and site - * - * @param siteKey - * @param pfield - * @param phuc - * @return - */ - private ConcurrentHashMap getUriMap(String siteKey, - String source, String phuc) { - - ConcurrentHashMap>> siteLoadedUris = null; - - if (ffmpLoadedUris != null) { - siteLoadedUris = ffmpLoadedUris.get(siteKey); - } - - if (siteLoadedUris == null) { - siteLoadedUris = new ConcurrentHashMap>>(); - ffmpLoadedUris.put(siteKey, siteLoadedUris); - } - - ConcurrentHashMap> sourceLoadedUris = null; - - if (ffmpLoadedUris != null) { - sourceLoadedUris = ffmpLoadedUris.get(siteKey).get(source); - } - - if (sourceLoadedUris == null) { - - sourceLoadedUris = new ConcurrentHashMap>(); - ffmpLoadedUris.get(siteKey).put(source, sourceLoadedUris); - } - - ConcurrentHashMap hucLoadedUris = null; - - if (ffmpLoadedUris != null) { - hucLoadedUris = ffmpLoadedUris.get(siteKey).get(source).get(phuc); - } - - if (hucLoadedUris == null) { - - hucLoadedUris = new ConcurrentHashMap(200, 0.75f, 4); - if (ffmpLoadedUris != null) { - ffmpLoadedUris.get(siteKey).get(source) - .put(phuc, hucLoadedUris); - } - } - - return hucLoadedUris; - } - - /** - * Static to make it fast, at least that's the idea. - * - * @param uri - * @return - * @throws VizException - */ - private static FFMPRecord loadRecordFromDatabase(String uri) - throws VizException { - FFMPRecord ffmpRec = null; - - if (uri != null) { - Map vals = new HashMap(); - vals.put("pluginName", "ffmp"); - vals.put("dataURI", uri); - ffmpRec = (FFMPRecord) Loader.loadData(vals); - } - - return ffmpRec; - } - - public FFMPRecord populateFFMPRecord(ProductXML product, String siteKey, - String dataKey, String source, Date ptime, String phuc) { - return populateFFMPRecord(product, siteKey, dataKey, source, ptime, - phuc, false); - } - - /** - * populate a new FFMPRecord - * - * @param sourceName - * @param icao - * @param refTime - * @return - * @throws VizException - */ - public FFMPRecord populateFFMPRecord(ProductXML product, String siteKey, - String dataKey, String source, Date ptime, String phuc, - boolean retrieveNew) { - - FFMPRecord ffmpRec = null; - boolean isProductLoad = false; - if (product != null) { - isProductLoad = true; - } - - if (source != null) { - - SortedMap> urisByDate = getAvailableUris( - siteKey, dataKey, source, ptime, retrieveNew); - - if (urisByDate != null) { - for (List uris : urisByDate.values()) { - for (String uri : uris) { - if ((uri != null) - && !getUriMap(siteKey, source, phuc) - .containsKey(uri)) { - try { - ffmpRec = loadRecordFromDatabase(uri); - populateFFMPRecord(isProductLoad, siteKey, - ffmpRec, source, phuc); - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - "FFMP Can't retrieve FFMP URI, " + uri, - e); - } - } - } - } - } - } - - return ffmpRec; - } - - /** - * populate a new FFMPRecord - * - * @param sourceName - * @param icao - * @param refTime - * @return - * @throws VizException - */ - public FFMPRecord populateFFMPRecord(boolean isProductLoad, String uri, - String siteKey, String source, String phuc) throws Exception { - - try { - populateFFMPRecord(isProductLoad, siteKey, - loadRecordFromDatabase(uri), source, phuc); - } catch (VizException e) { - statusHandler.handle(Priority.INFO, - "FFMP Can't retrieve FFMP URI, " + uri, e); - } - - return ffmpData.get(siteKey).get(source); - } - - /** - * Inserts the loader records directly into the cache - * - * @param data - * @param siteKey - * @param dataKey - * @param source - * @param huc - */ - public void insertFFMPData(FFMPBasinData data, String siteKey, - String source, String huc) { - - final String fsiteKey = siteKey; - final FFMPBasinData fdata = data; - final String fsource = source; - final String fhuc = huc; - - VizApp.runAsync(new Runnable() { - @Override - public void run() { - - if (ffmpData.containsKey(fsiteKey)) { - if (ffmpData.get(fsiteKey).containsKey(fsource)) { - ffmpData.get(fsiteKey).get(fsource) - .setBasinBuddyData(fdata, fhuc); - } - } - } - }); - } - - /** - * Try and get the loading off of the GUI thread - * - * @param isProductLoad - * @param siteKey - * @param ffmpRec - * @param source - * @param phuc - * @throws Exception - */ - public void populateFFMPRecord(boolean isProductLoad, String siteKey, - FFMPRecord ffmpRec, String source, String phuc) throws Exception { - - FFMPLoadRecord flr = new FFMPLoadRecord(isProductLoad, siteKey, - ffmpRec, source, phuc); - flr.run(); - } - - /** - * Get load of basins off the main thread - * - * @param dataUri - * @param siteKey - * @param source - * @param phuc - * @param basin - * @throws VizException - */ - public void populateFFMPBasin(String dataUri, String siteKey, - String source, String phuc, FFMPBasin basin) throws VizException { - - final String fdataUri = dataUri; - final String fsiteKey = siteKey; - final String fhuc = phuc; - final String fsource = source; - final FFMPBasin fbasin = basin; - - VizApp.runAsync(new Runnable() { - @Override - public void run() { - - if (fdataUri != null) { - ConcurrentMap uris = getUriMap(fsiteKey, - fsource, fhuc); - if (!uris.containsKey(fdataUri)) { - try { - FFMPRecord ffmpRec = loadRecordFromDatabase(fdataUri); - File loc = HDF5Util.findHDF5Location(ffmpRec); - IDataStore dataStore = DataStoreFactory - .getDataStore(loc); - SourceXML sourceXML = fscm.getSource(fsource); - - if (sourceXML.getSourceType().equals( - SOURCE_TYPE.GAGE.getSourceType()) - && fhuc.equals("ALL")) { - ffmpRec.retrieveVirtualBasinFromDataStore( - dataStore, fdataUri, - getTemplates(fsiteKey), ffmpRec - .getDataTime().getRefTime(), - fbasin); - } else { - ffmpRec.retrieveBasinFromDataStore(dataStore, - fdataUri, getTemplates(fsiteKey), fhuc, - ffmpRec.getDataTime().getRefTime(), - ffmpRec.getSourceName(), fbasin); - } - } catch (Throwable e) { - try { - throw new VizException( - "Error occurred loading uri " - + fdataUri, e); - } catch (VizException e1) { - statusHandler.handle(Priority.PROBLEM, - "FFMP Can't retrieve FFMP URI, " - + fdataUri, e1); - } - } - } - } - } - }); - } - - /** - * Getting a specific URI - * - * @param date - * @return - */ - public String getAvailableUri(String siteKey, String dataKey, - String sourceName, Date ptime) { - - String uri = null; - SimpleDateFormat datef = new SimpleDateFormat(datePattern); - datef.setTimeZone(TimeZone.getTimeZone("Zulu")); - String sql = "select datauri from ffmp where wfo = '" + getWfo() - + "' and reftime = '" + datef.format(ptime) - + "' and sourcename = '" + sourceName + "' and sitekey = '" - + siteKey + "' and datakey = '" + dataKey - + "' order by reftime"; - try { - List results = DirectDbQuery.executeQuery(sql, - "metadata", QueryLanguage.SQL); - if (results.size() > 0) { - uri = (String) results.get(0)[0]; - } - } catch (VizException e) { - e.printStackTrace(); - } - - return uri; - } - - public ConcurrentNavigableMap> getAvailableUris( - String siteKey, String dataKey, String sourceName, Date time) { - return getAvailableUris(siteKey, dataKey, sourceName, time, false); - } - - /** - * Gets the available uris back to a given time - * - * @param date - * @return - */ - public ConcurrentNavigableMap> getAvailableUris( - String siteKey, String dataKey, String sourceName, Date time, - boolean retrieveNew) { - - if (!ffmpAvailableUris.containsKey(siteKey)) { - ConcurrentHashMap>> tempUriList = new ConcurrentHashMap>>( - 16, 0.75f, 4); - ffmpAvailableUris.put(siteKey, tempUriList); - } - - ConcurrentSkipListMap> sortedUris = ffmpAvailableUris - .get(siteKey).get(sourceName); - if (sortedUris == null) { - synchronized (ffmpAvailableUris) { - // double check in case another thread created in the mean time - sortedUris = ffmpAvailableUris.get(siteKey).get(sourceName); - if (sortedUris == null) { - sortedUris = new ConcurrentSkipListMap>(); - ffmpAvailableUris.get(siteKey).put(sourceName, sortedUris); - } - } - } - - if (!ffmpAvailableUriQueryDates.containsKey(siteKey)) { - ConcurrentHashMap tempUriQueryDates = new ConcurrentHashMap( - 16, 0.75f, 4); - ffmpAvailableUriQueryDates.put(siteKey, tempUriQueryDates); - } - - Date previousQueryTime = ffmpAvailableUriQueryDates.get(siteKey).get( - sourceName); - SourceXML source = getSourceConfig().getSource(sourceName); - - if (retrieveNew - || ((time != null) && ((previousQueryTime == null) || (time - .getTime() < previousQueryTime.getTime())))) { - SimpleDateFormat datef = new SimpleDateFormat(datePattern); - datef.setTimeZone(TimeZone.getTimeZone("Zulu")); - Date earliestTime = time; - StringBuilder query = new StringBuilder(200); - query.append("select datauri from ffmp where wfo = '"); - query.append(getWfo()); - query.append("' and sourcename = '"); - query.append(sourceName); - - // GUIDANCE we save by displayName, *type* - if (source.getSourceType().equals( - SOURCE_TYPE.GUIDANCE.getSourceType())) { - - long timeOffset = source.getExpirationMinutes(siteKey) * 1000 * 60; - earliestTime = new Date(time.getTime() - timeOffset); - } - - query.append("' and sitekey = '"); - query.append(siteKey); - - if (!source.isMosaic()) { - query.append("' and datakey = '"); - query.append(dataKey); - } - - query.append("' and reftime >= '"); - query.append(datef.format(earliestTime)); - - if (!retrieveNew && (previousQueryTime != null)) { - query.append("' and reftime < '"); - query.append(datef.format(previousQueryTime)); - } - - query.append("' order by reftime desc"); - - try { - List results = DirectDbQuery.executeQuery( - query.toString(), "metadata", QueryLanguage.SQL); - List list = new LinkedList(); - Date prevRefTime = null; - - for (int j = 0; j < results.size(); j++) { - if (results.size() > 0) { - Object[] results2 = results.get(j); - // System.out.println("Querrying for URIs: " - // + query.toString() + " # " + results2.length); - - for (int i = 0; i < results2.length; i++) { - String uri = (String) results2[0]; - FFMPRecord rec = new FFMPRecord(uri); - Date curRefTime = rec.getDataTime().getRefTime(); - if ((prevRefTime != null) - && !prevRefTime.equals(curRefTime)) { - sortedUris.put(prevRefTime, list); - list = new LinkedList(); - } - - prevRefTime = curRefTime; - list.add(uri); - } - } - } - - if (list != null) { - if ((prevRefTime == null) || (list == null)) { - statusHandler.handle(Priority.WARN, - "Source prevTime or list = null: " + sourceName - + " Date: " + time); - } else { - sortedUris.put(prevRefTime, list); - } - } - - ffmpAvailableUriQueryDates.get(siteKey).put(sourceName, time); - - } catch (VizException e) { - statusHandler.handle(Priority.PROBLEM, - "FFMP Can't find availble URI list for, " + sourceName, - e); - } - } - - if (time != null) { - if (source.getSourceType().equals( - SOURCE_TYPE.GUIDANCE.getSourceType())) { - return sortedUris; - } else { - return sortedUris.tailMap(time, true); - } - } - - return null; - } - - /** - * Request a record - * - * @param retrieveNew - * - * @param refTime - * @param field - * @param huc - * @return - * - */ - public FFMPRecord getFFMPData(ProductXML product, String siteKey, - String dataKey, String sourceName, Date ptime, String phuc, - boolean retrieveNew) { - - FFMPRecord record = ffmpData.get(siteKey).get(sourceName); - String guidSrc = FFMPConfig.getInstance().getFFMPConfigData().getGuidSrc(); - - if ((record != null) - && (record.getBasinData(phuc).getBasins().size() > 0)) { - - SourceXML sourceXML = getSourceConfig().getSource(sourceName); - - if (sourceXML == null) { - sourceXML = getSourceConfig() - .getSourceByDisplayName(sourceName); - } - - if (sourceXML.getSourceType().equals( - SOURCE_TYPE.GUIDANCE.getSourceType())) { - // FFG in table special case where display is the sourceName - if (product != null) { - - ProductRunXML productRun = getRunConfig().getProduct( - siteKey); - - for (SourceXML source : productRun.getGuidanceSources( - product, guidSrc)) { - if (ffmpLoadedUris.get(siteKey).containsKey( - source.getSourceName())) { - continue; - } else { - populateFFMPRecord(product, siteKey, dataKey, - source.getSourceName(), ptime, phuc, - retrieveNew); - } - } - } else { - // FFG is the primary if - if (!ffmpLoadedUris.get(siteKey).containsKey(sourceName)) { - populateFFMPRecord(product, siteKey, dataKey, - sourceName, ptime, phuc, retrieveNew); - } - } - - record = ffmpData.get(siteKey).get(sourceName); - - } else { - populateFFMPRecord(product, siteKey, dataKey, sourceName, - ptime, phuc, retrieveNew); - } - - } else { // must populate for a different huc for all possible times - if (product != null) { - - SourceXML sourceXML = getSourceConfig().getSourceByDisplayName( - sourceName); - - if (sourceXML != null) { - - if (sourceXML.getDisplayName().equals(sourceName)) { - // FFG table display special case updates - ProductRunXML productRun = getRunConfig().getProduct( - siteKey); - - for (SourceXML ffgSource : productRun - .getGuidanceSources(product, guidSrc)) { - - populateFFMPRecord(product, siteKey, dataKey, - ffgSource.getSourceName(), ptime, phuc, - retrieveNew); - } - } - } else { - populateFFMPRecord(product, siteKey, dataKey, sourceName, - ptime, phuc, retrieveNew); - } - } else { - // special case where FFG is the primary source - // check for special case with dual stand alone and table - // display loaded - SourceXML sourcexml = getSourceConfig().getSource(sourceName); - - if (sourcexml.getSourceType().equals( - SOURCE_TYPE.GUIDANCE.getSourceType())) { - sourceName = sourcexml.getDisplayName(); - } else { - populateFFMPRecord(product, siteKey, dataKey, sourceName, - ptime, phuc, retrieveNew); - } - } - - record = ffmpData.get(siteKey).get(sourceName); - } - - return record; - - } - - /** - * Sort by DataTime - * - * @author dhladky - * - */ - public class SortByDataTime implements Comparator { - - @Override - public int compare(DataTime o1, DataTime o2) { - - return o1.compareTo(o2); - } - } - - /** - * gets the wfo - * - * @return - */ - public String getWfo() { - return wfo; - } - - /** - * sets the wfo - * - * @param wfo - */ - public void setWfo(String wfo) { - this.wfo = wfo; - } - - /** - * gets the reverse of the later - * - * @param sourceName - * @return - */ - public FIELDS getField(String sourceName) { - - String sfield = getSourceConfig().getSourceType(sourceName) - .getSourceType().toLowerCase(); - FIELDS myField = null; - if (sfield.equals(FFMPRecord.FIELDS.QPE.getFieldName())) { - myField = FFMPRecord.FIELDS.QPE; - } else if (sfield.equals(FFMPRecord.FIELDS.RATE.getFieldName())) { - myField = FFMPRecord.FIELDS.RATE; - } else if (sfield.equals(FFMPRecord.FIELDS.QPF.getFieldName())) { - myField = FFMPRecord.FIELDS.QPF; - } else if (sfield.equals(FFMPRecord.FIELDS.GUIDANCE.getFieldName())) { - myField = FFMPRecord.FIELDS.GUIDANCE; - } else if (sfield.equals("gage")) { - myField = FFMPRecord.FIELDS.VIRTUAL; - } - return myField; - } - - /** - * Start secondary and tertiary data loads - * - * @param startTime - * @param loadType - * @throws VizException - */ - public void startLoad(FFMPResource resource, Date startTime, - LOADER_TYPE loadType) throws VizException { - Date timeBack = null; - FFMPTemplateConfigurationManager ftcm = FFMPTemplateConfigurationManager - .getInstance(); - ArrayList hucsToLoad = ftcm.getHucLevels(); - FFMPResourceData frd = resource.getResourceData(); - - if (loadType == LOADER_TYPE.SECONDARY) { - hucsToLoad.remove("ALL"); - hucsToLoad.remove(getConfig().getFFMPConfigData().getLayer()); - - timeBack = new Date( - (long) (resource.getMostRecentTime().getTime() - ((getConfig() - .getFFMPConfigData().getTimeFrame() * 3) * 3600 * 1000))); - - frd.timeBack = timeBack; - } - - frd.floader = new FFMPDataLoader(frd, timeBack, startTime, loadType, - hucsToLoad); - frd.floader.addListener(resource); - frd.floader.start(); - - } - - public void launchSplash(String siteKey) { - - final String fsiteKey = siteKey; - - VizApp.runAsync(new Runnable() { - @Override - public void run() { - Shell fshell = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow().getShell(); - - if (ffmpSplash == null) { - ffmpSplash = new FFMPSplash(fshell); - // latch - int count = 0; - while (!getTemplates(fsiteKey).done) { - - try { - count++; - if (count == 50) { - ffmpSplash.disposeDialog(); - break; - } - Thread.sleep(1000); - } catch (InterruptedException e) { - e.printStackTrace(); - if (ffmpSplash != null) { - ffmpSplash.disposeDialog(); - } - } - } - } - } - }); - } - - /** - * Launch a basin trend from a screen click - * - * @param pfaf - */ - public void basinTrend(Long pfaf) { - - final String pfafs = pfaf.toString(); - - VizApp.runAsync(new Runnable() { - @Override - public void run() { - for (IMonitorListener listener : getMonitorListeners()) { - if (listener instanceof FfmpBasinTableDlg) { - ((FfmpBasinTableDlg) listener).displayBasinTrend(pfafs); - } - } - } - }); - } - - /** - * launch the dialog - */ - public void launchFFMPDialog(FFMPResource resource) { - - final FFMPResource fresource = resource; - - if (resource.basinTableDlg == null) { - VizApp.runAsync(new Runnable() { - - @Override - public void run() { - Shell fshell = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow().getShell(); - - FFMPTableData tData = new FFMPTableData(); - fresource.basinTableDlg = new FfmpBasinTableDlg(fshell, - tData, fresource); - addMonitorListener(fresource.basinTableDlg); - fresource.basinTableDlg.addListener(fresource); - fresource.basinTableDlg.open(); - } - }); - } else { - resource.basinTableDlg.getShell().setActive(); - } - } - - /** - * update the data in the dialog - */ - public void updateDialog(FFMPResource resource) { - - if (resource.basinTableDlg != null) { - - resource.isFirst = false; - fireMonitorEvent(resource.basinTableDlg.getClass().getName()); - } - } - - public synchronized void splashDisposeAndDataLoad(FFMPResource resource) { - if (ffmpSplash != null) { - ffmpSplash.disposeDialog(); - ffmpSplash = null; - - if (resource.isFirst) { - updateDialog(resource); - } - - // start secondary data load - try { - startLoad(resource, resource.getResourceData().timeBack, - LOADER_TYPE.SECONDARY); - } catch (VizException e) { - statusHandler.handle(Priority.PROBLEM, - "Secondary Data Load failure", e); - } - } - } - - public void forceKillFFMPSplash() { - if (ffmpSplash != null) { - ffmpSplash.disposeDialog(); - ffmpSplash = null; - } - } - - /** - * Add the FFMPResource - * - * @param listener - */ - public void addResourceListener(IFFMPResourceListener listener) { - resourceListeners.add(listener); - } - - /** - * Remove the FFMPResource - * - * @param listener - */ - public void removeResourceListener(IFFMPResourceListener listener) { - - ConcurrentHashMap siteCount = new ConcurrentHashMap(); - - for (IFFMPResourceListener clistener : resourceListeners) { - if (listener instanceof FFMPResource) { - FFMPResource res = (FFMPResource) clistener; - if (siteCount.containsKey(res.getSiteKey())) { - int val = siteCount.get(res.getSiteKey()); - siteCount.replace(res.getSiteKey(), val + 1); - } else { - siteCount.put(res.getSiteKey(), 1); - } - } - } - - if (listener instanceof FFMPResource) { - FFMPResource res = (FFMPResource) listener; - if (res.getResourceData().floader != null) { - res.getResourceData().floader.kill(); - } - res.getResourceData().floader = null; - int val = siteCount.get(res.getSiteKey()); - - if ((val == 1) && (siteCount.size() > 1)) { - - ffmpData.remove(res.getSiteKey()); - ffmpAvailableUriQueryDates.remove(res.getSiteKey()); - ffmpAvailableUris.remove(res.getSiteKey()); - ffmpLoadedUris.remove(res.getSiteKey()); - } - } - - resourceListeners.remove(listener); - } - - @Override - public void updateDialogTime(DataTime tableTime) { - - for (IFFMPResourceListener listener : getResourceListenerList()) { - if (listener instanceof FFMPResource) { - FFMPResource res = (FFMPResource) listener; - if (res.isLinkToFrame()) { - res.setTableTime(tableTime.getRefTime()); - if (res.basinTableDlg != null) { - updateDialog(res); - } - } - } - - } - - } - - public ArrayList getResourceListenerList() { - return resourceListeners; - } - - /** - * close dialog and cleanup - */ - public void closeDialog(FFMPResource res) { - if (res.basinTableDlg != null) { - res.basinTableDlg.removeListener(res); - res.basinTableDlg.disposeDialog(); - res.basinTableDlg = null; - } - } - - /** - * Thread the updates to the drawing - * - * @param listener - */ - private void fireRefresh(IFFMPResourceListener listener) { - - final IFFMPResourceListener flistener = listener; - - Display.getDefault().asyncExec(new Runnable() { - @Override - public void run() { - flistener.refresh(); - } - }); - } - - /** - * Sees if this source is a primary source for a product - * - * @param sourceName - * @return - */ - public ProductXML getProductXML(String sourceName) { - return getSourceConfig().getProduct(sourceName); - } - - /** - * Get the pertinent QPE source Record. - * - * @param date - * @param phuc - * @param retrieveNew - * @return - */ - public FFMPRecord getQPERecord(ProductXML product, String siteKey, - String dataKey, String sourceName, Date date, String phuc, - boolean retrieveNew) { - - // comparisons done with table display - if (product != null) { - sourceName = product.getQpe(); - } - - return getFFMPData(product, siteKey, dataKey, sourceName, date, phuc, - retrieveNew); - } - - /** - * Get the pertinent QPE source basin. - * - * @param date - * @param phuc - * @param pfaf - * @return - */ - public FFMPBasin getGraphQPEBasin(ProductXML product, String siteKey, - String dataKey, String sourceName, Date date, String phuc, Long pfaf) - throws VizException { - // comparisons done with table display - if ((product != null) && (sourceName == null)) { - sourceName = product.getQpe(); - } - - return getFFMPBasinData(product, siteKey, dataKey, sourceName, date, - phuc, pfaf); - } - - /** - * Get the rate record. - * - * @param date - * @param phuc - * @param retrieveNew - * @return - */ - public FFMPRecord getRateRecord(ProductXML product, String siteKey, - String dataKey, String sourceName, Date date, String phuc, - boolean retrieveNew) { - - // comparisons done with table display - if (product != null) { - sourceName = product.getRate(); - } - - return getFFMPData(product, siteKey, dataKey, sourceName, date, phuc, - retrieveNew); - } - - /** - * Get the rate basin. - * - * @param ptime - * @param phuc - * @param pfaf - * @return - */ - public FFMPBasin getGraphRateBasin(ProductXML product, String siteKey, - String dataKey, String sourceName, Date ptime, String phuc, - Long pfaf) throws VizException { - - // comparisons done with table display - if ((product != null) && (sourceName == null)) { - sourceName = product.getRate(); - } - - return getFFMPBasinData(product, siteKey, dataKey, sourceName, ptime, - phuc, pfaf); - } - - /** - * Gets the QPF record - * - * @param date - * @param phuc - * @param retrieveNew - * @return - */ - public FFMPRecord getQPFRecord(ProductXML product, String siteKey, - String dataKey, String sourceName, Date date, String phuc, - boolean retrieveNew) { - - FfmpTableConfigData ffmpTableCfgData = FfmpTableConfig.getInstance() - .getTableConfigData(siteKey); - String qpfType = ffmpTableCfgData.getQpfType(); - ProductRunXML productRun = FFMPRunConfigurationManager.getInstance() - .getProduct(siteKey); - - // comparisons done with table display - if (product != null) { - sourceName = productRun.getQpfSources(product, qpfType).get(0) - .getSourceName(); - } - - return getFFMPData(product, siteKey, dataKey, sourceName, date, phuc, - retrieveNew); - } - - /** - * Get the QPF Basin. - * - * @param date - * @param phuc - * @param pfaf - * @return - */ - public FFMPBasin getGraphQPFBasin(ProductXML product, String siteKey, - String dataKey, String sourceName, Date date, String phuc, Long pfaf) - throws VizException { - - // comparisons done with table display - if (product != null) { - ProductRunXML productRun = FFMPRunConfigurationManager - .getInstance().getProduct(siteKey); - FfmpTableConfigData ffmpTableCfgData = FfmpTableConfig - .getInstance().getTableConfigData(siteKey); - String qpfType = ffmpTableCfgData.getQpfGraphType(); - sourceName = productRun.getQpfSources(product, qpfType).get(0) - .getSourceName(); - } - - return getFFMPBasinData(product, siteKey, dataKey, sourceName, date, - phuc, pfaf); - } - - /** - * Gets the guidance source types - * - * @param date - * @param phuc - * @return - */ - public FFMPRecord getGuidanceRecord(ProductXML product, String siteKey, - String sourceName, Date date, String phuc, boolean isStandAlone) { - String guidSrc = FFMPConfig.getInstance().getFFMPConfigData().getGuidSrc(); - if (!isStandAlone && guidSrc.startsWith("xxx")) { - return null; - } - if (product != null) { - ProductRunXML productRun = FFMPRunConfigurationManager - .getInstance().getProduct(siteKey); - SourceXML source = productRun.getGuidanceSources(product, - guidSrc).get(0); - sourceName = source.getDisplayName(); - } - - return getFFMPData(product, siteKey, null, sourceName, date, phuc, - false); - } - - /** - * Gets the Guidance records NOTE: This is only used in the - * FFMPDataGenerator - * - * @param product - * @param siteKey - * @param date - * @param phuc - * @param retrieveNew - * @return - */ - public HashMap getGuidanceRecords(ProductXML product, - String siteKey, Date date, String phuc, boolean retrieveNew) { - - HashMap guidRecs = new HashMap(); - ProductRunXML productRun = FFMPRunConfigurationManager.getInstance() - .getProduct(siteKey); - ArrayList guidTypes = productRun.getGuidanceTypes(product); - - for (String type : guidTypes) { - - FFMPRecord guidRec = getFFMPData(product, siteKey, null, type, - date, phuc, retrieveNew); - guidRecs.put(type, guidRec); - } - - return guidRecs; - } - - /** - * Gets the guidance source types. - * - * @param date - * @param phuc - * @param pfaf - * @return - */ - public FFMPBasin getGraphGuidanceBasin(ProductXML product, String siteKey, - String dataKey, String sourceName, Date date, String phuc, Long pfaf) - throws VizException { - - if (product != null) { - String guidSrc = FFMPConfig.getInstance().getFFMPConfigData().getGuidSrc(); - SourceXML source = product.getGuidanceSourcesByType( - guidSrc).get(0); - sourceName = source.getDisplayName(); - } - - return getFFMPBasinData(product, siteKey, dataKey, sourceName, date, - phuc, pfaf); - } - - /** - * Gets the virtual gage basin record - * - * @param date - * @param phuc - * @param retrieveNew - * @return - */ - public FFMPRecord getVirtualRecord(ProductXML product, String siteKey, - String dataKey, String sourceName, Date date, String phuc, - boolean retrieveNew) { - // comparisons done with table display - // field doesn't matter here - - if (product != null) { - sourceName = product.getVirtual(); - } - - return getFFMPData(product, siteKey, dataKey, sourceName, date, phuc, - retrieveNew); - } - - /** - * Grabs data for a particular basin. Used by the graph's. - * - * @param sourceName - * @param date - * @param phuc - * @param pfaf - * @return - */ - public FFMPBasin getFFMPBasinData(ProductXML product, String siteKey, - String dataKey, String sourceName, Date ptime, String phuc, - Long pfaf) throws VizException { - FFMPBasin basin = null; - // check for already loaded records - FFMPRecord record = ffmpData.get(siteKey).get(sourceName); - if (record != null) { - FFMPBasinData basinData = record.getBasinData(phuc); - if (basinData != null) { - basin = basinData.get(pfaf); - } - } - - SourceXML psource = getSourceConfig().getSource(sourceName); - if (psource == null) { - psource = getSourceConfig().getSourceByDisplayName(sourceName); - } - // basin should have loaded something - if (psource.getDisplayName().equals(sourceName) - && psource.getSourceType().equals( - SOURCE_TYPE.GUIDANCE.getSourceType())) { - FFMPGuidanceBasin fgb = null; - if (basin != null) { - fgb = (FFMPGuidanceBasin) basin; - } else { - fgb = new FFMPGuidanceBasin(pfaf, !phuc.equals("ALL")); - basin = fgb; - } - - if (product != null) { - ProductRunXML productRun = getRunConfig().getProduct(siteKey); - FfmpTableConfigData ffmpTableCfgData = FfmpTableConfig - .getInstance().getTableConfigData(siteKey); - - for (SourceXML source : productRun.getGuidanceSources(product, - ffmpTableCfgData.getFfgGraphType())) { - if (fgb.containsKey(source.getSourceName())) { - continue; - } else { - // populate if it isn't there - SortedMap> availableUris = getAvailableUris( - siteKey, dataKey, source.getSourceName(), ptime); - - if ((availableUris != null) - && (availableUris.size() > 0)) { - POINT_RETRIVAL: for (List uris : availableUris - .values()) { - for (String uri : uris) { - - if (!ffmpLoadedUris.containsKey(siteKey)) { - - ConcurrentHashMap>> tempLoadedUris = new ConcurrentHashMap>>(); - tempLoadedUris - .put(source.getSourceName(), - new ConcurrentHashMap>( - 16, 0.75f, 4)); - - ffmpLoadedUris.put(siteKey, - tempLoadedUris); - } - - if (!ffmpLoadedUris.get(siteKey) - .get(source).get(phuc) - .containsKey(uri)) { - // populate point only - populateFFMPBasin(uri, siteKey, - source.getSourceName(), phuc, - fgb); - } else { - break POINT_RETRIVAL; - } - } - } - } - } - } - } else { - // FFG is the primary source - if (!fgb.containsKey(sourceName)) { - // populate if it isn't there - SortedMap> availableUris = getAvailableUris( - siteKey, dataKey, sourceName, ptime); - - if ((availableUris != null) && (availableUris.size() > 0)) { - POINT_RETRIVAL: for (List uris : availableUris - .values()) { - for (String uri : uris) { - - if (!ffmpLoadedUris.containsKey(siteKey)) { - - ConcurrentHashMap>> tempLoadedUris = new ConcurrentHashMap>>(); - - tempLoadedUris - .put(sourceName, - new ConcurrentHashMap>( - 16, 0.75f, 4)); - - ffmpLoadedUris.put(siteKey, tempLoadedUris); - } - - if (!ffmpLoadedUris.get(siteKey) - .get(sourceName).get(phuc) - .containsKey(uri)) { - // populate point only - populateFFMPBasin(uri, siteKey, sourceName, - phuc, fgb); - } else { - break POINT_RETRIVAL; - } - } - } - } - } - } - } else { - // populate if it isn't there - SortedMap> availableUris = getAvailableUris( - siteKey, dataKey, sourceName, ptime); - - if ((availableUris != null) && (availableUris.size() > 0)) { - POINT_RETRIVAL: for (List uris : availableUris.values()) { - for (String uri : uris) { - - if (!ffmpLoadedUris.containsKey(siteKey)) { - - ConcurrentHashMap>> tempLoadedUris = new ConcurrentHashMap>>(); - - if (product != null) { - for (String source : product.getSources()) { - - tempLoadedUris - .put(source, - new ConcurrentHashMap>( - 16, 0.75f, 4)); - } - - ffmpLoadedUris.put(siteKey, tempLoadedUris); - - } else { - tempLoadedUris - .put(sourceName, - new ConcurrentHashMap>( - 16, 0.75f, 4)); - ffmpLoadedUris.put(siteKey, tempLoadedUris); - } - } - - if (!ffmpLoadedUris.get(siteKey) - .containsKey(sourceName)) { - ConcurrentHashMap>> tempLoadedUris = new ConcurrentHashMap>>(); - tempLoadedUris - .put(sourceName, - new ConcurrentHashMap>( - 16, 0.75f, 4)); - ffmpLoadedUris.put(siteKey, tempLoadedUris); - } - - if (!ffmpLoadedUris.get(siteKey).get(sourceName) - .containsKey(phuc)) { - ffmpLoadedUris - .get(siteKey) - .get(sourceName) - .put(phuc, - new ConcurrentHashMap()); - } - - if (!ffmpLoadedUris.get(siteKey).get(sourceName) - .get(phuc).containsKey(uri)) { - // populate point only - populateFFMPBasin(uri, siteKey, sourceName, phuc, - basin); - } else { - break POINT_RETRIVAL; - } - } - } - } - } - - return basin; - } - - /** - * Gets the valid time window for the source as a long - * - * @param sourceName - * @return - */ - public long getSourceTimeWindow(String sourceName, String siteKey) { - return getSourceConfig().getSource(sourceName).getExpirationMinutes( - siteKey) * 60 * 1000; - } - - /** - * gets the time window object - * - * @param sourceName - * @return - */ - public FFMPTimeWindow getTimeWindow(String sourceName, Date date, - String siteKey) { - FFMPTimeWindow window = new FFMPTimeWindow(); - long lwindow = getSourceTimeWindow(sourceName, siteKey); - window.setAfterTime(new Date(date.getTime() - lwindow)); - window.setBeforeTime(new Date(date.getTime() + lwindow)); - - return window; - } - - public FFMPTimeWindow getQpfWindow() { - return qpfWindow; - } - - public void setQpfWindow(FFMPTimeWindow qpfWindow) { - this.qpfWindow = qpfWindow; - } - - public FFMPTimeWindow getQpeWindow() { - return qpeWindow; - } - - public void setQpeWindow(FFMPTimeWindow qpeWindow) { - this.qpeWindow = qpeWindow; - } - - @Override - public ArrayList getTimeOrderedKeys(IMonitor monitor, String type) { - // TODO Auto-generated method stub - return null; - } - - /** - * fire off a cleaner - * - * @param product - * @param source - * @param siteKey - * @param date - */ - public void purgeFFMPData(ProductXML product, String source, - String siteKey, Date date) { - PurgeFFMPData pfd = new PurgeFFMPData(product, source, siteKey, date); - pfd.purge(); - } - - /** - * Purge old data from the cache - * - * @author dhladky - * - */ - private class PurgeFFMPData implements Runnable { - - final ProductXML fproduct; - - final String fsource; - - final String fsiteKey; - - final Date fdate; - - public PurgeFFMPData(ProductXML product, String source, String siteKey, - Date date) { - - this.fproduct = product; - this.fsource = source; - this.fsiteKey = siteKey; - this.fdate = date; - } - - @Override - public void run() { - try { - purge(); - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - "Unable to purge Data from FFMP cache, ", e); - } - } - - public void purge() { - - ArrayList purgeSources = new ArrayList(); - - if (fproduct != null) { - - ProductRunXML productRun = getRunConfig().getProduct(fsiteKey); - - // guidance - for (String type : productRun.getGuidanceTypes(fproduct)) { - for (SourceXML guidSource : productRun.getGuidanceSources( - fproduct, type)) { - if (guidSource != null) { - purgeSources.add(guidSource.getSourceName()); - } - } - } - - // qpf - for (String type : productRun.getQpfTypes(fproduct)) { - for (SourceXML qpfSource : productRun.getQpfSources( - fproduct, type)) { - if (qpfSource != null) { - purgeSources.add(qpfSource.getSourceName()); - } - } - } - // qpe, etc - for (String sourceName : fproduct.getSources()) { - if (!purgeSources.contains(sourceName)) { - purgeSources.add(sourceName); - } - } - - for (String sourceName : purgeSources) { - - SourceXML source = fscm.getSource(sourceName); - - if (source != null) { - if (source.getSourceType().equals( - SOURCE_TYPE.GUIDANCE.getSourceType())) { - sourceName = SOURCE_TYPE.GUIDANCE.getSourceType(); - } - - if (ffmpData != null) { - if (ffmpData.containsKey(fsiteKey)) { - FFMPRecord record = ffmpData.get(fsiteKey).get( - sourceName); - if (record != null) { - record.purgeData(fdate); - } - } - } - } - } - - } else { - if (ffmpData != null) { - if (ffmpData.containsKey(fsiteKey)) { - FFMPRecord record = ffmpData.get(fsiteKey).get(fsource); - if (record != null) { - record.purgeData(fdate); - } - } - } - } - - if (ffmpAvailableUris != null) { - for (Entry>> entry : ffmpAvailableUris - .get(fsiteKey).entrySet()) { - ConcurrentNavigableMap> oldUris = entry - .getValue().headMap(fdate); - for (List uris : oldUris.headMap(fdate).values()) { - for (String uri : uris) { - - if (fproduct != null) { - - for (String sourceName : purgeSources) { - - if (ffmpLoadedUris.get(fsiteKey) - .containsKey(sourceName)) { - for (ConcurrentHashMap loadedUris : ffmpLoadedUris - .get(fsiteKey).get(sourceName) - .values()) { - loadedUris.remove(uri); - } - } - } - } else { - for (ConcurrentHashMap loadedUris : ffmpLoadedUris - .get(fsiteKey).get(fsource).values()) { - loadedUris.remove(uri); - } - } - } - } - - oldUris.clear(); - } - } - } - } - - /** - * Process an individual URI - * - * @param isProductLoad - * @param uri - * @param siteKey - * @param sourceName - * @param barrierTime - * @param phuc - */ - public void processUri(boolean isProductLoad, String uri, String siteKey, - String sourceName, Date barrierTime, String phuc) { - - final boolean fisProductLoad = isProductLoad; - final String furi = uri; - final String fsiteKey = siteKey; - final String fsourceName = sourceName; - final String fhuc = phuc; - - VizApp.runAsync(new Runnable() { - @Override - public void run() { - - SourceXML source = getSourceConfig().getSource(fsourceName); - - if (furi != null) { - FFMPRecord record = new FFMPRecord(furi); - - try { - record = populateFFMPRecord(fisProductLoad, furi, - fsiteKey, fsourceName, fhuc); - if ((record != null) && (source != null)) { - record.setExpiration(source - .getExpirationMinutes(fsiteKey)); - record.setRate(source.isRate()); - } - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - "FFMP Can't retrieve FFMP URI, " + furi, e); - } - } - } - }); - } - - /** - * Adds this source to the URI hash in the monitor - * - * @param uris - * @param sourceName - */ - public void processUris(NavigableMap> uriMap, - boolean isProductLoad, String siteKey, String sourceName, - Date barrierTime, String phuc, LOADER_TYPE type) { - - // don't wrap it, locks UI thread - if ((type == LOADER_TYPE.GENERAL) || (type == LOADER_TYPE.TERTIARY)) { - - FFMPProcessUris processor = new FFMPProcessUris(uriMap, - isProductLoad, siteKey, sourceName, barrierTime, phuc); - processor.run(); - - } else { - - final boolean fisProductLoad = isProductLoad; - final NavigableMap> furiMap = uriMap; - final String fsiteKey = siteKey; - final String fsourceName = sourceName; - final Date fbarrierTime = barrierTime; - final String fhuc = phuc; - - VizApp.runAsync(new Runnable() { - @Override - public void run() { - - SourceXML source = getSourceConfig().getSource(fsourceName); - - if (furiMap != null) { - for (List uris : furiMap.descendingMap() - .values()) { - for (String uri : uris) { - if (uri != null) { - FFMPRecord record = new FFMPRecord(uri); - if (record.getDataTime().getRefTime() - .after(fbarrierTime) - || source - .getSourceType() - .equals(FFMPSourceConfigurationManager.SOURCE_TYPE.GUIDANCE - .getSourceType())) { - try { - - if (!getUriMap(fsiteKey, - fsourceName, fhuc) - .containsKey(uri)) { - - record = populateFFMPRecord( - fisProductLoad, uri, - fsiteKey, fsourceName, - fhuc); - - if ((record != null) - && (source != null)) { - record.setExpiration(source - .getExpirationMinutes(fsiteKey)); - record.setRate(source - .isRate()); - } - } - - } catch (Exception e) { - statusHandler.handle( - Priority.PROBLEM, - "FFMP Can't retrieve FFMP URI, " - + uri, e); - } - } - } - } - } - } - } - }); - } - } - - @Override - protected void nullifyMonitor(String icao) { - // TODO Auto-generated method stub - - } - - /** - * Gets the HUC templates - * - * @return - */ - public FFMPTemplates getTemplates(String siteKey) { - if (templates == null) { - FFMPRunXML runner = getRunConfig().getRunner(wfo); - this.templates = FFMPTemplates.getInstance( - runner.getPrimaryDomain(), siteKey, MODE.CAVE); - // backup domains - if (runner.getBackupDomains() != null) { - for (DomainXML backup : runner.getBackupDomains()) { - templates.addDomain(siteKey, backup); - } - } else { - templates.done = true; - } - } - - if (!templates.isSiteLoaded(siteKey)) { - FFMPRunXML runner = getRunConfig().getRunner(wfo); - - for (DomainXML domain : runner.getDomains()) { - templates.addDomain(siteKey, domain); - } - } - - return templates; - } - - /** - * Get the Run configuration - * - * @return - */ - public FFMPRunConfigurationManager getRunConfig() { - if (frcm == null) { - frcm = FFMPRunConfigurationManager.getInstance(); - } - return frcm; - } - - /** - * Get the PP and PC values from curpp and curpc tables - * - * @param pfaf - * @param lid - * @param refTime - */ - public FFMPVirtualGageBasin getVirtualGageBasinData(long pfaf, String lid, - Date refTime) { - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - TimeZone gmt = TimeZone.getTimeZone("GMT"); - final String ihfs = "ihfs"; - FFMPVirtualGageBasin basin = new FFMPVirtualGageBasin(lid, pfaf, false); - - sdf.setTimeZone(gmt); - - Calendar cal = Calendar.getInstance(gmt); - cal.setTime(refTime); - cal.add(Calendar.HOUR_OF_DAY, -24); - Date startTime = cal.getTime(); - - String starttime = sdf.format(startTime); - String endtime = sdf.format(refTime); - - /* - * First we will check "PC" precip data from the database; The big issue - * of the PC data is that the gage amount sometimes is re-set to "zero" - * which will be ignored. If the "PC" data is not available, then we - * will check for its "PP" data which is less frequently updated most of - * the times and has an issue of "duration" (1 min, 15 min, 30 min, 1 - * hour, 2 hours, 3 hours and 6 hours) we have to deal with. - */ - String pe = "PC"; - String tablename = "curpc"; - - String format = "SELECT lid, pe, dur, ts, obstime, value, product_id " - + "FROM %s WHERE lid = '%s' AND obstime >= '%s' AND obstime < '%s' " - + "AND pe = '%s' ORDER BY obstime DESC, ts ASC"; - - String sql = String.format(format, tablename, lid, starttime, endtime, - pe); - - List precipData = null; - try { - precipData = DirectDbQuery.executeQuery(sql, ihfs, - QueryLanguage.SQL); - } catch (VizException e) { - // problem querying PC data - e.printStackTrace(); - } - - // if PC data NOT available - if ((precipData == null) || (precipData.size() == 0)) { - - pe = "PP"; - tablename = "curpp"; - String desiredDur = "1001"; - format = "SELECT lid, pe, dur, ts, obstime, value, product_id " - + "FROM %s WHERE lid = '%s' AND obstime >= '%s' AND obstime < '%s' " - + "AND pe = '%s' AND dur <= %s AND value >=0 ORDER BY dur ASC, " - + "obstime DESC, ts ASC"; - - sql = String.format(format, tablename, lid, starttime, endtime, pe, - desiredDur); - - try { - precipData = DirectDbQuery.executeQuery(sql, ihfs, - QueryLanguage.SQL); - } catch (VizException e) { - // problem querying PP data - e.printStackTrace(); - } - - if ((precipData == null) || (precipData.size() == 0)) { - return null; - } - } - - /* - * need to check whether the data list contains records from different - * type source which should not be plotted in one graph. Use the - * "ingestfilter" table to pick up the type source with the highest type - * ranking order. - */ - String typeSrc = null; - List uniqueSrcType = new ArrayList(); - List trendData = new ArrayList(); - - // no type source need to be checked if only one record is found. - if (precipData.size() > 1) { - for (Object[] oa : precipData) { - String ts = (String) oa[3]; - if (uniqueSrcType.contains(ts) == false) { - uniqueSrcType.add(ts); - } - } - - if (uniqueSrcType.size() > 1) { - /* - * more than one ts found. Get the type source rankings by - * accessing the "ingestfilter" table in the database. The - * smaller the type source rank value is, the higher priority - * the type source should be taken into account. - */ - format = "SELECT dur, ts, ts_rank FROM ingestFilter WHERE " - + "lid = '%s' AND pe = '%s' ORDER BY ts_rank ASC"; - - sql = String.format(format, lid, pe); - List rs = null; - - try { - rs = DirectDbQuery.executeQuery(sql, ihfs, - QueryLanguage.SQL); - } catch (VizException e) { - // problem querying IngestFilter table - e.printStackTrace(); - } - - if ((rs != null) && (rs.size() > 0)) { - typeSrc = (String) rs.get(0)[1]; - } - - // Get the records of the desired type source. - for (Object[] oa : precipData) { - if (((String) oa[3]).equals(typeSrc)) { - trendData.add(oa); - } - } - } else { - for (Object[] oa : precipData) { - trendData.add(oa); - } - } - } - - // processing gage data - float gageAccu = 0; - - if (pe.equalsIgnoreCase("PP")) { - // to select the data with the shortest duration from - // durations of 1 min, 15 min, 30 min, 1 hr and 2 hrs. - TreeSet durOrderSet = new TreeSet(); - - for (Object[] oa : trendData) { - int dur = Integer.parseInt((String) oa[2]); - durOrderSet.add(dur); - } - - // need to get the max duration for each hour - List> idxSameHour = getMaxDurationPerHour(trendData); - - Iterator iter = durOrderSet.iterator(); - int maxDur = 0; - boolean first = true; - List data1Dur = null; - - while (iter.hasNext()) { - if (first) { - maxDur = iter.next(); - first = false; - } - - // Notes (02/07/2006): For the AWOS and ASOS sites, the metar - // data are converted by SHEFDECODER and then saved into the PP - // precip database. But the metar data taken at 0005Z - // (20 min duration), 0025Z (40 min duration) and - // 0045Z (60 min duration) might be stored as records with - // 1-hour duration (as dur=1001). To avoid to count the - // 1-hour precip for multipe times for one same period, - // only ONE of the multiple records will be taken for VGB - // gage plot. Using the maximum duration -- 1-hr dur will - // be the most representative one. Need to make sure only - // one data point should be used within each hour if those - // multiple data points have the same duration for this hour. - data1Dur = selectMaxDurData(trendData, maxDur, idxSameHour); - - if (data1Dur.size() > 0) { - break; - } - } - - long secondsL = 0; // duration left bound - long secondsR = 0; // duration right bound - Date t1 = refTime; - // Date t0 = refTime - purgeTime; - long dur = 0; - - if (data1Dur != null) { - // should differentiate the "duration" of the gage data. - for (int i = 0; i < data1Dur.size(); i++) { - secondsL = (t1.getTime() - ((Date) data1Dur.get(i)[4]) - .getTime()) / 1000; - if (((Integer) data1Dur.get(i)[2]) > 1000) { - dur = ((Integer) data1Dur.get(i)[2] - 1000) - * SECONDS_PER_HOUR; - } else { - dur = ((Integer) data1Dur.get(i)[2]) * 1000; - } - - secondsR = secondsL + dur; // time drawn in reverse way - // we can not include the future gage data into the plot - // compared - // to the latest inv time of FFMP accum - // Note: for PP data, each precip value relates to two time - // instants - // based on "duration". A horizontal line (composed of two - // points) will be drawn to represent the precip during - // each "duration" period. - if ((secondsL < 0) || (secondsR > t1.getTime() / 1000)) { // gage - // data - // ahead - // of - // or - // beyond - // radar - // time - // range - continue; - } else { - gageAccu += (Float) data1Dur.get(i)[5]; - basin.setValue(refTime, gageAccu); - } - } - } - } else { // PC Data - long seconds = 0; // initialized - Date t1 = refTime; - if ((trendData != null) && (trendData.size() > 0)) { - double firstValue = (Double) trendData.get(0)[5]; - for (int i = 0; i < trendData.size(); i++) { - Date dataDate = (Date) trendData.get(i)[4]; - Double value = (Double) trendData.get(i)[5]; - double prevValue = -99; - if (i > 1) { - prevValue = (Double) trendData.get(i - 1)[5]; - } - - seconds = (t1.getTime() - ((Date) trendData.get(i)[4]) - .getTime()) / 1000; - - if ((seconds < 0) || (seconds > t1.getTime() / 1000)) { // gage - // range - continue; - } else if (i == 0) { - // accum is set to zero at the first gage data point. - basin.setValue(dataDate, gageAccu); - } else { - if (value < 0) { // if cur point unavailable - continue; - } else if (prevValue < 0) { // previous point N/A - if (firstValue > 0) { - gageAccu = (float) (firstValue - value); - } else { - continue; - } - } else { - double dAccu = prevValue - value; - if (dAccu < 0) { // gage reading error - continue; - } else { - gageAccu += dAccu; - // Note: PC data are the rain amount that fallen - // since some time when the "counter" was set to - // 0. - // So we can not count the accum if gage_accu is - // a negative value which means the accumulation - // will be re-started from zero. - } - - basin.setValue(dataDate, gageAccu); - } - } - } - } - } - - return basin; - } - - private List selectMaxDurData(List org, int dur, - List> idxSameHour) { - List filtered = new ArrayList(); - - // go through the indices for each hour period - for (int i = 0; i < idxSameHour.size(); i++) { - // select the max obsTime at desired duration as the data point - // to be used as the representative within each hour. Since the - // obstime was sorted in the descending order, the first one will be - // the max Obstime for the specified hour. - for (int j = 0; j < idxSameHour.size(); j++) { - if ((Integer) org.get(idxSameHour.get(i).get(j))[4] == dur) { - // the obsTime has already been in DESCENDING order, so the - // largest one for the hour is what we are looking for. - filtered.add(org.get(idxSameHour.get(i).get(j))); - } - } - } - - return filtered; - } - - private List> getMaxDurationPerHour(List data) { - List> idx = new ArrayList>(); - ArrayList dummyIdx = new ArrayList(); - - for (int i = 0; i < data.size(); i++) { - Object[] oa = data.get(i); - if (i < data.size() - 1) { - dummyIdx.add(i); - if (!withinSameHour((Date) oa[4], (Date) data.get(i + 1)[4])) { - idx.add(dummyIdx); - dummyIdx.clear(); - } - } else { // for the LAST time element - if (withinSameHour((Date) data.get(i - 1)[4], (Date) oa[4])) { - // Note: the previously grouped times have not been inserted - // into the list, so add it with the last time element. - dummyIdx.add(i); - idx.add(dummyIdx); - dummyIdx.clear(); - } else { - // Note: the last time element does NOT belong to the - // previous group, - dummyIdx.add(i); - idx.add(dummyIdx); - dummyIdx.clear(); - } - } - } - - return idx; - } - - /** - * To check whether the passed-in hours belong to the same hour period. - * - * @param a - * Date - * @param b - * Date - * @return true if times belong to the same hour - */ - private boolean withinSameHour(Date a, Date b) { - TimeZone gmt = TimeZone.getTimeZone("GMT"); - Calendar calA = Calendar.getInstance(gmt); - calA.setTime(a); - Calendar calB = Calendar.getInstance(gmt); - calB.setTime(b); - if (calB.get(Calendar.MINUTE) == 0) { - return false; - } else if ((calA.get(Calendar.YEAR) == calB.get(Calendar.YEAR)) - && (calA.get(Calendar.MONTH) == calB.get(Calendar.MONTH)) - && (calA.get(Calendar.DAY_OF_MONTH) == calB - .get(Calendar.DAY_OF_MONTH))) { - if (calA.get(Calendar.HOUR_OF_DAY) == calB - .get(Calendar.HOUR_OF_DAY)) { - return true; - } else if ((calA.get(Calendar.MINUTE) == 0) - && (Math.abs(calA.getTimeInMillis() - - calB.getTimeInMillis()) < (60 * 60))) { - return true; - } - } - - return false; - } - - /** - * Update FFFG - */ - public void updateFFFG() { - - fffg = FFFGDataMgr.getUpdatedInstance(); - - for (IFFMPResourceListener listener : getResourceListenerList()) { - if (listener instanceof FFMPResource) { - - FFMPResource resource = (FFMPResource) listener; - resource.dirty(); - resource.refresh(); - resource.clearTables(); - - if (resource.getResourceData().tableLoad) { - updateDialog(resource); - } - } - } - } - - /** - * Gets the previous URI available - * - * @param siteKey - * @param sourceName - * @return - */ - public Date getPreviousQueryTime(String siteKey, String sourceName) { - return ffmpAvailableUriQueryDates.get(siteKey).get(sourceName); - } - - /** - * class used to thread data loads - * - * @author dhladky - * - */ - private class FFMPLoadRecord implements Runnable { - - final FFMPRecord fffmpRec; - - final String fsource; - - final String fhuc; - - final String fsiteKey; - - final boolean fisProductLoad; - - public FFMPLoadRecord(boolean isProductLoad, String siteKey, - FFMPRecord ffmpRec, String source, String huc) throws Exception { - this.fffmpRec = ffmpRec; - this.fsource = source; - this.fsiteKey = siteKey; - this.fisProductLoad = isProductLoad; - this.fhuc = huc; - } - - public void run() { - try { - load(); - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, "FFMP load FFMPData, " - + fsource + " " + fhuc, e); - } - } - - public void load() { - if (fffmpRec != null) { - - ConcurrentMap uris = getUriMap(fsiteKey, - fsource, fhuc); - String dataUri = fffmpRec.getDataURI(); - if (!uris.containsKey(dataUri)) { - File loc = HDF5Util.findHDF5Location(fffmpRec); - IDataStore dataStore = DataStoreFactory.getDataStore(loc); - - if (!ffmpData.containsKey(fsiteKey)) { - ConcurrentHashMap fieldRecs = new ConcurrentHashMap(); - ffmpData.put(fsiteKey, fieldRecs); - } - - String mySource = fsource; - SourceXML source = fscm.getSource(fsource); - - if (source.getSourceType().equals( - SOURCE_TYPE.GUIDANCE.getSourceType()) - && fisProductLoad) { - mySource = source.getDisplayName(); - } - - FFMPRecord curRecord = ffmpData.get(fsiteKey).get(mySource); - if (curRecord == null) { - // ensure the record can only be set once - synchronized (ffmpData) { - curRecord = ffmpData.get(fsiteKey).get(mySource); - if (curRecord == null) { - curRecord = fffmpRec; - ffmpData.get(fsiteKey).put(mySource, curRecord); - } - } - } - - SourceXML sourceXML = fscm.getSource(mySource); - - if ((sourceXML != null) - && sourceXML.getSourceType().equals( - SOURCE_TYPE.GAGE.getSourceType()) - && fhuc.equals("ALL")) { - try { - curRecord.retrieveVirtualMapFromDataStore( - dataStore, dataUri, getTemplates(fsiteKey), - fffmpRec.getDataTime().getRefTime(), - fffmpRec.getSourceName()); - } catch (FileNotFoundException e) { - statusHandler.handle(Priority.PROBLEM, - "FFMP Can't find FFMP URI, " + dataUri, e); - } catch (StorageException e) { - statusHandler.handle(Priority.PROBLEM, - "FFMP Can't retrieve (Storage problem) FFMP URI, " - + dataUri, e); - } - } else { - try { - statusHandler.handle(Priority.INFO, - "Retrieving and Populating URI: , " - + dataUri); - curRecord.retrieveMapFromDataStore(dataStore, - dataUri, getTemplates(fsiteKey), fhuc, - fffmpRec.getDataTime().getRefTime(), - fffmpRec.getSourceName()); - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - "FFMP Can't retrieve FFMP URI, " + dataUri, - e); - e.printStackTrace(); - } - } - - ConcurrentHashMap>> siteLoadedUris = ffmpLoadedUris - .get(fsiteKey); - - if (siteLoadedUris == null) { - - siteLoadedUris = new ConcurrentHashMap>>(); - ffmpLoadedUris.put(fsiteKey, siteLoadedUris); - } - - ConcurrentHashMap> sourceLoadedUris = ffmpLoadedUris - .get(fsiteKey).get(fsource); - - if (sourceLoadedUris == null) { - - sourceLoadedUris = new ConcurrentHashMap>(); - ffmpLoadedUris.get(fsiteKey).put(fsource, - sourceLoadedUris); - } - - ConcurrentHashMap hucLoadedUris = ffmpLoadedUris - .get(fsiteKey).get(fsource).get(fhuc); - - if (hucLoadedUris == null) { - - hucLoadedUris = new ConcurrentHashMap(); - ffmpLoadedUris.get(fsiteKey).get(fsource) - .put(fhuc, hucLoadedUris); - } - - synchronized (hucLoadedUris) { - // ensure not created by another thread - ffmpLoadedUris.get(fsiteKey).get(fsource).get(fhuc) - .put(dataUri, dataUri); - } - } - } - } - } - - /** - * Thread the uri processing - * - * @author dhladky - * - */ - private class FFMPProcessUris implements Runnable { - - final NavigableMap> furiMap; - - final boolean fisProductLoad; - - final String fsiteKey; - - final String fsourceName; - - final Date fbarrierTime; - - final String fhuc; - - public FFMPProcessUris(NavigableMap> uriMap, - boolean isProductLoad, String siteKey, String sourceName, - Date barrierTime, String phuc) { - - this.furiMap = uriMap; - this.fsiteKey = siteKey; - this.fbarrierTime = barrierTime; - this.fisProductLoad = isProductLoad; - this.fsourceName = sourceName; - this.fhuc = phuc; - - } - - public void run() { - SourceXML source = getSourceConfig().getSource(fsourceName); - - if (furiMap != null) { - for (List uris : furiMap.descendingMap().values()) { - for (String uri : uris) { - if (uri != null) { - FFMPRecord record = new FFMPRecord(uri); - if (record.getDataTime().getRefTime() - .after(fbarrierTime) - || source - .getSourceType() - .equals(FFMPSourceConfigurationManager.SOURCE_TYPE.GUIDANCE - .getSourceType())) { - try { - - if (!getUriMap(fsiteKey, fsourceName, fhuc) - .containsKey(uri)) { - - record = populateFFMPRecord( - fisProductLoad, uri, fsiteKey, - fsourceName, fhuc); - - if ((record != null) - && (source != null)) { - record.setExpiration(source - .getExpirationMinutes(fsiteKey)); - record.setRate(source.isRate()); - } - } - - } catch (Exception e) { - statusHandler.handle(Priority.PROBLEM, - "FFMP Can't retrieve FFMP URI, " - + uri, e); - } - } - } - } - } - } - } - } + private static final transient IUFStatusHandler statusHandler = UFStatus + .getHandler(FFMPMonitor.class); + + @Override + public void nullifyMonitor() { + + if (resourceListeners != null) { + for (IFFMPResourceListener listener : resourceListeners) { + if (listener instanceof FFMPResource) { + FFMPResource res = (FFMPResource) listener; + if (res.basinTableDlg != null) { + closeDialog(res); + } + + // will kill any loaders running + if (res.getResourceData().floader != null) { + res.getResourceData().floader.kill(); + res.getResourceData().floader = null; + } + } + } + + // clear the resource list + resourceListeners.clear(); + } + + // clear all remaining data + if (ffmpData != null) { + for (String key : ffmpData.keySet()) { + for (Entry entry : ffmpData.get(key) + .entrySet()) { + entry.getValue().closeCache(); + } + } + } + + ffmpData = null; + ffmpAvailableUriQueryDates = null; + ffmpAvailableUris = null; + ffmpLoadedUris = null; + + // kill this monitor + monitor = null; + System.gc(); + } + + @Override + public void thresholdUpdate(IMonitorThresholdEvent me) { + // TODO Auto-generated method stub + } + + @Override + public void configUpdate(IMonitorConfigurationEvent me) { + // updates the config + getSourceConfig().readConfigXml(); + boolean isLinkToFrame = getConfig().getFFMPConfigData() + .getLinkToFrame(); + + for (IFFMPResourceListener listener : resourceListeners) { + + listener.setLinkToFrame(isLinkToFrame); + + if (listener.isAutoRefresh()) { + listener.setQuery(true); + fireRefresh(listener); + } + + listener.updateDialog(); + } + } + + /** + * Actual initialization if necessary + * + * @return + */ + public static synchronized FFMPMonitor getInstance() { + if (monitor == null) { + monitor = new FFMPMonitor(); + monitor.createDataStructures(); + isInitialized = true; + } + + return monitor; + } + + /** + * check for life + * + * @return + */ + public static boolean isRunning() { + + if (monitor == null) { + return false; + } + + return true; + } + + /** + * get a ref to the config + * + * @return + */ + public FFMPSourceConfigurationManager getSourceConfig() { + if (fscm == null) { + fscm = FFMPSourceConfigurationManager.getInstance(); + fscm.readConfigXml(); + } + + return fscm; + } + + /** + * Gets the FFFG manager + * + * @return + */ + public FFFGDataMgr getFFFGConfig() { + if (fffg == null) { + fffg = FFFGDataMgr.getInstance(); + } + + return fffg; + } + + /** + * Gets the dialog config + * + * @return + */ + public FFMPConfig getConfig() { + if (ffmpConfig == null) { + ffmpConfig = FFMPConfig.getInstance(); + } + return ffmpConfig; + } + + /** + * Creates the linked maps + */ + private void createDataStructures() { + ffmpData = new ConcurrentHashMap>(); + ffmpAvailableUris = new ConcurrentHashMap>>>(); + ffmpAvailableUriQueryDates = new ConcurrentHashMap>(); + ffmpLoadedUris = new ConcurrentHashMap>>>(); + } + + /** + * gets the URI's by field type and site + * + * @param siteKey + * @param pfield + * @param phuc + * @return + */ + private ConcurrentHashMap getUriMap(String siteKey, + String source, String phuc) { + + ConcurrentHashMap>> siteLoadedUris = null; + + if (ffmpLoadedUris != null) { + siteLoadedUris = ffmpLoadedUris.get(siteKey); + } + + if (siteLoadedUris == null) { + siteLoadedUris = new ConcurrentHashMap>>(); + ffmpLoadedUris.put(siteKey, siteLoadedUris); + } + + ConcurrentHashMap> sourceLoadedUris = null; + + if (ffmpLoadedUris != null) { + sourceLoadedUris = ffmpLoadedUris.get(siteKey).get(source); + } + + if (sourceLoadedUris == null) { + + sourceLoadedUris = new ConcurrentHashMap>(); + ffmpLoadedUris.get(siteKey).put(source, sourceLoadedUris); + } + + ConcurrentHashMap hucLoadedUris = null; + + if (ffmpLoadedUris != null) { + hucLoadedUris = ffmpLoadedUris.get(siteKey).get(source).get(phuc); + } + + if (hucLoadedUris == null) { + + hucLoadedUris = new ConcurrentHashMap(200, 0.75f, 4); + if (ffmpLoadedUris != null) { + ffmpLoadedUris.get(siteKey).get(source) + .put(phuc, hucLoadedUris); + } + } + + return hucLoadedUris; + } + + /** + * Static to make it fast, at least that's the idea. + * + * @param uri + * @return + * @throws VizException + */ + private static FFMPRecord loadRecordFromDatabase(String uri) + throws VizException { + FFMPRecord ffmpRec = null; + + if (uri != null) { + Map vals = new HashMap(); + vals.put("pluginName", "ffmp"); + vals.put("dataURI", uri); + ffmpRec = (FFMPRecord) Loader.loadData(vals); + } + + return ffmpRec; + } + + /** + * populate a new FFMPRecord + * + * @param sourceName + * @param icao + * @param refTime + * @return + * @throws VizException + */ + public void populateFFMPRecord(ProductXML product, String siteKey, + String dataKey, String source, Date ptime, String phuc, + boolean retrieveNew) { + + boolean isProductLoad = false; + if (product != null) { + isProductLoad = true; + } + + if (source != null) { + + SortedMap> urisByDate = getAvailableUris( + siteKey, dataKey, source, ptime, retrieveNew); + + if (urisByDate != null) { + for (List uris : urisByDate.values()) { + for (String uri : uris) { + if ((uri != null) + && !getUriMap(siteKey, source, phuc) + .containsKey(uri)) { + try { + populateFFMPRecord(isProductLoad, siteKey, + loadRecordFromDatabase(uri), source, + phuc); + } catch (Exception e) { + statusHandler.handle(Priority.PROBLEM, + "FFMP Can't retrieve FFMP URI, " + uri, + e); + } + } + } + } + } + } + } + + /** + * populate a new FFMPRecord + * + * @param sourceName + * @param icao + * @param refTime + * @return + * @throws VizException + */ + public FFMPCacheRecord populateFFMPRecord(boolean isProductLoad, + String uri, String siteKey, String source, String phuc) + throws Exception { + + try { + populateFFMPRecord(isProductLoad, siteKey, + loadRecordFromDatabase(uri), source, phuc); + } catch (VizException e) { + statusHandler.handle(Priority.INFO, + "FFMP Can't retrieve FFMP URI, " + uri, e); + } + + return ffmpData.get(siteKey).get(source); + } + + /** + * Inserts the loader records directly into the cache + * + * @param data + * @param siteKey + * @param dataKey + * @param source + * @param huc + */ + public void insertFFMPData(FFMPBasinData data, String siteKey, + String source, String huc) { + + final String fsiteKey = siteKey; + final FFMPBasinData fdata = data; + final String fsource = source; + final String fhuc = huc; + + VizApp.runAsync(new Runnable() { + @Override + public void run() { + + if (ffmpData.containsKey(fsiteKey)) { + if (ffmpData.get(fsiteKey).containsKey(fsource)) { + ffmpData.get(fsiteKey).get(fsource) + .setBasinBuddyData(fdata, fhuc); + } + } + } + }); + } + + /** + * Try and get the loading off of the GUI thread + * + * @param isProductLoad + * @param siteKey + * @param ffmpRec + * @param source + * @param phuc + * @throws Exception + */ + public void populateFFMPRecord(boolean isProductLoad, String siteKey, + FFMPRecord ffmpRec, String source, String phuc) throws Exception { + + FFMPLoadRecord flr = new FFMPLoadRecord(isProductLoad, siteKey, + ffmpRec, source, phuc); + flr.run(); + } + + /** + * Get load of basins off the main thread + * + * @param dataUri + * @param siteKey + * @param source + * @param phuc + * @param basin + * @throws VizException + */ + public void populateFFMPBasin(String dataUri, String siteKey, + String source, String phuc, FFMPBasin basin) throws VizException { + + final String fdataUri = dataUri; + final String fsiteKey = siteKey; + final String fhuc = phuc; + final String fsource = source; + final FFMPBasin fbasin = basin; + + VizApp.runAsync(new Runnable() { + @Override + public void run() { + + if (fdataUri != null) { + ConcurrentMap uris = getUriMap(fsiteKey, + fsource, fhuc); + if (!uris.containsKey(fdataUri)) { + try { + FFMPRecord ffmpRec = loadRecordFromDatabase(fdataUri); + File loc = HDF5Util.findHDF5Location(ffmpRec); + IDataStore dataStore = DataStoreFactory + .getDataStore(loc); + SourceXML sourceXML = fscm.getSource(fsource); + + if (sourceXML.getSourceType().equals( + SOURCE_TYPE.GAGE.getSourceType()) + && fhuc.equals("ALL")) { + ffmpRec.retrieveVirtualBasinFromDataStore( + dataStore, fdataUri, + getTemplates(fsiteKey), ffmpRec + .getDataTime().getRefTime(), + fbasin); + } else { + ffmpRec.retrieveBasinFromDataStore(dataStore, + fdataUri, getTemplates(fsiteKey), fhuc, + ffmpRec.getDataTime().getRefTime(), + ffmpRec.getSourceName(), fbasin); + } + } catch (Throwable e) { + try { + throw new VizException( + "Error occurred loading uri " + + fdataUri, e); + } catch (VizException e1) { + statusHandler.handle(Priority.PROBLEM, + "FFMP Can't retrieve FFMP URI, " + + fdataUri, e1); + } + } + } + } + } + }); + } + + /** + * Getting a specific URI + * + * @param date + * @return + */ + public String getAvailableUri(String siteKey, String dataKey, + String sourceName, Date ptime) { + + String uri = null; + SimpleDateFormat datef = new SimpleDateFormat(datePattern); + datef.setTimeZone(TimeZone.getTimeZone("Zulu")); + String sql = "select datauri from ffmp where wfo = '" + getWfo() + + "' and reftime = '" + datef.format(ptime) + + "' and sourcename = '" + sourceName + "' and sitekey = '" + + siteKey + "' and datakey = '" + dataKey + + "' order by reftime"; + try { + List results = DirectDbQuery.executeQuery(sql, + "metadata", QueryLanguage.SQL); + if (results.size() > 0) { + uri = (String) results.get(0)[0]; + } + } catch (VizException e) { + e.printStackTrace(); + } + + return uri; + } + + public ConcurrentNavigableMap> getAvailableUris( + String siteKey, String dataKey, String sourceName, Date time) { + return getAvailableUris(siteKey, dataKey, sourceName, time, false); + } + + /** + * Gets the available uris back to a given time + * + * @param date + * @return + */ + public ConcurrentNavigableMap> getAvailableUris( + String siteKey, String dataKey, String sourceName, Date time, + boolean retrieveNew) { + + if (!ffmpAvailableUris.containsKey(siteKey)) { + ConcurrentHashMap>> tempUriList = new ConcurrentHashMap>>( + 16, 0.75f, 4); + ffmpAvailableUris.put(siteKey, tempUriList); + } + + ConcurrentSkipListMap> sortedUris = ffmpAvailableUris + .get(siteKey).get(sourceName); + if (sortedUris == null) { + synchronized (ffmpAvailableUris) { + // double check in case another thread created in the mean time + sortedUris = ffmpAvailableUris.get(siteKey).get(sourceName); + if (sortedUris == null) { + sortedUris = new ConcurrentSkipListMap>(); + ffmpAvailableUris.get(siteKey).put(sourceName, sortedUris); + } + } + } + + if (!ffmpAvailableUriQueryDates.containsKey(siteKey)) { + ConcurrentHashMap tempUriQueryDates = new ConcurrentHashMap( + 16, 0.75f, 4); + ffmpAvailableUriQueryDates.put(siteKey, tempUriQueryDates); + } + + Date previousQueryTime = ffmpAvailableUriQueryDates.get(siteKey).get( + sourceName); + SourceXML source = getSourceConfig().getSource(sourceName); + + if (retrieveNew + || ((time != null) && ((previousQueryTime == null) || (time + .getTime() < previousQueryTime.getTime())))) { + SimpleDateFormat datef = new SimpleDateFormat(datePattern); + datef.setTimeZone(TimeZone.getTimeZone("Zulu")); + Date earliestTime = time; + StringBuilder query = new StringBuilder(200); + query.append("select datauri from ffmp where wfo = '"); + query.append(getWfo()); + query.append("' and sourcename = '"); + query.append(sourceName); + + // GUIDANCE we save by displayName, *type* + if (source.getSourceType().equals( + SOURCE_TYPE.GUIDANCE.getSourceType())) { + + long timeOffset = source.getExpirationMinutes(siteKey) * 1000 * 60; + earliestTime = new Date(time.getTime() - timeOffset); + } + + query.append("' and sitekey = '"); + query.append(siteKey); + if (!source.isMosaic()) { + query.append("' and datakey = '"); + query.append(dataKey); + } + + query.append("' and reftime >= '"); + query.append(datef.format(earliestTime)); + + if (!retrieveNew && (previousQueryTime != null)) { + query.append("' and reftime < '"); + query.append(datef.format(previousQueryTime)); + } + + query.append("' order by reftime desc"); + + try { + List results = DirectDbQuery.executeQuery( + query.toString(), "metadata", QueryLanguage.SQL); + List list = new LinkedList(); + Date prevRefTime = null; + + for (int j = 0; j < results.size(); j++) { + if (results.size() > 0) { + Object[] results2 = results.get(j); + // System.out.println("Querrying for URIs: " + // + query.toString() + " # " + results2.length); + + for (int i = 0; i < results2.length; i++) { + String uri = (String) results2[0]; + FFMPRecord rec = new FFMPRecord(uri); + Date curRefTime = rec.getDataTime().getRefTime(); + if ((prevRefTime != null) + && !prevRefTime.equals(curRefTime)) { + sortedUris.put(prevRefTime, list); + list = new LinkedList(); + } + + prevRefTime = curRefTime; + list.add(uri); + } + } + } + + if (list != null) { + if ((prevRefTime == null) || (list == null)) { + statusHandler.handle(Priority.WARN, + "Source prevTime or list = null: " + sourceName + + " Date: " + time); + } else { + sortedUris.put(prevRefTime, list); + } + } + + ffmpAvailableUriQueryDates.get(siteKey).put(sourceName, time); + + } catch (VizException e) { + statusHandler.handle(Priority.PROBLEM, + "FFMP Can't find availble URI list for, " + sourceName, + e); + } + } + + if (time != null) { + if (source.getSourceType().equals( + SOURCE_TYPE.GUIDANCE.getSourceType())) { + return sortedUris; + } else { + return sortedUris.tailMap(time, true); + } + } + + return null; + } + + /** + * Request a record + * + * @param retrieveNew + * + * @param refTime + * @param field + * @param huc + * @return + * + */ + public FFMPCacheRecord getFFMPData(ProductXML product, String siteKey, + String dataKey, String sourceName, Date ptime, String phuc, + boolean retrieveNew) { + + FFMPCacheRecord record = ffmpData.get(siteKey).get(sourceName); + String guidSrc = FFMPConfig.getInstance().getFFMPConfigData() + .getGuidSrc(); + + if ((record != null) + && (record.getBasinData(phuc).getBasins().size() > 0)) { + + SourceXML sourceXML = getSourceConfig().getSource(sourceName); + + if (sourceXML == null) { + sourceXML = getSourceConfig() + .getSourceByDisplayName(sourceName); + } + + if (sourceXML.getSourceType().equals( + SOURCE_TYPE.GUIDANCE.getSourceType())) { + // FFG in table special case where display is the sourceName + if (product != null) { + + ProductRunXML productRun = getRunConfig().getProduct( + siteKey); + + for (SourceXML source : productRun.getGuidanceSources( + product, guidSrc)) { + if (ffmpLoadedUris.get(siteKey).containsKey( + source.getSourceName())) { + continue; + } else { + populateFFMPRecord(product, siteKey, dataKey, + source.getSourceName(), ptime, phuc, + retrieveNew); + } + } + } else { + // FFG is the primary if + if (!ffmpLoadedUris.get(siteKey).containsKey(sourceName)) { + populateFFMPRecord(product, siteKey, dataKey, + sourceName, ptime, phuc, retrieveNew); + } + } + + record = ffmpData.get(siteKey).get(sourceName); + + } else { + populateFFMPRecord(product, siteKey, dataKey, sourceName, + ptime, phuc, retrieveNew); + } + + } else { // must populate for a different huc for all possible times + if (product != null) { + + SourceXML sourceXML = getSourceConfig().getSourceByDisplayName( + sourceName); + + if (sourceXML != null) { + + if (sourceXML.getDisplayName().equals(sourceName)) { + // FFG table display special case updates + ProductRunXML productRun = getRunConfig().getProduct( + siteKey); + + if (sourceXML + .getSourceType() + .equals(FFMPSourceConfigurationManager.SOURCE_TYPE.GUIDANCE + .getSourceType())) { + for (SourceXML ffgSource : productRun + .getGuidanceSources(product, guidSrc)) { + + populateFFMPRecord(product, siteKey, dataKey, + ffgSource.getSourceName(), ptime, phuc, + retrieveNew); + } + } else { + populateFFMPRecord(product, siteKey, dataKey, + sourceName, ptime, phuc, retrieveNew); + } + } + } else { + populateFFMPRecord(product, siteKey, dataKey, sourceName, + ptime, phuc, retrieveNew); + } + } else { + // special case where FFG is the primary source + // check for special case with dual stand alone and table + // display loaded + SourceXML sourcexml = getSourceConfig().getSource(sourceName); + + if (sourcexml.getSourceType().equals( + SOURCE_TYPE.GUIDANCE.getSourceType())) { + sourceName = sourcexml.getDisplayName(); + } else { + populateFFMPRecord(product, siteKey, dataKey, sourceName, + ptime, phuc, retrieveNew); + } + } + + record = ffmpData.get(siteKey).get(sourceName); + } + + return record; + + } + + /** + * Sort by DataTime + * + * @author dhladky + * + */ + public class SortByDataTime implements Comparator { + + @Override + public int compare(DataTime o1, DataTime o2) { + + return o1.compareTo(o2); + } + } + + /** + * gets the wfo + * + * @return + */ + public String getWfo() { + return wfo; + } + + /** + * sets the wfo + * + * @param wfo + */ + public void setWfo(String wfo) { + this.wfo = wfo; + } + + /** + * gets the reverse of the later + * + * @param sourceName + * @return + */ + public FIELDS getField(String sourceName) { + + String sfield = getSourceConfig().getSourceType(sourceName) + .getSourceType().toLowerCase(); + FIELDS myField = null; + if (sfield.equals(FFMPRecord.FIELDS.QPE.getFieldName())) { + myField = FFMPRecord.FIELDS.QPE; + } else if (sfield.equals(FFMPRecord.FIELDS.RATE.getFieldName())) { + myField = FFMPRecord.FIELDS.RATE; + } else if (sfield.equals(FFMPRecord.FIELDS.QPF.getFieldName())) { + myField = FFMPRecord.FIELDS.QPF; + } else if (sfield.equals(FFMPRecord.FIELDS.GUIDANCE.getFieldName())) { + myField = FFMPRecord.FIELDS.GUIDANCE; + } else if (sfield.equals("gage")) { + myField = FFMPRecord.FIELDS.VIRTUAL; + } + return myField; + } + + /** + * Start secondary and tertiary data loads + * + * @param startTime + * @param loadType + * @throws VizException + */ + public void startLoad(FFMPResource resource, Date startTime, + LOADER_TYPE loadType) throws VizException { + Date timeBack = null; + FFMPTemplateConfigurationManager ftcm = FFMPTemplateConfigurationManager + .getInstance(); + ArrayList hucsToLoad = ftcm.getHucLevels(); + FFMPResourceData frd = resource.getResourceData(); + + if (loadType == LOADER_TYPE.SECONDARY) { + //hucsToLoad.remove("ALL"); + //hucsToLoad.remove(getConfig().getFFMPConfigData().getLayer()); + + timeBack = new Date( + (long) (resource.getMostRecentTime().getTime() - ((getConfig() + .getFFMPConfigData().getTimeFrame() * 3) * 3600 * 1000))); + + frd.timeBack = timeBack; + } else if (loadType == LOADER_TYPE.TERTIARY) { + hucsToLoad.clear(); + hucsToLoad.add("ALL"); + startTime = new Date(resource.getMostRecentTime().getTime() - (3600 * 1000 * 6)); + timeBack = new Date(resource.getMostRecentTime().getTime() - (3600 * 1000 * 24)); + } + + frd.floader = new FFMPDataLoader(frd, timeBack, startTime, loadType, + hucsToLoad); + frd.floader.addListener(resource); + frd.floader.start(); + + } + + public void launchSplash(String siteKey) { + + final String fsiteKey = siteKey; + + VizApp.runAsync(new Runnable() { + @Override + public void run() { + Shell fshell = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getShell(); + + if (ffmpSplash == null) { + ffmpSplash = new FFMPSplash(fshell); + // latch + int count = 0; + while (!getTemplates(fsiteKey).done) { + + try { + count++; + if (count == 50) { + ffmpSplash.disposeDialog(); + break; + } + Thread.sleep(1000); + } catch (InterruptedException e) { + e.printStackTrace(); + if (ffmpSplash != null) { + ffmpSplash.disposeDialog(); + } + } + } + } + } + }); + } + + /** + * Launch a basin trend from a screen click + * + * @param pfaf + */ + public void basinTrend(Long pfaf) { + + final String pfafs = pfaf.toString(); + + VizApp.runAsync(new Runnable() { + @Override + public void run() { + for (IMonitorListener listener : getMonitorListeners()) { + if (listener instanceof FfmpBasinTableDlg) { + ((FfmpBasinTableDlg) listener).displayBasinTrend(pfafs); + } + } + } + }); + } + + /** + * launch the dialog + */ + public void launchFFMPDialog(FFMPResource resource) { + + final FFMPResource fresource = resource; + + if (resource.basinTableDlg == null) { + VizApp.runAsync(new Runnable() { + + @Override + public void run() { + Shell fshell = PlatformUI.getWorkbench() + .getActiveWorkbenchWindow().getShell(); + + FFMPTableData tData = new FFMPTableData(); + fresource.basinTableDlg = new FfmpBasinTableDlg(fshell, + tData, fresource); + addMonitorListener(fresource.basinTableDlg); + fresource.basinTableDlg.addListener(fresource); + fresource.basinTableDlg.open(); + } + }); + } else { + resource.basinTableDlg.getShell().setActive(); + } + } + + /** + * update the data in the dialog + */ + public void updateDialog(FFMPResource resource) { + + if (resource.basinTableDlg != null) { + + resource.isFirst = false; + fireMonitorEvent(resource.basinTableDlg.getClass().getName()); + } + } + + public synchronized void splashDisposeAndDataLoad(FFMPResource resource) { + if (ffmpSplash != null) { + ffmpSplash.disposeDialog(); + ffmpSplash = null; + + if (resource.isFirst) { + updateDialog(resource); + } + + // start secondary data load + try { + startLoad(resource, resource.getResourceData().timeBack, + LOADER_TYPE.SECONDARY); + } catch (VizException e) { + statusHandler.handle(Priority.PROBLEM, + "Secondary Data Load failure", e); + } + } + } + + public void forceKillFFMPSplash() { + if (ffmpSplash != null) { + ffmpSplash.disposeDialog(); + ffmpSplash = null; + } + } + + /** + * Add the FFMPResource + * + * @param listener + */ + public void addResourceListener(IFFMPResourceListener listener) { + resourceListeners.add(listener); + } + + /** + * Remove the FFMPResource + * + * @param listener + */ + public void removeResourceListener(IFFMPResourceListener listener) { + + ConcurrentHashMap siteCount = new ConcurrentHashMap(); + + for (IFFMPResourceListener clistener : resourceListeners) { + if (listener instanceof FFMPResource) { + FFMPResource res = (FFMPResource) clistener; + if (siteCount.containsKey(res.getSiteKey())) { + int val = siteCount.get(res.getSiteKey()); + siteCount.replace(res.getSiteKey(), val + 1); + } else { + siteCount.put(res.getSiteKey(), 1); + } + } + } + + if (listener instanceof FFMPResource) { + FFMPResource res = (FFMPResource) listener; + if (res.getResourceData().floader != null) { + res.getResourceData().floader.kill(); + } + res.getResourceData().floader = null; + int val = siteCount.get(res.getSiteKey()); + + // clear out the cache + for (Entry entry: ffmpData.get(res.getSiteKey()).entrySet()){ + entry.getValue().closeCache(); + } + + if ((val == 1) && (siteCount.size() > 1)) { + + ffmpData.remove(res.getSiteKey()); + ffmpAvailableUriQueryDates.remove(res.getSiteKey()); + ffmpAvailableUris.remove(res.getSiteKey()); + ffmpLoadedUris.remove(res.getSiteKey()); + } + } + + resourceListeners.remove(listener); + } + + @Override + public void updateDialogTime(DataTime tableTime) { + + for (IFFMPResourceListener listener : getResourceListenerList()) { + if (listener instanceof FFMPResource) { + FFMPResource res = (FFMPResource) listener; + if (res.isLinkToFrame()) { + res.setTableTime(tableTime.getRefTime()); + if (res.basinTableDlg != null) { + updateDialog(res); + } + } + } + + } + + } + + public ArrayList getResourceListenerList() { + return resourceListeners; + } + + /** + * close dialog and cleanup + */ + public void closeDialog(FFMPResource res) { + if (res.basinTableDlg != null) { + res.basinTableDlg.removeListener(res); + res.basinTableDlg.disposeDialog(); + res.basinTableDlg = null; + } + } + + /** + * Thread the updates to the drawing + * + * @param listener + */ + private void fireRefresh(IFFMPResourceListener listener) { + + final IFFMPResourceListener flistener = listener; + + Display.getDefault().asyncExec(new Runnable() { + @Override + public void run() { + flistener.refresh(); + } + }); + } + + /** + * Sees if this source is a primary source for a product + * + * @param sourceName + * @return + */ + public ProductXML getProductXML(String sourceName) { + return getSourceConfig().getProduct(sourceName); + } + + /** + * Get the pertinent QPE source Record. + * + * @param date + * @param phuc + * @param retrieveNew + * @return + */ + public FFMPCacheRecord getQPERecord(ProductXML product, String siteKey, + String dataKey, String sourceName, Date date, String phuc, + boolean retrieveNew) { + + // comparisons done with table display + if (product != null) { + sourceName = product.getQpe(); + } + + return getFFMPData(product, siteKey, dataKey, sourceName, date, phuc, + retrieveNew); + } + + /** + * Get the pertinent QPE source basin. + * + * @param date + * @param phuc + * @param pfaf + * @return + */ + public FFMPBasin getGraphQPEBasin(ProductXML product, String siteKey, + String dataKey, String sourceName, Date date, String phuc, Long pfaf) + throws VizException { + // comparisons done with table display + if ((product != null) && (sourceName == null)) { + sourceName = product.getQpe(); + } + + return getFFMPBasinData(product, siteKey, dataKey, sourceName, date, + phuc, pfaf); + } + + /** + * Get the rate record. + * + * @param date + * @param phuc + * @param retrieveNew + * @return + */ + public FFMPCacheRecord getRateRecord(ProductXML product, String siteKey, + String dataKey, String sourceName, Date date, String phuc, + boolean retrieveNew) { + + // comparisons done with table display + if (product != null) { + sourceName = product.getRate(); + } + + return getFFMPData(product, siteKey, dataKey, sourceName, date, phuc, + retrieveNew); + } + + /** + * Get the rate basin. + * + * @param ptime + * @param phuc + * @param pfaf + * @return + */ + public FFMPBasin getGraphRateBasin(ProductXML product, String siteKey, + String dataKey, String sourceName, Date ptime, String phuc, + Long pfaf) throws VizException { + + // comparisons done with table display + if ((product != null) && (sourceName == null)) { + sourceName = product.getRate(); + } + + return getFFMPBasinData(product, siteKey, dataKey, sourceName, ptime, + phuc, pfaf); + } + + /** + * Gets the QPF record + * + * @param date + * @param phuc + * @param retrieveNew + * @return + */ + public FFMPCacheRecord getQPFRecord(ProductXML product, String siteKey, + String dataKey, String sourceName, Date date, String phuc, + boolean retrieveNew) { + + FfmpTableConfigData ffmpTableCfgData = FfmpTableConfig.getInstance() + .getTableConfigData(siteKey); + String qpfType = ffmpTableCfgData.getQpfType(); + ProductRunXML productRun = FFMPRunConfigurationManager.getInstance() + .getProduct(siteKey); + + // comparisons done with table display + if (product != null) { + sourceName = productRun.getQpfSources(product, qpfType).get(0) + .getSourceName(); + } + + return getFFMPData(product, siteKey, dataKey, sourceName, date, phuc, + retrieveNew); + } + + /** + * Get the QPF Basin. + * + * @param date + * @param phuc + * @param pfaf + * @return + */ + public FFMPBasin getGraphQPFBasin(ProductXML product, String siteKey, + String dataKey, String sourceName, Date date, String phuc, Long pfaf) + throws VizException { + + // comparisons done with table display + if (product != null) { + ProductRunXML productRun = FFMPRunConfigurationManager + .getInstance().getProduct(siteKey); + FfmpTableConfigData ffmpTableCfgData = FfmpTableConfig + .getInstance().getTableConfigData(siteKey); + String qpfType = ffmpTableCfgData.getQpfGraphType(); + sourceName = productRun.getQpfSources(product, qpfType).get(0) + .getSourceName(); + } + + return getFFMPBasinData(product, siteKey, dataKey, sourceName, date, + phuc, pfaf); + } + + /** + * Gets the guidance source types + * + * @param date + * @param phuc + * @return + */ + public FFMPCacheRecord getGuidanceRecord(ProductXML product, + String siteKey, String sourceName, Date date, String phuc, + boolean isStandAlone) { + String guidSrc = FFMPConfig.getInstance().getFFMPConfigData() + .getGuidSrc(); + if (!isStandAlone && guidSrc.startsWith("xxx")) { + return null; + } + if (product != null) { + ProductRunXML productRun = FFMPRunConfigurationManager + .getInstance().getProduct(siteKey); + SourceXML source = productRun.getGuidanceSources(product, guidSrc) + .get(0); + sourceName = source.getDisplayName(); + } + + return getFFMPData(product, siteKey, null, sourceName, date, phuc, + false); + } + + /** + * Gets the Guidance records NOTE: This is only used in the + * FFMPDataGenerator + * + * @param product + * @param siteKey + * @param date + * @param phuc + * @param retrieveNew + * @return + */ + public HashMap getGuidanceRecords( + ProductXML product, String siteKey, Date date, String phuc, + boolean retrieveNew) { + + HashMap guidRecs = new HashMap(); + ProductRunXML productRun = FFMPRunConfigurationManager.getInstance() + .getProduct(siteKey); + ArrayList guidTypes = productRun.getGuidanceTypes(product); + + for (String type : guidTypes) { + + FFMPCacheRecord guidRec = getFFMPData(product, siteKey, null, type, + date, phuc, retrieveNew); + guidRecs.put(type, guidRec); + } + + return guidRecs; + } + + /** + * Gets the guidance source types. + * + * @param date + * @param phuc + * @param pfaf + * @return + */ + public FFMPBasin getGraphGuidanceBasin(ProductXML product, String siteKey, + String dataKey, String sourceName, Date date, String phuc, Long pfaf) + throws VizException { + + if (product != null) { + String guidSrc = FFMPConfig.getInstance().getFFMPConfigData() + .getGuidSrc(); + SourceXML source = product.getGuidanceSourcesByType(guidSrc).get(0); + sourceName = source.getDisplayName(); + } + + return getFFMPBasinData(product, siteKey, dataKey, sourceName, date, + phuc, pfaf); + } + + /** + * Gets the virtual gage basin record + * + * @param date + * @param phuc + * @param retrieveNew + * @return + */ + public FFMPCacheRecord getVirtualRecord(ProductXML product, String siteKey, + String dataKey, String sourceName, Date date, String phuc, + boolean retrieveNew) { + // comparisons done with table display + // field doesn't matter here + + if (product != null) { + sourceName = product.getVirtual(); + } + + return getFFMPData(product, siteKey, dataKey, sourceName, date, phuc, + retrieveNew); + } + + /** + * Grabs data for a particular basin. Used by the graph's. + * + * @param sourceName + * @param date + * @param phuc + * @param pfaf + * @return + */ + public FFMPBasin getFFMPBasinData(ProductXML product, String siteKey, + String dataKey, String sourceName, Date ptime, String phuc, + Long pfaf) throws VizException { + FFMPBasin basin = null; + // check for already loaded records + FFMPCacheRecord record = ffmpData.get(siteKey).get(sourceName); + if (record != null) { + FFMPBasinData basinData = record.getBasinData(phuc); + if (basinData != null) { + basin = basinData.get(pfaf); + } + } + + SourceXML psource = getSourceConfig().getSource(sourceName); + if (psource == null) { + psource = getSourceConfig().getSourceByDisplayName(sourceName); + } + // basin should have loaded something + if (psource.getDisplayName().equals(sourceName) + && psource.getSourceType().equals( + SOURCE_TYPE.GUIDANCE.getSourceType())) { + FFMPGuidanceBasin fgb = null; + if (basin != null) { + fgb = (FFMPGuidanceBasin) basin; + } else { + fgb = new FFMPGuidanceBasin(pfaf, !phuc.equals("ALL")); + basin = fgb; + } + + if (product != null) { + ProductRunXML productRun = getRunConfig().getProduct(siteKey); + FfmpTableConfigData ffmpTableCfgData = FfmpTableConfig + .getInstance().getTableConfigData(siteKey); + + for (SourceXML source : productRun.getGuidanceSources(product, + ffmpTableCfgData.getFfgGraphType())) { + if (fgb.containsKey(source.getSourceName())) { + continue; + } else { + // populate if it isn't there + SortedMap> availableUris = getAvailableUris( + siteKey, dataKey, source.getSourceName(), ptime); + + if ((availableUris != null) + && (availableUris.size() > 0)) { + POINT_RETRIVAL: for (List uris : availableUris + .values()) { + for (String uri : uris) { + + if (!ffmpLoadedUris.containsKey(siteKey)) { + + ConcurrentHashMap>> tempLoadedUris = new ConcurrentHashMap>>(); + tempLoadedUris + .put(source.getSourceName(), + new ConcurrentHashMap>( + 16, 0.75f, 4)); + + ffmpLoadedUris.put(siteKey, + tempLoadedUris); + } + + if (!ffmpLoadedUris.get(siteKey) + .get(source).get(phuc) + .containsKey(uri)) { + // populate point only + populateFFMPBasin(uri, siteKey, + source.getSourceName(), phuc, + fgb); + } else { + break POINT_RETRIVAL; + } + } + } + } + } + } + } else { + // FFG is the primary source + if (!fgb.containsKey(sourceName)) { + // populate if it isn't there + SortedMap> availableUris = getAvailableUris( + siteKey, dataKey, sourceName, ptime); + + if ((availableUris != null) && (availableUris.size() > 0)) { + POINT_RETRIVAL: for (List uris : availableUris + .values()) { + for (String uri : uris) { + + if (!ffmpLoadedUris.containsKey(siteKey)) { + + ConcurrentHashMap>> tempLoadedUris = new ConcurrentHashMap>>(); + + tempLoadedUris + .put(sourceName, + new ConcurrentHashMap>( + 16, 0.75f, 4)); + + ffmpLoadedUris.put(siteKey, tempLoadedUris); + } + + if (!ffmpLoadedUris.get(siteKey) + .get(sourceName).get(phuc) + .containsKey(uri)) { + // populate point only + populateFFMPBasin(uri, siteKey, sourceName, + phuc, fgb); + } else { + break POINT_RETRIVAL; + } + } + } + } + } + } + } else { + // populate if it isn't there + SortedMap> availableUris = getAvailableUris( + siteKey, dataKey, sourceName, ptime); + + if ((availableUris != null) && (availableUris.size() > 0)) { + POINT_RETRIVAL: for (List uris : availableUris.values()) { + for (String uri : uris) { + + if (!ffmpLoadedUris.containsKey(siteKey)) { + + ConcurrentHashMap>> tempLoadedUris = new ConcurrentHashMap>>(); + + if (product != null) { + for (String source : product.getSources()) { + + tempLoadedUris + .put(source, + new ConcurrentHashMap>( + 16, 0.75f, 4)); + } + + ffmpLoadedUris.put(siteKey, tempLoadedUris); + + } else { + tempLoadedUris + .put(sourceName, + new ConcurrentHashMap>( + 16, 0.75f, 4)); + ffmpLoadedUris.put(siteKey, tempLoadedUris); + } + } + + if (!ffmpLoadedUris.get(siteKey) + .containsKey(sourceName)) { + ConcurrentHashMap>> tempLoadedUris = new ConcurrentHashMap>>(); + tempLoadedUris + .put(sourceName, + new ConcurrentHashMap>( + 16, 0.75f, 4)); + ffmpLoadedUris.put(siteKey, tempLoadedUris); + } + + if (!ffmpLoadedUris.get(siteKey).get(sourceName) + .containsKey(phuc)) { + ffmpLoadedUris + .get(siteKey) + .get(sourceName) + .put(phuc, + new ConcurrentHashMap()); + } + + if (!ffmpLoadedUris.get(siteKey).get(sourceName) + .get(phuc).containsKey(uri)) { + // populate point only + populateFFMPBasin(uri, siteKey, sourceName, phuc, + basin); + } else { + break POINT_RETRIVAL; + } + } + } + } + } + + return basin; + } + + /** + * Gets the valid time window for the source as a long + * + * @param sourceName + * @return + */ + public long getSourceTimeWindow(String sourceName, String siteKey) { + return getSourceConfig().getSource(sourceName).getExpirationMinutes( + siteKey) * 60 * 1000; + } + + /** + * gets the time window object + * + * @param sourceName + * @return + */ + public FFMPTimeWindow getTimeWindow(String sourceName, Date date, + String siteKey) { + FFMPTimeWindow window = new FFMPTimeWindow(); + long lwindow = getSourceTimeWindow(sourceName, siteKey); + window.setAfterTime(new Date(date.getTime() - lwindow)); + window.setBeforeTime(new Date(date.getTime() + lwindow)); + + return window; + } + + public FFMPTimeWindow getQpfWindow() { + return qpfWindow; + } + + public void setQpfWindow(FFMPTimeWindow qpfWindow) { + this.qpfWindow = qpfWindow; + } + + public FFMPTimeWindow getQpeWindow() { + return qpeWindow; + } + + public void setQpeWindow(FFMPTimeWindow qpeWindow) { + this.qpeWindow = qpeWindow; + } + + @Override + public ArrayList getTimeOrderedKeys(IMonitor monitor, String type) { + // TODO Auto-generated method stub + return null; + } + + /** + * fire off a cleaner + * + * @param product + * @param source + * @param siteKey + * @param date + */ + public void purgeFFMPData(ProductXML product, String source, + String siteKey, Date date) { + PurgeFFMPData pfd = new PurgeFFMPData(product, source, siteKey, date); + pfd.purge(); + } + + /** + * Purge old data from the cache + * + * @author dhladky + * + */ + private class PurgeFFMPData implements Runnable { + + final ProductXML fproduct; + + final String fsource; + + final String fsiteKey; + + final Date fdate; + + public PurgeFFMPData(ProductXML product, String source, String siteKey, + Date date) { + + this.fproduct = product; + this.fsource = source; + this.fsiteKey = siteKey; + this.fdate = date; + } + + @Override + public void run() { + try { + purge(); + } catch (Exception e) { + statusHandler.handle(Priority.PROBLEM, + "Unable to purge Data from FFMP cache, ", e); + } + } + + public void purge() { + + ArrayList purgeSources = new ArrayList(); + + if (fproduct != null) { + + ProductRunXML productRun = getRunConfig().getProduct(fsiteKey); + + // guidance + for (String type : productRun.getGuidanceTypes(fproduct)) { + for (SourceXML guidSource : productRun.getGuidanceSources( + fproduct, type)) { + if (guidSource != null) { + purgeSources.add(guidSource.getSourceName()); + } + } + } + + // qpf + for (String type : productRun.getQpfTypes(fproduct)) { + for (SourceXML qpfSource : productRun.getQpfSources( + fproduct, type)) { + if (qpfSource != null) { + purgeSources.add(qpfSource.getSourceName()); + } + } + } + // qpe, etc + for (String sourceName : fproduct.getSources()) { + if (!purgeSources.contains(sourceName)) { + purgeSources.add(sourceName); + } + } + + for (String sourceName : purgeSources) { + + SourceXML source = fscm.getSource(sourceName); + + if (source != null) { + if (source.getSourceType().equals( + SOURCE_TYPE.GUIDANCE.getSourceType())) { + sourceName = SOURCE_TYPE.GUIDANCE.getSourceType(); + } + + if (ffmpData != null) { + if (ffmpData.containsKey(fsiteKey)) { + FFMPCacheRecord record = ffmpData.get(fsiteKey) + .get(sourceName); + if (record != null) { + record.purgeData(fdate); + } + } + } + } + } + + } else { + if (ffmpData != null) { + if (ffmpData.containsKey(fsiteKey)) { + FFMPCacheRecord record = ffmpData.get(fsiteKey).get( + fsource); + if (record != null) { + record.purgeData(fdate); + } + } + } + } + + if (ffmpAvailableUris != null) { + for (Entry>> entry : ffmpAvailableUris + .get(fsiteKey).entrySet()) { + ConcurrentNavigableMap> oldUris = entry + .getValue().headMap(fdate); + for (List uris : oldUris.headMap(fdate).values()) { + for (String uri : uris) { + + if (fproduct != null) { + + for (String sourceName : purgeSources) { + + if (ffmpLoadedUris.get(fsiteKey) + .containsKey(sourceName)) { + for (ConcurrentHashMap loadedUris : ffmpLoadedUris + .get(fsiteKey).get(sourceName) + .values()) { + loadedUris.remove(uri); + } + } + } + } else { + for (ConcurrentHashMap loadedUris : ffmpLoadedUris + .get(fsiteKey).get(fsource).values()) { + loadedUris.remove(uri); + } + } + } + } + + oldUris.clear(); + } + } + } + } + + /** + * Process an individual URI + * + * @param isProductLoad + * @param uri + * @param siteKey + * @param sourceName + * @param barrierTime + * @param phuc + */ + public void processUri(boolean isProductLoad, String uri, String siteKey, + String sourceName, Date barrierTime, String phuc) { + + final boolean fisProductLoad = isProductLoad; + final String furi = uri; + final String fsiteKey = siteKey; + final String fsourceName = sourceName; + final String fhuc = phuc; + + VizApp.runAsync(new Runnable() { + @Override + public void run() { + + SourceXML source = getSourceConfig().getSource(fsourceName); + + if (furi != null) { + FFMPRecord record = new FFMPRecord(furi); + + try { + record = populateFFMPRecord(fisProductLoad, furi, + fsiteKey, fsourceName, fhuc); + if ((record != null) && (source != null)) { + record.setExpiration(source + .getExpirationMinutes(fsiteKey)); + record.setRate(source.isRate()); + } + } catch (Exception e) { + statusHandler.handle(Priority.PROBLEM, + "FFMP Can't retrieve FFMP URI, " + furi, e); + } + } + } + }); + } + + /** + * Adds this source to the URI hash in the monitor + * + * @param uris + * @param sourceName + */ + public void processUris(NavigableMap> uriMap, + boolean isProductLoad, String siteKey, String sourceName, + Date barrierTime, String phuc, LOADER_TYPE type) { + + // don't wrap it, locks UI thread + if ((type == LOADER_TYPE.GENERAL) || (type == LOADER_TYPE.TERTIARY)) { + + FFMPProcessUris processor = new FFMPProcessUris(uriMap, + isProductLoad, siteKey, sourceName, barrierTime, phuc); + processor.run(); + + } else { + + final boolean fisProductLoad = isProductLoad; + final NavigableMap> furiMap = uriMap; + final String fsiteKey = siteKey; + final String fsourceName = sourceName; + final Date fbarrierTime = barrierTime; + final String fhuc = phuc; + + VizApp.runAsync(new Runnable() { + @Override + public void run() { + + SourceXML source = getSourceConfig().getSource(fsourceName); + + if (furiMap != null) { + for (List uris : furiMap.descendingMap() + .values()) { + for (String uri : uris) { + if (uri != null) { + FFMPRecord record = new FFMPRecord(uri); + if (record.getDataTime().getRefTime() + .after(fbarrierTime) + || source + .getSourceType() + .equals(FFMPSourceConfigurationManager.SOURCE_TYPE.GUIDANCE + .getSourceType())) { + try { + + if (!getUriMap(fsiteKey, + fsourceName, fhuc) + .containsKey(uri)) { + + record = populateFFMPRecord( + fisProductLoad, uri, + fsiteKey, fsourceName, + fhuc); + + if ((record != null) + && (source != null)) { + record.setExpiration(source + .getExpirationMinutes(fsiteKey)); + record.setRate(source + .isRate()); + } + } + + } catch (Exception e) { + statusHandler.handle( + Priority.PROBLEM, + "FFMP Can't retrieve FFMP URI, " + + uri, e); + } + } + } + } + } + } + } + }); + } + } + + @Override + protected void nullifyMonitor(String icao) { + // TODO Auto-generated method stub + + } + + /** + * Gets the HUC templates + * + * @return + */ + public FFMPTemplates getTemplates(String siteKey) { + if (templates == null) { + FFMPRunXML runner = getRunConfig().getRunner(wfo); + this.templates = FFMPTemplates.getInstance( + runner.getPrimaryDomain(), siteKey, MODE.CAVE); + // backup domains + if (runner.getBackupDomains() != null) { + for (DomainXML backup : runner.getBackupDomains()) { + templates.addDomain(siteKey, backup); + } + } else { + templates.done = true; + } + } + + if (!templates.isSiteLoaded(siteKey)) { + FFMPRunXML runner = getRunConfig().getRunner(wfo); + + for (DomainXML domain : runner.getDomains()) { + templates.addDomain(siteKey, domain); + } + } + + return templates; + } + + /** + * Get the Run configuration + * + * @return + */ + public FFMPRunConfigurationManager getRunConfig() { + if (frcm == null) { + frcm = FFMPRunConfigurationManager.getInstance(); + } + return frcm; + } + + /** + * Get the PP and PC values from curpp and curpc tables + * + * @param pfaf + * @param lid + * @param refTime + */ + public FFMPVirtualGageBasin getVirtualGageBasinData(long pfaf, String lid, + Date refTime) { + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + TimeZone gmt = TimeZone.getTimeZone("GMT"); + final String ihfs = "ihfs"; + FFMPVirtualGageBasin basin = new FFMPVirtualGageBasin(lid, pfaf, false); + + sdf.setTimeZone(gmt); + + Calendar cal = Calendar.getInstance(gmt); + cal.setTime(refTime); + cal.add(Calendar.HOUR_OF_DAY, -24); + Date startTime = cal.getTime(); + + String starttime = sdf.format(startTime); + String endtime = sdf.format(refTime); + + /* + * First we will check "PC" precip data from the database; The big issue + * of the PC data is that the gage amount sometimes is re-set to "zero" + * which will be ignored. If the "PC" data is not available, then we + * will check for its "PP" data which is less frequently updated most of + * the times and has an issue of "duration" (1 min, 15 min, 30 min, 1 + * hour, 2 hours, 3 hours and 6 hours) we have to deal with. + */ + String pe = "PC"; + String tablename = "curpc"; + + String format = "SELECT lid, pe, dur, ts, obstime, value, product_id " + + "FROM %s WHERE lid = '%s' AND obstime >= '%s' AND obstime < '%s' " + + "AND pe = '%s' ORDER BY obstime DESC, ts ASC"; + + String sql = String.format(format, tablename, lid, starttime, endtime, + pe); + + List precipData = null; + try { + precipData = DirectDbQuery.executeQuery(sql, ihfs, + QueryLanguage.SQL); + } catch (VizException e) { + // problem querying PC data + e.printStackTrace(); + } + + // if PC data NOT available + if ((precipData == null) || (precipData.size() == 0)) { + + pe = "PP"; + tablename = "curpp"; + String desiredDur = "1001"; + format = "SELECT lid, pe, dur, ts, obstime, value, product_id " + + "FROM %s WHERE lid = '%s' AND obstime >= '%s' AND obstime < '%s' " + + "AND pe = '%s' AND dur <= %s AND value >=0 ORDER BY dur ASC, " + + "obstime DESC, ts ASC"; + + sql = String.format(format, tablename, lid, starttime, endtime, pe, + desiredDur); + + try { + precipData = DirectDbQuery.executeQuery(sql, ihfs, + QueryLanguage.SQL); + } catch (VizException e) { + // problem querying PP data + e.printStackTrace(); + } + + if ((precipData == null) || (precipData.size() == 0)) { + return null; + } + } + + /* + * need to check whether the data list contains records from different + * type source which should not be plotted in one graph. Use the + * "ingestfilter" table to pick up the type source with the highest type + * ranking order. + */ + String typeSrc = null; + List uniqueSrcType = new ArrayList(); + List trendData = new ArrayList(); + + // no type source need to be checked if only one record is found. + if (precipData.size() > 1) { + for (Object[] oa : precipData) { + String ts = (String) oa[3]; + if (uniqueSrcType.contains(ts) == false) { + uniqueSrcType.add(ts); + } + } + + if (uniqueSrcType.size() > 1) { + /* + * more than one ts found. Get the type source rankings by + * accessing the "ingestfilter" table in the database. The + * smaller the type source rank value is, the higher priority + * the type source should be taken into account. + */ + format = "SELECT dur, ts, ts_rank FROM ingestFilter WHERE " + + "lid = '%s' AND pe = '%s' ORDER BY ts_rank ASC"; + + sql = String.format(format, lid, pe); + List rs = null; + + try { + rs = DirectDbQuery.executeQuery(sql, ihfs, + QueryLanguage.SQL); + } catch (VizException e) { + // problem querying IngestFilter table + e.printStackTrace(); + } + + if ((rs != null) && (rs.size() > 0)) { + typeSrc = (String) rs.get(0)[1]; + } + + // Get the records of the desired type source. + for (Object[] oa : precipData) { + if (((String) oa[3]).equals(typeSrc)) { + trendData.add(oa); + } + } + } else { + for (Object[] oa : precipData) { + trendData.add(oa); + } + } + } + + // processing gage data + float gageAccu = 0; + + if (pe.equalsIgnoreCase("PP")) { + // to select the data with the shortest duration from + // durations of 1 min, 15 min, 30 min, 1 hr and 2 hrs. + TreeSet durOrderSet = new TreeSet(); + + for (Object[] oa : trendData) { + int dur = Integer.parseInt((String) oa[2]); + durOrderSet.add(dur); + } + + // need to get the max duration for each hour + List> idxSameHour = getMaxDurationPerHour(trendData); + + Iterator iter = durOrderSet.iterator(); + int maxDur = 0; + boolean first = true; + List data1Dur = null; + + while (iter.hasNext()) { + if (first) { + maxDur = iter.next(); + first = false; + } + + // Notes (02/07/2006): For the AWOS and ASOS sites, the metar + // data are converted by SHEFDECODER and then saved into the PP + // precip database. But the metar data taken at 0005Z + // (20 min duration), 0025Z (40 min duration) and + // 0045Z (60 min duration) might be stored as records with + // 1-hour duration (as dur=1001). To avoid to count the + // 1-hour precip for multipe times for one same period, + // only ONE of the multiple records will be taken for VGB + // gage plot. Using the maximum duration -- 1-hr dur will + // be the most representative one. Need to make sure only + // one data point should be used within each hour if those + // multiple data points have the same duration for this hour. + data1Dur = selectMaxDurData(trendData, maxDur, idxSameHour); + + if (data1Dur.size() > 0) { + break; + } + } + + long secondsL = 0; // duration left bound + long secondsR = 0; // duration right bound + Date t1 = refTime; + // Date t0 = refTime - purgeTime; + long dur = 0; + + if (data1Dur != null) { + // should differentiate the "duration" of the gage data. + for (int i = 0; i < data1Dur.size(); i++) { + secondsL = (t1.getTime() - ((Date) data1Dur.get(i)[4]) + .getTime()) / 1000; + if (((Integer) data1Dur.get(i)[2]) > 1000) { + dur = ((Integer) data1Dur.get(i)[2] - 1000) + * SECONDS_PER_HOUR; + } else { + dur = ((Integer) data1Dur.get(i)[2]) * 1000; + } + + secondsR = secondsL + dur; // time drawn in reverse way + // we can not include the future gage data into the plot + // compared + // to the latest inv time of FFMP accum + // Note: for PP data, each precip value relates to two time + // instants + // based on "duration". A horizontal line (composed of two + // points) will be drawn to represent the precip during + // each "duration" period. + if ((secondsL < 0) || (secondsR > t1.getTime() / 1000)) { // gage + // data + // ahead + // of + // or + // beyond + // radar + // time + // range + continue; + } else { + gageAccu += (Float) data1Dur.get(i)[5]; + basin.setValue(refTime, gageAccu); + } + } + } + } else { // PC Data + long seconds = 0; // initialized + Date t1 = refTime; + if ((trendData != null) && (trendData.size() > 0)) { + double firstValue = (Double) trendData.get(0)[5]; + for (int i = 0; i < trendData.size(); i++) { + Date dataDate = (Date) trendData.get(i)[4]; + Double value = (Double) trendData.get(i)[5]; + double prevValue = -99; + if (i > 1) { + prevValue = (Double) trendData.get(i - 1)[5]; + } + + seconds = (t1.getTime() - ((Date) trendData.get(i)[4]) + .getTime()) / 1000; + + if ((seconds < 0) || (seconds > t1.getTime() / 1000)) { // gage + // range + continue; + } else if (i == 0) { + // accum is set to zero at the first gage data point. + basin.setValue(dataDate, gageAccu); + } else { + if (value < 0) { // if cur point unavailable + continue; + } else if (prevValue < 0) { // previous point N/A + if (firstValue > 0) { + gageAccu = (float) (firstValue - value); + } else { + continue; + } + } else { + double dAccu = prevValue - value; + if (dAccu < 0) { // gage reading error + continue; + } else { + gageAccu += dAccu; + // Note: PC data are the rain amount that fallen + // since some time when the "counter" was set to + // 0. + // So we can not count the accum if gage_accu is + // a negative value which means the accumulation + // will be re-started from zero. + } + + basin.setValue(dataDate, gageAccu); + } + } + } + } + } + + return basin; + } + + private List selectMaxDurData(List org, int dur, + List> idxSameHour) { + List filtered = new ArrayList(); + + // go through the indices for each hour period + for (int i = 0; i < idxSameHour.size(); i++) { + // select the max obsTime at desired duration as the data point + // to be used as the representative within each hour. Since the + // obstime was sorted in the descending order, the first one will be + // the max Obstime for the specified hour. + for (int j = 0; j < idxSameHour.size(); j++) { + if ((Integer) org.get(idxSameHour.get(i).get(j))[4] == dur) { + // the obsTime has already been in DESCENDING order, so the + // largest one for the hour is what we are looking for. + filtered.add(org.get(idxSameHour.get(i).get(j))); + } + } + } + + return filtered; + } + + private List> getMaxDurationPerHour(List data) { + List> idx = new ArrayList>(); + ArrayList dummyIdx = new ArrayList(); + + for (int i = 0; i < data.size(); i++) { + Object[] oa = data.get(i); + if (i < data.size() - 1) { + dummyIdx.add(i); + if (!withinSameHour((Date) oa[4], (Date) data.get(i + 1)[4])) { + idx.add(dummyIdx); + dummyIdx.clear(); + } + } else { // for the LAST time element + if (withinSameHour((Date) data.get(i - 1)[4], (Date) oa[4])) { + // Note: the previously grouped times have not been inserted + // into the list, so add it with the last time element. + dummyIdx.add(i); + idx.add(dummyIdx); + dummyIdx.clear(); + } else { + // Note: the last time element does NOT belong to the + // previous group, + dummyIdx.add(i); + idx.add(dummyIdx); + dummyIdx.clear(); + } + } + } + + return idx; + } + + /** + * To check whether the passed-in hours belong to the same hour period. + * + * @param a + * Date + * @param b + * Date + * @return true if times belong to the same hour + */ + private boolean withinSameHour(Date a, Date b) { + TimeZone gmt = TimeZone.getTimeZone("GMT"); + Calendar calA = Calendar.getInstance(gmt); + calA.setTime(a); + Calendar calB = Calendar.getInstance(gmt); + calB.setTime(b); + if (calB.get(Calendar.MINUTE) == 0) { + return false; + } else if ((calA.get(Calendar.YEAR) == calB.get(Calendar.YEAR)) + && (calA.get(Calendar.MONTH) == calB.get(Calendar.MONTH)) + && (calA.get(Calendar.DAY_OF_MONTH) == calB + .get(Calendar.DAY_OF_MONTH))) { + if (calA.get(Calendar.HOUR_OF_DAY) == calB + .get(Calendar.HOUR_OF_DAY)) { + return true; + } else if ((calA.get(Calendar.MINUTE) == 0) + && (Math.abs(calA.getTimeInMillis() + - calB.getTimeInMillis()) < (60 * 60))) { + return true; + } + } + + return false; + } + + /** + * Update FFFG + */ + public void updateFFFG() { + + fffg = FFFGDataMgr.getUpdatedInstance(); + + for (IFFMPResourceListener listener : getResourceListenerList()) { + if (listener instanceof FFMPResource) { + + FFMPResource resource = (FFMPResource) listener; + resource.dirty(); + resource.refresh(); + resource.clearTables(); + + if (resource.getResourceData().tableLoad) { + updateDialog(resource); + } + } + } + } + + /** + * Gets the previous URI available + * + * @param siteKey + * @param sourceName + * @return + */ + public Date getPreviousQueryTime(String siteKey, String sourceName) { + return ffmpAvailableUriQueryDates.get(siteKey).get(sourceName); + } + + /** + * class used to thread data loads + * + * @author dhladky + * + */ + private class FFMPLoadRecord implements Runnable { + + final FFMPRecord fffmpRec; + + final String fsource; + + final String fhuc; + + final String fsiteKey; + + final boolean fisProductLoad; + + public FFMPLoadRecord(boolean isProductLoad, String siteKey, + FFMPRecord ffmpRec, String source, String huc) throws Exception { + this.fffmpRec = ffmpRec; + this.fsource = source; + this.fsiteKey = siteKey; + this.fisProductLoad = isProductLoad; + this.fhuc = huc; + } + + public void run() { + try { + load(); + } catch (Exception e) { + statusHandler.handle(Priority.PROBLEM, "FFMP load FFMPData, " + + fsource + " " + fhuc, e); + } + } + + public void load() { + if (fffmpRec != null) { + + ConcurrentMap uris = getUriMap(fsiteKey, + fsource, fhuc); + String dataUri = fffmpRec.getDataURI(); + if (!uris.containsKey(dataUri)) { + File loc = HDF5Util.findHDF5Location(fffmpRec); + IDataStore dataStore = DataStoreFactory.getDataStore(loc); + + if (!ffmpData.containsKey(fsiteKey)) { + ConcurrentHashMap fieldRecs = new ConcurrentHashMap(); + ffmpData.put(fsiteKey, fieldRecs); + } + + String mySource = fsource; + SourceXML source = fscm.getSource(fsource); + + if (source.getSourceType().equals( + SOURCE_TYPE.GUIDANCE.getSourceType()) + && fisProductLoad) { + mySource = source.getDisplayName(); + } + + FFMPCacheRecord curRecord = ffmpData.get(fsiteKey).get( + mySource); + if (curRecord == null) { + // ensure the record can only be set once + synchronized (ffmpData) { + curRecord = ffmpData.get(fsiteKey).get(mySource); + if (curRecord == null) { + curRecord = new FFMPCacheRecord(fffmpRec, + mySource); + ffmpData.get(fsiteKey).put(mySource, curRecord); + } + } + } + + SourceXML sourceXML = fscm.getSource(mySource); + + if ((sourceXML != null) + && sourceXML.getSourceType().equals( + SOURCE_TYPE.GAGE.getSourceType()) + && fhuc.equals("ALL")) { + try { + curRecord.retrieveVirtualMapFromDataStore( + dataStore, dataUri, getTemplates(fsiteKey), + fffmpRec.getDataTime().getRefTime(), + fffmpRec.getSourceName()); + } catch (FileNotFoundException e) { + statusHandler.handle(Priority.PROBLEM, + "FFMP Can't find FFMP URI, " + dataUri, e); + } catch (StorageException e) { + statusHandler.handle(Priority.PROBLEM, + "FFMP Can't retrieve (Storage problem) FFMP URI, " + + dataUri, e); + } + } else { + try { + statusHandler.handle(Priority.INFO, + "Retrieving and Populating URI: , " + + dataUri); + curRecord.retrieveMapFromDataStore(dataStore, + dataUri, getTemplates(fffmpRec.getSiteKey()), fhuc, + fffmpRec.getDataTime().getRefTime(), + fffmpRec.getSourceName()); + } catch (Exception e) { + statusHandler.handle(Priority.PROBLEM, + "FFMP Can't retrieve FFMP URI, " + dataUri, + e); + e.printStackTrace(); + } + } + + ConcurrentHashMap>> siteLoadedUris = ffmpLoadedUris + .get(fsiteKey); + + if (siteLoadedUris == null) { + + siteLoadedUris = new ConcurrentHashMap>>(); + ffmpLoadedUris.put(fsiteKey, siteLoadedUris); + } + + ConcurrentHashMap> sourceLoadedUris = ffmpLoadedUris + .get(fsiteKey).get(fsource); + + if (sourceLoadedUris == null) { + + sourceLoadedUris = new ConcurrentHashMap>(); + ffmpLoadedUris.get(fsiteKey).put(fsource, + sourceLoadedUris); + } + + ConcurrentHashMap hucLoadedUris = ffmpLoadedUris + .get(fsiteKey).get(fsource).get(fhuc); + + if (hucLoadedUris == null) { + + hucLoadedUris = new ConcurrentHashMap(); + ffmpLoadedUris.get(fsiteKey).get(fsource) + .put(fhuc, hucLoadedUris); + } + + synchronized (hucLoadedUris) { + // ensure not created by another thread + ffmpLoadedUris.get(fsiteKey).get(fsource).get(fhuc) + .put(dataUri, dataUri); + } + } + } + } + } + + /** + * Thread the uri processing + * + * @author dhladky + * + */ + private class FFMPProcessUris implements Runnable { + + final NavigableMap> furiMap; + + final boolean fisProductLoad; + + final String fsiteKey; + + final String fsourceName; + + final Date fbarrierTime; + + final String fhuc; + + public FFMPProcessUris(NavigableMap> uriMap, + boolean isProductLoad, String siteKey, String sourceName, + Date barrierTime, String phuc) { + + this.furiMap = uriMap; + this.fsiteKey = siteKey; + this.fbarrierTime = barrierTime; + this.fisProductLoad = isProductLoad; + this.fsourceName = sourceName; + this.fhuc = phuc; + + } + + public void run() { + SourceXML source = getSourceConfig().getSource(fsourceName); + + if (furiMap != null) { + for (List uris : furiMap.descendingMap().values()) { + for (String uri : uris) { + if (uri != null) { + FFMPRecord record = new FFMPRecord(uri); + if (record.getDataTime().getRefTime() + .after(fbarrierTime) + || source + .getSourceType() + .equals(FFMPSourceConfigurationManager.SOURCE_TYPE.GUIDANCE + .getSourceType())) { + try { + + if (!getUriMap(fsiteKey, fsourceName, fhuc) + .containsKey(uri)) { + + record = populateFFMPRecord( + fisProductLoad, uri, fsiteKey, + fsourceName, fhuc); + + if ((record != null) + && (source != null)) { + record.setExpiration(source + .getExpirationMinutes(fsiteKey)); + record.setRate(source.isRate()); + } + } + + } catch (Exception e) { + statusHandler.handle(Priority.PROBLEM, + "FFMP Can't retrieve FFMP URI, " + + uri, e); + } + } + } + } + } + } + } + } } diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/dialogs/FFMPTableCellData.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/dialogs/FFMPTableCellData.java index 3acef4b86f..1e7a61aaad 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/dialogs/FFMPTableCellData.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/dialogs/FFMPTableCellData.java @@ -176,9 +176,9 @@ public class FFMPTableCellData { if (displayAsInt == true) { tmpVal = Math.rint(value); } else { - if (!value.isNaN()) { - tmpVal = (double) (((int) ((value + 0.005) * 100))) / 100; - } + if (!value.isNaN()) { + tmpVal = (double) ((Math.round(value * 100.0))/100.0); + } } if ((columnName == FIELDS.GUIDANCE) && this.guidForcedFlag) { diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/dialogs/FfmpBasinTableDlg.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/dialogs/FfmpBasinTableDlg.java index bbfc85a03e..3eb7026847 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/dialogs/FfmpBasinTableDlg.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/dialogs/FfmpBasinTableDlg.java @@ -1186,7 +1186,7 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements shell.setCursor(getDisplay().getSystemCursor(SWT.CURSOR_WAIT)); updateTimeDurationLabel(val, split); if (dialogInitialized) { - fireTimeChangedEvent(val, split); + fireTimeChangedEvent(val, split, false); } updateD2DRefresh(); } @@ -1260,18 +1260,28 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements this.ffmpConfig.setVisibleColumns(attrData); this.ffmpConfig.setAttrData(attrData); this.ffmpTable.showHideTableColumns(); + boolean changeSplit = false; + + if (timeDurScale.split != ffmpConfig.isSplit()) { + changeSplit = true; + } timeDurScale.setSplit(ffmpConfig.isSplit()); - updateTimeDurationLabel(timeDurScale.getSelectedHoursValue(), ffmpConfig.isSplit()); - if (updateData) { - resource.clearTables(); - resource.getDrawable(resource.getPaintTime()).setDirty(true); - FFMPMonitor monitor = FFMPMonitor.getInstance(); - monitor.fireMonitorEvent(this.getClass().getName()); - } + if (updateData) { + + if (changeSplit) { + fireTimeChangedEvent(timeDurScale.getSelectedHoursValue(), + ffmpConfig.isSplit(), true); + } + resource.clearTables(); + resource.getDrawable(resource.getPaintTime()).setDirty(true); + FFMPMonitor.getInstance().fireMonitorEvent( + this.getClass().getName()); + + } ffmpTable.calculateTableSize(); shell.pack(); @@ -1314,7 +1324,7 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements ffmpListeners.remove(fl); } - public void fireTimeChangedEvent(double newTime, boolean split) { + public void fireTimeChangedEvent(double newTime, boolean split, boolean override) { FFMPRecord.FIELDS field = FFMPRecord.FIELDS.QPE; @@ -1325,7 +1335,7 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements } } - if (time != newTime) { + if ((time != newTime) || override) { FFMPTimeChangeEvent ftce = new FFMPTimeChangeEvent(newTime, split); Iterator iter = ffmpListeners.iterator(); while (iter.hasNext()) { @@ -1756,7 +1766,7 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements */ timeDurScale.setTimeDurationAndUpdate(ffmpConfig.getFFMPConfigData() .getTimeFrame()); - fireTimeChangedEvent(ffmpConfig.getFFMPConfigData().getTimeFrame(), false); + fireTimeChangedEvent(ffmpConfig.getFFMPConfigData().getTimeFrame(), false, false); /* * Layer @@ -2006,6 +2016,8 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements dataLoadComp.setVisible(false); shell.pack(); } + + resource.manageLoaders(status); } @Override @@ -2053,7 +2065,7 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements public void tableDataUpdateComplete(FFMPTableDataUpdate updateData) { final FFMPTableDataUpdate fupdateData = updateData; - + if (!this.isDisposed()) { Display.getDefault().asyncExec(new Runnable() { @@ -2078,9 +2090,9 @@ public class FfmpBasinTableDlg extends CaveSWTDialog implements resetCursor(); } }); - } + } } - + /** * used to blank the group label when channging HUC * while in an aggregate. diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/dialogs/TimeDurScaleComp.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/dialogs/TimeDurScaleComp.java index a1ff6f4ed7..672086b461 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/dialogs/TimeDurScaleComp.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/dialogs/TimeDurScaleComp.java @@ -111,7 +111,7 @@ public class TimeDurScaleComp extends Composite { /** * Split flag. */ - private boolean split = false; + public boolean split = false; /** * Display numbers for the range. diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPColorUtils.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPColorUtils.java index 30ac429cc6..3d70cc4fc4 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPColorUtils.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPColorUtils.java @@ -49,7 +49,7 @@ import com.raytheon.viz.core.style.image.ImagePreferences; * Date Ticket# Engineer Description * ------------ ---------- ----------- -------------------------- * 08/29/09 2152 D. Hladky Initial release - * + * 05/21/12 DR 14833 G. Zhang Error handling for invalid cmap * * * @author dhladky @@ -68,7 +68,16 @@ public class FFMPColorUtils { private ArrayList fileArray = new ArrayList(); - private TreeMap hourColorMapMap = new TreeMap(); + private TreeMap hourColorMapMap = new TreeMap(); + + // DR 14833: replacing the one in the constructor + private StyleRule sr = null; + + // DR 14833: used when no colormap found + private static final String DEFAULT_COLORMAP = "ffmp/qpe"; + + // DR 14833: used when paramname not matching colormap name found + private static final String DEFAULT_PARAMNAME = "qpe"; /** * Set up FFMP Color maps @@ -84,7 +93,18 @@ public class FFMPColorUtils { this.tableLoad = tableLoad; this.colormapparams = null; - StyleRule sr = null; + // LocalizationFile[] files = ColorMapLoader.listColorMapFiles(); + // for (LocalizationFile file : files) { + // String fn = file.getName(); + // if (fn.startsWith("colormaps/ffmp/qpe")) + // { + // System.out.println(file.getName()); + // String hour = fn.s + // } + // + // } + +// StyleRule sr = null;// DR 14833 replaced by a instance field try { sr = StyleManager.getInstance().getStyleRule( StyleManager.StyleType.IMAGERY, getMatchCriteria()); @@ -102,6 +122,7 @@ public class FFMPColorUtils { e.printStackTrace(); } + if(cxml == null) cxml = getDefaultColorMap(); // DR 14833: load the default map ColorMap colorMap = new ColorMap(colormapfile, (ColorMap) cxml); colormapparams = new ColorMapParameters(); colormapparams.setColorMap(colorMap); @@ -167,8 +188,8 @@ public class FFMPColorUtils { double val2 = (Math.round(valueArg * 100.0)) / 100.0; Double value = val2; - - if (value < 0.01 && field != FIELDS.DIFF) { + + if (value < 0.005 && field != FIELDS.DIFF) { ret = 0; } else if (field == FIELDS.DIFF) { @@ -320,5 +341,72 @@ public class FFMPColorUtils { fileArray.add(fn); } } + } + + + /** + * DR 14833: Error handling for the following: + * when a user modified the ffmpImageryStyleRules.xml file + * without adding the related qpeX.cmap and for a user made + * error like: qpe6/qpe4.cmap then default qpe/qpe.cmap used. + * + */ + public IColorMap getDefaultColorMap(){ + IColorMap cxml = null; + + /*see parseFileNames(): colormap_name is "0.0" or qpe+key+".cmap" + double hour = hourColorMapMap.firstKey(); + String cmapHour = ( hour==0.0 ? "" : String.valueOf(hour) ); + System.out.println("FFMPColorUtils.getDefaultColorMap() cmapHour: "+cmapHour );*/ + + /* Loop through all StyleRules to get the default. + * In StyleManager.loadRules(StyleType), all levels(not only USER) + * StyleRule loaded. So it is guaranteed the default can be loaded. + */ + + com.raytheon.uf.viz.core.style.StyleRuleset srs = + StyleManager.getInstance().getStyleRuleSet(StyleManager.StyleType.IMAGERY); + + for(StyleRule srl : srs.getStyleRules()){ + String pn="", cm=""; + try{ + pn = ((ParamLevelMatchCriteria)srl.getMatchCriteria()).getParameterNames().get(0); + cm = ((ImagePreferences)srl.getPreferences()).getDefaultColormap(); + }catch(Exception e){ continue; } + + if(DEFAULT_PARAMNAME.equalsIgnoreCase(pn) && DEFAULT_COLORMAP.equalsIgnoreCase(cm)){ + sr = srl; + System.out.println("FFMPColorUtils.getDefaultColorMap(): StyleRule pn-cm value: "+pn+"-"+cm); + break; + } + + } + /* + if(sr == null){ + //get the MatchCriteria + ParamLevelMatchCriteria match = new ParamLevelMatchCriteria(); + ArrayList paramList = new ArrayList(); + paramList.add( FIELDS.QPE.getFieldName()+cmapHour ); + match.setParameterName(paramList); + + //get the StyleRule + try { + sr=StyleManager.getInstance().getStyleRule(StyleManager.StyleType.IMAGERY, match); + } catch (VizStyleException e) { + e.printStackTrace(); + } + } + */ + //get the colormapfile name + String colormapfile = ((ImagePreferences) sr.getPreferences()).getDefaultColormap(); + + //load the colormap + try { + cxml = ColorMapLoader.loadColorMap(colormapfile); + } catch (VizException e) { + e.printStackTrace(); + } + + return cxml; } } diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataGenerator.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataGenerator.java index ec9e26c716..ae4aa8c0f9 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataGenerator.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataGenerator.java @@ -26,9 +26,9 @@ import java.util.HashMap; import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasin; import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasinData; import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasinMetaData; +import com.raytheon.uf.common.dataplugin.ffmp.FFMPCacheRecord; import com.raytheon.uf.common.dataplugin.ffmp.FFMPGuidanceBasin; import com.raytheon.uf.common.dataplugin.ffmp.FFMPGuidanceInterpolation; -import com.raytheon.uf.common.dataplugin.ffmp.FFMPRecord; import com.raytheon.uf.common.dataplugin.ffmp.FFMPRecord.FIELDS; import com.raytheon.uf.common.dataplugin.ffmp.FFMPTemplates; import com.raytheon.uf.common.dataplugin.ffmp.FFMPUtils; @@ -94,17 +94,17 @@ public class FFMPDataGenerator { FFMPBasinData virtualBasin = null; - FFMPRecord rateRecord = null; + FFMPCacheRecord rateRecord = null; - FFMPRecord qpeRecord = null; + FFMPCacheRecord qpeRecord = null; - FFMPRecord qpfRecord = null; + FFMPCacheRecord qpfRecord = null; - HashMap guidRecords = null; + HashMap guidRecords = null; - FFMPRecord virtualRecord = null; + FFMPCacheRecord virtualRecord = null; - FFMPRecord baseRec = null; + FFMPCacheRecord baseRec = null; // Date time = null; @@ -374,7 +374,7 @@ public class FFMPDataGenerator { if ((qpfBasin != null) && (qpfBasin.get(parentBasinPfaf) != null)) { - qpf = qpfBasin.get(parentBasinPfaf).getValue( + qpf = qpfBasin.get(parentBasinPfaf).getAverageValue( monitor.getQpfWindow().getAfterTime(), monitor.getQpfWindow().getBeforeTime()); trd.setTableCellData(3, new FFMPTableCellData( @@ -557,7 +557,7 @@ public class FFMPDataGenerator { if ((qpfBasin != null) && (qpfBasin.get(cBasin.getPfaf()) != null)) { - qpf = qpfBasin.get(cBasin.getPfaf()).getValue( + qpf = qpfBasin.get(cBasin.getPfaf()).getAverageValue( monitor.getQpfWindow().getAfterTime(), monitor.getQpfWindow().getBeforeTime()); // qpf = getQPFValue(false, cBasin.getPfaf(), @@ -872,7 +872,7 @@ public class FFMPDataGenerator { trd.setTableCellData( 3, new FFMPTableCellData(FIELDS.QPF, new Float( - qpeBasin.get(cBasin.getPfaf()).getValue( + qpfBasin.get(cBasin.getPfaf()).getMaxValue( monitor.getQpfWindow() .getAfterTime(), monitor.getQpfWindow() @@ -960,7 +960,7 @@ public class FFMPDataGenerator { Float.NaN)); } if (qpfBasin != null) { - qpf = qpfBasin.getMaxValue(pfafs, monitor.getQpfWindow() + qpf = qpfBasin.getAverageMaxValue(pfafs, monitor.getQpfWindow() .getAfterTime(), monitor.getQpfWindow() .getBeforeTime()); @@ -1103,7 +1103,7 @@ public class FFMPDataGenerator { trd.setTableCellData( 3, new FFMPTableCellData(FIELDS.QPF, new Float( - qpeBasin.get(cBasin.getPfaf()).getValue( + qpfBasin.get(cBasin.getPfaf()).getMaxValue( monitor.getQpfWindow() .getAfterTime(), monitor.getQpfWindow() @@ -1266,7 +1266,9 @@ public class FFMPDataGenerator { qpeBasin = qpeRecord.getBasinData(huc); if (qpeBasin.getBasins().size() > 0) { field = FIELDS.QPE; - baseRec = qpeRecord; + if (baseRec == null) { + baseRec = qpeRecord; + } } } if (qpfRecord != null) { diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataLoader.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataLoader.java index bed5a74482..f0cf2743a5 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataLoader.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPDataLoader.java @@ -102,7 +102,7 @@ public class FFMPDataLoader extends Thread { sharePath = AppsDefaults.getInstance().getToken("apps_dir") + File.separator + "ffmp" + File.separator; //sharePath = "/awips2/edex/data/share/hydroapps/ffmp/"; - + this.product = resourceData.getProduct(); this.siteKey = resourceData.siteKey; this.dataKey = resourceData.dataKey; @@ -151,7 +151,9 @@ public class FFMPDataLoader extends Thread { long time = System.currentTimeMillis(); try { - + resourceData.setLoader(loadType); + System.out.println("Starting Loader: "+loadType.getLoaderType()); + ProductRunXML productRun = runner.getProduct(siteKey); ArrayList qpfSources = new ArrayList(); @@ -162,8 +164,8 @@ public class FFMPDataLoader extends Thread { || (loadType == LOADER_TYPE.GENERAL)) { rateURI = getMonitor().getAvailableUri(siteKey, dataKey, product.getRate(), mostRecentTime); - } - + } + NavigableMap> qpeURIs = getMonitor() .getAvailableUris(siteKey, dataKey, product.getQpe(), timeBack); @@ -185,7 +187,7 @@ public class FFMPDataLoader extends Thread { qpfURIs = getMonitor().getAvailableUris(siteKey, dataKey, qpfSource.getSourceName(), qpfTime); - if (qpfURIs != null) { + if (qpfURIs != null && !qpfURIs.isEmpty()) { qpfs.add(qpfURIs); qpfSources.add(qpfSource.getSourceName()); } @@ -213,11 +215,16 @@ public class FFMPDataLoader extends Thread { iguidURIs = getMonitor().getAvailableUris(siteKey, dataKey, guidSource.getSourceName(), guidTime); - if (iguidURIs != null) { + if (iguidURIs != null && !iguidURIs.isEmpty()) { guids.put(guidSource.getSourceName(), iguidURIs); } } } + // We only load all for long range data, all + layer for medium range + if (loadType == LOADER_TYPE.TERTIARY) { + hucsToLoad.clear(); + hucsToLoad.add("ALL"); + } for (String phuc : hucsToLoad) { @@ -231,8 +238,9 @@ public class FFMPDataLoader extends Thread { } else { // rate if (rateURI != null) { - System.out.println("Processing " + loadType - + " Rate: huc = " + phuc); + fireLoaderEvent(loadType, "Processing "+product.getRate() + "/" + phuc, + isDone); + getMonitor().processUri(isProductLoad, rateURI, siteKey, product.getRate(), timeBack, phuc); fireLoaderEvent(loadType, product.getRate() + "/" @@ -240,8 +248,8 @@ public class FFMPDataLoader extends Thread { } // qpes - System.out.println("Processing " + loadType - + " QPE: huc = " + phuc); + fireLoaderEvent(loadType, "Processing "+product.getQpe() + "/" + phuc, + isDone); FFMPBasinData qpeData = null; if ((loadType == LOADER_TYPE.INITIAL) @@ -258,10 +266,10 @@ public class FFMPDataLoader extends Thread { getMonitor().insertFFMPData(qpeData, siteKey, product.getQpe(), phuc); } - } + } - if (!qpeURIs.isEmpty()) { - if (phuc.equals(config.getFFMPConfigData().getLayer())) { + if (!qpeURIs.isEmpty() && qpeData == null) { + if (phuc.equals(config.getFFMPConfigData().getLayer()) || phuc.equals("ALL")) { getMonitor().processUris(qpeURIs, isProductLoad, siteKey, product.getQpe(), timeBack, phuc, loadType); @@ -274,8 +282,8 @@ public class FFMPDataLoader extends Thread { int i = 0; for (NavigableMap> qpfURIs : qpfs) { // qpf - System.out.println("Processing " + loadType - + " QPF: huc = " + phuc); + fireLoaderEvent(loadType, "Processing "+product.getQpf(i) + "/" + phuc, + isDone); FFMPBasinData qpfData = null; if ((loadType == LOADER_TYPE.INITIAL) || (loadType == LOADER_TYPE.SECONDARY)) { @@ -289,8 +297,8 @@ public class FFMPDataLoader extends Thread { if (qpfData != null) { - if (phuc.equals(config.getFFMPConfigData() - .getLayer()) + if ((phuc.equals(config.getFFMPConfigData() + .getLayer()) || phuc.equals("ALL")) && loadType == LOADER_TYPE.INITIAL && source.getSourceName().equals( config.getFFMPConfigData() @@ -311,7 +319,7 @@ public class FFMPDataLoader extends Thread { //if (isUrisProcessNeeded(qpfData,qpfURIs)) {/*DR13839*/ if ((qpfData == null) && !qpfURIs.isEmpty()) { if (phuc.equals(config.getFFMPConfigData() - .getLayer())) { //old code: keep for reference*/ + .getLayer()) || phuc.equals("ALL")) { //old code: keep for reference*/ //if (isHucProcessNeeded(phuc)) {/*DR13839*/ getMonitor().processUris(qpfURIs, isProductLoad, siteKey, @@ -329,9 +337,8 @@ public class FFMPDataLoader extends Thread { } // virtuals only have data for ALL if (phuc.equals("ALL")) { - System.out.println("Processing " + loadType - + " VGB: huc = " + phuc); - + fireLoaderEvent(loadType, "Processing "+product.getVirtual() + "/" + phuc, + isDone); FFMPBasinData vgbData = null; if ((loadType == LOADER_TYPE.INITIAL) @@ -361,16 +368,17 @@ public class FFMPDataLoader extends Thread { } // process guidance all at once - System.out.println("Processing " + loadType - + " GUIDANCE: huc = " + phuc); - for (String type : productRun.getGuidanceTypes(product)) { - + ArrayList guidSources = productRun .getGuidanceSources(product, type); for (SourceXML guidSource : guidSources) { + NavigableMap> iguidURIs = guids .get(guidSource.getSourceName()); + + fireLoaderEvent(loadType, "Processing "+guidSource.getSourceName() + "/" + phuc, + isDone); getMonitor().processUris(iguidURIs, isProductLoad, siteKey, guidSource.getSourceName(), timeBack, @@ -386,11 +394,10 @@ public class FFMPDataLoader extends Thread { } } catch (Exception e) { isDone = true; - statusHandler.error("FFMP Data Loader terminated...." + System.err.println("FFMP Data Loader terminated...." + e.getMessage()); } finally { isDone = true; - resourceData.setLoader(loadType); } String message = null; @@ -471,26 +478,35 @@ public class FFMPDataLoader extends Thread { String sourceName = source.getSourceName(); File file = new File(sharePath + wfo + File.separator + sourceName + "-" + siteKey + "-" + pdataKey + "-" + huc + ".bin"); + System.out.println("Buddy File path: " + file.getAbsolutePath()); - FFMPBasinData basinData = null; + FFMPBasinData basinData = null; - if (file.exists()) { + if (file.exists()) { + + System.out.println("Last mod: " + new Date(file.lastModified())); + //System.out.println("6 hour mod: " + new Date((System.currentTimeMillis() - (6 * 1000 * 3600)))); + //System.out.println("DIFF: "+(file.lastModified() - (System.currentTimeMillis() - (6 * 1000 * 3600)))); - System.out.println("File path: " + file.getName()); + if (file.lastModified() > (System.currentTimeMillis() - (6 * 1000 * 3600))) { + + System.out.println("Buddy File path: " + file.getName()); + + try { + basinData = (FFMPBasinData) SerializationUtil + .transformFromThrift(FileUtil.file2bytes(file, + false)); + } catch (SerializationException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } - try { - basinData = (FFMPBasinData) SerializationUtil - .transformFromThrift(FileUtil.file2bytes(file, false)); - } catch (SerializationException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } - } + return basinData; - return basinData; - - } + } /** * Finds the home datakey identifier for QPF sources diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPResource.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPResource.java index 010cb50ffb..96098d006c 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPResource.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPResource.java @@ -52,6 +52,7 @@ import org.opengis.referencing.operation.TransformException; import com.raytheon.uf.common.dataplugin.PluginDataObject; import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasin; import com.raytheon.uf.common.dataplugin.ffmp.FFMPBasinMetaData; +import com.raytheon.uf.common.dataplugin.ffmp.FFMPCacheRecord; import com.raytheon.uf.common.dataplugin.ffmp.FFMPGap; import com.raytheon.uf.common.dataplugin.ffmp.FFMPGuidanceBasin; import com.raytheon.uf.common.dataplugin.ffmp.FFMPGuidanceInterpolation; @@ -65,9 +66,17 @@ import com.raytheon.uf.common.dataplugin.ffmp.FFMPVirtualGageBasinMetaData; import com.raytheon.uf.common.dataplugin.ffmp.HucLevelGeometriesFactory; import com.raytheon.uf.common.geospatial.MapUtil; import com.raytheon.uf.common.geospatial.ReferencedCoordinate; +import com.raytheon.uf.common.localization.IPathManager; +import com.raytheon.uf.common.localization.LocalizationContext; +import com.raytheon.uf.common.localization.LocalizationContext.LocalizationLevel; +import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; +import com.raytheon.uf.common.localization.LocalizationFile; +import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.monitor.config.FFFGDataMgr; +import com.raytheon.uf.common.monitor.config.FFMPRunConfigurationManager; import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager; import com.raytheon.uf.common.monitor.xml.DomainXML; +import com.raytheon.uf.common.monitor.xml.ProductRunXML; import com.raytheon.uf.common.monitor.xml.ProductXML; import com.raytheon.uf.common.monitor.xml.SourceXML; import com.raytheon.uf.common.status.IUFStatusHandler; @@ -108,6 +117,7 @@ import com.raytheon.uf.viz.monitor.ffmp.FFMPMonitor; import com.raytheon.uf.viz.monitor.ffmp.ui.dialogs.FFMPConfig; import com.raytheon.uf.viz.monitor.ffmp.ui.dialogs.FfmpBasinTableDlg; import com.raytheon.uf.viz.monitor.ffmp.ui.dialogs.FfmpTableConfig; +import com.raytheon.uf.viz.monitor.ffmp.ui.dialogs.FfmpTableConfigData; import com.raytheon.uf.viz.monitor.ffmp.ui.listeners.FFMPAutoRefreshEvent; import com.raytheon.uf.viz.monitor.ffmp.ui.listeners.FFMPCWAChangeEvent; import com.raytheon.uf.viz.monitor.ffmp.ui.listeners.FFMPFieldChangeEvent; @@ -249,23 +259,23 @@ public class FFMPResource extends }; - private FFMPRecord rateRecord = null; + private FFMPCacheRecord rateRecord = null; private boolean isNewRate = true; - private FFMPRecord qpeRecord = null; + private FFMPCacheRecord qpeRecord = null; private boolean isNewQpe = true; - private FFMPRecord guidRecord = null; + private FFMPCacheRecord guidRecord = null; private boolean isNewGuid = true; - private FFMPRecord qpfRecord = null; + private FFMPCacheRecord qpfRecord = null; private boolean isNewQpf = true; - private FFMPRecord virtualRecord = null; + private FFMPCacheRecord virtualRecord = null; private boolean isNewVirtual = true; @@ -309,7 +319,7 @@ public class FFMPResource extends /** table slider time **/ private Date tableTime = null; - + // complete reset public boolean isQuery = true; @@ -332,6 +342,9 @@ public class FFMPResource extends /** guidance source expiration **/ public long guidSourceExpiration = 0l; + + /** QPF source expiration **/ + public long qpfSourceExpiration = 0l; /** is this a rate load **/ public Boolean isRate = null; @@ -622,7 +635,7 @@ public class FFMPResource extends } case QPF: { value = getQpfRecord(recentTime).getBasinData("ALL") - .getMaxValue(pfafs, recentTime); + .getAverageMaxValue(pfafs, recentTime, getQpfSourceExpiration()); break; } case GUIDANCE: { @@ -673,7 +686,7 @@ public class FFMPResource extends case RATE:// fall through case QPF: { value = getBasin(key, field, recentTime, aggregate) - .getValue(recentTime); + .getAverageValue(recentTime, getQpfSourceExpiration()); break; } case GUIDANCE: { @@ -700,7 +713,7 @@ public class FFMPResource extends switch (field) { case QPF: { value = getBasin(key, field, recentTime, aggregate) - .getValue(recentTime); + .getAverageValue(recentTime, getQpfSourceExpiration()); break; } case GUIDANCE: { @@ -1262,18 +1275,6 @@ public class FFMPResource extends } } - if (getResourceData().isSecondaryLoad) { - // kick in tertiary loader - if (!getResourceData().isTertiaryLoad) { - if ((loader == null) || !loader.isAlive()) { - Date backDate = new Date(getMostRecentTime() - .getTime() - (24 * 1000 * 3600)); - startLoader(getOldestTime(), backDate, - LOADER_TYPE.TERTIARY); - } - } - } - // the product string if (isFfmpDataToggle() && fieldDescString != null) { paintProductString(aTarget, paintProps); @@ -1568,13 +1569,13 @@ public class FFMPResource extends buf.append("County: " + metaBasin.getState() + ", " + metaBasin.getCounty() + "\n"); String valst = null; - Float val = getBasinValue(pfaf, paintTime.getRefTime(), + Float val = getBasinValue(pfaf, getPaintTime().getRefTime(), aggregate); if (val.isNaN() || (val == FFMPUtils.MISSING)) { valst = "NO DATA"; } else { valst = df.format(getBasinValue(pfaf, - paintTime.getRefTime(), aggregate)); + getPaintTime().getRefTime(), aggregate)); } if (!valst.equals("NO DATA")) { @@ -2233,7 +2234,7 @@ public class FFMPResource extends public DataTime getPaintTime() { return paintTime; } - + /** * Add a value to worst case hash * @@ -3026,7 +3027,7 @@ public class FFMPResource extends if (ffmpTime.getTime() != time || isSplit != ffmpTime.isSplit()) { isSplit = ffmpTime.isSplit(); - setTime(ffmpTime.getTime()); + setTime(ffmpTime.getTime()); setTableTime(); if (interpolationMap != null) { interpolationMap.clear(); @@ -3916,7 +3917,7 @@ public class FFMPResource extends private void purge(Date pdate) { long time = pdate.getTime(); - time = time - (3600 * 1000 * 24); + time = time - getPurgePeriod(); Date ndate = new Date(time); ArrayList removes = new ArrayList(); @@ -3965,6 +3966,30 @@ public class FFMPResource extends } return qpeSourceExpiration; } + + /** + * source expiration value as a long + * + * @return + */ + public long getQpfSourceExpiration() { + if (qpfSourceExpiration == 0l) { + SourceXML source = null; + if (getProduct() != null) { + FfmpTableConfigData ffmpTableCfgData = FfmpTableConfig + .getInstance().getTableConfigData(getSiteKey()); + String qpfType = ffmpTableCfgData.getQpfType(); + + source = getProduct().getQpfSourcesByType(qpfType).get(0); + } else { + source = FFMPSourceConfigurationManager.getInstance() + .getSource(getResourceData().sourceName); + } + qpfSourceExpiration = source.getExpirationMinutes(getSiteKey()) * 60 * 1000; + } + return qpfSourceExpiration; + } + /** * Gets the guidance source expiration @@ -4130,7 +4155,9 @@ public class FFMPResource extends ArrayList hucsToLoad = new ArrayList(); if (isWorstCase) { - hucsToLoad.add("ALL"); + if (!hucsToLoad.contains("ALL")) { + hucsToLoad.add("ALL"); + } } // tertiary loader only loads ALL @@ -4163,5 +4190,62 @@ public class FFMPResource extends loader.removeListener(this); } } + + /** + * Get the purge file time + */ + public long getPurgePeriod() { + + IPathManager pm = PathManagerFactory.getPathManager(); + LocalizationContext lc = pm.getContext( + LocalizationType.COMMON_STATIC, LocalizationLevel.SITE); + LocalizationFile lfFile = pm.getLocalizationFile(lc, + "purge/ffmpPurgeRules.xml"); + + if (lfFile.exists()) { + + //TODO Need to figure out why we can't read in the purgeRules! + /*try { + PurgeRuleSet prs = (PurgeRuleSet) SerializationUtil + .jaxbUnmarshalFromXmlFile(lfFile.getFile().getAbsolutePath()); + + for (PurgeRule rule: prs.getRules()) { + if (rule.getId().equals("ffmp")) { + return rule.getPeriodInMillis(); + } + } + + } catch (SerializationException e) { + e.printStackTrace(); + return 3600*24*1000; + } */ + + } + + return 3600*24*1000; + } + + /** + * Kicks off additional loaders that need to be fired off + * @param loader + * @param isDone + */ + public void manageLoaders(FFMPLoaderStatus status) { + + if (status.getLoaderType() == LOADER_TYPE.SECONDARY) { + if (status.isDone() && !this.getResourceData().isTertiaryLoad) { + try { + Date startDate = new Date(getMostRecentTime().getTime() - 12 * 3600 * 1000); + FFMPMonitor.getInstance().startLoad(this, startDate, + LOADER_TYPE.TERTIARY); + } catch (VizException e) { + statusHandler.handle(Priority.PROBLEM, + "Secondary Data Load failure", e); + } + } + } + + // We don't really care about status of tertiary and general loaders + } } diff --git a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPResourceData.java b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPResourceData.java index a0d42b7492..3f6145738a 100644 --- a/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPResourceData.java +++ b/cave/com.raytheon.uf.viz.monitor.ffmp/src/com/raytheon/uf/viz/monitor/ffmp/ui/rsc/FFMPResourceData.java @@ -40,6 +40,7 @@ import com.raytheon.uf.common.localization.LocalizationContext.LocalizationType; import com.raytheon.uf.common.localization.PathManagerFactory; import com.raytheon.uf.common.monitor.config.FFMPRunConfigurationManager; import com.raytheon.uf.common.monitor.config.FFMPSourceConfigurationManager.SOURCE_TYPE; +import com.raytheon.uf.common.monitor.config.FFMPTemplateConfigurationManager; import com.raytheon.uf.common.monitor.xml.DomainXML; import com.raytheon.uf.common.monitor.xml.ProductRunXML; import com.raytheon.uf.common.monitor.xml.ProductXML; @@ -229,41 +230,18 @@ public class FFMPResourceData extends AbstractRequestableResourceData { this.timeBack = new Date( (long) (mostRecentTime.getRefTime().getTime() - (cfgBasinXML .getTimeFrame() * 3600 * 1000))); - ArrayList hucsToLoad = new ArrayList(); - hucsToLoad.add(ffmpConfig.getFFMPConfigData().getLayer()); - if (!ffmpConfig.getFFMPConfigData().getLayer().equals("ALL")) { - hucsToLoad.add("ALL"); - } - + ArrayList hucsToLoad = FFMPTemplateConfigurationManager.getInstance().getHucLevels(); // goes back X hours and pre populates the Data Hashes FFMPDataLoader loader = new FFMPDataLoader(this, timeBack, mostRecentTime.getRefTime(), LOADER_TYPE.INITIAL, hucsToLoad); loader.start(); - int i = 0; - // make the table load wait for finish of initial data load - while (!loader.isDone) { - try { - // give it 120 or so seconds - if (i > 12000) { - statusHandler - .handle(Priority.WARN, - "Didn't load initial data in allotted time, releasing table"); - break; - } - Thread.sleep(30); - i++; - } catch (InterruptedException e) { - e.printStackTrace(); - } - } - } else { SourceXML source = getPrimarySourceXML(); this.domains = monitor.getRunConfig().getDomains(); - + for (int i = 0; i < objects.length; i++) { FFMPRecord rec = (FFMPRecord) objects[i]; rec.setExpiration(source.getExpirationMinutes(siteKey)); diff --git a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/data/TableUtil.java b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/data/TableUtil.java index 3e347fea0b..d6938540ae 100644 --- a/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/data/TableUtil.java +++ b/cave/com.raytheon.uf.viz.monitor/src/com/raytheon/uf/viz/monitor/data/TableUtil.java @@ -48,6 +48,7 @@ import com.raytheon.uf.viz.monitor.util.MonitorConfigConstants; * ------------ ---------- ----------- -------------------------- * Dec. 3, 2009 3424 zhao Initial creation. * Jan 25, 2010 4281 wkwock/Zhao Added history-table-row-data related modules + * May 23, 2012 14410 zhao Modified getCellTypeForBlizWarn and getCellTypeForHsnowWarn modules * * * @@ -750,23 +751,39 @@ public final class TableUtil { CellType type = CellType.NotAvailable; // default; assuming no observation available String presentWx = report.getPresentWx(); + + CellType windSpeed = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_PROD_BLIZZ_WIND_SPEED.getXmlKey(), report.getWindSpeed()); - CellType windSpeed = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_WIND_WIND_SPEED.getXmlKey(), report.getWindSpeed()); + CellType peakWind = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_PROD_BLIZZ_PEAK_WIND.getXmlKey(), report.getMaxWindSpeed()); - CellType peakWind = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_WIND_PEAK_WIND.getXmlKey(), report.getMaxWindSpeed()); + CellType windGust = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_PROD_BLIZZ_GUST_SPEED.getXmlKey(), report.getWindGust()); - CellType windGust = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_WIND_GUST_SPEED.getXmlKey(), report.getWindGust()); - - CellType visibility = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_METEO_VIS.getXmlKey(), report.getVisibility()); + CellType visibility = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_PROD_BLIZZ_VIS.getXmlKey(), report.getVisibility()); if ( presentWx.contains("SN") || presentWx.contains("BLSN") ) { // snow or blowing snow observed - if ( windSpeed.equals(CellType.R) || peakWind.equals(CellType.R) || windGust.equals(CellType.R) || visibility.equals(CellType.R) ) { - type = CellType.R; - } else if ( windSpeed.equals(CellType.Y) || peakWind.equals(CellType.Y) || windGust.equals(CellType.Y) || visibility.equals(CellType.Y) ) { - type = CellType.Y; - } else if ( windSpeed.equals(CellType.G) || peakWind.equals(CellType.G) || windGust.equals(CellType.G) || visibility.equals(CellType.G) ) { - type = CellType.G; + if ( windSpeed.equals(CellType.R) || peakWind.equals(CellType.R) || windGust.equals(CellType.R) ) { + if ( visibility.equals(CellType.R) ) { + type = CellType.R; + } else { + type = CellType.Y; + } + } else if ( windSpeed.equals(CellType.Y) || peakWind.equals(CellType.Y) || windGust.equals(CellType.Y) ) { + type = CellType.Y; + } else if ( windSpeed.equals(CellType.G) || peakWind.equals(CellType.G) || windGust.equals(CellType.G) ) { + if ( visibility.equals(CellType.R) || visibility.equals(CellType.Y) ) { + type = CellType.Y; + } else if ( visibility.equals(CellType.G) ) { + type = CellType.G; + } else { + type = CellType.NotAvailable; + } + } else { + if ( visibility.equals(CellType.R) || visibility.equals(CellType.Y) ) { + type = CellType.Y; + } else { + type = CellType.NotAvailable; + } } } else { // snow or blowing snow not observed @@ -836,12 +853,12 @@ public final class TableUtil { public static CellType getCellTypeForHsnowWarn(String zone, ObReport report, AbstractThresholdMgr tm) { CellType type = CellType.NotAvailable; // default, assuming no observation available + + CellType snowDepth = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_PROD_HSW_SNOW_DEPTH.getXmlKey(), report.getSnowDepth()); - CellType snowDepth = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_METEO_TEMP.getXmlKey(), report.getSnowDepth()); + CellType snincrHourly = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_PROD_HSW_SNINCR_HOURLY.getXmlKey(), report.getSnincrHourly()); - CellType snincrHourly = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_METEO_TEMP.getXmlKey(), report.getSnincrHourly()); - - CellType snincrTotal = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_METEO_TEMP.getXmlKey(), report.getSnincrTotal()); + CellType snincrTotal = tm.getThresholdValueCellType(DataUsageKey.DISPLAY, zone, MonitorConfigConstants.SnowDisplay.SNOW_DISP_PROD_HSW_SNINCR_TOTAL.getXmlKey(), report.getSnincrTotal()); if ( snowDepth.equals(CellType.R) || snincrHourly.equals(CellType.R) || snincrTotal.equals(CellType.R) ) { type = CellType.R; diff --git a/cave/com.raytheon.uf.viz.objectiveanalysis/src/com/raytheon/uf/viz/objectiveanalysis/rsc/OAResource.java b/cave/com.raytheon.uf.viz.objectiveanalysis/src/com/raytheon/uf/viz/objectiveanalysis/rsc/OAResource.java index 9ae30e4137..65f13463c2 100644 --- a/cave/com.raytheon.uf.viz.objectiveanalysis/src/com/raytheon/uf/viz/objectiveanalysis/rsc/OAResource.java +++ b/cave/com.raytheon.uf.viz.objectiveanalysis/src/com/raytheon/uf/viz/objectiveanalysis/rsc/OAResource.java @@ -77,14 +77,12 @@ import com.raytheon.uf.viz.core.style.StyleManager; import com.raytheon.uf.viz.core.style.StyleRule; import com.raytheon.uf.viz.core.style.VizStyleException; import com.raytheon.uf.viz.core.style.level.SingleLevel; -import com.raytheon.viz.core.contours.ILoadableAsImage; import com.raytheon.viz.core.contours.rsc.displays.GriddedContourDisplay; import com.raytheon.viz.core.contours.rsc.displays.GriddedVectorDisplay; import com.raytheon.viz.core.drawables.ColorMapParameterFactory; import com.raytheon.viz.core.rsc.displays.GriddedImageDisplay; import com.raytheon.viz.core.rsc.displays.GriddedImageDisplay.GriddedImagePaintProperties; import com.raytheon.viz.core.style.contour.ContourPreferences; -import com.raytheon.viz.grid.rsc.GridLoadProperties; import com.vividsolutions.jts.geom.Coordinate; /** @@ -106,7 +104,7 @@ import com.vividsolutions.jts.geom.Coordinate; public class OAResource extends AbstractVizResource implements - IResourceDataChanged, ILoadableAsImage { + IResourceDataChanged { private static final transient IUFStatusHandler statusHandler = UFStatus .getHandler(OAResource.class); @@ -178,6 +176,8 @@ public class OAResource extends this.displayType = getCapability(DisplayTypeCapability.class) .getDisplayType(); + getCapability(DisplayTypeCapability.class).setAlternativeDisplayTypes( + Arrays.asList(DisplayType.IMAGE)); resourceData.addChangeListener(this); if (this.displayType == DisplayType.IMAGE) { this.getCapability(ImagingCapability.class); @@ -694,17 +694,6 @@ public class OAResource extends disposeRenderable(renderableMap.remove(dataTime)); } - /* - * (non-Javadoc) - * - * @see com.raytheon.viz.core.contours.ILoadableAsImage#getImageryResource() - */ - @Override - public AbstractVizResource getImageryResource() throws VizException { - return this.resourceData.construct(new GridLoadProperties( - DisplayType.IMAGE), descriptor); - } - /* * (non-Javadoc) * @@ -720,13 +709,4 @@ public class OAResource extends } } - /* - * (non-Javadoc) - * - * @see com.raytheon.viz.core.contours.ILoadableAsImage#isLoadableAsImage() - */ - @Override - public boolean isLoadableAsImage() { - return true; - } } diff --git a/cave/com.raytheon.uf.viz.python.swt/src/com/raytheon/uf/viz/python/swt/DialogAreaComposite.java b/cave/com.raytheon.uf.viz.python.swt/src/com/raytheon/uf/viz/python/swt/DialogAreaComposite.java index 76f3816563..b9f38686f4 100644 --- a/cave/com.raytheon.uf.viz.python.swt/src/com/raytheon/uf/viz/python/swt/DialogAreaComposite.java +++ b/cave/com.raytheon.uf.viz.python.swt/src/com/raytheon/uf/viz/python/swt/DialogAreaComposite.java @@ -86,21 +86,21 @@ public class DialogAreaComposite extends ScrolledComposite { Composite rowOfButtons = new Composite(composite, style); GridLayout gridLayout = new GridLayout(1, false); rowOfButtons.setLayout(gridLayout); - widget.buildComposite(rowOfButtons, style); + widget.buildComposite(rowOfButtons); while (wIterator.hasNext()) { widget = wIterator.next(); if (widget instanceof ButtonWidget) { gridLayout.numColumns++; - widget.buildComposite(rowOfButtons, style); + widget.buildComposite(rowOfButtons); } else { - widget.buildComposite(composite, style); + widget.buildComposite(composite); break; } } } else { - widget.buildComposite(composite, style); + widget.buildComposite(composite); } } diff --git a/cave/com.raytheon.uf.viz.python.swt/src/com/raytheon/uf/viz/python/swt/widgets/ButtonWidget.java b/cave/com.raytheon.uf.viz.python.swt/src/com/raytheon/uf/viz/python/swt/widgets/ButtonWidget.java index 1b614485f0..677b220374 100644 --- a/cave/com.raytheon.uf.viz.python.swt/src/com/raytheon/uf/viz/python/swt/widgets/ButtonWidget.java +++ b/cave/com.raytheon.uf.viz.python.swt/src/com/raytheon/uf/viz/python/swt/widgets/ButtonWidget.java @@ -24,7 +24,7 @@ import java.util.ArrayList; import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionListener; import org.eclipse.swt.layout.GridData; -import org.eclipse.swt.layout.RowLayout; +import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Group; @@ -56,22 +56,26 @@ public abstract class ButtonWidget extends Widget { * .swt.widgets.Composite, int) */ @Override - public Composite buildComposite(Composite parent, int style) { + public Composite buildComposite(Composite parent) { - Group group = new Group(parent, style); + Group group = new Group(parent, SWT.NONE); group.setText(makeGuiLabel(getLabel())); GridData layoutData = new GridData(SWT.DEFAULT, SWT.FILL, false, true); group.setLayoutData(layoutData); - RowLayout rowLayout = new RowLayout(SWT.VERTICAL); - rowLayout.pack = false; - group.setLayout(rowLayout); + GridLayout layout = new GridLayout(1, false); + layout.marginHeight = 0; + layout.verticalSpacing = 0; + group.setLayout(layout); buttons = new ArrayList