From e65d1c796cf7605ba7a0ab2afa00d342f4c15ce7 Mon Sep 17 00:00:00 2001 From: Wesley Ray Date: Wed, 27 May 2026 19:35:42 -0400 Subject: [PATCH] Name the GPS k-means areas by their marquee ride Replace the "Area N" fallbacks with derived names: Kiddieland (lowest mean PC2) plus The Woodies / The Grand Midway / Flying Turns Grove / Giant Wheel Corner, each keyed off the headline ride that lands in the cluster so the labels survive re-clustering as the wait history grows. Co-Authored-By: Claude Opus 4.7 --- app.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/app.py b/app.py index a77ad2c..22a9011 100644 --- a/app.py +++ b/app.py @@ -170,8 +170,10 @@ def compute_pca(): loadings = loadings.join(meta) # Spatial "areas" from GPS alone — k-means on standardized lat/lon, the same - # 5 clusters the write-up uses. Label the one whose rides lean most negative - # on PC2 as Kiddieland so the colors read in plain English. + # 5 clusters the write-up uses. Names are derived, not hard-coded to a + # cluster index, so they survive re-clustering as the history grows: + # - Kiddieland = the cluster whose rides lean most negative on PC2. + # - the rest are named for the marquee ride that lands in each. located = loadings.dropna(subset=["lat", "lon"]) if len(located) >= 5: km = KMeans(n_clusters=5, n_init=10, random_state=0).fit_predict( @@ -179,6 +181,13 @@ def compute_pca(): area = pd.Series(km, index=located.index) kiddie = loadings.loc[area.index].assign(a=area).groupby("a")["PC2"].mean().idxmin() names = {kiddie: "Kiddieland"} + anchors = [("phoenix", "The Woodies"), + ("impulse", "The Grand Midway"), + ("flying_turns", "Flying Turns Grove"), + ("giant_wheel", "Giant Wheel Corner")] + for ride, label in anchors: + if ride in area.index: + names.setdefault(area[ride], label) # don't overwrite Kiddieland loadings["area"] = area.map(lambda a: names.get(a, f"Area {a + 1}")) else: loadings["area"] = "Untagged"