265 lines
9.5 KiB
C#
265 lines
9.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Data;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Imaging;
|
|
using System.Windows.Shapes;
|
|
using Newtonsoft.Json;
|
|
using Xylem.Common.CommonCore.Consts;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol;
|
|
using Xylem.Common.Logic.ProductionOrderCore.TestResults;
|
|
using Xylem.Common.Logic.SoftwareAccessHelper;
|
|
using Xylem.Common.Metrology.Measurements;
|
|
|
|
|
|
namespace CordoPlot
|
|
{
|
|
/// <summary>
|
|
/// Interaktionslogik für StartDialog.xaml
|
|
/// </summary>
|
|
public partial class StartDialog : Window
|
|
{
|
|
public StartDialog()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
string[] FileNames;
|
|
private void Button_Click(Object sender, RoutedEventArgs e)
|
|
{
|
|
var dialog = new Microsoft.Win32.OpenFileDialog();
|
|
dialog.FileName = "led"; // Default file name
|
|
dialog.DefaultExt = ".log"; // Default file extension
|
|
dialog.Filter = "Text documents (.log)|*.log"; // Filter files by extension
|
|
dialog.Multiselect = true;
|
|
bool? result = dialog.ShowDialog();
|
|
|
|
// Process open file dialog box results
|
|
|
|
|
|
if (result == true)
|
|
{
|
|
TestResults = new List<PlotableTestResults>();
|
|
FileNames = dialog.FileNames;
|
|
|
|
pbStatus.Maximum = dialog.FileNames.Length;
|
|
|
|
BackgroundWorker worker = new BackgroundWorker();
|
|
worker.WorkerReportsProgress = true;
|
|
worker.DoWork += worker_DoWork;
|
|
|
|
worker.ProgressChanged += worker_ProgressChanged;
|
|
|
|
worker.RunWorkerAsync();
|
|
worker.RunWorkerCompleted += Worker_RunWorkerCompleted;
|
|
|
|
}
|
|
}
|
|
|
|
private void Worker_RunWorkerCompleted(Object sender, RunWorkerCompletedEventArgs e)
|
|
{
|
|
DataTable MainInfoDt = new DataTable("DisplayData");
|
|
|
|
|
|
MainInfoDt.Columns.Add("Nr", typeof(int));
|
|
MainInfoDt.Columns.Add("File", typeof(string));
|
|
MainInfoDt.Columns.Add("Status", typeof(bool));
|
|
|
|
|
|
|
|
var i = 0;
|
|
foreach (PlotableTestResults row in TestResults)
|
|
{
|
|
i = i + 1;
|
|
MainInfoDt.Rows.Add(i, row.FileName, row.HasResults);
|
|
}
|
|
|
|
|
|
|
|
Fileoverview.DataContext = MainInfoDt.DefaultView;
|
|
|
|
}
|
|
|
|
void worker_DoWork(object sender, DoWorkEventArgs e)
|
|
{
|
|
var i = 0;
|
|
foreach (var filename in FileNames)
|
|
{
|
|
|
|
|
|
|
|
i = i + 1;
|
|
(sender as BackgroundWorker).ReportProgress(i, $"({i}/{FileNames.Length}){filename}");
|
|
PlotableTestResults testBenchresults = new PlotableTestResults();
|
|
testBenchresults.FileName = filename;
|
|
try
|
|
{
|
|
|
|
|
|
var AllLines = File.ReadAllLines(filename);
|
|
|
|
//LedRawData__Slot_7_SN24712962_PG2016079130.log
|
|
if (filename.Contains("_SN") && filename.Contains("_PG"))
|
|
{
|
|
try
|
|
{
|
|
|
|
|
|
var sn = filename.Substring(filename.LastIndexOf("_SN") + 3, filename.LastIndexOf("_PG") - filename.LastIndexOf("_SN") - 3);
|
|
var pg = filename.Substring(filename.LastIndexOf("_PG") + 3, filename.LastIndexOf(".log") - filename.LastIndexOf("_PG") - 3);
|
|
testBenchresults = JsonConvert.DeserializeObject<PlotableTestResults>(LocalWebRequest.GetRequest($"http://localhost:50076/api/TestBench/GetTestResults?SerialNr={sn}&TestRunNr={pg}", 10000));
|
|
testBenchresults.HasResults = true;
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var listOfData = new List<List<IMeasurementRecord>>();
|
|
listOfData.Add(new List<IMeasurementRecord>());
|
|
listOfData.Add(new List<IMeasurementRecord>());
|
|
listOfData.Add(new List<IMeasurementRecord>());
|
|
listOfData.Add(new List<IMeasurementRecord>());
|
|
var decoder = new StreamingDecoder();
|
|
var currentSyncmark = SyncMarkRecord.DecodeEveryPackage;
|
|
//DecodeMsg
|
|
var linecounter = 0;
|
|
foreach (var line in AllLines)
|
|
{
|
|
linecounter = linecounter + 1;
|
|
decoder = new StreamingDecoder();
|
|
|
|
if (line.Contains("|"))
|
|
{
|
|
|
|
var t = line.Split('|');
|
|
DateTime recived = DateTime.Now;
|
|
DateTime.TryParse(t[0], out recived);
|
|
if (t[1].Contains("@"))
|
|
{
|
|
decoder.DecodeMsg(t[1].Trim());
|
|
IMeasurementRecord recordToAdd;
|
|
if (decoder.DataBendDetectTest != null && decoder.DataBendDetectTest.IsValid)
|
|
{
|
|
decoder.DataBendDetectTest.ReceivedTime = recived;
|
|
decoder.DataBendDetectTest.SyncMarkRecord = currentSyncmark;
|
|
recordToAdd = decoder.DataBendDetectTest;
|
|
}
|
|
else if (decoder.DataCalib != null && decoder.DataCalib.IsValid)
|
|
{
|
|
decoder.DataCalib.ReceivedTime = recived;
|
|
decoder.DataCalib.SyncMarkRecord = currentSyncmark;
|
|
var n = new PlotCalibrationRecord(decoder.DataCalib, linecounter);
|
|
|
|
listOfData[n.GetChannel()].Add(n);
|
|
}
|
|
else if (decoder.DataFlowTest != null && decoder.DataFlowTest.IsValid)
|
|
{
|
|
decoder.DataFlowTest.ReceivedTime = recived;
|
|
decoder.DataFlowTest.SyncMarkRecord = currentSyncmark;
|
|
var n = new PlotFlowTestRecord(decoder.DataFlowTest, linecounter);
|
|
listOfData[n.GetChannel()].Add(n);
|
|
|
|
}
|
|
else
|
|
{
|
|
//No valid data
|
|
continue;
|
|
}
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
if (line.Contains("Mark next incoming record as"))
|
|
{
|
|
if (line.Contains("Mark next incoming record as SyncStart"))
|
|
{
|
|
currentSyncmark = SyncMarkRecord.SyncStart;
|
|
}
|
|
else if (line.Contains("Mark next incoming record as DecodeIntermediate"))
|
|
{
|
|
currentSyncmark = SyncMarkRecord.DecodeIntermediate;
|
|
}
|
|
else if (line.Contains("Mark next incoming record as SkipDecoding"))
|
|
{
|
|
currentSyncmark = SyncMarkRecord.SkipDecoding;
|
|
}
|
|
else if (line.Contains("Mark next incoming record as SyncEnd"))
|
|
{
|
|
currentSyncmark = SyncMarkRecord.SyncEnd;
|
|
}
|
|
else
|
|
{
|
|
currentSyncmark = SyncMarkRecord.DecodeEveryPackage;
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
//FlowTestRecord
|
|
}
|
|
|
|
|
|
testBenchresults.MapDataPoints(listOfData);
|
|
|
|
|
|
|
|
|
|
testBenchresults.PrepExprtDataPoints();
|
|
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
|
|
}
|
|
TestResults.Add(testBenchresults);
|
|
Thread.Sleep(100);
|
|
}
|
|
}
|
|
|
|
|
|
void worker_ProgressChanged(object sender, ProgressChangedEventArgs e)
|
|
{
|
|
pbStatus.Value = e.ProgressPercentage;
|
|
lblProgress.Content = (string)e.UserState;
|
|
|
|
|
|
}
|
|
|
|
public List<PlotableTestResults> TestResults { get; set; }
|
|
|
|
private void Fileoverview_SelectedCellsChanged(Object sender, SelectedCellsChangedEventArgs e)
|
|
{
|
|
DataGridCellInfo di = e.AddedCells.First();
|
|
|
|
var currentIndex = Fileoverview.Items.IndexOf(Fileoverview.CurrentItem);
|
|
TestResults[currentIndex];
|
|
|
|
|
|
}
|
|
|
|
private void Fileoverview_CurrentCellChanged(Object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
}
|