From 5e5c9b70c53f16880bd33e41b96e68da94a03a21 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 10 Jul 2020 18:01:52 +0200 Subject: [PATCH 1/6] Inizio mod x dati decimal in prod (s e non ms) --- .../DTOModels/ThProd/DTOProdInfo.cs | 71 +++++++++++++++++++ Thermo.Active.NC/NcAdapter.cs | 16 ++--- .../Controllers/WebApi/ProdController.cs | 2 +- 3 files changed, 80 insertions(+), 9 deletions(-) create mode 100644 Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs diff --git a/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs b/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs new file mode 100644 index 00000000..7f20e9fe --- /dev/null +++ b/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Thermo.Active.Model.DTOModels.ThProd +{ + public class DTOProdInfo + { + public DateTime DtEvent { get; set; } + public short NumTarget { get; set; } = 0; + public short NumDone { get; set; } = 0; + public double TimeWarm { get; set; } = 0; + public double TimeVent { get; set; } = 0; + public double TimeVacuum { get; set; } = 0; + public double TimeCycleGross { get; set; } = 0; + public double TimeCycleNet { get; set; } = 0; + public int NumDec { get; set; } = 1; + public int ScaleFactor { get; set; } = 1000; + public double MaterialTempEndWarm { get; set; } = 0; + public double MaterialTempEndVent { get; set; } = 0; + public double MoldTemp { get; set; } = 0; + public double VacuumReadVal { get; set; } = 0; + public double MouldEnergyOUT { get; set; } = 0; + public double MouldEnergyIN { get; set; } = 0; + + public override bool Equals(object obj) + { + // Object is not a GaugeModel instance + if (!(obj is DTOProdInfo item)) + return false; + + if (DtEvent != item.DtEvent) + return false; + if (NumTarget != item.NumTarget) + return false; + if (NumDone != item.NumDone) + return false; + if (TimeWarm != item.TimeWarm) + return false; + if (TimeVent != item.TimeVent) + return false; + if (TimeVacuum != item.TimeVacuum) + return false; + if (TimeCycleGross != item.TimeCycleGross) + return false; + if (TimeCycleNet != item.TimeCycleNet) + return false; + if (MaterialTempEndWarm != item.MaterialTempEndWarm) + return false; + if (MaterialTempEndVent != item.MaterialTempEndVent) + return false; + if (MoldTemp != item.MoldTemp) + return false; + if (VacuumReadVal != item.VacuumReadVal) + return false; + if (MouldEnergyOUT != item.MouldEnergyOUT) + return false; + if (MouldEnergyIN != item.MouldEnergyIN) + return false; + + return true; + } + public override int GetHashCode() + { + return base.GetHashCode(); + } + + } +} diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index b43f142a..831e4e68 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1404,29 +1404,29 @@ namespace Thermo.Active.NC /// /// /// - public CmsError ReadProdInfoData(out ThermoModels.ProdInfoModel prodInfoData) + public CmsError ReadProdInfoData(out DTOProdInfo prodInfoData) { - prodInfoData = new ThermoModels.ProdInfoModel(); - CmsError libraryError = numericalControl.PLC_RProdInfo(ref prodInfoData); + ThermoModels.ProdInfoModel prodInfoRawData = new ThermoModels.ProdInfoModel(); + CmsError libraryError = numericalControl.PLC_RProdInfo(ref prodInfoRawData); if (libraryError.IsError()) return libraryError; // if lastProdInfo is missing --> populate! if (lastProdInfoData == null) - lastProdInfoData = prodInfoData; + lastProdInfoData = prodInfoRawData; // se ho update, sennò restituisco ultima lettura... if (ThermoProdUpdatedStr) { // do comparison with old record and if changed --> persist on DB! - if (!prodInfoData.Equals(lastProdInfoData)) + if (!prodInfoRawData.Equals(lastProdInfoData)) { // save on DB! using (ProdInfoController prodInfoController = new ProdInfoController()) - prodInfoController.Create(prodInfoData.NumTarget, prodInfoData.NumDone, prodInfoData.TimeWarm, prodInfoData.TimeVent, prodInfoData.TimeVacuum, prodInfoData.TimeCycleGross, prodInfoData.TimeCycleNet, prodInfoData.MaterialTempEndWarm, prodInfoData.MaterialTempEndVent, prodInfoData.MoldTemp, prodInfoData.VacuumReadVal, prodInfoData.MouldEnergyOUT, prodInfoData.MouldEnergyIN); + prodInfoController.Create(prodInfoRawData.NumTarget, prodInfoRawData.NumDone, prodInfoRawData.TimeWarm, prodInfoRawData.TimeVent, prodInfoRawData.TimeVacuum, prodInfoRawData.TimeCycleGross, prodInfoRawData.TimeCycleNet, prodInfoRawData.MaterialTempEndWarm, prodInfoRawData.MaterialTempEndVent, prodInfoRawData.MoldTemp, prodInfoRawData.VacuumReadVal, prodInfoRawData.MouldEnergyOUT, prodInfoRawData.MouldEnergyIN); // update last info data - lastProdInfoData = prodInfoData; + lastProdInfoData = prodInfoRawData; // manage strobe/ack! libraryError = numericalControl.PLC_WAckProdUpdate(); @@ -1436,7 +1436,7 @@ namespace Thermo.Active.NC } else { - prodInfoData = lastProdInfoData; + prodInfoRawData = lastProdInfoData; } // ora controllo inizio/fine produzione diff --git a/Thermo.Active/Controllers/WebApi/ProdController.cs b/Thermo.Active/Controllers/WebApi/ProdController.cs index 2d6f1cf7..81f28f97 100644 --- a/Thermo.Active/Controllers/WebApi/ProdController.cs +++ b/Thermo.Active/Controllers/WebApi/ProdController.cs @@ -143,7 +143,7 @@ namespace Thermo.Active.Controllers.WebApi } // scrivo sul PLC il comando strobe richiesta AUTO! - libraryError = ncAdapter.ReadProdInfoData(out ThermoModels.ProdInfoModel prodInfoDat); + libraryError = ncAdapter.ReadProdInfoData(out DTOProdInfo prodInfoDat); if (libraryError.IsError()) { ThermoActiveLogger.LogError($"GetProd error | {libraryError.exception}"); From 6ccb5682c1f18f11fb562fa37fa20599ced91735 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 10 Jul 2020 18:33:20 +0200 Subject: [PATCH 2/6] Fix gestione TempiCiclo in sec! --- Thermo.Active.Core/ThreadsFunctions.cs | 2 +- .../DTOModels/ThProd/DTOProdInfo.cs | 140 ++++++++++-------- .../Thermo.Active.Model.csproj | 1 + Thermo.Active.NC/NcAdapter.cs | 20 ++- .../Listeners/SignalR/SignalRListener.cs | 2 +- .../Listeners/SignalRStaticObjects.cs | 4 +- Thermo.Active/Properties/AssemblyInfo.cs | 2 +- 7 files changed, 98 insertions(+), 73 deletions(-) diff --git a/Thermo.Active.Core/ThreadsFunctions.cs b/Thermo.Active.Core/ThreadsFunctions.cs index 3a4281d8..5b097c2a 100644 --- a/Thermo.Active.Core/ThreadsFunctions.cs +++ b/Thermo.Active.Core/ThreadsFunctions.cs @@ -732,7 +732,7 @@ public static class ThreadsFunctions if (ncAdapter.numericalControl.NC_IsConnected()) { // Get new data from PLC (and log if changed...) - libraryError = ncAdapter.ReadProdInfoData(out ThermoModels.ProdInfoModel prodInfoData); + libraryError = ncAdapter.ReadProdInfoData(out DTOProdInfo prodInfoData); if (libraryError.IsError()) ManageLibraryError(libraryError); diff --git a/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs b/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs index 7f20e9fe..b8949bc0 100644 --- a/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs +++ b/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs @@ -1,4 +1,5 @@ -using System; +using CMS_CORE_Library.Models; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -6,66 +7,87 @@ using System.Threading.Tasks; namespace Thermo.Active.Model.DTOModels.ThProd { - public class DTOProdInfo + public class DTOProdInfo + { + public DateTime DtEvent { get; set; } + public short NumTarget { get; set; } = 0; + public short NumDone { get; set; } = 0; + public double TimeWarm { get; set; } = 0; + public double TimeVent { get; set; } = 0; + public double TimeVacuum { get; set; } = 0; + public double TimeCycleGross { get; set; } = 0; + public double TimeCycleNet { get; set; } = 0; + public int NumDec { get; set; } = 1; + public int ScaleFactor { get; set; } = 1000; + public double MaterialTempEndWarm { get; set; } = 0; + public double MaterialTempEndVent { get; set; } = 0; + public double MoldTemp { get; set; } = 0; + public double VacuumReadVal { get; set; } = 0; + public double MouldEnergyOUT { get; set; } = 0; + public double MouldEnergyIN { get; set; } = 0; + + public override bool Equals(object obj) { - public DateTime DtEvent { get; set; } - public short NumTarget { get; set; } = 0; - public short NumDone { get; set; } = 0; - public double TimeWarm { get; set; } = 0; - public double TimeVent { get; set; } = 0; - public double TimeVacuum { get; set; } = 0; - public double TimeCycleGross { get; set; } = 0; - public double TimeCycleNet { get; set; } = 0; - public int NumDec { get; set; } = 1; - public int ScaleFactor { get; set; } = 1000; - public double MaterialTempEndWarm { get; set; } = 0; - public double MaterialTempEndVent { get; set; } = 0; - public double MoldTemp { get; set; } = 0; - public double VacuumReadVal { get; set; } = 0; - public double MouldEnergyOUT { get; set; } = 0; - public double MouldEnergyIN { get; set; } = 0; + // Object is not a GaugeModel instance + if (!(obj is DTOProdInfo item)) + return false; - public override bool Equals(object obj) - { - // Object is not a GaugeModel instance - if (!(obj is DTOProdInfo item)) - return false; - - if (DtEvent != item.DtEvent) - return false; - if (NumTarget != item.NumTarget) - return false; - if (NumDone != item.NumDone) - return false; - if (TimeWarm != item.TimeWarm) - return false; - if (TimeVent != item.TimeVent) - return false; - if (TimeVacuum != item.TimeVacuum) - return false; - if (TimeCycleGross != item.TimeCycleGross) - return false; - if (TimeCycleNet != item.TimeCycleNet) - return false; - if (MaterialTempEndWarm != item.MaterialTempEndWarm) - return false; - if (MaterialTempEndVent != item.MaterialTempEndVent) - return false; - if (MoldTemp != item.MoldTemp) - return false; - if (VacuumReadVal != item.VacuumReadVal) - return false; - if (MouldEnergyOUT != item.MouldEnergyOUT) - return false; - if (MouldEnergyIN != item.MouldEnergyIN) - return false; - - return true; - } - public override int GetHashCode() - { - return base.GetHashCode(); - } + if (DtEvent != item.DtEvent) + return false; + if (NumTarget != item.NumTarget) + return false; + if (NumDone != item.NumDone) + return false; + if (TimeWarm != item.TimeWarm) + return false; + if (TimeVent != item.TimeVent) + return false; + if (TimeVacuum != item.TimeVacuum) + return false; + if (TimeCycleGross != item.TimeCycleGross) + return false; + if (TimeCycleNet != item.TimeCycleNet) + return false; + if (MaterialTempEndWarm != item.MaterialTempEndWarm) + return false; + if (MaterialTempEndVent != item.MaterialTempEndVent) + return false; + if (MoldTemp != item.MoldTemp) + return false; + if (VacuumReadVal != item.VacuumReadVal) + return false; + if (MouldEnergyOUT != item.MouldEnergyOUT) + return false; + if (MouldEnergyIN != item.MouldEnergyIN) + return false; + return true; } + public override int GetHashCode() + { + return base.GetHashCode(); + } + + public DTOProdInfo() + { + } + + public DTOProdInfo(ThermoModels.ProdInfoModel pimRawData) + { + this.DtEvent = pimRawData.DtEvent; + this.NumDone = pimRawData.NumDone; + this.NumTarget = pimRawData.NumTarget; + this.TimeCycleGross = (double)pimRawData.TimeCycleGross / this.ScaleFactor; + this.TimeCycleNet = (double)pimRawData.TimeCycleNet / this.ScaleFactor; + this.TimeVacuum = (double)pimRawData.TimeVacuum / this.ScaleFactor; + this.TimeVent = (double)pimRawData.TimeVent / this.ScaleFactor; + this.TimeWarm = (double)pimRawData.TimeWarm / this.ScaleFactor; + this.MaterialTempEndWarm = pimRawData.MaterialTempEndWarm; + this.MaterialTempEndVent = pimRawData.MaterialTempEndVent; + this.MoldTemp = pimRawData.MoldTemp; + this.VacuumReadVal = pimRawData.VacuumReadVal; + this.MouldEnergyIN = pimRawData.MouldEnergyIN; + this.MouldEnergyOUT = pimRawData.MouldEnergyOUT; + } + } } diff --git a/Thermo.Active.Model/Thermo.Active.Model.csproj b/Thermo.Active.Model/Thermo.Active.Model.csproj index 5bb9344c..85350ec6 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.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 831e4e68..c1054b75 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1296,10 +1296,10 @@ namespace Thermo.Active.NC { currentProdPanel.NumDone = lastProdInfoData.NumDone; currentProdPanel.NumTarget = lastProdInfoData.NumTarget; - currentProdPanel.LastTCiclo = lastProdInfoData.TimeCycleGross; + currentProdPanel.LastTCiclo = (double)lastProdInfoData.TimeCycleGross/1000; if (lastProdInfoData.TimeCycleGross > 0) { - currentProdPanel.LastCadenza = (double)3600 / lastProdInfoData.TimeCycleGross; + currentProdPanel.LastCadenza = (double)3600000 / lastProdInfoData.TimeCycleGross; } // stima durata da pz fatti... currentProdPanel.StimaDurata = (currentProdPanel.NumTarget - currentProdPanel.NumDone) * currentProdPanel.LastTCiclo; @@ -1324,21 +1324,21 @@ namespace Thermo.Active.NC { if (TS_TC.ContainsKey(item.NumDone)) { - TS_TC[item.NumDone] = item.TimeCycleGross; + TS_TC[item.NumDone] = (double)item.TimeCycleGross/1000; } else { - TS_TC.Add(item.NumDone, item.TimeCycleGross); + TS_TC.Add(item.NumDone, (double)item.TimeCycleGross/1000); } if (item.TimeCycleGross > 0) { if (TS_Cad.ContainsKey(item.NumDone)) { - TS_Cad[item.NumDone] = 3600 / item.TimeCycleGross; + TS_Cad[item.NumDone] = (double)3600000 / item.TimeCycleGross; } else { - TS_Cad.Add(item.NumDone, 3600 / item.TimeCycleGross); + TS_Cad.Add(item.NumDone, (double)3600000 / item.TimeCycleGross); } numTcOk++; } @@ -1362,11 +1362,11 @@ namespace Thermo.Active.NC TS_TC[numPz] = TCMedio + (rand.NextDouble() * 4 - 2); if (TS_Cad.ContainsKey(numPz)) { - TS_Cad[numPz] = 3600 / TS_TC[numPz]; + TS_Cad[numPz] = (double)3600 / TS_TC[numPz]; } else { - TS_Cad.Add(numPz, 3600 / TS_TC[numPz]); + TS_Cad.Add(numPz, (double)3600 / TS_TC[numPz]); } } } @@ -1406,11 +1406,15 @@ namespace Thermo.Active.NC /// public CmsError ReadProdInfoData(out DTOProdInfo prodInfoData) { + prodInfoData = new DTOProdInfo(); ThermoModels.ProdInfoModel prodInfoRawData = new ThermoModels.ProdInfoModel(); CmsError libraryError = numericalControl.PLC_RProdInfo(ref prodInfoRawData); if (libraryError.IsError()) return libraryError; + // converto 1:1 dati da ThermoModels.ProdInfoModel --> DTOProdInfo + prodInfoData = new DTOProdInfo(prodInfoRawData); + // if lastProdInfo is missing --> populate! if (lastProdInfoData == null) lastProdInfoData = prodInfoRawData; diff --git a/Thermo.Active/Listeners/SignalR/SignalRListener.cs b/Thermo.Active/Listeners/SignalR/SignalRListener.cs index 2614409e..86dbb1f7 100644 --- a/Thermo.Active/Listeners/SignalR/SignalRListener.cs +++ b/Thermo.Active/Listeners/SignalR/SignalRListener.cs @@ -430,7 +430,7 @@ namespace Thermo.Active.Listeners.SignalR } public static void SendThermoProdInfoData(object prodInfoData) { - ProdInfoModel currProdInfo = prodInfoData as ProdInfoModel; + DTOProdInfo currProdInfo = prodInfoData as DTOProdInfo; if (!LastProdInfoData.Equals(currProdInfo)) { diff --git a/Thermo.Active/Listeners/SignalRStaticObjects.cs b/Thermo.Active/Listeners/SignalRStaticObjects.cs index 7f5f9987..a34ab879 100644 --- a/Thermo.Active/Listeners/SignalRStaticObjects.cs +++ b/Thermo.Active/Listeners/SignalRStaticObjects.cs @@ -38,11 +38,9 @@ namespace Thermo.Active.Listeners public static Dictionary LastAreaData = new Dictionary(); public static Dictionary LastLiveProdData = new Dictionary(); public static ThermoModels.ProdCycleModel LastProdCycleData = new ThermoModels.ProdCycleModel(); - public static ThermoModels.ProdInfoModel LastProdInfoData = new ThermoModels.ProdInfoModel(); + public static DTOProdInfo LastProdInfoData = new DTOProdInfo(); public static DTOThermoPanelProd LastProdPanelData = new DTOThermoPanelProd(); - public static bool LastIsNcConnected = false; - } } \ No newline at end of file diff --git a/Thermo.Active/Properties/AssemblyInfo.cs b/Thermo.Active/Properties/AssemblyInfo.cs index 6832e260..bb57b0f6 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.34")] \ No newline at end of file +[assembly: AssemblyVersion("0.9.35")] \ No newline at end of file From 6c64825fa29303fa1b24d8f1c48a09d84292a145 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Fri, 10 Jul 2020 20:15:16 +0200 Subject: [PATCH 3/6] Fix decimali + SIM debug variaz tempo(+/- 10s) --- .../DTOModels/ThProd/DTOProdInfo.cs | 10 ++-- Thermo.Active.NC/NcAdapter.cs | 56 +++++++++---------- 2 files changed, 31 insertions(+), 35 deletions(-) diff --git a/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs b/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs index b8949bc0..a8ac886a 100644 --- a/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs +++ b/Thermo.Active.Model/DTOModels/ThProd/DTOProdInfo.cs @@ -77,11 +77,11 @@ namespace Thermo.Active.Model.DTOModels.ThProd this.DtEvent = pimRawData.DtEvent; this.NumDone = pimRawData.NumDone; this.NumTarget = pimRawData.NumTarget; - this.TimeCycleGross = (double)pimRawData.TimeCycleGross / this.ScaleFactor; - this.TimeCycleNet = (double)pimRawData.TimeCycleNet / this.ScaleFactor; - this.TimeVacuum = (double)pimRawData.TimeVacuum / this.ScaleFactor; - this.TimeVent = (double)pimRawData.TimeVent / this.ScaleFactor; - this.TimeWarm = (double)pimRawData.TimeWarm / this.ScaleFactor; + this.TimeCycleGross = Math.Round((double)pimRawData.TimeCycleGross / this.ScaleFactor, 2); + this.TimeCycleNet = Math.Round((double)pimRawData.TimeCycleNet / this.ScaleFactor, 2); + this.TimeVacuum = Math.Round((double)pimRawData.TimeVacuum / this.ScaleFactor, 2); + this.TimeVent = Math.Round((double)pimRawData.TimeVent / this.ScaleFactor, 2); + this.TimeWarm = Math.Round((double)pimRawData.TimeWarm / this.ScaleFactor, 2); this.MaterialTempEndWarm = pimRawData.MaterialTempEndWarm; this.MaterialTempEndVent = pimRawData.MaterialTempEndVent; this.MoldTemp = pimRawData.MoldTemp; diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index c1054b75..534dffc5 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1296,13 +1296,13 @@ namespace Thermo.Active.NC { currentProdPanel.NumDone = lastProdInfoData.NumDone; currentProdPanel.NumTarget = lastProdInfoData.NumTarget; - currentProdPanel.LastTCiclo = (double)lastProdInfoData.TimeCycleGross/1000; + currentProdPanel.LastTCiclo = Math.Round((double)lastProdInfoData.TimeCycleGross / 1000, 2); if (lastProdInfoData.TimeCycleGross > 0) { - currentProdPanel.LastCadenza = (double)3600000 / lastProdInfoData.TimeCycleGross; + currentProdPanel.LastCadenza = Math.Round((double)3600000 / lastProdInfoData.TimeCycleGross, 2); } // stima durata da pz fatti... - currentProdPanel.StimaDurata = (currentProdPanel.NumTarget - currentProdPanel.NumDone) * currentProdPanel.LastTCiclo; + currentProdPanel.StimaDurata = Math.Round((currentProdPanel.NumTarget - currentProdPanel.NumDone) * currentProdPanel.LastTCiclo, 2); } // dai parametri sistemo i setpoints if (lastRecipe != null) @@ -1324,52 +1324,48 @@ namespace Thermo.Active.NC { if (TS_TC.ContainsKey(item.NumDone)) { - TS_TC[item.NumDone] = (double)item.TimeCycleGross/1000; + TS_TC[item.NumDone] = Math.Round((double)item.TimeCycleGross / 1000, 2); } else { - TS_TC.Add(item.NumDone, (double)item.TimeCycleGross/1000); + TS_TC.Add(item.NumDone, Math.Round((double)item.TimeCycleGross / 1000, 2)); } if (item.TimeCycleGross > 0) { if (TS_Cad.ContainsKey(item.NumDone)) { - TS_Cad[item.NumDone] = (double)3600000 / item.TimeCycleGross; + TS_Cad[item.NumDone] = Math.Round((double)3600000 / item.TimeCycleGross, 2); } else { - TS_Cad.Add(item.NumDone, (double)3600000 / item.TimeCycleGross); + TS_Cad.Add(item.NumDone, Math.Round((double)3600000 / item.TimeCycleGross, 2)); } numTcOk++; } } - // FIXME TODO: da levare post test... SE i TC sono zero (almeno 5)--> SIMULO - if (numTcOk == 0 || (numRecProdPanelGraph - numTcOk) > 5) +#if DEBUG + + // creo una perturubazione... + var rand = new Random(); + Dictionary origTcData = new Dictionary(); + foreach (var item2fix in TS_TC) { - // calcolo primo/ultimo e divido... - DateTime fine = prodInfoDataList[0].DtEvent; - DateTime inizio = prodInfoDataList[prodInfoDataList.Count - 1].DtEvent; - double TCMedio = Math.Abs(fine.Subtract(inizio).TotalSeconds / prodInfoDataList.Count); - // simulo - var rand = new Random(); - List numList = new List(); - foreach (var item2fix in TS_TC) + origTcData.Add(item2fix.Key, item2fix.Value); + } + foreach (var origVal in origTcData) + { + TS_TC[origVal.Key] = Math.Round(origVal.Value + (rand.NextDouble() * 20 - 10), 2); + if (TS_Cad.ContainsKey(origVal.Key)) { - numList.Add(item2fix.Key); + TS_Cad[origVal.Key] = Math.Round((double)3600 / TS_TC[origVal.Key], 2); } - foreach (var numPz in numList) + else { - TS_TC[numPz] = TCMedio + (rand.NextDouble() * 4 - 2); - if (TS_Cad.ContainsKey(numPz)) - { - TS_Cad[numPz] = (double)3600 / TS_TC[numPz]; - } - else - { - TS_Cad.Add(numPz, (double)3600 / TS_TC[numPz]); - } + TS_Cad.Add(origVal.Key, Math.Round((double)3600 / TS_TC[origVal.Key], 2)); } } + +#endif // accodo! currentProdPanel.TS_Cadenza = TS_Cad; currentProdPanel.TS_TCiclo = TS_TC; @@ -1419,8 +1415,8 @@ namespace Thermo.Active.NC if (lastProdInfoData == null) lastProdInfoData = prodInfoRawData; - // se ho update, sennò restituisco ultima lettura... - if (ThermoProdUpdatedStr) + // se ho update OPPURE differenza di lettura..., sennò restituisco ultima lettura... + if (ThermoProdUpdatedStr || (lastProdInfoData.NumDone != prodInfoRawData.NumDone)) { // do comparison with old record and if changed --> persist on DB! if (!prodInfoRawData.Equals(lastProdInfoData)) From cb586e3fb491158781f99de3f6848339c07c7550 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 11 Jul 2020 10:19:51 +0200 Subject: [PATCH 4/6] start new release --- Thermo.Active/Properties/AssemblyInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Thermo.Active/Properties/AssemblyInfo.cs b/Thermo.Active/Properties/AssemblyInfo.cs index bb57b0f6..ec2cfffb 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.35")] \ No newline at end of file +[assembly: AssemblyVersion("0.9.36")] \ No newline at end of file From ddd989223d52f42d14ccc7163ffb1d8ecf9219b9 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 11 Jul 2020 10:20:25 +0200 Subject: [PATCH 5/6] Recipe serialization: DONE with formatting --- Thermo.Active.NC/NcFileAdapter.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Thermo.Active.NC/NcFileAdapter.cs b/Thermo.Active.NC/NcFileAdapter.cs index 6730692f..233332a8 100644 --- a/Thermo.Active.NC/NcFileAdapter.cs +++ b/Thermo.Active.NC/NcFileAdapter.cs @@ -764,7 +764,7 @@ namespace Thermo.Active.NC { answ = true; // serialize - string rawData = JsonConvert.SerializeObject(RecipeLiveData); + string rawData = JsonConvert.SerializeObject(RecipeLiveData, Newtonsoft.Json.Formatting.Indented); // save live! var dir = Path.GetDirectoryName(LIVE_RECIPE_PATH); if (!Directory.Exists(dir)) @@ -848,7 +848,7 @@ namespace Thermo.Active.NC // fix name! currRecipe.RecipeName = fileName; // serialize - string rawData = JsonConvert.SerializeObject(currRecipe); + string rawData = JsonConvert.SerializeObject(currRecipe, Newtonsoft.Json.Formatting.Indented); // save live! File.WriteAllText(LIVE_RECIPE_PATH, rawData); // verifica path From 04457841c1079991a7110e3179068861b0a582f6 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Sat, 11 Jul 2020 10:20:43 +0200 Subject: [PATCH 6/6] Annotation for saving recipe with user data --- .../Controllers/WebApi/RecipeController.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index afe21404..9bb8d6e2 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -2,18 +2,22 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net; using System.Net.Http; +using System.Security.Claims; using System.Threading.Tasks; using System.Web; using System.Web.Http; using Thermo.Active.Config; +using Thermo.Active.Database.Controllers; using Thermo.Active.Model.DTOModels.ThRecipe; using Thermo.Active.Model.DTOModels.ThWarmers; using Thermo.Active.NC; using Thermo.Active.Utils; using static CMS_CORE_Library.Models.DataStructures; using static Thermo.Active.Config.ServerConfig; +using static Thermo.Active.Model.Constants; namespace Thermo.Active.Controllers.WebApi { @@ -309,8 +313,25 @@ namespace Thermo.Active.Controllers.WebApi /// /// [Route("save"), HttpPut] + //[WebApiAuthorize(FunctionAccess = FUNCTIONALITY_NAMES.USER_FUNCTIONS, Action = ACTIONS.READ)] public IHttpActionResult Save() { +#if false + // recupero dati utente loggato + var identity = User.Identity as ClaimsIdentity; + // Find user id from the bearer token + var userId = identity.Claims.FirstOrDefault(c => c.Type == USER_ID_KEY); + if (userId == null) + return Unauthorized(); + + using (UsersController usersController = new UsersController()) + { + var userData = usersController.GetUserInfo(Convert.ToInt32(userId.Value)); + } +#endif + + + // recupero i dati LIVE dei parametri HMI della ricetta... CmsError libraryError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); if (libraryError.IsError())