From 122461b98adad3fc7a267cdb6a0126a6439c5e78 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Wed, 4 Mar 2020 13:24:05 +0200 Subject: Statistics JobRunView GUI changes. Related Work Items: #2509 --- .../Converters/DateTimeToStringFormatConverter.cs | 28 +++ .../MidTankLevelToElementHeightConverter.cs | 2 +- .../Tango.MachineStudio.Statistics.csproj | 1 + .../ViewModels/JobRunsViewVM.cs | 43 ++-- .../Views/JobRunsView.xaml | 248 +++++++++++---------- .../Views/JobRunsView.xaml.cs | 16 ++ 6 files changed, 200 insertions(+), 138 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/DateTimeToStringFormatConverter.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/DateTimeToStringFormatConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/DateTimeToStringFormatConverter.cs new file mode 100644 index 000000000..79b8cb92e --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/DateTimeToStringFormatConverter.cs @@ -0,0 +1,28 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace Tango.MachineStudio.Statistics.Converters +{ + public class DateTimeToStringFormatConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if(value is DateTime) + { + DateTime date = (DateTime)value; + return date.ToLocalTime().ToString(@"hh\:mm\:ss"); + } + return ""; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/MidTankLevelToElementHeightConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/MidTankLevelToElementHeightConverter.cs index e9f513cc3..4ea46336f 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/MidTankLevelToElementHeightConverter.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/MidTankLevelToElementHeightConverter.cs @@ -25,7 +25,7 @@ namespace Tango.MachineStudio.Statistics.Converters if (midTankLevel < (MAX_QUANTITY/10))// if quantity < 10|% set 2 pixel delta = 2.0; var test = delta; - return test;// (parentActualHeight - (midTankLevel / MAX_QUANTITY) * parentActualHeight); + return parentActualHeight - delta; } catch { diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj index 603429f94..1300d7dba 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Tango.MachineStudio.Statistics.csproj @@ -74,6 +74,7 @@ + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs index 07e431751..567867a80 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs @@ -25,7 +25,6 @@ namespace Tango.MachineStudio.Statistics.ViewModels private List _allMachines; private List _allUsers; private List _rmlsModels; - private List _allJobRuns; #region Properties @@ -172,7 +171,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels /// public ISuggestionProvider JobsProvider { get; set; } - private Job _selectedJob; + private Job _selectedJob; /// /// Gets or sets the job. Used as Sele /// @@ -182,17 +181,10 @@ namespace Tango.MachineStudio.Statistics.ViewModels set { _selectedJob = value; - SelectedJobName = _selectedJob != null ? _selectedJob.Name : ""; RaisePropertyChangedAuto(); } } - /// - /// Gets or sets the name of the selected job. Used in filter. - /// - private string SelectedJobName { get; set; } - - #endregion public RelayCommand LoadJobRunsCommand { get; set; } @@ -201,7 +193,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels { _notification = notificationProvider; JobRuns = new ObservableCollection(); - LoadJobRunsCommand = new RelayCommand(async () => await LoadJobRuns(), ()=> IsFree); + LoadJobRunsCommand = new RelayCommand(async () => await LoadJobRuns(), () => IsFree); LengthUpperValue = 5000.0; LengthLowerValue = 0.0; DateTime now = DateTime.Now; @@ -233,7 +225,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels JobRunStatus.Failed, }); - JobRunSelectedStatuses.SelectionChanged -= (x,y)=> RaisePropertyChanged(nameof(JobRunSelectedStatuses)); + JobRunSelectedStatuses.SelectionChanged -= (x, y) => RaisePropertyChanged(nameof(JobRunSelectedStatuses)); JobRunSelectedStatuses.SelectionChanged += (x, y) => RaisePropertyChanged(nameof(JobRunSelectedStatuses)); IsGradientSelection = new SelectedObjectCollection(new ObservableCollection @@ -251,15 +243,25 @@ namespace Tango.MachineStudio.Statistics.ViewModels { try { - SelectedJobName = filter; - return _allJobRuns.Where(x => x.Name != null && x.Name.ToString().StartsWith(filter, StringComparison.CurrentCultureIgnoreCase)).ToList(); + if (filter != null) + { + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { + return db.Jobs.Where(x => x.Name!= null && x.Name.ToLower().Contains(filter.ToLower())).ToList(); + } + } + else + { + return new List(); + } } - catch + catch (Exception ex) { + LogManager.Log(ex, "Error loading jobs."); return null; } }); - + } /// @@ -275,13 +277,11 @@ namespace Tango.MachineStudio.Statistics.ViewModels using (var db = ObservablesContext.CreateDefault()) { - _allJobRuns = await db.Jobs.ToListAsync(); ; _allMachines = await db.Machines.ToListAsync(); _allUsers = await db.Users.Include(x => x.Contact).ToListAsync(); - _rmlsModels = await db.Rmls.Select(x=> new RmlModel(){ Name = x.Name, Guid = x.Guid}).ToListAsync(); + _rmlsModels = await db.Rmls.Select(x => new RmlModel() { Name = x.Name, Guid = x.Guid }).ToListAsync(); SelectedMachines = new SelectedObjectCollection(_allMachines.ToObservableCollection(), new ObservableCollection()); SelectedThreads = new SelectedObjectCollection(_rmlsModels.ToObservableCollection(), new ObservableCollection()); - } } catch (Exception ex) @@ -311,6 +311,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels DateTime startUtc = StartSelectedDate.ToUniversalTime(); TimeSpan offsetTime = (EndSelectedDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(23, 59, 59); DateTime endUtc = EndSelectedDate.ToUniversalTime() + offsetTime; + string jobName = SelectedJob == null ? "" : SelectedJob.Name; var runs = await new JobRunsCollectionBuilder(db).Set(x => x.ActualStartDate <= DbFunctions.TruncateTime(endUtc) && x.ActualStartDate >= DbFunctions.TruncateTime(startUtc.Date)) .WithMachines(SelectedMachines.SynchedSource.ToList()) @@ -318,10 +319,10 @@ namespace Tango.MachineStudio.Statistics.ViewModels .WithJobStatus(JobRunSelectedStatuses.SynchedSource) .WithGradient(IsGradientSelection.SynchedSource) .WithRmls(SelectedThreads.SynchedSource.Select(x => x.Guid).ToList()) - .Query(y => y.Where(x => (String.IsNullOrEmpty(SelectedJobName) || x.JobName.ToString().ToLower().StartsWith(SelectedJobName.ToLower())) - && ( x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue) - )) + .Query(y => y.Where(x => ( String.IsNullOrEmpty(jobName) || x.JobName.ToLower().StartsWith(jobName.ToLower())) + && (x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue))) .BuildListAsync(); + var modelList = runs.Select(x => new JobRunModel() { 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 c82fa3beb..82043ae72 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 @@ -17,7 +17,7 @@ - + @@ -36,12 +36,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + + + + @@ -50,7 +82,7 @@ - + @@ -65,6 +97,11 @@ + + @@ -85,7 +122,7 @@ - + @@ -96,7 +133,7 @@ - + @@ -120,20 +157,13 @@ - - - - - - - - - - - - - - + + + + + + + @@ -154,10 +184,9 @@ - - - - + + + @@ -167,7 +196,7 @@ - + @@ -181,19 +210,13 @@ - - - - - - - - - - - - - + + + + + + + @@ -201,7 +224,7 @@ - + @@ -217,19 +240,13 @@ - - - - - - - - - - - - - + + + + + + + @@ -239,14 +256,14 @@ - - - - + + + - + @@ -264,19 +281,12 @@ - - - - - - - - - - - - - + + + + + + @@ -310,20 +320,14 @@ - - + + + + + - - - - - - - - - - - + + @@ -334,30 +338,41 @@ - + - - + + + + + +