233 lines
12 KiB
C#
233 lines
12 KiB
C#
///
|
|
/// Copyright (c) 2013-2015 Sensus Metering Systems
|
|
///
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using Config.Entities;
|
|
using TBF.Resources;
|
|
|
|
namespace TBF.Forms
|
|
{
|
|
public class ResultItemSpec
|
|
{
|
|
///
|
|
/// 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(MeterTestResult meterTestResult);
|
|
|
|
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(MeterTestResult meterTestResult)
|
|
{
|
|
string str = printDlgt(meterTestResult);
|
|
return (str == null) ? string.Empty : str;
|
|
}
|
|
|
|
|
|
///
|
|
/// Function to pick a MeterTestResult field and convert it into a string
|
|
///
|
|
public delegate string PrintCombinedDlgt(MeterTestResult largeMeterTestResult,
|
|
MeterTestResult smallMeterTestResult,
|
|
MeterTestResult combinedMeterTestResult);
|
|
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(MeterTestResult largeMeterTestResult,
|
|
MeterTestResult smallMeterTestResult,
|
|
MeterTestResult combinedMeterTestResult)
|
|
{
|
|
string str = printCombinedDlgt(largeMeterTestResult, smallMeterTestResult, combinedMeterTestResult);
|
|
return (str == null) ? string.Empty : str;
|
|
}
|
|
|
|
|
|
|
|
///
|
|
/// Public constructor
|
|
///
|
|
public ResultItemSpec(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<ResultItemSpec> AllItems;
|
|
|
|
/// Static constructor that initializes the list of all items
|
|
static ResultItemSpec()
|
|
{
|
|
AllItems = new List<ResultItemSpec>();
|
|
|
|
/// Common
|
|
AllItems.Add(new ResultItemSpec("Test name", "Test", x => x.TestResult.TestName,
|
|
(x, y, z) => x.TestResult.TestName));
|
|
AllItems.Add(new ResultItemSpec("Procedure name", Strings.Procedure, x => x.TestResult.ProcedureName,
|
|
(x, y, z) => x.TestResult.ProcedureName));
|
|
AllItems.Add(new ResultItemSpec("Batch number", "Batch nr.", x => x.TestResult.BatchNr.ToString(),
|
|
(x, y, z) => x.TestResult.BatchNr.ToString()));
|
|
|
|
/// Target values
|
|
AllItems.Add(new ResultItemSpec("Q from", Strings.Q_from_m3h, x => x.TestResult.Qfrom.ToString("F3"),
|
|
(x, y, z) => x.TestResult.Qfrom.ToString("F3")));
|
|
AllItems.Add(new ResultItemSpec("Q to", Strings.Q_to_m3h, x => x.TestResult.Qto.ToString("F3"),
|
|
(x, y, z) => x.TestResult.Qto.ToString("F3")));
|
|
AllItems.Add(new ResultItemSpec("Test volume", "Test vol. [l]", x => x.TestResult.Volume.ToString("F1"),
|
|
(x, y, z) => x.TestResult.Volume.ToString("F1")));
|
|
AllItems.Add(new ResultItemSpec("Error limit Lo", "Err.Lim.Lo [%]", x => x.TestResult.ErrLimLo.ToString("F1"),
|
|
(x, y, z) => x.TestResult.ErrLimLo.ToString("F1")));
|
|
AllItems.Add(new ResultItemSpec("Error limit Hi", "Err.Lim.Hi [%]", x => x.TestResult.ErrLimHi.ToString("F1"),
|
|
(x, y, z) => x.TestResult.ErrLimHi.ToString("F1")));
|
|
AllItems.Add(new ResultItemSpec("Error limit sum", "Err.Lim.Sum [%]", x => (x.TestResult.ErrLimHi - x.TestResult.ErrLimLo).ToString("F1"),
|
|
(x, y, z) => (x.TestResult.ErrLimHi - x.TestResult.ErrLimLo).ToString("F1")));
|
|
|
|
/// Test results
|
|
AllItems.Add(new ResultItemSpec("Start time", "T start", x => x.TestResult.TimeStart.ToShortTimeString(),
|
|
(x, y, z) => z.TestResult.TimeStart.ToShortTimeString()));
|
|
AllItems.Add(new ResultItemSpec("End time", "T end", x => x.TestResult.TimeEnd.ToShortTimeString(),
|
|
(x, y, z) => z.TestResult.TimeEnd.ToShortTimeString()));
|
|
AllItems.Add(new ResultItemSpec("Test time", "T [s]", x => x.TestResult.Time.ToString("F2"),
|
|
(x, y, z) => z.TestResult.Time.ToString("F2")));
|
|
AllItems.Add(new ResultItemSpec("Flow", Strings.Flow_m3h, x => FloatToStr(x.TestResult.FlowVolume / 1000.0f, 4),
|
|
(x, y, z) => FloatToStr(z.TestResult.FlowVolume / 1000.0f, 4)));
|
|
AllItems.Add(new ResultItemSpec("T in", Strings.T_in, x => x.TestResult.TempInAvrg.ToString("F2"),
|
|
(x, y, z) => z.TestResult.TempInAvrg.ToString("F2")));
|
|
AllItems.Add(new ResultItemSpec("T out", Strings.T_out, x => x.TestResult.TempOutAvrg.ToString("F2"),
|
|
(x, y, z) => z.TestResult.TempOutAvrg.ToString("F2")));
|
|
AllItems.Add(new ResultItemSpec("T div", Strings.T_div, x => x.TestResult.TempDivAvrg.ToString("F2"),
|
|
(x, y, z) => z.TestResult.TempDivAvrg.ToString("F2")));
|
|
AllItems.Add(new ResultItemSpec("P up", Strings.P_in, x => x.TestResult.PressInAvrg.ToString("F3"),
|
|
(x, y, z) => z.TestResult.PressInAvrg.ToString("F3")));
|
|
AllItems.Add(new ResultItemSpec("P up start", Strings.P_in_start, x => x.TestResult.PressInStart.ToString("F3"),
|
|
(x, y, z) => z.TestResult.PressInStart.ToString("F3")));
|
|
AllItems.Add(new ResultItemSpec("P up end", Strings.P_in_end, x => x.TestResult.PressInEnd.ToString("F3"),
|
|
(x, y, z) => z.TestResult.PressInEnd.ToString("F3")));
|
|
AllItems.Add(new ResultItemSpec("P down", Strings.P_out, x => x.TestResult.PressOutAvrg.ToString("F3"),
|
|
(x, y, z) => z.TestResult.PressOutAvrg.ToString("F3")));
|
|
AllItems.Add(new ResultItemSpec("P down start", Strings.P_out_start, x => x.TestResult.PressOutStart.ToString("F3"),
|
|
(x, y, z) => z.TestResult.PressOutStart.ToString("F3")));
|
|
AllItems.Add(new ResultItemSpec("P down end", Strings.P_out_end, x => x.TestResult.PressOutEnd.ToString("F3"),
|
|
(x, y, z) => z.TestResult.PressOutEnd.ToString("F3")));
|
|
AllItems.Add(new ResultItemSpec("Reference error", "Err.ref. [%]", x => x.TestResult.ErrorMaster.ToString("F3"),
|
|
(x, y, z) => z.TestResult.ErrorMaster.ToString("F3")));
|
|
AllItems.Add(new ResultItemSpec("Ambient temperature", "T amb", x => x.TestResult.AmbientTempAve.ToString("F1"),
|
|
(x, y, z) => z.TestResult.AmbientTempAve.ToString("F1")));
|
|
AllItems.Add(new ResultItemSpec("Ambient pressure", "P amb", x => x.TestResult.AmbientPressAve.ToString("F0"),
|
|
(x, y, z) => z.TestResult.AmbientPressAve.ToString("F0")));
|
|
AllItems.Add(new ResultItemSpec("Ambient humidity", "H amb [%]", x => x.TestResult.AmbientHumiAve.ToString("F1"),
|
|
(x, y, z) => z.TestResult.AmbientHumiAve.ToString("F1")));
|
|
|
|
/// Single and combined meter results
|
|
AllItems.Add(new ResultItemSpec("Volume", "Volume [l]", x => x.VolumeMeter.ToString("F3"),
|
|
(x, y, z) => z.VolumeMeter.ToString("F3")));
|
|
AllItems.Add(new ResultItemSpec("Reference volume", "Vol.ref. [l]", x => x.VolumeRef.ToString("F3"),
|
|
(x, y, z) => z.VolumeRef.ToString("F3")));
|
|
AllItems.Add(new ResultItemSpec("Error", "Error [%]", x => x.VolumeErrorPct.ToString("F2"),
|
|
(x, y, z) => z.VolumeErrorPct.ToString("F2")));
|
|
AllItems.Add(new ResultItemSpec("Passed", "Result", x => (x.Passed ? Strings.Passed + "|Green" : Strings.Failed + "|Red"),
|
|
(x, y, z) => (z.Passed ? Strings.Passed + "|Green" : Strings.Failed + "|Red")));
|
|
|
|
/// Single water meters only results
|
|
AllItems.Add(new ResultItemSpec("Serial Nr", "s/n", x => x.SerialNr, null));
|
|
AllItems.Add(new ResultItemSpec("End state", "End state", x => x.EndState, null));
|
|
AllItems.Add(new ResultItemSpec("Pulses", "Pulses", x => x.PulsesMeter.ToString(), null));
|
|
AllItems.Add(new ResultItemSpec("Pulses/liter", "Pulses/liter", x => x.PulsesPerLiter.ToString(), null));
|
|
AllItems.Add(new ResultItemSpec("Reference pulses", "Ref.pulses", x => x.PulsesMaster.ToString(), null));
|
|
|
|
/// Combined water meters only results
|
|
AllItems.Add(new ResultItemSpec("Q rise", "Q rise [m3/h]", null, (x, y, z) => (x.TestResult.QRise == 0) ? "-" : Utils.FloatToStr(x.TestResult.QRise, 4)));
|
|
AllItems.Add(new ResultItemSpec("Q fall", "Q fall [m3/h]", null, (x, y, z) => (x.TestResult.QFall == 0) ? "-" : Utils.FloatToStr(x.TestResult.QFall, 4)));
|
|
AllItems.Add(new ResultItemSpec("Error large WM", "Error-L [%]", null, (x, y, z) => x.VolumeErrorPct.ToString("F2")));
|
|
AllItems.Add(new ResultItemSpec("Error small WM", "Error-S [%]", null, (x, y, z) => y.VolumeErrorPct.ToString("F2")));
|
|
AllItems.Add(new ResultItemSpec("Serial Nr large WM", "s/n", null, (x, y, z) => x.SerialNr));
|
|
AllItems.Add(new ResultItemSpec("Serial Nr small WM", "s/n", null, (x, y, z) => y.SerialNr));
|
|
AllItems.Add(new ResultItemSpec("End state large WM", "End state", null, (x, y, z) => x.EndState));
|
|
AllItems.Add(new ResultItemSpec("End state small WM", "End state", null, (x, y, z) => y.EndState));
|
|
}
|
|
|
|
public static ResultItemSpec GetItem(string name)
|
|
{
|
|
foreach (var item in AllItems) if (item.Name.Equals(name)) return item;
|
|
return null;
|
|
}
|
|
|
|
public static string[] ToStrArray(IList<ResultItemSpec> 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<ResultItemSpec> FromStrArray(string[] strArray)
|
|
{
|
|
IList<ResultItemSpec> result = new List<ResultItemSpec>();
|
|
if (strArray != null)
|
|
{
|
|
for (int i = 0; i < strArray.Length; i++)
|
|
{
|
|
ResultItemSpec 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 FloatToStr(float value, int validDigits)
|
|
{
|
|
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();
|
|
}
|
|
}
|
|
}
|