diff --git a/MP.Stats/Components/ChartEnergy.razor b/MP.Stats/Components/ChartEnergy.razor index 5725bcaa..0d81f2b6 100644 --- a/MP.Stats/Components/ChartEnergy.razor +++ b/MP.Stats/Components/ChartEnergy.razor @@ -26,7 +26,14 @@
- + @if (DynMode) + { + + } + else + { + + }
diff --git a/MP.Stats/Components/ChartEnergy.razor.cs b/MP.Stats/Components/ChartEnergy.razor.cs index 2c2fb08a..acff2888 100644 --- a/MP.Stats/Components/ChartEnergy.razor.cs +++ b/MP.Stats/Components/ChartEnergy.razor.cs @@ -87,22 +87,22 @@ namespace MP.Stats.Components #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++) + // ciclo x numRecords-1 + for (int j = 0; j < numRecords; 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}"); - } + answ.Add($"rgba({54 + (180 - 54) * j / numRecords}, {86 + (35 - 86) * j / numRecords}, {254 + (180 - 254) * j / numRecords}, {alpha}"); } // chiude while (answ.Count < numRecords) @@ -128,8 +128,8 @@ namespace MP.Stats.Components #region Private Fields - private string lineTitle = "Consumo/UM"; - private string pieTitle = "Macchina / Articolo"; + private List lineTitles = new List() { "Consumo/UM" }; + private string pieTitle = "Macchina"; #endregion Private Fields @@ -155,46 +155,73 @@ namespace MP.Stats.Components get => TSData.Select(r => $"{r.x:yyyy-MM-dd}").ToList(); } + private int numMachine + { + get => listMachine.Count; + } + private List ParetoData { get; set; } = new List(); private List TSData { get; set; } = new List(); + private List> TSDataMulti { get; set; } = new List>(); + + private List listMachine = new List(); #endregion Private 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) { - - lineTitle = $"{TradService.Traduci("MP-STATS_TotEn01")}/{StatService.FluxGetUM("TotCount01")}"; - - ParetoData = RawData - .GroupBy(p => new { p.IdxMacchina, p.CodArticolo }) - .Select(y => new ChartKV() { label = $"{y.First().IdxMacchina} {y.First().CodArticolo}", value = y.Count() }) - .OrderByDescending(x => x.value) - .ToList(); - + lineTitles = new List(); if (DynMode) { + ParetoData = RawData + .GroupBy(p => new { p.IdxMacchina}) + //.GroupBy(p => new { p.IdxMacchina, p.CodArticolo }) + .Select(y => new ChartKV() { label = y.First().IdxMacchina, value = y.Count() }) + //.Select(y => new ChartKV() { label = $"{y.First().IdxMacchina} {y.First().CodArticolo}", value = y.Count() }) + .OrderByDescending(x => x.value) + .ToList(); + TSData = RawData .Select(r => new chartJsData.chartJsTSerie() { x = r.DataInizio, y = (double)r.AvgTotEn01 }) .OrderBy(o => o.x) .ToList(); - //TSData = RawData - // .GroupBy(x => x.DataInizio.Date) - // .Select(r => new chartJsData.chartJsTSerie() { x = r.First().DataInizio.Date, y = r.Average(l => (double)l.AvgTotEn01) }) - // .OrderBy(o => o.x) - // .ToList(); + + // reset lista + TSDataMulti = new List>(); + // ciclo x ogni macchina + listMachine = RawData + .GroupBy(x => x.IdxMacchina) + .Select(y => y.First().IdxMacchina) + .ToList(); + + foreach (var idxMacc in listMachine) + { + lineTitles.Add($"{idxMacc} | {TradService.Traduci("MP-STATS_TotEn01")} / {StatService.FluxGetUM("TotCount01")}"); + + var TSDataCurr = RawData + .Where(x => x.IdxMacchina == idxMacc) + .Select(r => new chartJsData.chartJsTSerie() { x = r.DataInizio, y = (double)r.AvgTotEn01 }) + .OrderBy(o => o.x) + .ToList(); + TSDataMulti.Add(TSDataCurr); + } + } else { + lineTitles.Add($"{TradService.Traduci("MP-STATS_TotEn01")} / {StatService.FluxGetUM("TotCount01")}"); + ParetoData = RawData + .GroupBy(p => new { p.IdxMacchina }) + //.GroupBy(p => new { p.IdxMacchina, p.CodArticolo }) + .Select(y => new ChartKV() { label = y.First().IdxMacchina, value = y.Count() }) + //.Select(y => new ChartKV() { label = $"{y.First().IdxMacchina} {y.First().CodArticolo}", value = y.Count() }) + .OrderByDescending(x => x.value) + .ToList(); + TSData = RawData .GroupBy(x => x.DataInizio.Date) .Select(r => new chartJsData.chartJsTSerie() { x = r.First().DataInizio.Date, y = r.Average(l => (double)l.AvgWatt) }) diff --git a/MP.Stats/Components/ChartJs/Line.razor b/MP.Stats/Components/ChartJs/Line.razor index 8fd09cc2..781da4bf 100644 --- a/MP.Stats/Components/ChartJs/Line.razor +++ b/MP.Stats/Components/ChartJs/Line.razor @@ -26,6 +26,9 @@ [Parameter] public double AspRatio { get; set; } = 0; + [Parameter] + public bool Stepped { get; set; } = false; + [Parameter] public string MinValue { get; set; } = "0"; @@ -74,6 +77,8 @@ { yAxes = new { + type = "linear", + // type = "logarithmic", display = true, ticks = new { @@ -96,14 +101,13 @@ labels = Labels, datasets = new[] { - new - { + new { data = DataTS, - borderColor= lineColor, - backgroundColor= backColor, - lineTension= lTens, - stepped= false, - label= Title + borderColor = lineColor, + backgroundColor = backColor, + lineTension = lTens, + stepped = Stepped, + label = Title } } } diff --git a/MP.Stats/Components/ChartJs/MultiLine.razor b/MP.Stats/Components/ChartJs/MultiLine.razor new file mode 100644 index 00000000..89cf5b81 --- /dev/null +++ b/MP.Stats/Components/ChartJs/MultiLine.razor @@ -0,0 +1,119 @@ +@using MP.Data +@inject IJSRuntime JSRuntime + + + +@code { + + [Parameter] + public string Id { get; set; } = "MyTs"; + + [Parameter] + public List Titles { get; set; } = new List() { "Demo Line" }; + + [Parameter] + public List> DataTSList { 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 bool Stepped { get; set; } = false; + + + [Parameter] + public string MinValue { get; set; } = "0"; + + [Parameter] + public string MaxValue { get; set; } = "0"; + + [Parameter] + public int lTens { get; set; } = 0; + + /// + /// Inizializzazione rendering componente + /// + /// partendo da qui: + /// https://www.williamleme.com/posts/2020/003-chartjs-blazor/ + /// https://www.puresourcecode.com/dotnet/blazor/using-chart-js-with-blazor/ + /// https://www.tutorialsteacher.com/csharp/csharp-anonymous-type + /// + /// + /// + protected override async Task OnAfterRenderAsync(bool firstRender) + { + await renderChart(); + } + + /// + /// Inizializzazione rendering componente + /// + /// partendo da qui: + /// https://www.williamleme.com/posts/2020/003-chartjs-blazor/ + /// https://www.puresourcecode.com/dotnet/blazor/using-chart-js-with-blazor/ + /// https://www.tutorialsteacher.com/csharp/csharp-anonymous-type + /// + /// + protected async Task renderChart() + { + int i = 0; + // preparo lista di dati... + var dataSetsList = DataTSList.Select(dTS => new + { + data = dTS, + borderColor = lineColor[i], + backgroundColor = backColor, + lineTension = lTens, + stepped = Stepped, + label = Titles[i++] + }).ToList(); + + // creazione di un oggetto anonymous type con tutte le opzioni da passare a chart.js + var config = new + { + type = "line", + options = new + { + responsive = true, + scales = new + { + yAxes = new + { + stacked= true, + type = "linear", + // type = "logarithmic", + display = true, + ticks = new + { + maxTicksLimit = 10 + }, + suggestedMin = MinValue != MaxValue ? MinValue : "auto", + suggestedMax = MinValue != MaxValue ? MaxValue : "auto" + }, + xAxes = new + { + type = "time", + distribution = "linear", + } + }, + Animation = false, + AspectRatio = AspRatio == 0 ? "auto" : $"{AspRatio}" + }, + data = new + { + labels = Labels, + datasets = dataSetsList + } + }; + await JSRuntime.InvokeVoidAsync("setup", Id, config); + } +} \ No newline at end of file diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index 629ec67b..59fbed6c 100644 --- a/MP.Stats/MP.Stats.csproj +++ b/MP.Stats/MP.Stats.csproj @@ -4,8 +4,8 @@ net6.0 MP.Stats 826e877c-ba70-4253-84cb-d0b1cafd4440 - 6.16.2502.1815 - 6.16.2502.1815 + 6.16.2502.1816 + 6.16.2502.1816 true $(NoWarn);1591 en diff --git a/MP.Stats/Resources/ChangeLog.html b/MP.Stats/Resources/ChangeLog.html index 12fe2c51..c883e715 100644 --- a/MP.Stats/Resources/ChangeLog.html +++ b/MP.Stats/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

Versione: 6.16.2502.1815

+

Versione: 6.16.2502.1816


Note di rilascio:
    diff --git a/MP.Stats/Resources/VersNum.txt b/MP.Stats/Resources/VersNum.txt index 4e0acda1..9f540008 100644 --- a/MP.Stats/Resources/VersNum.txt +++ b/MP.Stats/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2502.1815 +6.16.2502.1816 diff --git a/MP.Stats/Resources/manifest.xml b/MP.Stats/Resources/manifest.xml index dd52eaa0..a6b9eed2 100644 --- a/MP.Stats/Resources/manifest.xml +++ b/MP.Stats/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2502.1815 + 6.16.2502.1816 https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html false