From 7f7a3b6f51141ef67c5a044a4f8afe0b89ae90b5 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 21 Oct 2023 12:41:44 +0200 Subject: [PATCH] Inserimento progress in dedup FL --- MP.Data/Controllers/MpSpecController.cs | 195 ++++++---------------- MP.Data/DatabaseModels/LogFLDedupModel.cs | 40 +++++ MP.Data/MoonProContext.cs | 2 + MP.SPEC/MP.SPEC.csproj | 2 +- MP.SPEC/Pages/FluxLogStatus.razor | 1 + MP.SPEC/Pages/FluxLogStatus.razor.cs | 13 +- MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- 9 files changed, 109 insertions(+), 150 deletions(-) create mode 100644 MP.Data/DatabaseModels/LogFLDedupModel.cs diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index aef87929..cb420ac9 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -8,6 +8,7 @@ using NLog.LayoutRenderers; using System; using System.Collections.Generic; using System.Data; +using System.Diagnostics; using System.Linq; using System.Runtime.InteropServices; using System.Threading.Tasks; @@ -553,6 +554,7 @@ namespace MP.Data.Controllers /// public async Task FluxLogDataRedux(string idxMaccSel, List fluxList, Periodo currPeriodo, Enum.ValSelection valMode, Enum.DataInterval intReq) { + Log.Info($"Inizio FluxLogDataRedux | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio} --> {currPeriodo.Fine}"); bool fatto = false; TimeSpan step = TimeSpan.FromHours(1); switch (intReq) @@ -569,6 +571,7 @@ namespace MP.Data.Controllers default: break; } + List procStats = new List(); // setup parametri costanti x stored var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMaccSel); @@ -578,6 +581,10 @@ namespace MP.Data.Controllers // processo 1:1 ogni flusso foreach (var item in fluxList) { + Log.Info($"FluxLogDataRedux | Flux: {item}"); + int numRecProc = 0; + Stopwatch sw = new Stopwatch(); + sw.Start(); // parametri x flusso var pCodFlux = new SqlParameter("@CodFlux", item); // inizializzo cursore timer @@ -596,67 +603,14 @@ namespace MP.Data.Controllers .Where(x => (x.CodFlux == item) && (x.dtEvento >= dtCursStart && x.dtEvento < dtCursEnd) && (x.IdxMacchina == idxMaccSel)) .ToListAsync(); - // incremento dt fine periodo - dtCursStart = dtCursEnd; - dtCursEnd = dtCursStart.Add(step); int numRec = currFlux.Count; + numRecProc += numRec; if (numRec > 1) { if (dtCursStart > currPeriodo.Fine) { setCompleted = true; } -#if false - //var set2del = currFlux; - - //switch (valMode) - //{ - // case Enum.ValSelection.First: - // // tolgo il primo (che quindi lascio) - // set2del.RemoveAt(0); - // break; - // case Enum.ValSelection.Last: - // set2del.RemoveAt(numRec - 1); - // break; - // case Enum.ValSelection.Center: - // set2del.RemoveAt(numRec / 2); - // break; - // default: - // break; - //} - //dbCtx.DbSetFluxLog.RemoveRange(set2del); -#endif - -#if false - switch (valMode) - { - case Enum.ValSelection.First: - // tolgo il primo (che quindi lascio) - currFlux.RemoveAt(0); - break; - case Enum.ValSelection.Last: - currFlux.RemoveAt(numRec - 1); - break; - case Enum.ValSelection.Center: - currFlux.RemoveAt(numRec / 2); - break; - default: - break; - } - dbCtx.RemoveRange(currFlux); - - dbCtx.ChangeTracker.DetectChanges(); - Log.Trace(dbCtx.ChangeTracker.DebugView.LongView); - try - { - // salvo - await dbCtx.SaveChangesAsync(false); - } - catch (Exception exc) - { - Log.Error($"Eccezione in deduplica dati FluxLog{Environment.NewLine}{exc}"); - } -#endif List listPeriodi = new List(); @@ -687,8 +641,6 @@ namespace MP.Data.Controllers // ciclo x tutti i periodi e chiamo stored... foreach (var slot in listPeriodi) { - - // parametri x periodo (base) var pDtStart = new SqlParameter("@DtStart", slot.Inizio); var pDtEnd = new SqlParameter("@DtEnd", slot.Fine); @@ -696,99 +648,52 @@ namespace MP.Data.Controllers .Database .ExecuteSqlRaw("EXEC man.stp_ReduceFluxLog @IdxMacchina, @CodFlux, @DtStart, @DtEnd, @OnlyTest, @DoReIndex", pIdxMacchina, pCodFlux, pDtStart, pDtEnd, pOnlyTest, pDoReIndex); } - -#if false - if (dtCursStart > currPeriodo.Fine) - { - setCompleted = true; - } - var currSet = currFlux.ToList(); - if (currSet.Count > 0) - { - switch (valMode) - { - case Enum.ValSelection.First: - // tolgo il primo (che quindi lascio) - currSet.RemoveAt(0); - break; - case Enum.ValSelection.Last: - currSet.RemoveAt(currSet.Count - 1); - break; - case Enum.ValSelection.Center: - currSet.RemoveAt(currSet.Count / 2); - break; - default: - break; - } - - //// elimino i dati processati - //foreach (var item2del in currSet) - //{ - // currFlux.Remove(item2del); - //} - dbCtx.DbSetFluxLog.RemoveRange(currSet); - try - { - // salvo - dbCtx.SaveChanges(); - } - catch (Exception exc) - { - Log.Error($"Eccezione in deduplica dati FluxLog{Environment.NewLine}{exc}"); - } - - } -#endif - - - -#if false - // seleziono dati da processare - var currSet = currFlux.Where(x => x.dtEvento < dtCursStart).ToList(); - if (currSet.Count > 0) - { - switch (valMode) - { - case Enum.ValSelection.First: - // tolgo il primo (che quindi lascio) - currSet.RemoveAt(0); - break; - case Enum.ValSelection.Last: - currSet.RemoveAt(currSet.Count - 1); - break; - case Enum.ValSelection.Center: - currSet.RemoveAt(currSet.Count / 2); - break; - default: - break; - } - - //// elimino i dati processati - //foreach (var item2del in currSet) - //{ - // currFlux.Remove(item2del); - //} - dbCtx.DbSetFluxLog.RemoveRange(currSet); - try - { - // salvo - dbCtx.SaveChanges(); - } - catch (Exception exc) - { - Log.Error($"Eccezione in deduplica dati FluxLog{Environment.NewLine}{exc}"); - } - - // tengo solo i dati successivi x prossimo giro... - currFlux = currFlux.Where(x => x.dtEvento >= dtCursStart).ToList(); - } -#endif } - } + // incremento dt fine periodo + dtCursStart = dtCursEnd; + dtCursEnd = dtCursStart.Add(step); + } + } + // fermo cronometro e salvo su DB... + sw.Stop(); + LogFLDedupModel currStat = new LogFLDedupModel() + { + IdxMacchina = idxMaccSel, + CodFlux = item, + DtRif = DateTime.Now, + NumRec = numRecProc, + ProcTime = sw.Elapsed.TotalSeconds + }; + procStats.Add(currStat); + } + + // salvo le statistiche di processing... + fatto = LogFLDedupInsert(procStats); + Log.Info($"FINE FluxLogDataRedux | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio} --> {currPeriodo.Fine}"); + return fatto; + } + /// + /// Inserimento record risultati deduplica FluxLog + /// + /// + /// + protected bool LogFLDedupInsert(List rec2ins) + { + bool fatto = false; + using (var dbCtx = new MoonProContext(_configuration)) + { + try + { + dbCtx.DbSetLogFLDedup.AddRange(rec2ins); + var res = dbCtx.SaveChanges(); + fatto = res != 0; + } + catch (Exception exc) + { + Log.Error($"Errore in fase inserimento log dedup x FL{Environment.NewLine}{exc}"); } } - //await Task.Delay(1500); return fatto; } diff --git a/MP.Data/DatabaseModels/LogFLDedupModel.cs b/MP.Data/DatabaseModels/LogFLDedupModel.cs new file mode 100644 index 00000000..4e3ffee1 --- /dev/null +++ b/MP.Data/DatabaseModels/LogFLDedupModel.cs @@ -0,0 +1,40 @@ +using System; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + + +#nullable disable +// +// This is here so CodeMaid doesn't reorganize this document +// +namespace MP.Data.DatabaseModels +{ + [Table("LogFLDedup")] + public partial class LogFLDedupModel + { + #region Public Properties + + [Key, DatabaseGenerated(DatabaseGeneratedOption.Identity)] + public int DedupIdx { get; set; } = 0; + + [MaxLength(50)] + public string IdxMacchina { get; set; } = ""; + + [MaxLength(50)] + public string CodFlux { get; set; } = ""; + + public DateTime DtRif { get; set; }=DateTime.Now; + + /// + /// Num record processati + /// + public int NumRec { get; set; } = 0; + + /// + /// Tempo processing (secondi) + /// + public double ProcTime { get; set; } = 1; + + #endregion Public Properties + } +} \ No newline at end of file diff --git a/MP.Data/MoonProContext.cs b/MP.Data/MoonProContext.cs index aad4e57d..54fd7757 100644 --- a/MP.Data/MoonProContext.cs +++ b/MP.Data/MoonProContext.cs @@ -90,7 +90,9 @@ namespace MP.Data public virtual DbSet DbSetCommenti { get; set; } public virtual DbSet DbSetFNQ { get; set; } + public virtual DbSet DbSetLogFLDedup { get; set; } + public virtual DbSet DbSetVSEB { get; set; } public virtual DbSet DbSetVSODL { get; set; } diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index f33a96bc..eefa302b 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 6.16.2310.2111 + 6.16.2310.2112 diff --git a/MP.SPEC/Pages/FluxLogStatus.razor b/MP.SPEC/Pages/FluxLogStatus.razor index d401c25e..372c0e5a 100644 --- a/MP.SPEC/Pages/FluxLogStatus.razor +++ b/MP.SPEC/Pages/FluxLogStatus.razor @@ -33,6 +33,7 @@
@if (isProcessing) { + } else diff --git a/MP.SPEC/Pages/FluxLogStatus.razor.cs b/MP.SPEC/Pages/FluxLogStatus.razor.cs index c918d071..1cf9d043 100644 --- a/MP.SPEC/Pages/FluxLogStatus.razor.cs +++ b/MP.SPEC/Pages/FluxLogStatus.razor.cs @@ -116,11 +116,22 @@ namespace MP.SPEC.Pages protected async Task DoCleanup() { isProcessing = true; - + // processo i flussi in subset x mandare update ad avanzamento await MDataServ.FluxLogDataRedux(idxMaccSel, fluxList, CurrPeriodo, ValMode, IntReq); isProcessing = false; } + /// + /// Tempo atteso processing + /// - da calcolare in abse al num eventi e alla tab logProcessing... + /// + private int expTimeMsec = 10000; + private int countFlux = 0; + private int numFlux + { + get => fluxList.Count * 10; + } + protected ValSelection ValMode = ValSelection.Center; protected DataInterval IntReq = DataInterval.hour; diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 1fb3ba8b..115c9339 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 6.16.2310.2111

+

Versione: 6.16.2310.2112


Note di rilascio:
  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index 010d11a2..d40ef182 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2310.2111 +6.16.2310.2112 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index e272862b..f6fcc50c 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2310.2111 + 6.16.2310.2112 https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/MP.SPEC.zip https://nexus.steamware.net/repository/SWS/MP-SPEC/stable/LAST/ChangeLog.html false