tbf/SharedDatabase/Entities/TestData.cs

185 lines
7.1 KiB
C#

///
/// Copyright (c) 2016-2023 Sensus Slovensko a.s.
///
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Config.Entities;
namespace SharedDatabase.Entities
{
/// <summary>
/// Test, consisting of one or more repetitions of the test 'SingleTest'.
/// </summary>
public class TestData
{
public virtual int Id { get; protected set; }
public virtual string Name { get; set; }
public virtual int Repeats { get; set; }
public virtual double Qtg { get; set; } /// [m3/h] flow range low limit
public virtual double Qfrom { get; set; } /// [m3/h] or [%] flow range low limit
public virtual double Qto { get; set; } /// [m3/h] or [%] flow range high limit
public virtual bool IsFromToInPct { get; set; } /// true: Qfrom and Qto are in % of Qtg, false: Qfrom and Qto are in [m3/h]
public virtual double TargetVolume { get; set; } /// [l] target test volume
public virtual double TargetTime { get; set; } /// [s] target test time
public virtual string Method { get; set; }
public virtual double ErrLimLo { get; set; } /// [%] usually < 0, in case of heat meters: 1=class1, 2=class2, 3=class3
public virtual double ErrLimHi { get; set; } /// [%] usually > 0, in case of heat meters: -Qn in m3/h
public virtual double ErrLimMargin { get; set; } /// [%] makes error limits tighter: 0 <= ErrLimMargin <= abs(ErrLimXx)
public virtual float TempLimLo { get; set; }
public virtual float TempLimHi { get; set; }
public virtual string TempControl { get; set; }
public virtual sbyte Publish { get; set; } /// 0=no, 1=in all protocols, 2=on screen, 3=internal
public virtual bool Evaluate { get; set; }
/// <summary>
/// Default constructor, safe values
/// </summary>
public TestData()
{
Name = string.Empty;
Method = string.Empty;
}
public TestData(Test test)
: this()
{
Name = test.Name;
Repeats = test.Repeats;
Qtg = test.Qtg;
Qfrom = test.Qfrom;
Qto = test.Qto;
IsFromToInPct = test.IsFromToInPct;
TargetVolume = test.Volume;
TargetTime = test.TestTime;
Method = test.Method;
ErrLimLo = test.ErrLimLo;
ErrLimHi = test.ErrLimHi;
ErrLimMargin = test.Uncertainty;
TempLimLo = test.TempLimLo;
TempLimHi = test.TempLimHi;
TempControl = test.TempControl;
Publish = test.Publish;
Evaluate = test.DoEvaluate;
}
/// <summary>
/// Copy constructor, copies all except of Id
/// </summary>
public TestData(TestData oriTestData)
{
Name = oriTestData.Name;
Repeats = oriTestData.Repeats;
Qtg = oriTestData.Qtg;
Qfrom = oriTestData.Qfrom;
Qto = oriTestData.Qto;
IsFromToInPct = oriTestData.IsFromToInPct;
TargetVolume = oriTestData.TargetVolume;
TargetTime = oriTestData.TargetTime;
Method = oriTestData.Method;
ErrLimLo = oriTestData.ErrLimLo;
ErrLimHi = oriTestData.ErrLimHi;
ErrLimMargin = oriTestData.ErrLimMargin;
TempLimLo = oriTestData.TempLimLo;
TempLimHi = oriTestData.TempLimHi;
TempControl = oriTestData.TempControl;
Publish = oriTestData.Publish;
Evaluate = oriTestData.Evaluate;
}
/// <summary>
/// Method to compare the content of two entities
/// </summary>
/// <param name="wmd">Second entity to compare with</param>
/// <returns>first = two entities are equal (except of Id)</returns>
public virtual bool Equals(TestData td)
{
if (Name != td.Name) return false;
if (Repeats != td.Repeats) return false;
if (Qtg != td.Qtg) return false;
if (Qfrom != td.Qfrom) return false;
if (Qto != td.Qto) return false;
if (IsFromToInPct != td.IsFromToInPct) return false;
if (TargetVolume != td.TargetVolume) return false;
if (TargetTime != td.TargetTime) return false;
if (Method != td.Method) return false;
if (ErrLimLo != td.ErrLimLo) return false;
if (ErrLimHi != td.ErrLimHi) return false;
if (ErrLimMargin != td.ErrLimMargin) return false;
if (TempLimLo != td.TempLimLo) return false;
if (TempLimHi != td.TempLimHi) return false;
if (TempControl != td.TempControl) return false;
if (Publish != td.Publish) return false;
if (Evaluate != td.Evaluate) return false;
return true;
}
/// <summary>
/// Adds an item to the list if it does not occur there
/// </summary>
/// <param name="list">List of items</param>
/// <param name="item">Item to add to the list or find there</param>
/// <returns>Item from the list (existing or added)</returns>
public static TestData UpdateList(IList<TestData> list, TestData item)
{
if (item == null) return null; /// Null item is not stored in the list
TestData found = list.FirstOrDefault<TestData>(x => x.Equals(item));
if (found != null) return found; /// The same item found in the list, The found item returned
list.Add(item); /// Item not fund in the list, it is added to the list
return item;
}
public virtual void WriteBinary(BinaryWriter writer)
{
writer.Write(Id);
writer.Write((Name != null) ? Name : string.Empty);
writer.Write(Repeats);
writer.Write(Qtg);
writer.Write(Qfrom);
writer.Write(Qto);
writer.Write(IsFromToInPct);
writer.Write(TargetVolume);
writer.Write(TargetTime);
writer.Write((Method != null) ? Method : string.Empty);
writer.Write(ErrLimLo);
writer.Write(ErrLimHi);
writer.Write(ErrLimMargin);
writer.Write(TempLimLo);
writer.Write(TempLimHi);
writer.Write((TempControl != null) ? TempControl : string.Empty);
writer.Write(Publish);
writer.Write(Evaluate);
}
public virtual void ReadBinary(BinaryReader reader)
{
Id = reader.ReadInt32();
Name = reader.ReadString();
Repeats = reader.ReadInt32();
Qtg = reader.ReadDouble();
Qfrom = reader.ReadDouble();
Qto = reader.ReadDouble();
IsFromToInPct = reader.ReadBoolean();
TargetVolume = reader.ReadDouble();
TargetTime = reader.ReadDouble();
Method = reader.ReadString();
ErrLimLo = reader.ReadDouble();
ErrLimHi = reader.ReadDouble();
ErrLimMargin = reader.ReadDouble();
TempLimLo = reader.ReadSingle();
TempLimHi = reader.ReadSingle();
TempControl = reader.ReadString();
Publish = reader.ReadSByte();
Evaluate = reader.ReadBoolean();
}
}
}