Compare commits
No commits in common. "eb3be4cb515b4afb2c1f6af623b44d4c1ee61473" and "a7296c943b23e16828919ce9e4b1e8d45e83e822" have entirely different histories.
eb3be4cb51
...
a7296c943b
|
@ -14,31 +14,6 @@ Leg = dict[str, str]
|
||||||
|
|
||||||
TravelList = list[dict[str, typing.Any]]
|
TravelList = list[dict[str, typing.Any]]
|
||||||
|
|
||||||
RouteDistances = dict[tuple[str, str], float]
|
|
||||||
|
|
||||||
|
|
||||||
def coords(airport: StrDict) -> tuple[float, float]:
|
|
||||||
"""Longitude / Latitude as coordinate tuples."""
|
|
||||||
# return (airport["longitude"], airport["latitude"])
|
|
||||||
return (airport["latitude"], airport["longitude"])
|
|
||||||
|
|
||||||
|
|
||||||
def flight_distance(f: StrDict) -> float:
|
|
||||||
"""Distance of flight."""
|
|
||||||
return float(geodesic(coords(f["from_airport"]), coords(f["to_airport"])).km)
|
|
||||||
|
|
||||||
|
|
||||||
def route_distances_as_json(route_distances: RouteDistances) -> str:
|
|
||||||
"""Format route distances as JSON string."""
|
|
||||||
return (
|
|
||||||
"[\n"
|
|
||||||
+ ",\n".join(
|
|
||||||
" " + json.dumps([s1, s2, dist])
|
|
||||||
for (s1, s2), dist in route_distances.items()
|
|
||||||
)
|
|
||||||
+ "\n]"
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def parse_yaml(travel_type: str, data_dir: str) -> TravelList:
|
def parse_yaml(travel_type: str, data_dir: str) -> TravelList:
|
||||||
"""Parse flights YAML and return list of travel."""
|
"""Parse flights YAML and return list of travel."""
|
||||||
|
@ -92,6 +67,9 @@ def all_events(data_dir: str) -> list[Event]:
|
||||||
return get_trains(data_dir) + get_flights(data_dir)
|
return get_trains(data_dir) + get_flights(data_dir)
|
||||||
|
|
||||||
|
|
||||||
|
RouteDistances = dict[tuple[str, str], float]
|
||||||
|
|
||||||
|
|
||||||
def train_leg_distance(geojson_data: StrDict) -> float:
|
def train_leg_distance(geojson_data: StrDict) -> float:
|
||||||
"""Calculate the total length of a LineString in kilometers from GeoJSON data."""
|
"""Calculate the total length of a LineString in kilometers from GeoJSON data."""
|
||||||
# Extract coordinates
|
# Extract coordinates
|
||||||
|
@ -103,6 +81,7 @@ def train_leg_distance(geojson_data: StrDict) -> float:
|
||||||
else:
|
else:
|
||||||
first_object["type"] == "MultiLineString"
|
first_object["type"] == "MultiLineString"
|
||||||
coord_list = first_object["coordinates"]
|
coord_list = first_object["coordinates"]
|
||||||
|
# pprint(coordinates)
|
||||||
|
|
||||||
total_length_km = 0.0
|
total_length_km = 0.0
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
"""Trips."""
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from datetime import date, datetime, time
|
from datetime import date, datetime, time
|
||||||
from zoneinfo import ZoneInfo
|
from zoneinfo import ZoneInfo
|
||||||
|
@ -75,8 +73,6 @@ def load_flights(data_dir: str) -> list[StrDict]:
|
||||||
flight["to_airport"] = airports[flight["to"]]
|
flight["to_airport"] = airports[flight["to"]]
|
||||||
if "airline" in flight:
|
if "airline" in flight:
|
||||||
flight["airline_name"] = airlines.get(flight["airline"], "[unknown]")
|
flight["airline_name"] = airlines.get(flight["airline"], "[unknown]")
|
||||||
|
|
||||||
flight["distance"] = travel.flight_distance(flight)
|
|
||||||
return flights
|
return flights
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -98,10 +98,7 @@
|
||||||
| <a href="https://uk.flightaware.com/live/flight/{{ full_flight_number | replace("U2", "EZY") }}">FlightAware</a>
|
| <a href="https://uk.flightaware.com/live/flight/{{ full_flight_number | replace("U2", "EZY") }}">FlightAware</a>
|
||||||
| <a href="{{ radarbox_url }}">radarbox</a>
|
| <a href="{{ radarbox_url }}">radarbox</a>
|
||||||
</div>
|
</div>
|
||||||
<div class="grid-item text-end">
|
<div class="grid-item">
|
||||||
{% if item.distance %}
|
|
||||||
{{ "{:,.0f} km / {:,.0f} miles".format(item.distance, item.distance / 1.60934) }}
|
|
||||||
{% endif %}
|
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
|
|
@ -110,7 +110,7 @@ async def weekends() -> str:
|
||||||
def travel_list() -> str:
|
def travel_list() -> str:
|
||||||
"""Page showing a list of upcoming travel."""
|
"""Page showing a list of upcoming travel."""
|
||||||
data_dir = app.config["PERSONAL_DATA"]
|
data_dir = app.config["PERSONAL_DATA"]
|
||||||
flights = agenda.trip.load_flights(data_dir)
|
flights = travel.parse_yaml("flights", data_dir)
|
||||||
trains = [
|
trains = [
|
||||||
item
|
item
|
||||||
for item in travel.parse_yaml("trains", data_dir)
|
for item in travel.parse_yaml("trains", data_dir)
|
||||||
|
|
Loading…
Reference in a new issue