From a7e2947de7bea08990cd18f42e895e2032aa3cb0 Mon Sep 17 00:00:00 2001 From: Milan Hanajik Date: Wed, 7 Jul 2021 08:53:32 +0200 Subject: [PATCH] Feature vector calculator - initial version of the offline tool. --- .gitignore | 2 + Common/Iperl/OptoTelegramRaw.cs | 4 +- FeatureVectorCalculator/App.config | 6 + .../CalculatorWnd.Designer.cs | 97 ++++++++++++++ FeatureVectorCalculator/CalculatorWnd.cs | 89 +++++++++++++ FeatureVectorCalculator/CalculatorWnd.resx | 120 ++++++++++++++++++ .../FeatureVectorCalculator.csproj | 98 ++++++++++++++ FeatureVectorCalculator/Program.cs | 25 ++++ .../Properties/AssemblyInfo.cs | 36 ++++++ .../Properties/Resources.Designer.cs | 63 +++++++++ .../Properties/Resources.resx | 117 +++++++++++++++++ .../Properties/Settings.Designer.cs | 26 ++++ .../Properties/Settings.settings | 7 + TBF.sln | 12 ++ clean.bat | 2 + 15 files changed, 702 insertions(+), 2 deletions(-) create mode 100644 FeatureVectorCalculator/App.config create mode 100644 FeatureVectorCalculator/CalculatorWnd.Designer.cs create mode 100644 FeatureVectorCalculator/CalculatorWnd.cs create mode 100644 FeatureVectorCalculator/CalculatorWnd.resx create mode 100644 FeatureVectorCalculator/FeatureVectorCalculator.csproj create mode 100644 FeatureVectorCalculator/Program.cs create mode 100644 FeatureVectorCalculator/Properties/AssemblyInfo.cs create mode 100644 FeatureVectorCalculator/Properties/Resources.Designer.cs create mode 100644 FeatureVectorCalculator/Properties/Resources.resx create mode 100644 FeatureVectorCalculator/Properties/Settings.Designer.cs create mode 100644 FeatureVectorCalculator/Properties/Settings.settings diff --git a/.gitignore b/.gitignore index 815d68d8a..755fbf4fc 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,8 @@ EventViewer/bin/ EventViewer/obj/ Events/bin/ Events/obj/ +FeatureVectorCalculator/bin/ +FeatureVectorCalculator/obj/ GemCard/bin GemCard/obj GenCode128/bin diff --git a/Common/Iperl/OptoTelegramRaw.cs b/Common/Iperl/OptoTelegramRaw.cs index d0304abc8..c17bdff67 100644 --- a/Common/Iperl/OptoTelegramRaw.cs +++ b/Common/Iperl/OptoTelegramRaw.cs @@ -105,7 +105,7 @@ namespace Common.Iperl /// /// A complete byte array data /// true = telegram OK, false = telegram NOK - public bool UpdateFromString(string telegram, int counter, float refFlow, ref Int64 volumeRawExtLast, ref Int64 timestampExtLast) + public bool UpdateFromString(string telegram, int counter, float refFlow, ref Int64 volumeRawExtLast, ref Int64 timestampExtLast, bool isLog = false) { DateTime = DateTime.Now; Counter = counter; @@ -114,7 +114,7 @@ namespace Common.Iperl if ((telegram == null) || (telegram.Length < Length) || (telegram[6] != '\t') || (telegram[11] != '\t') || (telegram[16] != '\t') || (telegram[23] != '\t') || (telegram[28] != '\t') || (telegram[37] != '\t') || - (telegram[40] != '\r') || (telegram[41] != '\n')) + (!isLog && (telegram[40] != '\r' || telegram[41] != '\n'))) { Flags = OptoTelegramFlags.InvalidTelegram; return false; diff --git a/FeatureVectorCalculator/App.config b/FeatureVectorCalculator/App.config new file mode 100644 index 000000000..56efbc7b5 --- /dev/null +++ b/FeatureVectorCalculator/App.config @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/FeatureVectorCalculator/CalculatorWnd.Designer.cs b/FeatureVectorCalculator/CalculatorWnd.Designer.cs new file mode 100644 index 000000000..c84bdc799 --- /dev/null +++ b/FeatureVectorCalculator/CalculatorWnd.Designer.cs @@ -0,0 +1,97 @@ +namespace FeatureVectorCalculator +{ + partial class CalculatorWnd + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + this.rawFileComboBox = new System.Windows.Forms.ComboBox(); + this.browseButton = new System.Windows.Forms.Button(); + this.processButton = new System.Windows.Forms.Button(); + this.resultsTextBox = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // rawFileComboBox + // + this.rawFileComboBox.FormattingEnabled = true; + this.rawFileComboBox.Location = new System.Drawing.Point(29, 28); + this.rawFileComboBox.Name = "rawFileComboBox"; + this.rawFileComboBox.Size = new System.Drawing.Size(715, 21); + this.rawFileComboBox.TabIndex = 0; + // + // browseButton + // + this.browseButton.Location = new System.Drawing.Point(769, 19); + this.browseButton.Name = "browseButton"; + this.browseButton.Size = new System.Drawing.Size(66, 37); + this.browseButton.TabIndex = 1; + this.browseButton.Text = "Browse"; + this.browseButton.UseVisualStyleBackColor = true; + this.browseButton.Click += new System.EventHandler(this.browseButton_Click); + // + // processButton + // + this.processButton.Location = new System.Drawing.Point(29, 66); + this.processButton.Name = "processButton"; + this.processButton.Size = new System.Drawing.Size(91, 46); + this.processButton.TabIndex = 2; + this.processButton.Text = "Process"; + this.processButton.UseVisualStyleBackColor = true; + this.processButton.Click += new System.EventHandler(this.processButton_Click); + // + // resultsTextBox + // + this.resultsTextBox.Location = new System.Drawing.Point(29, 131); + this.resultsTextBox.Multiline = true; + this.resultsTextBox.Name = "resultsTextBox"; + this.resultsTextBox.Size = new System.Drawing.Size(715, 181); + this.resultsTextBox.TabIndex = 3; + // + // CalculatorWnd + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(859, 335); + this.Controls.Add(this.resultsTextBox); + this.Controls.Add(this.processButton); + this.Controls.Add(this.browseButton); + this.Controls.Add(this.rawFileComboBox); + this.Name = "CalculatorWnd"; + this.Text = "Feature vector calculator"; + this.ResumeLayout(false); + this.PerformLayout(); + + } + + #endregion + + private System.Windows.Forms.ComboBox rawFileComboBox; + private System.Windows.Forms.Button browseButton; + private System.Windows.Forms.Button processButton; + private System.Windows.Forms.TextBox resultsTextBox; + } +} + diff --git a/FeatureVectorCalculator/CalculatorWnd.cs b/FeatureVectorCalculator/CalculatorWnd.cs new file mode 100644 index 000000000..a425c59cf --- /dev/null +++ b/FeatureVectorCalculator/CalculatorWnd.cs @@ -0,0 +1,89 @@ +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +using System; +using System.IO; +using System.Windows.Forms; +using Common.Iperl; + +namespace FeatureVectorCalculator +{ + public partial class CalculatorWnd : Form + { + public const int MaxOptoDataCount = 40000; + OptoTelegramRaw[] optoData; + Int64 volumeRawExtLast; + Int64 timestampExtLast; + + + public CalculatorWnd() + { + InitializeComponent(); + + optoData = new OptoTelegramRaw[MaxOptoDataCount]; + for (int i = 0; i < MaxOptoDataCount; i++) + { + optoData[i] = new OptoTelegramRaw(); + } + } + + private void browseButton_Click(object sender, EventArgs e) + { + OpenFileDialog ofd = new OpenFileDialog(); + var dr = ofd.ShowDialog(); + rawFileComboBox.Text = ofd.FileName; + } + + private void processButton_Click(object sender, EventArgs e) + { + if (optoData == null) return; + + int counter = 0; + int startIx = -1; + int endIx = -1; + + using (StreamReader reader = new StreamReader(rawFileComboBox.Text)) + { + string line; + while ((line = reader.ReadLine()) != null && counter < MaxOptoDataCount) + { + int ix = line.IndexOf(" :\t"); + + if (ix >= 0) + { + if (optoData[counter].UpdateFromString(line.Substring(ix + 3), counter, 0, ref volumeRawExtLast, ref timestampExtLast, true)) + { + if (line.EndsWith("#### start test ####")) + { + startIx = counter; + optoData[counter].Flags = OptoTelegramFlags.OK_TestStart; + } + else if (line.EndsWith("#### end of test ####")) + { + endIx = counter; + optoData[counter].Flags = OptoTelegramFlags.OK_TestEnd; + } + } + } + else + { + optoData[counter].Flags = OptoTelegramFlags.InvalidTelegram; + } + + counter++; + } + + reader.Close(); + } + + float[] featureVector = new float[9]; + Common.Utils.CalculateFeatureVector(optoData, counter, startIx, endIx, ref featureVector); + + resultsTextBox.Clear(); + for (int i = 0; i < 9; i++) + { + resultsTextBox.Text += string.Format("X{0} = {1}\r\n", i + 1, featureVector[i]); + } + } + } +} diff --git a/FeatureVectorCalculator/CalculatorWnd.resx b/FeatureVectorCalculator/CalculatorWnd.resx new file mode 100644 index 000000000..1af7de150 --- /dev/null +++ b/FeatureVectorCalculator/CalculatorWnd.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FeatureVectorCalculator/FeatureVectorCalculator.csproj b/FeatureVectorCalculator/FeatureVectorCalculator.csproj new file mode 100644 index 000000000..827349aa4 --- /dev/null +++ b/FeatureVectorCalculator/FeatureVectorCalculator.csproj @@ -0,0 +1,98 @@ + + + + + Debug + AnyCPU + {6280F3F9-139A-48E3-8C88-25EB4124E982} + WinExe + Properties + FeatureVectorCalculator + FeatureVectorCalculator + v4.7.2 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + FeatureVectorCalculator.Program + + + + + + + + + + + + + + + + Form + + + CalculatorWnd.cs + + + + + CalculatorWnd.cs + + + ResXFileCodeGenerator + Resources.Designer.cs + Designer + + + True + Resources.resx + True + + + SettingsSingleFileGenerator + Settings.Designer.cs + + + True + Settings.settings + True + + + + + + + + {c8939821-ba5c-4988-a3d0-bf53b74865c7} + Common + + + + + \ No newline at end of file diff --git a/FeatureVectorCalculator/Program.cs b/FeatureVectorCalculator/Program.cs new file mode 100644 index 000000000..d967d67a2 --- /dev/null +++ b/FeatureVectorCalculator/Program.cs @@ -0,0 +1,25 @@ +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Windows.Forms; + +namespace FeatureVectorCalculator +{ + static class Program + { + /// + /// The main entry point for the application. + /// + [STAThread] + static void Main() + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new CalculatorWnd()); + } + } +} diff --git a/FeatureVectorCalculator/Properties/AssemblyInfo.cs b/FeatureVectorCalculator/Properties/AssemblyInfo.cs new file mode 100644 index 000000000..27b71bede --- /dev/null +++ b/FeatureVectorCalculator/Properties/AssemblyInfo.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("FeatureVectorCalculator")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("FeatureVectorCalculator")] +[assembly: AssemblyCopyright("Copyright © 2021")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("4d3a6fe2-3153-4581-8ec7-e5a386b50177")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] diff --git a/FeatureVectorCalculator/Properties/Resources.Designer.cs b/FeatureVectorCalculator/Properties/Resources.Designer.cs new file mode 100644 index 000000000..bf91995a1 --- /dev/null +++ b/FeatureVectorCalculator/Properties/Resources.Designer.cs @@ -0,0 +1,63 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace FeatureVectorCalculator.Properties { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // This class was auto-generated by the StronglyTypedResourceBuilder + // class via a tool like ResGen or Visual Studio. + // To add or remove a member, edit your .ResX file then rerun ResGen + // with the /str option, or rebuild your VS project. + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + internal class Resources { + + private static global::System.Resources.ResourceManager resourceMan; + + private static global::System.Globalization.CultureInfo resourceCulture; + + [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] + internal Resources() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Resources.ResourceManager ResourceManager { + get { + if (object.ReferenceEquals(resourceMan, null)) { + global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("FeatureVectorCalculator.Properties.Resources", typeof(Resources).Assembly); + resourceMan = temp; + } + return resourceMan; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + } +} diff --git a/FeatureVectorCalculator/Properties/Resources.resx b/FeatureVectorCalculator/Properties/Resources.resx new file mode 100644 index 000000000..af7dbebba --- /dev/null +++ b/FeatureVectorCalculator/Properties/Resources.resx @@ -0,0 +1,117 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/FeatureVectorCalculator/Properties/Settings.Designer.cs b/FeatureVectorCalculator/Properties/Settings.Designer.cs new file mode 100644 index 000000000..fb5e1f594 --- /dev/null +++ b/FeatureVectorCalculator/Properties/Settings.Designer.cs @@ -0,0 +1,26 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace FeatureVectorCalculator.Properties { + + + [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")] + internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { + + private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); + + public static Settings Default { + get { + return defaultInstance; + } + } + } +} diff --git a/FeatureVectorCalculator/Properties/Settings.settings b/FeatureVectorCalculator/Properties/Settings.settings new file mode 100644 index 000000000..39645652a --- /dev/null +++ b/FeatureVectorCalculator/Properties/Settings.settings @@ -0,0 +1,7 @@ + + + + + + + diff --git a/TBF.sln b/TBF.sln index 6ef689be3..a06434be4 100644 --- a/TBF.sln +++ b/TBF.sln @@ -81,6 +81,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DataStreamMeter", "DataStre EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MergeResultsDBs", "MergeResultsDBs\MergeResultsDBs.csproj", "{9786D0A8-BA9A-41F6-9E61-C7B2B76D4C08}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FeatureVectorCalculator", "FeatureVectorCalculator\FeatureVectorCalculator.csproj", "{6280F3F9-139A-48E3-8C88-25EB4124E982}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -355,6 +357,16 @@ Global {9786D0A8-BA9A-41F6-9E61-C7B2B76D4C08}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU {9786D0A8-BA9A-41F6-9E61-C7B2B76D4C08}.Release|Mixed Platforms.Build.0 = Release|Any CPU {9786D0A8-BA9A-41F6-9E61-C7B2B76D4C08}.Release|x86.ActiveCfg = Release|Any CPU + {6280F3F9-139A-48E3-8C88-25EB4124E982}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {6280F3F9-139A-48E3-8C88-25EB4124E982}.Debug|Any CPU.Build.0 = Debug|Any CPU + {6280F3F9-139A-48E3-8C88-25EB4124E982}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU + {6280F3F9-139A-48E3-8C88-25EB4124E982}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU + {6280F3F9-139A-48E3-8C88-25EB4124E982}.Debug|x86.ActiveCfg = Debug|Any CPU + {6280F3F9-139A-48E3-8C88-25EB4124E982}.Release|Any CPU.ActiveCfg = Release|Any CPU + {6280F3F9-139A-48E3-8C88-25EB4124E982}.Release|Any CPU.Build.0 = Release|Any CPU + {6280F3F9-139A-48E3-8C88-25EB4124E982}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU + {6280F3F9-139A-48E3-8C88-25EB4124E982}.Release|Mixed Platforms.Build.0 = Release|Any CPU + {6280F3F9-139A-48E3-8C88-25EB4124E982}.Release|x86.ActiveCfg = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/clean.bat b/clean.bat index 0e1943158..2c41ff7ee 100644 --- a/clean.bat +++ b/clean.bat @@ -20,6 +20,8 @@ rmdir /s /q EventViewer\bin rmdir /s /q EventViewer\obj rmdir /s /q Events\bin rmdir /s /q Events\obj +rmdir /s /q FeatureVectorCalculator\bin +rmdir /s /q FeatureVectorCalculator\obj rmdir /s /q GemCard\bin rmdir /s /q GemCard\obj rmdir /s /q GenCode128\bin