Completato migrazione grafici x scarti

This commit is contained in:
Samuele Locatelli
2022-02-26 13:38:45 +01:00
parent f16d3a3275
commit a3a8c0ffaf
9 changed files with 119 additions and 131 deletions
+2 -2
View File
@@ -84,7 +84,7 @@
},
xAxes = new
{
type = "timeseries",
type = "time",
distribution = "linear",
}
},
@@ -93,7 +93,7 @@
},
data = new
{
//labels = Labels.ToArray(),
labels = Labels,
datasets = new[]
{
new
+19 -20
View File
@@ -1,35 +1,34 @@
@using MP.Stats.Components.ChartJs
@using MP.Stats.Components.ChartJs
<div class="row">
@if (RawData == null || RawData.Count == 0)
{
<div class="col-12">
<div class="alert alert-secondary text-center h4"><span class="oi oi-graph"></span> No Chart Data</div>
</div>
<div class="col-12">
<div class="alert alert-secondary text-center h4"><span class="oi oi-graph"></span> No Chart Data</div>
</div>
}
else
{
<div class="col-2" style="max-height: 10em; overflow:hidden; overflow-y: auto;">
<ul class="list-group list-group-sm small">
<div class="col-2" style="max-height: 10em; overflow:hidden; overflow-y: auto;">
<ul class="list-group list-group-sm small">
@foreach (var item in @ParetoData)
{
<li class="list-group-item p-1 d-flex justify-content-between align-items-center">
<li class="list-group-item p-1 d-flex justify-content-between align-items-center">
@item.label
<span class="badge badge-primary badge-pill">@item.value.ToString("N2")%</span>
</li>
<span class="badge badge-primary badge-pill">@item.value.ToString("N2")%</span>
</li>
}
</ul>
</div>
<div class="col-10">
<div class="row">
<div class="col-6">
<BarPlot Id="ParetoOee" AspRatio="3" Data="@DatiParetoOee" Labels="@LabelParetoOee" Legenda="Pareto OEE Macchine" lineColor="@lineColors" backColor="@bgColors"></BarPlot>
</div>
<div class="col-6">
<Line Id="AndamentoTrs" AspRatio="3" DataTS="@DatiTrs" Labels="@LabelTrs" lineColor="@lineColor" backColor="@lineColor" lTens="0" Title="Andamento TRS" MinValue="0" MaxValue="110"></Line>
</ul>
</div>
<div class="col-10">
<div class="row">
<div class="col-6">
<BarPlot Id="ParetoOee" AspRatio="3" Data="@DatiParetoOee" Labels="@LabelParetoOee" Legenda="Pareto OEE Macchine" lineColor="@lineColors" backColor="@bgColors"></BarPlot>
</div>
<div class="col-6">
<Line Id="AndamentoTrs" AspRatio="3" DataTS="@DatiTrs" Labels="@LabelTrs" lineColor="@lineColor" backColor="@lineColor" lTens="0" Title="Andamento TRS" MinValue="0" MaxValue="110"></Line>
</div>
</div>
</div>
</div>
}
</div>
+1 -6
View File
@@ -13,11 +13,6 @@ namespace MP.Stats.Components
#region Protected Fields
protected List<double> NumGuasti = new List<double>();
protected List<double> ParetoGuasti = new List<double>();
#endregion Protected Fields
#region Protected Properties
@@ -76,7 +71,7 @@ namespace MP.Stats.Components
}
private List<string> LabelTrs
{
get => TSData.Select(r => $"{r.x:dd.MM}").ToList();
get => TSData.Select(r => $"{r.x:yyyy-MM-dd}").ToList();
}
private Dictionary<DateTime, double> calcTSData(DateTime inizio, List<double> yData)
+6 -4
View File
@@ -1,4 +1,6 @@
@*<div class="row">
@using MP.Stats.Components.ChartJs
<div class="row">
@if (RawData == null || RawData.Count == 0)
{
<div class="col-12">
@@ -21,12 +23,12 @@
<div class="col-10">
<div class="row">
<div class="col-6">
<BarChart @ref="ParetoGuasti" TItem="double" OptionsObject="barChartOptions" />
<BarPlot Id="ParetoScarti" AspRatio="3" Data="@DatiPareto" Labels="@LabelPareto" Legenda="Pareto Scarti Macchine" lineColor="@lineColors" backColor="@bgColors"></BarPlot>
</div>
<div class="col-6">
<LineChart @ref="NumGuasti" TItem="double" OptionsObject="lineChartOptions" />
<Line Id="NumScarti" AspRatio="3" DataTS="@DatiPlot" Labels="@LabelPlot" lineColor="@lineColor" backColor="@lineColor" lTens="0" Title="Num Scarti"></Line>
</div>
</div>
</div>
}
</div>*@
</div>
+87 -95
View File
@@ -1,9 +1,8 @@
using System;
using Microsoft.AspNetCore.Components;
using MP.Data;
using MP.Stats.Data;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Components;
using MP.Stats.Data;
namespace MP.Stats.Components
{
@@ -80,20 +79,68 @@ namespace MP.Stats.Components
AspectRatio = 3.5
};
#if false
protected LineChart<double> NumGuasti = new LineChart<double>();
protected BarChart<double> ParetoGuasti = new BarChart<double>();
#endif
#endregion Protected Fields
#region Private Properties
private List<double> DatiPareto
{
get => ParetoData.Select(x => x.value).ToList();
}
private List<chartJsData.chartJsTSerie> DatiPlot
{
get => TSData;
}
private List<string> LabelPareto
{
get => ParetoData.Select(x => x.label).ToList();
}
private List<string> LabelPlot
{
get => TSData.Select(r => $"{r.x:yyyy-MM-dd}").ToList();
}
#endregion Private Properties
#region Protected Properties
protected SelectData _currFilter { get; set; } = new SelectData();
protected List<MP.Data.DatabaseModels.ResScarti> _rawData { get; set; } = new List<MP.Data.DatabaseModels.ResScarti>();
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> bgColors
{
get => semaphColors(ParetoData.Count, "0.3");
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> lineColor
{
get => solidColors("1");
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> lineColors
{
get => semaphColors(ParetoData.Count, "1");
}
[Inject]
protected MessageService MessageService { get; set; }
@@ -102,7 +149,7 @@ namespace MP.Stats.Components
[Inject]
protected MpStatsService StatService { get; set; }
protected List<ChartTS> TSData { get; set; } = new List<ChartTS>();
protected List<chartJsData.chartJsTSerie> TSData { get; set; } = new List<chartJsData.chartJsTSerie>();
#endregion Protected Properties
@@ -120,10 +167,6 @@ namespace MP.Stats.Components
{
// ricalcolo charting data
recalcData();
var dataReload = Task.Run(async () =>
{
await HandleRedraw();
});
}
}
}
@@ -132,50 +175,6 @@ namespace MP.Stats.Components
#region Private Methods
#if false
private BarChartDataset<double> GetBarChartDataset()
{
var answ = new BarChartDataset<double>
{
Label = "Pareto Causali Scarto",
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<string> GetBarChartLabels()
{
var answ = ParetoData.Select(x => x.label).ToList();
return answ;
}
#if false
private LineChartDataset<double> GetLineChartDataset()
{
var answ = new LineChartDataset<double>
{
Label = "Numero Scarti Periodo",
Data = TSData.Select(x => x.Value).ToList(),
BorderColor = backgroundColors(1, 1f),
Fill = true,
PointRadius = 2,
SteppedLine = true,
BorderDash = new List<int> { }
};
return answ;
}
#endif
private List<string> GetLineChartLabels()
{
var answ = TSData.Select(x => x.TLabel.ToString("ddd dd.MM")).ToList();
return answ;
}
private void recalcData()
{
if (RawData != null)
@@ -188,8 +187,8 @@ namespace MP.Stats.Components
TSData = RawData
.GroupBy(x => x.DataOraRif.Date)
.Select(y => new ChartTS() { TLabel = y.First().DataOraRif.Date, Value = y.Sum(c => c.Qta) })
.OrderBy(x => x.TLabel)
.Select(r => new chartJsData.chartJsTSerie() { x = r.First().DataOraRif.Date, y = r.Sum(c => c.Qta) })
.OrderBy(o => o.x)
.ToList();
}
}
@@ -198,50 +197,43 @@ namespace MP.Stats.Components
#region Protected Methods
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></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++)
{
for (int i = 0; i < numRecords / numStep; i++)
{
answ.Add($"rgba(255, {82 + (206 - 82) * j / numStep}, {132 + (74 - 132) * j / numStep}, {alpha}");
}
}
// chiude
while (answ.Count < numRecords)
{
answ.Add($"rgba(255, 206, 86, {alpha})");
}
return answ;
}
/// <summary>
/// Genera colori sfondo 33% rosso / arancione / giallo
/// </summary>
/// <param name="numRecords"></param>
/// <returns></returns>
protected List<string> backgroundColors(int numRecords, float alpha)
protected List<string> solidColors(string alpha)
{
List<string> answ = new List<string>();
#if false
// rosso...
for (int i = 0; i < numRecords / 3; i++)
{
answ.Add(ChartColor.FromRgba(255, 99, 132, alpha));
}
// arancione
for (int i = 0; i < numRecords / 3; i++)
{
answ.Add(ChartColor.FromRgba(255, 206, 86, alpha));
}
while (answ.Count < numRecords)
{
answ.Add(ChartColor.FromRgba(54, 82, 235, alpha));
}
#endif
answ.Add($"rgba(54, 162, 235, {alpha})");
return answ;
}
protected async Task HandleRedraw()
{
#if false
if (ParetoGuasti != null)
{
await ParetoGuasti.Clear();
await ParetoGuasti.AddLabelsDatasetsAndUpdate(GetBarChartLabels(), GetBarChartDataset());
}
if (NumGuasti != null)
{
await NumGuasti.Clear();
await NumGuasti.AddLabelsDatasetsAndUpdate(GetLineChartLabels(), GetLineChartDataset());
}
#endif
}
#endregion Protected Methods
}
}
+1 -1
View File
@@ -4,7 +4,7 @@
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>MP.Stats</RootNamespace>
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
<Version>6.14.2202.2612</Version>
<Version>6.14.2202.2613</Version>
</PropertyGroup>
<ItemGroup>
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo statistiche MAPO</i>
<h4>Versione: 6.14.2202.2612</h4>
<h4>Versione: 6.14.2202.2613</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
6.14.2202.2612
6.14.2202.2613
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.14.2202.2612</version>
<version>6.14.2202.2613</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>