Module statistics/aggregator

Statistics Aggregation Service

This module provides comprehensive data aggregation and analytics functionality for processing raw listening data into meaningful statistical insights. It forms the analytical core of the application, transforming raw event data into actionable insights and visualization-ready datasets.

Features:

  • Multi-dimensional aggregation across time periods (daily, weekly, monthly)
  • Artist, track, and genre-level analytics with engagement metrics
  • Skip pattern detection and behavior classification
  • Temporal analysis of listening habits (time of day, day of week)
  • Device usage and context-based analytics (playlists, albums)
  • Data normalization and outlier handling for reliable metrics
  • Advanced statistical calculations (distributions, moving averages)
  • Persistent storage of aggregated results with efficient indexing
  • Incremental processing to handle large datasets efficiently

This module implements several interconnected aggregation pipelines:

  1. Temporal Aggregation:

    • Daily metrics calculation → Weekly summaries → Monthly trends
    • Time-of-day and day-of-week analysis
    • Moving averages and trend identification
  2. Entity Aggregation:

    • Artist-level metrics with engagement scoring
    • Track-specific performance analysis
    • Genre and mood categorization and preferences
  3. Behavioral Analysis:

    • Skip pattern classification (preview, midpoint, near-end)
    • Session analysis (sequential skips, listening sessions)
    • Context awareness (playlist vs. album behavior differences)

All aggregated data is structured for efficient retrieval by the UI visualization components and export functionality.

Functions

createSafeDate
ensureStatisticsDir
aggregateDailySkipMetrics
aggregateWeeklySkipMetrics
getISOWeekIdentifier
getISOWeek
getWeekStartAndEndDates
aggregateArtistSkipMetrics
calculateLibrarySkipStatistics
analyzeTimeBasedPatterns
calculateArtistInsights