211 lines
12 KiB
C#
211 lines
12 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Results.Entities;
|
|
|
|
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);
|
|
|
|
private readonly PrintDlgt printDlgt;
|
|
|
|
public bool CanPrintSingle { get { return (printDlgt != null); } }
|
|
|
|
/// <summary> Safe wrapper which replaces null-s by empty strings </summary>
|
|
public string Print(MeterTestRslt meterTestRslt)
|
|
{
|
|
string str = printDlgt(meterTestRslt);
|
|
return (str == null) ? string.Empty : str;
|
|
}
|
|
|
|
|
|
///
|
|
/// Function to pick a MeterTestResult field and convert it into a string
|
|
///
|
|
public delegate string PrintCombinedDlgt(MeterTestRslt mainMtrTestResult,
|
|
MeterTestRslt auxMtrTestResult,
|
|
MeterTestRslt compoundMtrTestResult);
|
|
|
|
private readonly PrintCombinedDlgt printCombinedDlgt;
|
|
|
|
public bool CanPrintCombined { get { return (printCombinedDlgt != null); } }
|
|
|
|
/// <summary> Safe wrapper which replaces null-s by empty strings </summary>
|
|
public string PrintCombined(MeterTestRslt mainMtrTestResult,
|
|
MeterTestRslt auxMtrTestResult,
|
|
MeterTestRslt compoundMtrTestResult)
|
|
{
|
|
string str = printCombinedDlgt(mainMtrTestResult, auxMtrTestResult, compoundMtrTestResult);
|
|
return (str == null) ? string.Empty : str;
|
|
}
|
|
|
|
|
|
|
|
///
|
|
/// Public constructor
|
|
///
|
|
public ItemSpec(string name, string clmnHeaderText, PrintDlgt printDlgt, PrintCombinedDlgt printCombinedDlgt)
|
|
{
|
|
Name = name;
|
|
ClmnHeaderText = clmnHeaderText;
|
|
this.printDlgt = printDlgt;
|
|
this.printCombinedDlgt = printCombinedDlgt;
|
|
}
|
|
|
|
|
|
/// 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", "Test", x => x.Name(), (x, y, z) => z.Name()));
|
|
AllItems.Add(new ItemSpec("Procedure name", "Procedure", x => x.ProcedureName(), (x, y, z) => z.ProcedureName()));
|
|
AllItems.Add(new ItemSpec("Batch number", "Batch nr.", x => x.BatchNr().ToString(), (x, y, z) => z.BatchNr().ToString()));
|
|
AllItems.Add(new ItemSpec("Test method", "Test method", x => x.Method(), (x, y, z) => z.Method()));
|
|
AllItems.Add(new ItemSpec("Density", "Density", x => x.DensityOut().ToString("F1"), (x, y, z) => z.DensityOut().ToString("F1"))); /// [kg/m3]
|
|
|
|
/// Target values
|
|
AllItems.Add(new ItemSpec("Q from", "Q from [m3/h]", x => x.Qfrom().ToString("F3"), (x, y, z) => z.Qfrom().ToString("F3")));
|
|
AllItems.Add(new ItemSpec("Q to", "Q to [m3/h]", x => x.Qto().ToString("F3"), (x, y, z) => z.Qto().ToString("F3")));
|
|
AllItems.Add(new ItemSpec("Test volume", "Test vol. [l]", x => x.TargetVolume().ToString("F1"),(x, y, z) => z.TargetVolume().ToString("F1")));
|
|
AllItems.Add(new ItemSpec("Error limit Lo", "Err.Lim.Lo [%]", x => x.ErrLimLo().ToString("F1"), (x, y, z) => z.ErrLimLo().ToString("F1")));
|
|
AllItems.Add(new ItemSpec("Error limit Hi", "Err.Lim.Hi [%]", x => x.ErrLimHi().ToString("F1"), (x, y, z) => z.ErrLimHi().ToString("F1")));
|
|
AllItems.Add(new ItemSpec("Uncertainty", "Uncertainty [%]",x => x.Uncertainty().ToString("F2"), (x, y, z) => z.Uncertainty().ToString("F2")));
|
|
|
|
/// Test results
|
|
AllItems.Add(new ItemSpec("Start time", "T start", x => x.StartTime().ToShortTimeString(), (x, y, z) => z.StartTime().ToShortTimeString()));
|
|
AllItems.Add(new ItemSpec("End time", "T end", x => x.EndTime().ToShortTimeString(), (x, y, z) => z.EndTime().ToShortTimeString()));
|
|
AllItems.Add(new ItemSpec("Test time", "T [s]", x => x.TestTime.ToString("F2"), (x, y, z) => z.TestTime.ToString("F2")));
|
|
AllItems.Add(new ItemSpec("Flow", "Flow [m3/h]", x => DoubleToStr(x.FlowVolume(), 4), (x, y, z) => DoubleToStr(z.FlowVolume(), 4)));
|
|
AllItems.Add(new ItemSpec("T in", "T in", x => x.TestRslt.TempInAvrg.ToString("F2"), (x, y, z) => z.TestRslt.TempInAvrg.ToString("F2")));
|
|
AllItems.Add(new ItemSpec("T out", "T out", x => x.TestRslt.TempOutAvrg.ToString("F2"), (x, y, z) => z.TestRslt.TempOutAvrg.ToString("F2")));
|
|
AllItems.Add(new ItemSpec("T div", "T div", x => x.TestRslt.TempDivAvrg.ToString("F2"), (x, y, z) => z.TestRslt.TempDivAvrg.ToString("F2")));
|
|
AllItems.Add(new ItemSpec("P up", "P up", x => x.TestRslt.PressUpAvrg.ToString("F3"), (x, y, z) => z.TestRslt.PressUpAvrg.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("P up start", "P up start", x => x.TestRslt.PressUpStart.ToString("F3"), (x, y, z) => z.TestRslt.PressUpStart.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("P up end", "P up end", x => x.TestRslt.PressUpEnd.ToString("F3"), (x, y, z) => z.TestRslt.PressUpEnd.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("P down", "P down", x => x.TestRslt.PressDownAvrg.ToString("F3"), (x, y, z) => z.TestRslt.PressDownAvrg.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("P down start", "P down start", x => x.TestRslt.PressDownStart.ToString("F3"), (x, y, z) => z.TestRslt.PressDownStart.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("P down end", "P down end", x => x.TestRslt.PressDownEnd.ToString("F3"), (x, y, z) => z.TestRslt.PressDownEnd.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("Reference error","Err.ref. [%]", x => x.TestRslt.ErrorMaster.ToString("F3"), (x, y, z) => z.TestRslt.ErrorMaster.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("Ambient temperature","T amb", x => x.TestRslt.AmbientTempAve.ToString("F1"), (x, y, z) => z.TestRslt.AmbientTempAve.ToString("F1")));
|
|
AllItems.Add(new ItemSpec("Ambient pressure", "P amb", x => x.TestRslt.AmbientPressAve.ToString("F0"), (x, y, z) => z.TestRslt.AmbientPressAve.ToString("F0")));
|
|
AllItems.Add(new ItemSpec("Ambient humidity", "H amb [%]",x => x.TestRslt.AmbientHumiAve.ToString("F1"), (x, y, z) => z.TestRslt.AmbientHumiAve.ToString("F1")));
|
|
|
|
/// Single and combined meter results
|
|
AllItems.Add(new ItemSpec("Volume", "Volume [l]", x => x.VolumeMeter.ToString("F3"), (x, y, z) => z.VolumeMeter.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("Reference volume", "Vol.ref. [l]", x => x.VolumeRef.ToString("F3"), (x, y, z) => z.VolumeRef.ToString("F3")));
|
|
AllItems.Add(new ItemSpec("Error", "Error [%]", x => x.Error.ToString("F2"), (x, y, z) => z.Error.ToString("F2")));
|
|
AllItems.Add(new ItemSpec("Passed", "Result", x => x.PassedColorStr(), (x, y, z) => z.PassedColorStr()));
|
|
/// Single water meters only results
|
|
AllItems.Add(new ItemSpec("Serial Nr", "s/n", x => x.SerialNr(), null));
|
|
AllItems.Add(new ItemSpec("End state", "End state", x => x.EndState(), null));
|
|
AllItems.Add(new ItemSpec("Pulses", "Pulses", x => x.PulsesMeter.ToString(), null));
|
|
AllItems.Add(new ItemSpec("Pulses/liter", "Pulses/liter", x => x.PulsesPerLiter.ToString(), null));
|
|
AllItems.Add(new ItemSpec("Reference pulses", "Ref.pulses", x => x.PulsesMaster.ToString(), null));
|
|
|
|
/// Combined water meters only results
|
|
AllItems.Add(new ItemSpec("Q rise", "Q rise [m3/h]", null, (x, y, z) => (z.QRise() == 0) ? "-" : DoubleToStr(z.QRise(), 4)));
|
|
AllItems.Add(new ItemSpec("Q fall", "Q fall [m3/h]", null, (x, y, z) => (z.QFall() == 0) ? "-" : 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()));
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Converts float number to a string with the specified number of valid digits
|
|
/// </summary>
|
|
/// <param name="value">Float value to be converted to a string</param>
|
|
/// <param name="validDigits">Number of valid digits: 4, 3, or 2 (otherwise a full precision number is printed)</param>
|
|
/// <returns>String representation of the float number</returns>
|
|
public static string DoubleToStr(double value, int validDigits)
|
|
{
|
|
if (-float.Epsilon <= value && value <= float.Epsilon)
|
|
{
|
|
return "0";
|
|
}
|
|
else if (validDigits == 4)
|
|
{
|
|
if (value >= 999.5 || value < -999.5) return value.ToString("F0");
|
|
else if (value >= 99.95 || value < -99.95) return value.ToString("F1");
|
|
else if (value >= 9.995 || value < -9.995) return value.ToString("F2");
|
|
else if (value >= 0.9995 || value < -0.9995) return value.ToString("F3");
|
|
else if (value >= 0.09995 || value < -0.09995) return value.ToString("F4");
|
|
else if (value >= 0.009995 || value < -0.009995) return value.ToString("F5");
|
|
else return value.ToString("F6");
|
|
}
|
|
else if (validDigits == 3)
|
|
{
|
|
if (value >= 99.5 || value < -99.5) return value.ToString("F0");
|
|
else if (value >= 9.95 || value < -9.95) return value.ToString("F1");
|
|
else if (value >= 0.995 || value < -0.995) return value.ToString("F2");
|
|
else if (value >= 0.0995 || value < -0.0995) return value.ToString("F3");
|
|
else if (value >= 0.00995 || value < -0.00995) return value.ToString("F4");
|
|
else if (value >= 0.000995 || value < -0.000995) return value.ToString("F5");
|
|
else return value.ToString("F6");
|
|
}
|
|
else if (validDigits == 2)
|
|
{
|
|
if (value >= 9.5 || value < -9.5) return value.ToString("F0");
|
|
else if (value >= 0.95 || value < -0.95) return value.ToString("F1");
|
|
else if (value >= 0.095 || value < -0.095) return value.ToString("F2");
|
|
else if (value >= 0.0095 || value < -0.0095) return value.ToString("F3");
|
|
else if (value >= 0.00095 || value < -0.00095) return value.ToString("F4");
|
|
else return value.ToString("F5");
|
|
}
|
|
else return value.ToString();
|
|
}
|
|
}
|
|
}
|