From fe7108fd24e8dd403b4efb3557d32013ce1f9a06 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Mon, 16 Jun 2025 07:21:31 +0300 Subject: Production data graph. --- .../Tango.PPC.MachineSettings/Views/MainView.xaml | 5 +- .../PPC/Tango.PPC.Common/PPCSettings.cs | 10 +++ .../Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs | 78 ++++++++++++++++------ .../PPC/Tango.PPC.UI/Views/MachineStatusView.xaml | 2 +- .../Visual_Studio/PPC/Tango.PPC.UI/app.manifest | 2 +- 5 files changed, 72 insertions(+), 25 deletions(-) (limited to 'Software/Visual_Studio/PPC') diff --git a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Views/MainView.xaml b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Views/MainView.xaml index d13d6c124..f92b92b5e 100644 --- a/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Views/MainView.xaml +++ b/Software/Visual_Studio/PPC/Modules/Tango.PPC.MachineSettings/Views/MainView.xaml @@ -192,6 +192,9 @@ Enable White Thread Trimming Feature + + Production Data Graph Start Time + @@ -413,7 +416,7 @@ Phone Numbers (comma separated) - + diff --git a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs index 55a8be975..d149fc16a 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.Common/PPCSettings.cs @@ -433,11 +433,21 @@ namespace Tango.PPC.Common /// public bool EnableWhiteThreadSkip { get; set; } + /// + /// Gets or sets the production data start time. + /// + public int ProductionDataStartTimeHours { get; set; } + + public int ProductionDataRefreshRateSeconds { get; set; } + + /// /// Initializes a new instance of the class. /// public PPCSettings() { + ProductionDataStartTimeHours = 6; + ProductionDataRefreshRateSeconds = 60; EnableWhiteThreadSkip = false; BuzzerDuration = 30; EnableJerricanChangePopup = true; diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs index 2faee12ac..7b0f47927 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs @@ -75,11 +75,14 @@ namespace Tango.PPC.UI.ViewModels }; private DispatcherTimer _productiondata_timer; + private double _lastProductionDataProgress; private bool startingJob = false; private bool _jerricanDialogShowing; private List _colorSpaces; private bool _conversion_Busy; private bool _printingEnded; + private double _totalProductionDataMeters; + private DateTime productionStartTime; #region Properties @@ -170,7 +173,7 @@ namespace Tango.PPC.UI.ViewModels if (_isDyeingProcess != value) { _isDyeingProcess = value; - RaisePropertyChangedAuto(); + RaisePropertyChangedAuto(); } } } @@ -330,7 +333,7 @@ namespace Tango.PPC.UI.ViewModels } } - public WpfGraphController JobController { get; set; } + public WpfGraphController JobController { get; set; } private JobResumeModel _resumeModel; public JobResumeModel ResumeModel @@ -401,8 +404,10 @@ namespace Tango.PPC.UI.ViewModels public MachineStatusViewVM() { + productionStartTime = DateTime.Today.AddHours(Settings.ProductionDataStartTimeHours); + _productiondata_timer = new DispatcherTimer(); - _productiondata_timer.Interval = TimeSpan.FromMinutes(10); + _productiondata_timer.Interval = TimeSpan.FromSeconds(Settings.ProductionDataRefreshRateSeconds); _productiondata_timer.Tick += _productiondata_timer_Tick; @@ -469,10 +474,7 @@ namespace Tango.PPC.UI.ViewModels MachineProvider.MachineOperator.MachineStatusChanged += MachineOperator_MachineStatusChanged; - DateTime dateTime = DateTime.Now; - DateTime onedayEarlier = dateTime.AddDays(-1); - - GetCollectionDyePropByStartTime(onedayEarlier); + GetCollectionDyePropByStartTime(productionStartTime); _productiondata_timer.Start(); } @@ -586,7 +588,29 @@ namespace Tango.PPC.UI.ViewModels private void _productiondata_timer_Tick(object sender, EventArgs e) { - var CurrentDateTime = DateTime.Now; + if (MachineProvider.MachineOperator.IsPrinting) + { + if (RunningJobStatus != null) + { + var delta = RunningJobStatus.Progress - _lastProductionDataProgress; + _lastProductionDataProgress = RunningJobStatus.Progress; + + if (BuildProvider.MachineType == MachineTypes.Eureka) + { + _totalProductionDataMeters += (delta * 4); + } + else + { + _totalProductionDataMeters += delta; + } + + JobController.PushData(DateTime.Now.TimeOfDay, _totalProductionDataMeters); + } + else + { + _lastProductionDataProgress = 0; + } + } } private async void MidTankLevel_PressedEvent(object sender, JerricanLevelModel e) @@ -641,6 +665,8 @@ namespace Tango.PPC.UI.ViewModels CurrentBrushStop = null; JobBrushStop = null; + JobController.PushData(DateTime.Now.TimeOfDay, _totalProductionDataMeters); + List outputs = new List(); var idsPacks = MachineProvider.Machine.Configuration.GetSupportedIdsPacks(Job.Rml).OrderBy(x => x.PackIndex).ToList(); @@ -1083,9 +1109,9 @@ namespace Tango.PPC.UI.ViewModels public TimeToDyeValueCollection graphDyeingValuesCollection = new TimeToDyeValueCollection(); - private WpfGraphController CreateController(params WpfGraphDataSeries[] seriesCollection) + private WpfGraphController CreateController(params WpfGraphDataSeries[] seriesCollection) { - var controller = new WpfGraphController(); + var controller = new WpfGraphController(); foreach (var series in seriesCollection) { @@ -1095,9 +1121,9 @@ namespace Tango.PPC.UI.ViewModels controller.Range.AutoY = true; controller.Range.MaximumY = 100; controller.Range.MinimumY = 0; - controller.Range.MaximumX = new DateTime(0).AddMinutes(30); + controller.Range.MaximumX = TimeSpan.FromHours(24); - controller.RefreshRate = TimeSpan.FromMilliseconds(300000);//5 min + controller.RefreshRate = TimeSpan.FromSeconds(Settings.ProductionDataRefreshRateSeconds); return controller; } @@ -1121,24 +1147,32 @@ namespace Tango.PPC.UI.ViewModels { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - var jobRuns = await db.JobRuns.Where(x => x.StartDate >= starttime).Select(x => new { x.StartDate, x.EndDate, x.EndPosition }).OrderBy(y => y.StartDate).ToListAsync(); - double allvalues = 0; - graphDyeingValuesCollection.StartTime = starttime; - for (int i = 0; i < jobRuns.Count; i++) + DateTime startTimeUTC = starttime.ToUniversalTime(); + + var jobRuns = await db.JobRuns.Where(x => x.StartDate >= startTimeUTC).Select(x => new { x.StartDate, x.EndDate, x.ActualStartPosition, x.ActualEndPosition }).OrderBy(y => y.StartDate).ToListAsync(); + + JobController.PushData(starttime.TimeOfDay, _totalProductionDataMeters); + + foreach (var jobRun in jobRuns) { - JobController.PushData(jobRuns[i].StartDate, allvalues); - if (i > 0) + JobController.PushData(jobRun.StartDate.ToLocalTime().TimeOfDay, _totalProductionDataMeters); + + if (BuildProvider.MachineType == MachineTypes.Eureka) + { + _totalProductionDataMeters += (jobRun.ActualEndPosition - jobRun.ActualStartPosition) * 4; + } + else { - allvalues += jobRuns[i - 1].EndPosition; + _totalProductionDataMeters += jobRun.ActualEndPosition - jobRun.ActualStartPosition; } - graphDyeingValuesCollection.items.Add(new TimeToDyeValueItem() { startTime = jobRuns[i].StartDate, endTime = jobRuns[i].EndDate, totalValue = allvalues }); - JobController.PushData(jobRuns[i].EndDate, allvalues); + + JobController.PushData(jobRun.EndDate.ToLocalTime().TimeOfDay, _totalProductionDataMeters); } } } catch (Exception ex) { - LogManager.Log(ex, "Error loading machine counters."); + LogManager.Log(ex, "Error loading production data."); } } diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineStatusView.xaml b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineStatusView.xaml index a269c590d..2f1a54e64 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineStatusView.xaml +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/Views/MachineStatusView.xaml @@ -1409,7 +1409,7 @@ + VerticalAxisVisibility="Visible" HorizontalAxisVisibility="Visible" VerticalTicks ="6" AxisLabelAngle="0.0"/> diff --git a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest index d72e75011..efc5f8179 100644 --- a/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest +++ b/Software/Visual_Studio/PPC/Tango.PPC.UI/app.manifest @@ -16,7 +16,7 @@ Remove this element if your application requires this virtualization for backwards compatibility. --> - + -- cgit v1.3.1