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
|
import PointDataView, PointDataContainer, NoDataException
|
||||||
|
|
||||||
#
|
#
|
||||||
# Python module to request point data. Split out of
|
# Python module to request point data. Split out of PointDataContainer.py.
|
||||||
# PointDataContainer.py.
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# SOFTWARE HISTORY
|
# SOFTWARE HISTORY
|
||||||
#
|
#
|
||||||
# Date Ticket# Engineer Description
|
# Date Ticket# Engineer Description
|
||||||
# ------------ ---------- ----------- --------------------------
|
# ------------ ---------- ----------- --------------------------
|
||||||
# 05/11/11 njensen Initial Creation.
|
# 05/11/11 njensen Initial Creation.
|
||||||
# 25Apr2012 14688 rferrel Made into an abstract class.
|
# 25Apr2012 14688 rferrel Made into an abstract class.
|
||||||
|
# Sep 14, 2015 4880 njensen Improved __queryNewestRefTime()
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
|
|
||||||
class PointDataRetrieve(object):
|
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.
|
"""Initializes a python PointDataContainer which wraps the Java PointDataContainer capabilities.
|
||||||
@pluginName the name of the type of data, e.g. bufrmos
|
@pluginName the name of the type of data, e.g. bufrmos
|
||||||
@site the name of the station, e.g. KOMA
|
@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
|
@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
|
@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,
|
@constraint a dictionary of extra string constraints to narrow the data type returned,
|
||||||
e.g. {'type':'LAMP'}
|
e.g. {'type':'LAMP'}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
self.pluginName = pluginName
|
self.pluginName = pluginName
|
||||||
self.site = site
|
self.site = site
|
||||||
self.constraint = constraint
|
self.constraint = constraint
|
||||||
if not refTime:
|
if not refTime:
|
||||||
refTime = self.__queryNewestRefTime()
|
refTime = self.__queryNewestRefTime()
|
||||||
import time
|
import time
|
||||||
if refTime < time.time() - 86400:
|
if refTime < time.time() - 86400:
|
||||||
|
@ -67,38 +67,40 @@ class PointDataRetrieve(object):
|
||||||
self.__keyId = keyId
|
self.__keyId = keyId
|
||||||
self._query(parameters, int(maxSize))
|
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):
|
def _query(self, parameters, maxSize):
|
||||||
raise NoDataException.NoDataException('_query not implemented')
|
raise NoDataException.NoDataException('_query not implemented')
|
||||||
|
|
||||||
def __queryNewestRefTime(self):
|
def __queryNewestRefTime(self):
|
||||||
from com.raytheon.uf.viz.core.catalog import CatalogQuery
|
from com.raytheon.uf.viz.core.catalog import CatalogQuery
|
||||||
from java.util import Arrays
|
constraints = self._buildConstraints()
|
||||||
from com.raytheon.uf.common.time import DataTime
|
results = CatalogQuery.performTimeQuery(constraints, True, None)
|
||||||
results = CatalogQuery.performQuery('dataTime.refTime', self._buildConstraints(None))
|
nResults = len(results)
|
||||||
Arrays.sort(results)
|
if nResults != 1:
|
||||||
if len(results) == 0:
|
if nResults > 1:
|
||||||
if self.site:
|
# 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)
|
raise NoDataException.NoDataException("No data available for site " + self.site)
|
||||||
else:
|
else:
|
||||||
raise NoDataException.NoDataException("No data available")
|
raise NoDataException.NoDataException("No data available")
|
||||||
dt = DataTime(results[len(results)-1])
|
dt = results[0]
|
||||||
return dt.getRefTime().getTime() / 1000
|
return dt.getRefTime().getTime() / 1000
|
||||||
|
|
||||||
def _buildConstraints(self, refTime):
|
def _buildConstraints(self, refTime=None):
|
||||||
from java.util import HashMap
|
from java.util import HashMap
|
||||||
from com.raytheon.uf.common.dataquery.requests import RequestConstraint
|
from com.raytheon.uf.common.dataquery.requests import RequestConstraint
|
||||||
queryTerms = HashMap()
|
queryTerms = HashMap()
|
||||||
queryTerms.put("pluginName", RequestConstraint(self.pluginName))
|
queryTerms.put("pluginName", RequestConstraint(self.pluginName))
|
||||||
if self.site:
|
if self.site:
|
||||||
queryTerms.put("location.stationId", RequestConstraint(self.site))
|
queryTerms.put("location.stationId", RequestConstraint(self.site))
|
||||||
if refTime:
|
if refTime:
|
||||||
from com.raytheon.uf.common.time.util import TimeUtil
|
from com.raytheon.uf.common.time.util import TimeUtil
|
||||||
queryTerms.put('dataTime.refTime', RequestConstraint(TimeUtil.formatToSqlTimestamp(refTime)))
|
queryTerms.put('dataTime.refTime', RequestConstraint(TimeUtil.formatToSqlTimestamp(refTime)))
|
||||||
if self.constraint:
|
if self.constraint:
|
||||||
for k in self.constraint.keys():
|
for k in self.constraint.keys():
|
||||||
queryTerms.put(k, RequestConstraint(self.constraint[k]))
|
queryTerms.put(k, RequestConstraint(self.constraint[k]))
|
||||||
return queryTerms
|
return queryTerms
|
||||||
|
|
||||||
def _organizeData(self, container):
|
def _organizeData(self, container):
|
||||||
import PointDataView
|
import PointDataView
|
||||||
|
|
Loading…
Add table
Reference in a new issue