From 0008603819e92278101b84254fce4755a4386538 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Mon, 1 Jun 2020 10:02:13 +0300 Subject: Statistic Charts page. Added validation rule to check start date less or equals to end date and enable/disable 'Analyze' button according to validation. --- .../ViewModels/ChartsViewVM.cs | 75 ++++------------------ .../Views/ChartsView.xaml | 38 ++++++++++- .../Views/ChartsView.xaml.cs | 39 +++++++++++ .../Views/JobRunsView.xaml | 2 +- 4 files changed, 88 insertions(+), 66 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/ChartsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/ChartsViewVM.cs index 38c1cc24a..a98257086 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/ChartsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/ChartsViewVM.cs @@ -49,30 +49,16 @@ namespace Tango.MachineStudio.Statistics.ViewModels public DateTime StartDate { get { return _startDate; } - set { _startDate = value; RaisePropertyChangedAuto();} + set { _startDate = value; RaisePropertyChangedAuto(); RaisePropertyChanged("EndDate"); } } private DateTime _endDate; public DateTime EndDate { get { return _endDate; } - set { _endDate = value; RaisePropertyChangedAuto();} + set { _endDate = value; RaisePropertyChangedAuto(); RaisePropertyChanged("StartDate"); } } - - private DateTime _minDate; - public DateTime MinDate - { - get { return _minDate; } - set { _minDate = value; RaisePropertyChangedAuto(); } - } - - private DateTime _maxDate; - public DateTime MaxDate - { - get { return _maxDate; } - set { _maxDate = value; RaisePropertyChangedAuto(); } - } - + public RelayCommand LoadJobRunsCommand { get; set; } #endregion @@ -85,41 +71,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels } #region Generate Charts - - //public async void Init() - //{ - //using (_notification.PushTaskItem("Loading statistics...")) - //{ - // IsFree = false; - - // await Task.Factory.StartNew(() => - // { - // _context = ObservablesContext.CreateDefault(); - // //_job_runs = _context.JobRuns.OrderBy(x => x.StartDate).ToList().Select(x => new JobRunStatisticsModel(x)).ToList(); - // //foreach (var run in _job_runs) - // //{ - // // run.LoadMachine(_context).GetAwaiter().GetResult(); - // //} - // }); - - // if (_job_runs.Count > 0) - // { - // MinDate = _job_runs.Min(x => x.StartDate); - // MaxDate = _job_runs.Max(x => x.StartDate); - // } - - // InvokeUIOnIdle(() => - // { - // if (_loaded) - // { - // OnDateRangeChanged(); - // } - // }); - - // _loaded = true; - // IsFree = true; - //} - //} + private async Task LoadJobRuns() { using (_notification.PushTaskItem("Loading statistics...")) @@ -127,25 +79,24 @@ namespace Tango.MachineStudio.Statistics.ViewModels try { IsFree = false; - + await Task.Factory.StartNew(() => { using (var db = ObservablesContext.CreateDefault()) { - _job_runs = db.JobRuns.OrderBy(x => x.StartDate).ToList().Select(x => new JobRunStatisticsModel(x)).ToList(); + DateTime startUtc = new DateTime(StartDate.Year, StartDate.Month, StartDate.Day, 0, 0, 0).ToUniversalTime(); + TimeSpan offsetTime = (EndDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(23, 59, 59); + DateTime endUtc = EndDate.ToUniversalTime() + offsetTime; + + _job_runs = db.JobRuns.Where(x => (x.StartDate <= endUtc && x.StartDate >= startUtc)).OrderBy(x => x.StartDate).ToList().Select(x => new JobRunStatisticsModel(x)).ToList(); + foreach (var run in _job_runs) { run.LoadMachine(db).GetAwaiter().GetResult(); } - } }); - if (_job_runs.Count > 0) - { - MinDate = _job_runs.Min(x => x.StartDate); - MaxDate = _job_runs.Max(x => x.StartDate); - } - + InvokeUIOnIdle(() => { if (_loaded) @@ -400,7 +351,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels #region Filter by Date public void OnDateRangeChanged() { - if (_job_runs != null && _job_runs.Count > 0)// && _loaded) + if (_job_runs != null)// && _job_runs.Count > 0)// && _loaded) { GenerateTimelineJobStatusChart(); GeneratePieFailedReasonsChart(); diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/ChartsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/ChartsView.xaml index ae4bf1d46..b76154941 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/ChartsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/ChartsView.xaml @@ -6,6 +6,7 @@ xmlns:vm="clr-namespace:Tango.MachineStudio.Statistics.ViewModels" xmlns:global="clr-namespace:Tango.MachineStudio.Statistics" xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:localrule="clr-namespace:Tango.MachineStudio.Statistics.ValidationRules" xmlns:local="clr-namespace:Tango.MachineStudio.Statistics.Views" xmlns:tooltips="clr-namespace:Tango.MachineStudio.Statistics.Tooltips" xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" @@ -21,14 +22,45 @@ Start Date: - + + + + + + + + + End Date: - + + + + + + + + + - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/ChartsView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/ChartsView.xaml.cs index d79d88281..bd97ed2bc 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/ChartsView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/ChartsView.xaml.cs @@ -31,5 +31,44 @@ namespace Tango.MachineStudio.Statistics.Views var tooltip = ((chartPoint.ChartView as PieChart).DataTooltip as Tooltips.PieChartTooltipControl).Title; txtPieTitle.Text = tooltip; } + private void StartDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e) + { + DatePicker datePickerObj = sender as DatePicker; + if (datePickerObj != null && datePickerObj.SelectedDate != null && endDatePicker.SelectedDate != null) + { + if (datePickerObj.SelectedDate > endDatePicker.SelectedDate) + { + BindingExpression start_be = datePickerObj.GetBindingExpression(DatePicker.SelectedDateProperty); + ValidationError validationError = new ValidationError(StartDateExpiredRule, start_be); + validationError.ErrorContent = "The start time must be less than or equal to end time."; + Validation.MarkInvalid(start_be, validationError); + } + else if (Validation.GetHasError(endDatePicker)) + { + BindingExpression end_be = endDatePicker.GetBindingExpression(DatePicker.SelectedDateProperty); + Validation.ClearInvalid(end_be); + } + } + } + + private void EndDatePicker_SelectedDateChanged(object sender, SelectionChangedEventArgs e) + { + DatePicker datePickerObj = sender as DatePicker; + if (datePickerObj.SelectedDate != null && startdatePicker.SelectedDate != null) + { + if (datePickerObj != null && datePickerObj.SelectedDate < startdatePicker.SelectedDate) + { + BindingExpression end_be = datePickerObj.GetBindingExpression(DatePicker.SelectedDateProperty); + ValidationError validationError = new ValidationError(EndDateExpiredRule, end_be); + validationError.ErrorContent = "The end time must be greater than or equal to the start time."; + Validation.MarkInvalid(end_be, validationError); + } + else if (Validation.GetHasError(startdatePicker)) + { + BindingExpression start_be = startdatePicker.GetBindingExpression(DatePicker.SelectedDateProperty); + Validation.ClearInvalid(start_be); + } + } + } } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml index 9617361f7..4ce6030d9 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml @@ -346,7 +346,7 @@