diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index 99a5856f..aef87929 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -9,6 +9,7 @@ using System; using System.Collections.Generic; using System.Data; using System.Linq; +using System.Runtime.InteropServices; using System.Threading.Tasks; using ZXing; using static EgwCoreLib.Utils.DtUtils; @@ -553,43 +554,197 @@ namespace MP.Data.Controllers public async Task FluxLogDataRedux(string idxMaccSel, List fluxList, Periodo currPeriodo, Enum.ValSelection valMode, Enum.DataInterval intReq) { bool fatto = false; - using (var dbCtx = new MoonProContext(_configuration)) + TimeSpan step = TimeSpan.FromHours(1); + switch (intReq) { - // ora recupero TUTTI i dati della macchina - var dbResult = await dbCtx - .DbSetFluxLog - .Where(x => (x.dtEvento >= currPeriodo.Inizio && x.dtEvento <= currPeriodo.Fine) && (x.IdxMacchina == idxMaccSel)) - .ToListAsync(); - TimeSpan step = TimeSpan.FromHours(1); - switch (intReq) + case Enum.DataInterval.minute: + step = TimeSpan.FromMinutes(1); + break; + case Enum.DataInterval.hour: + step = TimeSpan.FromHours(1); + break; + case Enum.DataInterval.day: + step = TimeSpan.FromDays(1); + break; + default: + break; + } + + // setup parametri costanti x stored + var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMaccSel); + var pOnlyTest = new SqlParameter("@OnlyTest", false); + var pDoReIndex = new SqlParameter("@DoReIndex", false); // sarà cambiato solo alla fine x avere un reindex finale x macchina + + // processo 1:1 ogni flusso + foreach (var item in fluxList) + { + // parametri x flusso + var pCodFlux = new SqlParameter("@CodFlux", item); + // inizializzo cursore timer + DateTime dtCursStart = currPeriodo.Inizio; + DateTime dtCursEnd = dtCursStart.Add(step); + bool setCompleted = false; + // dbCOntext x ogni singolo flusso + using (var dbCtx = new MoonProContext(_configuration)) { - case Enum.DataInterval.minute: - step = TimeSpan.FromMinutes(1); - break; - case Enum.DataInterval.hour: - step = TimeSpan.FromHours(1); - break; - case Enum.DataInterval.day: - step = TimeSpan.FromDays(1); - break; - default: - break; - } - // processo 1:1 ogni flusso - foreach (var item in fluxList) - { - DateTime dtCursor = currPeriodo.Inizio; - // dati da processare - var currFlux = dbResult - .Where(x => x.CodFlux == item) - .ToList(); // li processo per intervallo richiesto, cercando dati nel periodo e selezionando VC - while (currFlux.Count > 0) + while (!setCompleted) { + // ora recupero TUTTI i dati della macchina + var currFlux = await dbCtx + .DbSetFluxLog + .Where(x => (x.CodFlux == item) && (x.dtEvento >= dtCursStart && x.dtEvento < dtCursEnd) && (x.IdxMacchina == idxMaccSel)) + .ToListAsync(); + // incremento dt fine periodo - dtCursor = dtCursor.Add(step); + dtCursStart = dtCursEnd; + dtCursEnd = dtCursStart.Add(step); + int numRec = currFlux.Count; + 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(); + + + switch (valMode) + { + case Enum.ValSelection.First: + // recupero 2° item + var recStart = currFlux.Skip(1).FirstOrDefault(); + // salvo periodo! + listPeriodi.Add(new Periodo(recStart.dtEvento, dtCursEnd)); + break; + case Enum.ValSelection.Last: + // recupero ultimo item + var recEnd = currFlux.LastOrDefault(); + // salvo periodo! + listPeriodi.Add(new Periodo(dtCursStart, recEnd.dtEvento)); + break; + case Enum.ValSelection.Center: + var recCent = currFlux.Skip(numRec / 2).FirstOrDefault(); + // salvo 2 periodi! + listPeriodi.Add(new Periodo(dtCursStart, recCent.dtEvento)); + listPeriodi.Add(new Periodo(recCent.dtEvento.AddSeconds(1), dtCursEnd)); + break; + default: + break; + } + + // 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); + var dbResult = dbCtx + .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 < dtCursor).ToList(); + var currSet = currFlux.Where(x => x.dtEvento < dtCursStart).ToList(); if (currSet.Count > 0) { switch (valMode) @@ -608,12 +763,16 @@ namespace MP.Data.Controllers break; } - // elimino i dati processati + //// elimino i dati processati + //foreach (var item2del in currSet) + //{ + // currFlux.Remove(item2del); + //} dbCtx.DbSetFluxLog.RemoveRange(currSet); try { // salvo - await dbCtx.SaveChangesAsync(); + dbCtx.SaveChanges(); } catch (Exception exc) { @@ -621,15 +780,15 @@ namespace MP.Data.Controllers } // tengo solo i dati successivi x prossimo giro... - currFlux = currFlux.Where(x => x.dtEvento >= dtCursor).ToList(); + currFlux = currFlux.Where(x => x.dtEvento >= dtCursStart).ToList(); + } +#endif } } - // salvo - await dbCtx.SaveChangesAsync(); } } - await Task.Delay(1500); + //await Task.Delay(1500); return fatto; } diff --git a/MP.SPEC/Components/FLStatusList.razor b/MP.SPEC/Components/FLStatusList.razor index 9a31dad1..ac7918be 100644 --- a/MP.SPEC/Components/FLStatusList.razor +++ b/MP.SPEC/Components/FLStatusList.razor @@ -28,10 +28,10 @@ else @($"{item.Qty:N0}") - @($"{(item.Qty / numDay):N0}") + @($"{((float)item.Qty / numDay):N1}") - @($"{(item.Qty / numHour):N0}") + @($"{((float)item.Qty / numHour):N2}") } diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index d506ec1e..f33a96bc 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 6.16.2310.2020 + 6.16.2310.2111 diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index f0125553..1fb3ba8b 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 6.16.2310.2020

+

Versione: 6.16.2310.2111


Note di rilascio:
  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index de257374..010d11a2 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2310.2020 +6.16.2310.2111 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index f5ca8fcb..e272862b 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2310.2020 + 6.16.2310.2111 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