223 lines
17 KiB
C#
223 lines
17 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Results.Entities;
|
|
using Results.Resources;
|
|
|
|
namespace Results
|
|
{
|
|
public class ItemSpec
|
|
{
|
|
///
|
|
/// Public fields
|
|
///
|
|
public readonly string Name; /// Name-s of all items must be unique
|
|
public readonly string ClmnHeaderText; /// Text printed in the column header
|
|
|
|
|
|
///
|
|
/// Function to pick a MeterTestResult field and convert it into a string
|
|
///
|
|
public delegate string PrintDlgt(MeterTestRslt meterTestRslt);
|
|
|
|
///
|
|
/// Function to pick a MeterTestResult field and convert it into a string
|
|
///
|
|
public delegate string PrintCompoundDlgt(MeterTestRslt mainMtrTestResult,
|
|
MeterTestRslt auxMtrTestResult,
|
|
MeterTestRslt compoundMtrTestResult);
|
|
|
|
///
|
|
/// Function to pick a MeterTestResult field and convert it into a string
|
|
///
|
|
public delegate string PrintHeatMeterDlgt(MeterTestRslt volumeTestResult,
|
|
MeterTestRslt energyTestResult);
|
|
|
|
private readonly PrintDlgt printDlgt;
|
|
private readonly PrintCompoundDlgt printCompoundDlgt;
|
|
private readonly PrintHeatMeterDlgt printHeatMeterDlgt;
|
|
|
|
public bool CanPrintSingle { get { return (printDlgt != null); } }
|
|
public bool CanPrintCompoundMeter { get { return (printCompoundDlgt != null); } }
|
|
public bool CanPrintHeatMeter { get { return (printHeatMeterDlgt != null); } }
|
|
|
|
/// <summary> Safe wrapper which replaces null-s by empty strings </summary>
|
|
public string Print(MeterTestRslt meterTestRslt)
|
|
{
|
|
string str = null;
|
|
if (printDlgt != null) str = printDlgt(meterTestRslt);
|
|
return (str == null) ? string.Empty : str;
|
|
}
|
|
|
|
/// <summary> Safe wrapper which replaces null-s by empty strings </summary>
|
|
public string PrintCombined(MeterTestRslt mainMtrTestResult,
|
|
MeterTestRslt auxMtrTestResult,
|
|
MeterTestRslt compoundMtrTestResult)
|
|
{
|
|
string str = null;
|
|
if (printCompoundDlgt != null) str = printCompoundDlgt(mainMtrTestResult, auxMtrTestResult, compoundMtrTestResult);
|
|
return (str == null) ? string.Empty : str;
|
|
}
|
|
|
|
/// <summary> Safe wrapper which replaces null-s by empty strings </summary>
|
|
public string PrintHeatMeter(MeterTestRslt volumeTestResult,
|
|
MeterTestRslt energyTestResult)
|
|
{
|
|
string str = null;
|
|
if (printHeatMeterDlgt != null) str = printHeatMeterDlgt(volumeTestResult, energyTestResult);
|
|
return (str == null) ? string.Empty : str;
|
|
}
|
|
|
|
|
|
///
|
|
/// Public constructor
|
|
///
|
|
public ItemSpec(string name, string clmnHeaderText, PrintDlgt printDlgt, PrintCompoundDlgt printCombinedDlgt, PrintHeatMeterDlgt printHeatMeterDlgt)
|
|
{
|
|
Name = name;
|
|
ClmnHeaderText = clmnHeaderText;
|
|
this.printDlgt = printDlgt;
|
|
this.printCompoundDlgt = printCombinedDlgt;
|
|
this.printHeatMeterDlgt = printHeatMeterDlgt;
|
|
}
|
|
|
|
|
|
/// Static list of all available items
|
|
public static readonly IList<ItemSpec> AllItems;
|
|
|
|
/// Static constructor that initializes the list of all items
|
|
static ItemSpec()
|
|
{
|
|
AllItems = new List<ItemSpec>();
|
|
|
|
/// Common
|
|
|
|
//AllItems.Add(new ResultItemSpec("Bench ID", "Bench ID", x => x.BenchID, (x, y, z) => x.BenchID));
|
|
AllItems.Add(new ItemSpec("Test name", Strings.Test, x => x.Name(), (x, y, z) => z.Name(), (x, z) => z.Name()));
|
|
AllItems.Add(new ItemSpec("Procedure name", Strings.Procedure, x => x.ProcedureName(), (x, y, z) => z.ProcedureName(), (x, z) => z.ProcedureName()));
|
|
AllItems.Add(new ItemSpec("Batch number", Strings.Batch_nr, x => x.BatchNr().ToString(), (x, y, z) => z.BatchNr().ToString(), (x, z) => z.BatchNr().ToString()));
|
|
AllItems.Add(new ItemSpec("Test method", Strings.Test_method, x => x.Method(), (x, y, z) => z.Method(), (x, z) => z.Method()));
|
|
AllItems.Add(new ItemSpec("Density", Strings.Density, x => x.DensityOut().ToString("F1"), (x, y, z) => z.DensityOut().ToString("F1"), (x, z) => z.DensityOut().ToString("F1"))); /// [kg/m3]
|
|
|
|
/// Target values
|
|
AllItems.Add(new ItemSpec("Q from", Strings.Q_from + " [m3/h]", x => x.Qfrom().ToString("F3"), (x, y, z) => z.Qfrom().ToString("F3"), (x, z) => z.Qfrom().ToString("F3")));
|
|
AllItems.Add(new ItemSpec("Q to", Strings.Q_to + " [m3/h]", x => x.Qto().ToString("F3"), (x, y, z) => z.Qto().ToString("F3"), (x, z) => z.Qto().ToString("F3")));
|
|
AllItems.Add(new ItemSpec("Test volume", Strings.Test_vol + " [l]", x => x.TargetVolume().ToString("F1"), (x, y, z) => z.TargetVolume().ToString("F1"), (x, z) => z.TargetVolume().ToString("F1")));
|
|
AllItems.Add(new ItemSpec("Error limit Lo", Strings.ErrLimLo + " [%]", x => x.ErrLimLo().ToString("F1"), (x, y, z) => z.ErrLimLo().ToString("F1"), (x, z) => z.ErrLimLo().ToString("F1")));
|
|
AllItems.Add(new ItemSpec("Error limit Hi", Strings.ErrLimHi + " [%]", x => x.ErrLimHi().ToString("F1"), (x, y, z) => z.ErrLimHi().ToString("F1"), (x, z) => z.ErrLimHi().ToString("F1")));
|
|
AllItems.Add(new ItemSpec("Uncertainty", Strings.Uncertainty + " [%]", x => x.Uncertainty().ToString("F2"), (x, y, z) => z.Uncertainty().ToString("F2"), (x, z) => z.Uncertainty().ToString("F2")));
|
|
|
|
/// Test results
|
|
AllItems.Add(new ItemSpec("Test start time", Strings.T_start, x => x.StartTime().ToShortTimeString(), (x, y, z) => z.StartTime().ToShortTimeString(), (x, z) => z.StartTime().ToShortTimeString()));
|
|
AllItems.Add(new ItemSpec("Test end time", Strings.T_end, x => x.EndTime().ToShortTimeString(), (x, y, z) => z.EndTime().ToShortTimeString(), (x, z) => z.EndTime().ToShortTimeString()));
|
|
AllItems.Add(new ItemSpec("Test time", Strings.T_s, x => x.TestTime.ToString("F2"), (x, y, z) => z.TestTime.ToString("F2"), (x, z) => z.TestTime.ToString("F2")));
|
|
AllItems.Add(new ItemSpec("Flow", Strings.Flow + " [m3/h]", x => Utils.DoubleToStr(x.FlowVolume(), 4), (x, y, z) => Utils.DoubleToStr(z.FlowVolume(), 4), (x, z) => Utils.DoubleToStr(x.FlowVolume(), 4)));
|
|
AllItems.Add(new ItemSpec("T in", Strings.T_in + " [°C]", x => x.TestRslt.TempInAvrg.ToString("F2"), (x, y, z) => z.TestRslt.TempInAvrg.ToString("F2"), (x, z) => z.TestRslt.TempInAvrg.ToString("F2")));
|
|
AllItems.Add(new ItemSpec("T out", Strings.T_out + " [°C]", x => x.TestRslt.TempOutAvrg.ToString("F2"), (x, y, z) => z.TestRslt.TempOutAvrg.ToString("F2"), (x, z) => z.TestRslt.TempOutAvrg.ToString("F2")));
|
|
AllItems.Add(new ItemSpec("T div", Strings.T_div + " [°C]", x => x.TestRslt.TempDivAvrg.ToString("F2"), (x, y, z) => z.TestRslt.TempDivAvrg.ToString("F2"), (x, z) => z.TestRslt.TempDivAvrg.ToString("F2")));
|
|
AllItems.Add(new ItemSpec("P up", Strings.P_up + " [kPa]", x => (100 * x.TestRslt.PressUpAvrg).ToString("F3"), (x, y, z) => z.TestRslt.PressUpAvrg.ToString("F3"), (x, z) => z.TestRslt.PressUpAvrg.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("P up start", Strings.P_up_start + " [kPa]", x => (100 * x.TestRslt.PressUpStart).ToString("F3"), (x, y, z) => z.TestRslt.PressUpStart.ToString("F3"), (x, z) => z.TestRslt.PressUpStart.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("P up end", Strings.P_up_end + " [kPa]", x => (100 * x.TestRslt.PressUpEnd).ToString("F3"), (x, y, z) => z.TestRslt.PressUpEnd.ToString("F3"), (x, z) => z.TestRslt.PressUpEnd.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("P down", Strings.P_dn + " [kPa]", x => (100 * x.TestRslt.PressDownAvrg).ToString("F3"), (x, y, z) => z.TestRslt.PressDownAvrg.ToString("F3"), (x, z) => z.TestRslt.PressDownAvrg.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("P down start", Strings.P_dn_start + " [kPa]", x => (100 * x.TestRslt.PressDownStart).ToString("F3"), (x, y, z) => z.TestRslt.PressDownStart.ToString("F3"), (x, z) => z.TestRslt.PressDownStart.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("P down end", Strings.P_dn_end + " [kPa]", x => (100 * x.TestRslt.PressDownEnd).ToString("F3"), (x, y, z) => z.TestRslt.PressDownEnd.ToString("F3"), (x, z) => z.TestRslt.PressDownEnd.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("Reference error", Strings.ErrRef + " [%]", x => x.TestRslt.ErrorMaster.ToString("F3"), (x, y, z) => z.TestRslt.ErrorMaster.ToString("F3"), (x, z) => z.TestRslt.ErrorMaster.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("Ambient temperature", Strings.T_amb + " [°C]", x => x.TestRslt.AmbientTempAve.ToString("F1"), (x, y, z) => z.TestRslt.AmbientTempAve.ToString("F1"), (x, z) => z.TestRslt.AmbientTempAve.ToString("F1")));
|
|
AllItems.Add(new ItemSpec("Ambient pressure", Strings.P_amb + " [mbar]", x => (1000 * x.TestRslt.AmbientPressAve).ToString("F0"), (x, y, z) => (1000 * z.TestRslt.AmbientPressAve).ToString("F0"), (x, z) => (1000 * z.TestRslt.AmbientPressAve).ToString("F0")));
|
|
AllItems.Add(new ItemSpec("Ambient humidity", Strings.H_amb + " [%]", x => x.TestRslt.AmbientHumiAve.ToString("F1"), (x, y, z) => z.TestRslt.AmbientHumiAve.ToString("F1"), (x, z) => z.TestRslt.AmbientHumiAve.ToString("F1")));
|
|
|
|
/// Single and combined meter results
|
|
AllItems.Add(new ItemSpec("Volume", Strings.Volume + " [l]", x => x.VolumeMeter.ToString("F3"), (x, y, z) => z.VolumeMeter.ToString("F3"), (x, z) => x.VolumeMeter.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("Reference volume", Strings.VolRef + " [l]", x => x.VolumeRef.ToString("F3"), (x, y, z) => z.VolumeRef.ToString("F3"), (x, z) => x.VolumeRef.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("Error", Strings.Error + " [%]", x => x.Error.ToString("F2"), (x, y, z) => z.Error.ToString("F2"), null));
|
|
AllItems.Add(new ItemSpec("Passed", Strings.Result, x => x.PassedColorStr(), (x, y, z) => z.PassedColorStr(), null));
|
|
AllItems.Add(new ItemSpec("Volume Error", "Volume Error" + " [%]", null, null, (x, z) => x.Error.ToString("F2")));
|
|
AllItems.Add(new ItemSpec("Volume Passed", "Volume Passed", null, null, (x, z) => x.PassedColorStr()));
|
|
AllItems.Add(new ItemSpec("Energy Error", "Energy Error" + " [%]", null, null, (x, z) => z.Error.ToString("F2")));
|
|
AllItems.Add(new ItemSpec("Energy Passed", "Energy Passed", null, null, (x, z) => z.PassedColorStr()));
|
|
|
|
/// Water meter info
|
|
AllItems.Add(new ItemSpec("Watermeter type", Strings.WM_Type, x => x.WaterMeterData().ProductName, (x, y, z) => z.WaterMeterData().ProductName, (x, z) => z.WaterMeterData().ProductName));
|
|
AllItems.Add(new ItemSpec("Producer", Strings.Producer, x => x.WaterMeterData().Producer, (x, y, z) => z.WaterMeterData().Producer, (x, z) => z.WaterMeterData().Producer));
|
|
AllItems.Add(new ItemSpec("Metrological class", Strings.MClass, x => x.WaterMeterData().MetrologicalClass, (x, y, z) => z.WaterMeterData().MetrologicalClass, (x, z) => z.WaterMeterData().MetrologicalClass));
|
|
AllItems.Add(new ItemSpec("Approval info", Strings.Approval, x => x.WaterMeterData().ApprovalInfo, (x, y, z) => z.WaterMeterData().ApprovalInfo, (x, z) => z.WaterMeterData().ApprovalInfo));
|
|
AllItems.Add(new ItemSpec("Q4", "Q4 [m3/h]", x => x.WaterMeterData().Q4_Qmax.ToString(), (x, y, z) => z.WaterMeterData().Q4_Qmax.ToString(), null));
|
|
AllItems.Add(new ItemSpec("Q3", "Q3 [m3/h]", x => x.WaterMeterData().Q3_Qn.ToString(), (x, y, z) => z.WaterMeterData().Q3_Qn.ToString(), null));
|
|
AllItems.Add(new ItemSpec("Q2", "Q2 [m3/h]", x => x.WaterMeterData().Q2_Qt.ToString(), (x, y, z) => z.WaterMeterData().Q2_Qt.ToString(), null));
|
|
AllItems.Add(new ItemSpec("Q1", "Q1 [m3/h]", x => x.WaterMeterData().Q1_Qmin.ToString(), (x, y, z) => z.WaterMeterData().Q1_Qmin.ToString(), null));
|
|
AllItems.Add(new ItemSpec("Qmax", "Qmax [m3/h]", x => x.WaterMeterData().Q4_Qmax.ToString(), (x, y, z) => z.WaterMeterData().Q4_Qmax.ToString(), null));
|
|
AllItems.Add(new ItemSpec("Qn", "Qn [m3/h]", x => x.WaterMeterData().Q3_Qn.ToString(), (x, y, z) => z.WaterMeterData().Q3_Qn.ToString(), null));
|
|
AllItems.Add(new ItemSpec("Qt", "Qt [m3/h]", x => x.WaterMeterData().Q2_Qt.ToString(), (x, y, z) => z.WaterMeterData().Q2_Qt.ToString(), null));
|
|
AllItems.Add(new ItemSpec("Qmin", "Qmin [m3/h]", x => x.WaterMeterData().Q1_Qmin.ToString(), (x, y, z) => z.WaterMeterData().Q1_Qmin.ToString(), null));
|
|
|
|
/// Water meters results
|
|
AllItems.Add(new ItemSpec("Serial Nr", Strings.sn, x => x.WaterMeter.SerialNr, (x, y, z) => z.WaterMeter.SerialNr, (x, z) => z.WaterMeter.SerialNr));
|
|
AllItems.Add(new ItemSpec("Purchase order", Strings.PO, x => x.WaterMeter.PurchaseOrder, (x, y, z) => z.WaterMeter.PurchaseOrder, (x, z) => z.WaterMeter.PurchaseOrder));
|
|
AllItems.Add(new ItemSpec("Year of production", Strings.Year, x => x.WaterMeter.YearOfProduction.ToString(), (x, y, z) => z.WaterMeter.YearOfProduction.ToString(), (x, z) => z.WaterMeter.YearOfProduction.ToString()));
|
|
AllItems.Add(new ItemSpec("WM Position", Strings.Pos, x => x.WaterMeter.WMPosition.ToString(), (x, y, z) => z.WaterMeter.WMPosition.ToString(), (x, z) => z.WaterMeter.WMPosition.ToString()));
|
|
|
|
/// Water meters results (single)
|
|
AllItems.Add(new ItemSpec("End state", Strings.End_state, x => x.EndState(), null, null));
|
|
AllItems.Add(new ItemSpec("Pulses", Strings.Pulses, x => x.PulsesMeter.ToString(), null, null));
|
|
AllItems.Add(new ItemSpec("Pulses/liter", Strings.PulsesLiter, x => x.PulsesPerLiter.ToString(), null, null));
|
|
AllItems.Add(new ItemSpec("Reference pulses", Strings.RefPulses, x => x.PulsesMaster.ToString(), null, null));
|
|
|
|
/// Water meters results (combined)
|
|
AllItems.Add(new ItemSpec("Q rise", Strings.Q_rise + " [m3/h]", null, (x, y, z) => (z.QRise() == 0) ? "-" : Utils.DoubleToStr(z.QRise(), 4), null));
|
|
AllItems.Add(new ItemSpec("Q fall", Strings.Q_fall + " [m3/h]", null, (x, y, z) => (z.QFall() == 0) ? "-" : Utils.DoubleToStr(z.QFall(), 4), null));
|
|
AllItems.Add(new ItemSpec("Error large WM", Strings.Err_main + " [%]", null, (x, y, z) => x.Error.ToString("F2"), null));
|
|
AllItems.Add(new ItemSpec("Error small WM", Strings.Err_aux + " [%]", null, (x, y, z) => y.Error.ToString("F2"), null));
|
|
AllItems.Add(new ItemSpec("Serial Nr large WM", Strings.sn_main, null, (x, y, z) => x.SerialNr(), null));
|
|
AllItems.Add(new ItemSpec("Serial Nr small WM", Strings.sn_aux, null, (x, y, z) => y.SerialNr(), null));
|
|
AllItems.Add(new ItemSpec("End state large WM", Strings.EndState_main, null, (x, y, z) => x.EndState(), null));
|
|
AllItems.Add(new ItemSpec("End state small WM", Strings.EndState_aux, null, (x, y, z) => y.EndState(), null));
|
|
|
|
/// Batch info
|
|
AllItems.Add(new ItemSpec("Batch number", Strings.Batch_nr, x => x.Batch().BatchNr.ToString(), (x, y, z) => x.Batch().BatchNr.ToString(), (x, z) => x.Batch().BatchNr.ToString()));
|
|
AllItems.Add(new ItemSpec("Test bench ID", Strings.Bench, x => x.Batch().TestBenchId.ToString(), (x, y, z) => x.Batch().TestBenchId.ToString(), (x, z) => x.Batch().TestBenchId.ToString()));
|
|
AllItems.Add(new ItemSpec("Program version", Strings.Ver, x => x.Batch().ProgramVersion, (x, y, z) => x.Batch().ProgramVersion, (x, z) => x.Batch().ProgramVersion));
|
|
AllItems.Add(new ItemSpec("User name", Strings.User, x => x.Batch().UserName, (x, y, z) => x.Batch().UserName, (x, z) => x.Batch().UserName));
|
|
AllItems.Add(new ItemSpec("User nr.", Strings.User_nr, x => x.Batch().UserNumber.ToString(), (x, y, z) => x.Batch().UserNumber.ToString(), (x, z) => x.Batch().UserNumber.ToString()));
|
|
AllItems.Add(new ItemSpec("Procedure name", Strings.Procedure, x => x.Batch().ProcedureName, (x, y, z) => x.Batch().ProcedureName, (x, z) => x.Batch().ProcedureName));
|
|
AllItems.Add(new ItemSpec("Watermeters", Strings.WMs, x => x.Batch().WatermetersStr, (x, y, z) => x.Batch().WatermetersStr, (x, z) => x.Batch().WatermetersStr));
|
|
AllItems.Add(new ItemSpec("Protocol title", Strings.Protocol, x => x.Batch().ProtocolTitle, (x, y, z) => x.Batch().ProtocolTitle, (x, z) => x.Batch().ProtocolTitle));
|
|
AllItems.Add(new ItemSpec("Batch start time", Strings.Start, x => x.Batch().StartTime.ToShortTimeString(), (x, y, z) => x.Batch().StartTime.ToShortTimeString(), (x, z) => x.Batch().StartTime.ToShortTimeString()));
|
|
AllItems.Add(new ItemSpec("Batch end time", Strings.End, x => x.Batch().EndTime.ToShortTimeString(), (x, y, z) => x.Batch().EndTime.ToShortTimeString(), (x, z) => x.Batch().EndTime.ToShortTimeString()));
|
|
|
|
/// Heat meters results
|
|
AllItems.Add(new ItemSpec("Energy", Strings.Energy, null, null, (x,z) => z.VolumeMeter.ToString()));
|
|
AllItems.Add(new ItemSpec("Reference energy", Strings.Energy_ref, null, null, (x,z) => z.VolumeRef.ToString()));
|
|
}
|
|
|
|
public static ItemSpec GetItem(string name)
|
|
{
|
|
foreach (var item in AllItems) if (item.Name.Equals(name)) return item;
|
|
return null;
|
|
}
|
|
|
|
public static string[] ToStrArray(IList<ItemSpec> items)
|
|
{
|
|
int count = (items != null) ? items.Count : 0;
|
|
string[] result = new string[count];
|
|
for (int i = 0; i < count; i++) result[i] = items[i].Name;
|
|
return result;
|
|
}
|
|
|
|
public static IList<ItemSpec> FromStrArray(string[] strArray)
|
|
{
|
|
IList<ItemSpec> result = new List<ItemSpec>();
|
|
if (strArray != null)
|
|
{
|
|
for (int i = 0; i < strArray.Length; i++)
|
|
{
|
|
ItemSpec item = GetItem(strArray[i]);
|
|
if (item != null) result.Add(item);
|
|
}
|
|
}
|
|
return result;
|
|
}
|
|
}
|
|
}
|