Пример #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
Пример #2
0
    def get_cells(self):
        neLat, neLon, swLat, swLon, oNeLat, oNeLon, oSwLat, oSwLon = getBoundParameter(
            request)
        timestamp = request.args.get("timestamp", None)

        data = self._db.get_cells_in_rectangle(neLat=neLat,
                                               neLon=neLon,
                                               swLat=swLat,
                                               swLon=swLon,
                                               oNeLat=oNeLat,
                                               oNeLon=oNeLon,
                                               oSwLat=oSwLat,
                                               oSwLon=oSwLon,
                                               timestamp=timestamp)

        ret = []
        for cell in data:
            ret.append({
                "id": str(cell["id"]),
                "polygon": S2Helper.coords_of_cell(cell["id"]),
                "updated": cell["updated"]
            })

        return jsonify(ret)