module Admin class DashboardStats ACTIVE_STATUSES = %w[live reconnecting connecting paused].freeze def call now = Time.current day_start = now.beginning_of_day month_start = now.beginning_of_month ended_today = StreamSession.where(status: "ended").where("ended_at >= ?", day_start) ended_month = StreamSession.where(status: "ended").where("ended_at >= ?", month_start) { active_sessions: StreamSession.where(status: ACTIVE_STATUSES).count, sessions_today: ended_today.count, sessions_month: ended_month.count, stream_minutes_today: (ended_today.sum(:total_duration_secs).to_i / 60.0).round, stream_minutes_month: (ended_month.sum(:total_duration_secs).to_i / 60.0).round, teams_count: Team.count, users_count: User.count, matches_count: Match.count, recordings_count: Recording.not_deleted.count, recordings_ready: Recording.ready.count, recordings_bytes: Recording.ready.sum(:byte_size).to_i, recordings_expiring_soon: Recording.ready.expiring_within(7).count, } end end end