From 66d94b7757025c5d2f1a82428dc21f46efb604a6 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Mon, 19 Apr 2021 21:26:35 +0300 Subject: MS. Adding Organization & Site to Statistics. --- .../Models/OrganisationToSiteModel.cs | 54 ++++++++ .../Tango.MachineStudio.Statistics.csproj | 1 + .../ViewModels/JobRunsViewVM.cs | 137 +++++++++++++++++++-- .../Views/JobRunsView.xaml | 120 ++++++++++++++++-- .../Views/JobRunsView.xaml.cs | 12 ++ 5 files changed, 303 insertions(+), 21 deletions(-) create mode 100644 Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/OrganisationToSiteModel.cs (limited to 'Software/Visual_Studio/MachineStudio') diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/OrganisationToSiteModel.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/OrganisationToSiteModel.cs new file mode 100644 index 000000000..e24c7ba55 --- /dev/null +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Models/OrganisationToSiteModel.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.MachineStudio.Statistics.Models +{ + public class MachineModel + { + public string Guid { get; set; } + + public string Name { get; set; } + + public string SerialNumber { get; set; } + }; + + public class SiteModel + { + public string Guid { get; set; } + + public string Name { get; set; } + + public List Machines { get; set; } + + public SiteModel() + { + Machines = new List(); + } + }; + + public class OrganisationToSiteModel + { + public string Guid { get; set; } + + public string Name { get; set; } + + public List Sites { get; set; } + + public List Machines { get; set; } + + + public OrganisationToSiteModel() + { + Sites = new List(); + Machines = new List(); + } + + public override string ToString() + { + return Name; + } + }; +} 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 4ce0ea87d..5896b2c47 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 @@ -87,6 +87,7 @@ + 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 e1876e87e..e0b644fcf 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 @@ -41,6 +41,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels public class JobRunsViewVM : ViewModel { private INotificationProvider _notification; + private List _organizations; private List _allMachines; private List _allUsers; private List _rmlsModels; @@ -77,11 +78,72 @@ namespace Tango.MachineStudio.Statistics.ViewModels } } - private SelectedObjectCollection _selectedMachines; + private SelectedObjectCollection _selectedOrganizations; /// /// Gets or sets the selected machines. Contains all available machines and selected machines. Binding to ComboBox Machines. /// - public SelectedObjectCollection SelectedMachines + public SelectedObjectCollection SelectedOrganizations + { + get { return _selectedOrganizations; } + set + { + _selectedOrganizations = value; + RaisePropertyChangedAuto(); + } + } + + private bool _IsEnabledSelectionSites; + + public bool IsEnabledSelectionSites + { + get { return _IsEnabledSelectionSites; } + set { _IsEnabledSelectionSites = value; + RaisePropertyChangedAuto(); + } + } + + private bool _allSelectedSites; + + public bool AllSelectedSites + { + get { return _allSelectedSites; } + set { _allSelectedSites = value; + RaisePropertyChangedAuto(); + } + } + + + private SelectedObjectCollection _selectedSites; + /// + /// Gets or sets the selected machines. Contains all available machines and selected machines. Binding to ComboBox Machines. + /// + public SelectedObjectCollection SelectedSites + { + get { return _selectedSites; } + set + { + _selectedSites = value; + RaisePropertyChangedAuto(); + } + } + + private bool _allSelectedMachines; + + public bool AllSelectedMachines + { + get { return _allSelectedMachines; } + set + { + _allSelectedMachines = value; + RaisePropertyChangedAuto(); + } + } + + 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; } set @@ -236,7 +298,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels { _notification = notificationProvider; JobRuns = new ObservableCollection(); - LoadJobRunsCommand = new RelayCommand(async () => await LoadJobRuns(), () => IsFree); + LoadJobRunsCommand = new RelayCommand(async () => await LoadJobRuns(), () => IsFree && SelectedMachines.Source.Count >0); ExportToExcelCommand = new RelayCommand(ExportToExcel, () => IsFree); LengthUpperValue = 10000.0; LengthLowerValue = 0.0; @@ -325,12 +387,32 @@ namespace Tango.MachineStudio.Statistics.ViewModels using (var db = ObservablesContext.CreateDefault()) { + + _organizations = await db.Organizations.Select(x => new OrganisationToSiteModel(){ Name = x.Name, Guid = x.Guid}).ToListAsync(); + foreach(var org in _organizations) + { + org.Sites = await db.Sites.Where(y => y.OrganizationGuid == org.Guid).Select(y => new SiteModel(){ Guid = y.Guid,Name = y.Name,}).ToListAsync(); + foreach(var site in org.Sites) + { + site.Machines = await db.Machines.Where(x => x.SiteGuid == site.Guid).Select(y => new MachineModel(){Guid = y.Guid,Name = y.Name,SerialNumber = y.SerialNumber}).ToListAsync(); + } + org.Machines = await db.Machines.Where(y=> y.OrganizationGuid == org.Guid).Select(y => new MachineModel() {Guid = y.Guid, Name = y.Name, SerialNumber = y.SerialNumber }).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(); - SelectedMachines = new SelectedObjectCollection(_allMachines.ToObservableCollection(), new ObservableCollection()); - SelectedThreads = new SelectedObjectCollection(_rmlsModels.ToObservableCollection(), new ObservableCollection()); } + IsEnabledSelectionSites = false; + SelectedMachines = new SelectedObjectCollection(new ObservableCollection(), new ObservableCollection()); + SelectedThreads = new SelectedObjectCollection(_rmlsModels.ToObservableCollection(), new ObservableCollection()); + SelectedSites = new SelectedObjectCollection(new ObservableCollection(), new ObservableCollection()); + SelectedOrganizations = new SelectedObjectCollection(_organizations.ToObservableCollection(), _organizations.ToObservableCollection()); + SelectedOrganizations.SelectionChanged -= OnSelectedOrganizationsChanged; + SelectedOrganizations.SelectionChanged += OnSelectedOrganizationsChanged; + SelectedSites.SelectionChanged -= OnSelectedSitesChanged; + SelectedSites.SelectionChanged += OnSelectedSitesChanged; + AllSelectedSites = true; + AllSelectedMachines = true; } catch (Exception ex) { @@ -343,6 +425,46 @@ namespace Tango.MachineStudio.Statistics.ViewModels } } + + private void OnSelectedSitesChanged(object sender, EventArgs e) + { + if (SelectedSites.SynchedSource.Count > 0) + { + SelectedMachines = new SelectedObjectCollection(SelectedSites.SynchedSource.SelectMany(x => x.Machines).ToObservableCollection(), SelectedSites.SynchedSource.SelectMany(x => x.Machines).ToObservableCollection()); + } + else + { + SelectedMachines = new SelectedObjectCollection(SelectedOrganizations.SynchedSource.SelectMany(x => x.Machines).ToObservableCollection(), SelectedOrganizations.SynchedSource.SelectMany(x => x.Machines).ToObservableCollection()); + } + AllSelectedMachines = false; + AllSelectedMachines = true; + InvalidateRelayCommands(); + } + + private void OnSelectedOrganizationsChanged(object sender, EventArgs e) + { + if (SelectedOrganizations.SynchedSource.Count != SelectedOrganizations.Source.Count) + { + IsEnabledSelectionSites = true; + var selectedOrg = SelectedOrganizations.SynchedSource.ToList(); + SelectedSites = new SelectedObjectCollection(selectedOrg.SelectMany(x => x.Sites).ToObservableCollection(), selectedOrg.SelectMany(x => x.Sites).ToObservableCollection()); + SelectedSites.SelectionChanged -= OnSelectedSitesChanged; + SelectedSites.SelectionChanged += OnSelectedSitesChanged; + SelectedMachines = new SelectedObjectCollection(selectedOrg.SelectMany(x => x.Machines).ToObservableCollection(), selectedOrg.SelectMany(x => x.Machines).ToObservableCollection()); + AllSelectedSites = false; + AllSelectedSites = true; + } + else + { + SelectedSites = new SelectedObjectCollection(SelectedOrganizations.SynchedSource.SelectMany(x => x.Sites).ToObservableCollection(), SelectedOrganizations.SynchedSource.SelectMany(x => x.Sites).ToObservableCollection()); + AllSelectedSites = false; + IsEnabledSelectionSites = false; + SelectedMachines = new SelectedObjectCollection(SelectedOrganizations.SynchedSource.SelectMany(x => x.Machines).ToObservableCollection(), SelectedOrganizations.SynchedSource.SelectMany(x => x.Machines).ToObservableCollection()); + } + AllSelectedMachines = false; + AllSelectedMachines = true; + InvalidateRelayCommands(); + } /// /// Loads the job runs by filters. @@ -354,7 +476,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels try { IsFree = false; - + using (var db = ObservablesContext.CreateDefault()) { DateTime startUtc = new DateTime(StartSelectedDate.Year, StartSelectedDate.Month, StartSelectedDate.Day, 0, 0, 0).ToUniversalTime(); @@ -482,8 +604,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels JobRuns = modelList.ToObservableCollection(); GenerateStatistics(); } - - + } catch (Exception ex) { 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 bc99c1bfa..1184622f6 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 @@ -115,8 +115,102 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -145,7 +239,7 @@ - + @@ -161,7 +255,7 @@ - + Start Date: @@ -191,7 +285,7 @@ - + @@ -201,7 +295,7 @@ - + @@ -229,9 +323,9 @@ - + - + @@ -259,20 +353,20 @@ - + - + - + - + @@ -299,7 +393,7 @@ - + @@ -344,7 +438,7 @@ - + diff --git a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml.cs b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml.cs index 961d7f691..a2d129920 100644 --- a/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml.cs +++ b/Software/Visual_Studio/MachineStudio/Modules/Tango.MachineStudio.Statistics/Views/JobRunsView.xaml.cs @@ -67,6 +67,18 @@ namespace Tango.MachineStudio.Statistics.Views e.Handled = true; } + private void SelectOrganizationButton_Click(object sender, RoutedEventArgs e) + { + selectOrgButton.IsChecked = true; + e.Handled = true; + } + + private void SelectSiteButton_Click(object sender, RoutedEventArgs e) + { + selectSiteButton.IsChecked = true; + e.Handled = true; + } + private void SelectMachineButton_Click(object sender, RoutedEventArgs e) { selectThreadsButton.IsChecked = true; -- cgit v1.3.1 From ccaec5a493d2880c1d82b64bcad804fa51db6c57 Mon Sep 17 00:00:00 2001 From: Roy Ben Shabat Date: Sun, 25 Apr 2021 13:38:55 +0300 Subject: Job runs fixes. --- .../ViewModels/JobRunsViewVM.cs | 2 +- .../JobRuns/BasicJobRunsLogger.cs | 5 +++++ .../Tango.Integration/Operation/MachineOperator.cs | 22 ++++++++++++++++++++-- 3 files changed, 26 insertions(+), 3 deletions(-) (limited to 'Software/Visual_Studio/MachineStudio') 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 e0b644fcf..9494de3f9 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 @@ -833,7 +833,7 @@ namespace Tango.MachineStudio.Statistics.ViewModels { if (lq.Quantity < 0) { - Debug.WriteLine($"Warning: JobRun '{run.JobRun.ID}' contains an invalid value '{lq.Quantity}' for {lq.LiquidType} quantity."); + Debug.WriteLine($"Warning: JobRun '{run.JobRun.ID}' of machine '{run.Machine?.SerialNumber}' with user '{run.User?.Email}' started on '{run.JobRun.StartDate.ToLocalTime()}' ended on '{run.JobRun.EndDate.ToLocalTime()}' contains an invalid value '{lq.Quantity}' for {lq.LiquidType} quantity."); } total_quantities[lq.LiquidType] += Convert.ToUInt64(Math.Max(lq.Quantity, 0)); diff --git a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs index 7ba38c9ca..2b7c931f0 100644 --- a/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs +++ b/Software/Visual_Studio/Tango.Integration/JobRuns/BasicJobRunsLogger.cs @@ -8,6 +8,7 @@ using Tango.BL.Builders; using Tango.BL.Entities; using Tango.BL.Enumerations; using Tango.Core; +using Tango.Core.ExtensionMethods; using Tango.Integration.Operation; namespace Tango.Integration.JobRuns @@ -177,6 +178,8 @@ namespace Tango.Integration.JobRuns job.LastRun = DateTime.UtcNow; } + LogManager.Log($"Inserting job run for '{run.JobName}'...\n{run.ToJsonString(nameof(JobRun.JobString), nameof(JobRun.LiquidQuantityString))}"); + db.SaveChanges(); } } @@ -264,6 +267,8 @@ namespace Tango.Integration.JobRuns db.JobRuns.Add(run); + LogManager.Log($"Inserting head cleaning job run...\n{run.ToJsonString(nameof(JobRun.JobString), nameof(JobRun.LiquidQuantityString))}"); + db.SaveChanges(); } } diff --git a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs index bf21df35d..5bceef5aa 100644 --- a/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs +++ b/Software/Visual_Studio/Tango.Integration/Operation/MachineOperator.cs @@ -45,6 +45,7 @@ using Tango.PMR.Power; using Tango.PMR.ThreadLoading; using Tango.BL.DTO; using Tango.PMR.IFS; +using System.Diagnostics; namespace Tango.Integration.Operation { @@ -1701,7 +1702,6 @@ namespace Tango.Integration.Operation processParameters = cache.ProcessParametersDTO.ToObservable(); job = cache.JobDTO.ToObservable(); configuration = cache.MachineConfigurationDTO.ToObservable(); - _machineStatusBeforeJobStart = cache.MachineStatus; CurrentProcessParameters = processParameters; } catch (Exception ex) @@ -1752,6 +1752,14 @@ namespace Tango.Integration.Operation RunningJobStatus = s; }; + if (MachineStatus != null) + { + _machineStatusBeforeJobStart = MachineStatus.Clone(); + } + else + { + _machineStatusBeforeJobStart = cache.MachineStatus.Clone(); + } _jobStartDate = DateTime.UtcNow; _jobUploadingStartDate = _jobStartDate; @@ -2165,6 +2173,8 @@ namespace Tango.Integration.Operation /// The handler. private void SaveLastJobLiquidQuantities(Job job, Configuration configuration, ProcessParametersTable processParameters, JobHandler handler) { + LogManager.Log($"Calculating job run liquid quantities using '{JobLiquidQuantityCalculationMode}' method..."); + if (configuration == null) { configuration = _machineConfiguration; @@ -2183,6 +2193,12 @@ namespace Tango.Integration.Operation if (packLevelAfter != null && packLevelBefore != null) { + if (packLevelAfter.DispenserLevel > packLevelBefore.DispenserLevel) + { + LogManager.Log($"Invalid '{pack.LiquidType.Name}' dispenser level calculated: {packLevelBefore.DispenserLevel} - {packLevelAfter.DispenserLevel} = {packLevelBefore.DispenserLevel - packLevelAfter.DispenserLevel}. Ignoring..."); + continue; + } + _lastJobLiquidQuantities.Add(new BL.ValueObjects.JobRunLiquidQuantity() { LiquidType = pack.LiquidType.Type, @@ -2195,10 +2211,12 @@ namespace Tango.Integration.Operation { _lastJobLiquidQuantities = CreateJobRunLiquidQuantities(job, configuration, processParameters, handler.Status.Progress, handler.Status.TotalProgress); } + + LogManager.Log($"Job run liquid quantities calculation completed:\n{_lastJobLiquidQuantities.ToJsonString()}"); } catch (Exception ex) { - LogManager.Log(ex, LogCategory.Critical, "Error saving last job liquid quantities."); + LogManager.Log(ex, LogCategory.Critical, "Error calculating and saving last job run liquid quantities."); } } -- cgit v1.3.1