diff options
| author | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2019-12-09 16:59:59 +0200 |
|---|---|---|
| committer | Victoria Plitt <Victoria.Plitt@twine-s.com> | 2019-12-09 16:59:59 +0200 |
| commit | 4417c2eccb3795330144afa39e3bf271652bd31f (patch) | |
| tree | 9a2ebd1c680f12f04e1ecd7b0eaea58236379e81 /Software/Visual_Studio | |
| parent | 4fb7e23ead019e9c2b573eb4ccc89444fb5a7a6f (diff) | |
| download | Tango-4417c2eccb3795330144afa39e3bf271652bd31f.tar.gz Tango-4417c2eccb3795330144afa39e3bf271652bd31f.zip | |
Dispenser Jid - Test examples. Create DispenserAnalyser utility project. Seal test.
Diffstat (limited to 'Software/Visual_Studio')
20 files changed, 739 insertions, 9 deletions
diff --git a/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs b/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs index 6d1deded2..ec5b07630 100644 --- a/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs +++ b/Software/Visual_Studio/Tango.CSV/CsvFileReader.cs @@ -240,22 +240,39 @@ namespace Tango.CSV /// <param name="c">The c.</param> /// <param name="staticMember">if set to <c>true</c> [static member].</param> /// <returns></returns> - private static Action<T, string> FindSetter(string c, bool staticMember) + private static Action<T, string> FindSetter(string c, bool staticMember, int? index = null) { var flags = BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.IgnoreCase | (staticMember ? BindingFlags.Static : BindingFlags.Instance); Action<T, string> action = null; + PropertyInfo pi = typeof(T).GetProperty(c, flags); if (pi != null) { var pFunc = StringToObject(pi.PropertyType); action = EmitSetValueAction(pi, pFunc); } - FieldInfo fi = typeof(T).GetField(c, flags); - if (fi != null) + + if (action == null) + { + FieldInfo fi = typeof(T).GetField(c, flags); + if (fi != null) + { + var fFunc = StringToObject(fi.FieldType); + action = EmitSetValueAction(fi, fFunc); + } + } + + if (action == null && index != null) { - var fFunc = StringToObject(fi.FieldType); - action = EmitSetValueAction(fi, fFunc); + var propByIndex = typeof(T).GetProperties(flags).SingleOrDefault(x => x.GetCustomAttribute<CsvOrderAttribute>() != null && x.GetCustomAttribute<CsvOrderAttribute>().Index == index); + + if (propByIndex != null) + { + var pFunc = StringToObject(propByIndex.PropertyType); + action = EmitSetValueAction(propByIndex, pFunc); + } } + return action; } @@ -292,7 +309,7 @@ namespace Tango.CSV Action<T, string> action = null; if (columnName.IndexOf(' ') >= 0) columnName = columnName.Replace(" ", ""); - action = FindSetter(columnName, false) ?? FindSetter(columnName, true); + action = FindSetter(columnName, false, i) ?? FindSetter(columnName, true, i); list.Add(action); } diff --git a/Software/Visual_Studio/Tango.CSV/CsvOrderAttribute.cs b/Software/Visual_Studio/Tango.CSV/CsvOrderAttribute.cs new file mode 100644 index 000000000..cf04334cb --- /dev/null +++ b/Software/Visual_Studio/Tango.CSV/CsvOrderAttribute.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.CSV +{ + [AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)] + public class CsvOrderAttribute : Attribute + { + public int Index { get; set; } + + public CsvOrderAttribute(int index) + { + Index = index; + } + } +} diff --git a/Software/Visual_Studio/Tango.CSV/Tango.CSV.csproj b/Software/Visual_Studio/Tango.CSV/Tango.CSV.csproj index eee9649e6..c3e455ff1 100644 --- a/Software/Visual_Studio/Tango.CSV/Tango.CSV.csproj +++ b/Software/Visual_Studio/Tango.CSV/Tango.CSV.csproj @@ -85,6 +85,7 @@ <Compile Include="CsvFileLinqExtensions.cs" /> <Compile Include="CsvFileReader.cs" /> <Compile Include="CsvIgnoreAttribute.cs" /> + <Compile Include="CsvOrderAttribute.cs" /> <Compile Include="CsvSource.cs" /> <Compile Include="Properties\AssemblyInfo.cs" /> </ItemGroup> diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalysisPlotValue.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalysisPlotValue.cs new file mode 100644 index 000000000..3c9fe8cab --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalysisPlotValue.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI.Analysis +{ + public class AnalysisPlotValue + { + public double X { get; set; } + public double Y { get; set; } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalysisService.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalysisService.cs new file mode 100644 index 000000000..5aecc4e99 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalysisService.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI.Analysis +{ + public class AnalysisService + { + public static IAnalyzer GetAnalyzer(String fileName) + { + var analyzerTypes = typeof(AnalysisService).Assembly.GetTypes().Where(x => typeof(IAnalyzer).IsAssignableFrom(x)).ToList(); + var analyzerType = analyzerTypes.SingleOrDefault(x => fileName.ToLower().Contains(x.GetCustomAttribute<AnalyzerAttribute>().Name)); + return (analyzerType != null) ? Activator.CreateInstance(analyzerType) as IAnalyzer : null; + + } + public static string GetTestName(String fileName) + { + var analyzerTypes = typeof(AnalysisService).Assembly.GetTypes().Where(x => typeof(IAnalyzer).IsAssignableFrom(x)).ToList(); + var analyzerType = analyzerTypes.SingleOrDefault(x => fileName.Contains(x.GetCustomAttribute<AnalyzerAttribute>().Name)); + return analyzerType.GetCustomAttribute<AnalyzerAttribute>().Name; + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerAttribute.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerAttribute.cs new file mode 100644 index 000000000..2a1d3323e --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerAttribute.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI.Analysis +{ + [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Interface)] + public class AnalyzerAttribute : Attribute + { + public string Name { get; set; } + + public AnalyzerAttribute(string name) + { + Name = name; + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerResultBase.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerResultBase.cs new file mode 100644 index 000000000..0abf97117 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerResultBase.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI.Analysis +{ + public class AnalyzerResultBase : IAnalyzerResult + { + public AnalyzerResultValue Result { get; set; } + public List<AnalysisPlotValue> PlotValues { get; set; } + + public List<AnalyzerResultProperty> Properties + { + get + { + List<AnalyzerResultProperty> props = new List<AnalyzerResultProperty>(); + if (this.GetType() == typeof(AnalyzerResultBase)) + return props; + + foreach (var prop in this.GetType().GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.DeclaredOnly)) + { + AnalyzerResultProperty aProp = new AnalyzerResultProperty(); + + if (prop.GetCustomAttribute<DescriptionAttribute>() != null) + { + aProp.Name = prop.GetCustomAttribute<DescriptionAttribute>().Description; + } + else + { + aProp.Name = prop.Name; + } + + aProp.Value = prop.GetValue(this).ToString(); + + props.Add(aProp); + } + + return props; + } + } + + public AnalyzerResultBase() + { + PlotValues = new List<AnalysisPlotValue>(); + Result = AnalyzerResultValue.Undetermined; + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerResultProperty.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerResultProperty.cs new file mode 100644 index 000000000..f2548746e --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerResultProperty.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI.Analysis +{ + public class AnalyzerResultProperty + { + public String Name { get; set; } + public String Value { get; set; } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerResultValue.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerResultValue.cs new file mode 100644 index 000000000..ee0e5673d --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/AnalyzerResultValue.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI.Analysis +{ + public enum AnalyzerResultValue + { + //Undetermined + [Description("test-tube-empty")] + Undetermined, + [Description("Check")] + Passed, + [Description("CloseCircle")] + Failed, + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzer.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzer.cs new file mode 100644 index 000000000..9ca05ec1e --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzer.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.DispenserAnalyzer.UI.Models; + +namespace Tango.DispenserAnalyzer.UI.Analysis +{ + [Analyzer("INTERFACE")] + public interface IAnalyzer + { + Task<IAnalyzerResult> Process(List<DispenserSample> csvRows); + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzerResult.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzerResult.cs new file mode 100644 index 000000000..9adbc889d --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analysis/IAnalyzerResult.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI.Analysis +{ + public interface IAnalyzerResult + { + AnalyzerResultValue Result { get; set; } + List<AnalysisPlotValue> PlotValues { get; set; } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/SealingAnalyer.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/SealingAnalyer.cs new file mode 100644 index 000000000..911976821 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Analyzers/SealingAnalyer.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.DispenserAnalyzer.UI.Analysis; +using Tango.DispenserAnalyzer.UI.Models; + +namespace Tango.DispenserAnalyzer.UI.Analyzers +{ + [Analyzer("seal")] + public class SealingAnalyer : IAnalyzer + { + public Task<IAnalyzerResult> Process(List<DispenserSample> csvRows) + { + return Task.Factory.StartNew<IAnalyzerResult>(() => + { + List<DispenserSample> commands = csvRows.Where(x => x.Command != null).ToList< DispenserSample>(); + SealingAnalyzerResult result = new SealingAnalyzerResult(); + var pairs = commands.Select((x, i) => new { Index = i, Value = x }).GroupBy(x => x.Index /2).Select(x => x.Select(v => v.Value).ToList()).ToList(); + //start range of test + if (pairs.Count > 0 && pairs[0].Count > 1) + { + List<DispenserSample> rangeTestValues = csvRows.Where(x => x.Index > pairs[0][0].Index && x.Index < pairs[0][1].Index).ToList(); + result.AverageStartTestValue = rangeTestValues.Average(t => t.Pressure); + //int avgMinIndex = rangeTestValues.Select(x => x.Index).Min(); + //int avgMaxIndex = rangeTestValues.Select(x => x.Index).Max(); + //result.Time = TimeSpan.FromMilliseconds((avgMaxIndex - avgMinIndex) * 10).TotalSeconds.ToString() + " sec"; + } + //end range of test + if (pairs.Count > 1 && pairs[1].Count > 1) + { + List<DispenserSample> rangeTestValues = csvRows.Where(x => x.Index > pairs[1][0].Index && x.Index < pairs[1][1].Index).ToList(); + result.AverageEndTestValue = rangeTestValues.Average(t => t.Pressure); ; + } + result.AbsoluteTestValue = Math.Abs(result.AverageEndTestValue - result.AverageStartTestValue); + result.Result = result.AbsoluteTestValue < 8 ? AnalyzerResultValue.Passed : AnalyzerResultValue.Failed; + return result; + }); + } + } + + public class SealingAnalyzerResult : AnalyzerResultBase + { + [Description("Average Start Test Value")] + public double AverageStartTestValue { get; set; } + [Description("Average End Test Value")] + public double AverageEndTestValue { get; set; } + //[Description("Average Duration Time")] + //public String Time { get; set; } + [Description("Absolute Value")] + public double AbsoluteTestValue { get; set; } + public SealingAnalyzerResult() + { + AverageStartTestValue = 0.0; + AverageEndTestValue = 0.0; + AbsoluteTestValue = 0.0; + Result = AnalyzerResultValue.Undetermined; + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/App.xaml b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/App.xaml index 27f44bf12..73d8ea48c 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/App.xaml +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/App.xaml @@ -1,9 +1,56 @@ <Application x:Class="Tango.DispenserAnalyzer.UI.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:sys="clr-namespace:System;assembly=mscorlib" xmlns:local="clr-namespace:Tango.DispenserAnalyzer.UI" StartupUri="MainWindow.xaml"> <Application.Resources> - + <ResourceDictionary> + <ResourceDictionary.MergedDictionaries> + <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Defaults.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Primary/materialdesigncolor.lightblue.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignColors;component/Themes/Recommended/Accent/materialdesigncolor.yellow.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.Button.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.CheckBox.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ListBox.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.PopupBox.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.RadioButton.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ToggleButton.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/materialdesigntheme.TextBlock.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/materialdesigntheme.Label.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/materialdesigntheme.Slider.xaml"> + </ResourceDictionary> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/materialdesigntheme.ProgressBar.xaml"/> + <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.ComboBox.xaml" /> + + </ResourceDictionary.MergedDictionaries> + <FontFamily x:Key="FontName">Segoe UI</FontFamily> + <FontFamily x:Key="NotesFont">Lucida Console</FontFamily> + + <sys:Double x:Key="ExtraExtraLargeFontSize">28</sys:Double> + <sys:Double x:Key="ExtraLargeFontSize">26</sys:Double> + <sys:Double x:Key="LargeFontSize">20</sys:Double> + <sys:Double x:Key="MediumFontSize">16</sys:Double> + <sys:Double x:Key="SmallFontSize">14</sys:Double> + <sys:Double x:Key="MiniFontSize">12</sys:Double> + <sys:Double x:Key="TinyFontSize">9</sys:Double> + </ResourceDictionary> </Application.Resources> </Application> diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml index e7712805e..1d4b2e431 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml @@ -3,10 +3,88 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:lvc="clr-namespace:LiveCharts.Wpf;assembly=LiveCharts.Wpf" + xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes" + xmlns:converters="clr-namespace:Tango.SharedUI.Converters;assembly=Tango.SharedUI" xmlns:local="clr-namespace:Tango.DispenserAnalyzer.UI" + xmlns:vm ="clr-namespace:Tango.DispenserAnalyzer.UI.ViewModels" mc:Ignorable="d" - Title="MainWindow" Height="450" Width="800"> + Title="Dispenser Analyser" Height="1000" Width="800" WindowStartupLocation="CenterScreen" WindowStyle="SingleBorderWindow" ResizeMode="NoResize" Foreground="#202020" + d:DataContext="{d:DesignInstance Type=vm:MainWindowVM, IsDesignTimeCreatable=False}"> + <Window.Resources> + <converters:EnumToDescriptionConverter x:Key="EnumToDescriptionConverter" /> + <converters:IsNullToVisibilityConverter x:Key="IsNullToVisibilityConverter"/> + </Window.Resources> <Grid> - + <Grid.RowDefinitions> + <RowDefinition Height="80"/> + <RowDefinition Height="60"/> + <RowDefinition Height="2*"/> + <RowDefinition Height="1*"/> + </Grid.RowDefinitions> + <Grid Grid.Row="0" Margin="20 20 20 20"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="*"></ColumnDefinition> + <ColumnDefinition Width="100"></ColumnDefinition> + </Grid.ColumnDefinitions> + <TextBox x:Name="tbPath" BorderThickness="1" FontSize="16" VerticalContentAlignment="Center" IsReadOnly="False" Grid.Column="0" Margin="0 0 20 0" Text="{Binding OpenFilePath, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" AllowDrop="True" PreviewDrop="TextBlock_PreviewDrop" PreviewDragOver="TextBox_PreviewDragOver" BorderBrush="Silver"></TextBox> + <Button Grid.Column="1" Command="{Binding OpenCSVFileCommand}">Browse</Button> + </Grid> + <Button Grid.Row="1" Margin="20 0 20 20" Command="{Binding GenerateCommand}">GENERATE</Button> + <Grid Grid.Row="2"> + <Border BorderBrush="Silver" Padding="5" BorderThickness="1" CornerRadius="5" Margin="10" Background="#202020"> + <DockPanel> + <TextBlock DockPanel.Dock="Top" FontSize="16" FontWeight="Bold" HorizontalAlignment="Center" Padding="10" Foreground="Silver" Text="{Binding TestName}"></TextBlock> + <lvc:CartesianChart Series="{Binding PressedValuesCollection}" LegendLocation="Bottom" DisableAnimations="True" DataTooltip="{x:Null}" Hoverable="False" > + <!--<lvc:CartesianChart.DataTooltip> + <lvc:DefaultTooltip BulletSize="20" Background="#7EFFFFFF" Foreground="green"/> + </lvc:CartesianChart.DataTooltip>--> + <lvc:CartesianChart.AxisX> + <lvc:Axis Title="TIME" Foreground="Silver" Labels="{Binding Labels}"> + <lvc:Axis.Separator> + <lvc:Separator Stroke="#A5A5A5" Step="{Binding XStep}"/> + </lvc:Axis.Separator> + </lvc:Axis> + </lvc:CartesianChart.AxisX> + <lvc:CartesianChart.AxisY> + <lvc:Axis Title="PRESSURE" LabelFormatter="{Binding YFormatter}" MinValue="{Binding From, Mode=TwoWay}" MaxValue="{Binding To, Mode=TwoWay}" Foreground="Silver" FontSize="16" > + <lvc:Axis.Separator> + <lvc:Separator Stroke="#B0B0B0" /> + </lvc:Axis.Separator> + </lvc:Axis> + </lvc:CartesianChart.AxisY> + </lvc:CartesianChart> + </DockPanel> + </Border> + </Grid> + <Grid Grid.Row="3"> + <Border Visibility="Visible" BorderThickness="1" BorderBrush="Silver" CornerRadius="5" Margin="10"> + <StackPanel Margin="3"> + <Label Height="30" Content="RESULT" Background="LightSkyBlue" /> + <Separator Height="5"/> + <!--<Border BorderThickness="1" BorderBrush="Silver" VerticalAlignment="Stretch">--> + <Grid Margin="10 0 20 0"> + <Grid.ColumnDefinitions> + <ColumnDefinition Width="1*"></ColumnDefinition> + <ColumnDefinition Width="200"></ColumnDefinition> + </Grid.ColumnDefinitions> + <ItemsControl Grid.Column="0" ItemsSource="{Binding AnalyzerResult.Properties}"> + <ItemsControl.ItemTemplate> + <DataTemplate> + <StackPanel Orientation="Horizontal" Margin="5"> + <TextBlock Margin="5 0 0 0" FontSize="16"><Run Text="{Binding Name}"></Run> <Run Text=" : "></Run><Run Text="{Binding Value,StringFormat=0}"></Run></TextBlock> + </StackPanel> + </DataTemplate> + </ItemsControl.ItemTemplate> + </ItemsControl> + <Border Grid.Column="1" HorizontalAlignment="Stretch" Margin="10 0 0 0" VerticalAlignment="Stretch" Visibility="{Binding AnalyzerResult, Converter={StaticResource IsNullToVisibilityConverter}}"> + <materialDesign:PackIcon Kind="{Binding AnalyzerResult.Result, Converter= {StaticResource EnumToDescriptionConverter}}" Width="Auto" Height="Auto" Foreground="Green" HorizontalContentAlignment="Center" /> + </Border> + </Grid> + <!--</Border>--> + </StackPanel> + </Border> + </Grid> + </Grid> </Window> diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs index 1ba890c38..c343e9919 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/MainWindow.xaml.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -12,6 +13,7 @@ using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; +using Tango.DispenserAnalyzer.UI.ViewModels; namespace Tango.DispenserAnalyzer.UI { @@ -23,6 +25,32 @@ namespace Tango.DispenserAnalyzer.UI public MainWindow() { InitializeComponent(); + DataContext = new MainWindowVM(); + } + + private void TextBlock_PreviewDrop(object sender, DragEventArgs e) + { + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + if (files != null && files.Length != 0 && System.IO.Path.GetExtension(files[0]).ToUpperInvariant() == ".CSV") + { + tbPath.Text = files[0]; + } + e.Handled = true; + } + + private void TextBox_PreviewDragOver(object sender, DragEventArgs e) + { + string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); + if (files == null || files.Length == 0 || System.IO.Path.GetExtension(files[0]).ToUpperInvariant() != ".CSV") + { + e.Effects = DragDropEffects.None; + e.Handled = true; + } + else + { + e.Effects = DragDropEffects.All; + e.Handled = true; + } } } } diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/DispenserCsvRow.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/DispenserCsvRow.cs new file mode 100644 index 000000000..e3f270ab0 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/DispenserCsvRow.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Tango.CSV; + +namespace Tango.DispenserAnalyzer.UI.Models +{ + public class DispenserCsvRow + { + [CsvOrder(0)] + public String Pressure { get; set; } + [CsvOrder(1)] + public String Label { get; set; } + [CsvOrder(2)] + public String Command { get; set; } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/DispenserSample.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/DispenserSample.cs new file mode 100644 index 000000000..d1d37955d --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/DispenserSample.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI.Models +{ + public class DispenserSample + { + public double Pressure { get; set; } + public String Command { get; set; } + public int Index { get; set; } + + public override string ToString() + { + return $"{Pressure}, {Command}"; + } + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/DispenserSampleCommand.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/DispenserSampleCommand.cs new file mode 100644 index 000000000..15b0008d4 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Models/DispenserSampleCommand.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Tango.DispenserAnalyzer.UI.Models +{ + public enum DispenserSampleCommand + { + LB1, + LB2, + LB3, + LB4 + } +} diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Tango.DispenserAnalyzer.UI.csproj b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Tango.DispenserAnalyzer.UI.csproj index f51d8ac2f..75fcf9956 100644 --- a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Tango.DispenserAnalyzer.UI.csproj +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/Tango.DispenserAnalyzer.UI.csproj @@ -35,6 +35,21 @@ <WarningLevel>4</WarningLevel> </PropertyGroup> <ItemGroup> + <Reference Include="LiveCharts"> + <HintPath>..\..\packages\LiveCharts.0.9.7\lib\net45\LiveCharts.dll</HintPath> + </Reference> + <Reference Include="LiveCharts.Wpf"> + <HintPath>..\..\packages\LiveCharts.Wpf.0.9.7\lib\net45\LiveCharts.Wpf.dll</HintPath> + </Reference> + <Reference Include="MahApps.Metro"> + <HintPath>..\..\packages\MahApps.Metro.1.5.0\lib\net45\MahApps.Metro.dll</HintPath> + </Reference> + <Reference Include="MaterialDesignColors"> + <HintPath>..\..\packages\MaterialDesignColors.1.1.2\lib\net45\MaterialDesignColors.dll</HintPath> + </Reference> + <Reference Include="MaterialDesignThemes.Wpf"> + <HintPath>..\..\packages\MaterialDesignThemes.2.3.1.953\lib\net45\MaterialDesignThemes.Wpf.dll</HintPath> + </Reference> <Reference Include="System" /> <Reference Include="System.Data" /> <Reference Include="System.Xml" /> @@ -55,6 +70,19 @@ <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> </ApplicationDefinition> + <Compile Include="Analysis\AnalysisPlotValue.cs" /> + <Compile Include="Analysis\AnalyzerResultProperty.cs" /> + <Compile Include="Analysis\AnalyzerResultBase.cs" /> + <Compile Include="Analysis\AnalyzerResultValue.cs" /> + <Compile Include="Analysis\AnalysisService.cs" /> + <Compile Include="Analysis\IAnalyzerResult.cs" /> + <Compile Include="Analysis\IAnalyzer.cs" /> + <Compile Include="Analyzers\SealingAnalyer.cs" /> + <Compile Include="Analysis\AnalyzerAttribute.cs" /> + <Compile Include="Models\DispenserCsvRow.cs" /> + <Compile Include="Models\DispenserSample.cs" /> + <Compile Include="Models\DispenserSampleCommand.cs" /> + <Compile Include="ViewModels\MainWindowVM.cs" /> <Page Include="MainWindow.xaml"> <Generator>MSBuild:Compile</Generator> <SubType>Designer</SubType> @@ -94,5 +122,20 @@ <ItemGroup> <None Include="App.config" /> </ItemGroup> + <ItemGroup> + <ProjectReference Include="..\..\Tango.Core\Tango.Core.csproj"> + <Project>{a34ee0f0-649d-41c8-8489-b6f1cc6924ee}</Project> + <Name>Tango.Core</Name> + </ProjectReference> + <ProjectReference Include="..\..\Tango.CSV\Tango.CSV.csproj"> + <Project>{58e8825f-0c96-449c-b320-1e82b0aa876b}</Project> + <Name>Tango.CSV</Name> + </ProjectReference> + <ProjectReference Include="..\..\Tango.SharedUI\Tango.SharedUI.csproj"> + <Project>{8491d07b-c1f6-4b62-a412-41b9fd2d6538}</Project> + <Name>Tango.SharedUI</Name> + </ProjectReference> + </ItemGroup> + <ItemGroup /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> </Project>
\ No newline at end of file diff --git a/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs new file mode 100644 index 000000000..d14587fd8 --- /dev/null +++ b/Software/Visual_Studio/Utilities/Tango.DispenserAnalyzer.UI/ViewModels/MainWindowVM.cs @@ -0,0 +1,206 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Microsoft.Win32; +using Tango.Core.Commands; +using Tango.CSV; +using Tango.DispenserAnalyzer.UI.Models; +using LiveCharts; +using LiveCharts.Wpf; +using Tango.SharedUI; +using System.Collections.ObjectModel; +using System.IO; +using System.Windows.Input; +using Tango.DispenserAnalyzer.UI.Analysis; +using System.Reflection; +using Tango.DispenserAnalyzer.UI.Analyzers; + +namespace Tango.DispenserAnalyzer.UI.ViewModels +{ + public class MainWindowVM: ViewModel + { + private string _openFilePath; + public string OpenFilePath + { + get { return _openFilePath; } + set + { + if(value != null && _openFilePath != value) + { + PressedValuesCollection.Clear(); + AnalyzerResult = null; + _openFilePath = value; + RaisePropertyChangedAuto(); + GenerateCommand.RaiseCanExecuteChanged(); + } + } + } + + private string _testName; + public string TestName + { + get { return _testName; } + set { _testName = value; RaisePropertyChangedAuto(); } + } + + private ObservableCollection<String> _labels; + public ObservableCollection<String> Labels + { + get { return _labels; } + set { _labels = value; RaisePropertyChangedAuto(); } + } + + private int _step; + public int XStep + { + get { return _step; } + set { _step = value; RaisePropertyChangedAuto(); } + } + + private SeriesCollection _pressedValuesCollection; + public SeriesCollection PressedValuesCollection + { + get { return _pressedValuesCollection; } + set + { + _pressedValuesCollection = value; + RaisePropertyChangedAuto(); + } + } + + private double _from; + public double From + { + get { return _from; } + set + { + _from = value; RaisePropertyChangedAuto(); + } + } + + private double _to; + public double To + { + get { return _to; } + set + { + _to = value; RaisePropertyChangedAuto(); + } + } + + private IAnalyzerResult analyzerResult; + public IAnalyzerResult AnalyzerResult + { + get { return analyzerResult; } + set { analyzerResult = value; RaisePropertyChangedAuto(); } + } + + public Func<double, string> YFormatter { get; set; } + + public RelayCommand OpenCSVFileCommand { get; set; } + public RelayCommand GenerateCommand { get; set; } + + public MainWindowVM() + { + OpenCSVFileCommand = new RelayCommand(OpenCSVFile); + GenerateCommand = new RelayCommand(Generate, CanGenerate); + PressedValuesCollection = new SeriesCollection(); + + Labels = new ObservableCollection<string>() {}; + YFormatter = value => value.ToString(); + _from = 0; + _to = 1; + XStep = 1; + AnalyzerResult = null; + } + + private void OpenCSVFile() + { + OpenFileDialog dlg = new OpenFileDialog(); + dlg.Filter = "CSV Files|*.csv"; + if (dlg.ShowDialog().Value) + { + try + { + OpenFilePath = dlg.FileName; + } + catch (Exception ex) + { + //_notification.ShowError($"An error occurred while trying to import the benchmark file.\n{ex.FlattenMessage()}"); + } + } + } + public bool CanGenerate() + { + return (OpenFilePath!= null && OpenFilePath.Length != 0 && File.Exists(OpenFilePath)); + } + private async void Generate() + { + IAnalyzer analyzer = AnalysisService.GetAnalyzer(OpenFilePath); + if (analyzer == null) + return; + + AnalyzerAttribute attribute = (AnalyzerAttribute)analyzer.GetType().GetCustomAttributes(typeof(AnalyzerAttribute),true).FirstOrDefault(); + Series pressed_values = new LineSeries() + { + Title = attribute.Name, + Values = new ChartValues<double>(), + PointGeometry = null, + }; + TestName = attribute.Name; + Labels = new ObservableCollection<string>(); + List<DispenserCsvRow> data = CsvFile.Read<DispenserCsvRow>(new CsvSource(OpenFilePath)).ToList(); + List<DispenserSample> samples = new List<DispenserSample>(); + + To = 0; + From = 0; + int index = 0; + List<object> listValues = new List<object>(); + List<string> listLabel = new List<string>(); + bool in_test_range = false; + + foreach (var item in data) + { + double pressure = 0; + 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 + }); + + if(!String.IsNullOrWhiteSpace(item.Command)) + { + in_test_range = !in_test_range; + } + if( pressure != 0 )//&& listValues.Count< 10000) + { + if (listValues.Count == 0) + { + From = pressure - 100;//???? + } + listLabel.Add(index.ToString()); + listValues.Add(pressure); + _to = Math.Max(pressure, _to); + } + index++; + } + } + + _to += 100; + RaisePropertyChanged("To"); + + Labels = listLabel.ToObservableCollection<string>(); + XStep = (int)(Labels.Count / 5); + + pressed_values.Values.AddRange(listValues.AsEnumerable()); + PressedValuesCollection.Clear(); + PressedValuesCollection.Add(pressed_values); + + AnalyzerResult = await analyzer.Process(samples); + } + } +} |
