From 233d51d62cafa45b90cdf21b715a1ee19fe5a40c Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 13 Jul 2020 10:32:02 +0200 Subject: [PATCH 1/6] Fix LiveData x salvataggio dati ricetta --- Thermo.Active.Model/DTOModels/ThRecipe/LiveData.cs | 8 ++++++++ Thermo.Active.NC/NcAdapter.cs | 6 ++++++ Thermo.Active.NC/NcFileAdapter.cs | 4 ---- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/Thermo.Active.Model/DTOModels/ThRecipe/LiveData.cs b/Thermo.Active.Model/DTOModels/ThRecipe/LiveData.cs index 3cef6db1..74947f35 100644 --- a/Thermo.Active.Model/DTOModels/ThRecipe/LiveData.cs +++ b/Thermo.Active.Model/DTOModels/ThRecipe/LiveData.cs @@ -12,6 +12,10 @@ namespace Thermo.Active.Model.DTOModels.ThRecipe /// public string RecipeName = "current.json"; /// + /// User that made last save + /// + public string UserSave = ""; + /// /// Dictionary of all parameters and values /// public Dictionary RecipeParameters; @@ -23,6 +27,10 @@ namespace Thermo.Active.Model.DTOModels.ThRecipe /// Recipe Overview /// public Dictionary RecipeOverview; + /// + /// Last TC observed (stats) in sec + /// + public double TC_last = 3600; } diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 534dffc5..df3f4766 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -48,6 +48,10 @@ namespace Thermo.Active.NC /// Ultimo ciclo registrato(secondi) /// protected double lastCycle = 9999; + /// + /// Recipe Live data + /// + public static LiveData RecipeLiveData = new LiveData(); public NcAdapter() => // Choose NC @@ -1463,6 +1467,8 @@ namespace Thermo.Active.NC { lastCycle = 0.5 * lastCycle + 0.5 * lastDuration; } + // salvo anche nei live data della ricetta... + RecipeLiveData.TC_last = lastCycle; // manage strobe/ack! libraryError = numericalControl.PLC_WAckPzProdEnd(); diff --git a/Thermo.Active.NC/NcFileAdapter.cs b/Thermo.Active.NC/NcFileAdapter.cs index 233332a8..d46183f1 100644 --- a/Thermo.Active.NC/NcFileAdapter.cs +++ b/Thermo.Active.NC/NcFileAdapter.cs @@ -20,10 +20,6 @@ namespace Thermo.Active.NC public class NcFileAdapter : NcAdapter { - /// - /// Recipe Live data - /// - public static LiveData RecipeLiveData = new LiveData(); /// /// Read file from local devices ad give back string content From bd0f7517b0a3a0db5382d9dcf6bfb5e3bc8d2fcf Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 13 Jul 2020 10:46:17 +0200 Subject: [PATCH 2/6] Added saveAll method for recipe --- .../Controllers/WebApi/RecipeController.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/Thermo.Active/Controllers/WebApi/RecipeController.cs b/Thermo.Active/Controllers/WebApi/RecipeController.cs index 9bb8d6e2..1a98d457 100644 --- a/Thermo.Active/Controllers/WebApi/RecipeController.cs +++ b/Thermo.Active/Controllers/WebApi/RecipeController.cs @@ -9,6 +9,7 @@ using System.Security.Claims; using System.Threading.Tasks; using System.Web; using System.Web.Http; +using System.Windows.Media.Animation; using Thermo.Active.Config; using Thermo.Active.Database.Controllers; using Thermo.Active.Model.DTOModels.ThRecipe; @@ -456,6 +457,60 @@ namespace Thermo.Active.Controllers.WebApi } + [Route("saveAll"), HttpPost] + public async Task SaveAll(string newName, double estimTimeSec) + { + bool imageUploaded = false; + + if (!Request.Content.IsMimeMultipartContent()) + { + throw new HttpResponseException(HttpStatusCode.UnsupportedMediaType); + } + + List formItems = await MultipartHandler.ManageMultiPartFileAsync(Request); + + foreach (FormItem item in formItems) + { + if (item.IsAFile) + { + if (item.ParameterName == "image" || item.MediaType.StartsWith("image/")) + { + string filePath = item.FileName; + imageUploaded = NcFileAdapter.SaveRecipeImage(item.FileName, item.Data); + } + } + } + if (!string.IsNullOrEmpty(newName)) + { + // recupero i dati LIVE dei parametri HMI della ricetta... + CmsError libraryError = ncAdapter.ReadFullRecipe(out Dictionary currRecipe); + if (libraryError.IsError()) + { + ThermoActiveLogger.LogError($"SaveAll error | {libraryError.exception}"); + return BadRequest(libraryError.localizationKey); + } + + var currParams = new Dictionary(); + foreach (var item in currRecipe) + { + currParams.Add(item.Key, item.Value.SetpointPLC); + } + // salvo parametri + NcFileAdapter.RecipeLiveData.RecipeParameters = currParams; + + // ora salvo il dato del TC stimato se presente + if (estimTimeSec > 0) + { + NcFileAdapter.RecipeLiveData.TC_last = estimTimeSec; + } + // e salvo su disco + NcFileAdapter.SaveRecipe(newName, NcFileAdapter.RecipeLiveData); + } + + return Ok(); + } + + /// /// Do actual recipe parameters FileSave /// From 5a29ac454ff83a643a035f39dd3a396c83f4db63 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 13 Jul 2020 10:46:43 +0200 Subject: [PATCH 3/6] fix filter & stats for TC --- Thermo.Active.NC/NcAdapter.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index df3f4766..42e6caa2 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1457,12 +1457,12 @@ namespace Thermo.Active.NC lastProdEnd = DateTime.Now; // calcolo ultimo ciclo... var lastDuration = lastProdEnd.Subtract(lastProdStart).TotalSeconds; - // se il prec è > 3 cicli uso SOLO ultimo - if (lastCycle > 3 * lastDuration) + // se il valore SALVATO è > 3 * valore rilevato (ma NON inferiore a 1/3...) --> uso SOLO ultimo + if ((lastCycle > 3 * lastDuration) && (lastCycle / 3 < lastDuration)) { lastCycle = lastDuration; } - // altrimenti ewma 50% + // altrimenti EWMA 50% else { lastCycle = 0.5 * lastCycle + 0.5 * lastDuration; From 1b91c5d9011d8afa6101a99c449a19bee0fe8cdc Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 13 Jul 2020 11:27:30 +0200 Subject: [PATCH 4/6] fix per calcolo gauges TCiclo --- Thermo.Active.NC/NcAdapter.cs | 6 +++++- Thermo.Active/Properties/AssemblyInfo.cs | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 42e6caa2..50cefa61 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1231,7 +1231,6 @@ namespace Thermo.Active.NC break; } - // creo obj contenuto currProdData = new DTOThermoProd() { @@ -1245,6 +1244,11 @@ namespace Thermo.Active.NC MinVal = item.MinVal / item.ScaleFactor, MaxVal = item.MaxVal / item.ScaleFactor }; + // fix: se + timeAdv uso come max ultimo TC rilevato... + if (item.Name == "timeAdv") + { + currProdData.MaxVal = (int)Math.Ceiling((double)lastProdInfoData.TimeCycleGross / 1000); + } // aggiungo a dictionary! if (currentLiveProd.ContainsKey(item.Name)) { diff --git a/Thermo.Active/Properties/AssemblyInfo.cs b/Thermo.Active/Properties/AssemblyInfo.cs index ec2cfffb..97c53de1 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.36")] \ No newline at end of file +[assembly: AssemblyVersion("0.9.37")] \ No newline at end of file From 79f4f613a8da995176e462255a19190235e7b663 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 13 Jul 2020 12:00:58 +0200 Subject: [PATCH 5/6] fix stima tempo completamento lotto negativo --- Thermo.Active.NC/NcAdapter.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Thermo.Active.NC/NcAdapter.cs b/Thermo.Active.NC/NcAdapter.cs index 50cefa61..6c3366fb 100644 --- a/Thermo.Active.NC/NcAdapter.cs +++ b/Thermo.Active.NC/NcAdapter.cs @@ -1311,6 +1311,8 @@ namespace Thermo.Active.NC } // stima durata da pz fatti... currentProdPanel.StimaDurata = Math.Round((currentProdPanel.NumTarget - currentProdPanel.NumDone) * currentProdPanel.LastTCiclo, 2); + // se stima negativa (+ pezzi di quanti richiesti...) --> ZERO! + currentProdPanel.StimaDurata = currentProdPanel.StimaDurata < 0 ? 0 : currentProdPanel.StimaDurata; } // dai parametri sistemo i setpoints if (lastRecipe != null) From b0d2071ee9d6af157f6b9627ae0fb987a6fa6fb1 Mon Sep 17 00:00:00 2001 From: Samuele Locatelli Date: Mon, 13 Jul 2020 12:01:17 +0200 Subject: [PATCH 6/6] inizio nuova release 0.9.38 --- 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 97c53de1..8beaf5b9 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.37")] \ No newline at end of file +[assembly: AssemblyVersion("0.9.38")] \ No newline at end of file