From ada9a7ae55463bff48265c3828abab0a57c83be5 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 9 Jul 2020 16:45:56 +0200 Subject: [PATCH 1/3] Aggiunta modello dati pannello produzione --- .../DTOModels/ThProd/DTOThermoPanelProd.cs | 55 +++++++++++++++++++ .../Thermo.Active.Model.csproj | 1 + Thermo.Active/Properties/AssemblyInfo.cs | 2 +- 3 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 Thermo.Active.Model/DTOModels/ThProd/DTOThermoPanelProd.cs diff --git a/Thermo.Active.Model/DTOModels/ThProd/DTOThermoPanelProd.cs b/Thermo.Active.Model/DTOModels/ThProd/DTOThermoPanelProd.cs new file mode 100644 index 00000000..597e11a9 --- /dev/null +++ b/Thermo.Active.Model/DTOModels/ThProd/DTOThermoPanelProd.cs @@ -0,0 +1,55 @@ +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 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 (!Category.Equals(item.Category)) + // 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..d6a30a9a 100644 --- a/Thermo.Active.Model/Thermo.Active.Model.csproj +++ b/Thermo.Active.Model/Thermo.Active.Model.csproj @@ -107,6 +107,7 @@ + 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")] From d7ca3e056327141144500464c7da4b2ea28303c8 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 9 Jul 2020 17:26:17 +0200 Subject: [PATCH 2/3] First version of prod panel data... --- .../DTOModels/ThProd/DTOThermoPanelProd.cs | 10 ++-- .../Thermo.Active.Model.csproj | 4 +- Thermo.Active.NC/NcAdapter.cs | 52 ++++++++++++++++++- .../Controllers/WebApi/ProdController.cs | 34 ++++++++++-- 4 files changed, 88 insertions(+), 12 deletions(-) diff --git a/Thermo.Active.Model/DTOModels/ThProd/DTOThermoPanelProd.cs b/Thermo.Active.Model/DTOModels/ThProd/DTOThermoPanelProd.cs index 597e11a9..db565b97 100644 --- a/Thermo.Active.Model/DTOModels/ThProd/DTOThermoPanelProd.cs +++ b/Thermo.Active.Model/DTOModels/ThProd/DTOThermoPanelProd.cs @@ -7,6 +7,8 @@ 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; @@ -22,9 +24,11 @@ namespace Thermo.Active.Model.DTOModels.ThProd if (!(obj is DTOThermoPanelProd item)) return false; - //if (!Category.Equals(item.Category)) - // return false; - if (InizioProd!= item.InizioProd) + if (NumTarget != item.NumTarget) + return false; + if (NumDone != item.NumDone) + return false; + if (InizioProd != item.InizioProd) return false; if (StimaDurata != item.StimaDurata) return false; diff --git a/Thermo.Active.Model/Thermo.Active.Model.csproj b/Thermo.Active.Model/Thermo.Active.Model.csproj index d6a30a9a..5bb9344c 100644 --- a/Thermo.Active.Model/Thermo.Active.Model.csproj +++ b/Thermo.Active.Model/Thermo.Active.Model.csproj @@ -170,9 +170,7 @@ CMS_CORE_Library - - - + diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index e8c90fdc..aff637b2 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1252,6 +1252,51 @@ namespace Thermo.Active.NC return libraryError; } + public CmsError ReadProdPanel(out DTOThermoPanelProd currentProdPanel) + { + // preparo oggetti OUT + currentProdPanel = new DTOThermoPanelProd(); + 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... + + + + return libraryError; + } + + /// + /// Lettura dati ProdInfo + /// + /// + /// public CmsError ReadProdInfoData(out ThermoModels.ProdInfoModel prodInfoData) { prodInfoData = new ThermoModels.ProdInfoModel(); @@ -1382,6 +1427,11 @@ namespace Thermo.Active.NC return libraryError; } + /// + /// Get cycle prod data + /// + /// + /// public CmsError ReadProdCycleData(out ThermoModels.ProdCycleModel prodCycleData) { prodCycleData = new ThermoModels.ProdCycleModel(); @@ -1628,8 +1678,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..89da31a0 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 @@ -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 From bf3084b376e3dea9e4e188b2d4bb5413481f6c95 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Thu, 9 Jul 2020 17:53:11 +0200 Subject: [PATCH 3/3] Completed review of WebAPI method for prodPanel --- Thermo.Active.Model/Constants.cs | 2 + Thermo.Active.NC/NcAdapter.cs | 53 +++++++++++++++++-- .../Controllers/WebApi/ProdController.cs | 2 +- 3 files changed, 53 insertions(+), 4 deletions(-) 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.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index aff637b2..53e37114 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1256,6 +1256,8 @@ namespace Thermo.Active.NC { // preparo oggetti OUT currentProdPanel = new DTOThermoPanelProd(); + Dictionary TS_Cad = new Dictionary(); + Dictionary TS_TC = new Dictionary(); CmsError libraryError = NO_ERROR; // inizio da ncAdapter.lottoStart @@ -1277,7 +1279,7 @@ namespace Thermo.Active.NC } // dai parametri sistemo i setpoints - if(lastRecipe!=null) + if (lastRecipe != null) { if (lastRecipe.ContainsKey("pyrometer_pyrometer_setpoint")) { @@ -1285,8 +1287,52 @@ namespace Thermo.Active.NC currentProdPanel.TempSetpoint = lastRecipe["pyrometer_pyrometer_setpoint"].SetpointPLC; } } - // dal DB recupero i dati dei TC storici... - + // 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; @@ -1383,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, diff --git a/Thermo.Active/Controllers/WebApi/ProdController.cs b/Thermo.Active/Controllers/WebApi/ProdController.cs index 89da31a0..2d6f1cf7 100644 --- a/Thermo.Active/Controllers/WebApi/ProdController.cs +++ b/Thermo.Active/Controllers/WebApi/ProdController.cs @@ -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()) {