From afd3ec34bb8e8e7f48ebf88067d52738cdb611ba Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 23 Oct 2023 12:07:57 +0200 Subject: [PATCH 1/7] SPEC: - Completata procedura adv x ricalcolo FluxLog --- MP.Data/Controllers/MpSpecController.cs | 46 +++++++-- MP.Data/Enum.cs | 10 +- MP.SPEC/Data/MpDataService.cs | 32 +++++-- MP.SPEC/MP.SPEC.csproj | 2 +- MP.SPEC/Pages/FluxLogStatus.razor | 40 ++++---- MP.SPEC/Pages/FluxLogStatus.razor.cs | 118 +++++++++++++++++------- MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- 9 files changed, 181 insertions(+), 73 deletions(-) diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index cb420ac9..ddf75ff4 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -552,7 +552,7 @@ namespace MP.Data.Controllers /// /// /// - public async Task FluxLogDataRedux(string idxMaccSel, List fluxList, Periodo currPeriodo, Enum.ValSelection valMode, Enum.DataInterval intReq) + public async Task FluxLogDataRedux(string idxMaccSel, List fluxList, Periodo currPeriodo, Enum.ValSelection valMode, Enum.DataInterval intReq, int maxItem) { Log.Info($"Inizio FluxLogDataRedux | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio} --> {currPeriodo.Fine}"); bool fatto = false; @@ -560,13 +560,13 @@ namespace MP.Data.Controllers switch (intReq) { case Enum.DataInterval.minute: - step = TimeSpan.FromMinutes(1); + step = TimeSpan.FromMinutes(1.00/ maxItem); break; case Enum.DataInterval.hour: - step = TimeSpan.FromHours(1); + step = TimeSpan.FromHours(1.00 / maxItem); break; case Enum.DataInterval.day: - step = TimeSpan.FromDays(1); + step = TimeSpan.FromDays(1.00 / maxItem); break; default: break; @@ -576,7 +576,6 @@ namespace MP.Data.Controllers // 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) @@ -591,7 +590,7 @@ namespace MP.Data.Controllers DateTime dtCursStart = currPeriodo.Inizio; DateTime dtCursEnd = dtCursStart.Add(step); bool setCompleted = false; - // dbCOntext x ogni singolo flusso + // dbContext x ogni singolo flusso using (var dbCtx = new MoonProContext(_configuration)) { // li processo per intervallo richiesto, cercando dati nel periodo e selezionando VC @@ -646,7 +645,7 @@ namespace MP.Data.Controllers 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); + .ExecuteSqlRaw("EXEC man.stp_ReduceFluxLog @IdxMacchina, @CodFlux, @DtStart, @DtEnd, @OnlyTest", pIdxMacchina, pCodFlux, pDtStart, pDtEnd, pOnlyTest); } } @@ -673,6 +672,39 @@ namespace MP.Data.Controllers Log.Info($"FINE FluxLogDataRedux | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio} --> {currPeriodo.Fine}"); return fatto; } + + /// + /// Stored manutenzione del DB + /// + /// Esegue realmente il task + /// Aggiornamento statistiche + /// Salvataggio + /// def: 1000 + /// def: 10 + /// def: 50 + /// + public bool ForceDbMaint(bool doExec, bool doUpdStat, bool doSave, int minPgCnt, int minAvgFrag, int maxAvgFragReb) + { + Log.Info($"Inizio ForceDbMaint"); + bool fatto = false; + using (var dbCtx = new MoonProContext(_configuration)) + { + var pFlgExec = new SqlParameter("@FlgExec", doExec ? "Y" : "N"); + var pFlgUpdStat = new SqlParameter("@FlgUpdStat", doUpdStat ? "Y" : "N"); + var pFlgSave = new SqlParameter("@FlgSave", doSave ? "Y" : "N"); + var pMinPgCnt = new SqlParameter("@min_page_count", minPgCnt); + var pMinAvgFrag = new SqlParameter("@min_avg_fragmentation_in_percent", minAvgFrag); + var pMaxAvgFrag = new SqlParameter("@max_avg_fragmentation_per_rebuild", maxAvgFragReb); + + var dbResult = dbCtx + .Database + .ExecuteSqlRaw("EXEC man.stp_Utility_Maintanance @FlgExec, @FlgUpdStat, @FlgSave, @min_page_count, @min_avg_fragmentation_in_percent, @max_avg_fragmentation_per_rebuild", pFlgExec, pFlgUpdStat, pFlgSave, pMinPgCnt, pMinAvgFrag, pMaxAvgFrag); + fatto = true; + } + Log.Info($"FINE ForceDbMaint"); + return fatto; + } + /// /// Inserimento record risultati deduplica FluxLog /// diff --git a/MP.Data/Enum.cs b/MP.Data/Enum.cs index 3e1c6a41..3a5afa29 100644 --- a/MP.Data/Enum.cs +++ b/MP.Data/Enum.cs @@ -18,13 +18,13 @@ namespace MP.Data /// First, /// - /// Selezione ULTIMO valore del set - /// - Last, - /// /// Selezione Moda (norma) = elemento centrale /// - Center + Center, + /// + /// Selezione ULTIMO valore del set + /// + Last } /// /// Intervallo dati (es per definizione quanti dati FluxLog tenere x intervallo diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 64ceb227..90cf6134 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -1,4 +1,5 @@ using EgwCoreLib.Utils; +using Microsoft.AspNetCore.Razor.TagHelpers; using MP.Data; using MP.Data.Conf; using MP.Data.DatabaseModels; @@ -1775,15 +1776,32 @@ namespace MP.SPEC.Data /// /// Funzione di Data Reduction x FluxLog /// - /// - /// - /// - /// - /// + /// Macchina + /// Elenco FL da processare + /// Periodo + /// modalità sel valore + /// intervallo di analisi + /// max num per intervallo /// - public async Task FluxLogDataRedux(string idxMaccSel, List fluxList, DtUtils.Periodo currPeriodo, ValSelection valMode, DataInterval intReq) + public async Task FluxLogDataRedux(string idxMaccSel, List fluxList, DtUtils.Periodo currPeriodo, ValSelection valMode, DataInterval intReq, int maxItem) { - await dbController.FluxLogDataRedux(idxMaccSel, fluxList, currPeriodo, valMode, intReq); + await dbController.FluxLogDataRedux(idxMaccSel, fluxList, currPeriodo, valMode, intReq, maxItem); + await FlushCacheFluxLog(); + } + + /// + /// Stored manutenzione del DB + /// + /// Esegue realmente il task + /// Aggiornamento statistiche + /// Salvataggio + /// def: 1000 + /// def: 10 + /// def: 50 + /// + public async Task ForceDbMaint(bool doExec = true, bool doUpdStat = true, bool doSave = true, int minPgCnt = 1000, int minAvgFrag = 10, int maxAvgFragReb = 50) + { + dbController.ForceDbMaint(doExec, doUpdStat, doSave, minPgCnt, minAvgFrag, maxAvgFragReb); await FlushCacheFluxLog(); } diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index eefa302b..0e53782a 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 6.16.2310.2112 + 6.16.2310.2312 diff --git a/MP.SPEC/Pages/FluxLogStatus.razor b/MP.SPEC/Pages/FluxLogStatus.razor index 372c0e5a..2984c76b 100644 --- a/MP.SPEC/Pages/FluxLogStatus.razor +++ b/MP.SPEC/Pages/FluxLogStatus.razor @@ -3,8 +3,8 @@
-
-

FluxLogStatus

+
+

Status

@@ -25,7 +25,7 @@
-
+
@@ -33,7 +33,7 @@
@if (isProcessing) { - + } else @@ -45,22 +45,12 @@ diff --git a/MP.SPEC/Pages/FluxLogStatus.razor.cs b/MP.SPEC/Pages/FluxLogStatus.razor.cs index 1cf9d043..c8c34514 100644 --- a/MP.SPEC/Pages/FluxLogStatus.razor.cs +++ b/MP.SPEC/Pages/FluxLogStatus.razor.cs @@ -1,7 +1,7 @@ using global::Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; using MP.SPEC.Data; using NLog; -using System; using static EgwCoreLib.Utils.DtUtils; using static MP.Data.Enum; @@ -11,24 +11,84 @@ namespace MP.SPEC.Pages { #region Protected Fields + protected DataInterval IntReq = DataInterval.hour; protected int numRecPage = 10; protected int pageNum = 1; protected int totalCount = 0; + protected ValSelection ValMode = ValSelection.Center; + #endregion Protected Fields #region Protected Properties - protected Dictionary ListMacchineAll { get; set; } = new Dictionary(); protected List fluxList { get; set; } = new List(); + [Inject] + protected IJSRuntime JSRuntime { get; set; } = null!; + + protected Dictionary ListMacchineAll { get; set; } = new Dictionary(); + [Inject] protected MpDataService MDataServ { get; set; } = null!; + protected int NumItem + { + get => numItem; + set + { + if (numItem != value) + { + // controllo valori ammissibili + numItem = value >= 1 ? value : 1; + } + } + } + #endregion Protected Properties #region Protected Methods + /// + /// Esegue cleanup dati + /// + /// + protected async Task DoCleanup() + { + if (!await JSRuntime.InvokeAsync("confirm", "Attenzione! il task di Data Cleanup eliminerà in modo definitivo i dati in eccesso secondo lo schema impostato, sei sicuro di voler procedere?")) + return; + + isProcessing = true; + int currStep = 1; + int stepVal = 1; + foreach (var item in fluxList) + { + await InvokeAsync(StateHasChanged); + // aggiorno valori + currVal = (currStep - 1) * stepVal; + nextVal = currStep * stepVal; + // processo i flussi 1:1 x mandare update ad avanzamento + await MDataServ.FluxLogDataRedux(idxMaccSel, new List { item }, CurrPeriodo, ValMode, IntReq, NumItem); + currStep++; + } + //await MDataServ.FluxLogDataRedux(idxMaccSel, fluxList, CurrPeriodo, ValMode, IntReq, maxItem); + isProcessing = false; + } + + /// + /// Esegue cleanup dati + /// + /// + protected async Task IdxRebuild() + { + if (!await JSRuntime.InvokeAsync("confirm", "Manutenzione Database: si tratta di un operazione che può richiedere un tempo levato sei sicuro di voler procedere?")) + return; + + isProcessing = true; + await MDataServ.ForceDbMaint(true, true, true, 1000, 10, 50); + isProcessing = false; + } + protected override async Task OnInitializedAsync() { await ReloadData(); @@ -47,6 +107,12 @@ namespace MP.SPEC.Pages } } + protected async Task SaveFluxList(List newList) + { + fluxList = newList; + await Task.Delay(1); + } + protected void SaveNumRec(int newNum) { if (numRecPage != newNum) @@ -77,11 +143,6 @@ namespace MP.SPEC.Pages totalCount = numRec; await Task.Delay(1); } - protected async Task SaveFluxList(List newList) - { - fluxList = newList; - await Task.Delay(1); - } #endregion Protected Methods @@ -89,6 +150,14 @@ namespace MP.SPEC.Pages private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + + /// + /// Tempo atteso processing + /// - da calcolare in base al num eventi e alla tab logProcessing... + /// + private int expTimeMsec = 3000; + #endregion Private Fields #region Private Properties @@ -98,6 +167,16 @@ namespace MP.SPEC.Pages private string idxMaccSel { get; set; } = ""; private bool isProcessing { get; set; } = false; + + protected double currVal = 0; + protected double nextVal = 0; + protected int MaxVal + { + get => fluxList.Count; + } + + private int numItem { get; set; } = 1; + #endregion Private Properties #region Private Methods @@ -109,31 +188,6 @@ namespace MP.SPEC.Pages DateTime dtStart = dtEnd.AddMonths(-1); CurrPeriodo = new Periodo(dtStart, dtEnd); } - /// - /// Esegue cleanup dati - /// - /// - 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; #endregion Private Methods } diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 115c9339..09ad6fb2 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

Versione: 6.16.2310.2112

+

Versione: 6.16.2310.2312


Note di rilascio:
  • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index d40ef182..d90133b4 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2310.2112 +6.16.2310.2312 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index f6fcc50c..b4c63949 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2310.2112 + 6.16.2310.2312 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 From 3b82c3efcf173bc534198c779eca9680c254ff8c Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 23 Oct 2023 12:08:47 +0200 Subject: [PATCH 2/7] Refresh procedura ricalcolo --- MP.SPEC/Pages/FluxLogStatus.razor.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/MP.SPEC/Pages/FluxLogStatus.razor.cs b/MP.SPEC/Pages/FluxLogStatus.razor.cs index c8c34514..6bb67276 100644 --- a/MP.SPEC/Pages/FluxLogStatus.razor.cs +++ b/MP.SPEC/Pages/FluxLogStatus.razor.cs @@ -63,10 +63,10 @@ namespace MP.SPEC.Pages int stepVal = 1; foreach (var item in fluxList) { - await InvokeAsync(StateHasChanged); // aggiorno valori currVal = (currStep - 1) * stepVal; nextVal = currStep * stepVal; + await InvokeAsync(StateHasChanged); // processo i flussi 1:1 x mandare update ad avanzamento await MDataServ.FluxLogDataRedux(idxMaccSel, new List { item }, CurrPeriodo, ValMode, IntReq, NumItem); currStep++; From 6c563b8b2867d950916f6636af71a9ee50abbedd Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 23 Oct 2023 18:50:00 +0200 Subject: [PATCH 3/7] Update x gestione calcoli stats in Redis --- MP.Data/Controllers/MpSpecController.cs | 36 +++++++++----- MP.Data/DTO/StatDedupDTO.cs | 56 ++++++++++++++++++++++ MP.Data/Utils.cs | 1 + MP.SPEC/Data/MpDataService.cs | 64 ++++++++++++++++++++++++- MP.SPEC/MP.SPEC.csproj | 2 +- MP.SPEC/Pages/FluxLogStatus.razor.cs | 10 ++++ MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- 9 files changed, 159 insertions(+), 16 deletions(-) create mode 100644 MP.Data/DTO/StatDedupDTO.cs diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index ddf75ff4..e3cbc159 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -551,16 +551,16 @@ namespace MP.Data.Controllers /// /// /// - /// - public async Task FluxLogDataRedux(string idxMaccSel, List fluxList, Periodo currPeriodo, Enum.ValSelection valMode, Enum.DataInterval intReq, int maxItem) + /// Restitusice list dei record statistiche raccolti (da integrare a quelli rpesenti in Redis...) + public async Task> FluxLogDataRedux(string idxMaccSel, List fluxList, Periodo currPeriodo, Enum.ValSelection valMode, Enum.DataInterval intReq, int maxItem) { + List procStats = new List(); Log.Info($"Inizio FluxLogDataRedux | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio} --> {currPeriodo.Fine}"); - bool fatto = false; TimeSpan step = TimeSpan.FromHours(1); switch (intReq) { case Enum.DataInterval.minute: - step = TimeSpan.FromMinutes(1.00/ maxItem); + step = TimeSpan.FromMinutes(1.00 / maxItem); break; case Enum.DataInterval.hour: step = TimeSpan.FromHours(1.00 / maxItem); @@ -571,7 +571,6 @@ namespace MP.Data.Controllers default: break; } - List procStats = new List(); // setup parametri costanti x stored var pIdxMacchina = new SqlParameter("@IdxMacchina", idxMaccSel); @@ -628,9 +627,21 @@ namespace MP.Data.Controllers listPeriodi.Add(new Periodo(dtCursStart, recEnd.dtEvento)); break; case Enum.ValSelection.Center: - var recCent = currFlux.Skip(numRec / 2).FirstOrDefault(); - // salvo 2 periodi! + int idx = 1; + // per iniziare mi metto a 1/(n+1) rec come step + var recCent = currFlux.Skip(idx / (maxItem + 1)).FirstOrDefault(); listPeriodi.Add(new Periodo(dtCursStart, recCent.dtEvento)); + // salvo restanti periodi (se > 1)! + if (maxItem > 1) + { + for (int i = 2; i < maxItem; i++) + { + DateTime dtInizio = recCent.dtEvento; + recCent = currFlux.Skip(i / (maxItem + 1)).FirstOrDefault(); + listPeriodi.Add(new Periodo(dtInizio, recCent.dtEvento)); + } + } + // aggiungo ultimo... listPeriodi.Add(new Periodo(recCent.dtEvento.AddSeconds(1), dtCursEnd)); break; default: @@ -656,21 +667,24 @@ namespace MP.Data.Controllers } // fermo cronometro e salvo su DB... sw.Stop(); - LogFLDedupModel currStat = new LogFLDedupModel() + DTO.StatDedupDTO currStat = new DTO.StatDedupDTO() { IdxMacchina = idxMaccSel, CodFlux = item, - DtRif = DateTime.Now, + Interval = intReq, + Num4Int = maxItem, NumRec = numRecProc, ProcTime = sw.Elapsed.TotalSeconds }; procStats.Add(currStat); } +#if false // salvo le statistiche di processing... - fatto = LogFLDedupInsert(procStats); + fatto = LogFLDedupInsert(procStats); +#endif Log.Info($"FINE FluxLogDataRedux | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio} --> {currPeriodo.Fine}"); - return fatto; + return procStats; } /// diff --git a/MP.Data/DTO/StatDedupDTO.cs b/MP.Data/DTO/StatDedupDTO.cs new file mode 100644 index 00000000..076aca72 --- /dev/null +++ b/MP.Data/DTO/StatDedupDTO.cs @@ -0,0 +1,56 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; +using System.ComponentModel.DataAnnotations; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +// +// This is here so CodeMaid doesn't reorganize this document +// +namespace MP.Data.DTO +{ + public class StatDedupDTO + { + /// + /// Macchina + /// + public string IdxMacchina { get; set; } = ""; + + /// + /// Cod Flusso interessato + /// + public string CodFlux { get; set; } = ""; + + /// + /// Tipo di intervallo richiesto + /// + public Enum.DataInterval Interval { get; set; } = Enum.DataInterval.hour; + + /// + /// num max di item per intervallo + /// + public int Num4Int { get; set; } = 1; + + /// + /// Num record processati (iniziali) + /// + public int NumRec { get; set; } = 1; + + /// + /// Tempo processing (secondi) + /// + public double ProcTime { get; set; } = 1; + + /// + /// Tempo processing atteso in ms per record + /// + [NotMapped] + public double ProcTimeMs + { + get => (ProcTime * 1000) / (NumRec > 1 ? NumRec : 1); + } + } +} diff --git a/MP.Data/Utils.cs b/MP.Data/Utils.cs index 4a4efbaf..5b89a344 100644 --- a/MP.Data/Utils.cs +++ b/MP.Data/Utils.cs @@ -232,6 +232,7 @@ namespace MP.Data public const string redisConfKey = redisBaseAddr + "Cache:Config"; public const string redisAKVKey = redisBaseAddr + "Cache:AKV"; public const string redisParetoFLKey = redisBaseAddr + "Cache:ParetoFL"; + public const string redisStatsProcFL = redisBaseAddr + "Stats:ProcessFL"; public const string redisDossByMac = redisBaseAddr + "Cache:DossByMac"; public const string redisFluxByMac = redisBaseAddr + "Cache:FluxByMac"; public const string redisFluxLogFilt = redisBaseAddr + "Cache:FluxLogFilt"; diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index 90cf6134..a087def9 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -1785,10 +1785,72 @@ namespace MP.SPEC.Data /// public async Task FluxLogDataRedux(string idxMaccSel, List fluxList, DtUtils.Periodo currPeriodo, ValSelection valMode, DataInterval intReq, int maxItem) { - await dbController.FluxLogDataRedux(idxMaccSel, fluxList, currPeriodo, valMode, intReq, maxItem); + List procStats = await dbController.FluxLogDataRedux(idxMaccSel, fluxList, currPeriodo, valMode, intReq, maxItem); + // effettuo merge statistiche... + ProcStatMerge(procStats); await FlushCacheFluxLog(); } + /// + /// Restituisce le statistiche di processo correnti x depluplica FluxLog + /// + /// + public List ProcFLStats() + { + List actStats = new List(); + string currKey = $"{Utils.redisStatsProcFL}"; + // recupero i record statistiche correnti + RedisValue rawData = redisDb.StringGet(currKey); + if (rawData.HasValue) + { + var rawStats = JsonConvert.DeserializeObject>($"{rawData}"); + if (rawStats != null) + { + actStats = rawStats; + } + } + return actStats; + } + + protected bool ProcStatMerge(List procStats) + { + bool answ = false; + List actStats = ProcFLStats(); + // se fosse vuoto --> add diretto + if (actStats.Count == 0) + { + actStats.AddRange(procStats); + } + else + { + // aggiorno su redis i record statistiche 1:1... + foreach (var recStat in procStats) + { + // cerco se ci fosse x aggiornare + var currRec = actStats.Where(x => x.IdxMacchina == recStat.IdxMacchina + && x.CodFlux == recStat.CodFlux + && x.Interval == recStat.Interval + && x.Num4Int == recStat.Num4Int).FirstOrDefault(); + // se trovato aggiorno + if (currRec != null) + { + currRec.ProcTime += recStat.ProcTime; + currRec.NumRec += recStat.NumRec; + } + // altrimenti aggiungo + else + { + actStats.Add(recStat); + } + } + } + // salvo record statistiche + var rawData = JsonConvert.SerializeObject(actStats); + string currKey = $"{Utils.redisStatsProcFL}"; + redisDb.StringSet(currKey, rawData); + return answ; + } + /// /// Stored manutenzione del DB /// diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index 0e53782a..0180a490 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 6.16.2310.2312 + 6.16.2310.2318 diff --git a/MP.SPEC/Pages/FluxLogStatus.razor.cs b/MP.SPEC/Pages/FluxLogStatus.razor.cs index 6bb67276..7de016a4 100644 --- a/MP.SPEC/Pages/FluxLogStatus.razor.cs +++ b/MP.SPEC/Pages/FluxLogStatus.razor.cs @@ -91,9 +91,17 @@ namespace MP.SPEC.Pages protected override async Task OnInitializedAsync() { + ReloadStats(); await ReloadData(); } + private void ReloadStats() + { + actStats = MDataServ.ProcFLStats(); + } + + protected List actStats { get; set; } = new List(); + protected async Task ReloadMacchine() { if (ListMacchineAll == null || ListMacchineAll.Count == 0) @@ -187,6 +195,8 @@ namespace MP.SPEC.Pages DateTime dtEnd = DateTime.Today.AddDays(1); DateTime dtStart = dtEnd.AddMonths(-1); CurrPeriodo = new Periodo(dtStart, dtEnd); + // calcolo tempo stimato e mostro... + } #endregion Private Methods diff --git a/MP.SPEC/Resources/ChangeLog.html b/MP.SPEC/Resources/ChangeLog.html index 09ad6fb2..c1566c2e 100644 --- a/MP.SPEC/Resources/ChangeLog.html +++ b/MP.SPEC/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo MAPOSPEC -

    Versione: 6.16.2310.2312

    +

    Versione: 6.16.2310.2318


    Note di rilascio:
    • diff --git a/MP.SPEC/Resources/VersNum.txt b/MP.SPEC/Resources/VersNum.txt index d90133b4..3c671d09 100644 --- a/MP.SPEC/Resources/VersNum.txt +++ b/MP.SPEC/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2310.2312 +6.16.2310.2318 diff --git a/MP.SPEC/Resources/manifest.xml b/MP.SPEC/Resources/manifest.xml index b4c63949..72a5afcd 100644 --- a/MP.SPEC/Resources/manifest.xml +++ b/MP.SPEC/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2310.2312 + 6.16.2310.2318 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 From a25635485eb8e065b7050244552a6e89c2dd65d2 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 23 Oct 2023 19:57:39 +0200 Subject: [PATCH 4/7] Correzioni stima tempo calcolo redux Fluxlog --- MP.Data/Controllers/MpSpecController.cs | 14 +- MP.SPEC/Components/FLStatusList.razor.cs | 16 ++ MP.SPEC/Data/MpDataService.cs | 189 +++++++++++------------ MP.SPEC/MP.SPEC.csproj | 2 +- MP.SPEC/Pages/FluxLogStatus.razor | 9 +- MP.SPEC/Pages/FluxLogStatus.razor.cs | 54 ++++++- MP.SPEC/Resources/ChangeLog.html | 2 +- MP.SPEC/Resources/VersNum.txt | 2 +- MP.SPEC/Resources/manifest.xml | 2 +- 9 files changed, 177 insertions(+), 113 deletions(-) diff --git a/MP.Data/Controllers/MpSpecController.cs b/MP.Data/Controllers/MpSpecController.cs index e3cbc159..0d23400f 100644 --- a/MP.Data/Controllers/MpSpecController.cs +++ b/MP.Data/Controllers/MpSpecController.cs @@ -552,9 +552,9 @@ namespace MP.Data.Controllers /// /// /// Restitusice list dei record statistiche raccolti (da integrare a quelli rpesenti in Redis...) - public async Task> FluxLogDataRedux(string idxMaccSel, List fluxList, Periodo currPeriodo, Enum.ValSelection valMode, Enum.DataInterval intReq, int maxItem) + public async Task> FluxLogDataRedux(string idxMaccSel, List fluxList, Periodo currPeriodo, Enum.ValSelection valMode, Enum.DataInterval intReq, int maxItem) { - List procStats = new List(); + List procStats = new List(); Log.Info($"Inizio FluxLogDataRedux | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio} --> {currPeriodo.Fine}"); TimeSpan step = TimeSpan.FromHours(1); switch (intReq) @@ -667,7 +667,7 @@ namespace MP.Data.Controllers } // fermo cronometro e salvo su DB... sw.Stop(); - DTO.StatDedupDTO currStat = new DTO.StatDedupDTO() + StatDedupDTO currStat = new StatDedupDTO() { IdxMacchina = idxMaccSel, CodFlux = item, @@ -678,11 +678,6 @@ namespace MP.Data.Controllers }; procStats.Add(currStat); } - -#if false - // salvo le statistiche di processing... - fatto = LogFLDedupInsert(procStats); -#endif Log.Info($"FINE FluxLogDataRedux | idxMaccSel: {idxMaccSel} | periodo: {currPeriodo.Inizio} --> {currPeriodo.Fine}"); return procStats; } @@ -712,7 +707,8 @@ namespace MP.Data.Controllers var dbResult = dbCtx .Database - .ExecuteSqlRaw("EXEC man.stp_Utility_Maintanance @FlgExec, @FlgUpdStat, @FlgSave, @min_page_count, @min_avg_fragmentation_in_percent, @max_avg_fragmentation_per_rebuild", pFlgExec, pFlgUpdStat, pFlgSave, pMinPgCnt, pMinAvgFrag, pMaxAvgFrag); + .ExecuteSqlRaw("EXEC man.stp_Utility_Maintanance"); + //.ExecuteSqlRaw("EXEC man.stp_Utility_Maintanance @FlgExec, @FlgUpdStat, @FlgSave, @min_page_count, @min_avg_fragmentation_in_percent, @max_avg_fragmentation_per_rebuild", pFlgExec, pFlgUpdStat, pFlgSave, pMinPgCnt, pMinAvgFrag, pMaxAvgFrag); fatto = true; } Log.Info($"FINE ForceDbMaint"); diff --git a/MP.SPEC/Components/FLStatusList.razor.cs b/MP.SPEC/Components/FLStatusList.razor.cs index cf06f3a1..f25e8b8c 100644 --- a/MP.SPEC/Components/FLStatusList.razor.cs +++ b/MP.SPEC/Components/FLStatusList.razor.cs @@ -18,6 +18,8 @@ namespace MP.SPEC.Components [Parameter] public EventCallback E_TotalCount { get; set; } + [Parameter] + public EventCallback E_TotalRec { get; set; } [Parameter] public string IdxMaccSel { get; set; } = ""; @@ -80,6 +82,18 @@ namespace MP.SPEC.Components } } } + protected int TotalRecords + { + get => totRecords; + set + { + if (totRecords != value) + { + totRecords = value; + E_TotalRec.InvokeAsync(value).ConfigureAwait(false); + } + } + } #endregion Protected Properties @@ -104,6 +118,7 @@ namespace MP.SPEC.Components lastPeriodo = CurrPeriodo; ListComplete = await MDataServ.ParetoFluxLog(IdxMaccSel, CurrPeriodo.Inizio, CurrPeriodo.Fine); TotalCount = ListComplete.Count; + TotalRecords = ListComplete.Sum(x => x.Qty); FluxList = ListComplete.Select(x => x.CodFlux).ToList(); } // esegue paginazione @@ -133,6 +148,7 @@ namespace MP.SPEC.Components private string idxMaccLast = ""; private bool isProcessing = false; private int totalCount = 0; + private int totRecords = 0; #endregion Private Fields diff --git a/MP.SPEC/Data/MpDataService.cs b/MP.SPEC/Data/MpDataService.cs index a087def9..591f287a 100644 --- a/MP.SPEC/Data/MpDataService.cs +++ b/MP.SPEC/Data/MpDataService.cs @@ -1,5 +1,4 @@ using EgwCoreLib.Utils; -using Microsoft.AspNetCore.Razor.TagHelpers; using MP.Data; using MP.Data.Conf; using MP.Data.DatabaseModels; @@ -692,6 +691,24 @@ namespace MP.SPEC.Data return answ; } + /// + /// Funzione di Data Reduction x FluxLog + /// + /// Macchina + /// Elenco FL da processare + /// Periodo + /// modalità sel valore + /// intervallo di analisi + /// max num per intervallo + /// + public async Task FluxLogDataRedux(string idxMaccSel, List fluxList, DtUtils.Periodo currPeriodo, ValSelection valMode, DataInterval intReq, int maxItem) + { + List procStats = await dbController.FluxLogDataRedux(idxMaccSel, fluxList, currPeriodo, valMode, intReq, maxItem); + // effettuo merge statistiche... + ProcStatMerge(procStats); + await FlushCacheFluxLog(); + } + public List FluxLogDtoGetByFlux(string Valore) { List answ = new List(); @@ -761,6 +778,22 @@ namespace MP.SPEC.Data return result; } + /// + /// Stored manutenzione del DB + /// + /// Esegue realmente il task + /// Aggiornamento statistiche + /// Salvataggio + /// def: 1000 + /// def: 10 + /// def: 50 + /// + public async Task ForceDbMaint(bool doExec = true, bool doUpdStat = true, bool doSave = true, int minPgCnt = 1000, int minAvgFrag = 10, int maxAvgFragReb = 50) + { + dbController.ForceDbMaint(doExec, doUpdStat, doSave, minPgCnt, minAvgFrag, maxAvgFragReb); + await FlushCacheFluxLog(); + } + /// /// Init ricetta /// @@ -1417,6 +1450,27 @@ namespace MP.SPEC.Data return dbResult; } + /// + /// Restituisce le statistiche di processo correnti x depluplica FluxLog + /// + /// + public List ProcFLStats() + { + List actStats = new List(); + string currKey = $"{Utils.redisStatsProcFL}"; + // recupero i record statistiche correnti + RedisValue rawData = redisDb.StringGet(currKey); + if (rawData.HasValue) + { + var rawStats = JsonConvert.DeserializeObject>($"{rawData}"); + if (rawStats != null) + { + actStats = rawStats; + } + } + return actStats; + } + /// /// Ricerca ricetta su MongoDB dato PODL /// @@ -1712,6 +1766,45 @@ namespace MP.SPEC.Data return TimeSpan.FromMinutes(rndValue); } + protected bool ProcStatMerge(List procStats) + { + bool answ = false; + List actStats = ProcFLStats(); + // se fosse vuoto --> add diretto + if (actStats.Count == 0) + { + actStats.AddRange(procStats); + } + else + { + // aggiorno su redis i record statistiche 1:1... + foreach (var recStat in procStats) + { + // cerco se ci fosse x aggiornare + var currRec = actStats.Where(x => x.IdxMacchina == recStat.IdxMacchina + && x.CodFlux == recStat.CodFlux + && x.Interval == recStat.Interval + && x.Num4Int == recStat.Num4Int).FirstOrDefault(); + // se trovato aggiorno + if (currRec != null) + { + currRec.ProcTime += recStat.ProcTime; + currRec.NumRec += recStat.NumRec; + } + // altrimenti aggiungo + else + { + actStats.Add(recStat); + } + } + } + // salvo record statistiche + var rawData = JsonConvert.SerializeObject(actStats); + string currKey = $"{Utils.redisStatsProcFL}"; + redisDb.StringSet(currKey, rawData); + return answ; + } + #endregion Protected Methods #region Private Fields @@ -1773,100 +1866,6 @@ namespace MP.SPEC.Data await RedisFlushPatternAsync(pattern); } - /// - /// Funzione di Data Reduction x FluxLog - /// - /// Macchina - /// Elenco FL da processare - /// Periodo - /// modalità sel valore - /// intervallo di analisi - /// max num per intervallo - /// - public async Task FluxLogDataRedux(string idxMaccSel, List fluxList, DtUtils.Periodo currPeriodo, ValSelection valMode, DataInterval intReq, int maxItem) - { - List procStats = await dbController.FluxLogDataRedux(idxMaccSel, fluxList, currPeriodo, valMode, intReq, maxItem); - // effettuo merge statistiche... - ProcStatMerge(procStats); - await FlushCacheFluxLog(); - } - - /// - /// Restituisce le statistiche di processo correnti x depluplica FluxLog - /// - /// - public List ProcFLStats() - { - List actStats = new List(); - string currKey = $"{Utils.redisStatsProcFL}"; - // recupero i record statistiche correnti - RedisValue rawData = redisDb.StringGet(currKey); - if (rawData.HasValue) - { - var rawStats = JsonConvert.DeserializeObject>($"{rawData}"); - if (rawStats != null) - { - actStats = rawStats; - } - } - return actStats; - } - - protected bool ProcStatMerge(List procStats) - { - bool answ = false; - List actStats = ProcFLStats(); - // se fosse vuoto --> add diretto - if (actStats.Count == 0) - { - actStats.AddRange(procStats); - } - else - { - // aggiorno su redis i record statistiche 1:1... - foreach (var recStat in procStats) - { - // cerco se ci fosse x aggiornare - var currRec = actStats.Where(x => x.IdxMacchina == recStat.IdxMacchina - && x.CodFlux == recStat.CodFlux - && x.Interval == recStat.Interval - && x.Num4Int == recStat.Num4Int).FirstOrDefault(); - // se trovato aggiorno - if (currRec != null) - { - currRec.ProcTime += recStat.ProcTime; - currRec.NumRec += recStat.NumRec; - } - // altrimenti aggiungo - else - { - actStats.Add(recStat); - } - } - } - // salvo record statistiche - var rawData = JsonConvert.SerializeObject(actStats); - string currKey = $"{Utils.redisStatsProcFL}"; - redisDb.StringSet(currKey, rawData); - return answ; - } - - /// - /// Stored manutenzione del DB - /// - /// Esegue realmente il task - /// Aggiornamento statistiche - /// Salvataggio - /// def: 1000 - /// def: 10 - /// def: 50 - /// - public async Task ForceDbMaint(bool doExec = true, bool doUpdStat = true, bool doSave = true, int minPgCnt = 1000, int minAvgFrag = 10, int maxAvgFragReb = 50) - { - dbController.ForceDbMaint(doExec, doUpdStat, doSave, minPgCnt, minAvgFrag, maxAvgFragReb); - await FlushCacheFluxLog(); - } - #endregion Private Methods } } \ No newline at end of file diff --git a/MP.SPEC/MP.SPEC.csproj b/MP.SPEC/MP.SPEC.csproj index 0180a490..3c287af7 100644 --- a/MP.SPEC/MP.SPEC.csproj +++ b/MP.SPEC/MP.SPEC.csproj @@ -5,7 +5,7 @@ enable enable MP.SPEC - 6.16.2310.2318 + 6.16.2310.2319 diff --git a/MP.SPEC/Pages/FluxLogStatus.razor b/MP.SPEC/Pages/FluxLogStatus.razor index 2984c76b..bb940f4e 100644 --- a/MP.SPEC/Pages/FluxLogStatus.razor +++ b/MP.SPEC/Pages/FluxLogStatus.razor @@ -33,19 +33,22 @@
      @if (isProcessing) { - + } else { - + }