Files
lux/Lux.UI/Components/Compo/Stats/RealTimeStatsOld.razor
T
2025-12-15 18:43:03 +01:00

147 lines
4.2 KiB
Plaintext

@using EgwCoreLib.Lux.Core.Stats
@using EgwCoreLib.Lux.Data.Services
@inject CalcRuidService Calc
@inject IJSRuntime JSRuntime
<div class="card">
<div class="card-header d-flex justify-content-between">
<div class="px-0">
<h3>Statistiche in tempo reale</h3>
</div>
</div>
<div class="card-body">
<div class="row">
<div class="col">
<canvas id="chartRequestsMinute" width="400" height="150"></canvas>
</div>
<div class="col">
<canvas id="chartRequestsHour" width="400" height="150"></canvas>
</div>
</div>
<div class="row">
<div class="col">
<canvas id="chartAvgProcessing" width="400" height="150"></canvas>
</div>
<div class="col">
<canvas id="chartMaxProcessing" width="400" height="150"></canvas>
</div>
</div>
</div>
</div>
@code {
private StatsRealtimeDto? stats;
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await InitCharts();
_ = UpdateLoop();
}
}
private async Task InitCharts()
{
await JSRuntime.InvokeVoidAsync("chartsInterop.createChart", "chartRequestsMinute", new
{
type = "line",
data = new
{
labels = new[] { "Now" },
datasets = new[]
{
new {
label = "Richieste/minuto",
data = new[] { 0 },
borderColor = "blue"
}
}
}
});
await JSRuntime.InvokeVoidAsync("chartsInterop.createChart", "chartRequestsHour", new
{
type = "bar",
data = new
{
labels = new[] { "Now" },
datasets = new[]
{
new {
label = "Richieste/ora",
data = new[] { 0 },
backgroundColor = "green"
}
}
}
});
await JSRuntime.InvokeVoidAsync("chartsInterop.createChart", "chartAvgProcessing", new
{
type = "line",
data = new
{
labels = new[] { "Now" },
datasets = new[]
{
new {
label = "Tempo medio (s)",
data = new[] { 0 },
borderColor = "orange"
}
}
}
});
await JSRuntime.InvokeVoidAsync("chartsInterop.createChart", "chartMaxProcessing", new
{
type = "line",
data = new
{
labels = new[] { "Now" },
datasets = new[]
{
new {
label = "Tempo massimo (s)",
data = new[] { 0 },
borderColor = "red"
}
}
}
});
}
private async Task UpdateLoop()
{
var timer = new PeriodicTimer(TimeSpan.FromSeconds(5));
while (await timer.WaitForNextTickAsync())
{
stats = await Calc.GetStatsAsync();
await JSRuntime.InvokeVoidAsync("chartsInterop.updateChart",
"chartRequestsMinute",
DateTime.Now.ToString("HH:mm:ss"),
stats.RequestsLastMinute);
await JSRuntime.InvokeVoidAsync("chartsInterop.updateBarChart",
"chartRequestsHour",
DateTime.Now.ToString("HH:mm:ss"),
stats.RequestsLastHour);
await JSRuntime.InvokeVoidAsync("chartsInterop.updateChart",
"chartAvgProcessing",
DateTime.Now.ToString("HH:mm:ss"),
stats.ProcessingAvgLastHour);
await JSRuntime.InvokeVoidAsync("chartsInterop.updateChart",
"chartMaxProcessing",
DateTime.Now.ToString("HH:mm:ss"),
stats.ProcessingMaxLastHour);
StateHasChanged();
}
}
}