def runFromJava(myServerHost, myServerPort, myServerProtocol, myServerMHSID, myServerSite, sites, filterSites, mhsSites, issueTime, countDict, fname, xmlIncoming, xmtScript): init_logging() logger.info('*********** sendAT ****************') startT = time.time() try: sites = JUtil.javaObjToPyVal(sites) filterSites = JUtil.javaObjToPyVal(filterSites) mhsSites = JUtil.javaObjToPyVal(mhsSites) countDict = JUtil.javaObjToPyVal(countDict) execute_send_at(myServerHost, myServerPort, myServerProtocol, myServerMHSID, myServerSite, sites, filterSites, mhsSites, issueTime, countDict, fname, xmlIncoming, xmtScript) except: logger.exception('Error in sendAT:') raise #-------------------------------------------------------------------- # Finish #-------------------------------------------------------------------- endT = time.time() logger.info("Final: wctime: {0:-6.2f}, cputime: {1:-6.2f}".format( endT - startT, time.clock()))
def executeGeneratorFrom(self, moduleName, className, **kwargs): eventSet = [] if 'generatedProductList' in kwargs: updateList = True genProdList = kwargs.pop('generatedProductList') eventSet = PythonEventSet(genProdList.getEventSet()) dataList = [] for i in range(genProdList.size()): # make sure dataList is a python object dataList.append( JUtil.javaObjToPyVal(genProdList.get(i).getData())) kwargs['dataList'] = dataList kwargs['eventSet'] = eventSet else: updateList = False genProdList = GeneratedProductList() eventSet = PythonEventSet(kwargs.get('eventSet')) productParts = kwargs.get('productParts', None) # make sure keyInfoList is a python object if hasattr(productParts, 'java_name'): productParts = JUtil.javaObjToPyVal(productParts) kwargs['productParts'] = productParts # call executeFrom from product generator dataList = self.runMethod(moduleName, className, 'executeFrom', **kwargs) genProdList.setProductInfo(moduleName) self.createProductsFromDictionary(dataList, eventSet, genProdList, updateList) return genProdList
def executeGeneratorUpdate(self, moduleName, className, **kwargs): dataList = kwargs['dataList'] # make sure dataList is a python object if hasattr(dataList, 'java_name'): dataList = JUtil.javaObjToPyVal(dataList) kwargs['dataList'] = dataList formats = kwargs.pop('formats') javaEventSet = kwargs['eventSet'] kwargs['eventSet'] = PythonEventSet(javaEventSet) # call updateDataList from product generator dataList, events = self.runMethod(moduleName, className, 'updateDataList', **kwargs) if not isinstance(dataList, list): raise Exception('Expecting a list from ' + moduleName + '.execute()') kwargs['dataList'] = dataList # executeGeneratorFrom method is expected a javaEventSet kwargs['eventSet'] = javaEventSet genProdList = self.executeGeneratorFrom(moduleName, className, **kwargs) javaEventSet = EventSet() javaEventSet.addAll(JUtil.pyValToJavaObj(events)) genProdList.setEventSet(javaEventSet) return genProdList
def __toJavaMapInternal(pyDict, jmap): ''' Does the actual conversion of the elements inside of the dict to Map ''' for key in pyDict: jmap.put(JUtil.pyValToJavaObj(key), JUtil.pyValToJavaObj(pyDict[key])) return jmap
def runFromJava(myServerHost, myServerPort, myServerProtocol, myServerMHSID, myServerSite, sites, filterSites, mhsSites, issueTime, countDict, fname, xmlIncoming, xmtScript): init_logging() log.info('*********** sendAT ****************') startT = time.time() try: sites = JUtil.javaObjToPyVal(sites) filterSites = JUtil.javaObjToPyVal(filterSites) mhsSites = JUtil.javaObjToPyVal(mhsSites) countDict = JUtil.javaObjToPyVal(countDict) execute_send_at(myServerHost, myServerPort, myServerProtocol, myServerMHSID, myServerSite, sites, filterSites, mhsSites, issueTime, countDict, fname, xmlIncoming, xmtScript) except: log.exception('Error in sendAT:') sys.exit(1) #-------------------------------------------------------------------- # Finish #-------------------------------------------------------------------- endT = time.time() log.info("Final: wctime: {0:-6.2f}, cputime: {1:-6.2f}".format(endT - startT, time.clock()))
def executeGenerator(self, moduleName, className, **kwargs): javaDialogInput = kwargs['dialogInputMap'] if javaDialogInput is not None: kwargs['dialogInputMap'] = JUtil.javaObjToPyVal(javaDialogInput) formats = kwargs.pop('formats') javaEventSet = kwargs['eventSet'] # execute method in generators is expecting a python eventSet kwargs['eventSet'] = PythonEventSet(kwargs['eventSet']) dataList, events = self.runMethod(moduleName, className, 'execute', **kwargs) if not isinstance(dataList, list): raise Exception('Expecting a list from ' + moduleName + '.execute()') kwargs['dataList'] = dataList # executeGeneratorFrom method is expecting a javaEventSet kwargs['eventSet'] = javaEventSet # dialogInputMap no longer needed for executeFrom method kwargs.pop('dialogInputMap') genProdList = self.executeGeneratorFrom(moduleName, className, **kwargs) javaEventSet = EventSet() javaEventSet.addAll(JUtil.pyValToJavaObj(events)) genProdList.setEventSet(javaEventSet) return genProdList
def setUpUI(self): if sys.modules.has_key("MakeHazardConfig"): sys.modules.__delitem__("MakeHazardConfig") import MakeHazardConfig args = {} args['dataManager'] = self._dataManager args['selectedTimeRange'] = self.selectedTimeRange args['mapColor'] = MakeHazardConfig.mapColor args['defaultMapWidth'] = MakeHazardConfig.defaultMapWidth args['timeScaleEndTime'] = MakeHazardConfig.timeScaleEndTime args['areaThreshold'] = MakeHazardConfig.areaThreshold args['defaultHazardType'] = MakeHazardConfig.defaultHazardType args['mapNames'] = MakeHazardConfig.mapNames args['hazardDict'] = MakeHazardConfig.hazardDict args['tcmList'] = MakeHazardConfig.tcmList args['tropicalHaz'] = self._tropicalHaz args['natlBaseETN'] = self._natlBaseETN if not hasattr(MakeHazardConfig, 'localEffectAreas') or \ MakeHazardConfig.localEffectAreas is None: args['localEffectAreas'] = {} else: args['localEffectAreas'] = MakeHazardConfig.localEffectAreas if not hasattr(MakeHazardConfig, 'localAreaData') or \ MakeHazardConfig.localAreaData is None: args['localAreaData'] = {} else: args['localAreaData'] = MakeHazardConfig.localAreaData # create the Java/SWT dialog and open it from com.raytheon.viz.gfe.makehazard import MakeHazardDialog self.__dlg = MakeHazardDialog.createFromPython( JUtil.pyValToJavaObj(args)) self.__dlg.openFromPython() # run the Java/SWT event loop try: dismiss = False while not dismiss: args = JUtil.javaObjToPyVal(self.__dlg.runFromPython(), converter) dismiss = True # if args is None, then Cancel was pressed if args is not None: # dismiss is True if the Run/Dismiss button is pressed, # false if Run is pressed dismiss = args["dismiss"] del args["dismiss"] if self.makeHazardGrid(**args) != 1: dismiss = False finally: # close the Java/SWT dialog when Cancelled, Dismissed or exception occurs self.__dlg.closeFromPython()
def setUpUI(self): if sys.modules.has_key("MakeHazardConfig"): sys.modules.__delitem__("MakeHazardConfig") import MakeHazardConfig args = {} args['dataManager'] = self._dataManager args['selectedTimeRange'] = self.selectedTimeRange args['mapColor'] = MakeHazardConfig.mapColor args['defaultMapWidth'] = MakeHazardConfig.defaultMapWidth args['timeScaleEndTime'] = MakeHazardConfig.timeScaleEndTime args['areaThreshold'] = MakeHazardConfig.areaThreshold args['defaultHazardType'] = MakeHazardConfig.defaultHazardType args['mapNames'] = MakeHazardConfig.mapNames args['hazardDict'] = MakeHazardConfig.hazardDict args['tcmList'] = MakeHazardConfig.tcmList args['tropicalHaz'] = self._tropicalHaz args['natlBaseETN'] = self._natlBaseETN if not hasattr(MakeHazardConfig, 'localEffectAreas') or \ MakeHazardConfig.localEffectAreas is None: args['localEffectAreas'] = {} else: args['localEffectAreas'] = MakeHazardConfig.localEffectAreas if not hasattr(MakeHazardConfig, 'localAreaData') or \ MakeHazardConfig.localAreaData is None: args['localAreaData'] = {} else: args['localAreaData'] = MakeHazardConfig.localAreaData # create the Java/SWT dialog and open it from com.raytheon.viz.gfe.makehazard import MakeHazardDialog self.__dlg = MakeHazardDialog.createFromPython( JUtil.pyValToJavaObj(args) ) self.__dlg.openFromPython() # run the Java/SWT event loop try: dismiss = False while not dismiss: args = JUtil.javaObjToPyVal(self.__dlg.runFromPython(), converter) dismiss = True; # if args is None, then Cancel was pressed if args is not None: # dismiss is True if the Run/Dismiss button is pressed, # false if Run is pressed dismiss = args["dismiss"] del args["dismiss"] if self.makeHazardGrid(**args) != 1: dismiss = False finally: # close the Java/SWT dialog when Cancelled, Dismissed or exception occurs self.__dlg.closeFromPython()
def updateTafsFromJava(bbb, fcsts): import JUtil print "fcsts entry", fcsts fcsts = JUtil.javaStringListToPylist(fcsts) ids = [Avn._getIds(f) for f in fcsts] #bbb = self.sp.bbb.get().strip().upper() fcsts = updateTafs(bbb, dict(zip(ids, fcsts))) print type(fcsts), len(fcsts) return JUtil.pyValToJavaObj(fcsts) return fcsts
def updateProductText(key, productCategory, mode, segment, eventIDs, officeID, value): ''' Updates an entry in the database. The value must be able to be converted by JUtil to a Java Serializable object. ''' val = JUtil.pyValToJavaObj(value) eventIDs = JUtil.pyValToJavaObj(eventIDs) ProductTextUtil.updateProductText(key, productCategory, mode, segment, eventIDs, officeID, val)
def addToList(self, key, value): ''' The equivalent of hazardAttributes.setdefault(key, []).append(value) ''' currentVal = JUtil.javaObjToPyVal(self.jobj.getHazardAttribute(key)) if currentVal: currentVal.append(value) else: currentVal = [value] self.jobj.addHazardAttribute(key, JUtil.pyValToJavaObj(currentVal))
def __toPythonDictInternal(javaMap, pyDict, customConverter=None): ''' Converts to a Python dict. Passed in the dict type, and then handles the key conversion. ''' keys = javaMap.keySet() itr = keys.iterator() while itr.hasNext() : key = itr.next() obj = javaMap.get(key) pyDict[JUtil.javaObjToPyVal(key)] = JUtil.javaObjToPyVal(obj, customConverter) return pyDict
def deleteProductText(key, productCategory, mode, segment, eventIDs, officeID): ''' Deletes an entry from the database. ''' eventIDs = JUtil.pyValToJavaObj(eventIDs) ProductTextUtil.deleteProductText(key, productCategory, mode, segment, eventIDs, officeID)
def retrieveMapData(siteIDs, timeSeconds, parameters=Parameters): r = _retrieveMapData(siteIDs, timeSeconds, parameters=Parameters) results = {} for siteID in siteIDs: results[siteID] = cPickle.dumps(r[siteID]) return JUtil.pyDictToJavaMap(results)
def __init__(self, title, varList, varDict=None, parent=None, dataMgr=None, modal=1, runCB=None, argList=[], cmdLineVarDict=None): self.__varDict = varDict if self.__varDict is None: self.__varDict = {} self.__callbackResult = None # build widgetList widgetList = buildWidgetList(varList) # Construct the dialog self.__dialog = ValuesDialog.openDialog(title, widgetList, dataMgr) #self.__dialog = ValuesDialog(title,widgetList) # since ValuesDialog blocks on open() we can set status and varDict here values = JUtil.javaMapToPyDict(self.__dialog.getValues(), self.__convertJavaObjToPyWrapper) self.__varDict.update(values) from com.raytheon.uf.viz.python.swt import ButtonConstant self.__selectionStatus = str( ButtonConstant.getButton(self.__dialog.getReturnCode()))
def preEncode(self, object): # Encode AdvancedGeometries as dictionaries # suitable for converting into JSON. if isinstance(object, AdvancedGeometry): return JUtil.javaObjToPyVal(JsonConverter. toDictionary(object.getWrappedJavaObject())) # If the object is a dictionary, convert any keys # that are tuples into strings, and do any pre- # encoding needed for the values. if isinstance(object, dict): newObject = {} for key, value in object.iteritems(): if isinstance(key, tuple): key = str(key[0]) + " " + str(key[1]) newObject[key] = self.preEncode(value) return newObject # If the object is a list, do any pre-encoding # needed on the elements. if isinstance(object, list): newObject = [] for element in object: newObject.append(self.preEncode(element)) return newObject # No pre-encoding was needed, so simply return # the original object. return object
def __makeData(self, t): try: siteID = self.info['ident'] timeSeconds = long(t) if SiteGridManager.needData(timeSeconds) : siteIDs = JUtil.javaStringListToPylist(SiteGridManager.getSiteIDs()) containersMap = GridData.retrieveMapData(siteIDs, timeSeconds) SiteGridManager.setContainersMap(containersMap) return None o = SiteGridManager.getData(siteID, timeSeconds) if o is None : return None ndata = cPickle.loads(o) data = GridData.formatData(siteID, timeSeconds, ndata) bbb = 'RRA' tc=TafGen.TafGen('grid',data,bbb) taf=tc.createTaf(False) dcd = self.decoder(taf, bbb) if 'fatal' in dcd: raise Avn.AvnError return {'hourly': AvnLib.TafData(dcd['group']), \ 'text': '\n'.join(taf)} except Avn.AvnError: return None
def __makeData(self, t): try: siteID = self.info['ident'] timeSeconds = long(t) if SiteGridManager.needData(timeSeconds): siteIDs = JUtil.javaStringListToPylist( SiteGridManager.getSiteIDs()) containersMap = GridData.retrieveMapData(siteIDs, timeSeconds) SiteGridManager.setContainersMap(containersMap) return None o = SiteGridManager.getData(siteID, timeSeconds) if o is None: return None ndata = cPickle.loads(o) data = GridData.formatData(siteID, timeSeconds, ndata) bbb = 'RRA' tc = TafGen.TafGen('grid', data, bbb) taf = tc.createTaf(False) dcd = self.decoder(taf, bbb) if 'fatal' in dcd: raise Avn.AvnError return {'hourly': AvnLib.TafData(dcd['group']), \ 'text': '\n'.join(taf)} except Avn.AvnError: return None
def getEventSetForProduct(self, data, eventSet): """ @return: Returns a sub set of the eventSet passed to the generator that pertains to this one product. This sub set will be used as a PK to save the product to the productData table during dissemination. """ # Get all the eventIDs from the product eventIDs = set() for segment in data.get('segments', []): for vtecRecord in segment.get('vtecRecords', []): for eventID in vtecRecord.get('eventID', []): eventIDs.add(eventID) # Create a sub set of the eventSet based on the product eventIDs productEventSet = set() for eventID in eventIDs: for event in eventSet: if event.getEventID() == eventID: productEventSet.add(event) break javaEventSet = EventSet() javaEventSet.addAll(JUtil.pyValToJavaObj(productEventSet)) javaEventSet.addAttribute('runMode', eventSet.getAttribute('runMode')) return javaEventSet
def getScriptMetadata(self, moduleName, className, **kwargs): """ @return: Returns a map of string to string of the metadata. """ val = self.runMethod(moduleName, className, 'defineScriptMetadata', **kwargs) return JUtil.pyValToJavaObj(val)
def __toJavaSetInternal(val): ''' Does the actual conversion of the elements inside of the set or frozenset to Set ''' retObj = HashSet() for v in val : retObj.add(JUtil.pyValToJavaObj(v)) return retObj
def _toJavaList(val): ''' Turns a Python list to a Java List ''' retObj = ArrayList() for i in val : retObj.add(JUtil.pyValToJavaObj(i)) return retObj
def _convertTableToPurePython(self, table, siteId): javaRecList = ArrayList() for rec in table: javaRecList.add(rec.javaRecord()) javaDictFormat = ActiveTableUtil.convertToDict(javaRecList, siteId) return JUtil.javaObjToPyVal(javaDictFormat)
def putVtecRecords(self, vtecRecords, reqInfo={}): import JUtil from com.raytheon.uf.common.dataplugin.events.hazards.request import StoreHazardEventVtecRequest from com.raytheon.uf.common.serialization.comm import RequestRouter request = StoreHazardEventVtecRequest() request.setPractice(self.operationalMode == False) request.setVtecList(JUtil.pyValToJavaObj(vtecRecords)) response = RequestRouter.route(request)
def deleteVtecRecords(self, vtecRecords, reqInfo={}): import JUtil from com.raytheon.uf.common.dataplugin.events.hazards.request import DeleteHazardEventVtecsRequest from com.raytheon.uf.common.serialization.comm import RequestRouter javaRecords = JUtil.pyValToJavaObj(vtecRecords) request = DeleteHazardEventVtecsRequest(javaRecords, self.operationalMode == False) response = RequestRouter.route(request)
def get(self, key): ''' @summary Get the generic session object associated with the specified key. @param key Key for which to fetch the value. @return Value associated with the key, or None if no such value is found. ''' value = self._javaObject.get(key) return JUtil.javaObjToPyVal(value) if value is not None else None
def getVisualFeatures(self): # This may return a list, and not a VisualFeatures object (which is a # list subclass), so build one of the latter out of the former. visualFeatures = JUtil.javaObjToPyVal(self.jobj.getVisualFeatures()) if visualFeatures is None: return VisualFeatures([]) return VisualFeatures(visualFeatures)
def tafgen(siteObjs, model, format='short', routine=False, highlightFlightCat=True): siteObjs = JUtil.javaStringListToPylist(siteObjs) # print 'GuidanceEntry::tafgen model, format, highlightFlightCat:', model, format, highlightFlightCat if routine: bbb = ' ' else: bbb = 'AAX' includeReport = (format == 'table') if len(siteObjs) > 1 and includeReport: msg = 'Table display for all sites is not supported' return [msg] DataList = [] for siteObj in siteObjs: o = pickle.loads(siteObj) siteID = o['siteID'] data = o['data'] if data is not None: data = data[0] if data is not None and data.data is not None and len(data.data) > 1: DataList.append(data) if len(siteObjs) == 1: if data is None or data.data is None: return ["'No data available for site %s'" % siteID] elif len(data.data) == 1: # Assume error message return data.data if includeReport: return data.rpt else: tafList = [] tafWithHeader = [] if len(DataList) > 0: donot_group = (format == 'long') for data in DataList: tc = TafGen.TafGen(model, data.data, bbb) taf = tc.createTaf(donot_group) if highlightFlightCat: taf = __highlightFlightCat(taf) tafList.append(taf) tafWithHeader.append(__makeHeader(model, DataList[0].data)) for taf in tafList: tafWithHeader.append('') tafWithHeader += taf else: if len(siteObjs) == 1: tafWithHeader.append('No data available for the site %s' % siteID) else: tafWithHeader.append('No data available for the sites') return tafWithHeader
def getIdentifiers(self): ids = {} jmap = self.jobj.getIdentifiers() itr = jmap.keySet().iterator() while itr.hasNext(): key = itr.next() value = JUtil.javaObjToPyVal(jmap.get(key)) ids[key] = value return ids
def get_host_writes(filename): text = "" text += "Host Writes Low (hex): " low = JU.get_little_endian_from_DM_ASCII_file(filename, 48, 55, print_hex=False) text += low + "\n" text += "Host Writes High (hex): " high = JU.get_little_endian_from_DM_ASCII_file(filename, 56, 63, print_hex=False) text += high + "\n" total = high + low total = int(total, 16) * 1000 * 512 text += "Host Writes (Bytes): " + str(total) + "\n" return total, text
def set(self, key, value): ''' @summary Create an entry associating the specified key with the specified value. @param key Key for which to create the new entry. @param value Value to be associated with the key. ''' value = JUtil.pyValToJavaObj(value) if value is not None else None return self._javaObject.set(key, value)
def _convertEvents(self, eventSet): pyEvents = set() iter = eventSet.iterator() while iter.hasNext(): next = iter.next() event = JUtil.javaObjToPyVal(next) pyEvents.add(event) return pyEvents
def getMetars(siteObj, size=99): o = pickle.loads(siteObj) siteID = o['siteID'] data = o['data'] # print 'PlotEntry.getMetars siteID, size:', siteID, size if data is not None: data = [{'header' : d.header, 'text' : d.text, 'dcd' : d.dcd} for d in data] data.sort(lambda x, y: cmp(y['dcd']['itime']['str'], x['dcd']['itime']['str'])) return JUtil.pyValToJavaObj(data)
def tampgen(selSite, siteObjs, model, format, taf, tafHeader, cvOnly, routine = False, highlightFlightCat=True): siteObjs = JUtil.javaStringListToPylist(siteObjs) #print 'GuidanceEntry:tampgen model, format, taf, tafHeader, cvOnly, highlightFlightCat:', model, format, taf, tafHeader, cvOnly, highlightFlightCat if routine : bbb = ' ' else: bbb = 'AAX' LAMPs = [] siteIDs = [] for siteObj in siteObjs: o = pickle.loads(siteObj) siteID = o['siteID'] LAMP = o['data'] # print 'tampgen siteID, LAMP:', siteID, LAMP if LAMP is not None: LAMPs.append(LAMP) siteIDs.append(siteID) if selSite == siteID: selLAMP = LAMP if len(LAMPs) == 0 or selLAMP is None: if len(siteObjs) == 1 or selLAMP is None: msg = 'No data available for site %s' % selSite else: msg = 'No data available for the sites' return [msg] tafWithHeader = [__makeHeader('%s TAF/%s' % (selSite,model), selLAMP.data)] import TafDecoder, AvnParser, TAMPGenerator, ProbReader decoder = TafDecoder.Decoder() for siteID, LAMP in zip(siteIDs, LAMPs): tmtuple = time.gmtime(LAMP.data['itime']['value']) thresholds = ProbReader.prob_reader(siteID,[tmtuple[7],('%02d'%tmtuple[3])]) if thresholds is None: msg = 'Missing LAMP thresholds at this hour for %s' % siteID return [msg] header = tafHeader text = taf dcd = decoder(text, bbb) TAF = Avn.Bunch(header=header, text=text, dcd=dcd) try: siteinfo = AvnParser.getTafSiteCfg(LAMP.data['ident']['str']) tafDuration = int(siteinfo['thresholds'].get('tafduration','24')) newTaf = TAMPGenerator.TAMPGenerator(LAMP,TAF.dcd['group'],thresholds, bbb,cvOnly, (format == 'long'), tafDuration) if highlightFlightCat: newTaf = __highlightFlightCat(newTaf) tafWithHeader.append('') tafWithHeader += newTaf except (KeyError,TypeError,AttributeError, Avn.AvnError), e: msg = "%s - %s" % (siteID, e) _Logger.exception('Error with TAMPGenerator: %s', msg) if len(siteObjs) == 1: return [msg]
def _fromJepArray(obj, customConverter=None): ''' Converts from a Jep array to a Python list. ''' retVal = [] size = len(obj) for i in range(size): retVal.append(JUtil.javaObjToPyVal(obj[i], customConverter)) return retVal
def toJavaObj(self): productPart = JavaProductPart() productPart.setName(self.name) productPart.setDisplayable(self.displayable) productPart.setLabel(self.label) productPart.setEventIDsInLabel(self.eventIDsInLabel) productPart.setEditable(self.editable) productPart.setRequired(self.required) productPart.setNumLines(self.numLines) productPart.setSegmentDivider(self.segmentDivider) productPart.setSubParts(JUtil.pyValToJavaObj(self.subParts)) productPart.setFormatMethod(self.formatMethod) productPart.setKeyInfo(JUtil.pyValToJavaObj(self.keyInfo)) productPart.setGeneratedText(self.generatedText) productPart.setPreviousText(self.previousText) productPart.setCurrentText(self.currentText) productPart.setUsePreviousText(self.usePreviousText) return productPart
def getMos(siteObj, model): o = pickle.loads(siteObj) siteID = o['siteID'] mosData = o['data'] # print 'PlotEntry.getMos: model, siteID:', model, siteID if mosData is not None: data = [{'data' : mos.data} for mos in mosData] else: data = None return JUtil.pyValToJavaObj(data)
def decodeTaf(taf, wmoHeader): # print 'plotEntry.decodeTaf: taf<%s>,\nwmoHeader<%s>:' % ( taf, wmoHeader) decoder = TafDecoder.Decoder() try: bbb = wmoHeader.split()[3] except IndexError: bbb = ' ' dcd = decoder(taf, bbb) tafDict = {'header': wmoHeader, 'text': taf, 'dcd': dcd} return JUtil.pyValToJavaObj(tafDict)
def clearMetarCache(siteIDs, model = None, format = None): '''Clears all metar cached information for the sites. Returns the list of siteIDs.''' # print 'GuidanceEntry::clearMetarCache siteIDs - ', siteIDs siteIDs = JUtil.javaStringListToPylist(siteIDs) # print 'GuidanceEntry::clearMetarCache siteIDs, len - ', siteIDs, len(_metargenDataCache.cache) for siteID in siteIDs : _metargenDataCache.delSite(siteID) # print ' len -', len( _metargenDataCache.cache) return siteIDs
def get_metar(self, siteID): import JUtil import MetarData data = MetarData.retrieve([siteID], 1) if data is None: raise Avn.AvnError('Cannot retrieve data for %s' % siteID) data = [{'header' : d.header, 'text' : d.text, 'dcd' : d.dcd} for d in data] data.sort(lambda x, y: cmp(y['dcd']['itime']['str'], x['dcd']['itime']['str'])) tms = time.gmtime(data[0]['dcd']['itime']['value']) return JUtil.pyValToJavaObj(data[0])
def decode(self): #get pil and date-time group self._productPil, self._issueTime, linePos,\ self._completeProductPil = self._getPilAndDTG() # If this is a WCL - don't go any further. Run WCL procedure and exit. if self._productPil[0:3] == "WCL": endpoint = "WCLWatch" # build a Java object for the warning from com.raytheon.edex.plugin.gfe.wcl import WclInfo import JUtil lines = JUtil.pyValToJavaObj(self._lines) warning = WclInfo(long(self._issueTime * 1000), self._completeProductPil, lines, self._notifyGFE) from com.raytheon.uf.edex.core import EDEXUtil EDEXUtil.getMessageProducer().sendAsync(endpoint, warning) LogStream.logEvent("%s forwarded to WCLWatch" % self._productPil) return [] # Determine if this is a segmented product segmented = self._determineSegmented(linePos) # Get overview text if segmented == 1: self._overviewText, linePos = self._getOverviewText(linePos) else: self._overviewText = '' LogStream.logDebug("OverviewText: ", self._overviewText) #find all UGCs, VTEC strings, and segment text ugcVTECList = self._getUGCAndVTECStrings(linePos) self._polygon = self._getPolygon(linePos) self._storm = self._getStorm(linePos) #convert UGC strings into UGC list ugcVTECSegText = [] segCount = 1 for ugcString, vtecStrings, segText, cities in ugcVTECList: purgeTime = None self._checkForDTG(ugcString) if self._hasDTG: purgeTime = self._dtgFromDDHHMM(ugcString[-7:-1]) else: purgeTime = self._getPurgeTimeFromVTEC(vtecStrings) vtecList = self._expandVTEC(ugcString, vtecStrings, segCount, segText, cities, purgeTime) segCount = segCount + 1 for r in vtecList: ugcVTECSegText.append(r) if len(ugcVTECSegText) == 0: LogStream.logVerbose("No VTEC Found in product") return return ugcVTECSegText
def getScripts(paths, nameMap, definitionMap): global displayNameDict displayNameDict = {} rval = [] split = paths.split(':') for path in split: if not path in sys.path: sys.path.append(path) inv = os.listdir(path) inv = filter(filterScripts, inv) logger.info("TextProduct FormatterLauncher Processing....") for pid in inv: name = string.split(pid, ".")[0] if sys.modules.has_key(name): del sys.modules[name] try: mod = __import__(name) except: logger.exception("Import Failed " + name) mod = None definition = None if mod is not None: d = mod.__dict__ #search for Definition at top-level definition = d.get('Definition', None) if definition is None: # search for definition within class name definition = d.get(name, None) if definition is None: tp = d.get('TextProduct', None) if tp is not None: #search for definition within TextProduct class definition = getattr(tp, 'Definition', None) if definition is None or type(definition) is not dict: logger.info("Formatter: No Definition Found " + name) continue #fs = FormatterScript(self._dataMgr, name, mod, definition) dspName = getDisplayName(definition) if dspName is None or dspName == "None": #LogStream.logVerbose("Formatter displayName is None: " + # ppDef(definition)) continue #LogStream.logVerbose("Formatter displayName set: ", fs.dspName(), # ppDef(definition)) nameMap.put(dspName, name) from com.raytheon.uf.common.dataplugin.gfe.textproduct import ProductDefinition pdef = ProductDefinition() pdef.setDefinition(JUtil.pyDictToJavaMap(definition)) definitionMap.put(dspName, pdef) displayNameDict[dspName] = (mod, definition) #rval.append(fs) #rval.sort() logger.info("TextProduct FormatterLauncher Done....")
def runTool(self, moduleName, bbb, fcsts): import JUtil fcsts = JUtil.javaStringListToPylist(fcsts) ids = [Avn._getIds(f) for f in fcsts] #bbb = self.sp.bbb.get().strip().upper() mod = __import__(moduleName) fcsts = mod.updateTafs(bbb, dict(zip(ids, fcsts))) if fcsts: return '\n'.join([fcsts[i] for i in ids]) else: return None
def __checkArgs(self,parmsWanted, gridDims,gridBoundBox, iscWfosWanted): if type(parmsWanted) is not list: parmsWanted = JUtil.javaStringListToPylist(parmsWanted) if type(gridDims) is not list: pylist = [] size = gridDims.size() for i in range(size): pylist.append(gridDims.get(i).intValue()) gridDims = pylist if type(gridBoundBox) is not tuple: gridBoundBox = ((gridBoundBox.get(0).doubleValue(),gridBoundBox.get(1).doubleValue()),(gridBoundBox.get(2).doubleValue(),gridBoundBox.get(3).doubleValue())) if type(iscWfosWanted) is not list: iscWfosWanted = JUtil.javaStringListToPylist(iscWfosWanted) return parmsWanted, gridDims, gridBoundBox, iscWfosWanted
def getNam(siteObj): model = 'etabuf' o = pickle.loads(siteObj) siteID = o['siteID'] etaData = o['data'] # print 'PlotEntry.getNam: model, siteID:', model, siteID if etaData is not None: data = [{'data' : eta.data} for eta in etaData] else: data = None return JUtil.pyValToJavaObj(data)
def tafgen(siteObjs, model, format='short', routine = False, highlightFlightCat=True): siteObjs = JUtil.javaStringListToPylist(siteObjs) # print 'GuidanceEntry::tafgen model, format, highlightFlightCat:', model, format, highlightFlightCat if routine : bbb = ' ' else : bbb = 'AAX' includeReport = (format == 'table') if len(siteObjs) > 1 and includeReport: msg = 'Table display for all sites is not supported' return [msg] DataList = [] for siteObj in siteObjs: o = pickle.loads(siteObj) siteID = o['siteID'] data = o['data'] if data is not None: data = data[0] if data is not None and data.data is not None and len(data.data) > 1: DataList.append(data) if len(siteObjs) == 1: if data is None or data.data is None: return ["'No data available for site %s'" % siteID] elif len(data.data) == 1: # Assume error message return data.data if includeReport: return data.rpt else: tafList = [] tafWithHeader = [] if len(DataList) > 0: donot_group = (format == 'long') for data in DataList: tc = TafGen.TafGen(model,data.data,bbb) taf=tc.createTaf(donot_group) if highlightFlightCat: taf = __highlightFlightCat(taf) tafList.append(taf) tafWithHeader.append(__makeHeader(model, DataList[0].data)) for taf in tafList: tafWithHeader.append('') tafWithHeader += taf else : if len(siteObjs) == 1: tafWithHeader.append('No data available for the site %s' % siteID) else: tafWithHeader.append('No data available for the sites') return tafWithHeader
def monitor(request): taf = decodeTaf(request.getTaf(), request.getWmoHeader()) if taf.dcd.has_key('fatal'): _Logger.error(taf.dcd['fatal']) return JUtil.pyValToJavaObj({'fatal': taf.dcd['fatal']}) monitorModuleName = request.getCfg().getClassName() monitorModule = __import__(monitorModuleName) info = AvnParser.getTafSiteCfg(request.getSiteID()) m = transformCfg(monitorModule, request) monitor = monitorModule.Monitor(info, m) result = {'ident': info['ident'], 'taf': taf, \ 'newtaf': False, 'status': {}} result['taf'].hourly = AvnLib.TafData( \ result['taf'].dcd['group']) result['status'] = monitor.compare(result['taf']) result = bunchToDict(result) if result['taf'].has_key('hourly'): hourly = result['taf']['hourly'] result['taf']['hourly'] = None return JUtil.pyValToJavaObj(result)
def unPickle(str): import pickle,tempfile,os,JUtil tempfile.tempdir = "/tmp/" fname = tempfile.mktemp(".bin") FILE = open(fname,"w") FILE.write(str) FILE.close() FILE = open(fname,"r") retVal = pickle.load(FILE) FILE.close() return JUtil.pyDictToJavaMap(retVal)
def qcFromJava(self, text, sites, items, bbb, dataDir): import JUtil import TafDecoder # tafs # convert the ArrayList of tafs into a python list fcsts = [] size = text.size() for i in range(size): fcsts.append(str(text.get(i))) # decode the tafs for use in the QC check taf_decoder = TafDecoder.Decoder() pytafs = [] offset = 0 for fcst in fcsts: taf = taf_decoder(fcst, bbb, offset, strict=True) offset += fcst.count('\n')+1 if 'fatal' in taf: continue pytafs.append(taf) # convert the siteinfo Hashmap into python dictionary pysiteinfo = {} itr = sites.iterator() while itr.hasNext(): key = itr.next() ident = str(key) pysite = AvnParser.getTafSiteCfg(ident) pysiteinfo[ident] = pysite # convert the items HashMap into a python dictionary pyitems = {} keys = items.keySet() itr = keys.iterator() while itr.hasNext(): key = itr.next() val = items.get(key) wx = eval(str(val.get('currentwx'))) climate = eval(str(val.get('climate'))) impact = eval(str(val.get('impact'))) pyitem = {} pyitem['currentwx'] = wx pyitem['climate'] = climate pyitem['impact'] = impact pyitems[str(key)] = pyitem result = self(pytafs, pysiteinfo, pyitems, dataDir) return JUtil.pyValToJavaObj(result)
def buildWidgetList(pythonWidgetList): from java.util import ArrayList from com.raytheon.viz.gfe.smartscript import FieldDefinition from com.raytheon.viz.gfe.smartscript import FieldDefinition_FieldType as FieldType widgetList = ArrayList() for widget in pythonWidgetList: res = 1.0 # Default resolution prec = 3 # Default precision valueList = [] # unpack the tuple if len(widget) == 3: name,defaultValue,entType = widget if len(widget) == 4: name,defaultValue,entType,valueList = widget if len(widget) == 5: name,defaultValue,entType,valueList,res = widget if len(widget) == 6: name,defaultValue,entType,valueList,res,prec = widget # Handle possibility of (label, variable) tuple if type(name) is types.TupleType: desc = name[0] else: desc = name w = FieldDefinition(JUtil.pyValToJavaObj(name),desc,FieldType.convertPythonType(entType), JUtil.pyValToJavaObj(defaultValue),JUtil.pyValToJavaObj(valueList), float(res),int(prec)) widgetList.add(w) return widgetList
def getRequestXML(xml,selectedServers, selectedWEList): irt = IrtAccess.IrtAccess("") selectedServers = JUtil.javaStringListToPylist(selectedServers) selectedWElist = JUtil.javaStringListToPylist(selectedWEList) response = unPickle(createDomainDict(xml)) serverDictT2S = response['serverDictT2S'] domainDict = response['domains'] iscReqE = Element('iscrequest') servers = [] for serverT in selectedServers: server = serverDictT2S[serverT] servers.append(server) irt.addDestinationXML(iscReqE, servers) welistE = SubElement(iscReqE, 'welist') for we in selectedWElist: weE = SubElement(welistE, 'parm') weE.text = we # output the list of servers and their priority s = '\n' for key in domainDict.keys(): s += "DOMAIN=" + key + '\n' servers = selectedServers for serverT in servers: server = serverDictT2S[serverT] if server['site'] == key: s += " mhs=" + server['mhsid'] + " host=" + \ server['host'] + " port=" + server['port'] + "\n" #LogStream.logEvent("Chosen request servers:", s) # send to ifpServer xmlreq = ElementTree.tostring(iscReqE) return xmlreq;
def decode(moduleName, fileToDecode, commandArgs=None): mod = sys.modules[moduleName] exec 'dec = mod.' + moduleName + '(filePath=fileToDecode)' if commandArgs is not None: dec.setCommand(commandArgs) result = dec.decode() resultList = ArrayList() if result is not None: for resultDict in result: if type(resultDict) == dict: hashmap = JUtil.pyDictToJavaMap(resultDict) resultList.add(hashmap) else: resultList.add(resultDict) return resultList
def parseFromJava(self, text): self._str = text self._ci = None lines = map(lambda x: len(x), text.splitlines(1)) count = 0 lc = [] for l in lines: lc.append(count) count += l self._totals = lc #print 'text START ----------------------' #print text #print 'text END ------------------------' result = self.parse() #print 'result = ', result return JUtil.pyDictToJavaMap(result)
def printActiveTable(self, table, combine=False, idType='zone'): if table is None: s = "Table is None" return s elif hasattr(table,"jclassname"): table = JUtil.javaObjToPyVal(table) print type(table) #dictionary, single record if type(table) is dict: ptable = [] ptable.append(table) #list of dictionaries else: ptable = table s = '\n' #Return value # Use the zone or city printEntry method if idType == 'zone': printEntry = self.printEntry compare = None elif idType == 'city': printEntry = self.printCityEntry compare = ['start', 'end', 'phen', 'sig', 'seg'] #combine mode, attempt to combine records if combine: ctable = self.consolidateByID(ptable, compare=compare) for c in ctable: s = s + printEntry(c) #non-combine mode else: for p in ptable: s = s + printEntry(p) return s
def __init__(self, title, varList, varDict=None, parent=None, dataMgr=None, modal=1, runCB=None, argList=[], cmdLineVarDict=None): self.__varDict = varDict if self.__varDict is None: self.__varDict = {} self.__callbackResult = None # build widgetList widgetList = buildWidgetList(varList) # Construct the dialog self.__dialog = ValuesDialog.openDialog(title, widgetList, dataMgr) #self.__dialog = ValuesDialog(title,widgetList) # since ValuesDialog blocks on open() we can set status and varDict here values = JUtil.javaMapToPyDict(self.__dialog.getValues(), self.__convertJavaObjToPyWrapper) self.__varDict.update(values) from com.raytheon.uf.viz.python.swt import ButtonConstant self.__selectionStatus = str(ButtonConstant.getButton(self.__dialog.getReturnCode()))
def main(argv): initLogger() try: if type(argv) is not list: import JUtil argv = JUtil.javaObjToPyVal(argv) logEvent('*** iscDataRec ***', argv) try: MSGID = argv[0] SUBJECT = argv[1] FILES = argv[2].split(',') logEvent('SUBJECT:', SUBJECT, 'MSGID:', MSGID) #log the incoming files and size for file in FILES: filesize = os.stat(file)[stat.ST_SIZE] logEvent('Received:', file, filesize, "bytes") execIscDataRec(MSGID,SUBJECT,FILES) except: logProblem('Failure:', traceback.format_exc()) except: logProblem("FAIL: ", traceback.format_exc())
def process(self): import TimeRange # get list of edit areas that are part of the Zones/FireWx group from com.raytheon.viz.gfe.smarttool import TextFileUtil, GridCycler textID = TextFileUtil.getTextFile('Zones', 'editAreaGroups') zoneList = [] textFile = open(textID.getFile().getPath()) textFile.readline() for line in textFile: zoneList.append(line.rstrip()) textFile.close() textID = TextFileUtil.getTextFile('FireWxZones', 'editAreaGroups') textFile = open(textID.getFile().getPath()) textFile.readline() for line in textFile: zoneList.append(line.rstrip()) textFile.close() refMgr = self.__dataMgr.getRefManager() # make the basic edit areas that are required, go sequentially through # the zoneList requiredEA = ["west_half","east_half","east_one_third", "west_one_third", "east_two_thirds","west_two_thirds", "east_one_quarter", "west_one_quarter", "east_three_quarters", "west_three_quarters","SUPERIOR"] for x in xrange(len(requiredEA)): refData = refMgr.loadRefSet(ReferenceID(zoneList[x])) ea = ReferenceData(refData) ea.setId(ReferenceID(requiredEA[x])) refMgr.saveRefSet(ea) #ea = self.__client.getEditAreaPolygons(zoneList[x]) #self.__client.saveEditArea(requiredEA[x], ea) LogStream.logEvent("Saved ", zoneList[x], "under", requiredEA[x]) # special EAs (source,destination) special = [("ISC_Send_Area","FireArea"), ("ISC_Send_Area", "area3")] for s in special: refData = refMgr.loadRefSet(ReferenceID(s[0])) ea = ReferenceData(refData) ea.setId(ReferenceID(s[1])) refMgr.saveRefSet(ea) #ea = self.__client.getEditAreaPolygons(s[0]) #self.__client.saveEditArea(s[1], ea) LogStream.logEvent("Saved ", s[0], "under", s[1]) # topography simulated based edit areas # area3 = whole area, AboveElev, BelowElev LogStream.logEvent("Calculating topo-dependent edit areas...") topo = self.__dataMgr.getParmManager().getParmInExpr("Topo", True) topogrid = GridCycler.getInstance().getCorrespondingResult( topo, TimeRange.allTimes().toJavaObj(), "TimeWtAverage") topogrid = topogrid[0].getGridSlice().__numpy__[0] iscSend = ReferenceID('ISC_Send_Area') #wholeGrid = self.__client.getEditArea("ISC_Send_Area") wholeGrid = refMgr.loadRefSet(iscSend).getGrid().__numpy__[0] topoAve = 0 count = 0 minx, maxx, miny, maxy = self.__extremaOfSetBits(wholeGrid) for x in range(minx, maxx): for y in range(miny, maxy): if wholeGrid[y,x] == 1: count = count + 1 topoAve = topoAve + topogrid[y,x] topoAve = topoAve / count aboveGrid = wholeGrid * 0 belowGrid = wholeGrid * 0 for x in xrange(topogrid.shape[1]): for y in xrange(topogrid.shape[0]): if wholeGrid[y,x] == 1: if topogrid[y,x] > topoAve: aboveGrid[y,x] = 1 else: belowGrid[y,x] = 1 # area1 and area2 need to be "BelowElev", but should be different # than area3 desiredCount = 2000 count = 0 area1 = wholeGrid * 0 area2 = wholeGrid * 0 for x in xrange(topogrid.shape[1]): if count < desiredCount: for y in xrange(topogrid.shape[0]): if wholeGrid[y,x] == 0 and topogrid[y,x] < topoAve: area1[y,x] = 1 belowGrid[y,x] = 1 count = count + 1 count = 0 for x in xrange(topogrid.shape[1]): if count < desiredCount: for y in xrange(topogrid.shape[0]): if wholeGrid[y,x] == 0 and topogrid[y,x] < topoAve and \ area1[y,x] == 0: area2[y,x] = 1 belowGrid[y,x] = 1 count = count + 1 # save all topography-dependent edit areas self.__saveEA("area1", area1) LogStream.logEvent("Saved area1 based on area2, area3, and topo <", topoAve) self.__saveEA("area2", area2) LogStream.logEvent("Saved area2 based on area1, area3, and topo <", topoAve) self.__saveEA("AboveElev", aboveGrid) LogStream.logEvent("Saved AboveElev based on area3 > ", topoAve) self.__saveEA("BelowElev", belowGrid) LogStream.logEvent("Saved BelowElev based on area3 <= ", topoAve) self.__saveEA("Ridges", aboveGrid) LogStream.logEvent("Saved Ridges based on area3 > ", topoAve) self.__saveEA("Valleys", belowGrid) LogStream.logEvent("Saved Valleys based on area3 < ", topoAve) self.__saveEA("Inland", aboveGrid) LogStream.logEvent("Saved Ridges based on area3 > ", topoAve) self.__saveEA("Coastal", belowGrid) LogStream.logEvent("Saved Valleys based on area3 < ", topoAve) #city areas, which are a small part of other edit areas cityBased = [("area1",["city1","city2"]), ("area2", ["city3"]), ("area3",["city4", "area3_pt"])] for baseArea,cityAreas in cityBased: #wholeGrid = self.__client.getEditArea(baseArea) wholeGrid = refMgr.loadRefSet(ReferenceID(baseArea)).getGrid().__numpy__[0] minx, maxx, miny, maxy = self.__extremaOfSetBits(wholeGrid) cNumber = 0 print minx, maxx, miny, maxy, wholeGrid.shape for x in range(minx, maxx): for y in range(miny, maxy): if wholeGrid[y,x] == 1: if cNumber >= len(cityAreas): break cityGrid = numpy.logical_and(wholeGrid, 0) cityGrid[y,x] = 1 self.__saveEA(cityAreas[cNumber], cityGrid.astype('int8')) LogStream.logEvent("Saved ", cityAreas[cNumber], "based on:", baseArea) cNumber = cNumber + 1 # special for ISC areas for CCF database source test #txt = self.__eagdb["ISC"] #iscList = cPickle.loads(txt) textID = TextFileUtil.getTextFile('ISC', 'editAreaGroups') iscList = [] textFile = open(textID.getFile().getPath()) textFile.readline() for line in textFile: iscList.append(line.rstrip()) textFile.close() count = 0 while count < 6: for i in iscList: if i == "ISC_Send_Area" or i == "ISC_Tool_Area": continue wholeGrid = refMgr.loadRefSet(ReferenceID(i)).getGrid().__numpy__[0] minx, maxx, miny, maxy = self.__extremaOfSetBits(wholeGrid) if minx == -1: continue ok = 1 print minx, maxx, miny, maxy, wholeGrid.shape for x in range(minx, maxx): if ok: for y in range(miny, maxy): if wholeGrid[y,x] == 1: ptGrid = numpy.logical_and(wholeGrid, 0) ptGrid[y,x] = 1 name = "isc" + `count` self.__saveEA(name, ptGrid.astype('int8')) requiredEA.append(name) LogStream.logEvent("Saved ", name, "based on ", i) ok = 0 break else: break count = count + 1 if count > 6: break # store an edit area group with all of the generated edit areas requiredEA.append("FireArea") requiredEA.append("AboveElev") requiredEA.append("BelowElev") requiredEA.append("Valleys") requiredEA.append("Ridges") requiredEA.append("Inland") requiredEA.append("Coastal") requiredEA.append("city1") requiredEA.append("city2") requiredEA.append("city3") requiredEA.append("city4") requiredEA.append("area3") requiredEA.append("area2") requiredEA.append("area1") refMgr.saveGroup("GFETest", JUtil.pylistToJavaStringList(requiredEA)) time.sleep(.5)