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.UI/ViewModels/MachineStatusViewVM.cs | 78 ++++++++++++++++------ 1 file changed, 56 insertions(+), 22 deletions(-) (limited to 'Software/Visual_Studio/PPC/Tango.PPC.UI/ViewModels/MachineStatusViewVM.cs') 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."); } } -- cgit v1.3.1