diff --git a/IobConf.Core/IobConfTree.cs b/IobConf.Core/IobConfTree.cs index d169220a..11f7df18 100644 --- a/IobConf.Core/IobConfTree.cs +++ b/IobConf.Core/IobConfTree.cs @@ -3,6 +3,7 @@ using YamlDotNet.Serialization.NamingConventions; using YamlDotNet.Serialization; using static IobConf.Core.EnumConf; using NLog; +using System.Runtime.CompilerServices; // // This is here so CodeMaid doesn't reorganize this document @@ -23,6 +24,63 @@ namespace IobConf.Core Log = LogManager.GetCurrentClassLogger(); } + /// + /// Init classe configurazione da file + /// + public IobConfTree(string confFilePath) + { + Log = LogManager.GetCurrentClassLogger(); + if (File.Exists(confFilePath)) + { + IobConfTree newConfObj = new IobConfTree(); + // verifico TIPO file... + string fileExt = Path.GetExtension(confFilePath); + string fileName = Path.GetFileName(confFilePath); + string rawData = File.ReadAllText(confFilePath); + if (!string.IsNullOrEmpty(rawData)) + { + // leggo in base al tipo... + switch (fileExt) + { + case "yaml": + case "yml": + var deserializer = new DeserializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build(); + try + { + newConfObj = deserializer.Deserialize(rawData); + } + catch (Exception exc) + { + //lgError($"Eccezione in LoadFromYaml{Environment.NewLine}{exc}"); + } + break; + default: + break; + } + if (newConfObj != null) + { + // ora copio in oggetto corrente... + CncData = newConfObj.CncData; + CodIOB = newConfObj.CodIOB; + ConfFileName = fileName; + Customer = newConfObj.Customer; + GeneralCom = newConfObj.GeneralCom; + InputDataProc = newConfObj.InputDataProc; + IobManConf = newConfObj.IobManConf; + IobType = newConfObj.IobType; + Model = newConfObj.Model; + OptPar = newConfObj.OptPar; + ReleaseVers = newConfObj.ReleaseVers; + ServerMES = newConfObj.ServerMES; + TempoCiclo = newConfObj.TempoCiclo; + Vendor = newConfObj.Vendor; + } + } + } + } + /// /// Restituisce un oggetto di conf leggendo INI ed effettuando conversione /// @@ -80,7 +138,7 @@ namespace IobConf.Core newConfObj.ServerMES.Transport = MpIp.StartsWith("https://") ? "https" : "http"; newConfObj.ServerMES.IpAddr = MpIp.Replace($"{newConfObj.ServerMES.Transport}://", ""); // tolgo http/https... } - + // Altro (versione, ...) newConfObj.ReleaseVers = $"{System.Reflection.Assembly.GetExecutingAssembly().GetName().Version}"; newConfObj.IobManConf.MinDeltaSec = fIni.ReadInteger("IOB", "MinDeltaSec", 6); @@ -114,6 +172,35 @@ namespace IobConf.Core return newConfObj; } + /// + /// Restituisce un oggetto di conf deserializzando lo Yaml relativo + /// + /// + /// + public static IobConfTree LoadFromYaml(string yamlFilePath) + { + IobConfTree newConfObj = new IobConfTree(); + if (File.Exists(yamlFilePath)) + { + string rawData = File.ReadAllText(yamlFilePath); + if (!string.IsNullOrEmpty(rawData)) + { + var deserializer = new DeserializerBuilder() + .WithNamingConvention(CamelCaseNamingConvention.Instance) + .Build(); + try + { + newConfObj = deserializer.Deserialize(rawData); + } + catch (Exception exc) + { + //lgError($"Eccezione in LoadFromYaml{Environment.NewLine}{exc}"); + } + } + } + return newConfObj; + } + #region Logging /// diff --git a/MP.Data/Controllers/MpStatsController.cs b/MP.Data/Controllers/MpStatsController.cs index 0ca54481..6ec25ef1 100644 --- a/MP.Data/Controllers/MpStatsController.cs +++ b/MP.Data/Controllers/MpStatsController.cs @@ -42,6 +42,22 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Elenco FLTranslations (decodifica + UM) + /// + /// + public List AnagFLTransGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonPro_STATSContext(_configuration)) + { + dbResult = dbCtx + .DbSetAnagFLTrans + .ToList(); + } + return dbResult; + } + /// /// Elenco tabella Articoli da filtro /// @@ -84,6 +100,24 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Elenco da tabella Config + /// + /// + public List ConfigGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonPro_STATSContext(_configuration)) + { + dbResult = dbCtx + .DbSetConfig + .AsNoTracking() + .OrderBy(x => x.Chiave) + .ToList(); + } + return dbResult; + } + public void Dispose() { } @@ -351,6 +385,24 @@ namespace MP.Data.Controllers return dbResult; } + /// + /// Elenco Vocabolario (completo) + /// + /// + public List VocabolarioGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonPro_STATSContext(_configuration)) + { + dbResult = dbCtx + .DbSetVocabolario + .AsNoTracking() + .OrderBy(x => x.Lemma) + .ToList(); + } + return dbResult; + } + #endregion Public Methods #region Private Fields diff --git a/MP.Data/Controllers/MpVocController.cs b/MP.Data/Controllers/MpVocController.cs new file mode 100644 index 00000000..6e55b500 --- /dev/null +++ b/MP.Data/Controllers/MpVocController.cs @@ -0,0 +1,97 @@ +using DnsClient.Protocol; +using Microsoft.Data.SqlClient; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.Configuration; +using MP.Data.DatabaseModels; +using NLog; +using System; +using System.Collections.Generic; +using System.Drawing.Drawing2D; +using System.Linq; +using static MP.Data.Objects.Enums; + +namespace MP.Data.Controllers +{ + public class MpVocController : IDisposable + { + #region Public Constructors + + public MpVocController(IConfiguration configuration) + { + _configuration = configuration; + Log.Info("Avviata classe MpVocController"); + } + + #endregion Public Constructors + + #region Public Methods + + /// + /// Elenco da tabella Config + /// + /// + public List ConfigGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonPro_VocContext(_configuration)) + { + dbResult = dbCtx + .DbSetConfig + .AsNoTracking() + .OrderBy(x => x.Chiave) + .ToList(); + } + return dbResult; + } + + public void Dispose() + { + } + + /// + /// Elenco Lingue + /// + /// + public List LingueGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonPro_VocContext(_configuration)) + { + dbResult = dbCtx + .DbSetLilngue + .AsNoTracking() + .OrderBy(x => x.Lingua) + .ToList(); + } + return dbResult; + } + + /// + /// Elenco Vocabolario (completo) + /// + /// + public List VocabolarioGetAll() + { + List dbResult = new List(); + using (var dbCtx = new MoonPro_VocContext(_configuration)) + { + dbResult = dbCtx + .DbSetVocabolario + .AsNoTracking() + .OrderBy(x => x.Lemma) + .ToList(); + } + return dbResult; + } + + #endregion Public Methods + + #region Private Fields + + private static IConfiguration _configuration; + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + #endregion Private Fields + } +} \ No newline at end of file diff --git a/MP.Data/DatabaseModels/AnagFLTransModel.cs b/MP.Data/DatabaseModels/AnagFLTransModel.cs new file mode 100644 index 00000000..b263a52d --- /dev/null +++ b/MP.Data/DatabaseModels/AnagFLTransModel.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +// +// This is here so CodeMaid doesn't reorganize this document +// +namespace MP.Data.DatabaseModels +{ + [Table("AnagFLTrans")] + public class AnagFLTransModel + { + [Key, MaxLength(50)] + public string CodFluxIn { get; set; } = ""; + + [MaxLength(50)] + public string CodFluxOut { get; set; } = ""; + + [MaxLength(50)] + public string UM { get; set; } = ""; + } +} diff --git a/MP.Data/DatabaseModels/LingueModel.cs b/MP.Data/DatabaseModels/LingueModel.cs new file mode 100644 index 00000000..e1d3bcbf --- /dev/null +++ b/MP.Data/DatabaseModels/LingueModel.cs @@ -0,0 +1,23 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +#nullable disable +// +// This is here so CodeMaid doesn't reorganize this document +// +namespace MP.Data.DatabaseModels +{ + [Table("Lingue")] + public partial class LingueModel + { + #region Public Properties + + [Key] + public string Lingua { get; set; } = ""; + public string DescrizioneLingua { get; set; } = ""; + + #endregion Public Properties + } +} \ No newline at end of file diff --git a/MP.Data/DatabaseModels/OdlEnergyModel.cs b/MP.Data/DatabaseModels/OdlEnergyModel.cs index 0a0c2ca8..e67251ed 100644 --- a/MP.Data/DatabaseModels/OdlEnergyModel.cs +++ b/MP.Data/DatabaseModels/OdlEnergyModel.cs @@ -19,10 +19,32 @@ namespace MP.Data.DatabaseModels public string DescArticolo { get; set; } = ""; public decimal TCAssegnato { get; set; } public string IdxMacchina { get; set; } - public DateTime? DataInizio { get; set; } + public DateTime DataInizio { get; set; } = DateTime.MinValue; public DateTime? DataFine { get; set; } public decimal TotCount { get; set; } = 0; - public decimal TotWatt { get; set; } = 0; public decimal TotGas { get; set; } = 0; + public decimal TotWatt { get; set; } = 0; + public decimal TotCount01 { get; set; } = 0; + public decimal TotCount02 { get; set; } = 0; + public decimal TotCount03 { get; set; } = 0; + public decimal TotEn01 { get; set; } = 0; + public decimal TotEn02 { get; set; } = 0; + public decimal TotEn03 { get; set; } = 0; + + [NotMapped] + public decimal AvgWatt + { + get + { + var num = TotWatt; + var den = TotCount; + if (den == 0) + { + den = 1; + } + decimal answ = num / den; + return answ; + } + } } } \ No newline at end of file diff --git a/MP.Data/DatabaseModels/StatsODL.cs b/MP.Data/DatabaseModels/StatsODL.cs index 5fa494ed..6efedf94 100644 --- a/MP.Data/DatabaseModels/StatsODL.cs +++ b/MP.Data/DatabaseModels/StatsODL.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel.DataAnnotations.Schema; #nullable disable @@ -29,6 +30,19 @@ namespace MP.Data.DatabaseModels public int? PzPallet { get; set; } public decimal Tcassegnato { get; set; } + [NotMapped] + public int TotCicli + { + get => NumPezziEv + NumPezziSca; + } + + [NotMapped] + public int NumPezziScaNet + { + get => NumPezziSca - NumPezziRil; + } + + #endregion Public Properties } } \ No newline at end of file diff --git a/MP.Data/MoonPro_STATSContext.cs b/MP.Data/MoonPro_STATSContext.cs index 4af88c94..28b5b027 100644 --- a/MP.Data/MoonPro_STATSContext.cs +++ b/MP.Data/MoonPro_STATSContext.cs @@ -36,16 +36,19 @@ namespace MP.Data #region Public Properties + public virtual DbSet DbSetAnagFLTrans { get; set; } public virtual DbSet DbSetArticoli { get; set; } public virtual DbSet DbSetAzioniUL { get; set; } + public virtual DbSet DbSetConfig { get; set; } public virtual DbSet DbSetControlli { get; set; } public virtual DbSet DbSetDdbTurni { get; set; } public virtual DbSet DbSetMacchine { get; set; } public virtual DbSet DbSetODL { get; set; } + public virtual DbSet DbSetOdlEnergy { get; set; } public virtual DbSet DbSetScarti { get; set; } public virtual DbSet DbSetTurniOee { get; set; } public virtual DbSet DbSetUserLog { get; set; } - public virtual DbSet DbSetOdlEnergy { get; set; } + public virtual DbSet DbSetVocabolario { get; set; } #endregion Public Properties @@ -72,6 +75,31 @@ namespace MP.Data { modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS"); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Chiave); + + entity.ToTable("Config"); + + entity.Property(e => e.Chiave) + .HasMaxLength(50) + .HasColumnName("chiave"); + + entity.Property(e => e.Note).HasColumnName("note"); + + entity.Property(e => e.Valore).HasColumnName("valore"); + + entity.Property(e => e.ValoreStd) + .HasColumnName("valoreStd") + .HasComment("Valore di default/riferimento per la variabile"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.Lingua, e.Lemma }); + + }); + modelBuilder.Entity(entity => { entity.HasNoKey(); diff --git a/MP.Data/MoonPro_VocContext.cs b/MP.Data/MoonPro_VocContext.cs new file mode 100644 index 00000000..bebd8193 --- /dev/null +++ b/MP.Data/MoonPro_VocContext.cs @@ -0,0 +1,97 @@ +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Metadata; +using Microsoft.Extensions.Configuration; +using MP.Data.DatabaseModels; +using NLog; + +#nullable disable +// +// This is here so CodeMaid doesn't reorganize this document +// +namespace MP.Data +{ + public partial class MoonPro_VocContext : DbContext + { + #region Private Fields + + private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); + + private IConfiguration _configuration; + + #endregion Private Fields + + #region Public Constructors + + public MoonPro_VocContext(IConfiguration configuration) + { + _configuration = configuration; + } + + public MoonPro_VocContext(DbContextOptions options) : base(options) + { + } + + #endregion Public Constructors + + #region Public Properties + + public virtual DbSet DbSetConfig { get; set; } + public virtual DbSet DbSetLilngue { get; set; } + public virtual DbSet DbSetVocabolario { get; set; } + + #endregion Public Properties + + #region Private Methods + + partial void OnModelCreatingPartial(ModelBuilder modelBuilder); + + #endregion Private Methods + + #region Protected Methods + + protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) + { + if (!optionsBuilder.IsConfigured) + { + string connString = _configuration.GetConnectionString("MP.Voc"); + + optionsBuilder.UseSqlServer(connString); + } + } + + protected override void OnModelCreating(ModelBuilder modelBuilder) + { + modelBuilder.HasAnnotation("Relational:Collation", "SQL_Latin1_General_CP1_CI_AS"); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.Chiave); + + entity.ToTable("Config"); + + entity.Property(e => e.Chiave) + .HasMaxLength(50) + .HasColumnName("chiave"); + + entity.Property(e => e.Note).HasColumnName("note"); + + entity.Property(e => e.Valore).HasColumnName("valore"); + + entity.Property(e => e.ValoreStd) + .HasColumnName("valoreStd") + .HasComment("Valore di default/riferimento per la variabile"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => new { e.Lingua, e.Lemma }); + + }); + + OnModelCreatingPartial(modelBuilder); + } + + #endregion Protected Methods + } +} \ No newline at end of file diff --git a/MP.Data/Services/ListSelectDataSrv.cs b/MP.Data/Services/ListSelectDataSrv.cs index 2a92ffde..8b007b84 100644 --- a/MP.Data/Services/ListSelectDataSrv.cs +++ b/MP.Data/Services/ListSelectDataSrv.cs @@ -91,9 +91,39 @@ namespace MP.Data.Services return result; } - public Task> ConfigGetAll() + /// + /// Recupero elenco config + /// + /// + public async Task> ConfigGetAll() { - return Task.FromResult(dbController.ConfigGetAll().ToList()); + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:Conf"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + //if (!string.IsNullOrEmpty($"{rawData}")) + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.ConfigGetAll(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, LongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"ConfigGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; } public void Dispose() @@ -104,6 +134,7 @@ namespace MP.Data.Services redisConn = null; redisDb = null; } + /// /// Pulizia cache Redis (tutta) /// @@ -126,6 +157,40 @@ namespace MP.Data.Services return answ; } + /// + /// Elenco link JQM (totale) + /// + /// + public async Task> ListLinkAll() + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:Menu:ALL"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = await Task.FromResult(dbController.ListLinkAll()); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"ListLinkAll | tipoLink: * | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + /// /// Elenco link JQM dato filtro tipo /// @@ -161,39 +226,6 @@ namespace MP.Data.Services Log.Debug($"ListLinkFilt | tipoLink: {tipoLink} | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return result; } - /// - /// Elenco link JQM (totale) - /// - /// - public async Task> ListLinkAll() - { - string source = "DB"; - Stopwatch sw = new Stopwatch(); - sw.Start(); - List? result = new List(); - // cerco in redis... - string currKey = $"{redisBaseKey}:Menu:ALL"; - RedisValue rawData = await redisDb.StringGetAsync(currKey); - if (rawData.HasValue) - { - result = JsonConvert.DeserializeObject>($"{rawData}"); - source = "REDIS"; - } - else - { - result = await Task.FromResult(dbController.ListLinkAll()); - // serializzp e salvo... - rawData = JsonConvert.SerializeObject(result); - await redisDb.StringSetAsync(currKey, rawData, UltraLongCache); - } - if (result == null) - { - result = new List(); - } - sw.Stop(); - Log.Debug($"ListLinkAll | tipoLink: * | {source} | {sw.Elapsed.TotalMilliseconds}ms"); - return result; - } /// /// Elenco Macchine dato operatore secondo gruppi (macchine/operatore) diff --git a/MP.Data/Services/OrderDataSrv.cs b/MP.Data/Services/OrderDataSrv.cs index f8393aca..7c5990c6 100644 --- a/MP.Data/Services/OrderDataSrv.cs +++ b/MP.Data/Services/OrderDataSrv.cs @@ -55,13 +55,57 @@ namespace MP.Data.Services #region Public Methods + /// + /// Recupero elenco config + /// + /// + public async Task> ConfigGetAll() + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:Conf"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + //if (!string.IsNullOrEmpty($"{rawData}")) + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.ConfigGetAll(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, LongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"ConfigGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + + public void Dispose() + { + // Clear database controller + dbController.Dispose(); + // redis dispose + redisConn = null; + redisDb = null; + } + /// /// Elenco ODL filtrati x articolo e macchina /// /// Cod articolo /// Macchina selezionata /// - public async Task> ListODLFilt(string CodArt, string IdxMacchina="*") + public async Task> ListODLFilt(string CodArt, string IdxMacchina = "*") { // setup parametri costanti bool inCorso = false; @@ -84,7 +128,7 @@ namespace MP.Data.Services } else { - result = await Task.FromResult(dbController.ListODLFilt(inCorso,CodArt, keyRichPart, Reparto, IdxMacchina, startDate, endDate)); + result = await Task.FromResult(dbController.ListODLFilt(inCorso, CodArt, keyRichPart, Reparto, IdxMacchina, startDate, endDate)); // serializzp e salvo... rawData = JsonConvert.SerializeObject(result); await redisDb.StringSetAsync(currKey, rawData, LongCache); @@ -98,23 +142,6 @@ namespace MP.Data.Services return result; } - - - public Task> ConfigGetAll() - { - return Task.FromResult(dbController.ConfigGetAll().ToList()); - } - - public void Dispose() - { - // Clear database controller - dbController.Dispose(); - // redis dispose - redisConn = null; - redisDb = null; - } - - #endregion Public Methods #region Protected Fields diff --git a/MP.Data/Services/StatusData.cs b/MP.Data/Services/StatusData.cs index 9d872f8a..c0a46009 100644 --- a/MP.Data/Services/StatusData.cs +++ b/MP.Data/Services/StatusData.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Configuration; using MP.Data.Conf; +using MP.Data.Controllers; using MP.Data.DatabaseModels; using Newtonsoft.Json; using NLog; @@ -74,9 +75,39 @@ namespace MP.Data.Services #region Public Methods - public Task> ConfigGetAll() + /// + /// Recupero elenco config + /// + /// + public async Task> ConfigGetAll() { - return Task.FromResult(dbController.ConfigGetAll().ToList()); + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:Conf"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + //if (!string.IsNullOrEmpty($"{rawData}")) + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.ConfigGetAll(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, LongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"ConfigGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; } public void Dispose() @@ -227,6 +258,22 @@ namespace MP.Data.Services return answ; } + /// + /// Elimina info numPezzi x macchina + /// + /// + /// + public bool MachProdStRem(string idxMacchina) + { + bool answ = false; + if (MachineProdStatus.ContainsKey(idxMacchina)) + { + MachineProdStatus.Remove(idxMacchina); + } + answ = true; + return answ; + } + /// /// Salva numPezzi x macchina /// @@ -248,22 +295,6 @@ namespace MP.Data.Services return answ; } - /// - /// Elimina info numPezzi x macchina - /// - /// - /// - public bool MachProdStRem(string idxMacchina) - { - bool answ = false; - if (MachineProdStatus.ContainsKey(idxMacchina)) - { - MachineProdStatus.Remove(idxMacchina); - } - answ = true; - return answ; - } - public async Task> MseGetAll(bool forceDb = false) { Stopwatch sw = new Stopwatch(); @@ -313,17 +344,12 @@ namespace MP.Data.Services #region Private Fields private static IConfiguration _configuration = null!; - private static NLog.Logger Log = LogManager.GetCurrentClassLogger(); /// /// Cache breve durata /// private TimeSpan FastCache = TimeSpan.FromSeconds(5); - /// - /// Cache brevissima durata - /// - private TimeSpan UltraFastCache = TimeSpan.FromMilliseconds(1500); /// /// Cache lunga durata @@ -331,6 +357,12 @@ namespace MP.Data.Services private TimeSpan LongCache = TimeSpan.FromSeconds(60); private int maxAge = 2000; + private string redisBaseKey = "MP:ALL:Cache"; + + /// + /// Cache brevissima durata + /// + private TimeSpan UltraFastCache = TimeSpan.FromMilliseconds(1500); #endregion Private Fields diff --git a/MP.Data/Services/TranslateSrv.cs b/MP.Data/Services/TranslateSrv.cs new file mode 100644 index 00000000..64839fe2 --- /dev/null +++ b/MP.Data/Services/TranslateSrv.cs @@ -0,0 +1,285 @@ +using Microsoft.Extensions.Configuration; +using MP.Data.Conf; +using MP.Data.DatabaseModels; +using Newtonsoft.Json; +using NLog; +using StackExchange.Redis; +using System; +using System.Collections.Generic; +using System.Data; +using System.Diagnostics; +using System.IO; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace MP.Data.Services +{ + /// + /// Classe accesso processi traduzione + /// + public class TranslateSrv : BaseServ, IDisposable + { + #region Public Constructors + + public TranslateSrv(IConfiguration configuration) + { + Stopwatch sw = Stopwatch.StartNew(); + sw.Start(); + _configuration = configuration; + // setup compoenti REDIS + redisConn = ConnectionMultiplexer.Connect(_configuration.GetConnectionString("Redis")); + redisDb = redisConn.GetDatabase(); + + // conf DB + string connStr = _configuration.GetConnectionString("MP.Voc"); + if (string.IsNullOrEmpty(connStr)) + { + Log.Error("MP.Voc: ConnString empty!"); + } + else + { + dbController = new Controllers.MpVocController(configuration); + InitDict(); + sw.Stop(); + Log.Info($"TranslateSrv | MpVocController OK | {sw.Elapsed.TotalMilliseconds} ms"); + } + } + + #endregion Public Constructors + + #region Public Properties + + public static Controllers.MpVocController dbController { get; set; } = null!; + + #endregion Public Properties + + #region Public Methods + + /// + /// Recupero elenco config + /// + /// + public async Task> ConfigGetAll() + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:Conf"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + //if (!string.IsNullOrEmpty($"{rawData}")) + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.ConfigGetAll(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, LongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"ConfigGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + + public void Dispose() + { + // Clear database controller + dbController.Dispose(); + // redis dispose + redisConn = null; + redisDb = null; + } + + /// + /// Pulizia cache Redis (tutta) + /// + /// + public async Task FlushCache() + { + RedisValue pattern = new RedisValue($"{redisBaseKey}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + // rileggo vocabolario! + var rawData = await VocabolarioGetAll(); + DictVocab = rawData.ToDictionary(kvp => $"{kvp.Lingua}_{kvp.Lemma}".ToUpper(), kvp => kvp.Traduzione); + return answ; + } + + /// + /// Pulizia cache Redis per chiave specifica (da redisBaseKey...) + /// + /// + public async Task FlushCache(string KeyReq) + { + RedisValue pattern = new RedisValue($"{redisBaseKey}:{KeyReq}:*"); + bool answ = await ExecFlushRedisPattern(pattern); + return answ; + } + + /// + /// Recupero elenco config + /// + /// + public async Task> LingueGetAll() + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:Lang"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + //if (!string.IsNullOrEmpty($"{rawData}")) + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.LingueGetAll(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, UltraLongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"LingueGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + + /// + /// Traduzione termine + /// + /// + /// + /// + public string Traduci(string lemma, string lingua = "IT") + { + string answ = $"[{lemma}.{lingua}]"; + string key = $"{lingua}_{lemma}".ToUpper(); + if (DictVocab.ContainsKey(key)) + { + answ = DictVocab[key]; + } + return answ; + } + + /// + /// Recupero elenco config + /// + /// + public async Task> VocabolarioGetAll() + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:Voc"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + //if (!string.IsNullOrEmpty($"{rawData}")) + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.VocabolarioGetAll(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, LongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"VocabolarioGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + + #endregion Public Methods + + #region Protected Fields + + /// + /// Vocabolario x recupero rapido traduzioni + /// + protected static Dictionary DictVocab = new Dictionary(); + + /// + /// Oggetto per connessione a REDIS + /// + protected ConnectionMultiplexer redisConn = null!; + + /// + /// Oggetto DB redis da impiegare x chiamate R/W + /// + protected IDatabase redisDb = null!; + + #endregion Protected Fields + + #region Private Fields + + private static Logger Log = LogManager.GetCurrentClassLogger(); + + private string redisBaseKey = "MP:Voc:Cache"; + + #endregion Private Fields + + #region Private Methods + + /// + /// Inizializzazione dict vari + /// + private static void InitDict() + { + // inizializzo dizionario vocabolario + var rawData = dbController.VocabolarioGetAll(); + DictVocab = rawData.ToDictionary(kvp => $"{kvp.Lingua}_{kvp.Lemma}".ToUpper(), kvp => kvp.Traduzione); + } + + /// + /// Esegue flush memoria redis dato pattern + /// + /// + /// + private async Task ExecFlushRedisPattern(RedisValue pattern) + { + bool answ = false; + var listEndpoints = redisConn.GetEndPoints(); + foreach (var endPoint in listEndpoints) + { + //var server = redisConnAdmin.GetServer(listEndpoints[0]); + var server = redisConn.GetServer(endPoint); + if (server != null) + { + var keyList = server.Keys(redisDb.Database, pattern); + foreach (var item in keyList) + { + await redisDb.KeyDeleteAsync(item); + } + answ = true; + } + } + + return answ; + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/MP.Stats/Components/ChartEnergy.razor b/MP.Stats/Components/ChartEnergy.razor new file mode 100644 index 00000000..dbe942c6 --- /dev/null +++ b/MP.Stats/Components/ChartEnergy.razor @@ -0,0 +1,34 @@ +@using ChartJs + +
+ @if (RawData == null || RawData.Count == 0) + { +
+
No Chart Data
+
+ } + else + { +
+
    + @foreach (var item in @ParetoData) + { +
  • + @item.label + @item.value +
  • + } +
+
+
+
+
+ +
+
+ +
+
+
+ } +
\ No newline at end of file diff --git a/MP.Stats/Components/ChartEnergy.razor.cs b/MP.Stats/Components/ChartEnergy.razor.cs new file mode 100644 index 00000000..9d843c6f --- /dev/null +++ b/MP.Stats/Components/ChartEnergy.razor.cs @@ -0,0 +1,181 @@ +using Microsoft.AspNetCore.Components; +using Microsoft.IdentityModel.Tokens; +using MP.Data; +using MP.Stats.Data; +using System.Collections.Generic; +using System.Linq; + +namespace MP.Stats.Components +{ + public partial class ChartEnergy + { + #region Public Properties + + [Parameter] + public List RawData + { + get => _rawData; + set + { + // salvo valori + _rawData = value; + if (value != null) + { + // ricalcolo charting data + recalcData(); + } + } + } + + #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(); + + protected List _rawData { get; set; } = new List(); + + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List bgColors + { + get => semaphColors(ParetoData.Count, "0.3"); + } + + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List lineColor + { + get => solidColors("1"); + } + + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List lineColors + { + get => semaphColors(ParetoData.Count, "1"); + } + + [Inject] + protected MessageService MessageService { get; set; } + + protected List ParetoData { get; set; } = new List(); + + [Inject] + protected MpStatsService StatService { get; set; } + + protected List TSData { get; set; } = new List(); + + #endregion Protected Properties + + #region Protected Methods + + /// Genera colori sfondo 33% rosso / arancione / giallo + ///
+ /// + /// + protected List semaphColors(int numRecords, string alpha) + { + List answ = new List(); + + int numStep = 5; + // ciclo x numStep-1 + for (int j = 0; j < numStep; j++) + { + for (int i = 0; i < numRecords / numStep; i++) + { + answ.Add($"rgba({54 + (180 - 54) * j / numStep}, {254 + (180 - 254) * j / numStep}, {86 + (35 - 86) * j / numStep}, {alpha}"); + } + } + // chiude + while (answ.Count < numRecords) + { + answ.Add($"rgba(180, 180, 35, {alpha})"); + } + return answ; + } + + /// + /// Genera colori sfondo 33% rosso / arancione / giallo + /// + /// + /// + protected List solidColors(string alpha) + { + List answ = new List(); + answ.Add($"rgba(54, 162, 235, {alpha})"); + return answ; + } + + #endregion Protected Methods + + #region Private Properties + + private List DatiPareto + { + get => ParetoData.Select(x => x.value).ToList(); + } + + private List DatiPlot + { + get => TSData; + } + + private List LabelPareto + { + get => ParetoData.Select(x => x.label).ToList(); + } + + private List LabelPlot + { + get => TSData.Select(r => $"{r.x:yyyy-MM-dd}").ToList(); + } + + #endregion Private Properties + + #region Private Methods + + private List GetLineChartLabels() + { + var answ = TSData.Select(x => x.x.ToString("ddd dd.MM")).ToList(); + return answ; + } + + private void recalcData() + { + if (RawData != null) + { + ParetoData = RawData + .GroupBy(p => new { p.IdxMacchina, p.CodArticolo }) + .Select(y => new ChartKV() { label = $"{y.First().IdxMacchina} {y.First().CodArticolo}", value = y.Count() }) + .OrderByDescending(x => x.value) + .ToList(); + + TSData = RawData + .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) + .ToList(); + } + } + + #endregion Private Methods + } +} \ No newline at end of file diff --git a/MP.Stats/Data/MpStatsService.cs b/MP.Stats/Data/MpStatsService.cs index a652db58..b945a01e 100644 --- a/MP.Stats/Data/MpStatsService.cs +++ b/MP.Stats/Data/MpStatsService.cs @@ -30,9 +30,10 @@ namespace MP.Stats.Data #region Public Constructors - public MpStatsService(IConfiguration configuration, ILogger logger) + public MpStatsService(IConfiguration configuration) { - _logger = logger; + Stopwatch sw = Stopwatch.StartNew(); + sw.Start(); _configuration = configuration; // setup compoenti REDIS @@ -43,14 +44,14 @@ namespace MP.Stats.Data string connStr = _configuration.GetConnectionString("MP.Stats"); if (string.IsNullOrEmpty(connStr)) { - _logger.LogError("ConnString empty!"); + Log.Error("MP.Stats: ConnString empty!"); } else { dbController = new MP.Data.Controllers.MpStatsController(configuration); - StringBuilder sb = new StringBuilder(); - sb.AppendLine($"DbController OK"); - _logger.LogInformation(sb.ToString()); + InitDict(); + sw.Stop(); + Log.Info($"MpStatsService | MpStatsController OK | {sw.Elapsed.TotalMilliseconds} ms"); } } @@ -95,7 +96,39 @@ namespace MP.Stats.Data result = new List(); } sw.Stop(); - _logger.LogDebug($"ActionsGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + Log.Debug($"ActionsGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + + public async Task> AnagFLTransGetAll() + { + // 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 = $"{redisBaseKey}:Cache:FLTrans"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.AnagFLTransGetAll(); + // serializzp e salvo... + rawData = JsonConvert.SerializeObject(result); + await redisDb.StringSetAsync(currKey, rawData, FastCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"AnagFLTransGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return result; } @@ -127,23 +160,6 @@ namespace MP.Stats.Data return Task.FromResult(answ); } -#if false - /// - /// Aggiorna record calcolando prossima scadenza dato ultima esecuzione - /// - /// - /// - public DateTime CalcNextExe(TaskListModel? taskRec) - { - DateTime dtNext = DateTime.Today; - if (taskRec != null) - { - dtNext = dbController.CalcNextExe(taskRec); - } - return dtNext; - } -#endif - public Task> CommesseGetSearch(int numRecord, string searchVal = "") { List answ = new List(); @@ -155,6 +171,41 @@ namespace MP.Stats.Data return Task.FromResult(answ); } + /// + /// Recupero elenco config + /// + /// + public async Task> ConfigGetAll() + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List? result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:Conf"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + //if (!string.IsNullOrEmpty($"{rawData}")) + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.ConfigGetAll(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, LongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"ConfigGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } + public void Dispose() { // Clear database controller @@ -164,22 +215,6 @@ namespace MP.Stats.Data redisDb = null; } -#if false - /// - /// Chiamata esecuzione di un singolo task programmato - /// - /// - /// Se true rischedula successiva chiamata - /// - public async Task ExecuteTask(int TaskId, bool SchedNext) - { - TaskResultModel dbResult = dbController.ExecuteTask(TaskId, SchedNext); - // svuoto cache! - await FlushCache("Task"); - return await Task.FromResult(dbResult); - } -#endif - /// /// Pulizia cache Redis (tutta) /// @@ -188,6 +223,10 @@ namespace MP.Stats.Data { RedisValue pattern = new RedisValue($"{redisBaseKey}:*"); bool answ = await ExecFlushRedisPattern(pattern); + + // rileggo conf UM! + var rawData = await AnagFLTransGetAll(); + DictFluxUm = rawData.ToDictionary(kvp => $"{kvp.CodFluxOut}", kvp => kvp.UM); return answ; } @@ -202,6 +241,20 @@ namespace MP.Stats.Data return answ; } + /// + /// Restituisce UM del flusso configurato + /// + /// + public string FluxGetUM(string codFlux) + { + string answ = "#"; + if (DictFluxUm.ContainsKey(codFlux)) + { + answ = DictFluxUm[codFlux]; + } + return answ; + } + public async Task> MacchineGetAll() { // setup parametri costanti @@ -230,7 +283,7 @@ namespace MP.Stats.Data result = new List(); } sw.Stop(); - _logger.LogDebug($"MacchineGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + Log.Debug($"MacchineGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return result; } @@ -303,7 +356,7 @@ namespace MP.Stats.Data .ToList(); } sw.Stop(); - _logger.LogDebug($"StatControlliGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + Log.Debug($"StatControlliGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return result; } @@ -335,7 +388,7 @@ namespace MP.Stats.Data result = new List(); } sw.Stop(); - _logger.LogDebug($"StatDdbGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + Log.Debug($"StatDdbGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return result; } @@ -354,7 +407,7 @@ namespace MP.Stats.Data dbResult = dbController.StatDdbGetAll(CurrFilter.DateStart, CurrFilter.DateEnd, CurrFilter.IdxMacchina, CurrFilter.IdxOdl, CurrFilter.KeyRichiesta, CurrFilter.CodArticolo, 1, 0); stopWatch.Stop(); TimeSpan ts = stopWatch.Elapsed; - _logger.LogTrace($"Effettuata lettura COMPLETA da DB + caching per StatDdbGetAllExport: {ts.TotalMilliseconds} ms"); + Log.Trace($"Effettuata lettura COMPLETA da DB + caching per StatDdbGetAllExport: {ts.TotalMilliseconds} ms"); return await Task.FromResult(dbResult); } @@ -382,7 +435,7 @@ namespace MP.Stats.Data await redisDb.StringSetAsync(currKey, rawData, FastCache); } sw.Stop(); - _logger.LogDebug($"StatDdbGetCount | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + Log.Debug($"StatDdbGetCount | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return numRec; } @@ -420,7 +473,7 @@ namespace MP.Stats.Data result = new List(); } sw.Stop(); - _logger.LogDebug($"StatOdlEnergyGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + Log.Debug($"StatOdlEnergyGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return result; } @@ -458,7 +511,7 @@ namespace MP.Stats.Data result = new List(); } sw.Stop(); - _logger.LogDebug($"StatOdlEnergyGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + Log.Debug($"StatOdlEnergyGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return result; } @@ -490,7 +543,7 @@ namespace MP.Stats.Data result = new List(); } sw.Stop(); - _logger.LogDebug($"StatScartiGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + Log.Debug($"StatScartiGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return result; } @@ -527,7 +580,7 @@ namespace MP.Stats.Data result = new List(); } sw.Stop(); - _logger.LogDebug($"StatTurniOeeGetAllCached | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + Log.Debug($"StatTurniOeeGetAllCached | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return result; } @@ -559,10 +612,44 @@ namespace MP.Stats.Data result = new List(); } sw.Stop(); - _logger.LogDebug($"StatUserLogGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + Log.Debug($"StatUserLogGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); return result; } + /// + /// Recupero vocabolario + /// + /// + public async Task> VocabolarioGetAll() + { + string source = "DB"; + Stopwatch sw = new Stopwatch(); + sw.Start(); + List result = new List(); + // cerco in redis... + string currKey = $"{redisBaseKey}:Vocabolario"; + RedisValue rawData = await redisDb.StringGetAsync(currKey); + //if (!string.IsNullOrEmpty($"{rawData}")) + if (rawData.HasValue) + { + result = JsonConvert.DeserializeObject>($"{rawData}"); + source = "REDIS"; + } + else + { + result = dbController.VocabolarioGetAll(); + // serializzo e salvo... + rawData = JsonConvert.SerializeObject(result); + redisDb.StringSet(currKey, rawData, LongCache); + } + if (result == null) + { + result = new List(); + } + sw.Stop(); + Log.Debug($"VocabolarioGetAll | {source} | {sw.Elapsed.TotalMilliseconds}ms"); + return result; + } #endregion Public Methods @@ -572,6 +659,11 @@ namespace MP.Stats.Data protected static string connStringFatt = ""; + /// + /// Vocabolario x recupero rapido traduzioni + /// + protected static Dictionary DictFluxUm = new Dictionary(); + /// /// Oggetto per connessione a REDIS /// @@ -604,14 +696,22 @@ namespace MP.Stats.Data private static IConfiguration _configuration; - private static ILogger _logger; - private string redisBaseKey = "MP:STATS"; #endregion Private Fields #region Private Methods + /// + /// Inizializzazione dict vari + /// + private static void InitDict() + { + // inizializzo dizionario vocabolario + var rawData = dbController.AnagFLTransGetAll(); + DictFluxUm = rawData.ToDictionary(kvp => $"{kvp.CodFluxOut}", kvp => kvp.UM); + } + /// /// Esegue flush memoria redis dato pattern /// diff --git a/MP.Stats/MP.Stats.csproj b/MP.Stats/MP.Stats.csproj index eb0176b7..f9311de8 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.2502.1011 - 6.16.2502.1011 + 6.16.2502.1811 + 6.16.2502.1811 true $(NoWarn);1591 en diff --git a/MP.Stats/Pages/Energy.razor b/MP.Stats/Pages/Energy.razor index 4f442e7f..7631b1c4 100644 --- a/MP.Stats/Pages/Energy.razor +++ b/MP.Stats/Pages/Energy.razor @@ -4,9 +4,13 @@
- +
+ @if (ShowCharts == true) + { + + } @if (ListRecords == null) { @@ -27,12 +31,36 @@ Articolo Inizio Fine - Unit - Energy - Gas - @* P1 - P2 - P3 *@ + @if (dynMode) + { + @Traduci("MP-STATS_TotCount01") + @if (numCount > 1) + { + @Traduci("MP-STATS_TotCount02") + } + @if (numCount > 2) + { + @Traduci("MP-STATS_TotCount03") + } + @Traduci("MP-STATS_TotEn01") + @Traduci("MP-STATS_TotEn01")/Unit + @if (numTotEn > 1) + { + @Traduci("MP-STATS_TotEn02") + @Traduci("MP-STATS_TotEn02")/Unit + } + @if (numTotEn > 2) + { + @Traduci("MP-STATS_TotEn03") + @Traduci("MP-STATS_TotEn03")/Unit + } + } + else + { + Unit + Energy + Gas + } @@ -46,33 +74,114 @@ @record.CodArticolo -
TBD: @record.CodArticolo
- @*
@record.DescArticolo
*@ +
@record.DescArticolo
@record.DataInizio @record.DataFine - @(record.TotCount.ToString("N0")) m - -
- @record.TotWatt.ToString("N2") kWh -
- - @righDiv(record.TotWatt, record.TotCount).ToString("N3") kWh/m - - - -
- @record.TotGas.ToString("N2") m3 -
- - @righDiv(record.TotGas, record.TotCount).ToString("N3") m3/m - - - @* - @($"{currSim:N1}") - @($"{currSimGas:N1}") - @($"{currSim + currSimGas:N1}") - *@ + @if (dynMode) + { + @($"{record.TotCount01:N0}") @GetUM("TotCount01") + @if (numCount > 1) + { + @($"{record.TotCount02:N0}") @GetUM("TotCount02") + } + @if (numCount > 2) + { + @($"{record.TotCount03:N0}") @GetUM("TotCount03") + } + +
+ @($"{record.TotEn01:N2}") @GetUM("TotEn01") +
+ + +
+ @righDiv(record.TotEn01, record.TotCount01).ToString("N3") @GetUM("TotEn01")/@GetUM("TotCount01") +
+ @if (numCount > 1) + { +
+ @righDiv(record.TotEn01, record.TotCount02).ToString("N3") @GetUM("TotEn01")/@GetUM("TotCount02") +
+ } + @if (numCount > 2) + { +
+ @righDiv(record.TotEn01, record.TotCount03).ToString("N3") @GetUM("TotEn01")/@GetUM("TotCount03") +
+ } + + @if (numTotEn > 1) + { + +
+ @($"{record.TotEn02:N2}") @GetUM("TotEn02") +
+ + +
+ @righDiv(record.TotEn02, record.TotCount01).ToString("N3") @GetUM("TotEn02")/@GetUM("TotCount01") +
+ @if (numCount > 1) + { +
+ @righDiv(record.TotEn02, record.TotCount02).ToString("N3") @GetUM("TotEn02")/@GetUM("TotCount02") +
+ } + @if (numCount > 2) + { +
+ @righDiv(record.TotEn02, record.TotCount03).ToString("N3") @GetUM("TotEn02")/@GetUM("TotCount03") +
+ } + + } + @if (numTotEn > 2) + { + +
+ @($"{record.TotEn03:N2}") @GetUM("TotEn03") +
+ + +
+ @righDiv(record.TotEn03, record.TotCount01).ToString("N3") @GetUM("TotEn02")/@GetUM("TotCount01") +
+ @if (numCount > 1) + { +
+ @righDiv(record.TotEn03, record.TotCount02).ToString("N3") @GetUM("TotEn02")/@GetUM("TotCount02") +
+ } + @if (numCount > 2) + { +
+ @righDiv(record.TotEn03, record.TotCount03).ToString("N3") @GetUM("TotEn02")/@GetUM("TotCount03") +
+ } + + } + } + else + { + @(record.TotCount.ToString("N0")) m + +
+ @record.TotWatt.ToString("N2") kWh +
+ + @righDiv(record.TotWatt, record.TotCount).ToString("N3") kWh/m + + + +
+ @record.TotGas.ToString("N2") m3 +
+ + @righDiv(record.TotGas, record.TotCount).ToString("N3") m3/m + + + } } @@ -82,6 +191,6 @@ }
\ No newline at end of file diff --git a/MP.Stats/Pages/Energy.razor.cs b/MP.Stats/Pages/Energy.razor.cs index 0f4d58a2..9e36eb0d 100644 --- a/MP.Stats/Pages/Energy.razor.cs +++ b/MP.Stats/Pages/Energy.razor.cs @@ -1,5 +1,7 @@ using Microsoft.AspNetCore.Components; using Microsoft.JSInterop; +using MP.Data.DatabaseModels; +using MP.Data.Services; using MP.Stats.Data; using System; using System.Collections.Generic; @@ -13,13 +15,18 @@ namespace MP.Stats.Pages { #region Private Fields - private MP.Data.DatabaseModels.OdlEnergyModel currRecord = null; + private OdlEnergyModel currRecord = null; - private List ListRecords; - private List SearchRecords; + private List ListRecords; + private List SearchRecords; + private List ConfigList; #endregion Private Fields + + [Inject] + protected TranslateSrv TradService { get; set; } + #region Protected Fields protected string fileName = "ODL_Energy.csv"; @@ -58,7 +65,7 @@ namespace MP.Stats.Pages protected IJSRuntime JSRuntime { get; set; } [Inject] - protected MessageService MessageService { get; set; } + protected MP.Stats.Data.MessageService MessageService { get; set; } [Inject] protected NavigationManager NavManager { get; set; } @@ -99,9 +106,64 @@ namespace MP.Stats.Pages private async Task ReloadData() { SearchRecords = await StatService.StatOdlEnergyGetAll(currFilter, MessageService.SearchVal); - ListRecords = SearchRecords.Skip(numRecord * (currPage - 1)).Take(numRecord).ToList(); + DisplayData(); } + /// + /// Traduzione lemma richeisto (lingua default="IT") + /// + /// + /// + public string Traduci(string Lemma) + { + return TradService.Traduci(Lemma); + } + + /// + /// recupero UM del flusso indicato + /// + /// + /// + public string GetUM(string CodFlux) + { + return StatService.FluxGetUM(CodFlux); + } + + private async Task LoadConfData() + { + ConfigList = await StatService.ConfigGetAll(); + dynMode = convVal("STATS_EnergyMode") == "Dynamic"; + var sNumCount = convVal("STATS_EnergyNumCount"); + int.TryParse(convVal("STATS_EnergyNumCount"), out numCount); + int.TryParse(convVal("STATS_EnergyNumTotEn"), out numTotEn); + } + + private string convVal(string chiave) + { + string answ = ""; + if (ConfigList != null && ConfigList.Count > 0) + { + var searchRec = ConfigList.First(x => x.Chiave == chiave); + if (searchRec != null) + { + answ = searchRec.Valore; + } + } + return answ; + } + + private void DisplayData() + { + ListRecords = SearchRecords + .Skip(numRecord * (currPage - 1)) + .Take(numRecord) + .ToList(); + } + + private bool dynMode = false; + private int numCount = 1; + private int numTotEn = 1; + #endregion Private Methods #region Protected Methods @@ -115,16 +177,16 @@ namespace MP.Stats.Pages await ReloadData(); } - protected async Task ForceReload(int newNum) + protected void SetNumRec(int newNum) { numRecord = newNum; - await ReloadData(); + DisplayData(); } - protected async Task ForceReloadPage(int newNum) + protected void SetPage(int newNum) { currPage = newNum; - await ReloadData(); + DisplayData(); } protected override async Task OnInitializedAsync() @@ -135,6 +197,7 @@ namespace MP.Stats.Pages MessageService.PageName = "ENERGY"; MessageService.PageIcon = "oi oi-bar-chart"; MessageService.EA_SearchUpdated += OnSeachUpdated; + await LoadConfData(); await ReloadData(); } @@ -196,6 +259,15 @@ namespace MP.Stats.Pages #endregion Public Methods + private bool ShowCharts { get; set; } = false; + protected async Task ToggleChart(bool doShow) + { + ShowCharts = !ShowCharts; + if (ShowCharts) + { + await ReloadData(); + } + } protected decimal righDiv(decimal num, decimal den) { if (den == 0) diff --git a/MP.Stats/Pages/ForceReset.razor.cs b/MP.Stats/Pages/ForceReset.razor.cs index 56bbc029..22d95f89 100644 --- a/MP.Stats/Pages/ForceReset.razor.cs +++ b/MP.Stats/Pages/ForceReset.razor.cs @@ -16,6 +16,9 @@ namespace MP.Stats.Pages [Inject] protected MpStatsService StatService { get; set; } + [Inject] + protected TranslateSrv TradServ { get; set; } = null!; + [Inject] protected TaskService TServ { get; set; } = null!; @@ -27,6 +30,7 @@ namespace MP.Stats.Pages { await StatService.FlushCache(); await TServ.FlushCache(); + await TradServ.FlushCache(); await Task.Delay(500); NavManager.NavigateTo("", true); } diff --git a/MP.Stats/Pages/ReportODL.razor b/MP.Stats/Pages/ReportODL.razor index 87774141..5483299e 100644 --- a/MP.Stats/Pages/ReportODL.razor +++ b/MP.Stats/Pages/ReportODL.razor @@ -27,10 +27,11 @@ Articolo Inizio Fine - Pezzi Rich - Pezzi Evasi - Pezzi Scarti - Pezzi Rilav + Pezzi Rich + # Buoni + # Scarti + Cicli Rilav + # Cicli Tot @@ -48,10 +49,11 @@ @record.DataInizio @record.DataFine - @record.NumPezzi - @record.NumPezziEv - @record.NumPezziSca - @record.NumPezziRil + @record.NumPezzi + @record.NumPezziEv + @record.NumPezziScaNet + @record.NumPezziRil + @record.TotCicli } diff --git a/MP.Stats/Resources/ChangeLog.html b/MP.Stats/Resources/ChangeLog.html index 2d54b823..46ce91c8 100644 --- a/MP.Stats/Resources/ChangeLog.html +++ b/MP.Stats/Resources/ChangeLog.html @@ -1,6 +1,6 @@ Modulo statistiche MAPO -

Versione: 6.16.2502.1011

+

Versione: 6.16.2502.1811


Note di rilascio:
    diff --git a/MP.Stats/Resources/VersNum.txt b/MP.Stats/Resources/VersNum.txt index 7dc780a1..a990f286 100644 --- a/MP.Stats/Resources/VersNum.txt +++ b/MP.Stats/Resources/VersNum.txt @@ -1 +1 @@ -6.16.2502.1011 +6.16.2502.1811 diff --git a/MP.Stats/Resources/manifest.xml b/MP.Stats/Resources/manifest.xml index 560d078f..4616e2a2 100644 --- a/MP.Stats/Resources/manifest.xml +++ b/MP.Stats/Resources/manifest.xml @@ -1,6 +1,6 @@ - 6.16.2502.1011 + 6.16.2502.1811 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 fcbdfdc1..4b13a292 100644 --- a/MP.Stats/Shared/NavMenu.razor +++ b/MP.Stats/Shared/NavMenu.razor @@ -43,10 +43,10 @@ diff --git a/MP.Stats/Startup.cs b/MP.Stats/Startup.cs index c756e42e..3511f254 100644 --- a/MP.Stats/Startup.cs +++ b/MP.Stats/Startup.cs @@ -5,6 +5,7 @@ using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.OpenApi.Models; +using MP.Data.Services; using MP.Stats.Data; using MP.TaskMan.Services; using StackExchange.Redis; @@ -146,8 +147,9 @@ namespace MP.Stats services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); - services.AddScoped(); + services.AddScoped(); } #endregion Public Methods diff --git a/MP.Stats/appsettings.Development.json b/MP.Stats/appsettings.Development.json index 51737579..ffb9a69f 100644 --- a/MP.Stats/appsettings.Development.json +++ b/MP.Stats/appsettings.Development.json @@ -6,5 +6,9 @@ "Microsoft": "Warning", "Microsoft.Hosting.Lifetime": "Information" } - } + }, + //"ConnectionStrings": { + // "DefaultConnection": "Server=SQL2022PROD;Database=TFT_MoonPro_STATS_Prod;Trusted_Connection=True;MultipleActiveResultSets=true", + // "MP.Stats": "Server=SQL2022PROD;Database=TFT_MoonPro_STATS_Prod;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.STATS;" + //} } diff --git a/MP.Stats/appsettings.json b/MP.Stats/appsettings.json index cdf5310e..da316a22 100644 --- a/MP.Stats/appsettings.json +++ b/MP.Stats/appsettings.json @@ -53,7 +53,8 @@ "ConnectionStrings": { "Redis": "localhost:26379,serviceName=devel,DefaultDatabase=5,connectTimeout=5000,syncTimeout=5000,asyncTimeout=5000,abortConnect=false,ssl=false,allowAdmin=true", "DefaultConnection": "Server=SQL2016DEV;Database=MoonPro_STATS;Trusted_Connection=True;MultipleActiveResultSets=true", - "MP.Stats": "Server=SQL2016DEV;Database=MoonPro_STATS;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.STATS;" + "MP.Stats": "Server=SQL2016DEV;Database=MoonPro_STATS;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.STATS;", + "MP.Voc": "Server=SQL2016DEV;Database=MoonPro_STATS;User ID=sa;Password=keyhammer16;integrated security=False;MultipleActiveResultSets=True;App=MP.STATS;" }, "FormatDur": "HH:mm.ss.ff", "SpecialConf": {