Skip to content

Commit 50a8260

Browse files
committed
nesh_timelines_season_summary_plot
1 parent 4e7d092 commit 50a8260

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

openskistats/nesh/timelines.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from pathlib import Path
1919
from typing import Any, ClassVar, Literal
2020

21+
import numpy as np
22+
import plotnine as pn
2123
import polars as pl
2224
import requests
2325
from bs4 import BeautifulSoup
@@ -226,6 +228,51 @@ def _nesh_timeline_aggregators() -> list[pl.Expr]:
226228
]
227229

228230

231+
def nesh_timelines_season_summary() -> pl.DataFrame:
232+
return (
233+
read_nesh_timelines_skimap_key()
234+
.group_by("season")
235+
.agg(
236+
*_nesh_timeline_aggregators(),
237+
)
238+
)
239+
240+
241+
def nesh_timelines_season_summary_plot() -> pn.ggplot:
242+
df = nesh_timelines_season_summary()
243+
date_offset_breaks, date_offset_labels = get_date_offset_breaks_and_labels()
244+
return (
245+
pn.ggplot(
246+
df,
247+
pn.aes(
248+
x="season",
249+
ymin="opening_date_offset_mean",
250+
ymax="closing_date_offset_mean",
251+
),
252+
)
253+
+ pn.geom_linerange(mapping=pn.aes(color="season_duration_count"), size=1.3)
254+
+ pn.geom_point(
255+
mapping=pn.aes(y="opening_date_offset_mean", color="opening_date_count"),
256+
stroke=0,
257+
size=2.5,
258+
)
259+
+ pn.geom_point(
260+
mapping=pn.aes(y="closing_date_offset_mean", color="closing_date_count"),
261+
stroke=0,
262+
size=2.5,
263+
)
264+
+ pn.scale_x_continuous(breaks=np.arange(1930, 2050, 10), name="")
265+
+ pn.scale_y_continuous(
266+
breaks=date_offset_breaks,
267+
labels=date_offset_labels,
268+
name="Mean Opening to Closing Date",
269+
)
270+
+ pn.scale_color_cmap(cmap_name="Blues", name="Ski Areas", trans="sqrt")
271+
+ pn.theme_bw()
272+
+ pn.theme(figure_size=(10, 5))
273+
)
274+
275+
229276
nesh_to_skimap = {
230277
"https://www.newenglandskihistory.com/NewHampshire/abenaki.php": "https://skimap.org/skiareas/view/4091",
231278
"https://www.newenglandskihistory.com/NewHampshire/arrowhead.php": "https://skimap.org/skiareas/view/2146",

0 commit comments

Comments
 (0)