2015-04-15 18:32:56 +00:00
///
2017-03-31 16:14:21 +00:00
/// Copyright (c) 2013-2017 Sensus Metering Systems
2015-04-15 18:32:56 +00:00
///
using System ;
2014-07-28 07:54:35 +00:00
using System.Collections.Generic ;
2017-03-31 16:14:21 +00:00
using System.IO ;
2014-07-28 07:54:35 +00:00
2015-12-04 16:17:20 +00:00
namespace Config.Entities
2014-07-28 07:54:35 +00:00
{
/// <summary>
/// Test, consisting of one or more repetitions of the test 'SingleTest'.
/// </summary>
public class Test : IHasItemNr
{
public virtual int Id { get ; protected set ; }
public virtual int ItemNr { get ; set ; }
2015-01-04 22:21:12 +00:00
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
2016-02-29 14:33:31 +00:00
public virtual sbyte Publish { get ; set ; } /// 0=no, 1=in all protocols, 2=on screen, 3=internal
2016-01-01 23:54:21 +00:00
public virtual bool Evaluate { get ; set ; }
2015-01-04 22:21:12 +00:00
public virtual float Qfrom { get ; set ; } /// Water flow low limit in [m3/h]
2014-07-28 07:54:35 +00:00
public virtual float Qto { get ; set ; } /// Water flow high limit in [m3/h]
public virtual float Volume { get ; set ; } /// Test volume (target) in [l]
2017-03-31 16:14:21 +00:00
public virtual float TstTime { get ; set ; } /// Test time (estimate) in [s]
2016-04-14 15:03:33 +00:00
public virtual string Method { get ; set ; }
public virtual float ErrLimLo { get ; set ; } /// in [%] (usually < 0)
public virtual float ErrLimHi { get ; set ; } /// in [%] (usually > 0)
public virtual float Uncertainty { get ; set ; } /// int [%] makes error limits tighter: 0 <= Uncertainty <= abs(ErrLimXx)
2014-07-28 07:54:35 +00:00
public virtual int Repeats { get ; set ; }
2017-03-28 21:47:32 +00:00
public virtual bool Draining { get ; set ; }
2014-07-28 07:54:35 +00:00
public virtual bool Zeroing { get ; set ; }
2017-03-28 19:40:27 +00:00
public virtual float PumpPower { get ; set ; } /// Power of the pump in [%] in the range 0 .. 100.0f, use values 0% and 100% for non-FM pumps
public virtual int MassRepeats { get ; set ; } /// Number of mass. measurements at the beginning/end of test, 0 = default (=5)
public virtual float MassSpread { get ; set ; } /// Max spread of mass. measurements at the beginning/end of test, 0 = default
public virtual MassMethod MassMethod { get ; set ; } /// method of mass. measurement at the beginning/end of test: false=slow (precise), true=using immediate mass measurement and evaluation
public virtual int TimeBeforeFlow { get ; set ; } /// Delay time before the start of flow control in [s]
public virtual int TimeFlow2Mass { get ; set ; } /// Delay time from the flow stable to the 1st mass measurement in [s]
public virtual int TimePump2StartV { get ; set ; } /// Delay time from the start of the pump to opening the start valve in [s]
public virtual int TimeStop2Mass { get ; set ; } /// Delay time from the test end (diverted) to the 2nd mass measuremen in [s]
public virtual double TolerRed { get ; set ; } /// = Filter
2014-07-28 07:54:35 +00:00
public virtual TestRedType RedType { get ; set ; }
public virtual string FeedingPath { get ; set ; }
public virtual string BenchPath { get ; set ; }
public virtual string OutputPath { get ; set ; }
public virtual string MetersPath { get ; set ; }
2017-02-14 12:25:43 +00:00
#if HEAT_METERS
2016-06-28 16:04:52 +00:00
public virtual string HeatMetersPath { get ; set ; }
#endif
public virtual string RelTransBefore { get ; set ; }
2015-05-22 08:29:56 +00:00
public virtual string RelTransBetween { get ; set ; }
public virtual string RelTransAfter { get ; set ; }
public virtual string TransitionAfter { get ; set ; }
2014-07-28 07:54:35 +00:00
public virtual IList < ComponentTest > MoreParams { get ; set ; }
public virtual Procedure Procedure { get ; set ; }
/// ------------- Additional stuff not mapped into the database -------------
public Test ( )
{
MoreParams = new List < ComponentTest > ( ) ;
2015-02-02 13:45:06 +00:00
///
/// Default values
///
2016-02-29 14:33:31 +00:00
Publish = ( sbyte ) Config . Entities . Publish . Always ;
2016-01-01 23:54:21 +00:00
Evaluate = true ;
2015-02-02 13:45:06 +00:00
Repeats = 1 ;
2017-03-28 21:47:32 +00:00
Draining = false ;
2015-02-02 13:45:06 +00:00
Zeroing = false ;
2017-03-28 19:40:27 +00:00
ErrLimLo = - 2.0f ; /// [%] lower error limit
ErrLimHi = 2.0f ; /// [%] upper error limit
2015-11-27 14:10:55 +00:00
Uncertainty = 0 ;
2017-03-28 19:40:27 +00:00
PumpPower = 60.0f ; /// [%]
MassRepeats = 0 ; /// default
MassSpread = 0 ; /// default
MassMethod = MassMethod . Scale ; /// default
TimeBeforeFlow = 10 ; /// [s] time before the start of flow control in [s]
TimeFlow2Mass = 5 ; /// [s] time from the flow stable to the 1st mass measurement in [s]
TimePump2StartV = 1 ; /// [s] time from the 1st mass measurement to the test start in [s]
TimeStop2Mass = 5 ; /// [s] between the test end and the final mass measurement
TolerRed = 0 ; /// = Filter parameter
RelTransBefore = string . Empty ;
2016-01-26 12:34:19 +00:00
RelTransBetween = string . Empty ;
2017-03-28 19:40:27 +00:00
RelTransAfter = string . Empty ;
2016-01-26 12:34:19 +00:00
TransitionAfter = string . Empty ;
2014-07-28 07:54:35 +00:00
}
public Test ( string name , int itemNr , Procedure procedure )
: this ( )
{
Name = name ;
ItemNr = itemNr ;
Procedure = procedure ;
}
// Makes a new copy of this object (not just a reference)
public virtual Test Clone ( )
{
Test result = new Test ( Name , ItemNr , Procedure ) ;
2015-01-04 22:21:12 +00:00
result . Part = Part ;
2016-01-01 23:54:21 +00:00
result . Publish = Publish ;
result . Evaluate = Evaluate ;
2014-07-28 07:54:35 +00:00
result . Qfrom = Qfrom ;
result . Qto = Qto ;
result . Volume = Volume ;
result . TstTime = TstTime ;
result . Repeats = Repeats ;
2017-03-28 21:47:32 +00:00
result . Draining = Draining ;
2014-07-28 07:54:35 +00:00
result . Zeroing = Zeroing ;
2015-01-17 03:52:42 +00:00
result . PumpPower = PumpPower ;
2016-04-14 15:03:33 +00:00
result . MassRepeats = MassRepeats ;
result . MassSpread = MassSpread ;
result . MassMethod = MassMethod ;
2015-05-19 13:38:58 +00:00
result . TimeBeforeFlow = TimeBeforeFlow ;
result . TimeFlow2Mass = TimeFlow2Mass ;
2016-03-17 04:05:30 +00:00
result . TimePump2StartV = TimePump2StartV ;
2015-05-19 13:38:58 +00:00
result . TimeStop2Mass = TimeStop2Mass ;
2014-07-28 07:54:35 +00:00
result . Method = Method ;
result . ErrLimLo = ErrLimLo ;
result . ErrLimHi = ErrLimHi ;
2015-11-27 14:10:55 +00:00
result . Uncertainty = Uncertainty ;
result . TolerRed = TolerRed ;
2014-07-28 07:54:35 +00:00
result . RedType = RedType ;
result . FeedingPath = FeedingPath ;
result . BenchPath = BenchPath ;
result . OutputPath = OutputPath ;
result . MetersPath = MetersPath ;
2017-02-14 12:25:43 +00:00
#if HEAT_METERS
2016-06-28 16:04:52 +00:00
result . HeatMetersPath = HeatMetersPath ;
#endif
2016-01-26 12:34:19 +00:00
result . RelTransBefore = RelTransBefore ;
result . RelTransBetween = RelTransBetween ;
result . RelTransAfter = RelTransAfter ;
result . TransitionAfter = TransitionAfter ;
2014-07-28 07:54:35 +00:00
foreach ( var prms in MoreParams ) { result . MoreParams . Add ( prms . Clone ( ) ) ; }
return result ;
}
2016-01-10 11:39:20 +00:00
2017-03-31 16:14:21 +00:00
public virtual void Export ( StreamWriter output )
{
output . WriteLine ( Name ) ;
output . WriteLine ( Part . ToString ( ) ) ;
output . WriteLine ( Publish . ToString ( ) ) ;
output . WriteLine ( Evaluate . ToString ( ) ) ;
output . WriteLine ( Qfrom . ToString ( ) ) ;
output . WriteLine ( Qto . ToString ( ) ) ;
output . WriteLine ( Volume . ToString ( ) ) ;
output . WriteLine ( TstTime . ToString ( ) ) ;
output . WriteLine ( Method ) ;
output . WriteLine ( ErrLimLo . ToString ( ) ) ;
output . WriteLine ( ErrLimHi . ToString ( ) ) ;
output . WriteLine ( Uncertainty . ToString ( ) ) ;
output . WriteLine ( Repeats . ToString ( ) ) ;
output . WriteLine ( Draining . ToString ( ) ) ;
output . WriteLine ( Zeroing . ToString ( ) ) ;
output . WriteLine ( PumpPower . ToString ( ) ) ;
output . WriteLine ( MassRepeats . ToString ( ) ) ;
output . WriteLine ( MassSpread . ToString ( ) ) ;
output . WriteLine ( ( ( byte ) MassMethod ) . ToString ( ) ) ;
output . WriteLine ( TimeBeforeFlow . ToString ( ) ) ;
output . WriteLine ( TimeFlow2Mass . ToString ( ) ) ;
output . WriteLine ( TimePump2StartV . ToString ( ) ) ;
output . WriteLine ( TimeStop2Mass . ToString ( ) ) ;
output . WriteLine ( FeedingPath ) ;
output . WriteLine ( BenchPath ) ;
output . WriteLine ( OutputPath ) ;
output . WriteLine ( MetersPath ) ;
output . WriteLine ( RelTransBefore ) ;
output . WriteLine ( RelTransBetween ) ;
output . WriteLine ( RelTransAfter ) ;
output . WriteLine ( TransitionAfter ) ;
foreach ( var prms in MoreParams ) { prms . Export ( output ) ; }
output . WriteLine ( ) ;
}
public static Test Import ( StreamReader input , Procedure newProcedure )
{
string firstLine = input . ReadLine ( ) ;
if ( string . IsNullOrEmpty ( firstLine ) ) return null ;
Test tst = new Test ( ) ;
tst . Name = firstLine ;
tst . Part = int . Parse ( input . ReadLine ( ) ) ;
tst . Publish = sbyte . Parse ( input . ReadLine ( ) ) ;
tst . Evaluate = bool . Parse ( input . ReadLine ( ) ) ;
tst . Qfrom = float . Parse ( input . ReadLine ( ) ) ;
tst . Qto = float . Parse ( input . ReadLine ( ) ) ;
tst . Volume = float . Parse ( input . ReadLine ( ) ) ;
tst . TstTime = float . Parse ( input . ReadLine ( ) ) ;
tst . Method = input . ReadLine ( ) ;
tst . ErrLimLo = float . Parse ( input . ReadLine ( ) ) ;
tst . ErrLimHi = float . Parse ( input . ReadLine ( ) ) ;
tst . Uncertainty = float . Parse ( input . ReadLine ( ) ) ;
tst . Repeats = int . Parse ( input . ReadLine ( ) ) ;
tst . Draining = bool . Parse ( input . ReadLine ( ) ) ;
tst . Zeroing = bool . Parse ( input . ReadLine ( ) ) ;
tst . PumpPower = float . Parse ( input . ReadLine ( ) ) ;
tst . MassRepeats = int . Parse ( input . ReadLine ( ) ) ;
tst . MassSpread = float . Parse ( input . ReadLine ( ) ) ;
tst . MassMethod = ( MassMethod ) byte . Parse ( input . ReadLine ( ) ) ;
tst . TimeBeforeFlow = int . Parse ( input . ReadLine ( ) ) ;
tst . TimeFlow2Mass = int . Parse ( input . ReadLine ( ) ) ;
tst . TimePump2StartV = int . Parse ( input . ReadLine ( ) ) ;
tst . TimeStop2Mass = int . Parse ( input . ReadLine ( ) ) ;
tst . FeedingPath = input . ReadLine ( ) ;
tst . BenchPath = input . ReadLine ( ) ;
tst . OutputPath = input . ReadLine ( ) ;
tst . MetersPath = input . ReadLine ( ) ;
tst . RelTransBefore = input . ReadLine ( ) ;
tst . RelTransBetween = input . ReadLine ( ) ;
tst . RelTransAfter = input . ReadLine ( ) ;
tst . TransitionAfter = input . ReadLine ( ) ;
while ( true )
{
ComponentTest prms = ComponentTest . Import ( input , tst ) ;
if ( prms = = null )
break ;
else
tst . MoreParams . Add ( prms ) ;
}
tst . Procedure = newProcedure ;
return tst ;
}
2016-01-10 11:39:20 +00:00
public override string ToString ( )
{
string partStr = ( Part > 0 ) ? string . Format ( ", part {0}" , Part ) : string . Empty ;
2016-02-25 17:04:18 +00:00
return string . Format ( "{0}(P.{1},{2}){3}" , Name , ( ( Publish ) Publish ) . ToString ( ) , Evaluate ? "E" : "-" , partStr ) ;
2016-01-10 11:39:20 +00:00
}
2014-07-28 07:54:35 +00:00
}
}