Files
mapo-core/MP.IOC/Components/Pages/CallStats.razor.cs
T

172 lines
4.9 KiB
C#

using Microsoft.AspNetCore.Components;
using MP.Core.DTO;
using MP.Data;
using MP.Data.DbModels.Utils;
using MP.Data.DTO;
using MP.Data.Services.Utils;
namespace MP.IOC.Components.Pages
{
public partial class CallStats
{
#region Protected Properties
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <returns></returns>
protected List<string> bgColors
{
get => semaphColors(currData.Count, "0.3");
}
#endregion Protected Properties
#region Protected Methods
protected override async Task OnInitializedAsync()
{
await ReloadData();
}
#endregion Protected Methods
#region Private Fields
private List<StatDataDTO> currData = new();
private string currId = "";
private string currHistId = "";
private string currPieId = "";
private string currTsId = "";
private string currTitle = "";
private Dictionary<string, List<StatDataDTO>> ParetoDay = new();
#endregion Private Fields
#region Private Properties
private List<double> DatiPareto
{
get => currData.Select(x => x.Value).ToList();
}
private List<string> LabelPareto
{
get => currData.Select(x => x.Label).ToList();
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <returns></returns>
private List<string> lineColors
{
get => semaphColors(currData.Count, "1");
}
[Inject]
private IStatsDetailService SDetService { get; set; } = null!;
#endregion Private Properties
#region Private Methods
private string CheckSelect(string curKey)
{
return !string.IsNullOrEmpty(currId) && currId == curKey ? "active" : "";
}
private void DoReset()
{
currId = "";
currHistId = "";
currPieId = "";
currTsId = "";
currData = new();
}
private void DoSelect(string reqKey)
{
if (ParetoDay.ContainsKey(reqKey))
{
currId = reqKey;
currHistId = $"Bar_{reqKey}";
currPieId = $"Pie_{reqKey}";
currTsId = $"TS_{reqKey}";
currTitle = $"Pareto | {reqKey}";
currData = ParetoDay[reqKey];
}
}
private async Task ReloadData()
{
ParetoDay = await SDetService.GetParetoStatsDayAsync();
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <param name="alpha"></param>
/// <returns></returns>
private List<string> semaphColors(int numRecords, string alpha)
{
List<string> answ = new List<string>();
// verde...
for (int i = 0; i < numRecords / 3; i++)
{
answ.Add($"rgba(54, 235, 82, {alpha})");
}
// arancione
for (int i = 0; i < numRecords / 3; i++)
{
answ.Add($"rgba(255, 206, 86, {alpha})");
}
while (answ.Count < numRecords)
{
answ.Add($"rgba(255, 99, 132, {alpha}");
}
return answ;
}
#endregion Private Methods
private string currDetail = "";
/// <summary>
/// abilita visualizzaione grafico dettagli x metodo indicato
/// </summary>
/// <param name="selDetail"></param>
private async Task ShowDetail(string selDetail)
{
currDetail = selDetail;
// recupero dettaglio 7gg...
DateTime adesso = DateTime.Now;
List<StatsDetailModel> rawData = await SDetService.GetFiltAsync(adesso.AddDays(-3), adesso, "", selDetail);
// conversione con grouping
tsData = rawData.Select(r => new chartJsData.chartJsTSerie() { x = r.Hour, y = (double)r.AvgDuration })
.OrderBy(o => o.x)
.ToList();
tsDataDetail = SDetService.GetTimeSeriesData(rawData);
lineTitles = tsDataDetail.Select(x => x.SeriesName).ToList();
TSDataMulti = tsDataDetail.Select(x => x.DataPoints).ToList();
}
private List<string> LabelPlot
{
get => tsData.Select(r => $"{r.x:yyyy-MM-dd}").ToList();
}
private List<ChartSeriesDto> tsDataDetail = new();
private List<chartJsData.chartJsTSerie> tsData = new List<chartJsData.chartJsTSerie>();
private List<List<chartJsData.chartJsTSerie>> TSDataMulti = new();
private List<string> lineTitles = new List<string>();
}
}