custom_components/nea_sg_weather/nea.py
def calc_wind_status(self, wind_speed, wind_direction):
        """Function to aggregate wind readings into a single aggregated value"""
        result = {
            "ns_sum": 0,
            "ns_avg": 0,
            "ew_sum": 0,
            "ew_avg": 0,
            "readings_used": 0,
            "agg_wind_speed": 0,
            "agg_wind_direction": 0,
        }
        for wind_speed_reading in wind_speed:
            for wind_direction_reading in wind_direction:
                if (
                    wind_speed_reading["station_id"]
                    == wind_direction_reading["station_id"]
                ):
                    result["ns_sum"] += wind_speed_reading["value"] * math.cos(
                        math.radians(wind_direction_reading["value"] + 180)
                    )
                    result["ew_sum"] += wind_speed_reading["value"] * math.sin(
                        math.radians(wind_direction_reading["value"] + 180)
                    )
                    result["readings_used"] += 1
        result["ns_avg"] = result["ns_sum"] / result["readings_used"]
        result["ew_avg"] = result["ew_sum"] / result["readings_used"]
        result["agg_wind_speed"] = math.sqrt(
            math.pow(result["ns_avg"], 2) + math.pow(result["ew_avg"], 2)
        )
        result["agg_wind_direction"] = math.degrees(
            math.atan2(result["ew_avg"], result["ns_avg"])
        )
        if result["agg_wind_direction"] < 0:
            result["agg_wind_direction"] += 360
        return result
Function to aggregate wind readings into a single aggregated value
Function to aggregate wind readings into a single aggregated value
Function to aggregate wind readings into a single aggregated value
def calc_wind_status(self, wind_speed, wind_direction):
        result = {
            "ns_sum": 0,
            "ns_avg": 0,
            "ew_sum": 0,
            "ew_avg": 0,
            "readings_used": 0,
            "agg_wind_speed": 0,
            "agg_wind_direction": 0,
        }
        for wind_speed_reading in wind_speed:
            for wind_direction_reading in wind_direction:
                if (
                    wind_speed_reading["station_id"]
                    == wind_direction_reading["station_id"]
                ):
                    result["ns_sum"] += wind_speed_reading["value"] * math.cos(
                        math.radians(wind_direction_reading["value"] + 180)
                    )
                    result["ew_sum"] += wind_speed_reading["value"] * math.sin(
                        math.radians(wind_direction_reading["value"] + 180)
                    )
                    result["readings_used"] += 1
        result["ns_avg"] = result["ns_sum"] / result["readings_used"]
        result["ew_avg"] = result["ew_sum"] / result["readings_used"]
        result["agg_wind_speed"] = math.sqrt(
            math.pow(result["ns_avg"], 2) + math.pow(result["ew_avg"], 2)
        )
        result["agg_wind_direction"] = math.degrees(
            math.atan2(result["ew_avg"], result["ns_avg"])
        )
        if result["agg_wind_direction"] < 0:
            result["agg_wind_direction"] += 360
        return result
def calc_wind_status ( self , wind_speed , wind_direction ) : result = { "ns_sum" : 0 , "ns_avg" : 0 , "ew_sum" : 0 , "ew_avg" : 0 , "readings_used" : 0 , "agg_wind_speed" : 0 , "agg_wind_direction" : 0 , } for wind_speed_reading in wind_speed : for wind_direction_reading in wind_direction : if ( wind_speed_reading [ "station_id" ] == wind_direction_reading [ "station_id" ] ) : result [ "ns_sum" ] += wind_speed_reading [ "value" ] * math . cos ( math . radians ( wind_direction_reading [ "value" ] + 180 ) ) result [ "ew_sum" ] += wind_speed_reading [ "value" ] * math . sin ( math . radians ( wind_direction_reading [ "value" ] + 180 ) ) result [ "readings_used" ] += 1 result [ "ns_avg" ] = result [ "ns_sum" ] / result [ "readings_used" ] result [ "ew_avg" ] = result [ "ew_sum" ] / result [ "readings_used" ] result [ "agg_wind_speed" ] = math . sqrt ( math . pow ( result [ "ns_avg" ] , 2 ) + math . pow ( result [ "ew_avg" ] , 2 ) ) result [ "agg_wind_direction" ] = math . degrees ( math . atan2 ( result [ "ew_avg" ] , result [ "ns_avg" ] ) ) if result [ "agg_wind_direction" ] < 0 : result [ "agg_wind_direction" ] += 360 return result
Function to aggregate wind readings into a single aggregated value
Function to aggregate wind readings into a single aggregated value
"""Function to aggregate wind readings into a single aggregated value"""
self
wind_speed
wind_direction