diff --git a/MP.Data/Repository/Utils/IStatsDetailRepository.cs b/MP.Data/Repository/Utils/IStatsDetailRepository.cs index 77bd329a..0a760329 100644 --- a/MP.Data/Repository/Utils/IStatsDetailRepository.cs +++ b/MP.Data/Repository/Utils/IStatsDetailRepository.cs @@ -11,6 +11,8 @@ namespace MP.Data.Repository.Utils /// public interface IStatsDetailRepository { + #region Public Methods + /// /// Recupera l'elenco delle statistiche di dettaglio per un periodo specifico, con filtri opzionali. /// @@ -21,6 +23,17 @@ namespace MP.Data.Repository.Utils /// L'elenco delle statistiche di dettaglio ordinate cronologicamente. Task> GetFiltAsync(DateTime dtStart, DateTime dtEnd, string sEnvir = "", string sType = ""); + /// + /// Elenco record in modalità pareto + /// + /// + /// + /// + /// + /// + /// + Task> GetParetoAsync(DateTime dtStart, DateTime dtEnd, int maxRec, string sDest = "", string sType = ""); + /// /// Recupera l'intervallo temporale disponibile nel database per le statistiche di dettaglio. /// @@ -36,5 +49,7 @@ namespace MP.Data.Repository.Utils /// Se true, elimina preventivamente i record nel periodo richiesto. /// Il numero di record inseriti. Task UpsertManyAsync(List listRecords, bool removeOld); + + #endregion Public Methods } } \ No newline at end of file diff --git a/MP.Data/Repository/Utils/StatsDetailRepository.cs b/MP.Data/Repository/Utils/StatsDetailRepository.cs index ba67a55a..e8ab5301 100644 --- a/MP.Data/Repository/Utils/StatsDetailRepository.cs +++ b/MP.Data/Repository/Utils/StatsDetailRepository.cs @@ -47,6 +47,34 @@ namespace MP.Data.Repository.Utils return answ; } + /// + public async Task> GetParetoAsync(DateTime dtStart, DateTime dtEnd, int maxRec, string sDest = "", string sType = "") + { + await using var dbCtx = await CreateContextAsync(); + List answ = new List(); + + // recupero ed ordino per data-ora + var query = dbCtx.DbSetStatsDet + .Where(x => x.Hour >= dtStart && x.Hour <= dtEnd); + + if (!string.IsNullOrEmpty(sDest)) + query = query.Where(x => x.Destination == sDest); + + if (!string.IsNullOrEmpty(sType)) + query = query.Where(x => x.Type == sType); + + answ = await query + .AsNoTracking() + .OrderByDescending(x => x.RequestCount) + .ThenBy(x => x.Hour) + .ThenBy(x => x.Destination) + .ThenBy(x => x.Type) + .Take(maxRec) + .ToListAsync(); + + return answ; + } + /// public async Task GetRangeAsync(string sEnvir, string sType) { @@ -68,7 +96,6 @@ namespace MP.Data.Repository.Utils return answ; } - /// public async Task UpsertManyAsync(List listRecords, bool removeOld) { @@ -161,6 +188,8 @@ namespace MP.Data.Repository.Utils } } + #endregion Public Methods + #if false /// public async Task UpsertManyAsyncOrig(List listRecords, bool removeOld) @@ -181,7 +210,6 @@ namespace MP.Data.Repository.Utils DateTime startDate = firstRec.Hour; DateTime endDate = lastRec.Hour; - var items = await dbCtx.DbSetStatsDet .Where(x => x.Hour >= startDate && x.Hour <= endDate) .ToListAsync(); @@ -209,11 +237,9 @@ namespace MP.Data.Repository.Utils await tx.RollbackAsync(); throw; } - } + } #endif - #endregion Public Methods - #region Protected Fields protected static NLog.Logger Log = LogManager.GetCurrentClassLogger(); diff --git a/MP.Data/Services/Utils/IStatsDetailService.cs b/MP.Data/Services/Utils/IStatsDetailService.cs index 8b674e89..7dd7568f 100644 --- a/MP.Data/Services/Utils/IStatsDetailService.cs +++ b/MP.Data/Services/Utils/IStatsDetailService.cs @@ -16,9 +16,20 @@ namespace MP.Data.Services.Utils /// /// Data inizio periodo /// Data fine periodo - /// Filtro opzionale per ambiente (default: vuoto = tutti) + /// Filtro opzionale per destinazione (default: vuoto = tutti) /// Filtro opzionale per tipo (default: vuoto = tutti) - Task> GetFiltAsync(DateTime dtStart, DateTime dtEnd, string sEnvir = "", string sType = ""); + Task> GetFiltAsync(DateTime dtStart, DateTime dtEnd, string sDest = "", string sType = ""); + + /// + /// restituisce un Pareto degli eventi più frequenti dato periodo ed eventuale filtro Destinazione/Tipo + /// + /// Data inizio periodo + /// Data fine periodo + /// + /// Filtro opzionale per destinazione (default: vuoto = tutti) + /// Filtro opzionale per tipo (default: vuoto = tutti) + /// + Task> GetParetoAsync(DateTime dtStart, DateTime dtEnd, int maxRec, string sDest = "", string sType = ""); /// /// Recupera il range di periodi valido per le chiamate di dettaglio. diff --git a/MP.Data/Services/Utils/StatsDetailService.cs b/MP.Data/Services/Utils/StatsDetailService.cs index 30a19f8c..28e58660 100644 --- a/MP.Data/Services/Utils/StatsDetailService.cs +++ b/MP.Data/Services/Utils/StatsDetailService.cs @@ -26,17 +26,48 @@ namespace MP.Data.Services.Utils #region Public Methods /// - public async Task> GetFiltAsync(DateTime dtStart, DateTime dtEnd, string sEnvir = "", string sType = "") + public async Task> GetFiltAsync(DateTime dtStart, DateTime dtEnd, string sDest = "", string sType = "") { return await TraceAsync($"{_className}.GetFilt", async (activity) => { + string cacheKey = $"{_redisBaseKey}:{_className}:DT:{dtStart:yyyyMMdd}:{dtEnd:yyyyMMdd}"; + if (!string.IsNullOrEmpty(sDest)) + { + cacheKey += $":{sDest}"; + } + if (!string.IsNullOrEmpty(sType)) + { + cacheKey += $":{sType}"; + } return await GetOrSetCacheAsync( - $"{_redisBaseKey}:{_className}:DT:{dtStart:yyyyMMdd}:{dtEnd:yyyyMMdd}", + cacheKey, async () => await _repo.GetFiltAsync(dtStart, dtEnd), UltraLongCache ); }); } + /// + public async Task> GetParetoAsync(DateTime dtStart, DateTime dtEnd, int maxRec, string sDest = "", string sType = "") + { + return await TraceAsync($"{_className}.GetFilt", async (activity) => + { + string cacheKey = $"{_redisBaseKey}:{_className}:PARETO:{dtStart:yyyyMMdd}:{dtEnd:yyyyMMdd}"; + if (!string.IsNullOrEmpty(sDest)) + { + cacheKey += $":{sDest}"; + } + if (!string.IsNullOrEmpty(sType)) + { + cacheKey += $":{sType}"; + } + return await GetOrSetCacheAsync( + cacheKey, + async () => await _repo.GetParetoAsync(dtStart, dtEnd, maxRec, sDest, sType), + UltraLongCache + ); + }); + } + /// public async Task GetRangeAsync(string sEnvir, string sType) diff --git a/MP.IOC/Components/Layout/NavMenu.razor b/MP.IOC/Components/Layout/NavMenu.razor index 955270ba..2dc559fa 100644 --- a/MP.IOC/Components/Layout/NavMenu.razor +++ b/MP.IOC/Components/Layout/NavMenu.razor @@ -59,7 +59,7 @@ *@