Files
mapo-mono/MP.MONO.UI/Components/ChartController.razor.cs
T
2022-09-22 17:44:01 +02:00

155 lines
4.3 KiB
C#

using Microsoft.AspNetCore.Components;
using MP.MONO.Data;
using MP.MONO.Data.DbModels;
using MP.MONO.UI.Data;
namespace MP.MONO.UI.Components
{
public partial class ChartController
{
#region Protected Fields
protected const string EsitoKO = "Esito: Non Passato";
protected const string EsitoOK = "Esito: OK";
#endregion Protected Fields
#region Private Properties
private List<double> DatiPareto
{
get => ParetoData.Select(x => x.value).ToList();
}
private List<chartJsData.chartJsTSerie> DatiPlot
{
get => TSData;
}
private List<string> LabelPareto
{
get => ParetoData.Select(x => x.label).ToList();
}
private List<string> LabelPlot
{
get => TSData.Select(r => $"{r.x:yyyy-MM-dd}").ToList();
}
#endregion Private Properties
#region Protected Properties
protected List<AlarmRecModel> _rawData { get; set; } = new List<AlarmRecModel>();
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> bgColors
{
get => semaphColors(ParetoData.Count, "0.3");
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> lineColor
{
get => solidColors("1");
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> lineColors
{
get => semaphColors(ParetoData.Count, "1");
}
protected List<ChartKV> ParetoData { get; set; } = new List<ChartKV>();
protected List<chartJsData.chartJsTSerie> TSData { get; set; } = new List<chartJsData.chartJsTSerie>();
#endregion Protected Properties
#region Public Properties
[Parameter]
public List<AlarmRecModel> RawData
{
get => _rawData;
set
{
// salvo valori
_rawData = value;
if (value != null)
{
// ricalcolo charting data
recalcData();
}
}
}
#endregion Public Properties
#region Private Methods
private void recalcData()
{
if (RawData != null)
{
ParetoData = RawData
.GroupBy(p => p.AlarmListNav.FullValue)
.Select(y => new ChartKV() { label = true ? EsitoOK : EsitoKO, value = y.Count() })
.OrderByDescending(x => x.value)
.ToList();
TSData = RawData
.GroupBy(x => x.AlarmListNav.FullValue)
.Select(r => new chartJsData.chartJsTSerie() { x = r.First().DtStart, y = r.Count() })
.OrderBy(o => o.x)
.ToList();
}
}
#endregion Private Methods
#region Protected Methods
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> semaphColors(int numRecords, string alpha)
{
List<string> answ = new List<string>();
// aggiungo verde/rosso
answ.Add($"rgba(54, 254, 82, {alpha})");
answ.Add($"rgba(254, 82, 65, {alpha})");
return answ;
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> solidColors(string alpha)
{
List<string> answ = new List<string>();
answ.Add($"rgba(54, 162, 235, {alpha})");
return answ;
}
#endregion Protected Methods
}
}