using Microsoft.AspNetCore.Components; using MP.Data; using MP.Stats.Data; using System.Collections.Generic; using System.Linq; namespace MP.Stats.Components { public partial class ChartUserLog { #region Protected Fields protected const string EsitoKO = "Esito: Non Passato"; protected const string EsitoOK = "Esito: OK"; #endregion Protected Fields #region Private Properties private List DatiPareto { get => ParetoData.Select(x => x.value).ToList(); } private List DatiPlot { get => TSData; } private List LabelPareto { get => ParetoData.Select(x => x.label).ToList(); } private List LabelPlot { get => TSData.Select(r => $"{r.x:yyyy-MM-dd}").ToList(); } #endregion Private Properties #region Protected Properties protected SelectData _currFilter { get; set; } = new SelectData(); protected List _rawData { get; set; } = new List(); /// /// Genera colori sfondo 33% rosso / arancione / giallo /// /// protected List bgColors { get => semaphColors(ParetoData.Count, "0.3"); } /// /// Genera colori sfondo 33% rosso / arancione / giallo /// /// protected List lineColor { get => solidColors("1"); } /// /// Genera colori sfondo 33% rosso / arancione / giallo /// /// protected List lineColors { get => semaphColors(ParetoData.Count, "1"); } [Inject] protected MessageService MessageService { get; set; } protected List ParetoData { get; set; } = new List(); [Inject] protected MpStatsService StatService { get; set; } protected List TSData { get; set; } = new List(); #endregion Protected Properties #region Public Properties [Parameter] public List RawData { get => _rawData; set { // salvo valori _rawData = value; if (value != null) { // ricalcolo charting data recalcData(); } } } #endregion Public Properties #region Private Methods private List GetLineChartLabels() { var answ = TSData.Select(x => x.x.ToString("ddd dd.MM")).ToList(); return answ; } private void recalcData() { if (RawData != null) { ParetoData = RawData .GroupBy(p => p.MatrOpr) .Select(y => new ChartKV() { label = $"{y.First().Cognome} {y.First().Nome}", value = y.Count() }) .OrderByDescending(x => x.value) .ToList(); TSData = RawData .GroupBy(x => x.DataOraRif.Date) .Select(r => new chartJsData.chartJsTSerie() { x = r.First().DataOraRif.Date, y = r.Count() }) .OrderBy(o => o.x) .ToList(); } } #endregion Private Methods #region Protected Methods /// /// Genera colori sfondo 33% rosso / arancione / giallo /// /// /// /// protected List semaphColors(int numRecords, string alpha) { List answ = new List(); int numStep = 5; // ciclo x numStep-1 for (int j = 0; j < numStep; j++) { for (int i = 0; i < numRecords / numStep; i++) { answ.Add($"rgba({54 + (180 - 54) * j / numStep}, {254 + (180 - 254) * j / numStep}, {86 + (35 - 86) * j / numStep}, {alpha}"); } } // chiude while (answ.Count < numRecords) { answ.Add($"rgba(180, 180, 35, {alpha})"); } return answ; } /// /// Genera colori bordo 33% rosso / arancione / giallo /// /// /// protected List solidColors(string alpha) { List answ = new List(); answ.Add($"rgba(54, 162, 235, {alpha})"); return answ; } #endregion Protected Methods } }