Exemplo n.º 1
0
    def __prepare_weather_data(self, weather_data):
        ret = []

        for weather in weather_data:
            weather_payload = {
                "s2_cell_id": weather["s2_cell_id"],
                "condition": weather["gameplay_weather"],
                "alert_severity": weather["severity"],
                "day": weather["world_time"],
                "time_changed": weather["last_updated"],
            }

            # required by PA but not provided by Monocle
            if weather.get("latitude", None) is None:
                weather_payload["latitude"] = S2Helper.middle_of_cell(
                    weather["s2_cell_id"])[0]
            else:
                weather_payload["latitude"] = weather["latitude"]

            if weather.get("longitude", None) is None:
                weather_payload["longitude"] = S2Helper.middle_of_cell(
                    weather["s2_cell_id"])[1]
            else:
                weather_payload["longitude"] = weather["longitude"]

            if weather.get("coords", None) is None:
                weather_payload["coords"] = S2Helper.coords_of_cell(
                    weather["s2_cell_id"])
            else:
                weather_payload["coords"] = weather["coords"]

            entire_payload = {"type": "weather", "message": weather_payload}
            ret.append(entire_payload)

        return ret
Exemplo n.º 2
0
    def _extract_args_single_weather(self, client_weather_data, time_of_day,
                                     received_timestamp):
        now = datetime.utcfromtimestamp(
            time.time()).strftime("%Y-%m-%d %H:%M:%S")
        cell_id = client_weather_data["cell_id"]
        real_lat, real_lng = S2Helper.middle_of_cell(cell_id)

        display_weather_data = client_weather_data.get("display_weather", None)
        if display_weather_data is None:
            return None
        else:
            gameplay_weather = client_weather_data["gameplay_weather"][
                "gameplay_condition"]

        return (
            cell_id,
            real_lat,
            real_lng,
            display_weather_data.get("cloud_level", 0),
            display_weather_data.get("rain_level", 0),
            display_weather_data.get("wind_level", 0),
            display_weather_data.get("snow_level", 0),
            display_weather_data.get("fog_level", 0),
            display_weather_data.get("wind_direction", 0),
            gameplay_weather,
            # TODO: alerts
            0,
            0,
            time_of_day,
            now)
Exemplo n.º 3
0
    def __extract_args_single_weather(self, client_weather_data, time_of_day, received_timestamp):
        now = datetime.utcfromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')
        cell_id = client_weather_data["cell_id"]
        real_lat, real_lng = S2Helper.middle_of_cell(cell_id)

        display_weather_data = client_weather_data.get("display_weather", None)
        if display_weather_data is None:
            return None
        elif time_of_day == 2 and client_weather_data["gameplay_weather"]["gameplay_condition"] == 3:
            gameplay_weather = 13
        else:
            gameplay_weather = client_weather_data["gameplay_weather"]["gameplay_condition"]

        now_timezone = datetime.fromtimestamp(float(received_timestamp))
        now_timezone = time.mktime(now_timezone.timetuple()) - (self.timezone * 60 * 60)

        self.webhook_helper.send_weather_webhook(cell_id, gameplay_weather, 0, 0,
                                                 time_of_day, now_timezone)

        return (
            cell_id, real_lat, real_lng,
            display_weather_data.get("cloud_level", 0),
            display_weather_data.get("rain_level", 0),
            display_weather_data.get("wind_level", 0),
            display_weather_data.get("snow_level", 0),
            display_weather_data.get("fog_level", 0),
            display_weather_data.get("wind_direction", 0),
            gameplay_weather,
            # TODO: alerts
            0, 0,
            time_of_day, now
        )
Exemplo n.º 4
0
    def update_insert_weather(self, cell_id, gameplay_weather, capture_time, cloud_level=0, rain_level=0, wind_level=0,
                              snow_level=0, fog_level=0, wind_direction=0, weather_daytime=0):
        log.debug("{RmWrapper::update_insert_weather} called")
        now_timezone = datetime.fromtimestamp(float(capture_time))
        now_timezone = time.mktime(now_timezone.timetuple()) - (self.timezone * 60 * 60)
        now = now = datetime.utcfromtimestamp(time.time()).strftime('%Y-%m-%d %H:%M:%S')

        real_lat, real_lng = S2Helper.middle_of_cell(cell_id)
        if weather_daytime == 2 and gameplay_weather == 3:
            gameplay_weather = 13

        # TODO: put severity and warn_weather properly
        query = 'INSERT INTO weather (s2_cell_id, latitude, longitude, cloud_level, rain_level, wind_level, ' \
                'snow_level, fog_level, wind_direction, gameplay_weather, severity, warn_weather, world_time, ' \
                'last_updated) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, \'%s\') ' \
                'ON DUPLICATE KEY UPDATE fog_level=%s, cloud_level=%s, snow_level=%s, wind_direction=%s, ' \
                'world_time=%s, latitude=%s, longitude=%s, gameplay_weather=%s, last_updated=\'%s\''
        data = (cell_id, real_lat, real_lng, cloud_level, rain_level, wind_level, snow_level, fog_level,
                wind_direction, gameplay_weather, None, None, weather_daytime, str(now),
                fog_level, cloud_level, snow_level, wind_direction, weather_daytime, real_lat, real_lng,
                gameplay_weather, str(now))

        self.execute(query, data, commit=True)

        self.webhook_helper.send_weather_webhook(
            cell_id, gameplay_weather, 0, 0, weather_daytime, now_timezone
        )