363 lines
19 KiB
C#
363 lines
19 KiB
C#
///
|
|
/// Copyright (c) 2019-2022 Sensus Slovensko a.s.
|
|
///
|
|
using System;
|
|
using System.Globalization;
|
|
using System.IO;
|
|
using Common;
|
|
|
|
namespace Config.Entities
|
|
{
|
|
/// <summary>
|
|
/// Test, consisting of one or more repetitions of the test 'SingleTest'.
|
|
/// </summary>
|
|
public class PTest : IHasName, IHasItemNr
|
|
{
|
|
public virtual int Id { get; protected set; }
|
|
public virtual int ItemNr { get; set; }
|
|
public virtual string Name { get; set; }
|
|
public virtual int Part { get; set; } /// Part=0 ... test of all WM-s /// Part>0 ... part of a set of tests with the same Name: subset of WM-s is given by MetersPath
|
|
public virtual double CoefQfrom { get; set; } /// Water flow low limit in [m3/h]
|
|
public virtual double CoefQto { get; set; } /// Water flow high limit in [m3/h]
|
|
public virtual double ErrLimLo { get; set; } /// in [%] usually < 0, in case of heat meters: 1=class1, 2=class2, 3=class3
|
|
public virtual double ErrLimHi { get; set; } /// in [%] usually > 0, in case of heat meters: -Qn in m3/h
|
|
public virtual double TempLimLo { get; set; } /// Lower limit for the controlled temperature
|
|
public virtual double TempLimHi { get; set; } /// Upper limit for the controlled temperature
|
|
public virtual double PressLimLo { get; set; } /// [bar] min. water pressure
|
|
public virtual double PressLimHi { get; set; } /// [bar] max. water pressure
|
|
public virtual sbyte Publish { get; set; } /// 0=no, 1=in all protocols, 2=on screen, 3=internal
|
|
public virtual bool Evaluate { get; set; }
|
|
public virtual string Method { get; set; } /// Test method (component name)
|
|
|
|
public virtual sbyte E1 { get; set; } ///
|
|
public virtual sbyte E2 { get; set; } ///
|
|
public virtual sbyte E3 { get; set; } ///
|
|
public virtual sbyte E4 { get; set; } ///
|
|
public virtual sbyte E5 { get; set; } ///
|
|
public virtual sbyte E6 { get; set; } ///
|
|
public virtual sbyte E7 { get; set; } ///
|
|
public virtual sbyte E8 { get; set; } ///
|
|
public virtual sbyte E9 { get; set; } /// 0=off, 1=info, 2=evaluate
|
|
public virtual sbyte E10 { get; set; } ///
|
|
public virtual sbyte E11 { get; set; } ///
|
|
public virtual sbyte E12 { get; set; } ///
|
|
public virtual sbyte E13 { get; set; } ///
|
|
public virtual sbyte E14 { get; set; } ///
|
|
public virtual sbyte E15 { get; set; } ///
|
|
public virtual sbyte E16 { get; set; } ///
|
|
public virtual sbyte E21 { get; set; } ///
|
|
|
|
public virtual double Delta_Q_pct { get; set; } /// [%] max deviation from the mean flow
|
|
public virtual double Delta_T { get; set; } /// [°C] max. T_up or T_down deviation from the mean temperature
|
|
public virtual double Delta_Tup_Tdn { get; set; } /// [°C] max. difference abs(T_up - T_down)
|
|
public virtual double TestTime_min { get; set; } /// [s]
|
|
public virtual double TestTime_max { get; set; } /// [s]
|
|
public virtual double AmbTemp_min { get; set; } /// [°C] min. ambient temperature
|
|
public virtual double AmbTemp_max { get; set; } /// [°C] max. ambient temperature
|
|
|
|
public virtual double Coef_E9 { get; set; } /// Coefficient used in E9, default 0.025
|
|
public virtual double Coef_E10 { get; set; } /// Coefficient used in E10, default 0.04
|
|
public virtual double Coef_E11 { get; set; } /// Coefficient used in E11, default 0.1
|
|
public virtual double Coef_E12 { get; set; } /// Coefficient used in E12, default 1
|
|
public virtual double Offset_E9 { get; set; } /// [s] default 0 (no offset)
|
|
public virtual double Offset_E12 { get; set; } /// [s] default 0 (no offset)
|
|
|
|
public virtual Profile Profile { get; set; }
|
|
|
|
/// ------------- Additional stuff not mapped into the database -------------
|
|
|
|
public PTest()
|
|
{
|
|
///
|
|
/// Default values
|
|
///
|
|
Part = 0;
|
|
CoefQfrom = 1.0;
|
|
CoefQto = 1.1;
|
|
ErrLimLo = -2.0; /// [%]
|
|
ErrLimHi = 2.0; /// [%]
|
|
TempLimLo = 15.0; /// [°C]
|
|
TempLimHi = 25.0; /// [°C]
|
|
PressLimLo = 0; /// [bar]
|
|
PressLimHi = 16.0; /// [bar]
|
|
Publish = (sbyte)Common.Publish.Always;
|
|
Evaluate = true;
|
|
Method = string.Empty;
|
|
|
|
E1 = (sbyte)ErrorFlagsMode.On;
|
|
E2 = (sbyte)ErrorFlagsMode.On;
|
|
E3 = (sbyte)ErrorFlagsMode.On;
|
|
E4 = (sbyte)ErrorFlagsMode.On;
|
|
E5 = (sbyte)ErrorFlagsMode.On;
|
|
E6 = (sbyte)ErrorFlagsMode.On;
|
|
E7 = (sbyte)ErrorFlagsMode.On;
|
|
E8 = (sbyte)ErrorFlagsMode.On;
|
|
E9 = (sbyte)ErrorFlagsMode.On;
|
|
E10 = (sbyte)ErrorFlagsMode.On;
|
|
E11 = (sbyte)ErrorFlagsMode.On;
|
|
E12 = (sbyte)ErrorFlagsMode.On;
|
|
E13 = (sbyte)ErrorFlagsMode.On;
|
|
E14 = (sbyte)ErrorFlagsMode.On;
|
|
E15 = (sbyte)ErrorFlagsMode.On;
|
|
E16 = (sbyte)ErrorFlagsMode.Off;
|
|
E21 = (sbyte)ErrorFlagsMode.Off;
|
|
|
|
Delta_Q_pct = 5.0; /// [%]
|
|
Delta_T = 10.0; /// [°C]
|
|
Delta_Tup_Tdn = 10.0; /// [°C]
|
|
TestTime_min = 0; /// [s]
|
|
TestTime_max = 99999; /// [s]
|
|
AmbTemp_min = 5.0; /// [°C]
|
|
AmbTemp_max = 95.0; /// [°C]
|
|
|
|
Coef_E9 = 0.025;
|
|
Coef_E10 = 0.04;
|
|
Coef_E11 = 0.1;
|
|
Coef_E12 = 1.0;
|
|
Offset_E9 = 0; /// [s]
|
|
Offset_E12 = 0; /// [s]
|
|
}
|
|
|
|
public PTest(string name, int itemNr, Profile profile)
|
|
: this()
|
|
{
|
|
Name = name;
|
|
ItemNr = itemNr;
|
|
Profile = profile;
|
|
}
|
|
|
|
// Makes a new copy of this object (not just a reference)
|
|
public virtual PTest Clone()
|
|
{
|
|
PTest result = new PTest(Name, ItemNr, Profile);
|
|
|
|
result.Part = Part;
|
|
result.CoefQfrom = CoefQfrom;
|
|
result.CoefQto = CoefQto;
|
|
result.ErrLimLo = ErrLimLo;
|
|
result.ErrLimHi = ErrLimHi;
|
|
result.TempLimLo = TempLimLo;
|
|
result.TempLimHi = TempLimHi;
|
|
result.PressLimLo = PressLimLo;
|
|
result.PressLimHi = PressLimHi;
|
|
result.Publish = Publish;
|
|
result.Evaluate = Evaluate;
|
|
result.Method = Method;
|
|
|
|
result.E1 = E1;
|
|
result.E2 = E2;
|
|
result.E3 = E3;
|
|
result.E4 = E4;
|
|
result.E5 = E5;
|
|
result.E6 = E6;
|
|
result.E7 = E7;
|
|
result.E8 = E8;
|
|
result.E9 = E9;
|
|
result.E10 = E10;
|
|
result.E11 = E11;
|
|
result.E12 = E12;
|
|
result.E13 = E13;
|
|
result.E14 = E14;
|
|
result.E15 = E15;
|
|
result.E16 = E16;
|
|
result.E21 = E21;
|
|
|
|
result.Delta_Q_pct = Delta_Q_pct;
|
|
result.Delta_T = Delta_T;
|
|
result.Delta_Tup_Tdn = Delta_Tup_Tdn;
|
|
result.TestTime_min = TestTime_min;
|
|
result.TestTime_max = TestTime_max;
|
|
result.AmbTemp_min = AmbTemp_min;
|
|
result.AmbTemp_max = AmbTemp_max;
|
|
|
|
result.Coef_E9 = Coef_E9;
|
|
result.Coef_E10 = Coef_E10;
|
|
result.Coef_E11 = Coef_E11;
|
|
result.Coef_E12 = Coef_E12;
|
|
result.Offset_E9 = Offset_E9;
|
|
result.Offset_E12 = Offset_E12;
|
|
|
|
return result;
|
|
}
|
|
|
|
public virtual void Export(StreamWriter output)
|
|
{
|
|
CultureInfo ci = CultureInfo.InvariantCulture;
|
|
|
|
output.WriteLine(Name);
|
|
output.WriteLine(Part);
|
|
output.WriteLine(CoefQfrom.ToString(ci));
|
|
output.WriteLine(CoefQto.ToString(ci));
|
|
output.WriteLine(ErrLimLo.ToString(ci));
|
|
output.WriteLine(ErrLimHi.ToString(ci));
|
|
output.WriteLine(TempLimLo.ToString(ci));
|
|
output.WriteLine(TempLimHi.ToString(ci));
|
|
output.WriteLine(PressLimLo.ToString(ci));
|
|
output.WriteLine(PressLimHi.ToString(ci));
|
|
output.WriteLine(Publish.ToString());
|
|
output.WriteLine(Evaluate.ToString());
|
|
output.WriteLine(Method);
|
|
|
|
output.WriteLine(E1.ToString());
|
|
output.WriteLine(E2.ToString());
|
|
output.WriteLine(E3.ToString());
|
|
output.WriteLine(E4.ToString());
|
|
output.WriteLine(E5.ToString());
|
|
output.WriteLine(E6.ToString());
|
|
output.WriteLine(E7.ToString());
|
|
output.WriteLine(E8.ToString());
|
|
output.WriteLine(E9.ToString());
|
|
output.WriteLine(E10.ToString());
|
|
output.WriteLine(E11.ToString());
|
|
output.WriteLine(E12.ToString());
|
|
output.WriteLine(E13.ToString());
|
|
output.WriteLine(E14.ToString());
|
|
output.WriteLine(E15.ToString());
|
|
output.WriteLine(E16.ToString());
|
|
output.WriteLine(E21.ToString());
|
|
|
|
output.WriteLine(Delta_Q_pct.ToString(ci));
|
|
output.WriteLine(Delta_T.ToString(ci));
|
|
output.WriteLine(Delta_Tup_Tdn.ToString(ci));
|
|
output.WriteLine(TestTime_min.ToString(ci));
|
|
output.WriteLine(TestTime_max.ToString(ci));
|
|
output.WriteLine(AmbTemp_min.ToString(ci));
|
|
output.WriteLine(AmbTemp_max.ToString(ci));
|
|
|
|
output.WriteLine(Coef_E9.ToString(ci));
|
|
output.WriteLine(Coef_E10.ToString(ci));
|
|
output.WriteLine(Coef_E11.ToString(ci));
|
|
output.WriteLine(Coef_E12.ToString(ci));
|
|
output.WriteLine(Offset_E9.ToString(ci));
|
|
output.WriteLine(Offset_E12.ToString(ci));
|
|
}
|
|
|
|
public static PTest Import(StreamReader input, Profile newProfile)
|
|
{
|
|
string firstLine = input.ReadLine();
|
|
if (string.IsNullOrEmpty(firstLine))
|
|
{
|
|
return null;
|
|
}
|
|
|
|
CultureInfo ci = CultureInfo.InvariantCulture;
|
|
PTest tst = new PTest();
|
|
|
|
tst.Name = firstLine;
|
|
tst.Part = int.Parse(input.ReadLine());
|
|
tst.CoefQfrom = double.Parse(input.ReadLine(), ci);
|
|
tst.CoefQto = double.Parse(input.ReadLine(), ci);
|
|
tst.ErrLimLo = double.Parse(input.ReadLine(), ci);
|
|
tst.ErrLimHi = double.Parse(input.ReadLine(), ci);
|
|
tst.TempLimLo = double.Parse(input.ReadLine(), ci);
|
|
tst.TempLimHi = double.Parse(input.ReadLine(), ci);
|
|
tst.PressLimLo = double.Parse(input.ReadLine(), ci);
|
|
tst.PressLimHi = double.Parse(input.ReadLine(), ci);
|
|
tst.Publish = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.Evaluate = bool.Parse(input.ReadLine());
|
|
tst.Method = input.ReadLine();
|
|
|
|
tst.E1 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E2 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E3 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E4 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E5 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E6 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E7 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E8 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E9 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E10 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E11 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E12 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E13 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E14 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E15 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E16 = sbyte.Parse(input.ReadLine(), ci);
|
|
tst.E21 = sbyte.Parse(input.ReadLine(), ci);
|
|
|
|
tst.Delta_Q_pct = double.Parse(input.ReadLine(), ci);
|
|
tst.Delta_T = double.Parse(input.ReadLine(), ci);
|
|
tst.Delta_Tup_Tdn = double.Parse(input.ReadLine(), ci);
|
|
tst.TestTime_min = double.Parse(input.ReadLine(), ci);
|
|
tst.TestTime_max = double.Parse(input.ReadLine(), ci);
|
|
tst.AmbTemp_min = double.Parse(input.ReadLine(), ci);
|
|
tst.AmbTemp_max = double.Parse(input.ReadLine(), ci);
|
|
|
|
tst.Coef_E9 = double.Parse(input.ReadLine(), ci);
|
|
tst.Coef_E10 = double.Parse(input.ReadLine(), ci);
|
|
tst.Coef_E11 = double.Parse(input.ReadLine(), ci);
|
|
tst.Coef_E12 = double.Parse(input.ReadLine(), ci);
|
|
tst.Offset_E9 = double.Parse(input.ReadLine(), ci);
|
|
tst.Offset_E12 = double.Parse(input.ReadLine(), ci);
|
|
|
|
tst.Profile = newProfile;
|
|
return tst;
|
|
}
|
|
|
|
public virtual string Compare(StreamReader inp)
|
|
{
|
|
System.Text.StringBuilder diff = new System.Text.StringBuilder();
|
|
string fmt = string.Format("Test {0} : ", Name) + "{0} = {1}\r\n (in the file {2})\r\n";
|
|
string ln;
|
|
CultureInfo ci = CultureInfo.InvariantCulture;
|
|
|
|
string firstLine = inp.ReadLine();
|
|
if (string.IsNullOrEmpty(firstLine)) return string.Format("Test {0} is missing in the file\r\n", Name);
|
|
|
|
if (Name != firstLine) { diff.AppendFormat(fmt, "Name", Name, firstLine); };
|
|
ln = inp.ReadLine(); if (ln != Part.ToString()) { diff.AppendFormat(fmt, "Part", Part.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != CoefQfrom.ToString(ci)) { diff.AppendFormat(fmt, "CoefQfrom", CoefQfrom.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != CoefQto.ToString(ci)) { diff.AppendFormat(fmt, "CoefQto", CoefQto.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != ErrLimLo.ToString(ci)) { diff.AppendFormat(fmt, "ErrLimLo", ErrLimLo.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != ErrLimHi.ToString(ci)) { diff.AppendFormat(fmt, "ErrLimHi", ErrLimHi.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != TempLimLo.ToString(ci)) { diff.AppendFormat(fmt, "TempLimLo", TempLimLo.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != TempLimHi.ToString(ci)) { diff.AppendFormat(fmt, "TempLimHi", TempLimHi.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != PressLimLo.ToString(ci)) { diff.AppendFormat(fmt, "Pressure_min", PressLimLo.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != PressLimHi.ToString(ci)) { diff.AppendFormat(fmt, "Pressure_max", PressLimHi.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != Publish.ToString()) { diff.AppendFormat(fmt, "Publish", Publish.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != Evaluate.ToString()) { diff.AppendFormat(fmt, "Evaluate", Evaluate.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != Method) { diff.AppendFormat(fmt, "Method", Method, ln); };
|
|
|
|
ln = inp.ReadLine(); if (ln != E1.ToString()) { diff.AppendFormat(fmt, "E1", E1.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E2.ToString()) { diff.AppendFormat(fmt, "E2", E2.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E3.ToString()) { diff.AppendFormat(fmt, "E3", E3.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E4.ToString()) { diff.AppendFormat(fmt, "E4", E4.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E5.ToString()) { diff.AppendFormat(fmt, "E5", E5.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E6.ToString()) { diff.AppendFormat(fmt, "E6", E6.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E7.ToString()) { diff.AppendFormat(fmt, "E7", E7.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E8.ToString()) { diff.AppendFormat(fmt, "E8", E8.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E9.ToString()) { diff.AppendFormat(fmt, "E9", E9.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E10.ToString()) { diff.AppendFormat(fmt, "E10", E10.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E11.ToString()) { diff.AppendFormat(fmt, "E11", E11.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E12.ToString()) { diff.AppendFormat(fmt, "E12", E12.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E13.ToString()) { diff.AppendFormat(fmt, "E13", E13.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E14.ToString()) { diff.AppendFormat(fmt, "E14", E14.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E15.ToString()) { diff.AppendFormat(fmt, "E15", E15.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E16.ToString()) { diff.AppendFormat(fmt, "E16", E16.ToString(), ln); };
|
|
ln = inp.ReadLine(); if (ln != E21.ToString()) { diff.AppendFormat(fmt, "E21", E21.ToString(), ln); };
|
|
|
|
ln = inp.ReadLine(); if (ln != Delta_Q_pct.ToString(ci)) { diff.AppendFormat(fmt, "Delta_Q_pct", Delta_Q_pct.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != Delta_T.ToString(ci)) { diff.AppendFormat(fmt, "Delta_T", Delta_T.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != Delta_Tup_Tdn.ToString(ci)) { diff.AppendFormat(fmt, "Delta_Tup_Tdn", Delta_Tup_Tdn.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != TestTime_min.ToString(ci)) { diff.AppendFormat(fmt, "TestTime_min", TestTime_min.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != TestTime_max.ToString(ci)) { diff.AppendFormat(fmt, "TestTime_max", TestTime_max.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != AmbTemp_min.ToString(ci)) { diff.AppendFormat(fmt, "AmbTemp_min", AmbTemp_min.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != AmbTemp_max.ToString(ci)) { diff.AppendFormat(fmt, "AmbTemp_max", AmbTemp_max.ToString(ci), ln); };
|
|
|
|
ln = inp.ReadLine(); if (ln != Coef_E9.ToString(ci)) { diff.AppendFormat(fmt, "Coef_E9", Coef_E9.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != Coef_E10.ToString(ci)) { diff.AppendFormat(fmt, "Coef_E10", Coef_E10.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != Coef_E11.ToString(ci)) { diff.AppendFormat(fmt, "Coef_E11", Coef_E11.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != Coef_E12.ToString(ci)) { diff.AppendFormat(fmt, "Coef_E12", Coef_E12.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != Offset_E9.ToString(ci)) { diff.AppendFormat(fmt, "Offset_E9", Offset_E9.ToString(ci), ln); };
|
|
ln = inp.ReadLine(); if (ln != Offset_E12.ToString(ci)) { diff.AppendFormat(fmt, "Offset_E12", Offset_E12.ToString(ci), ln); };
|
|
|
|
return diff.ToString();
|
|
}
|
|
|
|
public override string ToString()
|
|
{
|
|
return string.Format("{0}", Name);
|
|
}
|
|
}
|
|
}
|