From 8577e5c70ce9d3edf202e6d71c9f4820b875b618 Mon Sep 17 00:00:00 2001 From: Nate Jensen Date: Mon, 14 Sep 2015 12:37:01 -0500 Subject: [PATCH] Omaha #4880 fix AvnFPS to not use strings for dates Change-Id: I0357868db043b78aca234c362e9916625b7b9f3e Former-commit-id: dc39083c187635a6e6c5db7239a1a58ccfc05498 --- .../pointdata/PointDataRetrieve.py | 58 ++++++++++--------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/cave/com.raytheon.viz.pointdata/localization/pointdata/PointDataRetrieve.py b/cave/com.raytheon.viz.pointdata/localization/pointdata/PointDataRetrieve.py index 702bdfc40e..0d2f25596d 100644 --- a/cave/com.raytheon.viz.pointdata/localization/pointdata/PointDataRetrieve.py +++ b/cave/com.raytheon.viz.pointdata/localization/pointdata/PointDataRetrieve.py @@ -22,22 +22,22 @@ import PointDataView, PointDataContainer, NoDataException # -# Python module to request point data. Split out of -# PointDataContainer.py. +# Python module to request point data. Split out of PointDataContainer.py. # # -# SOFTWARE HISTORY -# -# Date Ticket# Engineer Description -# ------------ ---------- ----------- -------------------------- -# 05/11/11 njensen Initial Creation. -# 25Apr2012 14688 rferrel Made into an abstract class. +# SOFTWARE HISTORY +# +# Date Ticket# Engineer Description +# ------------ ---------- ----------- -------------------------- +# 05/11/11 njensen Initial Creation. +# 25Apr2012 14688 rferrel Made into an abstract class. +# Sep 14, 2015 4880 njensen Improved __queryNewestRefTime() # # # class PointDataRetrieve(object): - def __init__(self, pluginName, site, parameters, keyId='forecastHr', refTime=None, constraint={}, maxSize=99): + def __init__(self, pluginName, site, parameters, keyId='forecastHr', refTime=None, constraint={}, maxSize=99): """Initializes a python PointDataContainer which wraps the Java PointDataContainer capabilities. @pluginName the name of the type of data, e.g. bufrmos @site the name of the station, e.g. KOMA @@ -45,13 +45,13 @@ class PointDataRetrieve(object): @keyId how to organize views into the point data, defaults to forecastHr @refTime the reference time to request data for, if None will default to the newest time @constraint a dictionary of extra string constraints to narrow the data type returned, - e.g. {'type':'LAMP'} - """ - - self.pluginName = pluginName + e.g. {'type':'LAMP'} + """ + + self.pluginName = pluginName self.site = site self.constraint = constraint - if not refTime: + if not refTime: refTime = self.__queryNewestRefTime() import time if refTime < time.time() - 86400: @@ -67,38 +67,40 @@ class PointDataRetrieve(object): self.__keyId = keyId self._query(parameters, int(maxSize)) - # Abstract method must be implemented by sub-class. + # Abstract method must be implemented by sub-class. def _query(self, parameters, maxSize): raise NoDataException.NoDataException('_query not implemented') def __queryNewestRefTime(self): from com.raytheon.uf.viz.core.catalog import CatalogQuery - from java.util import Arrays - from com.raytheon.uf.common.time import DataTime - results = CatalogQuery.performQuery('dataTime.refTime', self._buildConstraints(None)) - Arrays.sort(results) - if len(results) == 0: - if self.site: + constraints = self._buildConstraints() + results = CatalogQuery.performTimeQuery(constraints, True, None) + nResults = len(results) + if nResults != 1: + if nResults > 1: + # this should be impossible to hit unless CatalogQuery is broken + raise NoDataException.NoDataException("Unable to determine latest time, received multiple times") + elif self.site: raise NoDataException.NoDataException("No data available for site " + self.site) else: raise NoDataException.NoDataException("No data available") - dt = DataTime(results[len(results)-1]) + dt = results[0] return dt.getRefTime().getTime() / 1000 - def _buildConstraints(self, refTime): - from java.util import HashMap - from com.raytheon.uf.common.dataquery.requests import RequestConstraint + def _buildConstraints(self, refTime=None): + from java.util import HashMap + from com.raytheon.uf.common.dataquery.requests import RequestConstraint queryTerms = HashMap() queryTerms.put("pluginName", RequestConstraint(self.pluginName)) if self.site: queryTerms.put("location.stationId", RequestConstraint(self.site)) - if refTime: - from com.raytheon.uf.common.time.util import TimeUtil + if refTime: + from com.raytheon.uf.common.time.util import TimeUtil queryTerms.put('dataTime.refTime', RequestConstraint(TimeUtil.formatToSqlTimestamp(refTime))) if self.constraint: for k in self.constraint.keys(): queryTerms.put(k, RequestConstraint(self.constraint[k])) - return queryTerms + return queryTerms def _organizeData(self, container): import PointDataView