Merge "Omaha #4880 fix AvnFPS to not use strings for dates" into omaha_16.2.1
Former-commit-id: 6f1432da260860214f8e967662e9b5a258c41256
This commit is contained in:
commit
7917735a55
1 changed files with 30 additions and 28 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue