parent
4a990a9fe5
commit
fd34190368
3 changed files with 123 additions and 22 deletions
|
|
@ -143,38 +143,42 @@ def get_trip_routes(trip: Trip) -> list[StrDict]:
|
|||
if "from_airport" not in t or "to_airport" not in t:
|
||||
continue
|
||||
fly_from, fly_to = t["from_airport"], t["to_airport"]
|
||||
key = "_".join(["flight"] + sorted([fly_from["iata"], fly_to["iata"]]))
|
||||
routes.append(
|
||||
{
|
||||
"type": "flight",
|
||||
"key": key,
|
||||
"from": latlon_tuple(fly_from),
|
||||
"to": latlon_tuple(fly_to),
|
||||
}
|
||||
)
|
||||
|
||||
else:
|
||||
assert t["type"] == "train"
|
||||
for leg in t["legs"]:
|
||||
train_from, train_to = leg["from_station"], leg["to_station"]
|
||||
geojson_filename = train_from.get("routes", {}).get(train_to["uic"])
|
||||
if not geojson_filename:
|
||||
routes.append(
|
||||
{
|
||||
"type": "train",
|
||||
"from": latlon_tuple(train_from),
|
||||
"to": latlon_tuple(train_to),
|
||||
}
|
||||
)
|
||||
continue
|
||||
|
||||
if geojson_filename in seen_geojson:
|
||||
continue
|
||||
seen_geojson.add(geojson_filename)
|
||||
|
||||
continue
|
||||
assert t["type"] == "train"
|
||||
for leg in t["legs"]:
|
||||
train_from, train_to = leg["from_station"], leg["to_station"]
|
||||
geojson_filename = train_from.get("routes", {}).get(train_to["uic"])
|
||||
key = "_".join(["train"] + sorted([train_from["name"], train_to["name"]]))
|
||||
if not geojson_filename:
|
||||
routes.append(
|
||||
{
|
||||
"type": "train",
|
||||
"geojson": read_geojson(geojson_filename),
|
||||
"key": key,
|
||||
"from": latlon_tuple(train_from),
|
||||
"to": latlon_tuple(train_to),
|
||||
}
|
||||
)
|
||||
continue
|
||||
|
||||
if geojson_filename in seen_geojson:
|
||||
continue
|
||||
seen_geojson.add(geojson_filename)
|
||||
|
||||
routes.append(
|
||||
{
|
||||
"type": "train",
|
||||
"key": key,
|
||||
"geojson_filename": geojson_filename,
|
||||
}
|
||||
)
|
||||
|
||||
return routes
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue