Continuo aggiornamenti Trend graph plot
This commit is contained in:
@@ -10,8 +10,14 @@
|
||||
else
|
||||
{
|
||||
<div class="col-2">
|
||||
<div class="w-100">
|
||||
@foreach (PeriodoSel sPer in Enum.GetValues(typeof(PeriodoSel)))
|
||||
{
|
||||
<button class="btn btn-outline-success w-100 @CssBtn(sPer)" @onclick="() => SetModo(sPer)">@sPer Detail</button>
|
||||
|
||||
}
|
||||
</div>
|
||||
<div class="border" style="max-height: 14em; overflow:hidden; overflow-y: auto;">
|
||||
<i>Selezione tipo (day/week/month/year) + selezione ITEM da mostrare, tra quelli POSSIBILI dato periodo...</i>
|
||||
<ul class="list-group list-group-sm small">
|
||||
@foreach (var item in @ParetoData)
|
||||
{
|
||||
@@ -21,6 +27,7 @@
|
||||
</li>
|
||||
}
|
||||
</ul>
|
||||
<i>Selezione tipo (day/week/month/year) + selezione ITEM da mostrare, tra quelli POSSIBILI dato periodo...</i>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-10">
|
||||
@@ -29,14 +36,10 @@
|
||||
<PieChart Id="PieODL" AspRatio="1" LegendPos="bottom" Data="@DatiPareto" Labels="@LabelPareto" lineColor="@lineColors" backColor="@bgColors" Title="@pieTitle"></PieChart>
|
||||
</div>
|
||||
<div class="col-10">
|
||||
<b>Day</b>
|
||||
<MultiLine Id="plotDay" AspRatio="4" DataTSList="@TSDataMulti" Labels="@LabelPlot" lineColor="@lineColors" backColor="@bgColors" lTens="0" Titles="@lineTitles" Stepped="false"></MultiLine>
|
||||
<b>Week</b>
|
||||
<MultiLine Id="plotWeek" AspRatio="4" DataTSList="@TSDataMulti" Labels="@LabelPlot" lineColor="@lineColors" backColor="@bgColors" lTens="0" Titles="@lineTitles" Stepped="false"></MultiLine>
|
||||
<b>Month</b>
|
||||
<MultiLine Id="plotMonth" AspRatio="4" DataTSList="@TSDataMulti" Labels="@LabelPlot" lineColor="@lineColors" backColor="@bgColors" lTens="0" Titles="@lineTitles" Stepped="false"></MultiLine>
|
||||
@* <b>Year</b>
|
||||
<MultiLine Id="plotYear" AspRatio="4" DataTSList="@TSDataMulti" Labels="@LabelPlot" lineColor="@lineColors" backColor="@bgColors" lTens="0" Titles="@lineTitles" Stepped="false"></MultiLine> *@
|
||||
<b>Periodo</b>
|
||||
<MultiLine Id="plotAll" AspRatio="4" DataTSList="@TSDataMulti" Labels="@LabelPlot" lineColor="@lineColors" backColor="@bgColors" lTens="0" Titles="@lineTitles" Stepped="false"></MultiLine>
|
||||
<b>@pSel</b> Detail
|
||||
<MultiLine Id="plotDetail" AspRatio="4" DataTSList="@TSDataMultiDetail" Labels="@LabelPlotDet" lineColor="@lineColorsDet" backColor="@bgColorsDet" lTens="0" Titles="@lineTitlesDet" Stepped="false"></MultiLine>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using MongoDB.Driver.Linq;
|
||||
using MP.Data;
|
||||
using MP.Data.DbModels;
|
||||
using MP.Data.Services;
|
||||
@@ -47,6 +48,7 @@ namespace MP.Stats.Components
|
||||
{
|
||||
get => semaphColors(ParetoData.Count, "0.3");
|
||||
}
|
||||
protected List<string> bgColorsDet { get; set; } = new List<string>();
|
||||
|
||||
/// <summary>
|
||||
/// Genera colori sfondo 33% rosso / arancione / giallo
|
||||
@@ -65,6 +67,7 @@ namespace MP.Stats.Components
|
||||
{
|
||||
get => semaphColors(ParetoData.Count, "1");
|
||||
}
|
||||
protected List<string> lineColorsDet { get; set; } = new List<string>();
|
||||
|
||||
[Inject]
|
||||
protected Data.MessageService MService { get; set; }
|
||||
@@ -121,6 +124,7 @@ namespace MP.Stats.Components
|
||||
#region Private Fields
|
||||
|
||||
private List<string> lineTitles = new List<string>() { "Consumo/UM" };
|
||||
private List<string> lineTitlesDet = new List<string>() { "Consumo/UM" };
|
||||
private string pieTitle = "Macchina";
|
||||
|
||||
#endregion Private Fields
|
||||
@@ -146,6 +150,7 @@ namespace MP.Stats.Components
|
||||
{
|
||||
get => TSData.Select(r => $"{r.x:yyyy-MM-dd}").ToList();
|
||||
}
|
||||
private List<string> LabelPlotDet { get; set; } = new List<string>();
|
||||
|
||||
private int numMachine
|
||||
{
|
||||
@@ -155,6 +160,10 @@ namespace MP.Stats.Components
|
||||
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>>();
|
||||
/// <summary>
|
||||
/// TimeSeries su scala DAY
|
||||
/// </summary>
|
||||
private List<List<chartJsData.chartJsTSerie>> TSDataMultiDetail { get; set; } = new List<List<chartJsData.chartJsTSerie>>();
|
||||
|
||||
private List<string> listMachine = new List<string>();
|
||||
|
||||
@@ -166,24 +175,24 @@ namespace MP.Stats.Components
|
||||
{
|
||||
if (RawData != null)
|
||||
{
|
||||
lineTitles = new List<string>();
|
||||
|
||||
// reset preliminare
|
||||
TSDataMulti.Clear();
|
||||
TSDataMultiDetail.Clear();
|
||||
lineTitles.Clear();
|
||||
lineTitlesDet.Clear();
|
||||
LabelPlotDet.Clear();
|
||||
bgColorsDet.Clear();
|
||||
lineColorsDet.Clear();
|
||||
|
||||
// calcolo i dati Pareto
|
||||
ParetoData = RawData
|
||||
//.GroupBy(p => new { p.IdxMacchina })
|
||||
.GroupBy(p => new { p.IdxMacchina, p.CodFlux })
|
||||
//.Select(y => new ChartKV() { label = y.First().IdxMacchina, value = y.Count() })
|
||||
//.Select(y => new ChartKV() { label = y.First().IdxMacchina, value = y.Count() })
|
||||
.Select(y => new ChartKV() { label = $"{y.First().IdxMacchina} {TradService.Traduci($"MP-STATS_{y.First().CodFlux}")}", value = y.Count() })
|
||||
.OrderByDescending(x => x.value)
|
||||
.ToList();
|
||||
|
||||
TSData = RawData
|
||||
.Select(r => new chartJsData.chartJsTSerie() { x = r.dtEvento, y = cDouble(r.Valore) })
|
||||
.OrderBy(o => o.x)
|
||||
.ToList();
|
||||
|
||||
// reset lista
|
||||
TSDataMulti = new List<List<chartJsData.chartJsTSerie>>();
|
||||
// ciclo x ogni macchina
|
||||
listMachine = RawData
|
||||
.GroupBy(x => x.IdxMacchina)
|
||||
@@ -193,22 +202,145 @@ namespace MP.Stats.Components
|
||||
foreach (var idxMacc in listMachine)
|
||||
{
|
||||
lineTitles.Add($"{idxMacc} | {TradService.Traduci("MP-STATS_TotEn01")}");
|
||||
lineTitlesDet.Add($"{idxMacc} | {TradService.Traduci("MP-STATS_TotEn01")} - CURR");
|
||||
lineTitlesDet.Add($"{idxMacc} | {TradService.Traduci("MP-STATS_TotEn01")} - PREV");
|
||||
|
||||
var TSDataCurr = RawData
|
||||
.Where(x => x.IdxMacchina == idxMacc)
|
||||
.Select(r => new chartJsData.chartJsTSerie() { x = r.dtEvento, y = cDouble(r.Valore) })
|
||||
.OrderBy(o => o.x)
|
||||
.ToList();
|
||||
TSDataMulti.Add(TSDataCurr);
|
||||
// periodo completo
|
||||
TSDataMulti.Add(GetTSDetail(idxMacc, "", null));
|
||||
// dettaglio richiesto...
|
||||
var currPlot = GetTSDetail(idxMacc, "", pSel, true);
|
||||
TSDataMultiDetail.Add(currPlot);
|
||||
TSDataMultiDetail.Add(GetTSDetail(idxMacc, "", pSel, false));
|
||||
if (LabelPlotDet.Count == 0)
|
||||
{
|
||||
if (pSel == PeriodoSel.Day)
|
||||
{
|
||||
LabelPlotDet = currPlot.Select(r => $"{r.x:HH:mm:ss}").ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
LabelPlotDet = currPlot.Select(r => $"{r.x:yyyy-MM-dd}").ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bgColorsDet = semaphColors(ParetoData.Count * 2, "0.3");
|
||||
lineColorsDet = semaphColors(ParetoData.Count * 2, "1");
|
||||
}
|
||||
}
|
||||
|
||||
private DateTime GetFirstDayOfWeek(DateTime date)
|
||||
{
|
||||
int offset = date.DayOfWeek - DayOfWeek.Sunday;
|
||||
return date.AddDays(-offset);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ritorna dettaglio dato macchina e tipo (current o prev)
|
||||
/// </summary>
|
||||
/// <param name="idxMacc">Macchina richiesta</param>
|
||||
/// <param name="codFlux">Flusso richiesto</param>
|
||||
/// <param name="recapMode">Modo recap (se null --> intero periodo)</param>
|
||||
/// <param name="isCurrent">Indica se iin caso di recap sia periodo corrente/precedente</param>
|
||||
/// <returns></returns>
|
||||
private List<chartJsData.chartJsTSerie> GetTSDetail(string idxMacc, string codFlux, PeriodoSel? recapMode, bool isCurrent = true)
|
||||
{
|
||||
List<chartJsData.chartJsTSerie> answ = new();
|
||||
if (!recapMode.HasValue)
|
||||
{
|
||||
answ = RawData
|
||||
.Where(x => x.IdxMacchina == idxMacc)
|
||||
.Select(r => new chartJsData.chartJsTSerie() { x = r.dtEvento, y = cDouble(r.Valore) })
|
||||
.OrderBy(o => o.x)
|
||||
.ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
// fake fix: indietro 7 gg...
|
||||
DateTime dataRif = DateTime.Today.AddDays(-7);
|
||||
DateTime inizio = dataRif;
|
||||
DateTime fine = inizio.AddDays(1);
|
||||
double startVal = 0;
|
||||
switch (recapMode)
|
||||
{
|
||||
case PeriodoSel.Day:
|
||||
inizio = isCurrent ? dataRif : dataRif.AddDays(-1);
|
||||
fine = inizio.AddDays(1);
|
||||
break;
|
||||
case PeriodoSel.Week:
|
||||
inizio = isCurrent ? GetFirstDayOfWeek(dataRif) : GetFirstDayOfWeek(dataRif).AddDays(-7);
|
||||
fine = inizio.AddDays(7);
|
||||
break;
|
||||
case PeriodoSel.Month:
|
||||
inizio = isCurrent ? new DateTime(dataRif.Year, dataRif.Month, 1) : new DateTime(dataRif.Year, dataRif.Month, 1).AddMonths(-1);
|
||||
fine = inizio.AddMonths(1);
|
||||
break;
|
||||
case PeriodoSel.Year:
|
||||
inizio = isCurrent ? new DateTime(dataRif.Year, 1, 1) : new DateTime(dataRif.Year, 1, 1).AddYears(-1);
|
||||
fine = inizio.AddYears(1);
|
||||
break;
|
||||
|
||||
|
||||
case null:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
// calcolo il minimo...
|
||||
var listRaw = RawData
|
||||
.Where(x => x.IdxMacchina == idxMacc && x.dtEvento >= inizio && x.dtEvento < fine)
|
||||
.OrderBy(o => o.dtEvento)
|
||||
.ToList();
|
||||
var firstRec = listRaw
|
||||
.FirstOrDefault();
|
||||
if (firstRec != null)
|
||||
{
|
||||
startVal = cDouble(firstRec.Valore);
|
||||
}
|
||||
|
||||
answ = listRaw
|
||||
.Select(r => new chartJsData.chartJsTSerie() { x = r.dtEvento, y = cDouble(r.Valore) - startVal })
|
||||
.OrderBy(o => o.x)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
return answ;
|
||||
}
|
||||
|
||||
private double cDouble(string origValue)
|
||||
{
|
||||
return double.Parse(origValue);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Modalità selezione
|
||||
/// </summary>
|
||||
private PeriodoSel pSel;
|
||||
|
||||
protected enum PeriodoSel
|
||||
{
|
||||
Day,
|
||||
Week,
|
||||
Month,
|
||||
Year
|
||||
}
|
||||
|
||||
private void SetModo(PeriodoSel newModo)
|
||||
{
|
||||
pSel = newModo;
|
||||
// ricalcolo!
|
||||
RecalcData();
|
||||
}
|
||||
|
||||
private string CssBtn(PeriodoSel reqMode)
|
||||
{
|
||||
string answ = "btn-outline-success";
|
||||
if (reqMode == pSel)
|
||||
{
|
||||
answ = "btn-success text-light";
|
||||
}
|
||||
return answ;
|
||||
}
|
||||
|
||||
#endregion Private Methods
|
||||
}
|
||||
}
|
||||
@@ -4,8 +4,8 @@
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<RootNamespace>MP.Stats</RootNamespace>
|
||||
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
|
||||
<Version>6.16.2503.1016</Version>
|
||||
<Version>6.16.2503.1016</Version>
|
||||
<Version>6.16.2503.1018</Version>
|
||||
<Version>6.16.2503.1018</Version>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
<NoWarn>$(NoWarn);1591</NoWarn>
|
||||
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<body>
|
||||
<i>Modulo statistiche MAPO</i>
|
||||
<h4>Versione: 6.16.2503.1016</h4>
|
||||
<h4>Versione: 6.16.2503.1018</h4>
|
||||
<br />
|
||||
Note di rilascio:
|
||||
<ul>
|
||||
|
||||
@@ -1 +1 @@
|
||||
6.16.2503.1016
|
||||
6.16.2503.1018
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<item>
|
||||
<version>6.16.2503.1016</version>
|
||||
<version>6.16.2503.1018</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>
|
||||
|
||||
Reference in New Issue
Block a user