From afd3ec34bb8e8e7f48ebf88067d52738cdb611ba Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 23 Oct 2023 12:07:57 +0200 Subject: [PATCH] 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