diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-03-15 16:22:40 +0200 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2020-03-15 16:22:40 +0200 |
| commit | e5accfce2c661fab649bb57c33b63c679a67e60c (patch) | |
| tree | 1f29c4d77fd8e70736f4745b86a30abcf9bb3fd0 /Software/Visual_Studio/MachineStudio/Modules | |
| parent | 56678ae530fe45b0880053793ab46f47051e4dc6 (diff) | |
| parent | b188d7bfd91062f65474bd139bb8a434694f117b (diff) | |
| download | Tango-e5accfce2c661fab649bb57c33b63c679a67e60c.tar.gz Tango-e5accfce2c661fab649bb57c33b63c679a67e60c.zip | |
merge
Diffstat (limited to 'Software/Visual_Studio/MachineStudio/Modules')
3 files changed, 49 insertions, 40 deletions
diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs index 534bb364f..df2643d88 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/ViewModels/MainViewVM.cs @@ -16,12 +16,15 @@ using Tango.BL.ValueObjects; using Tango.Core.Commands; using Tango.Core.ExtensionMethods; using Tango.MachineStudio.Common; +using Tango.MachineStudio.Common.Notifications; using Tango.SharedUI.Components; namespace Tango.MachineStudio.ActionLogs.ViewModels { public class MainViewVM : StudioViewModel { + private INotificationProvider _notification; + #region Properties private DateTime _startSelectedDate; @@ -83,30 +86,23 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels set { _differenceObject = value; RaisePropertyChangedAuto(); } } - - private bool _isRunning; - public bool IsRunning - { - get { return _isRunning; } - set { _isRunning = value; } - } - #endregion public RelayCommand SearchCommand { get; set; } public RelayCommand CopyToClipBoardCommand { get; set; } public RelayCommand CopyRelateObjectIDCommand { get; set; } - public MainViewVM() + public MainViewVM(INotificationProvider notification) { + _notification = notification; + ActionLogs = new ObservableCollection<ActionLog>(); - SearchCommand = new RelayCommand(GetActionLogs, () => !IsRunning); + SearchCommand = new RelayCommand(GetActionLogs, () => IsFree); CopyRelateObjectIDCommand = new RelayCommand(CopyRelateObjectID); CopyToClipBoardCommand = new RelayCommand(CopyToClipBoard, () => SelectedActionLog != null && SelectedActionLog.DifferenceObject != null); DateTime now = DateTime.Now; StartSelectedDate = now.AddMonths(-1); EndSelectedDate = now; - _isRunning = false; var source = Enum.GetValues(typeof(ActionLogType)).Cast<ActionLogType>().ToObservableCollection(); var syncedSource = Enum.GetValues(typeof(ActionLogType)).Cast<ActionLogType>().ToObservableCollection(); @@ -139,27 +135,40 @@ namespace Tango.MachineStudio.ActionLogs.ViewModels if (String.IsNullOrWhiteSpace(filter)) filter = null; - using (ObservablesContext db = ObservablesContext.CreateDefault()) + try { - - DateTime startUtc = new DateTime(StartSelectedDate.Date.Ticks, DateTimeKind.Utc); - TimeSpan offsetTime = (EndSelectedDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(24, 0, 0); - DateTime endUtc = new DateTime(EndSelectedDate.Date.Ticks + offsetTime.Ticks, DateTimeKind.Utc); + IsFree = false; - Debug.Write($"TEST TIME {startUtc} from {endUtc} " + System.Environment.NewLine); + using (ObservablesContext db = ObservablesContext.CreateDefault()) + { - IsRunning = true; - ActionLogs = await new ActionLogsCollectionBuilder(db).Set(x => x.LastUpdated <= DbFunctions.TruncateTime(endUtc) && x.LastUpdated >= DbFunctions.TruncateTime(startUtc)) - .WithUsers() - .WithActionType(SelectedActionLogTypes.SynchedSource.ToArray()) - .Query(y => y.Where - (x => filter == null || - (x.ID.ToString().ToLower().StartsWith(filter) - || (x.RelatedObjectName != null && x.RelatedObjectName.ToLower().StartsWith(filter)) - || (x.RelatedObjectGuid != null && x.RelatedObjectGuid.ToLower().StartsWith(filter)) - || (x.User != null && x.User.Contact != null && x.User.Contact.FullName.ToLower().StartsWith(filter))))) - .BuildAsync(); - IsRunning = false; + DateTime startUtc = new DateTime(StartSelectedDate.Date.Ticks, DateTimeKind.Utc); + TimeSpan offsetTime = (EndSelectedDate.Date == DateTime.Now.Date) ? DateTime.Now.TimeOfDay : new TimeSpan(24, 0, 0); + DateTime endUtc = new DateTime(EndSelectedDate.Date.Ticks + offsetTime.Ticks, DateTimeKind.Utc); + + Debug.Write($"TEST TIME {startUtc} from {endUtc} " + System.Environment.NewLine); + + ActionLogs = await new ActionLogsCollectionBuilder(db).Set(x => x.LastUpdated <= DbFunctions.TruncateTime(endUtc) && x.LastUpdated >= DbFunctions.TruncateTime(startUtc)) + .WithUsers() + .WithActionType(SelectedActionLogTypes.SynchedSource.ToArray()) + .Query(y => y.Where + (x => filter == null || + (x.ID.ToString().ToLower().StartsWith(filter) + || (x.RelatedObjectName != null && x.RelatedObjectName.ToLower().StartsWith(filter)) + || (x.RelatedObjectGuid != null && x.RelatedObjectGuid.ToLower().StartsWith(filter)) + || (x.User != null && x.User.Contact != null && x.User.Contact.FullName.ToLower().StartsWith(filter))))) + .BuildAsync(); + } + } + catch (Exception ex) + { + IsFree = true; + LogManager.Log(ex, "Error getting action logs."); + _notification.ShowError($"Error occurred while trying to retrieve the action logs.\n{ex.Message}"); + } + finally + { + IsFree = true; } } diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml index 3a7eaa802..fd640bae5 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.ActionLogs/Views/MainView.xaml @@ -207,7 +207,7 @@ </DataGrid.Columns> </DataGrid> </Grid> - <Grid Grid.Row="1" Grid.Column="0" Visibility="{Binding IsRunning,Converter={StaticResource BooleanToVisibilityConverter}}"> + <Grid Grid.Row="1" Grid.Column="0" Visibility="{Binding IsBusy,Converter={StaticResource BooleanToVisibilityConverter}}"> <StackPanel Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center"> <mahapps:ProgressRing Margin="20 60 20 40" Width="80" Height="80" IsActive="{Binding IsRunning}"></mahapps:ProgressRing> <TextBlock Text="Loading..." HorizontalAlignment="Center" FontSize="20" FontStyle="Italic" VerticalAlignment="Center" Margin="0 20 0 0"></TextBlock> 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 ed52c2352..ed7bbec56 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 @@ -256,7 +256,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels { using (ObservablesContext db = ObservablesContext.CreateDefault()) { - return db.Jobs.Where(x => x.Name!= null && x.Name.ToLower().Contains(filter.ToLower())).ToList(); + return db.Jobs.Where(x => x.Name != null && x.Name.ToLower().Contains(filter.ToLower())).ToList(); } } else @@ -270,7 +270,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels return null; } }); - + StatisticsValueCollection = new StatisticsValueCollection(); } @@ -329,7 +329,7 @@ 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(jobName) || x.JobName.ToLower().StartsWith(jobName.ToLower())) + .Query(y => y.Where(x => (String.IsNullOrEmpty(jobName) || x.JobName.ToLower().StartsWith(jobName.ToLower())) && (x.JobLength < LengthUpperValue && x.JobLength >= LengthLowerValue))) .BuildListAsync(); @@ -346,7 +346,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels GenerateStatistics(); } - + } catch (Exception ex) { @@ -404,8 +404,8 @@ namespace Tango.MachineStudio.Statistics.ViewModels /// </summary> protected void GenerateAverageUploadDuration() { - var average = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.UploadDuration != null && z.UploadDuration.Value.Ticks > 0).Average(x => x.UploadDuration.Value.TotalMinutes); - StatisticsValueCollection.AddStatisticsValue("Average Upload Duration", Math.Max(average, 0), " minutes"); + var val = (long)JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.UploadDuration != null).Average(x => x.UploadDuration.Value.TotalMilliseconds); + StatisticsValueCollection.AddStatisticsValue("Average Upload Duration", Math.Max(TimeSpan.FromMilliseconds(val).TotalMinutes, 0), " minutes"); } /// <summary> @@ -452,7 +452,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels protected void CreateThreadConsumptionPerThread() { var temp = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.Rml != null).GroupBy(x => x.Rml.Name); - List <StatisticsValue> result = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.Rml != null && !String.IsNullOrEmpty(z.Rml.Name)).GroupBy(x => x.Rml.Name).Select(y => new StatisticsValue { Name = y.Key, Value = y.Sum(x => x.JobRun.EndPosition), Unit="m" }).ToList(); + List<StatisticsValue> result = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.Rml != null && !String.IsNullOrEmpty(z.Rml.Name)).GroupBy(x => x.Rml.Name).Select(y => new StatisticsValue { Name = y.Key, Value = y.Sum(x => x.JobRun.EndPosition), Unit = "m" }).ToList(); StatisticsValueCollection.CreateThreadConsumptionPerThread(result); } @@ -461,12 +461,12 @@ namespace Tango.MachineStudio.Statistics.ViewModels /// </summary> protected void GenerateAllLiquidQuantities() { - var db_liquidQuantities = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.LiquidQuantities.Count > 0).Select(y=> y.JobRun.LiquidQuantities).ToList(); + var db_liquidQuantities = JobRuns.Where(z => z.JobRun.EndPosition > 0 && z.JobRun.LiquidQuantities.Count > 0).Select(y => y.JobRun.LiquidQuantities).ToList(); List<JobRunLiquidQuantity> allLiquidQuantities = new List<JobRunLiquidQuantity>(); - + foreach (LiquidTypes ltype in (LiquidTypes[])Enum.GetValues(typeof(LiquidTypes))) { - var liquidQuantityByTypeList = db_liquidQuantities.Select(x => x.FirstOrDefault(y => y.LiquidType == ltype)).Where(x=>x!=null); + var liquidQuantityByTypeList = db_liquidQuantities.Select(x => x.SingleOrDefault(y => y.LiquidType == ltype)).Where(x => x != null); var count = liquidQuantityByTypeList != null ? liquidQuantityByTypeList.Sum(x => x.Quantity) : 0; JobRunLiquidQuantity lq = new JobRunLiquidQuantity() { LiquidType = ltype, Quantity = count }; allLiquidQuantities.Add(lq); |
