diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-02-26 13:22:44 +0200 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-02-26 13:22:44 +0200 |
| commit | a64cfe8b7dec8417a3d380b55f4ae79c5459f49d (patch) | |
| tree | d40c32f55b65632b80031e64e03ae8d893ea1511 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs | |
| parent | e2fbc8e6047fef09681b994efe2ca1043d25ac9d (diff) | |
| download | Tango-a64cfe8b7dec8417a3d380b55f4ae79c5459f49d.tar.gz Tango-a64cfe8b7dec8417a3d380b55f4ae79c5459f49d.zip | |
Implementing JobRuns on Statistics module.
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs | 191 |
1 files changed, 143 insertions, 48 deletions
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 f03e7f67d..5c80a9564 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 @@ -6,6 +6,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; using Tango.BL; +using Tango.BL.Builders; using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Core.Commands; @@ -14,6 +15,7 @@ using Tango.MachineStudio.Common.Notifications; using Tango.MachineStudio.Statistics.Models; using Tango.SharedUI; using Tango.SharedUI.Components; +using Tango.AutoComplete.Editors; namespace Tango.MachineStudio.Statistics.ViewModels { @@ -22,11 +24,13 @@ namespace Tango.MachineStudio.Statistics.ViewModels private INotificationProvider _notification; private List<Machine> _allMachines; private List<User> _allUsers; + private List<RmlModel> _rmlsModels; + private List<JobRun> _allJobRuns; #region Properties - private List<JobRunModel> _jobRuns; - public List<JobRunModel> JobRuns + private ObservableCollection<JobRunModel> _jobRuns; + public ObservableCollection<JobRunModel> JobRuns { get { return _jobRuns; } set @@ -72,51 +76,84 @@ namespace Tango.MachineStudio.Statistics.ViewModels set { _endSelectedDate = value; RaisePropertyChangedAuto(); } } - protected Double _length; - public Double Length + protected Double _lengthLowerValue; + public Double LengthLowerValue { - get { return _length; } + get { return _lengthLowerValue; } set { - _length = value; + _lengthLowerValue = value; RaisePropertyChangedAuto(); } } - private JobSource _jobRunSource; + protected Double _lengthUpperValue; + public Double LengthUpperValue + { + get { return _lengthUpperValue; } + set + { + _lengthUpperValue = value; + RaisePropertyChangedAuto(); + } + } - public JobSource JobRunSource + private SelectedObjectCollection<JobSource> _jobRunSelectedSources; + public SelectedObjectCollection<JobSource> JobRunSelectedSources { - get { return _jobRunSource; } - set { _jobRunSource = value; RaisePropertyChangedAuto(); } + get { return _jobRunSelectedSources; } + set { _jobRunSelectedSources = value; RaisePropertyChangedAuto(); } } - private JobRunStatus _jobRunStatus; + private SelectedObjectCollection<JobRunStatus> _jobRunSelectedStatuses; + public SelectedObjectCollection<JobRunStatus> JobRunSelectedStatuses + { + get { return _jobRunSelectedStatuses; } + set { _jobRunSelectedStatuses = value; RaisePropertyChangedAuto(); } + } - public JobRunStatus JobRunStatus + public SelectedObjectCollection<bool> _isGradientSelection; + public SelectedObjectCollection<bool> IsGradientSelection { - get { return _jobRunStatus; } - set { _jobRunStatus = value; RaisePropertyChangedAuto(); } + get { return _isGradientSelection; } + set + { + _isGradientSelection = value; + RaisePropertyChangedAuto(); + } } - - private bool? _isGradient; - public bool? IsGradient + private SelectedObjectCollection<RmlModel> _selectedThreads; + public SelectedObjectCollection<RmlModel> SelectedThreads { - get { return _isGradient; } - set { - _isGradient = value; - RaisePropertyChangedAuto(); } + get { return _selectedThreads; } + set + { + _selectedThreads = value; + RaisePropertyChangedAuto(); + } } - private string _jobName; + /// <summary> + /// Gets or sets the JobRuns providers. + /// </summary> + public ISuggestionProvider JobRunsProvider { get; set; } - public string JobName + private JobRun _jobRun; + public JobRun JobRun { - get { return _jobName; } - set { _jobName = value; } + get { return _jobRun; } + set { + _jobRun = value; + if (_jobRun != null) + { + SelectedJobName = _jobRun.JobName; + } + RaisePropertyChangedAuto(); } } + private string SelectedJobName { get; set; } + #endregion @@ -125,11 +162,68 @@ namespace Tango.MachineStudio.Statistics.ViewModels public JobRunsViewVM(INotificationProvider notificationProvider) { _notification = notificationProvider; - JobRuns = new List<JobRunModel>(); - LoadJobRunsCommand = new RelayCommand( GetJobRuns); + JobRuns = new ObservableCollection<JobRunModel>(); + LoadJobRunsCommand = new RelayCommand(async () => await LoadJobRuns(), ()=> IsFree); + LengthUpperValue = 5000.0; + LengthLowerValue = 0.0; + DateTime now = DateTime.Now; + StartSelectedDate = now.AddMonths(-1); + EndSelectedDate = now; + + JobRunSelectedSources = new SelectedObjectCollection<JobSource>(new ObservableCollection<JobSource>() + { + JobSource.Local, + JobSource.Remote + }, new ObservableCollection<JobSource>() + { + JobSource.Local, + JobSource.Remote + }); + JobRunSelectedSources.SelectionChanged -= (x, y) => RaisePropertyChanged(nameof(JobRunSelectedSources)); + JobRunSelectedSources.SelectionChanged += (x, y) => RaisePropertyChanged(nameof(JobRunSelectedSources)); + + JobRunSelectedStatuses = new SelectedObjectCollection<JobRunStatus>(new ObservableCollection<JobRunStatus>() + { + JobRunStatus.Aborted, + JobRunStatus.Completed, + JobRunStatus.Failed, + + }, new ObservableCollection<JobRunStatus>() + { + JobRunStatus.Aborted, + JobRunStatus.Completed, + JobRunStatus.Failed, + + }); + JobRunSelectedStatuses.SelectionChanged -= (x,y)=> RaisePropertyChanged(nameof(JobRunSelectedStatuses)); + JobRunSelectedStatuses.SelectionChanged += (x, y) => RaisePropertyChanged(nameof(JobRunSelectedStatuses)); + + IsGradientSelection = new SelectedObjectCollection<bool>(new ObservableCollection<bool> + { + true, + false + }, new ObservableCollection<bool> + { + true, + false + }); + IsGradientSelection.SelectionChanged -= (x, y) => RaisePropertyChanged(nameof(IsGradientSelection)); + IsGradientSelection.SelectionChanged += (x, y) => RaisePropertyChanged(nameof(IsGradientSelection)); + JobRunsProvider = new SuggestionProvider((filter) => + { + try + { + SelectedJobName = filter; + return _allJobRuns.Where(x => x.JobName != null && x.JobName.ToString().StartsWith(filter, StringComparison.CurrentCultureIgnoreCase)).ToList(); + } + catch + { + return null; + } + }); + } - public async void Init() { using (_notification.PushTaskItem("Loading job runs...")) @@ -140,9 +234,13 @@ namespace Tango.MachineStudio.Statistics.ViewModels using (var db = ObservablesContext.CreateDefault()) { + _allJobRuns = await db.JobRuns.ToListAsync(); ; _allMachines = await db.Machines.ToListAsync(); - _allUsers = await db.Users.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(); SelectedMachines = new SelectedObjectCollection<Machine>(_allMachines.ToObservableCollection(), new ObservableCollection<Machine>()); + SelectedThreads = new SelectedObjectCollection<RmlModel>(_rmlsModels.ToObservableCollection(), new ObservableCollection<RmlModel>()); + } } catch (Exception ex) @@ -155,12 +253,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels } } } - - private async void GetJobRuns() - { - await LoadJobRuns(); - } - + private async Task LoadJobRuns() { using (_notification.PushTaskItem("Loading job runs...")) @@ -175,24 +268,25 @@ namespace Tango.MachineStudio.Statistics.ViewModels TimeSpan offsetTime = (EndSelectedDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(23, 59, 59); DateTime endUtc = EndSelectedDate.ToUniversalTime() + offsetTime; - var runs = await db.JobRuns.Select(x => new JobRunModel() + var runs = await new JobRunsBuilder(db).Set(x => x.ActualStartDate <= DbFunctions.TruncateTime(endUtc) && x.ActualStartDate >= DbFunctions.TruncateTime(startUtc.Date)) + .WithMachines(SelectedMachines.SynchedSource.ToList()) + .WithJobSource(JobRunSelectedSources.SynchedSource) + .WithJobStatus(JobRunSelectedStatuses.SynchedSource) + .WithGradient(IsGradientSelection.SynchedSource) + .Query(y => y.Where(x => (String.IsNullOrEmpty(SelectedJobName) || x.JobName.ToString().ToLower().StartsWith(SelectedJobName.ToLower())) + && ( x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue) + )) + .BuildListAsync(); + + var modelList = runs.Select(x => new JobRunModel() { JobRun = x, Machine = _allMachines.FirstOrDefault(y => y.Guid == x.MachineGuid), User = _allUsers.SingleOrDefault(y => y.Guid == x.UserGuid), - }).ToListAsync(); + }).ToList(); - // .Query(y => y.Where - //(x => JobName == null || - //(x.JobName.ToString().ToLower().StartsWith(JobName) - //|| Length == null || (x.JobLength == Length) - //|| IsGradient == null || (x.IsGradient != null && x.IsGradient == IsGradient) - //|| ( x.JobRunSource == JobRunSource)))) - //.BuildAsync(); - - runs.ForEach(x => x.Init()); - - JobRuns = runs; + modelList.ForEach(x => x.Init()); + JobRuns = modelList.ToObservableCollection(); } } catch (Exception ex) @@ -205,5 +299,6 @@ namespace Tango.MachineStudio.Statistics.ViewModels } } } + } } |
