Retrieves the top skipped artists based on skip count and percentage

Analyzes the artist-level skip statistics across the entire listening history and returns a list of artists whose tracks are skipped most frequently. This function helps identify potential patterns in artist preferences and listening behavior.

The analysis includes:

  • Total skip count for each artist's tracks
  • Skip percentage (skips relative to total plays)
  • Number of tracks played for each artist
  • Sorting by skip frequency with percentage as a secondary factor

This data is useful for understanding which artists' music the user tends to skip more frequently, which may indicate changing music preferences or context-dependent listening patterns.

// Display the top 3 most frequently skipped artists
const topSkippedArtists = await getTopSkippedArtists(3);
renderArtistSkipChart(topSkippedArtists);
export const getTopSkippedArtists = async (
limit: number = 5,
): Promise<
Array<{
id: string;
name: string;
skipCount: number;
trackCount: number;
skipPercentage: number;
}>
> => {
try {
const statistics = await getStatistics();

// Group tracks by artist and calculate aggregate statistics
const artistStats: Record<
string,
{
id: string;
name: string;
skipCount: number;
trackCount: number;
totalTracks: number;
}
> = {};

// Process track metrics to aggregate by artist
Object.values(statistics.trackMetrics).forEach((track) => {
const artistId = track.id.split(":")[0] || "unknown"; // Generate an ID if we don't have one
const artistName = track.artistName || "Unknown Artist";

if (!artistStats[artistId]) {
artistStats[artistId] = {
id: artistId,
name: artistName,
skipCount: 0,
trackCount: 0,
totalTracks: 0,
};
}

artistStats[artistId].skipCount += track.skipCount || 0;
artistStats[artistId].trackCount += track.playCount || 0;
artistStats[artistId].totalTracks += 1;
});

// Convert to array, calculate skip percentage, and sort by skipCount
const artists = Object.values(artistStats)
.map((artist) => ({
id: artist.id,
name: artist.name,
skipCount: artist.skipCount,
trackCount: artist.trackCount,
skipPercentage:
artist.trackCount > 0
? Math.round((artist.skipCount / artist.trackCount) * 100)
: 0,
}))
.filter((artist) => artist.skipCount > 0) // Only include artists with skips
.sort(
(a, b) =>
b.skipCount - a.skipCount || b.skipPercentage - a.skipPercentage,
) // Sort by skip count, then percentage
.slice(0, limit); // Take only the specified number of artists

return artists;
} catch (error) {
console.error("Error getting top skipped artists:", error);
return [];
}
};
  • Parameters

    • limit: number = 5

      Maximum number of artists to return (default: 5)

    Returns Promise<
        {
            id: string;
            name: string;
            skipCount: number;
            trackCount: number;
            skipPercentage: number;
        }[],
    >

    Promise resolving to an array of artists sorted by skip frequency