300 lines
13 KiB
C#
300 lines
13 KiB
C#
///
|
|
/// Copyright (c) 2013-2022 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Common;
|
|
|
|
namespace Results.Entities
|
|
{
|
|
public class MeterTestRslt
|
|
{
|
|
public virtual int Id { get; protected set; }
|
|
public virtual byte CompoundMeterId { get; set; } /// 0=single, 1=compound/main, 2=compound/aux., 3=compound/overal, 4=heat meter volume, 5=heat meter energy
|
|
public virtual int RegReaderType { get; set; } /// Not mapped to the DB, does not depend on localization and customer
|
|
public virtual double PulsesMeter { get; set; } /// # of water meter or heat meter pulses
|
|
public virtual double PulsesMaster { get; set; } /// # of reference flowmeter pulses (gated by this water meter pulses)
|
|
public virtual double PulsesPerLiter { get; set; } /// [l ^ -1], in case of heat meters (CompoundMeterId==5) pulses per kWh in [kWh ^ -1]
|
|
public virtual double VolumeStart { get; set; } /// Volume or energy (CompoundMeterId==5) on test start in [l] or [J]
|
|
public virtual double VolumeEnd { get; set; } /// Volume or energy (CompoundMeterId==5) on test end in [l] or [J]
|
|
public virtual double VolumeMeter { get; set; } /// Measured volume or energy (CompoundMeterId==5) in [l] or [J]
|
|
public virtual double VolumeRef { get; set; } /// Reference volume or energy (CompoundMeterId==5) in [l] or [J]
|
|
public virtual double TimestampStart { get; set; } /// [s]
|
|
public virtual double TimestampEnd { get; set; } /// [s]
|
|
public virtual double TestTime { get; set; } /// [s]
|
|
|
|
/// Main result
|
|
public virtual double Error { get; set; } /// [%]
|
|
public virtual long ErrorIndicators { get; set; } /// Not mapped to DB !!!, bit24=E25, bit25=E26, bit26=E27, bit27=E28 (error flags)
|
|
public virtual long InfoIndicators { get; set; } /// Not mapped to DB !!!, bit24=E25, bit25=E26, bit26=E27, bit27=E28 (info flags)
|
|
public virtual bool TestDone { get; set; } /// true = test was completed
|
|
public virtual bool Passed { get; set; } /// true = test passed, water meter is OK
|
|
#if IPERL
|
|
public virtual int CalibFactor { get; set; }
|
|
public virtual int CalibFactorLNA { get; set; }
|
|
public virtual int Q2CorrRL { get; set; }
|
|
public virtual int Q2CorrLR { get; set; }
|
|
public virtual string ExtraDataPath { get; set; } /// Relative path to a file with opto-data/raw-data
|
|
public virtual float X1 { get; set; }
|
|
public virtual float X2 { get; set; }
|
|
public virtual float X3 { get; set; }
|
|
public virtual float X4 { get; set; }
|
|
public virtual float X5 { get; set; }
|
|
public virtual float X6 { get; set; }
|
|
public virtual float X7 { get; set; }
|
|
public virtual float X8 { get; set; }
|
|
public virtual float X9 { get; set; }
|
|
#endif
|
|
#if ORACLE_DB
|
|
public virtual double ErrorBC { get; set; } /// [%] error before correction, saved to Oracle to table VT_PRUEFREIHE_IST_PD as KorrErrQ
|
|
public virtual double LastError { get; set; } /// [%] Previous test error at this Q in case Pruefindex > 1
|
|
#endif
|
|
|
|
public virtual WaterMeter WaterMeter { get; set; } /// reference to the WaterMeter entity
|
|
public virtual TestRslt TestRslt { get; set; } /// reference to the TestRslt entity
|
|
|
|
/// Wrappers
|
|
public virtual string Name() { return TestRslt.Name(); }
|
|
public virtual DateTime StartTime() { return TestRslt.StartTime; }
|
|
public virtual DateTime EndTime() { return TestRslt.EndTime; }
|
|
public virtual double FlowSetTime() { return TestRslt.FlowSetTime; } /// [s]
|
|
public virtual double Flow() { return TestRslt.Flow; } /// [m3/h]
|
|
public virtual double ErrorMaster() { return TestRslt.ErrorMaster; } /// [%]
|
|
public virtual double DensityLine() { return TestRslt.DensityLine; }
|
|
public virtual Components Components(){ return TestRslt.Components; }
|
|
///
|
|
public virtual TestData TestData() { return TestRslt.TestData; }
|
|
///
|
|
public virtual int Repeats() { return TestData().Repeats; }
|
|
public virtual double Qtg() { return TestData().Qtg; } /// [m3/h]
|
|
public virtual double Qfrom() { return TestData().Qfrom; } /// [m3/h]
|
|
public virtual double Qto() { return TestData().Qto; } /// [m3/h]
|
|
public virtual double TargetVolume() { return TestData().TargetVolume; } /// [l]
|
|
public virtual double TargetTime() { return TestData().TargetTime; } /// [s]
|
|
public virtual string Method() { return TestData().Method; }
|
|
public virtual double ErrLimLo() { return TestData().ErrLimLo; } /// [%]
|
|
public virtual double ErrLimHi() { return TestData().ErrLimHi; } /// [%]
|
|
public virtual double Uncertainty() { return TestData().ErrLimMargin; } /// [%]
|
|
|
|
public virtual string ProcedureName() { return WaterMeter.Batch.ProcedureName; }
|
|
public virtual int BatchNr() { return WaterMeter.Batch.BatchNr; }
|
|
public virtual string SerialNr() { return (CompoundMeterId == (byte)Common.CompoundMeterId.CompoundAux)
|
|
? WaterMeter.SerialNrAux
|
|
: WaterMeter.SerialNr; }
|
|
public virtual string EndState() { return WaterMeter.EndState; }
|
|
public virtual double QRise() { return WaterMeter.QRise; } /// [m3/h]
|
|
public virtual double QFall() { return WaterMeter.QFall; } /// [m3/h]
|
|
|
|
public virtual bool Evaluate() { return TestData().Evaluate; }
|
|
public virtual Publish Publish() { return (Publish)TestData().Publish; }
|
|
|
|
public virtual WaterMeterData WaterMeterData() { return WaterMeter.WaterMeterData; }
|
|
public virtual Batch Batch() { return WaterMeter.Batch; }
|
|
|
|
public virtual bool IsPilotRslt()
|
|
{
|
|
return (CompoundMeterId == (byte)Common.CompoundMeterId.Single) ||
|
|
(CompoundMeterId == (byte)Common.CompoundMeterId.Compound) ||
|
|
(CompoundMeterId == (byte)Common.CompoundMeterId.HeatMeterEnergy);
|
|
}
|
|
|
|
public virtual bool IsPulses() { return (RegReaderType == (int)RegisterReaderType.Pulses || RegReaderType == (int)RegisterReaderType.Unknown); }
|
|
public virtual bool IsCamera() { return (RegReaderType == (int)RegisterReaderType.Camera); }
|
|
public virtual bool IsDataStream() { return (RegReaderType == (int)RegisterReaderType.DataStream); }
|
|
public virtual bool IsManual() { return (RegReaderType == (int)RegisterReaderType.Manual); }
|
|
|
|
public virtual string PassedOrErrorFlagsStr()
|
|
{
|
|
string eFlags = Utils.ErrorFlagsStr(ErrorIndicators);
|
|
var str = string.IsNullOrEmpty(eFlags) ? PassedColorStr(null) : eFlags;
|
|
return str;
|
|
}
|
|
|
|
public virtual string PassedColorStr(string yesNoFormatOrEmpty)
|
|
{
|
|
if (string.IsNullOrEmpty(yesNoFormatOrEmpty))
|
|
{
|
|
return Utils.PassedColorStr(Passed, Evaluate());
|
|
}
|
|
else
|
|
{
|
|
string[] yesNo = yesNoFormatOrEmpty.Split(new char[] { '~' });
|
|
return Passed ? yesNo[0] : ((yesNo.Length >= 2) ? yesNo[1] : Results.Resources.Strings.No);
|
|
}
|
|
}
|
|
|
|
public MeterTestRslt()
|
|
{
|
|
TestDone = false;
|
|
Passed = false;
|
|
}
|
|
|
|
public MeterTestRslt(WaterMeter waterMeterRslt, TestRslt testRslt, CompoundMeterId compoundMeterId)
|
|
: this()
|
|
{
|
|
WaterMeter = waterMeterRslt;
|
|
TestRslt = testRslt;
|
|
CompoundMeterId = (byte)compoundMeterId;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Copy constructor, copies all except of Id
|
|
/// TestRslt and WaterMeter references arenot set.
|
|
/// They have to be copied/ser manually.
|
|
/// </summary>
|
|
public MeterTestRslt(MeterTestRslt oriMTR)
|
|
{
|
|
CopyContentFrom(oriMTR);
|
|
}
|
|
|
|
public virtual void CopyContentFrom(MeterTestRslt src)
|
|
{
|
|
if (src == null) return;
|
|
|
|
CompoundMeterId = src.CompoundMeterId;
|
|
RegReaderType = src.RegReaderType;
|
|
PulsesMeter = src.PulsesMeter;
|
|
PulsesMaster = src.PulsesMaster;
|
|
PulsesPerLiter = src.PulsesPerLiter;
|
|
VolumeStart = src.VolumeStart;
|
|
VolumeEnd = src.VolumeEnd;
|
|
VolumeMeter = src.VolumeMeter;
|
|
VolumeRef = src.VolumeRef;
|
|
TimestampStart = src.TimestampStart;
|
|
TimestampEnd = src.TimestampEnd;
|
|
TestTime = src.TestTime;
|
|
Error = src.Error;
|
|
ErrorIndicators = src.ErrorIndicators;
|
|
InfoIndicators = src.InfoIndicators;
|
|
TestDone = src.TestDone;
|
|
Passed = src.Passed;
|
|
#if IPERL
|
|
CalibFactor = src.CalibFactor;
|
|
CalibFactorLNA = src.CalibFactorLNA;
|
|
Q2CorrRL = src.Q2CorrRL;
|
|
Q2CorrLR = src.Q2CorrLR;
|
|
ExtraDataPath = src.ExtraDataPath;
|
|
X1 = src.X1;
|
|
X2 = src.X2;
|
|
X3 = src.X3;
|
|
X4 = src.X4;
|
|
X5 = src.X5;
|
|
X6 = src.X6;
|
|
X7 = src.X7;
|
|
X8 = src.X8;
|
|
X9 = src.X9;
|
|
#endif
|
|
#if ORACLE_DB
|
|
ErrorBC = src.ErrorBC;
|
|
LastError = src.LastError;
|
|
#endif
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return (TestRslt != null) ? Name() : base.ToString();
|
|
}
|
|
|
|
public virtual void WriteBinary(BinaryWriter writer)
|
|
{
|
|
writer.Write(Id);
|
|
writer.Write(CompoundMeterId);
|
|
writer.Write(RegReaderType);
|
|
writer.Write(PulsesMeter);
|
|
writer.Write(PulsesMaster);
|
|
writer.Write(PulsesPerLiter);
|
|
writer.Write(VolumeStart);
|
|
writer.Write(VolumeEnd);
|
|
writer.Write(VolumeMeter);
|
|
writer.Write(VolumeRef);
|
|
writer.Write(TimestampStart);
|
|
writer.Write(TimestampEnd);
|
|
writer.Write(TestTime);
|
|
writer.Write(Error);
|
|
writer.Write(ErrorIndicators);
|
|
writer.Write(InfoIndicators);
|
|
writer.Write(TestDone);
|
|
writer.Write(Passed);
|
|
#if IPERL
|
|
writer.Write(CalibFactor);
|
|
writer.Write(CalibFactorLNA);
|
|
writer.Write(Q2CorrRL);
|
|
writer.Write(Q2CorrLR);
|
|
writer.Write((ExtraDataPath != null) ? ExtraDataPath : string.Empty);
|
|
writer.Write(X1);
|
|
writer.Write(X2);
|
|
writer.Write(X3);
|
|
writer.Write(X4);
|
|
writer.Write(X5);
|
|
writer.Write(X6);
|
|
writer.Write(X7);
|
|
writer.Write(X8);
|
|
writer.Write(X9);
|
|
#endif
|
|
#if ORACLE_DB
|
|
writer.Write(ErrorBC);
|
|
writer.Write(LastError);
|
|
#endif
|
|
writer.Write((TestRslt != null && TestRslt.Name() != null) ? TestRslt.Name() : string.Empty);
|
|
writer.Write(TestRslt != null ? TestRslt.Part : 0);
|
|
}
|
|
|
|
public virtual void ReadBinary(BinaryReader reader, IList<TestRslt> testResults)
|
|
{
|
|
Id = reader.ReadInt32();
|
|
CompoundMeterId = reader.ReadByte();
|
|
RegReaderType = reader.ReadInt32();
|
|
PulsesMeter = reader.ReadDouble();
|
|
PulsesMaster = reader.ReadDouble();
|
|
PulsesPerLiter = reader.ReadDouble();
|
|
VolumeStart = reader.ReadDouble();
|
|
VolumeEnd = reader.ReadDouble();
|
|
VolumeMeter = reader.ReadDouble();
|
|
VolumeRef = reader.ReadDouble();
|
|
TimestampStart = reader.ReadDouble();
|
|
TimestampEnd = reader.ReadDouble();
|
|
TestTime = reader.ReadDouble();
|
|
Error = reader.ReadDouble();
|
|
ErrorIndicators = reader.ReadInt64();
|
|
InfoIndicators = reader.ReadInt64();
|
|
TestDone = reader.ReadBoolean();
|
|
Passed = reader.ReadBoolean();
|
|
#if IPERL
|
|
CalibFactor = reader.ReadInt32();
|
|
CalibFactorLNA = reader.ReadInt32();
|
|
Q2CorrRL = reader.ReadInt32();
|
|
Q2CorrLR = reader.ReadInt32();
|
|
ExtraDataPath = reader.ReadString();
|
|
X1 = reader.ReadSingle();
|
|
X2 = reader.ReadSingle();
|
|
X3 = reader.ReadSingle();
|
|
X4 = reader.ReadSingle();
|
|
X5 = reader.ReadSingle();
|
|
X6 = reader.ReadSingle();
|
|
X7 = reader.ReadSingle();
|
|
X8 = reader.ReadSingle();
|
|
X9 = reader.ReadSingle();
|
|
#endif
|
|
#if ORACLE_DB
|
|
ErrorBC = reader.ReadDouble();
|
|
LastError = reader.ReadDouble();
|
|
#endif
|
|
TestRslt = null;
|
|
string trName = reader.ReadString();
|
|
int trPart = reader.ReadInt32();
|
|
if (testResults != null && !string.IsNullOrEmpty(trName))
|
|
{
|
|
foreach (var tr in testResults)
|
|
{
|
|
if ((tr.Name() == trName) && (tr.Part == trPart))
|
|
{
|
|
TestRslt = tr;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|