Update gestione stats x macchine energy (filtro e display)

This commit is contained in:
Samuele Locatelli
2025-07-02 17:47:00 +02:00
parent 48e09805d9
commit 658aeaed52
12 changed files with 242 additions and 170 deletions
+61 -46
View File
@@ -6,6 +6,7 @@ using MP.Data.DbModels;
using NLog;
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing.Drawing2D;
using System.Linq;
using static MP.Core.Objects.Enums;
@@ -122,6 +123,66 @@ namespace MP.Data.Controllers
{
}
/// <summary>
/// Restituisce dataset FluxLog filtrato
/// </summary>
/// <param name="IdxMacchina">Macchina singola, se "" = tutte</param>
/// <param name="DtStart">Data inizio selezione odl (inizio/fine)</param>
/// <param name="DtEnd">Data fine selezione odl (inizio/fine)</param>
/// <param name="fluxType">Tipo Flusso, "" = tutti</param>
/// <returns></returns>
public List<FLModel> FluxLogRawData(string IdxMacchina, DateTime DtStart, DateTime DtEnd, string fluxType)
{
List<FLModel> dbResult = new List<FLModel>();
using (var dbCtx = new MoonPro_STATSContext(_configuration))
{
dbResult = dbCtx
.DbSetFL
.Where(x =>
(IdxMacchina == "*" || x.IdxMacchina == IdxMacchina)
&& (fluxType == "*" || x.FluxType == fluxType)
&& (x.dtEvento >= DtStart && x.dtEvento <= DtEnd))
.ToList();
}
return dbResult;
}
/// <summary>
/// Elenco di tipi flusso disponibili
/// </summary>
/// <returns></returns>
public List<string> FluxTypeList()
{
List<string> dbResult = new List<string>();
using (var dbCtx = new MoonPro_STATSContext(_configuration))
{
dbResult = dbCtx
.DbSetFL
.Select(x => x.FluxType)
.Distinct()
.OrderBy(x => x)
.ToList();
}
return dbResult;
}
/// <summary>
/// Elenco da tabella Macchine con dati Energy
/// </summary>
/// <returns></returns>
public List<MacchineModel> MacchineEnergy()
{
List<MacchineModel> dbResult = new List<MacchineModel>();
using (var dbCtx = new MoonPro_STATSContext(_configuration))
{
dbResult = dbCtx
.DbSetMacchine
.FromSqlRaw("EXEC stp_MaccEnergy")
.ToList();
}
return dbResult;
}
/// <summary>
/// Elenco da tabella Macchine
/// </summary>
@@ -277,52 +338,6 @@ namespace MP.Data.Controllers
return dbResult;
}
/// <summary>
/// Restituisce dataset FluxLog filtrato
/// </summary>
/// <param name="IdxMacchina">Macchina singola, se "" = tutte</param>
/// <param name="DtStart">Data inizio selezione odl (inizio/fine)</param>
/// <param name="DtEnd">Data fine selezione odl (inizio/fine)</param>
/// <param name="fluxType">Tipo Flusso, "" = tutti</param>
/// <returns></returns>
public List<FLModel> FluxLogRawData(string IdxMacchina, DateTime DtStart, DateTime DtEnd, string fluxType)
{
List<FLModel> dbResult = new List<FLModel>();
using (var dbCtx = new MoonPro_STATSContext(_configuration))
{
dbResult = dbCtx
.DbSetFL
.Where(x =>
(IdxMacchina == "*" || x.IdxMacchina == IdxMacchina)
&& (fluxType == "*" || x.FluxType == fluxType)
&& (x.dtEvento >= DtStart && x.dtEvento <= DtEnd))
.ToList();
}
return dbResult;
}
/// <summary>
/// Elenco di tipi flusso disponibili
/// </summary>
/// <returns></returns>
public List<string> FluxTypeList()
{
List<string> dbResult = new List<string>();
using (var dbCtx = new MoonPro_STATSContext(_configuration))
{
dbResult = dbCtx
.DbSetFL
.Select(x => x.FluxType)
.Distinct()
.OrderBy(x => x)
.ToList();
}
return dbResult;
}
/// <summary>
/// Elenco tabella ODL da filtro
/// </summary>
+8 -3
View File
@@ -15,6 +15,9 @@ namespace MP.Stats.Components
[Parameter]
public bool DynMode { get; set; } = false;
[Parameter]
public bool HideCurrent { get; set; } = false;
[Parameter]
public List<MP.Data.DbModels.OdlEnergyModel> RawData
{
@@ -163,14 +166,15 @@ namespace MP.Stats.Components
{
if (RawData != null)
{
lineTitles = new List<string>();
if (DynMode)
{
ParetoData = RawData
.GroupBy(p => new { p.IdxMacchina })
//.GroupBy(p => new { p.IdxMacchina, p.CodArticolo })
//.Select(y => new ChartKV() { label = $"{y.First().IdxMacchina} {y.First().CodArticolo}", value = y.Count() })
.GroupBy(p => new { p.IdxMacchina })
.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() })
.OrderByDescending(x => x.value)
.ToList();
@@ -192,7 +196,7 @@ namespace MP.Stats.Components
lineTitles.Add($"{idxMacc} | {TradService.Traduci("MP-STATS_TotEn01")} / {StatService.FluxGetUM("TotCount01")}");
var TSDataCurr = RawData
.Where(x => x.IdxMacchina == idxMacc)
.Where(x => x.IdxMacchina == idxMacc && (!HideCurrent || (x.TotCount01 + x.TotCount02 + x.TotCount03) > 0))
.Select(r => new chartJsData.chartJsTSerie() { x = r.DataInizio, y = (double)r.AvgTotEn01 })
.OrderBy(o => o.x)
.ToList();
@@ -211,6 +215,7 @@ namespace MP.Stats.Components
.ToList();
TSData = RawData
.Where(x => (!HideCurrent || (x.TotCount01 + x.TotCount02 + x.TotCount03) > 0))
.GroupBy(x => x.DataInizio.Date)
.Select(r => new chartJsData.chartJsTSerie() { x = r.First().DataInizio.Date, y = r.Average(l => (double)l.AvgWatt) })
.OrderBy(o => o.x)
+18 -14
View File
@@ -3,17 +3,19 @@
<div class="row">
<div class="col-2">
<div class="card shadow">
<div class="card-body p-1">
<div class="card-header px-1">
<div>
<label class="form-label small">Tipo Flusso</label>
<select @bind="@CodFluxSel" class="form-select">
<option value="*">-- TUTTI --</option>
<option value="*">-- TUTTI --</option>
@foreach (var item in CodFluxList)
{
<option value="@item">@item</option>
}
</select>
</div>
</div>
<div class="card-body p-1">
<div class="mt-2">
<label class="form-label small">Periodo Analisi</label>
<ul class="list-group list-group-sm small">
@@ -26,18 +28,20 @@
</ul>
</div>
</div>
</div>
<div class="border" style="max-height: 14em; overflow:hidden; overflow-y: auto;">
<ul class="list-group list-group-sm small">
@foreach (var item in @ParetoData)
{
<li class="list-group-item p-1 d-flex justify-content-between align-items-center">
@item.label
<span class="badge badge-primary badge-pill">@item.value</span>
</li>
}
</ul>
<i>selezione ITEM da mostrare, tra quelli POSSIBILI dato periodo...</i>
<div class="card-footer px-1">
<div class="border" style="max-height: 14em; overflow:hidden; overflow-y: auto;">
<ul class="list-group list-group-sm small">
@foreach (var item in @ParetoData)
{
<li class="list-group-item p-1 d-flex justify-content-between align-items-center">
@item.label
<span class="badge badge-primary badge-pill">@item.value</span>
</li>
}
</ul>
@* <i>selezione ITEM da mostrare, tra quelli POSSIBILI dato periodo...</i> *@
</div>
</div>
</div>
</div>
<div class="col-10">
+78 -71
View File
@@ -9,6 +9,52 @@ namespace MP.Stats.Components
{
public partial class SelectionFilter
{
#region Public Properties
/// <summary>
/// Indica se filtrare ANCHE le azioni (x tab UL)
/// </summary>
[Parameter]
public bool ActionsEnabled { get; set; } = false;
public string btnClass
{
get
{
return ChartEnabled ? "btn btn-sm btn-info" : "btn btn-sm btn-secondary";
}
}
[Parameter]
public bool ChartEnabled { get; set; } = false;
[Parameter]
public EventCallback<bool> chartsToggle { get; set; }
[Parameter]
public bool chartVisible { get; set; } = false;
[Parameter]
public bool CommessaEnabled { get; set; } = true;
[Parameter]
public EventCallback<SelectData> filterChanged { get; set; }
[Parameter]
public EventCallback<SelectData> filterReset { get; set; }
/// <summary>
/// Selettore x mostrare filtri relativi ad energia:
/// es: mostra solo macchine con dati energia
/// </summary>
[Parameter]
public bool OnlyEnergy { get; set; } = false;
[Parameter]
public SelectData SelFilter { get; set; }
#endregion Public Properties
#region Protected Fields
protected string _searchArt = "";
@@ -17,16 +63,6 @@ namespace MP.Stats.Components
#endregion Protected Fields
#region Private Properties
private List<AutocompleteModel> ddlArticoli { get; set; }
private List<AutocompleteModel> ddlCommesse { get; set; }
private List<AutocompleteModel> ddlMacchine { get; set; }
private List<AutocompleteModel> ddlAzioni { get; set; }
private string selectedSearchValue { get; set; } = "*";
#endregion Private Properties
#region Protected Properties
protected string Azione
@@ -164,67 +200,6 @@ namespace MP.Stats.Components
#endregion Protected Properties
#region Public Properties
public string btnClass
{
get
{
return ChartEnabled ? "btn btn-sm btn-info" : "btn btn-sm btn-secondary";
}
}
[Parameter]
public bool ChartEnabled { get; set; } = false;
[Parameter]
public EventCallback<bool> chartsToggle { get; set; }
[Parameter]
public bool chartVisible { get; set; } = false;
[Parameter]
public bool CommessaEnabled { get; set; } = true;
/// <summary>
/// Indica se filtrare ANCHE le azioni (x tab UL)
/// </summary>
[Parameter]
public bool ActionsEnabled { get; set; } = false;
[Parameter]
public EventCallback<SelectData> filterChanged { get; set; }
[Parameter]
public EventCallback<SelectData> filterReset { get; set; }
[Parameter]
public SelectData SelFilter { get; set; }
#endregion Public Properties
#region Private Methods
private void MySearchHandler(string newValue)
{
IdxMacchina = newValue;
}
private async Task reloadData()
{
ddlArticoli = await StatService.ArticoliGetSearch(-1, SearchArt);
ddlAzioni = await StatService.AzioniList();
ddlCommesse = await StatService.CommesseGetSearch(-1, SearchArt);
ddlMacchine = await StatService.MachineList();
}
private void reportChange()
{
filterChanged.InvokeAsync(SelFilter);
}
#endregion Private Methods
#region Protected Methods
protected override async Task OnInitializedAsync()
@@ -243,5 +218,37 @@ namespace MP.Stats.Components
}
#endregion Protected Methods
#region Private Properties
private List<AutocompleteModel> ddlArticoli { get; set; }
private List<AutocompleteModel> ddlAzioni { get; set; }
private List<AutocompleteModel> ddlCommesse { get; set; }
private List<AutocompleteModel> ddlMacchine { get; set; }
private string selectedSearchValue { get; set; } = "*";
#endregion Private Properties
#region Private Methods
private void MySearchHandler(string newValue)
{
IdxMacchina = newValue;
}
private async Task reloadData()
{
ddlArticoli = await StatService.ArticoliGetSearch(-1, SearchArt);
ddlAzioni = await StatService.AzioniList();
ddlCommesse = await StatService.CommesseGetSearch(-1, SearchArt);
ddlMacchine = await StatService.MachineList(OnlyEnergy);
}
private void reportChange()
{
filterChanged.InvokeAsync(SelFilter);
}
#endregion Private Methods
}
}
+58 -12
View File
@@ -250,7 +250,7 @@ namespace MP.Stats.Data
return answ;
}
public async Task<List<MacchineModel>> MacchineGetAll()
public List<MacchineModel> MacchineGetAll()
{
// setup parametri costanti
string source = "DB";
@@ -260,7 +260,7 @@ namespace MP.Stats.Data
// cerco in redis...
DateTime adesso = DateTime.Now;
string currKey = $"{redisBaseKey}:Cache:Macchine";
RedisValue rawData = await redisDb.StringGetAsync(currKey);
RedisValue rawData = redisDb.StringGet(currKey);
if (rawData.HasValue)
{
result = JsonConvert.DeserializeObject<List<MacchineModel>>($"{rawData}");
@@ -271,7 +271,7 @@ namespace MP.Stats.Data
result = dbController.MacchineGetAll().ToList();
// serializzp e salvo...
rawData = JsonConvert.SerializeObject(result);
await redisDb.StringSetAsync(currKey, rawData, FastCache);
redisDb.StringSet(currKey, rawData, FastCache);
}
if (result == null)
{
@@ -282,18 +282,64 @@ namespace MP.Stats.Data
return result;
}
public Task<List<AutocompleteModel>> MachineList()
public List<MacchineModel> MacchineEnergy()
{
// setup parametri costanti
string source = "DB";
Stopwatch sw = new Stopwatch();
sw.Start();
List<MacchineModel> result = new List<MacchineModel>();
// cerco in redis...
DateTime adesso = DateTime.Now;
string currKey = $"{redisBaseKey}:Cache:MacchineEnergy";
RedisValue rawData = redisDb.StringGet(currKey);
if (rawData.HasValue)
{
result = JsonConvert.DeserializeObject<List<MacchineModel>>($"{rawData}");
source = "REDIS";
}
else
{
result = dbController.MacchineEnergy().ToList();
// serializzp e salvo...
rawData = JsonConvert.SerializeObject(result);
redisDb.StringSet(currKey, rawData, FastCache);
}
if (result == null)
{
result = new List<MacchineModel>();
}
sw.Stop();
Log.Debug($"MacchineEnergy | {source} | {sw.Elapsed.TotalMilliseconds}ms");
return result;
}
public Task<List<AutocompleteModel>> MachineList(bool onlyEnergy = false)
{
List<AutocompleteModel> answ = new List<AutocompleteModel>();
answ.Add(new AutocompleteModel { LabelField = "--- TUTTE ---", ValueField = "*" });
answ.AddRange(dbController
.MacchineGetAll()
.Select(x => new AutocompleteModel
{
LabelField = $"{x.IdxMacchina} | {x.Nome} {x.Descrizione} ",
ValueField = x.IdxMacchina
})
.ToList());
if (onlyEnergy)
{
answ.AddRange(dbController
.MacchineEnergy()
.Select(x => new AutocompleteModel
{
LabelField = $"{x.IdxMacchina} | {x.Nome} {x.Descrizione} ",
ValueField = x.IdxMacchina
})
.ToList());
}
else
{
answ.AddRange(dbController
.MacchineGetAll()
.Select(x => new AutocompleteModel
{
LabelField = $"{x.IdxMacchina} | {x.Nome} {x.Descrizione} ",
ValueField = x.IdxMacchina
})
.ToList());
}
return Task.FromResult(answ);
}
+2 -2
View File
@@ -4,8 +4,8 @@
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>MP.Stats</RootNamespace>
<UserSecretsId>826e877c-ba70-4253-84cb-d0b1cafd4440</UserSecretsId>
<Version>6.16.2507.0213</Version>
<Version>6.16.2507.0213</Version>
<Version>6.16.2507.0217</Version>
<Version>6.16.2507.0217</Version>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<NoWarn>$(NoWarn);1591</NoWarn>
<SatelliteResourceLanguages>en</SatelliteResourceLanguages>
+3 -3
View File
@@ -4,12 +4,12 @@
<div class="card">
<div class="card-header table-primary p-1">
<SelectionFilter SelFilter="currFilter" filterChanged="DoFilter" filterReset="ResetFilter" chartVisible="ShowCharts" chartsToggle="ToggleChart" ChartEnabled="true"></SelectionFilter>
<SelectionFilter SelFilter="currFilter" filterChanged="DoFilter" filterReset="ResetFilter" chartVisible="ShowCharts" chartsToggle="ToggleChart" ChartEnabled="true" OnlyEnergy="true"></SelectionFilter>
</div>
<div class="card-body py-0 px-1">
@if (ShowCharts == true)
{
<ChartEnergy RawData="SearchRecords" DynMode="dynMode"></ChartEnergy>
<ChartEnergy RawData="SearchRecords" DynMode="dynMode" HideCurrent="true"></ChartEnergy>
}
@if (ListRecords == null)
{
@@ -66,7 +66,7 @@
<tbody>
@foreach (var record in ListRecords)
{
<tr class="@checkSelect(@record.IdxOdl)">
<tr class="@checkCurrent(record)">
<td>@record.IdxMacchina</td>
<td>
<div>@record.KeyRichiesta</div>
+10 -15
View File
@@ -51,18 +51,7 @@ namespace MP.Stats.Pages
[Inject]
protected MpStatsService StatService { get; set; }
protected int totalCount
{
get
{
int answ = 0;
if (SearchRecords != null)
{
answ = SearchRecords.Count;
}
return answ;
}
}
protected int totalCount = 0;
[Inject]
protected TranslateSrv TradService { get; set; }
@@ -71,14 +60,19 @@ namespace MP.Stats.Pages
#region Protected Methods
protected string checkSelect(int IdxODL)
/// <summary>
/// Verifica: se è nullo il valore pz totali --> current --> indico non confermato
/// </summary>
/// <param name="testRec"></param>
/// <returns></returns>
protected string checkCurrent(OdlEnergyModel testRec)
{
string answ = "";
if (currRecord != null)
if (testRec != null)
{
try
{
answ = (currRecord.IdxOdl == IdxODL) ? "table-info" : "";
answ = (testRec.TotCount01 + testRec.TotCount02 + testRec.TotCount03) == 0 || testRec.DataFine == null ? "table-warning opacity-50" : "";
}
catch
{ }
@@ -272,6 +266,7 @@ namespace MP.Stats.Pages
private async Task ReloadData()
{
SearchRecords = await StatService.StatOdlEnergyGetAll(currFilter, MServ.SearchVal);
totalCount = SearchRecords.Count;
DisplayData();
}
+1 -1
View File
@@ -5,7 +5,7 @@
<div class="card">
<div class="card-header table-primary p-1">
<SelectionFilter SelFilter="currFilter" filterChanged="DoFilter" filterReset="ResetFilter" ChartEnabled="false"></SelectionFilter>
<SelectionFilter SelFilter="currFilter" filterChanged="DoFilter" filterReset="ResetFilter" ChartEnabled="false" OnlyEnergy="true"></SelectionFilter>
</div>
<div class="card-body py-0 px-1">
@if (isLoading)
+1 -1
View File
@@ -1,6 +1,6 @@
<body>
<i>Modulo statistiche MAPO</i>
<h4>Versione: 6.16.2507.0213</h4>
<h4>Versione: 6.16.2507.0217</h4>
<br />
Note di rilascio:
<ul>
+1 -1
View File
@@ -1 +1 @@
6.16.2507.0213
6.16.2507.0217
+1 -1
View File
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<item>
<version>6.16.2507.0213</version>
<version>6.16.2507.0217</version>
<url>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/MP.Stats.zip</url>
<changelog>https://nexus.steamware.net/repository/SWS/MP-STATS/stable/LAST/ChangeLog.html</changelog>
<mandatory>false</mandatory>