mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Migrate commands chart to Blazor.Bootstrap.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
@using Aaru.Server.Database
|
@using Aaru.Server.Database
|
||||||
@using Aaru.Server.Database.Models
|
@using Aaru.Server.Database.Models
|
||||||
@using Blazorise.Charts
|
@using BlazorBootstrap
|
||||||
@using Blazorise.DataGrid
|
@using Blazorise.DataGrid
|
||||||
@rendermode InteractiveServer
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using Aaru.Server.Database.Models;
|
using Aaru.Server.Database.Models;
|
||||||
using Blazorise.Charts;
|
using BlazorBootstrap;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using DbContext = Aaru.Server.Database.DbContext;
|
using DbContext = Aaru.Server.Database.DbContext;
|
||||||
|
|
||||||
@@ -7,11 +7,11 @@ namespace Aaru.Server.Components.Pages.Statistics;
|
|||||||
|
|
||||||
public partial class Commands
|
public partial class Commands
|
||||||
{
|
{
|
||||||
PieChart<long>? _commandsChart;
|
PieChart _commandsChart;
|
||||||
List<long> _commandsCounts = [];
|
List<double?> _commandsCounts = [];
|
||||||
string[] _commandsLabels = [];
|
List<string> _commandsLabels = [];
|
||||||
bool _isAlreadyInitialized;
|
bool _isAlreadyInitialized;
|
||||||
List<Command> CommandsList { get; set; } = [];
|
List<Command> CommandsList { get; set; } = [];
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override async Task OnInitializedAsync()
|
protected override async Task OnInitializedAsync()
|
||||||
@@ -35,31 +35,40 @@ public partial class Commands
|
|||||||
_commandsLabels = await ctx.Commands.OrderByDescending(static o => o.Count)
|
_commandsLabels = await ctx.Commands.OrderByDescending(static o => o.Count)
|
||||||
.Take(10)
|
.Take(10)
|
||||||
.Select(static v => v.Name)
|
.Select(static v => v.Name)
|
||||||
.ToArrayAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
_commandsCounts = await ctx.Commands.OrderByDescending(static o => o.Count)
|
_commandsCounts = await ctx.Commands.OrderByDescending(static o => o.Count)
|
||||||
.Take(10)
|
.Take(10)
|
||||||
.Select(static x => x.Count)
|
.Select(static x => (double?)x.Count)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
if(_commandsLabels.Length >= 10)
|
if(_commandsLabels.Count >= 10)
|
||||||
{
|
{
|
||||||
_commandsLabels[9] = "Other";
|
_commandsLabels[9] = "Other";
|
||||||
|
|
||||||
_commandsCounts[9] = ctx.Commands.Sum(static o => o.Count) - _commandsCounts.Take(9).Sum();
|
_commandsCounts[9] = ctx.Commands.Sum(static o => o.Count) - _commandsCounts.Take(9).Sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable CS8604 // Possible null reference argument.
|
PieChartOptions pieChartOptions = new()
|
||||||
await Common.HandleRedrawAsync(_commandsChart, _commandsLabels, GetCommandsChartDataset);
|
{
|
||||||
#pragma warning restore CS8604 // Possible null reference argument.
|
Responsive = true
|
||||||
}
|
};
|
||||||
|
|
||||||
PieChartDataset<long> GetCommandsChartDataset() => new()
|
pieChartOptions.Plugins.Title.Text = $"Top {_commandsLabels.Count} used commands";
|
||||||
{
|
pieChartOptions.Plugins.Title.Display = true;
|
||||||
Label = $"Top {_commandsLabels.Length} used commands",
|
|
||||||
Data = _commandsCounts,
|
var chartData = new ChartData
|
||||||
BackgroundColor = Common.BackgroundColors,
|
{
|
||||||
BorderColor = Common.BorderColors,
|
Labels = _commandsLabels,
|
||||||
BorderWidth = 1
|
Datasets =
|
||||||
};
|
[
|
||||||
|
new PieChartDataset
|
||||||
|
{
|
||||||
|
Data = _commandsCounts
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
await _commandsChart.InitializeAsync(chartData, pieChartOptions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user