167 lines
5.4 KiB
C#
167 lines
5.4 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using Xylem.Common.Hardware.WaterMeter.Genesis.Protocols.StreamingProtocol;
|
|
|
|
namespace DynamicStremingLogAnalyzer
|
|
{
|
|
internal class PathOffsetBag
|
|
{
|
|
public int Path { get; set; }
|
|
public int CurrentOffsetValue { get; set; }
|
|
public List<double> DeltaTimeOfFlightS { get; set; }
|
|
public int indexOflastChange { get; set; }
|
|
|
|
}
|
|
|
|
internal class MeterBag
|
|
{
|
|
public MeterBag()
|
|
{
|
|
PathOffsets = new List<PathOffsetBag>();
|
|
}
|
|
public string SerialNumber { get; set; }
|
|
public string PcbID { get; set; }
|
|
|
|
public List<PathOffsetBag> PathOffsets { get; set; }
|
|
|
|
public bool MeterValid { get; set; } = true;
|
|
}
|
|
|
|
internal class Program
|
|
{
|
|
private static void Main(string[] args)
|
|
{
|
|
DateTimeOffset timestamp;
|
|
var meters = new List<MeterBag>();
|
|
|
|
foreach (var item in Directory.GetFiles("\\\\sla12buma\\cordonelds$\\LAA-D-70MYB62\\2023-02-06\\", "*_PreAdjustment.log", SearchOption.AllDirectories))
|
|
{
|
|
|
|
|
|
//Meter_SlotSlot_2_SN23706764_PreAdjustment
|
|
var meter = new MeterBag();
|
|
meter.SerialNumber = item.Substring(item.LastIndexOf("_SN") + 3, item.IndexOf("_PreAdjustment.log") - item.LastIndexOf("_SN") - 3);
|
|
meter.PathOffsets.Add(new PathOffsetBag() { Path = 1, CurrentOffsetValue = 0, indexOflastChange = 0, DeltaTimeOfFlightS = new List<double>() });
|
|
meter.PathOffsets.Add(new PathOffsetBag() { Path = 2, CurrentOffsetValue = 0, indexOflastChange = 0, DeltaTimeOfFlightS = new List<double>() });
|
|
meter.PathOffsets.Add(new PathOffsetBag() { Path = 3, CurrentOffsetValue = 0, indexOflastChange = 0, DeltaTimeOfFlightS = new List<double>() });
|
|
|
|
|
|
var directoryName = Path.GetDirectoryName(item);
|
|
|
|
|
|
//LedRawData__Slot_10_SN23706763_PreAdjustment.log
|
|
File.Exists(directoryName + "\\Meter_SlotSlot_2_SN23706764_PreAdjustment.log");
|
|
|
|
|
|
|
|
DateTimeOffset? Start = null;
|
|
var StreamingDecode = new StreamingDecoder(false);
|
|
foreach (var line in File.ReadAllLines(item))
|
|
{
|
|
|
|
if (line.Contains('|'))
|
|
{
|
|
if (DateTimeOffset.TryParse(line.Split('|')[0], out timestamp))
|
|
{
|
|
if (!Start.HasValue)
|
|
{
|
|
Start = timestamp;
|
|
}
|
|
else
|
|
{
|
|
if (StreamingDecode.DecodeMsg(line.Split('|')[1].Trim()))
|
|
{
|
|
var c = StreamingDecode.DataCalib;
|
|
if (c.IsValid)
|
|
{
|
|
meter.PathOffsets.Find(f => f.Path == c.Channel).DeltaTimeOfFlightS.Add(c.DeltaTimeOfFlightS);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
meters.Add(meter);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
foreach (var removeLineMeter in meters)
|
|
{
|
|
for (int i = 1; i <= 3; i++)
|
|
{
|
|
var cList = removeLineMeter.PathOffsets.Find(f => f.Path == i);
|
|
if (cList.DeltaTimeOfFlightS.Count > 27000)
|
|
{
|
|
cList.DeltaTimeOfFlightS.RemoveRange(0, cList.DeltaTimeOfFlightS.Count - 27000);
|
|
}
|
|
else
|
|
{
|
|
removeLineMeter.MeterValid = false;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var calcMeter in meters.Where(m => m.MeterValid))
|
|
{
|
|
foreach (var pOffset in calcMeter.PathOffsets)
|
|
{
|
|
List<double> CalculatedOffsets = new List<double>();
|
|
|
|
foreach (var currentOffset in pOffset.DeltaTimeOfFlightS)
|
|
{
|
|
CalculatedOffsets.Add(currentOffset);
|
|
|
|
var avg = CalculatedOffsets.Sum() / CalculatedOffsets.Count;
|
|
var OffsetValue = (Int32)((avg * Math.Pow(2, 40)));
|
|
if (pOffset.CurrentOffsetValue != OffsetValue)
|
|
{
|
|
pOffset.CurrentOffsetValue = OffsetValue;
|
|
pOffset.indexOflastChange = CalculatedOffsets.Count;
|
|
}
|
|
else
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
foreach (var PrintMeter in meters.Where(m => m.MeterValid))
|
|
{
|
|
|
|
Console.WriteLine(PrintMeter.SerialNumber);
|
|
foreach (var pOffset in PrintMeter.PathOffsets)
|
|
{
|
|
Console.WriteLine($"{pOffset.Path} = {pOffset.indexOflastChange}");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
Console.ReadLine();
|
|
|
|
//\Pruef2000
|
|
}
|
|
}
|
|
}
|