|
18 | 18 | from pathlib import Path
|
19 | 19 | from typing import Any, ClassVar, Literal
|
20 | 20 |
|
| 21 | +import numpy as np |
| 22 | +import plotnine as pn |
21 | 23 | import polars as pl
|
22 | 24 | import requests
|
23 | 25 | from bs4 import BeautifulSoup
|
@@ -226,6 +228,51 @@ def _nesh_timeline_aggregators() -> list[pl.Expr]:
|
226 | 228 | ]
|
227 | 229 |
|
228 | 230 |
|
| 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 | + |
229 | 276 | nesh_to_skimap = {
|
230 | 277 | "https://www.newenglandskihistory.com/NewHampshire/abenaki.php": "https://skimap.org/skiareas/view/4091",
|
231 | 278 | "https://www.newenglandskihistory.com/NewHampshire/arrowhead.php": "https://skimap.org/skiareas/view/2146",
|
|
0 commit comments