Exemplo n.º 1
0
 def getStationObservations(self, stationProperty, dbObj, active, sourceToXeniaMap, uomConverter, rowEntryDate, platformId):
   sensorRecs = []
   sensors = ""
   for obsProperty in stationProperty.observedProperty:
     #The attribute is a url to the observation. We're not going to follow the url, we just want the
     #observation name so split the url up and get the last piece.
     obsType = obsProperty.attrib['{http://www.w3.org/1999/xlink}href'].split('/')[-1]
     #Use the obsType to get the xenia observation.
     xeniaObs = sourceToXeniaMap.getXeniaFromDifObs(obsType)
     if(xeniaObs != None and len(xeniaObs)):
       for xeniaOb in xeniaObs:
         sensors += "obsName: %s\n" % (xeniaOb)
         #Get the dif column name from the xenia observation name.
         difObs = sourceToXeniaMap.getDifColNameFromXenia(xeniaOb)
         if(difObs):
           obsParts = re.findall("^(\w*)\s*\((.{1,})\)", difObs)
           #Get the xenia units. If we get None back, then we'll assume we're in the correct units.
           uom = uomConverter.getXeniaUOMName(obsParts[0][1].lower())
           if(uom == None):
             uom = obsParts[0][1].lower()
           #Get the m_type_id for the sensor rec.
           mType = dbObj.mTypeExists(xeniaOb, uom)
           if(mType):
             newSensor = sensor()
             #DWR 2013-06-12
             if(platformId):
               #To add a new sensor to the DB, it's got to have a platform id.
               newSensor.platform_id = platformId
             newSensor.row_entry_date = rowEntryDate
             newSensor.active = active
             newSensor.m_type_id = mType
             newSensor.s_order = 1
             newSensor.short_name = xeniaOb
             sensorRecs.append(newSensor)
             if(self.logger):
               self.logger.info("Found sensor: %s MType: %d SOrder: %d" % (newSensor.short_name,newSensor.m_type_id,newSensor.s_order))                          
           else:
             if(self.logger):
               self.logger.error("Unable to find the m_type for Obs: %s(%s)" % (xeniaOb, uom))
               sys.exit(-1)
         else:
           if(self.logger):
             self.logger.error("Could not find dif Observation for xenia: %s" %(xeniaOb))
     else: 
       if(self.logger):
         self.logger.error("GetCapabilities observedProperty: %s not found in xenia obs mapping." %(obsType))                      
   return(sensorRecs)
Exemplo n.º 2
0
            sensors = ""
            if (rec.sensors):
                for sensorRec in rec.sensors:
                    if (addnewobservationstodb):
                        try:
                            if (self.logger):
                                self.logger.info(
                                    "Platform: %s(%d) adding new sensor m_type: %d to database."
                                    % (rec.platform_handle,
                                       sensorRec.platform_id,
                                       sensorRec.m_type_id))

                            self.db.addRec(
                                sensor(platform_id=sensorRec.platform_id,
                                       row_entry_date=sensorRec.row_entry_date,
                                       active=sensorRec.active,
                                       m_type_id=sensorRec.m_type_id,
                                       s_order=sensorRec.s_order,
                                       short_name=sensorRec.short_name), True)
                            #self.db.addRec(sensorRec, True)
                        except Exception, e:
                            if (self.logger):
                                self.logger.exception(e)
                                sys.exit(-1)
                    if (len(sensors)):
                        sensors += "\n"
                    sensors += sensorRec.short_name
                activeStatus = 'Inactive'
                if (rec.active <= 3):
                    activeStatus = "Active"

                if (newPlatformsKML):
Exemplo n.º 3
0
        except Exception,e:
          if(self.logger):
            self.logger.exception(e)
            sys.exit(-1)  
            
        
    for rec in platsMissingObs:
      sensors = ""
      if(rec.sensors):
        for sensorRec in rec.sensors:
          if(addnewobservationstodb):
            try:
              if(self.logger):
                self.logger.info("Platform: %s(%d) adding new sensor m_type: %d to database." % (rec.platform_handle, sensorRec.platform_id, sensorRec.m_type_id))

              self.db.addRec(sensor(platform_id = sensorRec.platform_id, row_entry_date = sensorRec.row_entry_date, active = sensorRec.active, m_type_id = sensorRec.m_type_id, s_order = sensorRec.s_order, short_name = sensorRec.short_name), True)
              #self.db.addRec(sensorRec, True)              
            except Exception,e:
              if(self.logger):
                self.logger.exception(e)
                sys.exit(-1)  
          if(len(sensors)):
            sensors += "\n"
          sensors += sensorRec.short_name
        activeStatus = 'Inactive'
        if(rec.active <= 3):
          activeStatus = "Active"
          
        if(newPlatformsKML):
          pmDesc = "Active Status: %s\n\nDescription: %s\n\nSensors:\n\t%s" % (activeStatus, rec.description, sensors)
          pm = newPlatformsKML.createPlacemark(rec.platform_handle, rec.fixed_latitude, rec.fixed_longitude, pmDesc)