diff --git a/MP.Data/Controllers/MpStatsController.cs b/MP.Data/Controllers/MpStatsController.cs index a3460f58..36f947c9 100644 --- a/MP.Data/Controllers/MpStatsController.cs +++ b/MP.Data/Controllers/MpStatsController.cs @@ -277,6 +277,28 @@ namespace MP.Data.Controllers return dbResult; } + + /// + /// Restituisce dataset FluxLog filtrato + /// + /// Macchina singola, se "" = tutte + /// Data inizio selezione odl (inizio/fine) + /// Data fine selezione odl (inizio/fine) + /// + public List FluxLogRawData(string IdxMacchina, DateTime DtStart, DateTime DtEnd) + { + List dbResult = new List(); + using (var dbCtx = new MoonPro_STATSContext(_configuration)) + { + + dbResult = dbCtx + .DbSetFL + .Where(x => (IdxMacchina=="*" || x.IdxMacchina == IdxMacchina) && (x.dtEvento >= DtStart && x.dtEvento <= DtEnd)) + .ToList(); + } + return dbResult; + } + /// /// Elenco tabella ODL da filtro /// diff --git a/MP.Data/DbModels/FLModel.cs b/MP.Data/DbModels/FLModel.cs new file mode 100644 index 00000000..2a13bfea --- /dev/null +++ b/MP.Data/DbModels/FLModel.cs @@ -0,0 +1,30 @@ +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.DbModels +{ + [Table("FL")] + public partial class FLModel + { + #region Public Properties + + [MaxLength(50)] + public string IdxMacchina { get; set; } + + public DateTime dtEvento { get; set; } + + [MaxLength(50)] + public string CodFlux { get; set; } + + [MaxLength(250)] + public string Valore { get; set; } + + #endregion Public Properties + } +} \ No newline at end of file diff --git a/MP.Data/MoonPro_STATSContext.cs b/MP.Data/MoonPro_STATSContext.cs index e15406a3..fad0fc99 100644 --- a/MP.Data/MoonPro_STATSContext.cs +++ b/MP.Data/MoonPro_STATSContext.cs @@ -42,6 +42,7 @@ namespace MP.Data public virtual DbSet DbSetConfig { get; set; } public virtual DbSet DbSetControlli { get; set; } public virtual DbSet DbSetDdbTurni { get; set; } + public virtual DbSet DbSetFL { get; set; } public virtual DbSet DbSetMacchine { get; set; } public virtual DbSet DbSetODL { get; set; } public virtual DbSet DbSetOdlEnergy { get; set; } @@ -94,6 +95,12 @@ namespace MP.Data .HasComment("Valore di default/riferimento per la variabile"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.IdxMacchina, e.dtEvento, e.CodFlux }); + + }); + modelBuilder.Entity(entity => { entity.HasKey(e => new { e.Lingua, e.Lemma }); diff --git a/MP.Stats/Components/ChartEnergy.razor.cs b/MP.Stats/Components/ChartEnergy.razor.cs index 4225d72f..e2ae0f65 100644 --- a/MP.Stats/Components/ChartEnergy.razor.cs +++ b/MP.Stats/Components/ChartEnergy.razor.cs @@ -33,14 +33,6 @@ namespace MP.Stats.Components #endregion Public Properties - #region Protected Fields - - protected const string EsitoKO = "Esito: Non Passato"; - - protected const string EsitoOK = "Esito: OK"; - - #endregion Protected Fields - #region Protected Properties protected SelectData _currFilter { get; set; } = new SelectData(); @@ -87,8 +79,6 @@ namespace MP.Stats.Components #region Protected Methods - - /// /// Genera colori sfondo 33% rosso / arancione / giallo /// @@ -129,6 +119,7 @@ namespace MP.Stats.Components #region Private Fields private List lineTitles = new List() { "Consumo/UM" }; + private List listMachine = new List(); private string pieTitle = "Macchina"; #endregion Private Fields @@ -164,8 +155,6 @@ namespace MP.Stats.Components private List TSData { get; set; } = new List(); private List> TSDataMulti { get; set; } = new List>(); - private List listMachine = new List(); - #endregion Private Properties #region Private Methods @@ -178,7 +167,7 @@ namespace MP.Stats.Components if (DynMode) { ParetoData = RawData - .GroupBy(p => new { p.IdxMacchina}) + .GroupBy(p => new { p.IdxMacchina }) //.GroupBy(p => new { p.IdxMacchina, p.CodArticolo }) .Select(y => new ChartKV() { label = y.First().IdxMacchina, value = y.Count() }) //.Select(y => new ChartKV() { label = $"{y.First().IdxMacchina} {y.First().CodArticolo}", value = y.Count() }) @@ -209,7 +198,6 @@ namespace MP.Stats.Components .ToList(); TSDataMulti.Add(TSDataCurr); } - } else { @@ -218,7 +206,7 @@ namespace MP.Stats.Components .GroupBy(p => new { p.IdxMacchina }) //.GroupBy(p => new { p.IdxMacchina, p.CodArticolo }) .Select(y => new ChartKV() { label = y.First().IdxMacchina, value = y.Count() }) - //.Select(y => new ChartKV() { label = $"{y.First().IdxMacchina} {y.First().CodArticolo}", value = y.Count() }) + //.Select(y => new ChartKV() { label = $"{y.First().IdxMacchina} {y.First().CodArticolo}", value = y.Count() }) .OrderByDescending(x => x.value) .ToList(); diff --git a/MP.Stats/Components/ChartTrends.razor b/MP.Stats/Components/ChartTrends.razor index f389aa5b..55d92f68 100644 --- a/MP.Stats/Components/ChartTrends.razor +++ b/MP.Stats/Components/ChartTrends.razor @@ -11,7 +11,7 @@ {
- Selezione tipo (day/week/month/year) + selezione ITEM da mostrare + Selezione tipo (day/week/month/year) + selezione ITEM da mostrare, tra quelli POSSIBILI dato periodo...
    @foreach (var item in @ParetoData) { @@ -29,14 +29,14 @@
- @if (DynMode) - { - - } - else - { - - } + Day + + Week + + Month + + @* Year + *@
diff --git a/MP.Stats/Components/ChartTrends.razor.cs b/MP.Stats/Components/ChartTrends.razor.cs index a135df6b..c0a6fc2d 100644 --- a/MP.Stats/Components/ChartTrends.razor.cs +++ b/MP.Stats/Components/ChartTrends.razor.cs @@ -1,7 +1,9 @@ using Microsoft.AspNetCore.Components; using MP.Data; +using MP.Data.DbModels; using MP.Data.Services; using MP.Stats.Data; +using System; using System.Collections.Generic; using System.Linq; @@ -12,10 +14,7 @@ namespace MP.Stats.Components #region Public Properties [Parameter] - public bool DynMode { get; set; } = false; - - [Parameter] - public List RawData + public List RawData { get => _rawData; set @@ -34,17 +33,11 @@ namespace MP.Stats.Components #region Protected Fields - protected const string EsitoKO = "Esito: Non Passato"; - - protected const string EsitoOK = "Esito: OK"; - #endregion Protected Fields #region Protected Properties - protected SelectData _currFilter { get; set; } = new SelectData(); - - protected List _rawData { get; set; } = new List(); + protected List _rawData { get; set; } = new List(); /// /// Genera colori sfondo 33% rosso / arancione / giallo @@ -74,7 +67,7 @@ namespace MP.Stats.Components } [Inject] - protected Data.MessageService MessageService { get; set; } + protected Data.MessageService MService { get; set; } [Inject] protected MpStatsService StatService { get; set; } @@ -174,6 +167,42 @@ namespace MP.Stats.Components if (RawData != null) { lineTitles = new List(); + + + ParetoData = RawData + //.GroupBy(p => new { p.IdxMacchina }) + .GroupBy(p => new { p.IdxMacchina, p.CodFlux }) + //.Select(y => new ChartKV() { label = y.First().IdxMacchina, value = y.Count() }) + .Select(y => new ChartKV() { label = $"{y.First().IdxMacchina} {y.First().CodFlux}", value = y.Count() }) + .OrderByDescending(x => x.value) + .ToList(); + + TSData = RawData + .Select(r => new chartJsData.chartJsTSerie() { x = r.dtEvento, y = cDouble(r.Valore) }) + .OrderBy(o => o.x) + .ToList(); + + // reset lista + TSDataMulti = new List>(); + // ciclo x ogni macchina + listMachine = RawData + .GroupBy(x => x.IdxMacchina) + .Select(y => y.First().IdxMacchina) + .ToList(); + + foreach (var idxMacc in listMachine) + { + lineTitles.Add($"{idxMacc} | {TradService.Traduci("MP-STATS_TotEn01")} / {StatService.FluxGetUM("TotCount01")}"); + + var TSDataCurr = RawData + .Where(x => x.IdxMacchina == idxMacc) + .Select(r => new chartJsData.chartJsTSerie() { x = r.dtEvento, y = cDouble(r.Valore) }) + .OrderBy(o => o.x) + .ToList(); + TSDataMulti.Add(TSDataCurr); + } + +#if false if (DynMode) { ParetoData = RawData @@ -226,10 +255,16 @@ namespace MP.Stats.Components .Select(r => new chartJsData.chartJsTSerie() { x = r.First().DataInizio.Date, y = r.Average(l => (double)l.AvgWatt) }) .OrderBy(o => o.x) .ToList(); - } + } +#endif } } + private double cDouble(string origValue) + { + return double.Parse(origValue); + } + #endregion Private Methods } } \ No newline at end of file diff --git a/MP.Stats/Data/MpStatsService.cs b/MP.Stats/Data/MpStatsService.cs index 3048ebfe..8133f8ea 100644 --- a/MP.Stats/Data/MpStatsService.cs +++ b/MP.Stats/Data/MpStatsService.cs @@ -440,6 +440,45 @@ namespace MP.Stats.Data return numRec; } + + /// + /// Recupero dati FluxLog secondo filtro + richiesta raggruppamento + /// + /// + /// + /// + public async Task> FluxLogRawData(SelectData CurrFilter, string searchVal = "") + { + // setup parametri costanti + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List result = new List(); + // cerco in redis... + DateTime adesso = DateTime.Now; + string currKey = getCacheKey($"{redisBaseKey}:FL_DATA", CurrFilter); + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.FluxLogRawData(CurrFilter.IdxMacchina, CurrFilter.DateStart, CurrFilter.DateEnd); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, FastCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"FluxLogRawData | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + /// /// Statistiche ODL /// diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index 1e05c064..4a9537d3 100644 --- a/MP.Stats/MP.Stats.csproj +++ b/MP.Stats/MP.Stats.csproj @@ -4,8 +4,8 @@ net6.0 MP.Stats 826e877c-ba70-4253-84cb-d0b1cafd4440 - 6.16.2503.1012 - 6.16.2503.1012 + 6.16.2503.1016 + 6.16.2503.1016 true $(NoWarn);1591 en diff --git a/MP.Stats/Pages/Energy.razor.cs b/MP.Stats/Pages/Energy.razor.cs index 400a8997..32e8afa0 100644 --- a/MP.Stats/Pages/Energy.razor.cs +++ b/MP.Stats/Pages/Energy.razor.cs @@ -15,34 +15,9 @@ namespace MP.Stats.Pages { #region Public Methods - public string checkSelect(int IdxODL) - { - string answ = ""; - if (currRecord != null) - { - try - { - answ = (currRecord.IdxOdl == IdxODL) ? "table-info" : ""; - } - catch - { } - } - return answ; - } - public void Dispose() { - MessageService.EA_SearchUpdated -= OnSeachUpdated; - } - - /// - /// recupero UM del flusso indicato - /// - /// - /// - public string GetUM(string CodFlux) - { - return StatService.FluxGetUM(CodFlux); + MServ.EA_SearchUpdated -= OnSeachUpdated; } public async void OnSeachUpdated() @@ -54,16 +29,6 @@ namespace MP.Stats.Pages }); } - /// - /// Traduzione lemma richeisto (lingua default="IT") - /// - /// - /// - public string Traduci(string Lemma) - { - return TradService.Traduci(Lemma); - } - #endregion Public Methods #region Protected Fields @@ -78,7 +43,7 @@ namespace MP.Stats.Pages protected IJSRuntime JSRuntime { get; set; } [Inject] - protected Data.MessageService MessageService { get; set; } + protected Data.MessageService MServ { get; set; } [Inject] protected NavigationManager NavManager { get; set; } @@ -106,6 +71,21 @@ namespace MP.Stats.Pages #region Protected Methods + protected string checkSelect(int IdxODL) + { + string answ = ""; + if (currRecord != null) + { + try + { + answ = (currRecord.IdxOdl == IdxODL) ? "table-info" : ""; + } + catch + { } + } + return answ; + } + protected async Task DoFilter(SelectData newFilter) { clearFile(); @@ -115,14 +95,24 @@ namespace MP.Stats.Pages await ReloadData(); } + /// + /// recupero UM del flusso indicato + /// + /// + /// + protected string GetUM(string CodFlux) + { + return StatService.FluxGetUM(CodFlux); + } + protected override async Task OnInitializedAsync() { clearFile(); numRecord = 10; - MessageService.ShowSearch = false; - MessageService.PageName = "ENERGY"; - MessageService.PageIcon = "oi oi-bar-chart"; - MessageService.EA_SearchUpdated += OnSeachUpdated; + MServ.ShowSearch = false; + MServ.PageName = "ENERGY"; + MServ.PageIcon = "oi oi-bar-chart"; + MServ.EA_SearchUpdated += OnSeachUpdated; await LoadConfData(); await ReloadData(); } @@ -175,6 +165,16 @@ namespace MP.Stats.Pages } } + /// + /// Traduzione lemma richeisto (lingua default="IT") + /// + /// + /// + protected string Traduci(string Lemma) + { + return TradService.Traduci(Lemma); + } + protected async Task UpdateData() { currRecord = null; @@ -202,11 +202,11 @@ namespace MP.Stats.Pages { get { - return MessageService.ODL_Filter; + return MServ.ODL_Filter; } set { - MessageService.ODL_Filter = value; + MServ.ODL_Filter = value; } } @@ -271,7 +271,7 @@ namespace MP.Stats.Pages private async Task ReloadData() { - SearchRecords = await StatService.StatOdlEnergyGetAll(currFilter, MessageService.SearchVal); + SearchRecords = await StatService.StatOdlEnergyGetAll(currFilter, MServ.SearchVal); DisplayData(); } diff --git a/MP.Stats/Pages/TrendAnalisys.razor b/MP.Stats/Pages/TrendAnalisys.razor deleted file mode 100644 index a0c0c823..00000000 --- a/MP.Stats/Pages/TrendAnalisys.razor +++ /dev/null @@ -1,17 +0,0 @@ -@page "/TrendAnalisys" -@page "/trend-analisys" - -@using MP.Stats.Components - -
-
- @* *@ -

Titolo + filtro (TBD)

- filtro periodo e macchine -
-
- -
-
- - diff --git a/MP.Stats/Pages/TrendAnalisys.razor.cs b/MP.Stats/Pages/TrendAnalisys.razor.cs deleted file mode 100644 index 62ce0530..00000000 --- a/MP.Stats/Pages/TrendAnalisys.razor.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace MP.Stats.Pages -{ - public partial class TrendAnalisys - { - - } -} \ No newline at end of file diff --git a/MP.Stats/Pages/TrendAnalysis.razor b/MP.Stats/Pages/TrendAnalysis.razor new file mode 100644 index 00000000..b838a479 --- /dev/null +++ b/MP.Stats/Pages/TrendAnalysis.razor @@ -0,0 +1,18 @@ +@page "/TrendAnalysis" +@page "/trend-analysis" + +@using MP.Stats.Components + +
+
+ +
+
+ +
+ +
+ + diff --git a/MP.Stats/Pages/TrendAnalysis.razor.cs b/MP.Stats/Pages/TrendAnalysis.razor.cs new file mode 100644 index 00000000..8d51b2f3 --- /dev/null +++ b/MP.Stats/Pages/TrendAnalysis.razor.cs @@ -0,0 +1,167 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.JSInterop; +using MP.Data.DbModels; +using MP.Data.Services; +using MP.Stats.Data; +using System; +using System.Collections.Generic; +using System.IO; +using System.Linq; +using System.Threading.Tasks; + +namespace MP.Stats.Pages +{ + public partial class TrendAnalysis + { + #region Public Methods + + public void Dispose() + { + MServ.EA_SearchUpdated -= OnSeachUpdated; + } + + public async void OnSeachUpdated() + { + await InvokeAsync(() => + { + Task task = UpdateData(); + StateHasChanged(); + }); + } + + #endregion Public Methods + + #region Protected Fields + + protected string fileName = "TrendAnalysis.csv"; + + #endregion Protected Fields + + #region Protected Properties + + [Inject] + protected IJSRuntime JSRuntime { get; set; } + + [Inject] + protected Data.MessageService MServ { get; set; } + + [Inject] + protected NavigationManager NavManager { get; set; } + + [Inject] + protected MpStatsService StatService { get; set; } + + protected int totalCount + { + get + { + int answ = 0; + if (SearchRecords != null) + { + answ = SearchRecords.Count; + } + return answ; + } + } + + [Inject] + protected TranslateSrv TradService { get; set; } + + #endregion Protected Properties + + #region Protected Methods + + protected async Task DoFilter(SelectData newFilter) + { + SearchRecords = null; + currFilter = newFilter; + await ReloadData(); + } + + protected override async Task OnInitializedAsync() + { + MServ.ShowSearch = false; + MServ.PageName = "Trend Analisys"; + MServ.PageIcon = "fa-solid fa-arrow-trend-up"; + CalcFilt(); + MServ.EA_SearchUpdated += OnSeachUpdated; + await LoadConfData(); + await ReloadData(); + } + + protected async Task ResetFilter(SelectData newFilter) + { + SearchRecords = null; + CalcFilt(); + await ReloadData(); + } + + /// + /// Traduzione lemma richeisto (lingua default="IT") + /// + /// + /// + protected string Traduci(string Lemma) + { + return TradService.Traduci(Lemma); + } + + protected async Task UpdateData() + { + await ReloadData(); + } + + #endregion Protected Methods + + #region Private Fields + + private List ConfigList; + + private List SearchRecords; + + #endregion Private Fields + + #region Private Properties + + private SelectData currFilter + { + get + { + return MServ.ODL_Filter; + } + set + { + MServ.ODL_Filter = value; + } + } + + private bool isLoading { get; set; } = false; + + #endregion Private Properties + + #region Private Methods + + /// + /// Calcola il filtro alla data necessaria x arrivare al confronto x mese... + /// + private void CalcFilt() + { + DateTime oggi = DateTime.Now.Date; + DateTime inizio = new DateTime(oggi.Year, oggi.Month, 1).AddMonths(-1); + int numPrev = (int)oggi.Subtract(inizio).TotalDays; + currFilter = SelectData.Init(5, numPrev); + } + + private async Task LoadConfData() + { + ConfigList = await StatService.ConfigGetAll(); + } + + private async Task ReloadData() + { + SearchRecords = await StatService.FluxLogRawData(currFilter, MServ.SearchVal); + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/MP.Stats/Resources/ChangeLog.html b/MP.Stats/Resources/ChangeLog.html index f5e260a1..6b9265e5 100644 --- a/MP.Stats/Resources/ChangeLog.html +++ b/MP.Stats/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

Versione: 6.16.2503.1012

+

Versione: 6.16.2503.1016


Note di rilascio:
    diff --git a/MP.Stats/Resources/VersNum.txt b/MP.Stats/Resources/VersNum.txt index 667ee440..1f6d83aa 100644 --- a/MP.Stats/Resources/VersNum.txt +++ b/MP.Stats/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2503.1012 +6.16.2503.1016 diff --git a/MP.Stats/Resources/manifest.xml b/MP.Stats/Resources/manifest.xml index b7430525..fed16b82 100644 --- a/MP.Stats/Resources/manifest.xml +++ b/MP.Stats/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2503.1012 + 6.16.2503.1016 https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html false diff --git a/MP.Stats/Shared/NavMenu.razor b/MP.Stats/Shared/NavMenu.razor index 5ae726b9..99ede02a 100644 --- a/MP.Stats/Shared/NavMenu.razor +++ b/MP.Stats/Shared/NavMenu.razor @@ -42,7 +42,7 @@