90 lines
2.8 KiB
C#
90 lines
2.8 KiB
C#
///
|
|
/// 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]);
|
|
}
|
|
}
|
|
}
|
|
}
|