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..6c3366fb 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 @@ -1227,7 +1231,6 @@ namespace Thermo.Active.NC break; } - // creo obj contenuto currProdData = new DTOThermoProd() { @@ -1241,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)) { @@ -1303,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) @@ -1453,16 +1463,18 @@ 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; } + // 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 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 /// diff --git a/Thermo.Active/Properties/AssemblyInfo.cs b/Thermo.Active/Properties/AssemblyInfo.cs index ec2cfffb..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.36")] \ No newline at end of file +[assembly: AssemblyVersion("0.9.38")] \ No newline at end of file