From ee20b9809169f58db504f404d6bc3a7d7e2a6ebb Mon Sep 17 00:00:00 2001 From: Ewan Croft Date: Thu, 13 Aug 2026 15:38:42 +0100 Subject: [PATCH] feat(tourmaline): expose monthlyArtistPlays on ListenerProfile MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The aggregator already computes per-month artist play counts internally (AggregatedData.monthlyArtistPlays), but nothing surfaced it on the client-facing ListenerProfile. Needed as the data source for an upcoming bar-chart-race visualization — serialized as sorted tuples rather than a Map since it needs to round-trip through component props/state cleanly. --- packages/tourmaline/src/lib/client/load-profile.ts | 3 +++ packages/tourmaline/src/lib/types.ts | 6 ++++++ 2 files changed, 9 insertions(+) diff --git a/packages/tourmaline/src/lib/client/load-profile.ts b/packages/tourmaline/src/lib/client/load-profile.ts index 81453b3..9747012 100644 --- a/packages/tourmaline/src/lib/client/load-profile.ts +++ b/packages/tourmaline/src/lib/client/load-profile.ts @@ -159,6 +159,9 @@ export function computeProfile( albumMilestones: data.albumMilestones, longestNotListenedGap: data.longestNotListenedGap, recommendations: buildRecommendations(data.topArtists, data.allArtists, artistInfos), + monthlyArtistPlays: [...data.monthlyArtistPlays.entries()] + .sort(([a], [b]) => a.localeCompare(b)) + .map(([month, plays]) => [month, [...plays.entries()]]), }; const sessions = deriveSessions(filtered); diff --git a/packages/tourmaline/src/lib/types.ts b/packages/tourmaline/src/lib/types.ts index dd4cf32..90d7c46 100644 --- a/packages/tourmaline/src/lib/types.ts +++ b/packages/tourmaline/src/lib/types.ts @@ -137,6 +137,12 @@ export interface ListenerProfile { albumMilestones: Milestone[]; longestNotListenedGap: Gap | null; recommendations: Recommendation[]; + /** + * Chronologically ordered per-month artist play counts, serialized as + * tuples (Maps don't survive structured cloning the way we need for + * $state). Used by the bar-chart-race visualization. + */ + monthlyArtistPlays: Array<[month: string, plays: Array<[artist: string, count: number]>]>; } export interface UnusualMonth { -- 2.51.2