implement reviewer comments
- rename road_usage -> segments (as we're actually dealing with segments not with roads) - use "select as" to ensure defined behaviour - cleanup
This commit is contained in:
parent
e1763e0d3c
commit
da82303042
|
@ -122,22 +122,22 @@ async def export_events(req):
|
||||||
raise InvalidUsage("unknown export format")
|
raise InvalidUsage("unknown export format")
|
||||||
|
|
||||||
|
|
||||||
@api.get(r"/export/road_usage")
|
@api.get(r"/export/segments")
|
||||||
async def export_road_usage(req):
|
async def export_segments(req):
|
||||||
async with use_request_semaphore(req, "export_semaphore", timeout=30):
|
async with use_request_semaphore(req, "export_semaphore", timeout=30):
|
||||||
bbox = req.ctx.get_single_arg(
|
bbox = req.ctx.get_single_arg(
|
||||||
"bbox", default="-180,-90,180,90"
|
"bbox", default="-180,-90,180,90"
|
||||||
)
|
)
|
||||||
assert re.match(r"(-?\d+\.?\d+,?){4}", bbox)
|
assert re.match(r"(-?\d+\.?\d+,?){4}", bbox)
|
||||||
fmt = req.ctx.get_single_arg("fmt", convert=ExportFormat)
|
fmt = req.ctx.get_single_arg("fmt", convert=ExportFormat)
|
||||||
events = await req.ctx.db.stream(
|
segments = await req.ctx.db.stream(
|
||||||
text(
|
text(
|
||||||
f"select ST_AsGeoJSON(ST_Transform(geometry,4326)), way_id, distance_overtaker_mean, distance_overtaker_min,distance_overtaker_max,distance_overtaker_median,overtaking_event_count,usage_count,direction,zone,offset_direction,distance_overtaker_array from layer_obs_roads(ST_Transform(ST_MakeEnvelope({bbox},4326),3857),11,NULL,'1900-01-01'::timestamp,'2100-01-01'::timestamp) WHERE usage_count>0"
|
f"select ST_AsGeoJSON(ST_Transform(geometry,4326)) AS geometry, way_id, distance_overtaker_mean, distance_overtaker_min,distance_overtaker_max,distance_overtaker_median,overtaking_event_count,usage_count,direction,zone,offset_direction,distance_overtaker_array from layer_obs_roads(ST_Transform(ST_MakeEnvelope({bbox},4326),3857),11,NULL,'1900-01-01'::timestamp,'2100-01-01'::timestamp) WHERE usage_count>0"
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if fmt == ExportFormat.SHAPEFILE:
|
if fmt == ExportFormat.SHAPEFILE:
|
||||||
with shapefile_zip(shape_type=3, basename="road_usage") as (writer, zip_buffer):
|
with shapefile_zip(shape_type=3, basename="segments") as (writer, zip_buffer):
|
||||||
writer.field("distance_overtaker_mean", "N", decimal=4)
|
writer.field("distance_overtaker_mean", "N", decimal=4)
|
||||||
writer.field("distance_overtaker_max", "N", decimal=4)
|
writer.field("distance_overtaker_max", "N", decimal=4)
|
||||||
writer.field("distance_overtaker_min", "N", decimal=4)
|
writer.field("distance_overtaker_min", "N", decimal=4)
|
||||||
|
@ -148,41 +148,40 @@ async def export_road_usage(req):
|
||||||
writer.field("direction", "N", decimal=0)
|
writer.field("direction", "N", decimal=0)
|
||||||
writer.field("zone", "C")
|
writer.field("zone", "C")
|
||||||
|
|
||||||
async for road in events:
|
async for segment in segments:
|
||||||
geom = json.loads(road.st_asgeojson)
|
geom = json.loads(segment.st_asgeojson)
|
||||||
writer.line([geom["coordinates"]])
|
writer.line([geom["coordinates"]])
|
||||||
writer.record(
|
writer.record(
|
||||||
distance_overtaker_mean=road.distance_overtaker_mean,
|
distance_overtaker_mean=segment.distance_overtaker_mean,
|
||||||
distance_overtaker_median=road.distance_overtaker_median,
|
distance_overtaker_median=segment.distance_overtaker_median,
|
||||||
distance_overtaker_max=road.distance_overtaker_max,
|
distance_overtaker_max=segment.distance_overtaker_max,
|
||||||
distance_overtaker_min=road.distance_overtaker_min,
|
distance_overtaker_min=segment.distance_overtaker_min,
|
||||||
usage_count=road.usage_count,
|
usage_count=segment.usage_count,
|
||||||
overtaking_event_count=road.overtaking_event_count,
|
overtaking_event_count=segment.overtaking_event_count,
|
||||||
direction=road.direction,
|
direction=segment.direction,
|
||||||
way_id=road.way_id,
|
way_id=segment.way_id,
|
||||||
zone=road.zone,
|
zone=segment.zone,
|
||||||
# "time"=event.time,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return raw(zip_buffer.getbuffer())
|
return raw(zip_buffer.getbuffer())
|
||||||
|
|
||||||
if fmt == ExportFormat.GEOJSON:
|
if fmt == ExportFormat.GEOJSON:
|
||||||
features = []
|
features = []
|
||||||
async for road in events:
|
async for segment in segments:
|
||||||
features.append(
|
features.append(
|
||||||
{
|
{
|
||||||
"type": "Feature",
|
"type": "Feature",
|
||||||
"geometry": json.loads(road.st_asgeojson),
|
"geometry": json.loads(segment.geometry),
|
||||||
"properties": {
|
"properties": {
|
||||||
"distance_overtaker_mean": road.distance_overtaker_mean,
|
"distance_overtaker_mean": segment.distance_overtaker_mean,
|
||||||
"distance_overtaker_max": road.distance_overtaker_max,
|
"distance_overtaker_max": segment.distance_overtaker_max,
|
||||||
"distance_overtaker_median": road.distance_overtaker_median,
|
"distance_overtaker_median": segment.distance_overtaker_median,
|
||||||
"overtaking_event_count": road.overtaking_event_count,
|
"overtaking_event_count": segment.overtaking_event_count,
|
||||||
"usage_count": road.usage_count,
|
"usage_count": segment.usage_count,
|
||||||
"distance_overtaker_array": road.distance_overtaker_array,
|
"distance_overtaker_array": segment.distance_overtaker_array,
|
||||||
"direction": road.direction,
|
"direction": segment.direction,
|
||||||
"way_id": road.way_id,
|
"way_id": segment.way_id,
|
||||||
"zone": road.zone,
|
"zone": segment.zone,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
|
@ -104,7 +104,7 @@ const BoundingBoxSelector = React.forwardRef(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const MODES = ["events", "road_usage"];
|
const MODES = ["events", "segments"];
|
||||||
const FORMATS = ["geojson", "shapefile"];
|
const FORMATS = ["geojson", "shapefile"];
|
||||||
|
|
||||||
export default function ExportPage() {
|
export default function ExportPage() {
|
||||||
|
|
|
@ -95,7 +95,7 @@ ExportPage:
|
||||||
label: Modus
|
label: Modus
|
||||||
placeholder: Modus wählen
|
placeholder: Modus wählen
|
||||||
events: Überholvorgänge
|
events: Überholvorgänge
|
||||||
road_usage: Straßennutzung
|
segments: Straßenstatistiken
|
||||||
format:
|
format:
|
||||||
label: Format
|
label: Format
|
||||||
placeholder: Format wählen
|
placeholder: Format wählen
|
||||||
|
|
|
@ -101,7 +101,7 @@ ExportPage:
|
||||||
label: Mode
|
label: Mode
|
||||||
placeholder: Select mode
|
placeholder: Select mode
|
||||||
events: Events
|
events: Events
|
||||||
road_usage: Road usage
|
segments: Road statistics
|
||||||
format:
|
format:
|
||||||
label: Format
|
label: Format
|
||||||
placeholder: Select format
|
placeholder: Select format
|
||||||
|
|
|
@ -102,7 +102,7 @@ ExportPage:
|
||||||
label: Mode
|
label: Mode
|
||||||
placeholder: Sélectionner un mode
|
placeholder: Sélectionner un mode
|
||||||
events: Evénements
|
events: Evénements
|
||||||
road_usage: Utilisation des rues
|
segments: Statistiques des rues
|
||||||
format:
|
format:
|
||||||
label: Format
|
label: Format
|
||||||
placeholder: Sélectionner un format
|
placeholder: Sélectionner un format
|
||||||
|
|
Loading…
Reference in a new issue