Compare commits
4 commits
6444229694
...
bc6fc33cda
Author | SHA1 | Date | |
---|---|---|---|
|
bc6fc33cda | ||
|
938d8a5afe | ||
|
bab1d25dd4 | ||
|
b2cef3933d |
|
@ -211,6 +211,26 @@ def add_coordinates_for_unbooked_flights(
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def stations_from_travel(t: StrDict) -> list[StrDict]:
|
||||||
|
"""Stations from train journey."""
|
||||||
|
station_list = [t["from_station"], t["to_station"]]
|
||||||
|
for leg in t["legs"]:
|
||||||
|
station_list.append(leg["from_station"])
|
||||||
|
station_list.append(leg["to_station"])
|
||||||
|
|
||||||
|
return station_list
|
||||||
|
|
||||||
|
|
||||||
|
def process_station_list(station_list: list[StrDict]) -> StrDict:
|
||||||
|
"""Proess sation list."""
|
||||||
|
stations = {}
|
||||||
|
for s in station_list:
|
||||||
|
if s["name"] in stations:
|
||||||
|
continue
|
||||||
|
stations[s["name"]] = s
|
||||||
|
return stations
|
||||||
|
|
||||||
|
|
||||||
def get_locations(trip: Trip) -> dict[str, StrDict]:
|
def get_locations(trip: Trip) -> dict[str, StrDict]:
|
||||||
"""Collect locations of all travel locations in trip."""
|
"""Collect locations of all travel locations in trip."""
|
||||||
locations: dict[str, StrDict] = {
|
locations: dict[str, StrDict] = {
|
||||||
|
@ -223,10 +243,7 @@ def get_locations(trip: Trip) -> dict[str, StrDict]:
|
||||||
for t in trip.travel:
|
for t in trip.travel:
|
||||||
match t["type"]:
|
match t["type"]:
|
||||||
case "train":
|
case "train":
|
||||||
station_list += [t["from_station"], t["to_station"]]
|
station_list += stations_from_travel(t)
|
||||||
for leg in t["legs"]:
|
|
||||||
station_list.append(leg["from_station"])
|
|
||||||
station_list.append(leg["to_station"])
|
|
||||||
case "flight":
|
case "flight":
|
||||||
for field in "from_airport", "to_airport":
|
for field in "from_airport", "to_airport":
|
||||||
if field in t:
|
if field in t:
|
||||||
|
@ -236,11 +253,7 @@ def get_locations(trip: Trip) -> dict[str, StrDict]:
|
||||||
terminal = t[field]
|
terminal = t[field]
|
||||||
locations["ferry_terminal"][terminal["name"]] = terminal
|
locations["ferry_terminal"][terminal["name"]] = terminal
|
||||||
|
|
||||||
for s in station_list:
|
locations["station"] = process_station_list(station_list)
|
||||||
if s["name"] in locations["station"]:
|
|
||||||
continue
|
|
||||||
locations["station"][s["name"]] = s
|
|
||||||
|
|
||||||
return locations
|
return locations
|
||||||
|
|
||||||
|
|
||||||
|
@ -376,7 +389,7 @@ def get_trip_routes(trip: Trip, data_dir: str) -> list[StrDict]:
|
||||||
for item in trip.conferences
|
for item in trip.conferences
|
||||||
if "latitude" in item
|
if "latitude" in item
|
||||||
and "longitude" in item
|
and "longitude" in item
|
||||||
and item["country"] not in ("gb", "be") # not flying to Belgium
|
and item["country"] not in {"gb", "be", "fr"} # not flying to Belgium or France
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -73,20 +73,21 @@ class Trip:
|
||||||
return self.name
|
return self.name
|
||||||
titles: list[str] = [conf["name"] for conf in self.conferences] + [
|
titles: list[str] = [conf["name"] for conf in self.conferences] + [
|
||||||
event["title"] for event in self.events
|
event["title"] for event in self.events
|
||||||
]
|
] or self.titles_from_travel()
|
||||||
if not titles:
|
|
||||||
for travel in self.travel:
|
|
||||||
if travel["depart"] and utils.as_date(travel["depart"]) != self.start:
|
|
||||||
place = travel["from"]
|
|
||||||
if place not in titles:
|
|
||||||
titles.append(place)
|
|
||||||
if travel["depart"] and utils.as_date(travel["depart"]) != self.end:
|
|
||||||
place = travel["to"]
|
|
||||||
if place not in titles:
|
|
||||||
titles.append(place)
|
|
||||||
|
|
||||||
return format_list_with_ampersand(titles) or "[unnamed trip]"
|
return format_list_with_ampersand(titles) or "[unnamed trip]"
|
||||||
|
|
||||||
|
def titles_from_travel(self) -> list[str]:
|
||||||
|
"""Titles from travel."""
|
||||||
|
titles = []
|
||||||
|
for travel in self.travel:
|
||||||
|
if not (depart := (travel["depart"] and utils.as_date(travel["depart"]))):
|
||||||
|
continue
|
||||||
|
for when, from_or_to in ((self.start, "from"), (self.end, "to")):
|
||||||
|
if depart != when and travel["from_or_to"] not in titles:
|
||||||
|
titles.append(travel["from_or_to"])
|
||||||
|
return titles
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def end(self) -> datetime.date | None:
|
def end(self) -> datetime.date | None:
|
||||||
"""End date for trip."""
|
"""End date for trip."""
|
||||||
|
|
|
@ -56,7 +56,9 @@ def check_flights(airlines: set[str]) -> None:
|
||||||
assert "trip" in booking
|
assert "trip" in booking
|
||||||
assert all(flight["airline"] in airlines for flight in booking["flights"])
|
assert all(flight["airline"] in airlines for flight in booking["flights"])
|
||||||
flight_count += len(booking["flights"])
|
flight_count += len(booking["flights"])
|
||||||
co2_flight_count += len([flight for flight in booking["flights"] if "co2_kg" in flight])
|
co2_flight_count += len(
|
||||||
|
[flight for flight in booking["flights"] if "co2_kg" in flight]
|
||||||
|
)
|
||||||
check_currency(booking)
|
check_currency(booking)
|
||||||
|
|
||||||
if prev_first_depart:
|
if prev_first_depart:
|
||||||
|
@ -65,8 +67,10 @@ def check_flights(airlines: set[str]) -> None:
|
||||||
), "Bookings are not in chronological order by first flight's departure."
|
), "Bookings are not in chronological order by first flight's departure."
|
||||||
prev_first_depart = booking["flights"][0]["depart"]
|
prev_first_depart = booking["flights"][0]["depart"]
|
||||||
|
|
||||||
print(f"{len(bookings)} flight bookings, {flight_count} flights, "
|
print(
|
||||||
f"{co2_flight_count} with CO2 numbers")
|
f"{len(bookings)} flight bookings, {flight_count} flights, "
|
||||||
|
f"{co2_flight_count} with CO2 numbers"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def check_trains() -> None:
|
def check_trains() -> None:
|
||||||
|
|
Loading…
Reference in a new issue