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
+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) })