// ========================================================================== // Squidex Headless CMS // ========================================================================== // Copyright (c) Squidex UG (haftungsbeschraenkt) // All rights reserved. Licensed under the MIT license. // ========================================================================== using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using System.Linq; using Squidex.Domain.Apps.Entities.Apps.Plans; using Squidex.Infrastructure.UsageTracking; #pragma warning disable CS0618 // Type or member is obsolete namespace Squidex.Areas.Api.Controllers.Statistics.Models { public sealed class CallsUsageDtoDto { /// /// The total number of API calls. /// public long TotalCalls { get; set; } /// /// The total number of bytes transferred. /// public long TotalBytes { get; set; } /// /// The total number of API calls this month. /// public long MonthCalls { get; set; } /// /// The total number of bytes transferred this month. /// public long MonthBytes { get; set; } /// /// The amount of calls that will block the app. /// public long BlockingApiCalls { get; set; } /// /// The included API traffic. /// public long AllowedBytes { get; set; } /// /// The included API calls. /// public long AllowedCalls { get; set; } /// /// The average duration in milliseconds. /// public double AverageElapsedMs { get; set; } /// /// The statistics by date and group. /// [Required] public Dictionary Details { get; set; } public static CallsUsageDtoDto FromStats(IAppLimitsPlan plan, ApiStatsSummary summary, Dictionary> details) { return new CallsUsageDtoDto { AverageElapsedMs = summary.AverageElapsedMs, BlockingApiCalls = plan.BlockingApiCalls, AllowedBytes = plan.MaxApiBytes, AllowedCalls = plan.MaxApiCalls, TotalBytes = summary.TotalBytes, TotalCalls = summary.TotalCalls, MonthBytes = summary.MonthBytes, MonthCalls = summary.MonthCalls, Details = details.ToDictionary(x => x.Key, x => x.Value.Select(CallsUsagePerDateDto.FromStats).ToArray()) }; } } }