From c9ba7c0b806818cdcbcd10fb03805a61608b4233 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Thu, 27 Feb 2020 16:03:06 +0200 Subject: Liquid quantities implementation in xaml. Related Work Items: #2509 --- .../Converters/DateIsInListToBooleanConverter.cs | 29 -------- .../MidTankLevelToElementHeightConverter.cs | 41 +++++++++++ .../Converters/StringToFirstLetterConverter.cs | 30 ++++++++ .../Tango.MachineStudio.Statistics.csproj | 3 +- .../ViewModels/JobRunsViewVM.cs | 79 +++++++++++++++++----- .../Views/JobRunsView.xaml | 78 ++++++++++++--------- 6 files changed, 181 insertions(+), 79 deletions(-) delete mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/DateIsInListToBooleanConverter.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/MidTankLevelToElementHeightConverter.cs create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/StringToFirstLetterConverter.cs (limited to 'Software/Visual_Studio/MachineStudio/Modules') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/DateIsInListToBooleanConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/DateIsInListToBooleanConverter.cs deleted file mode 100644 index 74e0c61d8..000000000 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/DateIsInListToBooleanConverter.cs +++ /dev/null @@ -1,29 +0,0 @@ -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 DateIsInListToBooleanConverter : IMultiValueConverter - { - public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) - { - if (values.Length < 2 || !(values[0] is DateTime) || !(values[1] is IEnumerable)) - return false; - - var date = (DateTime)values[0]; - var dateList = (IEnumerable)values[1]; - - return dateList.ToList().Exists(x => x.ToLocalTime().ToShortDateString() == date.ToLocalTime().ToShortDateString()); - } - - public object[] ConvertBack(object value, Type[] targetTypes, 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 new file mode 100644 index 000000000..e9f513cc3 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/MidTankLevelToElementHeightConverter.cs @@ -0,0 +1,41 @@ +using System; +using System.Globalization; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Data; + +namespace Tango.MachineStudio.Statistics.Converters +{ + public class MidTankLevelToElementHeightConverter : IMultiValueConverter + { + public const double MAX_QUANTITY = 130000000; + public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture) + { + try + { + double parentActualHeight; + Double.TryParse(values[0].ToString(), out parentActualHeight); + double quantity; + Double.TryParse(values[1].ToString(), out quantity); + + double midTankLevel = (double)Math.Min(quantity, MAX_QUANTITY); + double delta = ((midTankLevel / MAX_QUANTITY) * parentActualHeight); + if (midTankLevel < (MAX_QUANTITY/10))// if quantity < 10|% set 2 pixel + delta = 2.0; + var test = delta; + return test;// (parentActualHeight - (midTankLevel / MAX_QUANTITY) * parentActualHeight); + } + catch + { + return 0d; + } + } + + public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/StringToFirstLetterConverter.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/StringToFirstLetterConverter.cs new file mode 100644 index 000000000..a1c9561b9 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Converters/StringToFirstLetterConverter.cs @@ -0,0 +1,30 @@ +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 StringToFirstLetterConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value != null && value.ToString().Length > 1) + { + return value.ToString().First().ToString(); + } + else + { + return value; + } + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file 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 fa62578a1..603429f94 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 @@ -75,8 +75,9 @@ + - + 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 cf74071c9..07e431751 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,11 +25,14 @@ namespace Tango.MachineStudio.Statistics.ViewModels private List _allMachines; private List _allUsers; private List _rmlsModels; - private List _allJobRuns; + private List _allJobRuns; #region Properties private ObservableCollection _jobRuns; + /// + /// Gets or sets the job runs. Contains filtered data of JobRunModel. + /// public ObservableCollection JobRuns { get { return _jobRuns; } @@ -41,6 +44,9 @@ namespace Tango.MachineStudio.Statistics.ViewModels } private JobRunModel _selectedJobRun = null; + /// + /// Gets or sets the JobRunModel. Binding to selected item of grid items. + /// public JobRunModel SelectedJobRun { get { return _selectedJobRun; } @@ -52,6 +58,9 @@ namespace Tango.MachineStudio.Statistics.ViewModels } private SelectedObjectCollection _selectedMachines; + /// + /// Gets or sets the selected machines. Contains all available machines and selected machines. Binding to ComboBox Machines. + /// public SelectedObjectCollection SelectedMachines { get { return _selectedMachines; } @@ -63,6 +72,9 @@ namespace Tango.MachineStudio.Statistics.ViewModels } private DateTime _startSelectedDate; + /// + /// Gets or sets the start selected date. + /// public DateTime StartSelectedDate { get { return _startSelectedDate; } @@ -70,6 +82,9 @@ namespace Tango.MachineStudio.Statistics.ViewModels } private DateTime _endSelectedDate; + /// + /// Gets or sets the end selected date. + /// public DateTime EndSelectedDate { get { return _endSelectedDate; } @@ -77,6 +92,9 @@ namespace Tango.MachineStudio.Statistics.ViewModels } protected Double _lengthLowerValue; + /// + /// Gets or sets the length lower value of Range Slider + /// public Double LengthLowerValue { get { return _lengthLowerValue; } @@ -88,6 +106,9 @@ namespace Tango.MachineStudio.Statistics.ViewModels } protected Double _lengthUpperValue; + /// + /// Gets or sets the length upper value of Range Slider. + /// public Double LengthUpperValue { get { return _lengthUpperValue; } @@ -99,6 +120,9 @@ namespace Tango.MachineStudio.Statistics.ViewModels } private SelectedObjectCollection _jobRunSelectedSources; + /// + /// Gets or sets the job run selected sources. Binding to ComboBox "Source". + /// public SelectedObjectCollection JobRunSelectedSources { get { return _jobRunSelectedSources; } @@ -106,6 +130,9 @@ namespace Tango.MachineStudio.Statistics.ViewModels } private SelectedObjectCollection _jobRunSelectedStatuses; + /// + /// Gets or sets the job run selected statuses. Binding to ComboBox "Status". + /// public SelectedObjectCollection JobRunSelectedStatuses { get { return _jobRunSelectedStatuses; } @@ -113,6 +140,9 @@ namespace Tango.MachineStudio.Statistics.ViewModels } public SelectedObjectCollection _isGradientSelection; + /// + /// Gets or sets the is gradient selection. Binding to ComboBox "IsGradient". + /// public SelectedObjectCollection IsGradientSelection { get { return _isGradientSelection; } @@ -124,6 +154,9 @@ namespace Tango.MachineStudio.Statistics.ViewModels } private SelectedObjectCollection _selectedThreads; + /// + /// Gets or sets the selected threads. Contains all available threads and selected threads. Binding to ComboBox "Thread". + /// public SelectedObjectCollection SelectedThreads { get { return _selectedThreads; } @@ -137,21 +170,26 @@ namespace Tango.MachineStudio.Statistics.ViewModels /// /// Gets or sets the JobRuns providers. /// - public ISuggestionProvider JobRunsProvider { get; set; } + public ISuggestionProvider JobsProvider { get; set; } - private JobRun _jobRun; - public JobRun JobRun + private Job _selectedJob; + /// + /// Gets or sets the job. Used as Sele + /// + public Job SelectedJob { - get { return _jobRun; } - set { - _jobRun = value; - if (_jobRun != null) - { - SelectedJobName = _jobRun.JobName; - } - RaisePropertyChangedAuto(); } + get { return _selectedJob; } + 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; } @@ -209,12 +247,12 @@ namespace Tango.MachineStudio.Statistics.ViewModels }); IsGradientSelection.SelectionChanged -= (x, y) => RaisePropertyChanged(nameof(IsGradientSelection)); IsGradientSelection.SelectionChanged += (x, y) => RaisePropertyChanged(nameof(IsGradientSelection)); - JobRunsProvider = new SuggestionProvider((filter) => + JobsProvider = new SuggestionProvider((filter) => { try { SelectedJobName = filter; - return _allJobRuns.Where(x => x.JobName != null && x.JobName.ToString().StartsWith(filter, StringComparison.CurrentCultureIgnoreCase)).ToList(); + return _allJobRuns.Where(x => x.Name != null && x.Name.ToString().StartsWith(filter, StringComparison.CurrentCultureIgnoreCase)).ToList(); } catch { @@ -223,7 +261,10 @@ namespace Tango.MachineStudio.Statistics.ViewModels }); } - + + /// + /// Initializes this instance. Called form main view VM in OnApplicationReady + /// public async void Init() { using (_notification.PushTaskItem("Loading job runs...")) @@ -234,7 +275,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels using (var db = ObservablesContext.CreateDefault()) { - _allJobRuns = await db.JobRuns.ToListAsync(); ; + _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(); @@ -253,7 +294,10 @@ namespace Tango.MachineStudio.Statistics.ViewModels } } } - + + /// + /// Loads the job runs by filters. + /// private async Task LoadJobRuns() { using (_notification.PushTaskItem("Loading job runs...")) @@ -273,6 +317,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels .WithJobSource(JobRunSelectedSources.SynchedSource) .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) )) 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 c89cd5819..c82fa3beb 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,14 +17,13 @@ - - - + + + + + + + + + + + + + + + + + + + + + + @@ -92,7 +120,7 @@ - + @@ -100,7 +128,7 @@ - + @@ -129,12 +157,11 @@ - + - - + @@ -237,7 +264,7 @@ - + @@ -259,7 +286,7 @@ - + @@ -268,10 +295,10 @@ - +