From 526019f244c1fc6f08361cd15cfce47927048823 Mon Sep 17 00:00:00 2001 From: Victoria Plitt Date: Sun, 13 Sep 2020 11:55:25 +0300 Subject: Dispenser Analyzer. A new analyzer was added - Process. Added additional level of Generic interfaces and implementation. --- .../ViewModels/MainWindowVM.cs | 143 ++++++++------------- 1 file changed, 56 insertions(+), 87 deletions(-) (limited to 'Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs') diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs index 38f8dee81..48d426d23 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs @@ -126,7 +126,24 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels } } - + private string _titleAxisBottom; + + public string TitleAxisBottom + { + get { return _titleAxisBottom; } + set { _titleAxisBottom = value; RaisePropertyChangedAuto(); } + } + + private string _titleAxisLeft; + + public string TitleAxisLeft + { + get { return _titleAxisLeft; } + set { _titleAxisLeft = value; RaisePropertyChangedAuto(); } + } + + + private bool _isRunning; /// /// Gets or sets a value indicating whether this instance is running. @@ -162,7 +179,8 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels XStep = 1; AnalyzerResults = new ObservableCollection(); _isRunning = false; - + TitleAxisBottom = ""; + TitleAxisLeft = ""; this.Points = new List(); } @@ -251,69 +269,38 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels return; ResetSettings(); - IAnalyzer analyzer = AnalysisService.GetAnalyzer(OpenFilePath); + var analyzer = AnalysisService.GetAnalyzer(OpenFilePath); if (analyzer == null) return; IsRunning = true; - AnalyzerAttribute attribute = (AnalyzerAttribute)analyzer.GetType().GetCustomAttributes(typeof(AnalyzerAttribute), true).FirstOrDefault(); - - TestName = attribute.Name; - List data = CsvFile.Read(new CsvSource(OpenFilePath)).ToList(); - List samples = new List(); - - To = 0; - From = 0; - int index = 0; - int last_labelIndex = 0; - - - foreach (var item in data) + AnalyzerAttribute[] attr = analyzer.GetType().GetCustomAttributes(typeof(AnalyzerAttribute), true); + if (attr != null && attr.Count() > 0) { - double pressure = 0; - if(item.Label == "Label") - { - item.Pressure = "0"; - item.Command = "Label"; - if (last_labelIndex == 0 || last_labelIndex < (index + 5)) - { - last_labelIndex = index; - - OxyPlot.Wpf.LineAnnotation _line = new OxyPlot.Wpf.LineAnnotation() - { - StrokeThickness = 1, - Color = Color.FromRgb(255, 5, 5), - Type = LineAnnotationType.Vertical, - Text = index.ToString(), - X = index, - }; - PlotControl.Annotations.Add(_line); - - } - } - if (double.TryParse(item.Pressure, out pressure) || !String.IsNullOrWhiteSpace(item.Command)) - { - samples.Add(new DispenserSample() - { - Pressure = pressure, - Command = String.IsNullOrWhiteSpace(item.Command) ? null : item.Command, - Index = index - }); - index++; - } + TestName = attr[0].Name; + } + List annotations = new List(); + var samples = analyzer.Reader.ReadScvFile(OpenFilePath, annotations); + analyzer.GetPoints(samples, Points); + if (Points.Count == 0) + { + IsRunning = false; + return; } + annotations.ForEach(x => PlotControl.Annotations.Add(x)); + To = 0; + From = 0; + List res = await analyzer.Process(samples, false); AnalyzerResults = new ObservableCollection(res); - samples.ForEach(x => - { - if (x.Pressure != 0.0) - { Points.Add(new DataPoint(x.Index, x.Pressure)); } - }); _to = Points.Max(x => x.Y); _from = TestName.Contains("sealtest") ? Points.FirstOrDefault(x => x.X == 0).Y : Points.Min(x => x.Y); + List titles = analyzer.Reader.GetTitles(OpenFilePath); + TitleAxisBottom = titles[0]; + TitleAxisLeft = titles[1]; - data.Clear(); + // data.Clear(); _to += 100; RaisePropertyChanged("To"); if (_from != 0) @@ -324,8 +311,10 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels IsRunning = false; PlotControl.InvalidatePlot(true); - await PrintToXpsFile(); - + if(analyzer.Reader.PrintResultsToPDFFile()) + { + await PrintToXpsFile(); + } } /// @@ -338,44 +327,24 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels if (false == File.Exists(OpenFilePath) || IsFileLocked(OpenFilePath)) return; - IAnalyzer analyzer = AnalysisService.GetAnalyzer(OpenFilePath); + var analyzer = AnalysisService.GetAnalyzer(OpenFilePath); if (analyzer == null) return; - - AnalyzerAttribute attribute = (AnalyzerAttribute)analyzer.GetType().GetCustomAttributes(typeof(AnalyzerAttribute), true).FirstOrDefault(); - - TestName = attribute.Name; - List data = CsvFile.Read(new CsvSource(OpenFilePath)).ToList(); - List samples = new List(); - - int index = 0; - int last_labelIndex = 0; + AnalyzerAttribute[] attr = analyzer.GetType().GetCustomAttributes(typeof(AnalyzerAttribute), true); + if (attr != null && attr.Count() > 0) + { + TestName = attr[0].Name; + } - foreach (var item in data) + List annotations = new List(); + var samples = analyzer.Reader.ReadScvFile(OpenFilePath, annotations); + analyzer.GetPoints(samples, Points); + if (Points.Count == 0) { - double pressure = 0; - if (item.Label == "Label") - { - item.Pressure = "0"; - item.Command = "Label"; - if (last_labelIndex == 0 || last_labelIndex < (index + 5)) - { - last_labelIndex = index; - } - } - if (double.TryParse(item.Pressure, out pressure) || !String.IsNullOrWhiteSpace(item.Command)) - { - samples.Add(new DispenserSample() - { - Pressure = pressure, - Command = String.IsNullOrWhiteSpace(item.Command) ? null : item.Command, - Index = index - }); - index++; - } + return; } - + List res = await analyzer.Process(samples, true); AnalyzerResults = new ObservableCollection(res); -- cgit v1.3.1