using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Media; using Tango.BL.Entities; using Tango.Core; using Tango.PMR.Diagnostics; using Tango.PPC.Common; using Tango.Settings; namespace Tango.PPC.UI.Models { public class MachineOverviewModel : ExtendedObject { public MachineOverviewItem DryerZone3 { get; set; } public MachineOverviewItem DryerAir { get; set; } public MachineOverviewItem Tunnel { get; set; } public MachineOverviewItem PumpsPressure { get; set; } public MachineOverviewItem Lubricant { get; set; } private PPCSettings _settings; /// /// Gets the main PPC settings. /// public PPCSettings Settings { get { if (_settings == null) { _settings = SettingsManager.Default.GetOrCreate(); } return _settings; } private set { _settings = value; } } public MachineOverviewModel() { DryerZone3 = new MachineOverviewItem(); DryerAir = new MachineOverviewItem(); DryerAir.MaxValue =140; Tunnel = new MachineOverviewItem(); PumpsPressure = new MachineOverviewItem(); PumpsPressure.MaxValue = 6; Lubricant = new MachineOverviewItem(); Lubricant.MaxValue = 100; Lubricant.Value = 100; } public void Update(StartDiagnosticsResponse diagnostics, Rml rml, ProcessParametersTable processParameters) { //Dryer Zone 3 var dryerZone3State = diagnostics.HeatersStates.FirstOrDefault(x => x.HeaterType == HeaterType.HeaterZone3); UpdateHeaterItem(DryerZone3, dryerZone3State); //Dryer Air var dryerAirState = diagnostics.Monitors.EuSpare1.FirstOrDefault(); UpdateDryerAirItem(dryerAirState); //diagnostics.HeatersStates.FirstOrDefault(x => x.HeaterType == HeaterType.DryerAirHeater); //Tunnel var tunnelState = diagnostics.HeatersStates.FirstOrDefault(x => x.HeaterType == HeaterType.ETunnelHeater); UpdateHeaterItem(Tunnel, tunnelState); //Pumps Pressure if (diagnostics.Monitors.EuInkLinesPressure.Count > 0 && diagnostics.Monitors.EuInkLinesPressure.Any(x => x.Data.Count > 0)) { var pumpsPressuerValue = diagnostics.Monitors.EuInkLinesPressure.SelectMany(x => x.Data).Max(); UpdatePumpsPressureItem(pumpsPressuerValue); } //Lubricant var lubricantValue = diagnostics.Monitors.EuLubricantCurrent.FirstOrDefault(); UpdateLubricantItem( rml, lubricantValue); } private void UpdateHeaterItem(MachineOverviewItem item, HeaterState state) { if (state != null) { if (state.IsRampingUp) { item.Status = "Heating Up"; item.Color = Colors.Orange; item.DisplayValue = $"{state.CurrentValue} / {state.SetPoint}"; item.MaxValue = state.SetPoint; item.Value = state.CurrentValue; } else if (state.CurrentValue > state.SetPoint) { item.Status = "Over-temperature"; item.Color = Colors.Red; item.DisplayValue = $"{state.CurrentValue} / {state.SetPoint}"; item.MaxValue = state.SetPoint; item.Value = state.CurrentValue; } else if (state.IsInSetPoint) { item.Status = "Operational"; item.Color = Colors.Green; item.DisplayValue = $" {state.SetPoint}"; item.MaxValue = state.SetPoint; item.Value = state.CurrentValue; } else { item.Color = Colors.Gray; item.MaxValue = 100; item.Value = 0; } } } private void UpdateDryerAirItem(double currentvalue) { if (currentvalue < 140) { DryerAir.Status = "Heating Up"; DryerAir.Color = Colors.Orange; DryerAir.DisplayValue = $"{currentvalue}"; } else if (currentvalue >= 140) { DryerAir.Status = "Operational"; DryerAir.Color = Colors.Green; DryerAir.DisplayValue = $"{currentvalue}"; } DryerAir.Value = currentvalue; } private void UpdatePumpsPressureItem(double maxValue) { if (maxValue > 6) { PumpsPressure.Status = "Overpressure"; PumpsPressure.Color = Colors.Red; PumpsPressure.DisplayValue = maxValue.ToString(); } else { PumpsPressure.Status = "Operational"; PumpsPressure.Color = Colors.Green; PumpsPressure.DisplayValue = maxValue.ToString(); } PumpsPressure.Value = maxValue; } private void UpdateLubricantItem(Rml rml, double lubricantValue) { if (rml != null) { var rmlLubrication = Settings.LubricationLevels.FirstOrDefault(x => x.RmlGuid == rml.Guid); if (( rml.Lubricant == false) || (rmlLubrication != null && rmlLubrication.LubricationLevel == Common.Lubrication.LubricationLevel.No)) { Lubricant.Status = "NotActive"; Lubricant.DisplayValue = "None"; Lubricant.Color = Colors.Gray; return; } Lubricant.Status = "Active"; Lubricant.DisplayValue = lubricantValue.ToString(); Lubricant.Color = Colors.Green; } Lubricant.Status = "NotActive"; Lubricant.DisplayValue = "None"; Lubricant.Color = Colors.Gray; } } }