Update display charts energy

This commit is contained in:
Samuele Locatelli
2025-02-18 16:13:19 +01:00
parent b32bafda51
commit 2d89f401dc
8 changed files with 199 additions and 42 deletions
+8 -1
View File
@@ -26,7 +26,14 @@
<PieChart Id="PieODL" AspRatio="1" LegendPos="bottom" Data="@DatiPareto" Labels="@LabelPareto" lineColor="@lineColors" backColor="@bgColors" Title="@pieTitle"></PieChart>
</div>
<div class="col-10">
<Line Id="PlotODL" AspRatio="6" DataTS="@DatiPlot" Labels="@LabelPlot" lineColor="@lineColor" backColor="@lineColor" lTens="0" Title="@lineTitle"></Line>
@if (DynMode)
{
<MultiLine Id="PlotODL" AspRatio="4" DataTSList="@TSDataMulti" Labels="@LabelPlot" lineColor="@lineColors" backColor="@bgColors" lTens="0" Titles="@lineTitles" Stepped="false"></MultiLine>
}
else
{
<Line Id="PlotODL" AspRatio="4" DataTS="@DatiPlot" Labels="@LabelPlot" lineColor="@lineColor" backColor="@lineColor" lTens="0" Title="@lineTitles.FirstOrDefault()" Stepped="true"></Line>
}
</div>
</div>
</div>
+56 -29
View File
@@ -87,22 +87,22 @@ namespace MP.Stats.Components
#region Protected Methods
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <param name="alpha"></param>
/// <returns></returns>
protected List<string> semaphColors(int numRecords, string alpha)
{
List<string> answ = new List<string>();
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<string> lineTitles = new List<string>() { "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<ChartKV> ParetoData { get; set; } = new List<ChartKV>();
private List<chartJsData.chartJsTSerie> TSData { get; set; } = new List<chartJsData.chartJsTSerie>();
private List<List<chartJsData.chartJsTSerie>> TSDataMulti { get; set; } = new List<List<chartJsData.chartJsTSerie>>();
private List<string> listMachine = new List<string>();
#endregion Private Properties
#region Private Methods
private List<string> 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<string>();
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<List<chartJsData.chartJsTSerie>>();
// 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) })
+11 -7
View File
@@ -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
}
}
}
+119
View File
@@ -0,0 +1,119 @@
@using MP.Data
@inject IJSRuntime JSRuntime
<canvas id="@Id"></canvas>
@code {
[Parameter]
public string Id { get; set; } = "MyTs";
[Parameter]
public List<string> Titles { get; set; } = new List<string>() { "Demo Line" };
[Parameter]
public List<List<chartJsData.chartJsTSerie>> DataTSList { get; set; } = null!;
[Parameter]
public List<string> Labels { get; set; } = new List<string>();
[Parameter]
public List<string> lineColor { get; set; } = new List<string>();
[Parameter]
public List<string> backColor { get; set; } = new List<string>();
[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;
/// <summary>
/// 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
/// </summary>
/// <param name="firstRender"></param>
/// <returns></returns>
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await renderChart();
}
/// <summary>
/// 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
/// </summary>
/// <returns></returns>
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);
}
}
+2 -2
View File
@@ -4,8 +4,8 @@
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>MP.Stats</RootNamespace>
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
<Version>6.16.2502.1815</Version>
<Version>6.16.2502.1815</Version>
<Version>6.16.2502.1816</Version>
<Version>6.16.2502.1816</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo statistiche MAPO</i>
<h4>Versione: 6.16.2502.1815</h4>
<h4>Versione: 6.16.2502.1816</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
6.16.2502.1815
6.16.2502.1816
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.16.2502.1815</version>
<version>6.16.2502.1816</version>
<url>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>