Esempio n. 1
0
    def post(self):
        global norm_radius
        global norm_color
        distro = self.get_argument("distro")
        routes = self.get_argument("routes", [])
        filters = json.loads(self.get_argument("filters", "[]"))
        paris = self.get_argument("paris")
        date = self.get_argument("date")
        flow_passagers = self.get_argument("flow_passagers")
        min_flow = self.get_argument("min_flow")
        max_flow = self.get_argument("max_flow")

        """
        AFFICHER LES DISTRO
        """
        features = []
        points, properties = sql.get_points(distro, filters, date)
        min_value = properties["min_value"]
        max_value = properties["max_value"]
        data_label = properties["data_label"]
        avg_value = properties["avg_value"]
        for p in points:
            # stop_id, , , , stop_cp, data_id, data_value
            lon, lat, name, transfers = (
                p["stop_lon"],
                p["stop_lat"],
                p["stop_name"],
                sql.get_transfers(p["stop_name"], date),
            )
            data_value = p["data_value"] if "data_value" in p else "0"
            radius = norm_radius(min_value, max_value, data_value)

            color = norm_color(min_value, max_value, data_value)
            feature = {
                "type": "Feature",
                "geometry": {"type": "Point", "coordinates": [lon, lat]},
                "properties": {
                    "stop_name": name,
                    "stop_transfers": transfers,
                    "data_value": data_value,
                    "radius": radius,
                    "fill_color": color,
                    "stop_cp": p["stop_cp"],
                    "rapport_avg": p["rapport_avg"],
                },
            }
            features.append(feature)

        distro_dic = {"type": "FeatureCollection", "features": features}

        features = []
        if paris != "0":
            for row in sql.get_paris():
                arr_coord, arr_name, arr_cp = row["arr_geo"], row["arr_name"], row["arr_cp"]
                barycentre_lon, barycentre_lat = row["barycentre_lon"], row["barycentre_lat"]
                feature = {
                    "type": "Feature",
                    "geometry": {"type": "Polygon", "coordinates": json.loads(arr_coord)},
                    "properties": {"arr_name": arr_name, "arr_cp": arr_cp},
                }
                features.append(feature)

                # feature = {
                #     "type": "Feature",
                #     "geometry": {
                #         "type": "Point",
                #         "coordinates": [barycentre_lon, barycentre_lat]
                #     },
                #     "properties": {
                #         "stop_name": "BARYCENTRE",
                #         "stop_transfers": '',
                #         "data_value": "VALUE",
                #         "radius": 10,
                #         "fill_color": "#ff9922"
                #     }
                # }
                # features.append(feature)
        paris_dic = {"type": "FeatureCollection", "features": features}

        features = []
        if flow_passagers == "1":
            chemins = sql.get_flow_passages(min_flow, max_flow)
            bound_min, bound_max = sql.get_flow_bounds()
            for row in chemins:
                feature = {
                    "chemin": json.loads(row["chemin"]),
                    "value": norm_radius(bound_min, bound_max, row["value"]),
                    "color": norm_color(bound_min, bound_max, row["value"]),
                }
                features.append(feature)
        flows = features

        features = []
        if routes != 0:
            for row in sql.get_routes(filters, date):
                route_multilinestring = row["multilinestring"]
                color = row["color"]
                # print route_linestring
                feature = {
                    "type": "Feature",
                    "geometry": {"type": "MultiLineString", "coordinates": json.loads(route_multilinestring)},
                    "properties": {"color": color},
                }
                features.append(feature)
        routes_dic = {"type": "FeatureCollection", "features": features}
        geo = {
            "distro": distro_dic,
            "properties_distro": {"data_label": data_label, "avg_value": avg_value},
            "paris": paris_dic,
            "routes": routes_dic,
            "flow": flows,
        }

        geojsons = json.dumps(geo)

        with open("geojsons.txt", "w") as f:
            f.write(geojsons)

        self.write(geojsons)
Esempio n. 2
0
 def get(self):
     flux_min, flux_max = sql.get_flow_bounds()
     result = {"flux_min": int(flux_min), "flux_max": int(flux_max)}
     return self.write(json.dumps(result))