aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels
diff options
context:
space:
mode:
authorRoy Ben-Shabat <Roy@Twine-s.com>2020-03-05 16:43:50 +0200
committerRoy Ben-Shabat <Roy@Twine-s.com>2020-03-05 16:43:50 +0200
commit937b2a545fc7405f4673377b209caf22f00375b7 (patch)
tree2ad1eedef4cf0cf428f4a312648f0d453865b1f0 /Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/ViewModels
parent60988675685060adfc98b2d071c3e1df1e10fd87 (diff)
parent1834b13df30bcf71aab363f9e504c4e79b3f2224 (diff)
downloadTango-937b2a545fc7405f4673377b209caf22f00375b7.tar.gz
Tango-937b2a545fc7405f4673377b209caf22f00375b7.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.cs48
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();