diff --git a/openskistats/nesh/tests/test_timelines.py b/openskistats/nesh/tests/test_timelines.py new file mode 100644 index 0000000000..f7753527bf --- /dev/null +++ b/openskistats/nesh/tests/test_timelines.py @@ -0,0 +1,21 @@ +from datetime import date + +import polars as pl + +from openskistats.nesh.timelines import read_nesh_timelines_skimap_key + + +def test_read_nesh_timelines_skimap_key() -> None: + df = read_nesh_timelines_skimap_key() + whaleback_2023_timeline = df.row( + by_predicate=pl.col.skimap_url.eq( + "https://skimap.org/skiareas/view/1078" + ).__and__(pl.col.season == 2023), + named=True, + ) + assert whaleback_2023_timeline["opening_date"] == date.fromisoformat("2023-12-26") + assert whaleback_2023_timeline["closing_date"] == date.fromisoformat("2024-03-10") + assert whaleback_2023_timeline["season_duration"] == 75 + assert whaleback_2023_timeline["nesh_sources"] == [ + "https://www.newenglandskihistory.com/NewHampshire/whaleback.php" + ] diff --git a/openskistats/nesh/timelines.py b/openskistats/nesh/timelines.py index 9e11f0b7f7..9dc42790dd 100644 --- a/openskistats/nesh/timelines.py +++ b/openskistats/nesh/timelines.py @@ -147,12 +147,30 @@ def read_nesh_timelines() -> pl.DataFrame: ) .drop("opening", "closing") .with_columns( - season_duration=pl.col("closing_date").sub("opening_date").dt.total_days() + season_duration=pl.col("closing_date").sub("opening_date").dt.total_days(), + skimap_url=pl.col("ski_area_page").replace_strict(nesh_to_skimap), ) ) return df +def read_nesh_timelines_skimap_key() -> pl.DataFrame: + return ( + read_nesh_timelines() + .filter(pl.col("skimap_url").is_not_null()) + .group_by("skimap_url", "season") + .agg( + pl.min("opening_date"), + pl.max("closing_date"), + pl.col("ski_area_page").alias("nesh_sources"), + ) + .with_columns( + season_duration=pl.col("closing_date").sub("opening_date").dt.total_days(), + ) + .sort("skimap_url", "season") + ) + + nesh_to_skimap = { "https://www.newenglandskihistory.com/NewHampshire/abenaki.php": "https://skimap.org/skiareas/view/4091", "https://www.newenglandskihistory.com/NewHampshire/arrowhead.php": "https://skimap.org/skiareas/view/2146",