diff --git a/Thermo.Active.Model/Constants.cs b/Thermo.Active.Model/Constants.cs index 38f717c7..82426a46 100644 --- a/Thermo.Active.Model/Constants.cs +++ b/Thermo.Active.Model/Constants.cs @@ -219,6 +219,8 @@ namespace Thermo.Active.Model public static readonly string CLIENT_PATH_86 = BASE_PATH + @"\Client\x86\" + CLIENT_EXE_NAME; public static string WEBSITE_DIRECTORY = BASE_PATH + "\\view"; #endif + + public const int numRecProdPanelGraph = 30; public const string CONFIG_DIRECTORY = "Config\\"; public const string RECIPE_DIRECTORY = "Recipes\\"; public const string RECIPE_TEMPLATE_PATH = CONFIG_DIRECTORY + RECIPE_DIRECTORY + "template.tpl"; diff --git a/Thermo.Active.Model/DTOModels/ThProd/DTOThermoPanelProd.cs b/Thermo.Active.Model/DTOModels/ThProd/DTOThermoPanelProd.cs new file mode 100644 index 00000000..db565b97 --- /dev/null +++ b/Thermo.Active.Model/DTOModels/ThProd/DTOThermoPanelProd.cs @@ -0,0 +1,59 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using static Thermo.Active.Model.Constants; + +namespace Thermo.Active.Model.DTOModels.ThProd +{ + public class DTOThermoPanelProd + { + public short NumTarget { get; set; } = 0; + public short NumDone { get; set; } = 0; + public DateTime InizioProd { get; set; } = DateTime.Now; + public double StimaDurata { get; set; } = 0; + public double TempAct { get; set; } = 0; + public double TempSetpoint { get; set; } = 0; + public string NomeRicetta { get; set; } = ""; + public double LastCadenza { get; set; } = 0; + public double LastTCiclo { get; set; } = 0; + public Dictionary TS_Cadenza { get; set; } = new Dictionary(); + public Dictionary TS_TCiclo { get; set; } = new Dictionary(); + + public override bool Equals(object obj) + { + if (!(obj is DTOThermoPanelProd item)) + return false; + + if (NumTarget != item.NumTarget) + return false; + if (NumDone != item.NumDone) + return false; + if (InizioProd != item.InizioProd) + return false; + if (StimaDurata != item.StimaDurata) + return false; + if (TempAct != item.TempAct) + return false; + if (TempSetpoint != item.TempSetpoint) + return false; + if (NomeRicetta != item.NomeRicetta) + return false; + if (LastCadenza != item.LastCadenza) + return false; + if (LastTCiclo != item.LastTCiclo) + return false; + if (!Enumerable.SequenceEqual(TS_Cadenza,item.TS_Cadenza)) + return false; + if (!Enumerable.SequenceEqual(TS_TCiclo, item.TS_TCiclo)) + return false; + + return true; + } + + public override int GetHashCode() + { + return base.GetHashCode(); + } + } + +} diff --git a/Thermo.Active.Model/Thermo.Active.Model.csproj b/Thermo.Active.Model/Thermo.Active.Model.csproj index 36c2ef50..5bb9344c 100644 --- a/Thermo.Active.Model/Thermo.Active.Model.csproj +++ b/Thermo.Active.Model/Thermo.Active.Model.csproj @@ -107,6 +107,7 @@ + @@ -169,9 +170,7 @@ CMS_CORE_Library - - - + diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index e8c90fdc..53e37114 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1252,6 +1252,97 @@ namespace Thermo.Active.NC return libraryError; } + public CmsError ReadProdPanel(out DTOThermoPanelProd currentProdPanel) + { + // preparo oggetti OUT + currentProdPanel = new DTOThermoPanelProd(); + Dictionary TS_Cad = new Dictionary(); + Dictionary TS_TC = new Dictionary(); + CmsError libraryError = NO_ERROR; + + // inizio da ncAdapter.lottoStart + currentProdPanel.InizioProd = lottoStart; + // dati ricetta da live + currentProdPanel.NomeRicetta = NcFileAdapter.RecipeLiveData.RecipeName; + // parto dai dati di lastProdInfoData... + if (lastProdInfoData != null) + { + currentProdPanel.NumDone = lastProdInfoData.NumDone; + currentProdPanel.NumTarget = lastProdInfoData.NumTarget; + currentProdPanel.LastTCiclo = lastProdInfoData.TimeCycleGross; + if (lastProdInfoData.TimeCycleGross > 0) + { + currentProdPanel.LastCadenza = (double)3600 / lastProdInfoData.TimeCycleGross; + } + // stima durata da pz fatti... + currentProdPanel.StimaDurata = (currentProdPanel.NumTarget - currentProdPanel.NumDone) * currentProdPanel.LastTCiclo; + } + + // dai parametri sistemo i setpoints + if (lastRecipe != null) + { + if (lastRecipe.ContainsKey("pyrometer_pyrometer_setpoint")) + { + currentProdPanel.TempAct = lastRecipe["pyrometer_pyrometer_setpoint"].ValueAct; + currentProdPanel.TempSetpoint = lastRecipe["pyrometer_pyrometer_setpoint"].SetpointPLC; + } + } + // dal DB recupero i dati dei TC storici... cablato a last 30 x ora... + if (currentProdPanel.NumDone > 0) + { + libraryError = GetHistProdInfoData(out List prodInfoDataList, currentProdPanel.NumDone, numRecProdPanelGraph); + // se ci sono dati --> creo le 2 TS! + if (prodInfoDataList != null) + { + foreach (var item in prodInfoDataList) + { + if (TS_TC.ContainsKey(item.NumDone)) + { + TS_TC[item.NumDone] = item.TimeCycleGross; + } + else + { + TS_TC.Add(item.NumDone, item.TimeCycleGross); + } + if (item.TimeCycleGross > 0) + { + if (TS_Cad.ContainsKey(item.NumDone)) + { + TS_Cad[item.NumDone] = 3600 / item.TimeCycleGross; + } + else + { + TS_Cad.Add(item.NumDone, 3600 / item.TimeCycleGross); + } + } + } + // accodo! + currentProdPanel.TS_Cadenza = TS_Cad; + currentProdPanel.TS_TCiclo = TS_TC; + } + // già che ci sono recupero prima record x prodStart... + libraryError = GetHistProdInfoData(out List prodInfoFirst, 1, 1); + // se ci sono dati --> fix start + if (prodInfoFirst != null) + { + try + { + currentProdPanel.InizioProd = prodInfoFirst.FirstOrDefault().DtEvent; + } + catch + { } + } + } + + + return libraryError; + } + + /// + /// Lettura dati ProdInfo + /// + /// + /// public CmsError ReadProdInfoData(out ThermoModels.ProdInfoModel prodInfoData) { prodInfoData = new ThermoModels.ProdInfoModel(); @@ -1338,6 +1429,7 @@ namespace Thermo.Active.NC // converto! prodInfoDataList = results.Select(x => new ThermoModels.ProdInfoModel() { + DtEvent = x.DtEvent, NumTarget = x.NumTarget, NumDone = x.NumDone, TimeWarm = x.TimeWarm, @@ -1382,6 +1474,11 @@ namespace Thermo.Active.NC return libraryError; } + /// + /// Get cycle prod data + /// + /// + /// public CmsError ReadProdCycleData(out ThermoModels.ProdCycleModel prodCycleData) { prodCycleData = new ThermoModels.ProdCycleModel(); @@ -1628,8 +1725,6 @@ namespace Thermo.Active.NC return NO_ERROR; } - - public CmsError ReadNcScada(ScadaSchemaModel scadaSchema, out DTOScadaModel scadaValue) { //ReadScadaDataSiemens(scadaSchema, out scadaValue); diff --git a/Thermo.Active/Controllers/WebApi/ProdController.cs b/Thermo.Active/Controllers/WebApi/ProdController.cs index f9a2619f..2d6f1cf7 100644 --- a/Thermo.Active/Controllers/WebApi/ProdController.cs +++ b/Thermo.Active/Controllers/WebApi/ProdController.cs @@ -131,7 +131,7 @@ namespace Thermo.Active.Controllers.WebApi /// Request production current data /// /// - [Route("get"), HttpPut] + [Route("get"), HttpGet] public IHttpActionResult GetProd() { // Try connection @@ -157,7 +157,7 @@ namespace Thermo.Active.Controllers.WebApi /// Request gauges current data /// /// - [Route("gauges"), HttpPut] + [Route("gauges"), HttpGet] public IHttpActionResult GetGauges() { // Try connection @@ -168,7 +168,7 @@ namespace Thermo.Active.Controllers.WebApi return BadRequest(libraryError.localizationKey); } - // scrivo sul PLC il comando strobe richiesta AUTO! + // leggo dati gauges libraryError = ncAdapter.ReadGaugeData(out Dictionary currentLiveProd); if (libraryError.IsError()) { @@ -183,7 +183,7 @@ namespace Thermo.Active.Controllers.WebApi /// Request production data from indexStart record for numRecord items (DESCENDING) /// /// - [Route("history"), HttpPut] + [Route("history"), HttpGet] public IHttpActionResult GetHistory(int indexStart, int numRecord) { // Try connection @@ -194,7 +194,7 @@ namespace Thermo.Active.Controllers.WebApi return BadRequest(libraryError.localizationKey); } - // scrivo sul PLC il comando strobe richiesta AUTO! + // recupero da DB i record richiesti libraryError = ncAdapter.GetHistProdInfoData(out List prodInfoDataList, indexStart, numRecord); if (libraryError.IsError()) { @@ -205,5 +205,31 @@ namespace Thermo.Active.Controllers.WebApi // ritorno solo fatto! return Ok(prodInfoDataList); } + /// + /// Request Prod Panel data + /// + /// + [Route("prodPanel"), HttpGet] + public IHttpActionResult GetProdPanel() + { + // Try connection + CmsError libraryError = ncAdapter.Connect(); + if (libraryError.IsError()) + { + ThermoActiveLogger.LogError($"NC Not connected! | GetProdPanel | {libraryError.exception}"); + return BadRequest(libraryError.localizationKey); + } + + // recupero dati produzione + libraryError = ncAdapter.ReadProdPanel(out DTOThermoPanelProd currentProdPanel); + if (libraryError.IsError()) + { + ThermoActiveLogger.LogError($"GetProdPanel error | {libraryError.exception}"); + return BadRequest(libraryError.localizationKey); + } + + // ritorno solo fatto! + return Ok(currentProdPanel); + } } } \ No newline at end of file diff --git a/Thermo.Active/Properties/AssemblyInfo.cs b/Thermo.Active/Properties/AssemblyInfo.cs index 05927901..fee85b14 100644 --- a/Thermo.Active/Properties/AssemblyInfo.cs +++ b/Thermo.Active/Properties/AssemblyInfo.cs @@ -30,4 +30,4 @@ using System.Runtime.InteropServices; // // You can specify all the values or you can default the Revision and Build Numbers // by using the '*' as shown below: -[assembly: AssemblyVersion("0.9.29")] +[assembly: AssemblyVersion("0.9.31")]