Move trip new-country filtering into stats
This commit is contained in:
parent
ddfa77b152
commit
f22772d12d
5 changed files with 27 additions and 15 deletions
|
|
@ -33,10 +33,13 @@ def conferences(trip: Trip, yearly_stats: Mapping[int, StrDict]) -> None:
|
|||
yearly_stats[c["start"].year]["conferences"] += 1
|
||||
|
||||
|
||||
def calculate_yearly_stats(trips: list[Trip]) -> dict[int, StrDict]:
|
||||
def calculate_yearly_stats(
|
||||
trips: list[Trip], previously_visited: set[str] | None = None
|
||||
) -> dict[int, StrDict]:
|
||||
"""Calculate total distance and distance by transport type grouped by year."""
|
||||
yearly_stats: defaultdict[int, StrDict] = defaultdict(dict)
|
||||
first_visit_year: dict[str, int] = {}
|
||||
excluded_new: set[str] = previously_visited or set()
|
||||
|
||||
for trip in trips:
|
||||
year = trip.start.year
|
||||
|
|
@ -72,7 +75,10 @@ def calculate_yearly_stats(trips: list[Trip]) -> dict[int, StrDict]:
|
|||
continue
|
||||
yearly_stats[year].setdefault("countries", set())
|
||||
yearly_stats[year]["countries"].add(country)
|
||||
if first_visit_year.get(country.alpha_2) == year:
|
||||
if (
|
||||
first_visit_year.get(country.alpha_2) == year
|
||||
and country.alpha_2 not in excluded_new
|
||||
):
|
||||
yearly_stats[year].setdefault("new_countries", set())
|
||||
yearly_stats[year]["new_countries"].add(country)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue