/// /// Copyright (c) 2016 Sensus Metering Systems /// using System; using System.Collections.Generic; using System.Linq; namespace Results.Entities { /// /// Test, consisting of one or more repetitions of the test 'SingleTest'. /// 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 Qfrom { get; set; } /// [m3/h] flow range low limit public virtual double Qto { get; set; } /// [m3/h] flow range high limit 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) public virtual double ErrLimHi { get; set; } /// [%] (usually > 0) public virtual double Uncertainty { get; set; } /// [%] makes error limits tighter: 0 <= Uncertainty <= abs(ErrLimXx) public virtual bool Evaluate { get; set; } protected TestData() { Name = string.Empty; Method = string.Empty; } public TestData(Config.Entities.Test test) : this() { Name = test.Name; Repeats = test.Repeats; Qfrom = (double)test.Qfrom; Qto = (double)test.Qto; TargetVolume = (double)test.Volume; TargetTime = (double)test.TstTime; Method = test.Method; ErrLimLo = (double)test.ErrLimLo; ErrLimHi = (double)test.ErrLimHi; Uncertainty = (double)test.Uncertainty; Evaluate = test.Evaluate; } /// /// Method to compare the content of two entities /// /// Second entity to compare with /// first = two entities are equal (except of Id) public virtual bool Equals(TestData td) { if (!Name.Equals(td.Name)) return false; if (Repeats != td.Repeats) return false; if (Qfrom != td.Qfrom) return false; if (Qto != td.Qto) return false; if (TargetVolume != td.TargetVolume) return false; if (TargetTime != td.TargetTime) return false; if (!Method.Equals(td.Method)) return false; if (ErrLimLo != td.ErrLimLo) return false; if (ErrLimHi != td.ErrLimHi) return false; if (Uncertainty != td.Uncertainty) return false; if (Evaluate != td.Evaluate) return false; return true; } /// /// Adds an item to the list if it does not occur there /// /// List of items /// Item to add to the list or find there /// Item from the list (existing or added) public static TestData UpdateList(IList list, TestData item) { if (item == null) return null; /// Null item is not stored in the list TestData found = list.FirstOrDefault(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; } } }