mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
Migrate versions chart to Blazor.Bootstrap.
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
@using Aaru.CommonTypes.Metadata
|
@using Aaru.CommonTypes.Metadata
|
||||||
@using Aaru.Server.Database
|
@using Aaru.Server.Database
|
||||||
@using Blazorise.Charts
|
@using BlazorBootstrap
|
||||||
@using Blazorise.DataGrid
|
@using Blazorise.DataGrid
|
||||||
@rendermode InteractiveServer
|
@rendermode InteractiveServer
|
||||||
|
|
||||||
@@ -10,7 +10,8 @@
|
|||||||
<p class="text-center" style="color: deeppink;">All Aaru versions...</p>
|
<p class="text-center" style="color: deeppink;">All Aaru versions...</p>
|
||||||
</h1>
|
</h1>
|
||||||
<PieChart @ref="_versionsChart" style="padding: 40px" TItem="long"/>
|
<PieChart @ref="_versionsChart" style="padding: 40px" TItem="long"/>
|
||||||
<DataGrid Data="@VersionsList" FixedHeader FixedHeaderDataGridMaxHeight="300px" PageSize="int.MaxValue" TItem="NameValueStats">
|
<DataGrid Data="@VersionsList" FixedHeader FixedHeaderDataGridMaxHeight="300px" PageSize="int.MaxValue"
|
||||||
|
TItem="NameValueStats">
|
||||||
<DataGridColumn Caption="Version" Field="@nameof(NameValueStats.name)"/>
|
<DataGridColumn Caption="Version" Field="@nameof(NameValueStats.name)"/>
|
||||||
<DataGridNumericColumn Caption="Times run" Field="@nameof(NameValueStats.Value)"/>
|
<DataGridNumericColumn Caption="Times run" Field="@nameof(NameValueStats.Value)"/>
|
||||||
</DataGrid>
|
</DataGrid>
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
using Aaru.CommonTypes.Metadata;
|
using Aaru.CommonTypes.Metadata;
|
||||||
using Blazorise.Charts;
|
using BlazorBootstrap;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using DbContext = Aaru.Server.Database.DbContext;
|
using DbContext = Aaru.Server.Database.DbContext;
|
||||||
|
|
||||||
@@ -8,9 +8,9 @@ namespace Aaru.Server.Components.Pages.Statistics;
|
|||||||
public partial class Versions
|
public partial class Versions
|
||||||
{
|
{
|
||||||
bool _isAlreadyInitialized;
|
bool _isAlreadyInitialized;
|
||||||
PieChart<long>? _versionsChart;
|
PieChart _versionsChart;
|
||||||
List<long> _versionsCounts = [];
|
List<double?> _versionsCounts = [];
|
||||||
string[] _versionsLabels = [];
|
List<string> _versionsLabels = [];
|
||||||
List<NameValueStats> VersionsList { get; set; } = [];
|
List<NameValueStats> VersionsList { get; set; } = [];
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@@ -40,31 +40,40 @@ public partial class Versions
|
|||||||
_versionsLabels = await ctx.Versions.OrderByDescending(static o => o.Count)
|
_versionsLabels = await ctx.Versions.OrderByDescending(static o => o.Count)
|
||||||
.Take(10)
|
.Take(10)
|
||||||
.Select(static v => v.Name == "previous" ? "Previous than 3.4.99.0" : v.Name)
|
.Select(static v => v.Name == "previous" ? "Previous than 3.4.99.0" : v.Name)
|
||||||
.ToArrayAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
_versionsCounts = await ctx.Versions.OrderByDescending(static o => o.Count)
|
_versionsCounts = await ctx.Versions.OrderByDescending(static o => o.Count)
|
||||||
.Take(10)
|
.Take(10)
|
||||||
.Select(static x => x.Count)
|
.Select(static x => (double?)x.Count)
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
if(_versionsLabels.Length >= 10)
|
if(_versionsLabels.Count >= 10)
|
||||||
{
|
{
|
||||||
_versionsLabels[9] = "Other";
|
_versionsLabels[9] = "Other";
|
||||||
|
|
||||||
_versionsCounts[9] = ctx.Versions.Sum(static o => o.Count) - _versionsCounts.Take(9).Sum();
|
_versionsCounts[9] = ctx.Versions.Sum(static o => o.Count) - _versionsCounts.Take(9).Sum();
|
||||||
}
|
}
|
||||||
|
|
||||||
#pragma warning disable CS8604 // Possible null reference argument.
|
PieChartOptions pieChartOptions = new()
|
||||||
await Common.HandleRedrawAsync(_versionsChart, _versionsLabels, GetVersionsChartDataset);
|
{
|
||||||
#pragma warning restore CS8604 // Possible null reference argument.
|
Responsive = true
|
||||||
}
|
};
|
||||||
|
|
||||||
PieChartDataset<long> GetVersionsChartDataset() => new()
|
pieChartOptions.Plugins.Title.Text = $"Top {_versionsLabels.Count} Aaru versions";
|
||||||
{
|
pieChartOptions.Plugins.Title.Display = true;
|
||||||
Label = $"Top {_versionsLabels.Length} Aaru versions",
|
|
||||||
Data = _versionsCounts,
|
var chartData = new ChartData
|
||||||
BackgroundColor = Common.BackgroundColors,
|
{
|
||||||
BorderColor = Common.BorderColors,
|
Labels = _versionsLabels,
|
||||||
BorderWidth = 1
|
Datasets =
|
||||||
};
|
[
|
||||||
|
new PieChartDataset
|
||||||
|
{
|
||||||
|
Data = _versionsCounts
|
||||||
|
}
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
await _versionsChart.InitializeAsync(chartData, pieChartOptions);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user