예제 #1
0
    def export(self, file_type):
        if (not request.args.get('bounds') and not request.args.get('ids')):
            return Response(json.dumps([]), mimetype='application/json')

        if not TransnetDownloadLog.add_log(
                uuid=request.args.get("token"),
                bounds=request.args.get("bounds"),
                countries=request.args.get("countries"),
                voltages=request.args.get("voltages"),
                relations_ids=request.args.get('ids'),
                file_type=file_type):
            return make_response('Bad Formatted User Token', 400)

        countries = None
        voltages = None
        if request.args.get("countries"):
            countries = request.args.get("countries").split(',')
        if request.args.get("voltages"):
            voltages = [
                int(v) for v in request.args.get("voltages").split(',')
            ]

        relations = None
        if request.args.get('bounds') is not None:
            bounds_parts = request.args.get("bounds").split(',')
            relations = TransnetRelation.get_filtered_relations(
                bounds_parts, voltages, countries, None)

        if request.args.get('ids') is not None:
            relations_ids = request.args.get("ids").split(',')
            relations = TransnetRelation.relations_for_export(relations_ids)

        return relations
예제 #2
0
    def stations_info(self):
        if not request.args.get('relation_id'):
            return Response(json.dumps([]), mimetype='application/json')
        relation_id = request.args.get("relation_id")

        relations = TransnetRelation.get_station_info(relation_id)

        return render_template('stations_info.html', relations=relations)
예제 #3
0
    def evaluations(self):
        if not request.args.get("countries"):
            return Response(json.dumps([]), mimetype='application/json')

        return render_template(
            'evaluations.html',
            countries_stats=TransnetRelation.get_evaluations(
                request.args.get("countries").split(',')))
예제 #4
0
    def export_cim(self):
        if (not request.args.get('bounds') and not request.args.get('ids')):
            return Response(json.dumps([]), mimetype='application/json')

        if not TransnetDownloadLog.add_log(
                uuid=request.args.get("token"),
                countries=request.args.get("countries"),
                voltages=request.args.get("voltages"),
                relations_ids=request.args.get("ids"),
                bounds=request.args.get('bounds'),
                file_type=TransnetExportType.CIM):
            return make_response('Bad Formatted User Token', 400)

        countries = None
        voltages = None
        if request.args.get("countries"):
            countries = request.args.get("countries").split(',')
        if request.args.get("voltages"):
            voltages = [
                int(v) for v in request.args.get("voltages").split(',')
            ]

        relations = None
        map_centroid = None
        if request.args.get('bounds') is not None:
            bounds_parts = request.args.get("bounds").split(',')
            relations, map_centroid = TransnetRelation.with_points_and_lines_in_bounds(
                bounds_parts, voltages, countries)

        if request.args.get('ids') is not None:
            relations_ids = request.args.get("ids").split(',')
            relations, map_centroid = TransnetRelation.relations_for_export(
                relations_ids)

        headers = {
            'Content-Type':
            'application/zip',
            'Content-Disposition':
            'attachment; filename=CIM-%s.zip' % datetime.now()
        }

        cim_writer = CimWriter(relations, map_centroid)

        return Response(cim_writer.publish(), headers=headers)
예제 #5
0
    def index(self):
        if not request.args.get('bounds'):
            return Response(json.dumps([]), mimetype='application/json')
        bounds_parts = request.args.get("bounds").split(',')

        zoom = request.args.get('zoom')

        countries = None
        voltages = None
        if request.args.get("countries"):
            countries = request.args.get("countries").split(',')
        if request.args.get("voltages"):
            voltages = [
                int(v) for v in request.args.get("voltages").split(',')
            ]

        relations = TransnetRelation.get_filtered_relations(
            bounds_parts, voltages, countries, zoom)

        return Response(json.dumps(relations), mimetype='application/json')
예제 #6
0
    def export_countries(self, file_type):
        if not request.args.get("countries"):
            return Response(json.dumps([]), mimetype='application/json')

        if not TransnetDownloadLog.add_log(
                uuid=request.args.get("token"),
                countries=request.args.get("countries"),
                voltages=request.args.get("voltages"),
                file_type=file_type):
            return make_response('Bad Formatted User Token', 400)

        voltages = None
        bounds_parts = None
        countries = request.args.get("countries").split(',')
        if request.args.get("voltages"):
            voltages = [
                int(v) for v in request.args.get("voltages").split(',')
            ]

        return TransnetRelation.get_filtered_relations(bounds_parts, voltages,
                                                       countries, None)