aboutsummaryrefslogtreecommitdiffstats
path: root/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs
diff options
context:
space:
mode:
authorAvi Levkovich <avi@twine-s.com>2020-08-25 10:08:01 +0300
committerAvi Levkovich <avi@twine-s.com>2020-08-25 10:08:01 +0300
commit338edba081dba2a2aefb634811be1cc84ec93d64 (patch)
tree0021538796c254a8eab8527e8461a2e831e68c1c /Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs
parent49ddda1cc22d6cbb72f499b37e5db32c95252dfa (diff)
downloadTango-338edba081dba2a2aefb634811be1cc84ec93d64.tar.gz
Tango-338edba081dba2a2aefb634811be1cc84ec93d64.zip
merge
Diffstat (limited to 'Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs')
-rw-r--r--Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs146
1 files changed, 132 insertions, 14 deletions
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 70034b6e7..38f8dee81 100644
--- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs
+++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs
@@ -28,6 +28,8 @@ using PdfSharp;
using OxyPlot.Reporting;
using System.Threading;
using Tango.DispenserAnalyzer.UI.View;
+using Tango.Core.Helpers;
+using Tango.Documents;
namespace Tango.DispenserAnalyzer.UI.ViewModels
{
@@ -134,6 +136,7 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels
get { return _isRunning; }
set { _isRunning = value; RaisePropertyChangedAuto(); }
}
+
private ObservableCollection<IAnalyzerResult> _analyzerResults;
public ObservableCollection<IAnalyzerResult> AnalyzerResults
{
@@ -233,13 +236,18 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels
#endregion
#region Generate
+
public bool CanGenerate()
{
return (OpenFilePath!= null && OpenFilePath.Length != 0 && File.Exists(OpenFilePath));
}
+
+ /// <summary>
+ /// Generates all results.
+ /// </summary>
public async void Generate()
{
- if (false == File.Exists(OpenFilePath) || IsFileLocked(OpenFilePath) )
+ if (false == File.Exists(OpenFilePath) || IsFileLocked(OpenFilePath))
return;
ResetSettings();
@@ -248,17 +256,18 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels
return;
IsRunning = true;
- AnalyzerAttribute attribute = (AnalyzerAttribute)analyzer.GetType().GetCustomAttributes(typeof(AnalyzerAttribute),true).FirstOrDefault();
-
+ AnalyzerAttribute attribute = (AnalyzerAttribute)analyzer.GetType().GetCustomAttributes(typeof(AnalyzerAttribute), true).FirstOrDefault();
+
TestName = attribute.Name;
- List<DispenserCsvRow> data = CsvFile.Read<DispenserCsvRow>(new CsvSource(OpenFilePath)).ToList();
+ List<DispenserCsvRow> data = CsvFile.Read<DispenserCsvRow>(new CsvSource(OpenFilePath)).ToList();
List<DispenserSample> samples = new List<DispenserSample>();
To = 0;
From = 0;
int index = 0;
int last_labelIndex = 0;
-
+
+
foreach (var item in data)
{
double pressure = 0;
@@ -269,6 +278,7 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels
if (last_labelIndex == 0 || last_labelIndex < (index + 5))
{
last_labelIndex = index;
+
OxyPlot.Wpf.LineAnnotation _line = new OxyPlot.Wpf.LineAnnotation()
{
StrokeThickness = 1,
@@ -278,11 +288,13 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels
X = index,
};
PlotControl.Annotations.Add(_line);
+
}
}
if (double.TryParse(item.Pressure, out pressure) || !String.IsNullOrWhiteSpace(item.Command))
{
- samples.Add(new DispenserSample(){
+ samples.Add(new DispenserSample()
+ {
Pressure = pressure,
Command = String.IsNullOrWhiteSpace(item.Command) ? null : item.Command,
Index = index
@@ -290,27 +302,84 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels
index++;
}
}
- List<IAnalyzerResult> res = await analyzer.Process(samples);
+ List<IAnalyzerResult> res = await analyzer.Process(samples, false);
AnalyzerResults = new ObservableCollection<IAnalyzerResult>(res);
-
- samples.ForEach(x => { if (x.Pressure != 0.0)
+
+ 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);
+ _to = Points.Max(x => x.Y);
+ _from = TestName.Contains("sealtest") ? Points.FirstOrDefault(x => x.X == 0).Y : Points.Min(x => x.Y);
data.Clear();
_to += 100;
RaisePropertyChanged("To");
- if(_from != 0)
+ if (_from != 0)
_from -= 100;
RaisePropertyChanged("From");
XStep = (int)(Points.Count / 5);
-
+
IsRunning = false;
PlotControl.InvalidatePlot(true);
-
+
await PrintToXpsFile();
+
+ }
+
+ /// <summary>
+ /// Generates all results from command line and close application.
+ /// </summary>
+ public async Task GenerateInBackground(string openFilePath)
+ {
+ OpenFilePath = openFilePath;
+
+ if (false == File.Exists(OpenFilePath) || IsFileLocked(OpenFilePath))
+ return;
+
+ IAnalyzer analyzer = AnalysisService.GetAnalyzer(OpenFilePath);
+ if (analyzer == null)
+ return;
+
+ AnalyzerAttribute attribute = (AnalyzerAttribute)analyzer.GetType().GetCustomAttributes(typeof(AnalyzerAttribute), true).FirstOrDefault();
+
+ TestName = attribute.Name;
+ List<DispenserCsvRow> data = CsvFile.Read<DispenserCsvRow>(new CsvSource(OpenFilePath)).ToList();
+ List<DispenserSample> samples = new List<DispenserSample>();
+
+ int index = 0;
+ int last_labelIndex = 0;
+
+
+ foreach (var item in data)
+ {
+ 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++;
+ }
+ }
+
+ List<IAnalyzerResult> res = await analyzer.Process(samples, true);
+ AnalyzerResults = new ObservableCollection<IAnalyzerResult>(res);
+
+ await ExportResultsToTextFile();
}
#endregion
@@ -487,5 +556,54 @@ namespace Tango.DispenserAnalyzer.UI.ViewModels
}
#endregion
+
+ #region ExportToExel
+
+ public async Task ExportResultsToTextFile()
+ {
+ var resultFile = FileHelper.GetResultFilePath();
+ var dir = Path.GetDirectoryName(resultFile);
+ var name = Path.GetFileNameWithoutExtension(resultFile);
+ string fileNameWithoutExtension = Path.Combine(dir, name);
+ String sourceFile = String.Format($"{fileNameWithoutExtension}s.txt");
+ File.Delete(sourceFile);
+
+ await Task.Factory.StartNew(() =>
+ {
+ try
+ {
+ List<IAnalyzerResult> results = AnalyzerResults.ToList();
+
+ using (StreamWriter outputFile = new StreamWriter(sourceFile))
+ {
+ outputFile.WriteLine(String.Format($" {TestName.ToUpper()} RESULTS: "));
+ outputFile.WriteLine("");
+ outputFile.WriteLine("");
+ foreach (var res in results)
+ {
+ if (res.GetType().IsSubclassOf(typeof(AnalyzerResultBase)))
+ {
+ List<AnalyzerResultProperty> properties = (res as AnalyzerResultBase).Properties;
+ foreach (var prop in properties)
+ {
+ outputFile.WriteLine(String.Format($" {prop.Name} : {prop.Value}"));
+ }
+ string resV = String.Format($" RESULT = {res.Result.ToString()}");
+ outputFile.WriteLine(resV);
+ outputFile.WriteLine("");
+ }
+ }
+ outputFile.Flush();
+ }
+ }
+ catch (Exception ex)
+ {
+ Debug.WriteLine(ex);
+ }
+ });
+
+ }
+ #endregion
+
}
}