2016-04-29 05:40:34 +00:00
///
/// Copyright (c) 2013-2016 Sensus Metering Systems
///
using System ;
using System.Collections.Generic ;
2016-10-14 12:27:38 +00:00
using Config ;
2016-05-03 17:00:15 +00:00
using Config.Entities ;
2016-04-29 05:40:34 +00:00
using Results.Entities ;
2016-06-05 19:11:36 +00:00
using Results.Resources ;
2016-04-29 05:40:34 +00:00
namespace Results
{
public class WMeterRsltItemSpec
{
///
/// Public fields
///
public readonly int Uid ;
2016-05-24 20:36:21 +00:00
public readonly string OldUid ;
2016-04-29 05:40:34 +00:00
public readonly string Name ; /// Name-s of all items must be unique
2016-10-14 12:27:38 +00:00
public readonly Quantity Quantity ; /// Quantity
2016-05-26 12:02:12 +00:00
public string Caption ; /// Specifies item description to be printed as a caption (in the header, etc.)
2016-04-29 05:40:34 +00:00
public string TestID ; /// Specifies the test
public Config . Unit Units ; /// Specifies units for the output
public string Format ; /// Specifies format for the output
public string Precision ; /// Specifies precision for the output
public int Width ; /// Specifies the number of characters of the output, 0 = automatic
public Config . Entities . Alignment Alignment ; /// Specifies alignment for the output
public WMeterRsltItemSpec Clone ( )
{
2016-10-14 12:27:38 +00:00
WMeterRsltItemSpec item2 = new WMeterRsltItemSpec ( ( ItemID ) Uid , Name , Quantity , printDlgt ) ;
2016-05-26 12:02:12 +00:00
item2 . Caption = Caption ;
2016-04-29 05:40:34 +00:00
item2 . TestID = TestID ;
item2 . Units = Units ;
item2 . Format = Format ;
item2 . Precision = Precision ;
item2 . Width = Width ;
item2 . Alignment = Alignment ;
return item2 ;
}
///
/// Function to pick a MeterTestResult field and convert it into a string
///
public delegate string PrintDlgt ( WaterMeter waterMeterResult , string testID , Config . Unit units , string format , string precision ) ;
private readonly PrintDlgt printDlgt ;
/// <summary> Safe wrapper which replaces null-s by empty strings </summary>
public string Print ( WaterMeter waterMeterResult )
{
string str = printDlgt ( waterMeterResult , TestID , Units , Format , Precision ) ;
if ( str = = null ) str = string . Empty ;
if ( ! string . IsNullOrEmpty ( Format ) )
{
str = string . Format ( Format , str ) ;
}
int len = str . Length ;
if ( Width = = 0 | | len > = Width )
{
return str ;
}
else if ( Alignment = = Config . Entities . Alignment . Left )
{
return str + new string ( ' ' , Width - len ) ;
}
else if ( Alignment = = Config . Entities . Alignment . Right )
{
return new string ( ' ' , Width - len ) + str ;
}
else // Alignment.Center or Alignment.Justified
{
int nrSpaces = Width - len ;
return new string ( ' ' , nrSpaces / 2 ) + str + new string ( ' ' , nrSpaces - ( nrSpaces / 2 ) ) ;
}
}
///
/// Public constructor
///
2016-10-14 12:27:38 +00:00
public WMeterRsltItemSpec ( ItemID itemId , string name , Quantity quantity , PrintDlgt printDlgt )
2016-04-29 05:40:34 +00:00
{
2016-08-01 13:40:51 +00:00
Uid = ( int ) itemId ;
OldUid = itemId . ToString ( ) . Replace ( "__" , "/" ) . Replace ( '_' , ' ' ) ;
2016-04-29 05:40:34 +00:00
Name = name ;
2016-10-14 12:27:38 +00:00
Quantity = quantity ;
2016-04-29 05:40:34 +00:00
this . printDlgt = printDlgt ;
}
/// Static list of all available items
public static readonly IList < WMeterRsltItemSpec > AllItems ;
/// Static constructor that initializes the list of all items
static WMeterRsltItemSpec ( )
{
AllItems = new List < WMeterRsltItemSpec > ( ) ;
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . String , "String" , Quantity . String , ( w , t , u , f , p ) = > f ) ) ;
2016-04-29 05:40:34 +00:00
/// Common
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Test_name , Strings . Test + " *" , Quantity . String , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : w . GetTestRslt ( t ) . Name ( ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Procedure_name , Strings . Procedure , Quantity . String , ( w , t , u , f , p ) = > w . ProcedureName ( ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Batch_number , Strings . Batch_nr , Quantity . Number , ( w , t , u , f , p ) = > w . BatchNr ( ) . ToString ( ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Test_method , Strings . Test_method + " *" , Quantity . String , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : w . GetTestRslt ( t ) . Method ( ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Density , Strings . Density + " *" , Quantity . Density , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : w . GetTestRslt ( t ) . DensityOut . ToString ( string . IsNullOrEmpty ( p ) ? "F1" : p ) ) ) ; /// [kg/m3]
2016-04-29 05:40:34 +00:00
/// Target values
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Q_from , Strings . Q_from + "()" , Quantity . Flow , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : w . GetTestRslt ( t ) . Qfrom ( ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Q_to , Strings . Q_to + "()" , Quantity . Flow , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : w . GetTestRslt ( t ) . Qto ( ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Test_volume , Strings . Test_vol + "()" , Quantity . Volume , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . TargetVolume ( ) ) . ToString ( string . IsNullOrEmpty ( p ) ? "F1" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Error_limit_Lo , Strings . ErrLimLo + "()" , Quantity . Error , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . ErrLimLo ( ) ) . ToString ( string . IsNullOrEmpty ( p ) ? "F1" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Error_limit_Hi , Strings . ErrLimHi + "()" , Quantity . Error , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . ErrLimHi ( ) ) . ToString ( string . IsNullOrEmpty ( p ) ? "F1" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Uncertainty , Strings . Uncertainty + "()" , Quantity . Error , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : w . GetTestRslt ( t ) . Uncertainty ( ) . ToString ( string . IsNullOrEmpty ( p ) ? "F2" : p ) ) ) ;
2016-04-29 05:40:34 +00:00
/// Test results
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Test_start_time , Strings . T_start + "()" , Quantity . DateTime , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : ( string . IsNullOrEmpty ( f ) ? w . GetTestRslt ( t ) . StartTime . ToString ( ) : string . Format ( f , w . GetTestRslt ( t ) . StartTime ) ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Test_end_time , Strings . T_end + "()" , Quantity . DateTime , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : ( string . IsNullOrEmpty ( f ) ? w . GetTestRslt ( t ) . EndTime . ToString ( ) : string . Format ( f , w . GetTestRslt ( t ) . EndTime ) ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Test_time , Strings . T_s + "()" , Quantity . Time , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : w . GetTestRslt ( t ) . TestTime . ToString ( string . IsNullOrEmpty ( p ) ? "F2" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Flow , Strings . Flow + "()" , Quantity . Flow , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Utils . DoubleToStr ( Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . FlowVolume ) , 4 ) ) ) ;
2016-10-18 16:48:20 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . T_up_mean , Strings . T_in + "()" , Quantity . Temperature , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . TempUpMean ) . ToString ( string . IsNullOrEmpty ( p ) ? "F2" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . T_down_mean , Strings . T_out + "()" , Quantity . Temperature , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . TempDownMean ) . ToString ( string . IsNullOrEmpty ( p ) ? "F2" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . T_div , Strings . T_div + "()" , Quantity . Temperature , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . TempDivMean ) . ToString ( string . IsNullOrEmpty ( p ) ? "F2" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . P_up , Strings . P_up + "()" , Quantity . Pressure , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . PressUpMean ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . P_up_start , Strings . P_up_start + "()" , Quantity . Pressure , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . PressUpStart ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . P_up_end , Strings . P_up_end + "()" , Quantity . Pressure , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . PressUpEnd ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
2016-10-18 16:48:20 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . P_down , Strings . P_dn + "()" , Quantity . Pressure , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . PressDownMean ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . P_down_start , Strings . P_dn_start + "()" , Quantity . Pressure , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . PressDownStart ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . P_down_end , Strings . P_dn_end + "()" , Quantity . Pressure , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . PressDownEnd ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
2016-10-18 16:48:20 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . P_delta_mean , Strings . P_delta + "()" , Quantity . Pressure , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . PressDeltaMean ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . P_delta_start , Strings . P_delta_start + "()" , Quantity . Pressure , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . PressDeltaStart ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . P_delta_end , Strings . P_delta_end + "()" , Quantity . Pressure , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . PressDeltaEnd ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Reference_error , Strings . ErrRef + "()" , Quantity . Error , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . ErrorMaster ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Ambient_temperature , Strings . T_amb + "()" , Quantity . Temperature , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? Config . Units . ConvertTo ( u , w . Batch . AmbientTempAve ( ) ) . ToString ( string . IsNullOrEmpty ( p ) ? "F1" : p ) : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . AmbTempMean ) . ToString ( string . IsNullOrEmpty ( p ) ? "F1" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Ambient_pressure , Strings . P_amb + "()" , Quantity . Pressure , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? Config . Units . ConvertTo ( u , w . Batch . AmbientPressAve ( ) ) . ToString ( string . IsNullOrEmpty ( p ) ? "F0" : p ) : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . AmbPressMean ) . ToString ( string . IsNullOrEmpty ( p ) ? "F0" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Ambient_humidity , Strings . H_amb + "()" , Quantity . Humidity , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? Config . Units . ConvertTo ( u , w . Batch . AmbientHumiAve ( ) ) . ToString ( string . IsNullOrEmpty ( p ) ? "F1" : p ) : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . AmbHumiMean ) . ToString ( string . IsNullOrEmpty ( p ) ? "F1" : p ) ) ) ;
2016-04-29 05:40:34 +00:00
/// Single and combined meter results
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Volume , Strings . Volume + "()" , Quantity . Volume , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t ) . VolumeMeter ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Reference_volume , Strings . VolRef + "()" , Quantity . Volume , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t ) . VolumeRef ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
2017-02-14 12:25:43 +00:00
#if TURA_IPERL | | TURA_SPECIAL
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Error , Strings . Error + "()" , Quantity . Error , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t ) = = null ) ? "0" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t ) . Error ) . ToString ( string . IsNullOrEmpty ( p ) ? "F2" : p ) ) ) ;
2016-05-26 15:14:55 +00:00
#else
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Error , Strings . Error + "()" , Quantity . Error , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t ) . Error ) . ToString ( string . IsNullOrEmpty ( p ) ? "F2" : p ) ) ) ;
2016-05-26 15:14:55 +00:00
#endif
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Passed , Strings . Result + "()" , Quantity . Boolean , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t ) = = null ) ? "" : w . GetMeterTestRslt ( t ) . PassedColorStr ( ) ) ) ;
2016-04-29 05:40:34 +00:00
/// Water meter info
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Watermeter_type , Strings . WM_Type , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . ProductName ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Producer , Strings . Producer , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . Producer ) ) ;
2016-08-02 11:42:26 +00:00
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . DN , "DN" , Quantity . Length , ( w , t , u , f , p ) = > string . IsNullOrEmpty ( p ) ? Config . Units . ConvertTo ( u , w . WaterMeterData . DN ) . ToString ( )
2016-08-02 11:42:26 +00:00
: Config . Units . ConvertTo ( u , w . WaterMeterData . DN ) . ToString ( p ) ) ) ;
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . L , "L" , Quantity . Length , ( w , t , u , f , p ) = > string . IsNullOrEmpty ( p ) ? Config . Units . ConvertTo ( u , w . WaterMeterData . L ) . ToString ( )
2016-08-02 11:42:26 +00:00
: Config . Units . ConvertTo ( u , w . WaterMeterData . L ) . ToString ( p ) ) ) ;
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Mounting , Strings . Mounting , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . Mounting . ToDescription ( ) ) ) ;
2016-08-02 11:42:26 +00:00
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Q4 , "Q4_Qmax" , Quantity . Flow , ( w , t , u , f , p ) = > string . IsNullOrEmpty ( p ) ? Config . Units . ConvertTo ( u , w . WaterMeterData . Q4_Qmax ) . ToString ( )
2016-08-02 11:42:26 +00:00
: Config . Units . ConvertTo ( u , w . WaterMeterData . Q4_Qmax ) . ToString ( p ) ) ) ;
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Q3 , "Q3_Qn" , Quantity . Flow , ( w , t , u , f , p ) = > string . IsNullOrEmpty ( p ) ? Config . Units . ConvertTo ( u , w . WaterMeterData . Q3_Qn ) . ToString ( )
2016-08-02 11:42:26 +00:00
: Config . Units . ConvertTo ( u , w . WaterMeterData . Q3_Qn ) . ToString ( p ) ) ) ;
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Q2 , "Q2_Qt" , Quantity . Flow , ( w , t , u , f , p ) = > string . IsNullOrEmpty ( p ) ? Config . Units . ConvertTo ( u , w . WaterMeterData . Q2_Qt ) . ToString ( )
2016-08-02 11:42:26 +00:00
: Config . Units . ConvertTo ( u , w . WaterMeterData . Q2_Qt ) . ToString ( p ) ) ) ;
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Q1 , "Q1_Qmin" , Quantity . Flow , ( w , t , u , f , p ) = > string . IsNullOrEmpty ( p ) ? Config . Units . ConvertTo ( u , w . WaterMeterData . Q1_Qmin ) . ToString ( )
2016-08-02 11:42:26 +00:00
: Config . Units . ConvertTo ( u , w . WaterMeterData . Q1_Qmin ) . ToString ( p ) ) ) ;
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Metrological_class , Strings . MClass , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . MetrologicalClass ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Temperature_class , "Temperature class" , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . TemperatureClass . ToDescription ( ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Pressure_loss_class , "Pressure loss class" , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . PressureLossClass . ToDescription ( ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Max_admissible_pressure , "Max. admissible pressure" , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . MaxAdmissiblePressure . ToDescription ( ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Flow_profile_sensitivity_class , "Flow profile sensitivity class" , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . FlowProfileSensitivityClass . ToDescription ( ) ) ) ;
2016-08-01 13:40:51 +00:00
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Approval_info , Strings . Approval , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . ApprovalInfo ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Certificate , "Certificate" , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . Certificate ) ) ;
2016-08-01 13:40:51 +00:00
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Pulses_per_liter , Strings . PulsesLiter , Quantity . PulsePerLtr , ( w , t , u , f , p ) = > string . IsNullOrEmpty ( p ) ? w . WaterMeterData . PulsesPerLtr . ToString ( )
2016-08-02 11:42:26 +00:00
: w . WaterMeterData . PulsesPerLtr . ToString ( p ) ) ) ;
2016-05-02 13:26:14 +00:00
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Text1 , "Text1" , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . Text1 ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Text2 , "Text2" , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . Text2 ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Text3 , "Text3" , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . Text3 ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Text4 , "Text4" , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . Text4 ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Text5 , "Text5" , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . Text5 ) ) ;
2016-05-02 13:26:14 +00:00
2016-04-29 05:40:34 +00:00
/// Water meters results
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Serial_Nr , Strings . sn , Quantity . String , ( w , t , u , f , p ) = > w . SerialNr ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Purchase_order , Strings . PO , Quantity . String , ( w , t , u , f , p ) = > w . PurchaseOrder ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Year_of_production , Strings . Year , Quantity . Number , ( w , t , u , f , p ) = > w . YearOfProduction . ToString ( ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . WM_Position , Strings . Pos , Quantity . Number , ( w , t , u , f , p ) = > w . WMPosition . ToString ( ) ) ) ;
2016-04-29 05:40:34 +00:00
/// Water meters results (single)
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . End_state , Strings . End_state , Quantity . String , ( w , t , u , f , p ) = > w . EndState ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Pulses , Strings . Pulses + "()" , Quantity . Number , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t ) = = null ) ? "" : w . GetMeterTestRslt ( t ) . PulsesMeter . ToString ( ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Pulses__liter , Strings . PulsesLiter + "()" , Quantity . PulsePerLtr , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t ) = = null ) ? "" : ( string . IsNullOrEmpty ( p ) ? w . GetMeterTestRslt ( t ) . PulsesPerLiter . ToString ( )
2016-08-02 21:06:53 +00:00
: w . GetMeterTestRslt ( t ) . PulsesPerLiter . ToString ( p ) ) ) ) ;
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Reference_pulses , Strings . RefPulses + "()" , Quantity . Number , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t ) = = null ) ? "" : w . GetMeterTestRslt ( t ) . PulsesMaster . ToString ( ) ) ) ;
2016-05-24 20:36:21 +00:00
/// Water meters results (combined)
//AllItems.Add(new ItemSpec("Q rise", "Q rise [m3/h]", null, (x, y, z) => (z.QRise() == 0) ? "-" : Utils.DoubleToStr(z.QRise(), 4)));
//AllItems.Add(new ItemSpec("Q fall", "Q fall [m3/h]", null, (x, y, z) => (z.QFall() == 0) ? "-" : Utils.DoubleToStr(z.QFall(), 4)));
//AllItems.Add(new ItemSpec("Error large WM", "Error-L [%]", null, (x, y, z) => x.Error.ToString("F2")));
//AllItems.Add(new ItemSpec("Error small WM", "Error-S [%]", null, (x, y, z) => y.Error.ToString("F2")));
//AllItems.Add(new ItemSpec("Serial Nr large WM", "s/n", null, (x, y, z) => x.SerialNr()));
//AllItems.Add(new ItemSpec("Serial Nr small WM", "s/n", null, (x, y, z) => y.SerialNr()));
//AllItems.Add(new ItemSpec("End state large WM", "End state", null, (x, y, z) => x.EndState()));
//AllItems.Add(new ItemSpec("End state small WM", "End state", null, (x, y, z) => y.EndState()));
2016-04-29 05:40:34 +00:00
/// Batch info
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Test_bench_ID , Strings . Bench , Quantity . String , ( w , t , u , f , p ) = > w . Batch . TestBenchId . ToString ( ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Program_version , Strings . Ver , Quantity . String , ( w , t , u , f , p ) = > w . Batch . ProgramVersion ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . User_name , Strings . User , Quantity . String , ( w , t , u , f , p ) = > w . Batch . UserName ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . User_nr , Strings . User_nr , Quantity . Number , ( w , t , u , f , p ) = > w . Batch . UserNumber . ToString ( ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Watermeters , Strings . WMs , Quantity . String , ( w , t , u , f , p ) = > w . Batch . WatermetersStr ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Protocol_title , Strings . Protocol , Quantity . String , ( w , t , u , f , p ) = > w . Batch . ProtocolTitle ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Batch_start_time , Strings . Start , Quantity . DateTime , ( w , t , u , f , p ) = > string . IsNullOrEmpty ( f ) ? w . Batch . StartTime . ToString ( ) : string . Format ( f , w . Batch . StartTime ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Batch_end_time , Strings . End , Quantity . DateTime , ( w , t , u , f , p ) = > string . IsNullOrEmpty ( f ) ? w . Batch . EndTime . ToString ( ) : string . Format ( f , w . Batch . EndTime ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Lite_per_pulse_Read , "1 / PlsPerLtr_Read" , Quantity . PulsePerLtr , ( w , t , u , f , p ) = > string . IsNullOrEmpty ( p ) ? ( ( w . WaterMeterData . PulsesPerLtr ! = 0 ) ? 1 / w . WaterMeterData . PulsesPerLtr : 0 ) . ToString ( )
2016-08-02 11:42:26 +00:00
: ( ( w . WaterMeterData . PulsesPerLtr ! = 0 ) ? 1 / w . WaterMeterData . PulsesPerLtr : 0 ) . ToString ( p ) ) ) ;
2016-06-17 13:59:32 +00:00
/// Extra water meter data
2016-10-14 12:27:38 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Result_code , Strings . Result_code , Quantity . Number , ( w , t , u , f , p ) = > string . IsNullOrEmpty ( f ) ? w . ResultCode . ToString ( ) : string . Format ( f , w . ResultCode ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Remark , Strings . Remark , Quantity . String , ( w , t , u , f , p ) = > w . Batch . Remark ) ) ;
2016-11-18 14:18:21 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Meter_type , Strings . Meter_type , Quantity . String , ( w , t , u , f , p ) = > w . WaterMeterData . Compound ? Strings . Compound : ( w . WaterMeterData . HeatMeter ? Strings . Heat_meter : Strings . Single ) ) ) ;
2016-10-14 14:54:19 +00:00
2016-12-06 14:59:33 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Volume_main , Strings . Volume_main + "()" , Quantity . Volume , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t , CompoundMeterId . CompoundMain ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t ) . VolumeMeter ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Volume_aux , Strings . Volume_aux + "()" , Quantity . Volume , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t , CompoundMeterId . CompoundAux ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t ) . VolumeMeter ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Start_volume , Strings . Start_volume + "()" , Quantity . Volume , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t ) . VolumeStart ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Start_volume_main , Strings . Start_volume_main + "()" , Quantity . Volume , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t , CompoundMeterId . CompoundMain ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t ) . VolumeStart ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Start_volume_aux , Strings . Start_volume_aux + "()" , Quantity . Volume , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t , CompoundMeterId . CompoundAux ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t ) . VolumeStart ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . End_volume , Strings . End_volume + "()" , Quantity . Volume , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t ) . VolumeEnd ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . End_volume_main , Strings . End_volume_main + "()" , Quantity . Volume , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t , CompoundMeterId . CompoundMain ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t ) . VolumeEnd ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . End_volume_aux , Strings . End_volume_aux + "()" , Quantity . Volume , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t , CompoundMeterId . CompoundAux ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t ) . VolumeEnd ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
2017-02-14 12:25:43 +00:00
#if HEAT_METERS
2016-10-14 14:54:19 +00:00
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Energy , Strings . Energy + "()" , Quantity . Energy , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t , Config . Entities . CompoundMeterId . HeatMeterEnergy ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t , Config . Entities . CompoundMeterId . HeatMeterEnergy ) . VolumeMeter ) . ToString ( string . IsNullOrEmpty ( p ) ? "F1" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . Reference_energy , Strings . Energy_ref + "()" , Quantity . Energy , ( w , t , u , f , p ) = > ( w . GetMeterTestRslt ( t , Config . Entities . CompoundMeterId . HeatMeterEnergy ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetMeterTestRslt ( t , Config . Entities . CompoundMeterId . HeatMeterEnergy ) . VolumeRef ) . ToString ( string . IsNullOrEmpty ( p ) ? "F1" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . TempHiMean , "T hi me" , Quantity . Temperature , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . Custom1 ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . TempHiStart , "T hi st" , Quantity . Temperature , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . Custom2 ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . TempHiEnd , "T hi en" , Quantity . Temperature , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . Custom3 ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . TempHiAve , "T hi av" , Quantity . Temperature , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , ( w . GetTestRslt ( t ) . Custom2 + w . GetTestRslt ( t ) . Custom3 ) / 2 ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . TempLoMean , "T lo me" , Quantity . Temperature , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . Custom6 ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . TempLoStart , "T lo st" , Quantity . Temperature , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . Custom7 ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . TempLoEnd , "T lo en" , Quantity . Temperature , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , w . GetTestRslt ( t ) . Custom8 ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
AllItems . Add ( new WMeterRsltItemSpec ( ItemID . TempLoAve , "T lo av" , Quantity . Temperature , ( w , t , u , f , p ) = > ( w . GetTestRslt ( t ) = = null ) ? "" : Config . Units . ConvertTo ( u , ( w . GetTestRslt ( t ) . Custom7 + w . GetTestRslt ( t ) . Custom8 ) / 2 ) . ToString ( string . IsNullOrEmpty ( p ) ? "F3" : p ) ) ) ;
#endif
2016-04-29 05:40:34 +00:00
}
/// <summary>
/// Converts a list of 'Output item specifications' to a string array
/// </summary>
/// <param name="items"></param>
/// <returns></returns>
public static string [ ] ToStrArray ( IList < WMeterRsltItemSpec > items )
{
int count = ( items ! = null ) ? items . Count : 0 ;
string [ ] result = new string [ count ] ;
for ( int i = 0 ; i < count ; i + + )
{
result [ i ] = string . Format ( "{0}~{1}~{2}~{3}~{4}~{5}~{6}~{7}" ,
items [ i ] . Uid ,
2016-05-26 12:02:12 +00:00
items [ i ] . Caption ,
2016-04-29 05:40:34 +00:00
items [ i ] . TestID ,
items [ i ] . Units ,
items [ i ] . Format ,
items [ i ] . Precision ,
items [ i ] . Width ,
2017-02-15 10:48:47 +00:00
items [ i ] . Alignment ) ;
2016-04-29 05:40:34 +00:00
}
return result ;
}
/// <summary>
/// Converts a string array to a list of 'Output item specifications'
/// </summary>
/// <param name="strArray"></param>
/// <returns></returns>
public static IList < WMeterRsltItemSpec > FromStrArray ( string [ ] strArray )
{
IList < WMeterRsltItemSpec > result = new List < WMeterRsltItemSpec > ( ) ;
2017-02-15 10:48:47 +00:00
2016-04-29 05:40:34 +00:00
if ( strArray ! = null )
{
for ( int i = 0 ; i < strArray . Length ; i + + )
{
2017-02-15 10:48:47 +00:00
try
{
//if (strArray[i].Contains("~"))
//{
string [ ] field = strArray [ i ] . Split ( new char [ ] { '~' } ) ;
WMeterRsltItemSpec item = GetItem ( int . Parse ( field [ 0 ] ) ) ;
item . Caption = field [ 1 ] ;
item . TestID = field [ 2 ] ;
item . Units = 0 ;
for ( Config . Unit u = 0 ; u < Config . Unit . Count ; u + + )
{
if ( u . ToString ( ) . Equals ( field [ 3 ] ) ) { item . Units = u ; break ; }
}
item . Format = field [ 4 ] ;
item . Precision = field [ 5 ] ;
item . Width = int . Parse ( field [ 6 ] ) ;
item . Alignment = 0 ;
for ( Config . Entities . Alignment a = 0 ; a < Config . Entities . Alignment . Count ; a + + )
{
if ( a . ToString ( ) . Equals ( field [ 7 ] ) ) { item . Alignment = a ; break ; }
}
result . Add ( item ) ;
//}
//else
//{
//}
}
catch
{
WMeterRsltItemSpec item = GetItem ( 0 ) ;
item . Format = string . Format ( "Parse error: {0}" , strArray [ i ] ) ;
result . Add ( item ) ;
}
2016-04-29 05:40:34 +00:00
}
}
return result ;
}
2016-08-01 13:40:51 +00:00
public static WMeterRsltItemSpec GetItem ( int uid )
2016-04-29 05:40:34 +00:00
{
foreach ( var item in AllItems )
{
if ( item . Uid = = uid ) return item . Clone ( ) ;
}
return null ;
}
2016-08-01 13:40:51 +00:00
public static WMeterRsltItemSpec GetItem ( ItemID itemId )
{
return GetItem ( ( int ) itemId ) ;
}
2016-04-29 05:40:34 +00:00
}
}