diff --git a/MP.Data/Controllers/MpStatsController.cs b/MP.Data/Controllers/MpStatsController.cs index 843c0daf..8a01f41f 100644 --- a/MP.Data/Controllers/MpStatsController.cs +++ b/MP.Data/Controllers/MpStatsController.cs @@ -168,13 +168,6 @@ namespace MP.Data.Controllers { List dbResult = new List(); - //dbResult = dbCtx - // . - // .Where(x => x.Descrizione.Contains(searchVal) || x.IdxMacchina.Contains(searchVal) || x.CodArticolo.Contains(searchVal) || x.KeyRichiesta.Contains(searchVal) || string.IsNullOrEmpty(searchVal)) - // .OrderByDescending(x => x.InizioStato) - // .Take(numRecord) - // .ToList(); - var dataFrom = new SqlParameter("@dataFrom", DataStart); var dataTo = new SqlParameter("@dataTo", DataEnd); var idxMacchina = new SqlParameter("@idxMacchina", IdxMacchina); @@ -269,60 +262,6 @@ namespace MP.Data.Controllers return dbResult; } - /// - /// Elenco tabella TurniPareto da filtro - /// - /// - /// - /// - /// - /// - public List StatTurniParetoGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo) - { - List dbResult = new List(); - - var dataFrom = new SqlParameter("@dataFrom", DataStart); - var dataTo = new SqlParameter("@dataTo", DataEnd); - var idxMacchina = new SqlParameter("@idxMacchina", IdxMacchina); - var idxODL = new SqlParameter("@IdxODL", IdxODL); - var keyRichiesta = new SqlParameter("@KeyRichiesta", KeyRichiesta); - var codArticolo = new SqlParameter("@CodArticolo", CodArticolo); - - dbResult = dbCtx - .DbSetTurniPareto - .FromSqlRaw("EXEC stp_UI_ParetoTurni_GetByFilter @dataFrom,@dataTo,@idxMacchina,@IdxODL,@KeyRichiesta,@CodArticolo", dataFrom, dataTo, idxMacchina, idxODL, keyRichiesta, codArticolo) - .ToList(); - - return dbResult; - } - - /// - /// Elenco tabella TurniParetoOdl da filtro - /// - /// - /// - /// - /// - /// - public List StatTurniParetoOdlGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo) - { - List dbResult = new List(); - - var dataFrom = new SqlParameter("@dataFrom", DataStart); - var dataTo = new SqlParameter("@dataTo", DataEnd); - var idxMacchina = new SqlParameter("@idxMacchina", IdxMacchina); - var idxODL = new SqlParameter("@IdxODL", IdxODL); - var keyRichiesta = new SqlParameter("@KeyRichiesta", KeyRichiesta); - var codArticolo = new SqlParameter("@CodArticolo", CodArticolo); - - dbResult = dbCtx - .DbSetTurniParetoOdl - .FromSqlRaw("EXEC stp_UI_ParetoTurniOdl_GetByFilter @dataFrom,@dataTo,@idxMacchina,@IdxODL,@KeyRichiesta,@CodArticolo", dataFrom, dataTo, idxMacchina, idxODL, keyRichiesta, codArticolo) - .ToList(); - - return dbResult; - } - /// /// Elenco tabella UserLog da filtro /// diff --git a/MP.Data/DatabaseModels/TurniPareto.cs b/MP.Data/DatabaseModels/TurniPareto.cs deleted file mode 100644 index 73c9d689..00000000 --- a/MP.Data/DatabaseModels/TurniPareto.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System; -using System.Collections.Generic; - -#nullable disable - -namespace MP.Data.DatabaseModels -{ - public partial class TurniPareto - { - #region Public Properties - - public string ClasseTempo { get; set; } - public string CodArticolo { get; set; } - public string CodMacchina { get; set; } - public DateTime DataRif { get; set; } - public string DescArticolo { get; set; } - public string Descrizione { get; set; } - public string IdxMacchina { get; set; } - public int IdxStato { get; set; } - public double? TotPeriodo { get; set; } - public int? TotPz { get; set; } - public string Turno { get; set; } - - #endregion Public Properties - } -} \ No newline at end of file diff --git a/MP.Data/DatabaseModels/TurniParetoOdl.cs b/MP.Data/DatabaseModels/TurniParetoOdl.cs deleted file mode 100644 index 7a15b270..00000000 --- a/MP.Data/DatabaseModels/TurniParetoOdl.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System; -using System.Collections.Generic; - -#nullable disable - -namespace MP.Data.DatabaseModels -{ - public partial class TurniParetoOdl - { - #region Public Properties - - public string ClasseTempo { get; set; } - public string CodArticolo { get; set; } - public string CodMacchina { get; set; } - public DateTime DataRif { get; set; } - public string DescArticolo { get; set; } - public string Descrizione { get; set; } - public string IdxMacchina { get; set; } - public int? IdxOdl { get; set; } - public int IdxStato { get; set; } - public string KeyRichiesta { get; set; } - public double? TotPeriodo { get; set; } - public int? TotPz { get; set; } - public string Turno { get; set; } - - #endregion Public Properties - } -} \ No newline at end of file diff --git a/MP.Data/MP.Data.csproj b/MP.Data/MP.Data.csproj index de2014da..f9e16cd0 100644 --- a/MP.Data/MP.Data.csproj +++ b/MP.Data/MP.Data.csproj @@ -6,6 +6,11 @@ MP.Data + + + + + diff --git a/MP.Data/MoonPro_STATSContext.cs b/MP.Data/MoonPro_STATSContext.cs index b6161519..3218b430 100644 --- a/MP.Data/MoonPro_STATSContext.cs +++ b/MP.Data/MoonPro_STATSContext.cs @@ -43,8 +43,10 @@ namespace MP.Data public virtual DbSet DbSetODL { get; set; } public virtual DbSet DbSetScarti { get; set; } public virtual DbSet DbSetTurniOee { get; set; } +#if false public virtual DbSet DbSetTurniPareto { get; set; } public virtual DbSet DbSetTurniParetoOdl { get; set; } +#endif public virtual DbSet DbSetUserLog { get; set; } #endregion Public Properties @@ -103,72 +105,6 @@ namespace MP.Data .HasMaxLength(5); }); - modelBuilder.Entity(entity => - { - entity.HasNoKey(); - - entity.ToView("v_UI_Pareto_Turni"); - - entity.Property(e => e.ClasseTempo).HasMaxLength(50); - - entity.Property(e => e.CodArticolo) - .IsRequired() - .HasMaxLength(50); - - entity.Property(e => e.CodMacchina).HasMaxLength(50); - - entity.Property(e => e.DataRif).HasColumnType("datetime"); - - entity.Property(e => e.DescArticolo).HasMaxLength(250); - - entity.Property(e => e.Descrizione).HasMaxLength(50); - - entity.Property(e => e.IdxMacchina) - .IsRequired() - .HasMaxLength(50); - - entity.Property(e => e.TotPeriodo).HasColumnName("totPeriodo"); - - entity.Property(e => e.Turno) - .IsRequired() - .HasMaxLength(5); - }); - - modelBuilder.Entity(entity => - { - entity.HasNoKey(); - - entity.ToView("v_UI_Pareto_TurniOdl"); - - entity.Property(e => e.ClasseTempo).HasMaxLength(50); - - entity.Property(e => e.CodArticolo) - .IsRequired() - .HasMaxLength(50); - - entity.Property(e => e.CodMacchina).HasMaxLength(50); - - entity.Property(e => e.DataRif).HasColumnType("datetime"); - - entity.Property(e => e.DescArticolo).HasMaxLength(250); - - entity.Property(e => e.Descrizione).HasMaxLength(50); - - entity.Property(e => e.IdxMacchina) - .IsRequired() - .HasMaxLength(50); - - entity.Property(e => e.IdxOdl).HasColumnName("IdxODL"); - - entity.Property(e => e.KeyRichiesta).HasMaxLength(50); - - entity.Property(e => e.TotPeriodo).HasColumnName("totPeriodo"); - - entity.Property(e => e.Turno) - .IsRequired() - .HasMaxLength(5); - }); - modelBuilder.Entity(entity => { entity.HasNoKey(); diff --git a/MP.Stats/Components/ChartScarti.razor b/MP.Stats/Components/ChartScarti.razor new file mode 100644 index 00000000..d64d42bb --- /dev/null +++ b/MP.Stats/Components/ChartScarti.razor @@ -0,0 +1,34 @@ +@using MP.Stats.Data + +
+ @if (ListScarti == null || ListScarti.Count == 0) + { +
+
No Chart Data
+
+ } + else + { +
+
    + @foreach (var item in @ParetoData) + { +
  • + @item.label + @item.value +
  • + } +
+
+
+
+
+ +
+
+ +
+
+
+ } +
\ No newline at end of file diff --git a/MP.Stats/Components/ChartScarti.razor.cs b/MP.Stats/Components/ChartScarti.razor.cs new file mode 100644 index 00000000..f67e7626 --- /dev/null +++ b/MP.Stats/Components/ChartScarti.razor.cs @@ -0,0 +1,245 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Blazorise.Charts; +using Microsoft.AspNetCore.Components; +using MP.Stats.Data; + +namespace MP.Stats.Components +{ + public partial class ChartScarti + { + #region Protected Fields + + protected object barChartOptions = new + { + Scales = new + { + XAxes = new object[] + { + new { + Display = false + } + }, + YAxes = new object[] + { + new { + Display = true, + ticks= new { + suggestedMin = 0 + } + } + } + }, + Tooltips = new + { + Mode = "nearest", + Intersect = false + }, + Hover = new + { + Mode = "nearest", + Intersect = false + }, + Animation = false, + AspectRatio = 2.5 + }; + + protected object lineChartOptions = new + { + Scales = new + { + XAxes = new object[] + { + new { + Display = true, + //type = "time" + } + }, + YAxes = new object[] + { + new { + Display = true, + ticks= new { + suggestedMin = 0 + } + } + } + }, + Tooltips = new + { + Mode = "nearest", + Intersect = false + }, + Hover = new + { + Mode = "nearest", + Intersect = false + }, + Animation = false, + AspectRatio = 2.5 + }; + + protected LineChart NumGuasti; + + protected BarChart ParetoGuasti; + + #endregion Protected Fields + + #region Protected Properties + + protected SelectData _currFilter { get; set; } = new SelectData(); + + protected List _listScarti { get; set; } = new List(); + + [Inject] + protected MessageService MessageService { get; set; } + + protected List ParetoData { get; set; } = new List(); + + [Inject] + protected MpStatsService StatService { get; set; } + + protected List TSData { get; set; } = new List(); + + #endregion Protected Properties + + #region Public Properties + + [Parameter] + public List ListScarti + { + get => _listScarti; + set + { + // salvo valori + _listScarti = value; + if (value != null) + { + // ricalcolo charting data + recalcData(); + var dataReload = Task.Run(async () => + { + await HandleRedraw(); + }); + } + } + } + + #endregion Public Properties + + #region Private Methods + + private BarChartDataset GetBarChartDataset() + { + var answ = new BarChartDataset + { + Label = "Pareto Causali Scarto", + Data = ParetoData.Select(x => x.value).ToList(), + BackgroundColor = backgroundColors(ParetoData.Count), + //BorderColor = borderColors, + HoverBorderWidth = 5 + }; + return answ; + } + + private List GetBarChartLabels() + { + var answ = ParetoData.Select(x => x.label).ToList(); + return answ; + } + + private LineChartDataset GetLineChartDataset() + { + var answ = new LineChartDataset + { + Label = "Numero Scarti Periodo", + Data = TSData.Select(x => x.Value).ToList(), + BackgroundColor = backgroundColors(1), + Fill = true, + PointRadius = 2, + SteppedLine = true, + BorderDash = new List { } + }; + return answ; + } + + private List GetLineChartLabels() + { + var answ = TSData.Select(x => x.TLabel.ToString("ddd dd.MM")).ToList(); + return answ; + } + + private void recalcData() + { + if (ListScarti != null) + { + ParetoData = ListScarti + .GroupBy(x => x.Causale) + .Select(y => new ChartKV() { label = y.First().Descrizione, value = y.Sum(c => c.Qta) }) + .OrderByDescending(x => x.value) + .ToList(); + + TSData = ListScarti + .GroupBy(x => x.DataOraRif.Date) + .Select(y => new ChartTS() { TLabel = y.First().DataOraRif.Date, Value = y.Sum(c => c.Qta) }) + .OrderBy(x => x.TLabel) + .ToList(); + } + } + + #endregion Private Methods + + #region Protected Methods + + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List backgroundColors(int numRecords) + { + List answ = new List(); + // rosso... + for (int i = 0; i < numRecords / 3; i++) + { + answ.Add(ChartColor.FromRgba(255, 99, 132, 0.4f)); + } + // arancione + for (int i = 0; i < numRecords / 3; i++) + { + answ.Add(ChartColor.FromRgba(255, 206, 86, 0.4f)); + } + while (answ.Count < numRecords) + { + answ.Add(ChartColor.FromRgba(54, 82, 235, 0.4f)); + } + + return answ; + } + + //protected override async Task OnAfterRenderAsync(bool firstRender) + //{ + // if (firstRender) + // { + // await HandleRedraw(); + // } + //} + protected async Task HandleRedraw() + { + if (ParetoGuasti != null) + { + await ParetoGuasti.Clear(); + await ParetoGuasti.AddLabelsDatasetsAndUpdate(GetBarChartLabels(), GetBarChartDataset()); + } + if (NumGuasti != null) + { + await NumGuasti.Clear(); + await NumGuasti.AddLabelsDatasetsAndUpdate(GetLineChartLabels(), GetLineChartDataset()); + } + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/MP.Stats/Components/SelectionFilter.razor b/MP.Stats/Components/SelectionFilter.razor index abc3bb9f..186d369e 100644 --- a/MP.Stats/Components/SelectionFilter.razor +++ b/MP.Stats/Components/SelectionFilter.razor @@ -2,63 +2,82 @@ @using MP.Stats.Data -
-
+
+
- - -
-
-
-
- - -
-
-
-
- - - @foreach (var item in ddlMacchine) +
+
-
-
-
-
- +
+
+
+
+ +
-
- - @foreach (var item in ddlCommesse) - { - - } - -
-
-
-
-
-
- +
+
+ + +
+
+
+
+ + + @foreach (var item in ddlMacchine) + { + + } + +
+
+
+
+
+
+ +
+ +
+ + @foreach (var item in ddlCommesse) + { + + } + +
+
+
+
+
+
+ +
+ +
+ + @foreach (var item in ddlArticoli) + { + + } +
-
- - @foreach (var item in ddlArticoli) - { - - } -
-
+

diff --git a/MP.Stats/Components/SelectionFilter.razor.cs b/MP.Stats/Components/SelectionFilter.razor.cs index 70af721e..6cfab2d6 100644 --- a/MP.Stats/Components/SelectionFilter.razor.cs +++ b/MP.Stats/Components/SelectionFilter.razor.cs @@ -150,6 +150,12 @@ namespace MP.Stats.Components #region Public Properties + [Parameter] + public EventCallback chartsToggle { get; set; } + + [Parameter] + public bool chartVisible { get; set; } = false; + [Parameter] public EventCallback filterChanged { get; set; } @@ -194,6 +200,11 @@ namespace MP.Stats.Components filterReset.InvokeAsync(SelFilter); } + protected void toggleChart() + { + chartsToggle.InvokeAsync(chartVisible); + } + #endregion Protected Methods } } \ No newline at end of file diff --git a/MP.Stats/Data/ChartKV.cs b/MP.Stats/Data/ChartKV.cs new file mode 100644 index 00000000..6fcca452 --- /dev/null +++ b/MP.Stats/Data/ChartKV.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Stats.Data +{ + public class ChartKV + { + #region Public Properties + + public string label { get; set; } = ""; + public double value { get; set; } = 0; + + #endregion Public Properties + } +} \ No newline at end of file diff --git a/MP.Stats/Data/ChartTS.cs b/MP.Stats/Data/ChartTS.cs new file mode 100644 index 00000000..18d64e24 --- /dev/null +++ b/MP.Stats/Data/ChartTS.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Stats.Data +{ + public class ChartTS + { + #region Public Properties + + public DateTime TLabel { get; set; } = DateTime.Now; + public double Value { get; set; } = 0; + + #endregion Public Properties + } +} \ No newline at end of file diff --git a/MP.Stats/Data/MpStatsService.cs b/MP.Stats/Data/MpStatsService.cs index 9b17ab77..659d7a45 100644 --- a/MP.Stats/Data/MpStatsService.cs +++ b/MP.Stats/Data/MpStatsService.cs @@ -135,12 +135,13 @@ namespace MP.Stats.Data return Task.FromResult(answ); } - public Task> ArticoliList(string searchVal) + public async Task> ArticoliList(string searchVal) { List answ = new List(); answ.Add(new AutocompleteModel { LabelField = "--- TUTTE ---", ValueField = "*" }); - answ.AddRange(dbController.MacchineGetAll().Select(x => new AutocompleteModel { LabelField = x.IdxMacchina, ValueField = x.IdxMacchina }).ToList()); - return Task.FromResult(answ); + var listMacchine = dbController.MacchineGetAll(); + answ.AddRange(listMacchine.Select(x => new AutocompleteModel { LabelField = x.IdxMacchina, ValueField = x.IdxMacchina }).ToList()); + return await Task.FromResult(answ); } public Task> CommesseGetSearch(int numRecord, string searchVal = "") @@ -242,7 +243,7 @@ namespace MP.Stats.Data { //return Task.FromResult(dbController.StatScartiGetAll(DataStart, DataEnd, IdxMacchina, IdxODL, KeyRichiesta, CodArticolo).ToArray()); List dbResult = new List(); - string cacheKey = getCacheKey("MP:STATS:SCARTI", CurrFilter); + string cacheKey = getCacheKey("MP:STATS:SCARTI:RAW", CurrFilter); string rawData; var redisDataList = await distributedCache.GetAsync(cacheKey); if (redisDataList != null) @@ -286,16 +287,6 @@ namespace MP.Stats.Data return await Task.FromResult(dbResult); } - public Task StatTurniParetoGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo, string searchVal = "") - { - return Task.FromResult(dbController.StatTurniParetoGetAll(DataStart, DataEnd, IdxMacchina, IdxODL, KeyRichiesta, CodArticolo).ToArray()); - } - - public Task StatTurniParetoOdlGetAll(DateTime DataStart, DateTime DataEnd, string IdxMacchina, int IdxODL, string KeyRichiesta, string CodArticolo, string searchVal = "") - { - return Task.FromResult(dbController.StatTurniParetoOdlGetAll(DataStart, DataEnd, IdxMacchina, IdxODL, KeyRichiesta, CodArticolo).ToArray()); - } - public async Task> StatUserLogGetAll(SelectData CurrFilter, string searchVal = "") { //return Task.FromResult(dbController.StatUserLogGetAll(DataStart, DataEnd, IdxMacchina, IdxODL, KeyRichiesta, CodArticolo).ToArray()); diff --git a/MP.Stats/Pages/Controlli.razor b/MP.Stats/Pages/Controlli.razor index 6fa4103f..4afbf04a 100644 --- a/MP.Stats/Pages/Controlli.razor +++ b/MP.Stats/Pages/Controlli.razor @@ -4,7 +4,7 @@ @using MP.Stats.Components
-
+
diff --git a/MP.Stats/Pages/Diario.razor b/MP.Stats/Pages/Diario.razor index 313bd370..ac381528 100644 --- a/MP.Stats/Pages/Diario.razor +++ b/MP.Stats/Pages/Diario.razor @@ -3,7 +3,7 @@ @using MP.Stats.Components
-
+
diff --git a/MP.Stats/Pages/Oee.razor b/MP.Stats/Pages/Oee.razor index 598eb0c3..2beb55a2 100644 --- a/MP.Stats/Pages/Oee.razor +++ b/MP.Stats/Pages/Oee.razor @@ -3,7 +3,7 @@ @using MP.Stats.Components
-
+
diff --git a/MP.Stats/Pages/ReportODL.razor b/MP.Stats/Pages/ReportODL.razor index ebf165af..536804d6 100644 --- a/MP.Stats/Pages/ReportODL.razor +++ b/MP.Stats/Pages/ReportODL.razor @@ -3,7 +3,7 @@ @using MP.Stats.Components
-
+
diff --git a/MP.Stats/Pages/Scarti.razor b/MP.Stats/Pages/Scarti.razor index 6e1d4d55..2cbadff3 100644 --- a/MP.Stats/Pages/Scarti.razor +++ b/MP.Stats/Pages/Scarti.razor @@ -3,10 +3,14 @@ @using MP.Stats.Components
-
- +
+
+ @if (ShowCharts == true) + { + + } @if (ListRecords == null) { diff --git a/MP.Stats/Pages/Scarti.razor.cs b/MP.Stats/Pages/Scarti.razor.cs index bfb8cc7c..bcd6b211 100644 --- a/MP.Stats/Pages/Scarti.razor.cs +++ b/MP.Stats/Pages/Scarti.razor.cs @@ -36,6 +36,7 @@ namespace MP.Stats.Pages private int currPage { get; set; } = 1; private bool isLoading { get; set; } = false; private int numRecord { get; set; } = 10; + private bool ShowCharts { get; set; } = false; #endregion Private Properties @@ -127,6 +128,15 @@ namespace MP.Stats.Pages await reloadData(); } + protected async Task ToggleChart(bool doShow) + { + ShowCharts = !ShowCharts; + if (ShowCharts) + { + await reloadData(); + } + } + protected async Task UpdateData() { currRecord = null; diff --git a/MP.Stats/Pages/UserLog.razor b/MP.Stats/Pages/UserLog.razor index 29465fa5..4dc6b64b 100644 --- a/MP.Stats/Pages/UserLog.razor +++ b/MP.Stats/Pages/UserLog.razor @@ -3,7 +3,7 @@ @using MP.Stats.Components
-
+