Skip to content

Commit

Permalink
read_nesh_timelines_skimap_key
Browse files Browse the repository at this point in the history
  • Loading branch information
dhimmel committed Jan 26, 2025
1 parent 0c5df69 commit ad87511
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
21 changes: 21 additions & 0 deletions openskistats/nesh/tests/test_timelines.py
Original file line number Diff line number Diff line change
@@ -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"
]
20 changes: 19 additions & 1 deletion openskistats/nesh/timelines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ad87511

Please sign in to comment.