コード例 #1
0
    def read(self, requestid=None):
        print("In current driver")
        response = requests.get(self.url)
        json_data = json.loads(response.text)
        if 'currently' not in json_data: return

        logging.info("currently {0}".format(json_data['currently']))
        nearestStormDistance =  json_data['currently'].get('nearestStormDistance',None)
        nearestStormBearing =   json_data['currently'].get('nearestStormBearing',None)
        precipIntensity =       json_data['currently'].get('precipIntensity',None)
        apparentTemperature =   json_data['currently'].get('apparentTemperature',None)
        humidity =              json_data['currently'].get('humidity',None)
        #print(json_data['currently'])
        if humidity is not None:
            humidity *= 100 # change from decimal to percent

        msg = xbos_pb2.XBOS(
            XBOSIoTDeviceState = iot_pb2.XBOSIoTDeviceState(
                time = int(time.time()*1e9),
                weather_station = weather_station_pb2.WeatherStation(
                    nearestStormDistance  =   types.Double(value=nearestStormDistance),
                    nearestStormBearing   =   types.Double(value=nearestStormBearing),
                    precipIntensity        =   types.Double(value=precipIntensity),
                    temperature             =   types.Double(value=apparentTemperature),
                    humidity                =   types.Double(value=humidity),
                )
            )
        )
        self.report(self.coords, msg)
コード例 #2
0
    def read(self, requestid=None):
        print("In prediction driver")
        response = requests.get(self.url)
        json_data = json.loads(response.text)
        if 'hourly' not in json_data: return

        hourly = json_data['hourly']
        #print(json_data)
        predictions = []
        output = {}

        for hour in hourly.get('data',[]):
            for key, value in hour.items():
                output[key] = value
            if 'humidity' in output:
                output['humidity'] *= 100 # change from decimal to percent
            #print(hour)
            timestamp = int(hour.get('time') * 1e9) # nanoseconds
            predictions.append(weather_station_pb2.WeatherStationPrediction.Prediction(
                prediction_time=timestamp,
                prediction=weather_station_pb2.WeatherStation(
                    time  =   types.Int64(value=output.get('time',None)),
                    icon  =  output.get('icon',None),
                    nearestStormDistance  =   types.Double(value=output.get('nearestStormDistance',None)),
                    nearestStormBearing  =   types.Double(value=output.get('nearestStormBearing',None)),
                    precipIntensity  =   types.Double(value=output.get('precipIntensity',None)),
                    precipIntensityError  =   types.Double(value=output.get('precipIntensityError',None)),
                    precipProbability  =   types.Double(value=output.get('precipProbability',None)),
                    precipType  =  output.get('precipType',None),
                    temperature  =   types.Double(value=output.get('temperature',None)),
                    apparentTemperature  =   types.Double(value=output.get('apparentTemperature',None)),
                    dewPoint  =   types.Double(value=output.get('dewPoint',None)),
                    humidity  =   types.Double(value=output.get('humidity',None)),
                    pressure  =   types.Double(value=output.get('pressure',None)),
                    windSpeed  =   types.Double(value=output.get('windSpeed',None)),
                    windGust  =   types.Double(value=output.get('windGust',None)),
                    windBearing  =   types.Double(value=output.get('windBearing',None)),
                    cloudCover  =   types.Double(value=output.get('cloudCover',None)),
                    uvIndex  =   types.Double(value=output.get('uvIndex',None)),
                    visibility  =   types.Double(value=output.get('visibility',None)),
                    ozone  =   types.Double(value=output.get('ozone',None)),
                )
            ))
            #print(predictions)

        msg = xbos_pb2.XBOS(
            XBOSIoTDeviceState = iot_pb2.XBOSIoTDeviceState(
                time = int(time.time()*1e9),
                weather_station_prediction = weather_station_pb2.WeatherStationPrediction(
                    predictions=predictions
                )
            )
        )
        self.report(self.coords+'/prediction', msg)
コード例 #3
0
    def read(self, requestid=None):
        response = requests.get(self.url)
        json_data = json.loads(response.text)
        if 'currently' not in json_data: return

        logging.info("currently {0}".format(json_data['currently']))
        print(json_data['currently'])
        output = {}
        for key, value in json_data['currently'].items():
            output[key] = value

        #print(json_data['currently'])
        if 'humidity' in output:
            output['humidity'] *= 100 # change from decimal to percent

        msg = xbos_pb2.XBOS(
            XBOSIoTDeviceState = iot_pb2.XBOSIoTDeviceState(
                time = int(time.time()*1e9),
                weather_station = weather_station_pb2.WeatherStation(
                    time  =   types.Int64(value=output.get('time',None)),
                    icon  =  output.get('icon',None),
                    nearestStormDistance  =   types.Double(value=output.get('nearestStormDistance',None)),
                    nearestStormBearing  =   types.Double(value=output.get('nearestStormBearing',None)),
                    precipIntensity  =   types.Double(value=output.get('precipIntensity',None)),
                    precipIntensityError  =   types.Double(value=output.get('precipIntensityError',None)),
                    precipProbability  =   types.Double(value=output.get('precipProbability',None)),
                    precipType  =  output.get('precipType',None),
                    temperature  =   types.Double(value=output.get('temperature',None)),
                    apparentTemperature  =   types.Double(value=output.get('apparentTemperature',None)),
                    dewPoint  =   types.Double(value=output.get('dewPoint',None)),
                    humidity  =   types.Double(value=output.get('humidity',None)),
                    pressure  =   types.Double(value=output.get('pressure',None)),
                    windSpeed  =   types.Double(value=output.get('windSpeed',None)),
                    windGust  =   types.Double(value=output.get('windGust',None)),
                    windBearing  =   types.Double(value=output.get('windBearing',None)),
                    cloudCover  =   types.Double(value=output.get('cloudCover',None)),
                    uvIndex  =   types.Double(value=output.get('uvIndex',None)),
                    visibility  =   types.Double(value=output.get('visibility',None)),
                    ozone  =   types.Double(value=output.get('ozone',None)),
                )
            )
        )
        self.report(self.coords, msg)
コード例 #4
0
    def read(self, requestid=None):
        print("In prediction driver")
        response = requests.get(self.url)
        json_data = json.loads(response.text)
        if 'hourly' not in json_data: return

        hourly = json_data['hourly']
        #print(json_data)
        predictions = []

        for hour in hourly.get('data',[]):
            timestamp = int(hour.get('time') * 1e9) # nanoseconds
            temperature = hour.get('apparentTemperature', None)
            precipIntensity = hour.get('precipIntensity', None)
            precipProbability = hour.get('precipProbability', None)
            humidity = hour.get('humidity', None)
            if humidity is not None:
                humidity *= 100 # change from decimal to percent

            predictions.append(weather_station_pb2.WeatherStationPrediction.Prediction(
                prediction_time=timestamp,
                prediction=weather_station_pb2.WeatherStation(
                    temperature=types.Double(value=temperature),
                    precipIntensity=types.Double(value=precipIntensity),
                    humidity=types.Double(value=humidity),
                )
            ))

        msg = xbos_pb2.XBOS(
            XBOSIoTDeviceState = iot_pb2.XBOSIoTDeviceState(
                time = int(time.time()*1e9),
                weather_prediction = weather_station_pb2.WeatherStationPrediction(
                    predictions=predictions
                )
            )
        )
        self.report(self.coords+'/prediction', msg)