using System; using System.Collections.Generic; using System.Linq; namespace Pulsar.Server.Statistics { public sealed class ClientStatisticsSnapshot { public ClientStatisticsSnapshot( int totalClients, int onlineClients, int offlineClients, int newClientsLast7Days, IReadOnlyList newClientsByDay, IReadOnlyList clientsByCountry, IReadOnlyList clientsByOperatingSystem, IReadOnlyList topTags, DateTime generatedAtUtc, string? errorMessage = null) { TotalClients = totalClients; OnlineClients = onlineClients; OfflineClients = offlineClients; NewClientsLast7Days = newClientsLast7Days; NewClientsByDay = newClientsByDay ?? Array.Empty(); ClientsByCountry = clientsByCountry ?? Array.Empty(); ClientsByOperatingSystem = clientsByOperatingSystem ?? Array.Empty(); TopTags = topTags ?? Array.Empty(); GeneratedAtUtc = generatedAtUtc; ErrorMessage = string.IsNullOrWhiteSpace(errorMessage) ? null : errorMessage; } public int TotalClients { get; } public int OnlineClients { get; } public int OfflineClients { get; } public int NewClientsLast7Days { get; } public IReadOnlyList NewClientsByDay { get; } public IReadOnlyList ClientsByCountry { get; } public IReadOnlyList ClientsByOperatingSystem { get; } public IReadOnlyList TopTags { get; } public DateTime GeneratedAtUtc { get; } public string? ErrorMessage { get; } public bool HasError => !string.IsNullOrWhiteSpace(ErrorMessage); public static ClientStatisticsSnapshot CreateError(string message) { return new ClientStatisticsSnapshot( 0, 0, 0, 0, Array.Empty(), Array.Empty(), Array.Empty(), Array.Empty(), DateTime.UtcNow, message); } } public sealed class DailyCount { public DailyCount(DateTime date, int count) { Date = date; Count = count; } public DateTime Date { get; } public int Count { get; } } public sealed class CategoryCount { public CategoryCount(string label, int count, double share) { Label = string.IsNullOrWhiteSpace(label) ? "Unknown" : label; Count = count; Share = share; } public string Label { get; } public int Count { get; } public double Share { get; } public override string ToString() { return $"{Label} ({Count})"; } } }