diff --git a/Moonlight/App/Helpers/Formatter.cs b/Moonlight/App/Helpers/Formatter.cs index 132a6fd9..05faba8c 100644 --- a/Moonlight/App/Helpers/Formatter.cs +++ b/Moonlight/App/Helpers/Formatter.cs @@ -156,6 +156,32 @@ public static class Formatter return (i / (1024D * 1024D)).Round(2) + " GB"; } } + + public static double CalculateAverage(List values) + { + if (values == null || values.Count == 0) + { + throw new ArgumentException("The list cannot be null or empty."); + } + + double sum = 0; + foreach (double value in values) + { + sum += value; + } + + return sum / values.Count; + } + + public static double CalculatePercentage(double part, double total) + { + if (total == 0) + { + return 0; + } + + return (part / total) * 100; + } public static RenderFragment FormatLineBreaks(string content) { diff --git a/Moonlight/App/Perms/Permissions.cs b/Moonlight/App/Perms/Permissions.cs index bc74ca82..cb6f4dab 100644 --- a/Moonlight/App/Perms/Permissions.cs +++ b/Moonlight/App/Perms/Permissions.cs @@ -410,10 +410,17 @@ public static class Permissions public static Permission AdminChangelog = new() { - Index = 59, + Index = 60, Name = "Admin changelog", Description = "View the changelog" }; + + public static Permission AdminStatisticsLive = new() + { + Index = 61, + Name = "Admin statistics live", + Description = "View the live statistics" + }; public static Permission? FromString(string name) { diff --git a/Moonlight/Pages/_Layout.cshtml b/Moonlight/Pages/_Layout.cshtml index a066a1f9..6dd42b6e 100644 --- a/Moonlight/Pages/_Layout.cshtml +++ b/Moonlight/Pages/_Layout.cshtml @@ -1,4 +1,4 @@ -@using Microsoft.AspNetCore.Components.Web +@using Microsoft.AspNetCore.Components.Web @using Moonlight.App.Extensions @using Moonlight.App.Repositories @using Moonlight.App.Services @@ -48,7 +48,6 @@ - @@ -98,6 +97,9 @@ + + + diff --git a/Moonlight/Shared/Components/Navigations/AdminStatisticsNavigation.razor b/Moonlight/Shared/Components/Navigations/AdminStatisticsNavigation.razor new file mode 100644 index 00000000..9a913bc7 --- /dev/null +++ b/Moonlight/Shared/Components/Navigations/AdminStatisticsNavigation.razor @@ -0,0 +1,22 @@ +
+ +
+ +@code +{ + [Parameter] + public int Index { get; set; } = 0; +} \ No newline at end of file diff --git a/Moonlight/Shared/Views/Admin/Statistics.razor b/Moonlight/Shared/Views/Admin/Statistics/Index.razor similarity index 98% rename from Moonlight/Shared/Views/Admin/Statistics.razor rename to Moonlight/Shared/Views/Admin/Statistics/Index.razor index 8441a22a..5fc5aa3c 100644 --- a/Moonlight/Shared/Views/Admin/Statistics.razor +++ b/Moonlight/Shared/Views/Admin/Statistics/Index.razor @@ -6,13 +6,16 @@ @using ApexCharts @using Moonlight.App.Helpers @using Moonlight.App.Services +@using Moonlight.Shared.Components.Navigations @inject StatisticsViewService StatisticsViewService @inject SmartTranslateService SmartTranslateService @attribute [PermissionRequired(nameof(Permissions.AdminStatistics))] -
+ + +