The complete statistics data structure
The total number of unique artists encountered in the listening history
export function calculateUniqueArtistCount(statistics: StatisticsData): number {
const allArtists = new Set<string>();
// Collect from daily metrics
for (const dateKey in statistics.dailyMetrics) {
const metric = statistics.dailyMetrics[dateKey];
if (metric.uniqueArtists instanceof Set) {
Array.from(metric.uniqueArtists).forEach((id) => allArtists.add(id));
} else if (Array.isArray(metric.uniqueArtists)) {
metric.uniqueArtists.forEach((id) => allArtists.add(id));
}
}
// Collect from artist metrics directly (more reliable)
for (const artistId in statistics.artistMetrics) {
allArtists.add(artistId);
}
return allArtists.size;
}
Calculate the total unique artist count from all metrics
Determines the total number of distinct artists present in the user's listening history across all time periods. This function employs a Set data structure to ensure each artist is counted only once regardless of how many tracks or listening sessions they appear in.
The counting process includes:
This metric is essential for measuring music discovery and diversity in the user's listening patterns, forming the basis for artist-related analytics and visualizations.