diff --git a/MP.Stats/Components/ChartJs/Line.razor b/MP.Stats/Components/ChartJs/Line.razor index 5ca58a3e..ac41d907 100644 --- a/MP.Stats/Components/ChartJs/Line.razor +++ b/MP.Stats/Components/ChartJs/Line.razor @@ -8,18 +8,31 @@ [Parameter] public string Id { get; set; } = "MyTs"; + [Parameter] + public string Title { get; set; } = "Demo Line"; + [Parameter] public List DataTS { get; set; } = null!; - + + [Parameter] + public List Labels { get; set; } = new List(); + [Parameter] public List lineColor { get; set; } = new List(); [Parameter] public List backColor { get; set; } = new List(); - + [Parameter] public double AspRatio { get; set; } = 0; + + [Parameter] + public string MinValue { get; set; } = "0"; + + [Parameter] + public string MaxValue { get; set; } = "100"; + [Parameter] public int lTens { get; set; } = 0; @@ -35,10 +48,7 @@ /// protected override async Task OnAfterRenderAsync(bool firstRender) { - //if (!firstRender) - //{ await renderChart(); - //} } /// @@ -68,7 +78,9 @@ ticks = new { maxTicksLimit = 10 - } + }, + suggestedMin = MinValue, + suggestedMax = MaxValue }, xAxes = new { @@ -81,8 +93,9 @@ }, data = new { + //labels = Labels.ToArray(), datasets = new[] - { + { new { data = DataTS, @@ -90,7 +103,7 @@ backgroundColor= backColor, lineTension= lTens, stepped= false, - label= "Temperatura Rilevata" + label= Title } } } diff --git a/MP.Stats/Components/ChartOEE.razor b/MP.Stats/Components/ChartOEE.razor index cbf95bee..e7bbdcb9 100644 --- a/MP.Stats/Components/ChartOEE.razor +++ b/MP.Stats/Components/ChartOEE.razor @@ -24,10 +24,10 @@
- +
- @**@ +
diff --git a/MP.Stats/Components/ChartOEE.razor.cs b/MP.Stats/Components/ChartOEE.razor.cs index f867296d..9bcbfe89 100644 --- a/MP.Stats/Components/ChartOEE.razor.cs +++ b/MP.Stats/Components/ChartOEE.razor.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using Microsoft.AspNetCore.Components; +using MP.Data; using MP.Stats.Data; namespace MP.Stats.Components @@ -11,7 +12,7 @@ namespace MP.Stats.Components { #region Protected Fields - + protected List NumGuasti = new List(); @@ -33,7 +34,7 @@ namespace MP.Stats.Components [Inject] protected MpStatsService StatService { get; set; } - protected List TSData { get; set; } = new List(); + protected List TSData { get; set; } = new List(); #endregion Protected Properties @@ -51,10 +52,6 @@ namespace MP.Stats.Components { // ricalcolo charting data recalcData(); - var dataReload = Task.Run(async () => - { - await HandleRedraw(); - }); } } } @@ -63,59 +60,40 @@ namespace MP.Stats.Components #region Private Methods -#if false - private BarChartDataset GetBarChartDataset() - { - var answ = new BarChartDataset - { - Label = "Pareto OEE Macchine", - Data = ParetoData.Select(x => x.value).ToList(), - BackgroundColor = backgroundColors(ParetoData.Count, 0.4f), - BorderColor = backgroundColors(ParetoData.Count, 1f), - HoverBorderWidth = 5 - }; - return answ; - } -#endif - private List GetBarChartLabels() - { - var answ = ParetoData.Select(x => x.label).ToList(); - return answ; - } - -#if false - private LineChartDataset GetLineChartDataset() - { - var answ = new LineChartDataset - { - Label = "TRS/OEE Periodo", - Data = TSData.Select(x => x.Value).ToList(), - BorderColor = backgroundColors(1, 1f), - Fill = true, - PointRadius = 2, - LineTension = 0, - BorderDash = new List { } - }; - return answ; - } -#endif - - private List DatiGuasti + private List DatiParetoOee { get => ParetoData.Select(x => x.value).ToList(); } - private List LabelGuasti + private List LabelParetoOee { get => ParetoData.Select(x => x.label).ToList(); } - private List GetLineChartLabels() + private List DatiTrs { - var answ = TSData.Select(x => x.TLabel.ToString("ddd dd.MM")).ToList(); + get => TSData; + } + private List LabelTrs + { + get => TSData.Select(r => $"{r.x:dd.MM}").ToList(); + } + + private Dictionary calcTSData(DateTime inizio, List yData) + { + Dictionary answ = new Dictionary(); + // usando i dati ricevuti aggiunge variabile x = tempo crescente + int idx = 0; + foreach (var item in yData) + { + answ.Add(inizio.AddHours(idx), item); + idx++; + } + // restituisco! return answ; } + private void recalcData() { if (RawData != null) @@ -128,8 +106,8 @@ namespace MP.Stats.Components TSData = RawData .GroupBy(x => x.DataRif.Date) - .Select(y => new ChartTS() { TLabel = y.First().DataRif.Date, Value = Math.Round(y.Average(c => c.OEE) * 100, 2) }) - .OrderBy(x => x.TLabel) + .Select(r => new chartJsData.chartJsTSerie() { x = r.First().DataRif.Date, y = Math.Round(r.Average(c => c.OEE) * 100, 2) }) + .OrderBy(o => o.x) .ToList(); } } @@ -143,27 +121,49 @@ namespace MP.Stats.Components ///
/// /// - protected List calcColors(int numRecords, double alpha) + protected List semaphColors(int numRecords, string alpha) { List answ = new List(); // verde... for (int i = 0; i < numRecords / 3; i++) { - answ.Add($"rgba(54, 235, 82, {alpha.ToString("N2").Replace(",", ".")})"); + answ.Add($"rgba(54, 235, 82, {alpha})"); } // arancione for (int i = 0; i < numRecords / 3; i++) { - answ.Add($"rgba(255, 206, 86, {alpha.ToString("N2").Replace(",", ".")})"); + answ.Add($"rgba(255, 206, 86, {alpha})"); } while (answ.Count < numRecords) { - answ.Add($"rgba(255, 99, 132, {alpha.ToString("N2").Replace(",",".")}"); - } + answ.Add($"rgba(255, 99, 132, {alpha}"); + } return answ; } + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List solidColors(string alpha) + { + List answ = new List(); + answ.Add($"rgba(54, 162, 235, {alpha})"); + return answ; + } + + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List lineColor + { + get => solidColors("1"); + } + /// /// Genera colori sfondo 33% rosso / arancione / giallo /// @@ -171,7 +171,7 @@ namespace MP.Stats.Components /// protected List lineColors { - get => calcColors(ParetoData.Count, 1); + get => semaphColors(ParetoData.Count, "1"); } /// @@ -181,25 +181,7 @@ namespace MP.Stats.Components /// protected List bgColors { - get => calcColors(ParetoData.Count, 0.3); - } - - protected async Task HandleRedraw() - { - if (ParetoGuasti != null) - { -#if false - await ParetoGuasti.Clear(); - await ParetoGuasti.AddLabelsDatasetsAndUpdate(GetBarChartLabels(), GetBarChartDataset()); -#endif - } - if (NumGuasti != null) - { -#if false - await NumGuasti.Clear(); - await NumGuasti.AddLabelsDatasetsAndUpdate(GetLineChartLabels(), GetLineChartDataset()); -#endif - } + get => semaphColors(ParetoData.Count, "0.3"); } #endregion Protected Methods diff --git a/MP.Stats/Pages/Test.razor.cs b/MP.Stats/Pages/Test.razor.cs index 1dc6b7ec..ab07f3a8 100644 --- a/MP.Stats/Pages/Test.razor.cs +++ b/MP.Stats/Pages/Test.razor.cs @@ -157,7 +157,7 @@ namespace MP.Stats.Pages protected List lineColors = new List(); - protected List? dataList { get; set; } = null; + protected List dataList { get; set; } = new List(); string[] Labels = { "Red", "Blue", "Yellow", "Green", "Purple", "Orange" };