Creates a high-level overview of the most important listening metrics
for dashboard display and quick insights. This function extracts and
calculates essential values from the full statistics data structure.
The summary includes:
Total number of unique tracks played
Total skips across all time periods
Overall skip percentage (ratio of skips to plays)
Today's skip count (current day statistics)
Current week's skip count
Current month's skip count
Average time before skipping (in seconds)
This summary provides a quick snapshot of listening behavior without
the need to process the full statistics data structure, making it
ideal for dashboard displays and regular UI updates.
// Calculate this week's skips constnow = newDate(); conststartOfWeek = newDate(now); startOfWeek.setDate(now.getDate() - now.getDay()); // Set to beginning of week (Sunday) letweekSkips = 0;
// Sum up skips for each day in the current week Object.entries(statistics.dailyMetrics).forEach(([dateStr, metrics]) => { constdate = newDate(dateStr); if (date >= startOfWeek && date <= now) { weekSkips += metrics.tracksSkipped; } });
// Sum up skips for each day in the current month Object.entries(statistics.dailyMetrics).forEach(([dateStr, metrics]) => { constdate = newDate(dateStr); if (date >= startOfMonth && date <= now) { monthSkips += metrics.tracksSkipped; } });
// Calculate average skip time (in seconds) lettotalSkipTimeMs = 0; letskipCount = 0;
Object.values(statistics.trackMetrics).forEach((track) => { if (track.skipCount > 0 && track.avgCompletionPercent !== undefined) { // Only count tracks that have been skipped consttrackDuration = 180000; // Default to 3 minutes if we don't have actual duration constavgSkipTimeForTrack = (track.avgCompletionPercent / 100) * trackDuration; totalSkipTimeMs += avgSkipTimeForTrack * track.skipCount; skipCount += track.skipCount; } });
constavgSkipTime = skipCount > 0 ? Math.round(totalSkipTimeMs / skipCount / 1000) // Convert to seconds : 60; // Default to 60 seconds if no data
Generates a concise summary of key statistics
Creates a high-level overview of the most important listening metrics for dashboard display and quick insights. This function extracts and calculates essential values from the full statistics data structure.
The summary includes:
This summary provides a quick snapshot of listening behavior without the need to process the full statistics data structure, making it ideal for dashboard displays and regular UI updates.
Example
Source