From 54cbf656e93fb375caef703a71481c9f9046d482 Mon Sep 17 00:00:00 2001 From: Roger Ferrel Date: Wed, 3 Apr 2013 07:41:39 -0500 Subject: [PATCH] Issue #1735 ForecastPointDataRetrieve now uses DbQueryRequest to obtain forecast times in asscending order and option to limit times returned. Change reviewer comments. Change-Id: Ida69b63198ffa5c229eedd3abb42c4f5f9e1d00d Former-commit-id: b836dcb6d55dfbdf8e825fb194903d45a83382c8 --- .../cave/etc/aviation/python/LLWSData.py | 24 ++++++---- .../cave/etc/aviation/python/RadLtgData.py | 14 +++--- .../pointdata/ForecastPointDataRetrieve.py | 48 +++++++++++-------- .../dataquery/requests/DbQueryRequest.java | 3 +- 4 files changed, 53 insertions(+), 36 deletions(-) diff --git a/cave/build/static/common/cave/etc/aviation/python/LLWSData.py b/cave/build/static/common/cave/etc/aviation/python/LLWSData.py index fcc5e43533..fb6085871e 100644 --- a/cave/build/static/common/cave/etc/aviation/python/LLWSData.py +++ b/cave/build/static/common/cave/etc/aviation/python/LLWSData.py @@ -1,19 +1,19 @@ ## # This software was developed and / or modified by Raytheon Company, -# pursuant to Contract DG133W-05-CQ-1067 with the US Government. -# -# U.S. EXPORT CONTROLLED TECHNICAL DATA +# pursuant to Contract DG133W-05-CQ-1067 with the US Government. +# +# U.S. EXPORT CONTROLLED TECHNICAL DATA # This software product contains export-restricted data whose # export/transfer/disclosure is restricted by U.S. law. Dissemination # to non-U.S. persons whether in the United States or abroad requires # an export license or other authorization. # -# Contractor Name: Raytheon Company -# Contractor Address: 6825 Pine Street, Suite 340 -# Mail Stop B8 -# Omaha, NE 68106 -# 402.291.0100 -# +# Contractor Name: Raytheon Company +# Contractor Address: 6825 Pine Street, Suite 340 +# Mail Stop B8 +# Omaha, NE 68106 +# 402.291.0100 +# # See the AWIPS II Master Rights File ("Master Rights File.pdf") for # further licensing information. ## @@ -96,6 +96,10 @@ def writeLLWS(ident, data): _Logger.error('Cannot write LLWS file for %s', ident) def retrieve(siteID, info): + from datetime import timedelta + day = timedelta(days=1) + secondsPerDay = day.total_seconds() + msPerSecond = 1000.0 th = LLWSThread.Server(info) t = 0 d = {} @@ -115,7 +119,7 @@ def retrieve(siteID, info): # This may be ok if database is purged frequently. # How far back should it go 1, 6, 12, 24 hours? # acarsRec = LlwsManager.getAcarsRecord(siteID, 0) - refTime = long((time.time() - (24.0*3600.0)) * 1000.0) + refTime = long((time.time() - secondsPerDay) * msPerSecond) acarsRec = LlwsManager.getAcarsRecord(siteID, refTime) if acarsRec: acarsId = siteID[1:] diff --git a/cave/build/static/common/cave/etc/aviation/python/RadLtgData.py b/cave/build/static/common/cave/etc/aviation/python/RadLtgData.py index d65c8d3e71..642a49acba 100644 --- a/cave/build/static/common/cave/etc/aviation/python/RadLtgData.py +++ b/cave/build/static/common/cave/etc/aviation/python/RadLtgData.py @@ -32,6 +32,7 @@ import ForecastPointDataRetrieve, NoDataException # ------------ ---------- ----------- -------------------------- # 09/15/09 njensen Initial Creation. # 26APR2012 14688 rferrel Use ForecastPointDataRetrieve. +# 03APR2013 1735 rferrel Limit retrieval for forecast times to the number used. # # # @@ -39,23 +40,24 @@ import ForecastPointDataRetrieve, NoDataException PARAMETERS = ['tstorm2hr', 'stationId', 'refTime', 'fcstHr'] LOOK_AHEAD = 3 # hours +SEC_PER_HOUR = 60*60 _Logger = logging.getLogger(Avn.CATEGORY) -def retrieve(siteID): - try: - pdc = ForecastPointDataRetrieve.retrieve('bufrmosLAMP', siteID, PARAMETERS) +def retrieve(siteID): + try: + pdc = ForecastPointDataRetrieve.retrieve('bufrmosLAMP', siteID, PARAMETERS, forecastTimesLimit=3) except NoDataException.NoDataException: return None pots = [] try: # assume pdc[0] is 0 hour and not used in the forecast. - vtime = pdc[1]['refTime'] / 1000.0 + LOOK_AHEAD*3600 + vtime = pdc[1]['refTime'] / 1000.0 + LOOK_AHEAD*SEC_PER_HOUR for n in range(1, LOOK_AHEAD): pdv = pdc[n] pots.append(pdv['tstorm2hr']) - data = max([x for x in pots if 0<= x <= 100] + [0]) - return {'from': vtime-LOOK_AHEAD*3600, 'to': vtime, 'prob': min(data, 100)} + data = max([x for x in pots if 0 <= x <= 100] + [0]) + return {'from': vtime-LOOK_AHEAD*SEC_PER_HOUR, 'to': vtime, 'prob': min(data, 100)} except KeyError: return None diff --git a/cave/com.raytheon.viz.pointdata/localization/pointdata/ForecastPointDataRetrieve.py b/cave/com.raytheon.viz.pointdata/localization/pointdata/ForecastPointDataRetrieve.py index 7db469ad23..2bb0718ca9 100644 --- a/cave/com.raytheon.viz.pointdata/localization/pointdata/ForecastPointDataRetrieve.py +++ b/cave/com.raytheon.viz.pointdata/localization/pointdata/ForecastPointDataRetrieve.py @@ -31,34 +31,47 @@ import PointDataView, PointDataContainer, NoDataException, PointDataRetrieve # Date Ticket# Engineer Description # ------------ ---------- ----------- -------------------------- # 25Apr2012 14688 rferrel Initial Creation. -# +# 03Apr2013 1735 rferrel Use DbQueryRequest to get forecast times +# and added option to limit number returned. # # class ForecastPointDataRetrieve(PointDataRetrieve.PointDataRetrieve): - def __init__(self, pluginName, site, parameters, keyId='forecastHr', refTime=None, constraint={}, maxSize=99): - super(ForecastPointDataRetrieve, self).__init__(pluginName, site, parameters, keyId, refTime, constraint, maxSize) + def __init__(self, pluginName, site, parameters, keyId='forecastHr', refTime=None, constraint={}, maxSize=99, forecastTimesLimit=-999): + self.forecastTimesLimit = forecastTimesLimit + super(ForecastPointDataRetrieve, self).__init__(pluginName, site, parameters, keyId, refTime, constraint, maxSize) def _query(self, parameters, maxSize): - times = self.__queryForecastTimes() - self.__javaPdc = self.__requestForecastData(times, parameters) + fctTimes = self.__queryForecastTimes() + self.__javaPdc = self.__requestForecastData(fctTimes, parameters) pdvDict = self._organizeData(self.__javaPdc) - self.pdc = PointDataContainer.PointDataContainer(pdvDict, self.__javaPdc, self.refTime) + self.pdc = PointDataContainer.PointDataContainer(pdvDict, self.__javaPdc, self.refTime) - def __queryForecastTimes(self): - from com.raytheon.uf.viz.core.catalog import CatalogQuery - return CatalogQuery.performQuery('dataTime.fcstTime', self._buildConstraints(self.refTime)) + def __queryForecastTimes(self): + from com.raytheon.uf.common.dataquery.requests import DbQueryRequest + from com.raytheon.uf.viz.core.requests import ThriftClient + from java.lang import Integer + request = DbQueryRequest() + request.setConstraints(self._buildConstraints(self.refTime)) + request.addRequestField('dataTime.fcstTime') + request.setOrderByField('dataTime.fcstTime') + request.setDistinct(True) + iForecastTimesLimit = Integer(self.forecastTimesLimit) + if (self.forecastTimesLimit > 0) : + request.setLimit(iForecastTimesLimit) + return ThriftClient.sendRequest(request).getFieldObjects('dataTime.fcstTime', iForecastTimesLimit.getClass()) def __requestForecastData(self, availableHours, parameters): from com.raytheon.viz.pointdata import PointDataRequest from com.raytheon.uf.common.time import DataTime from java.lang import String import jep - dts = jep.jarray(len(availableHours), DataTime) - for i in range(len(availableHours)): - dts[i] = DataTime(self.refTime, int(availableHours[i])) - constraints = self._buildConstraints(None) #times are explicitly set so we don't need to constrain those + dtsLen = len(availableHours) + dts = jep.jarray(dtsLen, DataTime) + for i in range(dtsLen): + dts[i] = DataTime(self.refTime, availableHours[i].intValue()) + constraints = self._buildConstraints(None) #fctTimes are explicitly set so we don't need to constrain those params = jep.jarray(len(parameters), String) for i in range(len(parameters)): params[i] = String(parameters[i]) @@ -69,11 +82,8 @@ class ForecastPointDataRetrieve(PointDataRetrieve.PointDataRetrieve): stations = None return PointDataRequest.requestPointData(dts, self.pluginName, params, stations, - constraints) + constraints) -def retrieve(pluginName, site, parameters, keyId='forecastHr', refTime=None, constraint={}, maxSize=99): - ret = ForecastPointDataRetrieve(pluginName, site, parameters, keyId, refTime, constraint, maxSize) +def retrieve(pluginName, site, parameters, keyId='forecastHr', refTime=None, constraint={}, maxSize=99, forecastTimesLimit=-999): + ret = ForecastPointDataRetrieve(pluginName, site, parameters, keyId, refTime, constraint, maxSize, forecastTimesLimit) return ret.pdc - - - \ No newline at end of file diff --git a/edexOsgi/com.raytheon.uf.common.dataquery/src/com/raytheon/uf/common/dataquery/requests/DbQueryRequest.java b/edexOsgi/com.raytheon.uf.common.dataquery/src/com/raytheon/uf/common/dataquery/requests/DbQueryRequest.java index 702f03c0b8..c0281724f8 100644 --- a/edexOsgi/com.raytheon.uf.common.dataquery/src/com/raytheon/uf/common/dataquery/requests/DbQueryRequest.java +++ b/edexOsgi/com.raytheon.uf.common.dataquery/src/com/raytheon/uf/common/dataquery/requests/DbQueryRequest.java @@ -302,7 +302,8 @@ public class DbQueryRequest implements IServerRequest { + ", orderBy=" + (orderBy == null ? "null" : String.format( "[field=%s, mode=%s]", orderBy.field, - orderBy.mode.toString())) + "]"; + orderBy.mode.toString())) + + (limit == null ? "" : ", limit=" + limit) + "]"; } }