def setTime(self, aDattim): convert = GempakConvert() name = "dataTime" operand = "between" aw2Time = convert.dattimToDbtime(aDattim) timeRange = convert.setTimeRange(aw2Time) self.query.addParameter(name, timeRange, operand)
def setTime(self, aDattim): convert = GempakConvert() name = "dataTime" operand = "between" aw2Time = convert.dattimToDbtime(aDattim) timeRange = convert.setTimeRange(aw2Time) self.query.addParameter(name, timeRange, operand)
def __makeResponse(self): from com.raytheon.edex.uengine.tasks.decode import FileIn from gov.noaa.nws.ncep.edex.uengine.output import GridOut response = ArrayList() size = self.queryResults.size() for i in range(size): currentQuery = self.queryResults.get(i) # # grid coverage # if self.pluginName == 'grib': gridNavInfo = GempakConvert.getGridNavigationContent( currentQuery.getSpatialObject()).split(";") elif self.pluginName == 'ncgrib': gridNavInfo = GempakConvert.getNcgridNavigationContent( currentQuery.getSpatialObject()).split(";") nx = gridNavInfo[1] ny = gridNavInfo[2] # # Call FileIn constructor # fileIn = FileIn(self.plugin, currentQuery) # # Call the execute method, getting back the data record # record = fileIn.execute() self.nxStr = "%s" % nx self.nyStr = "%s" % ny fileOut = GridOut(record.getDataObject(), self.format, self.nxStr, self.nyStr) # # Execute method of FileOut class stores the data # in a file in uEngineProducts directory with the extension # contained in the string self.format # writeFile = fileOut.execute() # # Separate the file name from the complete path and store in content # content = ( "%s" % writeFile).split("/")[len(("%s" % writeFile).split("/")) - 1] # # # import socket hostname = socket.gethostbyaddr(socket.gethostname())[2][0] # # Return content wrapped in a generic XML message # response.add(ResponseMessageGeneric(hostname + "|" + content)) return response
def __getDbTime(self, aDattim): refTime = aDattim.upper().split("F")[0] fcstTime = "%s" % (int(aDattim.upper().split("F")[1]) * 3600) convert = GempakConvert() refTime = convert.dattimToDbtime(refTime) print "refTime=", refTime print "fcstTime=", fcstTime return refTime, fcstTime
def __getDbTime (self, aDattim): refTime = aDattim.upper().split("F")[0] fcstTime = "%s" % (int(aDattim.upper().split("F")[1]) * 3600) convert = GempakConvert() refTime = convert.dattimToDbtime(refTime) print "refTime=", refTime print "fcstTime=", fcstTime return refTime, fcstTime
def __init__(self): BaseRequest.BaseRequest.__init__(self, "atcf") self.isTechniqueSet = False self.time = None self.StartTime = None self.EndTime = None self.isTimeList = False self.AllTimesList = [] self.TimesList = [] self.Convert = GempakConvert()
def __makeResponse(self): from com.raytheon.edex.uengine.tasks.decode import FileIn from gov.noaa.nws.ncep.edex.uengine.output import GridOut response = ArrayList() size = self.queryResults.size() for i in range(size): currentQuery = self.queryResults.get(i) # # grid coverage # if self.pluginName == 'grib': gridNavInfo = GempakConvert.getGridNavigationContent(currentQuery.getSpatialObject()).split(";") elif self.pluginName == 'ncgrib': gridNavInfo = GempakConvert.getNcgridNavigationContent(currentQuery.getSpatialObject()).split(";") nx = gridNavInfo[1] ny = gridNavInfo[2] # # Call FileIn constructor # fileIn = FileIn(self.plugin, currentQuery) # # Call the execute method, getting back the data record # record = fileIn.execute() self.nxStr = "%s" % nx self.nyStr = "%s" % ny fileOut = GridOut(record.getDataObject(), self.format, self.nxStr, self.nyStr) # # Execute method of FileOut class stores the data # in a file in uEngineProducts directory with the extension # contained in the string self.format # writeFile = fileOut.execute() # # Separate the file name from the complete path and store in content # content = ("%s" % writeFile).split("/")[len(("%s" % writeFile).split("/") ) - 1] # # # import socket hostname = socket.gethostbyaddr(socket.gethostname())[2][0] # # Return content wrapped in a generic XML message # response.add(ResponseMessageGeneric(hostname+"|"+content)) return response
class GempakGridCycleQuery(): def __init__(self, aPlugin): self.plugin = aPlugin self.queryResults = ArrayList() self.GSQ = GempakSqlQuery.GempakSqlQuery() self.GSQ.setReturnText() self.convert = GempakConvert() # # Set parameters of the metadata catalog query # def setParameters(self, aParms): parms = aParms.split("|") self.model = parms[0].upper() self.cycle = self.convert.dattimToDbtime(parms[1].upper()).replace( ' ', '_') #print "model=", self.model #print "cycle=", self.cycle # # Generates a list of responses in XML format # def makeResponse(self): retStr = self.convert.dbtimeToDattim((self.queryResult).split("/")[2]) #print "returning time=", retStr return ResponseMessageGeneric(retStr) # # Executes the query and calls appropriate response functions # def execute(self): # # construct the SQL query to execute # myQuery = "SELECT datauri FROM " + self.plugin + " WHERE datauri LIKE '%" + \ self.cycle + "%' AND datauri ~* '/" + self.model + "/' LIMIT 1" #print "myQuery:", myQuery # # set the SQL query # self.GSQ.setQuery(myQuery) self.queryResult = self.GSQ.execute() #print "self.queryResult=", self.queryResult # # process the results of the query # if self.queryResult is None: return self.makeNullResponse("Query returned no results") else: return self.makeResponse()
def setGridIdParms(self, aGridName, *parms): for ii in range(len(parms)): if ii == 0: #print "setting time to", parms[0] convert = GempakConvert() self.query.addParameter("dataTime", convert.dattimToDbtime(parms[0])) elif ii == 1: #print "setting eventName to", parms[1] self.query.addParameter("modelInfo.eventName", parms[1]) self.gridName= aGridName
def __makeResponse(self): from com.raytheon.edex.uengine.tasks.decode import FileIn response = ArrayList() size = self.queryResults.size() for i in range(size): currentQuery = self.queryResults.get(i) if self.pluginName == 'grib': content = GempakConvert.getGridNavigationContent(currentQuery.getSpatialObject()) elif self.pluginName == 'ncgrib': content = GempakConvert.getNcgridNavigationContent(currentQuery.getSpatialObject()) response.add(ResponseMessageGeneric(content)) return response
class GempakGridCycleQuery(): def __init__(self, aPlugin): self.plugin = aPlugin self.queryResults = ArrayList() self.GSQ = GempakSqlQuery.GempakSqlQuery() self.GSQ.setReturnText() self.convert = GempakConvert() # # Set parameters of the metadata catalog query # def setParameters (self, aParms): parms = aParms.split("|") self.model=parms[0].upper() self.cycle = self.convert.dattimToDbtime(parms[1].upper()).replace (' ', '_') #print "model=", self.model #print "cycle=", self.cycle # # Generates a list of responses in XML format # def makeResponse(self): retStr = self.convert.dbtimeToDattim((self.queryResult).split("/")[2]) #print "returning time=", retStr return ResponseMessageGeneric(retStr) # # Executes the query and calls appropriate response functions # def execute(self): # # construct the SQL query to execute # myQuery = "SELECT datauri FROM " + self.plugin + " WHERE datauri LIKE '%" + \ self.cycle + "%' AND datauri ~* '/" + self.model + "/' LIMIT 1" #print "myQuery:", myQuery # # set the SQL query # self.GSQ.setQuery(myQuery) self.queryResult = self.GSQ.execute() #print "self.queryResult=", self.queryResult # # process the results of the query # if self.queryResult is None: return self.makeNullResponse("Query returned no results") else: return self.makeResponse()
def __makeResponse(self): response = ArrayList() size = self.queryResults.size() for i in range(size): currentQuery = self.queryResults.get(i) content = GempakConvert.getSatHdrContent(currentQuery.getSpatialObject()) content = content + ";" + currentQuery.getCreatingEntity() + ";" + currentQuery.getPhysicalElement() aDbTime = "%s" % currentQuery.getDataTime() aDattim = GempakConvert.dbtimeToSatDattim(aDbTime) content = content + ";" + aDattim response.add(ResponseMessageGeneric(content)) return response
def __makeResponse(self): response = ArrayList() size = self.queryResults.size() for i in range(size): currentQuery = self.queryResults.get(i) content = GempakConvert.getSatHdrContent(currentQuery.getSpatialObject()) content = content + ";" + currentQuery.getCreatingEntity() + ";" + currentQuery.getPhysicalElement() aDbTime = "%s" % currentQuery.getDataTime() aDattim = GempakConvert.dbtimeToSatDattim(aDbTime) content = content + ";" + aDattim response.add(ResponseMessageGeneric(content)) return response
def __makeResponse(self): response = ArrayList() size = self.queryResults.size() for i in range(size): currentQuery = self.queryResults.get(i) content = GempakConvert.getMcidasHdrContent(currentQuery.getSpatialObject()) content = content + ";" + "%s" % currentQuery.getSatelliteId() + \ ";" + "%s" % currentQuery.getImageTypeNumber() + \ ";" + "%s" % currentQuery.getCalType() aDbTime = "%s" % currentQuery.getDataTime() aDattim = GempakConvert.dbtimeToSatDattim(aDbTime) content = content + ";" + aDattim response.add(ResponseMessageGeneric(content)) return response
def __init__(self): BaseRequest.BaseRequest.__init__(self, "atcf") self.isTechniqueSet = False self.time = None self.StartTime = None self.EndTime = None self.isTimeList= False self.AllTimesList = [] self.TimesList = [] self.Convert = GempakConvert()
def makeResponse(self): convert = GempakConvert(self.pluginName, self.queryResults) convert2 = GempakConvert() convertSt = convert.getStrings() returnStr = '' for s in convertSt: retTime = convert2.dbtimeToDattim(s) # # add only unique times # if returnStr.find(retTime) == -1: returnStr=returnStr+retTime+'|' # # sort times before returning # if self.returnText: return "|".join(sorted(returnStr[0:-1].split("|"))) else: return ResponseMessageGeneric("|".join(sorted(returnStr[0:-1].split("|"))))
def __makeResponse(self): from com.raytheon.edex.uengine.tasks.decode import FileIn response = ArrayList() size = self.queryResults.size() for i in range(size): currentQuery = self.queryResults.get(i) aLat = "%s" % currentQuery.getLatitude() aLon = "%s" % currentQuery.getLongitude() aProd = "%s" % currentQuery.getProductCode() aNx = "%s" % currentQuery.getNx() aNy = "%s" % currentQuery.getNy() aDbTime = "%s" % currentQuery.getDataTime() aDattim = GempakConvert.dbtimeToSatDattim(aDbTime) content = aLat + ";" + aLon + ";" + aProd + ";" + aNx + ";" + aNy + ";" + aDattim fileIn = FileIn(self.plugin, currentQuery) records = fileIn.retrieveGroup() convert = GempakConvert() thresholds = convert.getRadarThresholds(currentQuery, records) rpgIdDec = "10000" content = content + ";" + thresholds[0:-1] + ";" + rpgIdDec response.add(ResponseMessageGeneric(content)) return response
def __makeResponse(self): from com.raytheon.edex.uengine.tasks.decode import FileIn response = ArrayList() size = self.queryResults.size() for i in range(size): currentQuery = self.queryResults.get(i) aLat = "%s" % currentQuery.getLatitude() aLon = "%s" % currentQuery.getLongitude() aProd = "%s" % currentQuery.getProductCode() aNx = "%s" % currentQuery.getNx() aNy = "%s" % currentQuery.getNy() aDbTime = "%s" % currentQuery.getDataTime() aDattim = GempakConvert.dbtimeToSatDattim(aDbTime) content = aLat + ";" + aLon + ";" + aProd + ";" + aNx + ";" + aNy + ";" + aDattim fileIn = FileIn(self.plugin, currentQuery) records = fileIn.retrieveGroup() convert = GempakConvert(); thresholds = convert.getRadarThresholds(currentQuery, records); rpgIdDec = "10000" content = content + ";"+ thresholds[0:-1] + ";" + rpgIdDec response.add(ResponseMessageGeneric(content)) return response
def __makeResponse(self): from com.raytheon.edex.uengine.tasks.decode import FileIn response = ArrayList() size = self.queryResults.size() for i in range(size): currentQuery = self.queryResults.get(i) aLat = "%s" % currentQuery.getLatitude() aLon = "%s" % currentQuery.getLongitude() aProd = "%s" % currentQuery.getProductCode() aAngle = "%s" % currentQuery.getTrueElevationAngle() aNumBins = "%s" % currentQuery.getNumBins() aFormat = "%s" % currentQuery.getFormat() aDbTime = "%s" % currentQuery.getDataTime() aDattim = GempakConvert.dbtimeToSatDattim(aDbTime) content = aLat + ";" + aLon + ";" + aProd + ";" + aAngle + ";" + aNumBins + ";" + aFormat + ";" + aDattim fileIn = FileIn(self.plugin, currentQuery) records = fileIn.retrieveGroup() convert = GempakConvert(); thresholds = convert.getRadarThresholds(currentQuery, records); rpgIdDec = currentQuery.getSpatialObject().getRpgIdDec() content = content + ";"+ thresholds[0:-1] + ";" + rpgIdDec response.add(ResponseMessageGeneric(content)) return response
def makeResponse(self): convert = GempakConvert(self.pluginName, self.queryResults) convert2 = GempakConvert() convertSt = convert.getStrings() returnStr = '' for s in convertSt: retTime = convert2.dbtimeToDattim(s) # # add only unique times # if returnStr.find(retTime) == -1: returnStr = returnStr + retTime + '|' # # sort times before returning # if self.returnText: return "|".join(sorted(returnStr[0:-1].split("|"))) else: return ResponseMessageGeneric("|".join( sorted(returnStr[0:-1].split("|"))))
def __getDbTime (self, aDattim): if self.pluginName == 'grib' or self.pluginName == 'ncgrib': convert = GempakConvert() return convert.dattimToDbtime(aDattim) else: return None
class AtcfTrackRequest(BaseRequest.BaseRequest): def __init__(self): BaseRequest.BaseRequest.__init__(self, "atcf") self.isTechniqueSet = False self.time = None self.StartTime = None self.EndTime = None self.isTimeList = False self.AllTimesList = [] self.TimesList = [] self.Convert = GempakConvert() def setTime(self, aTime=None): self.time = aTime def setStartTime(self, aTime=None): if aTime: self.StartTime = aTime else: # set StartTime to the First Available Time self.StartTime = self.__getFirstTime() def setEndTime(self, aTime=None): if aTime: self.EndTime = aTime else: # set StartTime to the Last Available Time self.EndTime = self.__getLastTime() def setTechnique(self, aTechnique): self.technique = aTechnique self.isTechniqueSet = True def execute(self): if self.time: self.query.addParameter("dataTime", self.time) else: if not self.StartTime: self.StartTime = self.__getFirstTime() if not self.EndTime: self.EndTime = self.__getLastTime() if self.StartTime and self.EndTime: self.timeRange = self.StartTime + "--" + self.EndTime self.query.addParameter("dataTime", self.timeRange, "between") else: return self.__makeNullResponse("Could not set the time range") # get the results from the database self.queryResults = self.query.execute() if self.queryResults is None or self.queryResults.size() == 0: return self.__makeNullResponse() else: # process the results return self.__makeResponse() def __getFirstTime(self): # check if the list of available times has been calculated if self.isTimeList: return self.Convert.dattimToDbtime(self.AllTimesList[0]) else: # get the list of times and return the earliest available time self.__getTimeList() return self.Convert.dattimToDbtime(self.AllTimesList[0]) def __getLastTime(self): # check if the list of available times has been calculated if self.isTimeList: return self.Convert.dattimToDbtime( self.AllTimesList[len(self.AllTimesList) - 1]) else: # get the list of times and return the last available time self.__getTimeList() return self.Convert.dattimToDbtime( self.AllTimesList[len(self.AllTimesList) - 1]) def __getTimePlus(self, aTime, aPlus="168"): return self.Convert.addHours(aTime, aPlus) # def __createTimes(self): # if self.time: # self.TimesList.append(self.time) # else: # startIndex = self.AllTimesList.index(self.StartTime) # endIndex = self.AllTimesList.index(self.EndTime) # self.TimesList = self.AllTimesList[startIndex:endIndex] def __getTimeList(self): import GempakCatalogTimeQuery tq = GempakCatalogTimeQuery.GempakCatalogTimeQuery("atcf") tq.setReturnText() self.AllTimesList = tq.execute().split("|") self.isTimeList = True def __getDictionaries(self): import GempakSqlQuery # list of time cyclone ID tuples: # eg [('2010-08-28 06:00:00.0', 'EP9'), ('2010-08-28 12:00:00.0', 'EP8')] timeIdTupleList = [] # timeIdTqDict - is the key-value dictionary of time-Id tuple Technique List dictionary # each time has a corresponding dictionary of ID-Technique # eg: {('2010-08-28 06:00:00.0','AL8'):['AEMI', 'AEMN', 'AP01', 'AP02'], ('2010-08-28 12:00:00.0','AL9'):['AP11', 'AP14', 'AP18']} timeIdTqDict = {} # idNumberDict - is the key-value dictionary of cycloneID-basin, cycloneNumb tuple pairs # each cycloneId has a corresponding basin-cycloneNumb tuple # eg: {'AL8': ('AL', '8'), 'AL9': ('AL', '9')} idNumberDict = {} for ii in range(self.queryResults.size()): currentRecord = self.queryResults.get(ii) # get the time recordTime = str(currentRecord.getDataTime()) # get basin basin = str(currentRecord.getBasin()) # get cyclone number cycloneNumb = str(currentRecord.getCycloneNum()) # construct cyclone ID # eg EP9 cycloneId = basin + cycloneNumb # construct time - cyclone ID tuple # eg ('2010-08-21 06:00:00.0', 'EP9') timeIdTuple = (recordTime, cycloneId) # check time - cyclone ID tuple old or new if timeIdTuple in timeIdTupleList: # existing time - cyclone ID tuple - do not add to list pass else: timeIdTupleList.append(timeIdTuple) # add the basin,cycloneNumb tuple as value to the idNumberDict dictionary # for the key cycloneId, if has not been added already if (basin, cycloneNumb) in idNumberDict.values(): pass else: idNumberDict[cycloneId] = (basin, cycloneNumb) techniqueList = [] # check if the request is for a single technique if self.isTechniqueSet: techniqueList.append(self.technique) else: # perform the db query for the records with that cyclone ID techniqueQuery = GempakSqlQuery.GempakSqlQuery() # set the return type to text(string) # not a ResponseMessageGEneric object techniqueQuery.setReturnText() # set the separator techniqueQuery.setSeparator("|") # set the query text techniqueQueryText = "SELECT DISTINCT technique FROM atcf WHERE " + \ "basin ='" + idNumberDict[cycloneId][0] + "' AND " + \ "cyclonenum ='" + idNumberDict[cycloneId][1] + "' AND " + \ "reftime='" + recordTime + "'" techniqueQuery.setQuery(techniqueQueryText) # execute the query techniqueQueryResults = techniqueQuery.execute() # create a list of techniques techniqueList = techniqueQueryResults.split("|") # add technique as value to the to the time,cyclone ID - technique dictionary timeIdTqDict[timeIdTuple] = techniqueList return idNumberDict, timeIdTqDict def __makeResponse(self): from gov.noaa.nws.ncep.edex.uengine.tasks.atcf import AtcfCyclone, AtcfTrack response = ArrayList() idNumberDict, timeIdTqDict = self.__getDictionaries() # traverse the time,cyclone ID - technique dictionary to obtain AtcfRecords and # construct AtcfCyclone objects for key, value in timeIdTqDict.items(): currentTime = key[0] cycId = key[1] techList = value aBasin = idNumberDict[cycId][0] aCycloneNumb = idNumberDict[cycId][1] # create new AtcfCyclone object aCyclone = AtcfCyclone(cycId) for techniqueName in techList: bsResults = None # CARQ case if techniqueName == "CARQ": # first we need to create track for the past BaseRequest.BaseRequest.__init__(self, "atcf") self.query.addParameter("dataTime", currentTime) self.query.addParameter("basin", aBasin) self.query.addParameter("cycloneNum", aCycloneNumb) self.query.addParameter("technique", techniqueName) self.query.addParameter("radWind", "34") self.query.addParameter("fcstHour", "0", "<") order = True self.query.setSortBy("fcstHour", order) bsResultsPast = self.query.execute() bsResults = bsResultsPast # second we need to create track for the future BaseRequest.BaseRequest.__init__(self, "atcf") timeRange = currentTime + "--" + self.__getTimePlus( currentTime) self.query.addParameter("dataTime", timeRange, "between") self.query.addParameter("basin", aBasin) self.query.addParameter("cycloneNum", aCycloneNumb) self.query.addParameter("technique", techniqueName) self.query.addParameter("radWind", "34") self.query.addParameter("fcstHour", "0") order = True self.query.setSortBy("dataTime", order) bsResultsFuture = self.query.execute() count = 0 for ii in range(bsResultsFuture.size()): recordToChange = bsResultsFuture.get(ii) recordToChange.setFcstHour(ii * 6) bsResults.add(recordToChange) # non-CARQ case else: BaseRequest.BaseRequest.__init__(self, "atcf") self.query.addParameter("dataTime", currentTime) self.query.addParameter("basin", aBasin) self.query.addParameter("cycloneNum", aCycloneNumb) self.query.addParameter("technique", techniqueName) order = True self.query.setSortBy("fcstHour", order) bsResults = self.query.execute() if bsResults is None or bsResults.size() == 0: pass else: # create new AtcfTrack object aTrack = AtcfTrack(techniqueName, bsResults) # add AtcfTrack object to AtcfCyclone aCyclone.addTrack(aTrack) # add AtcfCyclone object to the response ArrayList response.add(ResponseMessageGeneric(aCyclone)) return response # # Returns a string with a response message # def __makeNullResponse(self, aMessage="Database Query returned no results"): return ResponseMessageGeneric(aMessage)
def setGdattim(self, aDbTime): convert = GempakConvert() aGdattim = convert.dbtimeToDattim(aDbTime.replace('_', ' ')) #print aGdattim self.Dgdriv.setGdattim (aGdattim)
def __init__(self, aPlugin): self.plugin = aPlugin self.queryResults = ArrayList() self.GSQ = GempakSqlQuery.GempakSqlQuery() self.GSQ.setReturnText() self.convert = GempakConvert()
def setGdattim(self, aDbTime): convert = GempakConvert() aGdattim = convert.dbtimeToDattim(aDbTime.replace('_', ' ')) #print aGdattim self.Dgdriv.setGdattim(aGdattim)
def __init__(self, aPlugin): self.plugin = aPlugin self.queryResults = ArrayList() self.GSQ = GempakSqlQuery.GempakSqlQuery() self.GSQ.setReturnText() self.convert = GempakConvert()
class AtcfTrackRequest(BaseRequest.BaseRequest): def __init__(self): BaseRequest.BaseRequest.__init__(self, "atcf") self.isTechniqueSet = False self.time = None self.StartTime = None self.EndTime = None self.isTimeList= False self.AllTimesList = [] self.TimesList = [] self.Convert = GempakConvert() def setTime(self, aTime=None): self.time = aTime def setStartTime(self, aTime=None): if aTime : self.StartTime = aTime else: # set StartTime to the First Available Time self.StartTime = self.__getFirstTime() def setEndTime(self, aTime=None): if aTime : self.EndTime = aTime else: # set StartTime to the Last Available Time self.EndTime = self.__getLastTime() def setTechnique(self, aTechnique): self.technique = aTechnique self.isTechniqueSet = True def execute(self): if self.time: self.query.addParameter("dataTime", self.time) else: if not self.StartTime: self.StartTime = self.__getFirstTime() if not self.EndTime: self.EndTime = self.__getLastTime() if self.StartTime and self.EndTime: self.timeRange = self.StartTime + "--" + self.EndTime self.query.addParameter("dataTime", self.timeRange, "between") else: return self.__makeNullResponse("Could not set the time range") # get the results from the database self.queryResults = self.query.execute() if self.queryResults is None or self.queryResults.size() == 0: return self.__makeNullResponse() else: # process the results return self.__makeResponse() def __getFirstTime(self): # check if the list of available times has been calculated if self.isTimeList: return self.Convert.dattimToDbtime(self.AllTimesList[0]) else: # get the list of times and return the earliest available time self.__getTimeList() return self.Convert.dattimToDbtime(self.AllTimesList[0]) def __getLastTime(self): # check if the list of available times has been calculated if self.isTimeList: return self.Convert.dattimToDbtime(self.AllTimesList[len(self.AllTimesList) -1]) else: # get the list of times and return the last available time self.__getTimeList() return self.Convert.dattimToDbtime(self.AllTimesList[len(self.AllTimesList) -1]) def __getTimePlus(self, aTime, aPlus="168"): return self.Convert.addHours(aTime, aPlus) # def __createTimes(self): # if self.time: # self.TimesList.append(self.time) # else: # startIndex = self.AllTimesList.index(self.StartTime) # endIndex = self.AllTimesList.index(self.EndTime) # self.TimesList = self.AllTimesList[startIndex:endIndex] def __getTimeList(self): import GempakCatalogTimeQuery tq = GempakCatalogTimeQuery.GempakCatalogTimeQuery("atcf") tq.setReturnText() self.AllTimesList = tq.execute().split("|") self.isTimeList =True def __getDictionaries(self): import GempakSqlQuery # list of time cyclone ID tuples: # eg [('2010-08-28 06:00:00.0', 'EP9'), ('2010-08-28 12:00:00.0', 'EP8')] timeIdTupleList = [] # timeIdTqDict - is the key-value dictionary of time-Id tuple Technique List dictionary # each time has a corresponding dictionary of ID-Technique # eg: {('2010-08-28 06:00:00.0','AL8'):['AEMI', 'AEMN', 'AP01', 'AP02'], ('2010-08-28 12:00:00.0','AL9'):['AP11', 'AP14', 'AP18']} timeIdTqDict = {} # idNumberDict - is the key-value dictionary of cycloneID-basin, cycloneNumb tuple pairs # each cycloneId has a corresponding basin-cycloneNumb tuple # eg: {'AL8': ('AL', '8'), 'AL9': ('AL', '9')} idNumberDict = {} for ii in range(self.queryResults.size()): currentRecord = self.queryResults.get(ii) # get the time recordTime = str(currentRecord.getDataTime()) # get basin basin = str(currentRecord.getBasin()) # get cyclone number cycloneNumb = str(currentRecord.getCycloneNum()) # construct cyclone ID # eg EP9 cycloneId = basin + cycloneNumb # construct time - cyclone ID tuple # eg ('2010-08-21 06:00:00.0', 'EP9') timeIdTuple = (recordTime, cycloneId) # check time - cyclone ID tuple old or new if timeIdTuple in timeIdTupleList: # existing time - cyclone ID tuple - do not add to list pass else: timeIdTupleList.append(timeIdTuple) # add the basin,cycloneNumb tuple as value to the idNumberDict dictionary # for the key cycloneId, if has not been added already if (basin, cycloneNumb) in idNumberDict.values(): pass else: idNumberDict[cycloneId] = (basin, cycloneNumb) techniqueList = [] # check if the request is for a single technique if self.isTechniqueSet: techniqueList.append(self.technique) else: # perform the db query for the records with that cyclone ID techniqueQuery = GempakSqlQuery.GempakSqlQuery() # set the return type to text(string) # not a ResponseMessageGEneric object techniqueQuery.setReturnText() # set the separator techniqueQuery.setSeparator("|") # set the query text techniqueQueryText = "SELECT DISTINCT technique FROM atcf WHERE " + \ "basin ='" + idNumberDict[cycloneId][0] + "' AND " + \ "cyclonenum ='" + idNumberDict[cycloneId][1] + "' AND " + \ "reftime='" + recordTime + "'" techniqueQuery.setQuery(techniqueQueryText) # execute the query techniqueQueryResults = techniqueQuery.execute() # create a list of techniques techniqueList = techniqueQueryResults.split("|") # add technique as value to the to the time,cyclone ID - technique dictionary timeIdTqDict[timeIdTuple] = techniqueList return idNumberDict, timeIdTqDict def __makeResponse(self): from gov.noaa.nws.ncep.edex.uengine.tasks.atcf import AtcfCyclone, AtcfTrack response = ArrayList() idNumberDict, timeIdTqDict = self.__getDictionaries() # traverse the time,cyclone ID - technique dictionary to obtain AtcfRecords and # construct AtcfCyclone objects for key, value in timeIdTqDict.items(): currentTime = key[0] cycId = key[1] techList = value aBasin = idNumberDict[cycId][0] aCycloneNumb = idNumberDict[cycId][1] # create new AtcfCyclone object aCyclone = AtcfCyclone(cycId) for techniqueName in techList: bsResults = None # CARQ case if techniqueName == "CARQ": # first we need to create track for the past BaseRequest.BaseRequest.__init__(self, "atcf") self.query.addParameter("dataTime", currentTime) self.query.addParameter("basin",aBasin) self.query.addParameter("cycloneNum",aCycloneNumb) self.query.addParameter("technique",techniqueName) self.query.addParameter("radWind", "34") self.query.addParameter("fcstHour","0", "<") order = True self.query.setSortBy("fcstHour", order) bsResultsPast = self.query.execute() bsResults = bsResultsPast # second we need to create track for the future BaseRequest.BaseRequest.__init__(self, "atcf") timeRange = currentTime + "--" + self.__getTimePlus(currentTime) self.query.addParameter("dataTime", timeRange, "between") self.query.addParameter("basin",aBasin) self.query.addParameter("cycloneNum",aCycloneNumb) self.query.addParameter("technique",techniqueName) self.query.addParameter("radWind", "34") self.query.addParameter("fcstHour","0") order = True self.query.setSortBy("dataTime", order) bsResultsFuture = self.query.execute() count = 0 for ii in range(bsResultsFuture.size()): recordToChange = bsResultsFuture.get(ii) recordToChange.setFcstHour(ii*6) bsResults.add(recordToChange) # non-CARQ case else: BaseRequest.BaseRequest.__init__(self, "atcf") self.query.addParameter("dataTime", currentTime) self.query.addParameter("basin",aBasin) self.query.addParameter("cycloneNum",aCycloneNumb) self.query.addParameter("technique",techniqueName) order = True self.query.setSortBy("fcstHour", order) bsResults = self.query.execute() if bsResults is None or bsResults.size() == 0: pass else: # create new AtcfTrack object aTrack = AtcfTrack(techniqueName, bsResults) # add AtcfTrack object to AtcfCyclone aCyclone.addTrack(aTrack) # add AtcfCyclone object to the response ArrayList response.add(ResponseMessageGeneric(aCyclone)) return response # # Returns a string with a response message # def __makeNullResponse(self, aMessage="Database Query returned no results"): return ResponseMessageGeneric(aMessage)
def __init__(self): self.convert = GempakConvert()
def makeResponse(self): convert = GempakConvert(self.pluginName, self.queryResults) return convert.ConvertRadarRMC(self.distinctField)