diff options
| author | Avi Levkovich <avi@twine-s.com> | 2020-03-08 14:01:38 +0200 |
|---|---|---|
| committer | Avi Levkovich <avi@twine-s.com> | 2020-03-08 14:01:38 +0200 |
| commit | a77c1ba4a7e45cae6b4de180fb625d1f1685988b (patch) | |
| tree | 1d07b0e67fa340dd5e22f9b293a3e5eaa7177b48 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels | |
| parent | 89235be35397d91ad5e8cadd59cd009b8d682960 (diff) | |
| parent | 0bafe1c34cb056a80b64d6a03c0dcf0fc921adca (diff) | |
| download | Tango-a77c1ba4a7e45cae6b4de180fb625d1f1685988b.tar.gz Tango-a77c1ba4a7e45cae6b4de180fb625d1f1685988b.zip | |
Merge branch 'master' of https://twinetfs.visualstudio.com/_git/Tango
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels')
| -rw-r--r-- | Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels/JobRunsViewVM.cs | 48 |
1 files changed, 25 insertions, 23 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 07e431751..a51d18909 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<Machine> _allMachines; private List<User> _allUsers; private List<RmlModel> _rmlsModels; - private List<Job> _allJobRuns; #region Properties @@ -172,7 +171,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels /// </summary> public ISuggestionProvider JobsProvider { get; set; } - private Job _selectedJob; + private Job _selectedJob; /// <summary> /// Gets or sets the job. Used as Sele /// </summary> @@ -182,17 +181,10 @@ namespace Tango.MachineStudio.Statistics.ViewModels set { _selectedJob = value; - SelectedJobName = _selectedJob != null ? _selectedJob.Name : ""; RaisePropertyChangedAuto(); } } - /// <summary> - /// Gets or sets the name of the selected job. Used in filter. - /// </summary> - 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<JobRunModel>(); - 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<bool>(new ObservableCollection<bool> @@ -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<Job>(); + } } - catch + catch (Exception ex) { + LogManager.Log(ex, "Error loading jobs."); return null; } }); - + } /// <summary> @@ -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<Machine>(_allMachines.ToObservableCollection(), new ObservableCollection<Machine>()); SelectedThreads = new SelectedObjectCollection<RmlModel>(_rmlsModels.ToObservableCollection(), new ObservableCollection<RmlModel>()); - } } catch (Exception ex) @@ -311,24 +311,26 @@ 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)) + var runs = await new JobRunsCollectionBuilder(db).Set(x => x.StartDate <= DbFunctions.TruncateTime(endUtc) && x.StartDate >= DbFunctions.TruncateTime(startUtc.Date)) .WithMachines(SelectedMachines.SynchedSource.ToList()) .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) - )) + .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() { JobRun = x, Machine = _allMachines.FirstOrDefault(y => y.Guid == x.MachineGuid), User = _allUsers.SingleOrDefault(y => y.Guid == x.UserGuid), - }).ToList(); + Rml = _rmlsModels.SingleOrDefault(y => y.Guid == x.RmlGuid) + }).OrderByDescending(x => x.JobRun.StartDate).ToList(); modelList.ForEach(x => x.Init()); JobRuns = modelList.ToObservableCollection(); |
