iPerlSpecial: Output.FileWriters.Basic rewritten to handle one water meter in one row (incl. fetch of test results).

This commit is contained in:
Milan Hanajik
2016-04-29 16:57:41 +02:00
parent 4ea8d66330
commit d1eb7b21d1
16 changed files with 1151 additions and 687 deletions
+6 -3
View File
@@ -24,8 +24,8 @@ namespace Results.Entities
public virtual bool TestDone { get; set; } /// true = test was completed
public virtual bool Passed { get; set; } /// true = test passed, water meter is OK
public virtual WaterMeter WaterMeter { get; set; } /// reference to the TestData entity
public virtual TestRslt TestRslt { get; set; } /// reference to the TestData entity
public virtual WaterMeter WaterMeter { get; set; } /// reference to the WaterMeter entity
public virtual TestRslt TestRslt { get; set; } /// reference to the TestRslt entity
/// Wrappers
public virtual string Name() { return TestRslt.Name(); }
@@ -57,9 +57,12 @@ namespace Results.Entities
public virtual double QRise() { return WaterMeter.QRise; } /// [m3/h]
public virtual double QFall() { return WaterMeter.QFall; } /// [m3/h]
public virtual bool Evaluate() { return TestData().Evaluate; }
public virtual bool Evaluate() { return TestData().Evaluate; }
public virtual Config.Entities.Publish Publish() { return (Config.Entities.Publish)TestData().Publish; }
public virtual WaterMeterData WaterMeterData() { return WaterMeter.WaterMeterData; }
public virtual Batch Batch() { return WaterMeter.Batch; }
public virtual string PassedColorStr()
{
if (!Evaluate()) return Passed ? "OK|White" : "NOK|White";
+81 -95
View File
@@ -54,7 +54,6 @@ namespace Results
}
///
/// Public constructor
///
@@ -77,63 +76,94 @@ namespace Results
/// 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]
//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")));
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")));
AllItems.Add(new ItemSpec("Test start time", "T start", x => x.StartTime().ToShortTimeString(), (x, y, z) => z.StartTime().ToShortTimeString()));
AllItems.Add(new ItemSpec("Test 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 => Utils.DoubleToStr(x.FlowVolume(), 4), (x, y, z) => Utils.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));
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()));
/// 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()));
}
/// Water meter info
AllItems.Add(new ItemSpec("Watermeter type", "WM Type", x => x.WaterMeterData().ProductName, (x, y, z) => z.WaterMeterData().ProductName));
AllItems.Add(new ItemSpec("Producer", "Producer", x => x.WaterMeterData().Producer, (x, y, z) => z.WaterMeterData().Producer));
AllItems.Add(new ItemSpec("Metrological class", "M.Class", x => x.WaterMeterData().MetrologicalClass, (x, y, z) => z.WaterMeterData().MetrologicalClass));
AllItems.Add(new ItemSpec("Approval info", "Approval", x => x.WaterMeterData().ApprovalInfo, (x, y, z) => z.WaterMeterData().ApprovalInfo));
AllItems.Add(new ItemSpec("Q4", "Q4", x => x.WaterMeterData().Q4_Qmax.ToString(), (x, y, z) => z.WaterMeterData().Q4_Qmax.ToString()));
AllItems.Add(new ItemSpec("Q3", "Q3", x => x.WaterMeterData().Q3.ToString(), (x, y, z) => z.WaterMeterData().Q3.ToString()));
AllItems.Add(new ItemSpec("Q2", "Q2", x => x.WaterMeterData().Q2_Qt.ToString(), (x, y, z) => z.WaterMeterData().Q2_Qt.ToString()));
AllItems.Add(new ItemSpec("Q1", "Q1", x => x.WaterMeterData().Q1_Qmin.ToString(), (x, y, z) => z.WaterMeterData().Q1_Qmin.ToString()));
AllItems.Add(new ItemSpec("Qmax", "Qmax", x => x.WaterMeterData().Q4_Qmax.ToString(), (x, y, z) => z.WaterMeterData().Q4_Qmax.ToString()));
AllItems.Add(new ItemSpec("Qn", "Qn", x => x.WaterMeterData().Q3.ToString(), (x, y, z) => z.WaterMeterData().Q3.ToString()));
AllItems.Add(new ItemSpec("Qt", "Qt", x => x.WaterMeterData().Q2_Qt.ToString(), (x, y, z) => z.WaterMeterData().Q2_Qt.ToString()));
AllItems.Add(new ItemSpec("Qmin", "Qmin", x => x.WaterMeterData().Q1_Qmin.ToString(), (x, y, z) => z.WaterMeterData().Q1_Qmin.ToString()));
/// Water meters results
AllItems.Add(new ItemSpec("Serial Nr", "s/n", x => x.WaterMeter.SerialNr, (x, y, z) => z.WaterMeter.SerialNr));
AllItems.Add(new ItemSpec("Purchase order", "PO", x => x.WaterMeter.PurchaseOrder, (x, y, z) => z.WaterMeter.PurchaseOrder));
AllItems.Add(new ItemSpec("Year of production", "Year", x => x.WaterMeter.YearOfProduction.ToString(), (x, y, z) => z.WaterMeter.YearOfProduction.ToString()));
AllItems.Add(new ItemSpec("WM Position", "Pos.", x => x.WaterMeter.WMPosition.ToString(), (x, y, z) => z.WaterMeter.WMPosition.ToString()));
/// Water meters results (single)
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));
/// 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()));
/// Batch info
AllItems.Add(new ItemSpec("Batch number", "Batch#", x => x.Batch().BatchNr.ToString(), (x, y, z) => x.Batch().BatchNr.ToString()));
AllItems.Add(new ItemSpec("Test bench ID", "Bench", x => x.Batch().TestBenchId.ToString(), (x, y, z) => x.Batch().TestBenchId.ToString()));
AllItems.Add(new ItemSpec("Program version", "Ver.", x => x.Batch().ProgramVersion, (x, y, z) => x.Batch().ProgramVersion));
AllItems.Add(new ItemSpec("User name", "User", x => x.Batch().UserName, (x, y, z) => x.Batch().UserName));
AllItems.Add(new ItemSpec("User nr.", "User#", x => x.Batch().UserNumber.ToString(), (x, y, z) => x.Batch().UserNumber.ToString()));
AllItems.Add(new ItemSpec("Procedure name", "Procedure", x => x.Batch().ProcedureName, (x, y, z) => x.Batch().ProcedureName));
AllItems.Add(new ItemSpec("Watermeters", "WMs", x => x.Batch().WatermetersStr, (x, y, z) => x.Batch().WatermetersStr));
AllItems.Add(new ItemSpec("Protocol title", "Protocol", x => x.Batch().ProtocolTitle, (x, y, z) => x.Batch().ProtocolTitle));
AllItems.Add(new ItemSpec("Batch start time", "Start", x => x.Batch().StartTime.ToShortTimeString(), (x, y, z) => x.Batch().StartTime.ToShortTimeString()));
AllItems.Add(new ItemSpec("Batch end time", "End", x => x.Batch().EndTime.ToShortTimeString(), (x, y, z) => x.Batch().EndTime.ToShortTimeString()));
}
public static ItemSpec GetItem(string name)
{
@@ -162,49 +192,5 @@ namespace Results
}
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();
}
}
}
+2 -2
View File
@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.5.265.0")]
[assembly: AssemblyFileVersion("2.5.265.0")]
[assembly: AssemblyVersion("2.5.276.0")]
[assembly: AssemblyFileVersion("2.5.276.0")]
+1
View File
@@ -75,6 +75,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ItemSpec.cs" />
<Compile Include="Utils.cs" />
<Compile Include="WMeterRsltItemSpec.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Config\Config.csproj">
+50 -2
View File
@@ -1,5 +1,9 @@
using System;
///
/// Copyright (c) 2016 Sensus Metering Systems
///
using System;
using System.Text;
using Config.Entities;
namespace Results
{
@@ -10,5 +14,49 @@ namespace Results
if (repeats == 1) return name;
return string.Format("{0} ({1}/{2})", name, repetitionNr, repeats);
}
}
/// <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();
}
}
}
+259
View File
@@ -0,0 +1,259 @@
///
/// Copyright (c) 2013-2016 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using Results.Entities;
namespace Results
{
public class WMeterRsltItemSpec
{
///
/// Public fields
///
public readonly int Uid;
public readonly string Name; /// Name-s of all items must be unique
public string Header; /// Specifies the header to be printed at the top of the table
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()
{
WMeterRsltItemSpec item2 = new WMeterRsltItemSpec(Uid, Name, printDlgt);
item2.Header = Header;
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
///
public WMeterRsltItemSpec(int uid, string name, PrintDlgt printDlgt)
{
Uid = uid;
Name = name;
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>();
AllItems.Add(new WMeterRsltItemSpec(0, "String", (w, t, u, f, p) => f));
/// Common
AllItems.Add(new WMeterRsltItemSpec(1, "Test name", (w, t, u, f, p) => w.GetTestRslt(t).Name()));
AllItems.Add(new WMeterRsltItemSpec(2, "Procedure name", (w, t, u, f, p) => w.ProcedureName()));
AllItems.Add(new WMeterRsltItemSpec(3, "Batch number", (w, t, u, f, p) => w.BatchNr().ToString()));
AllItems.Add(new WMeterRsltItemSpec(4, "Test method", (w, t, u, f, p) => w.GetTestRslt(t).Method()));
AllItems.Add(new WMeterRsltItemSpec(5, "Density", (w, t, u, f, p) => w.GetTestRslt(t).DensityOut.ToString(string.IsNullOrEmpty(p) ? "F1" : p))); /// [kg/m3]
/// Target values
AllItems.Add(new WMeterRsltItemSpec(6, "Q from", (w, t, u, f, p) => w.GetTestRslt(t).Qfrom().ToString(string.IsNullOrEmpty(p) ? "F3" : p)));
AllItems.Add(new WMeterRsltItemSpec(7, "Q to", (w, t, u, f, p) => w.GetTestRslt(t).Qto().ToString(string.IsNullOrEmpty(p) ? "F3" : p)));
AllItems.Add(new WMeterRsltItemSpec(8, "Test volume", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetTestRslt(t).TargetVolume()).ToString(string.IsNullOrEmpty(p) ? "F1" : p)));
AllItems.Add(new WMeterRsltItemSpec(9, "Error limit Lo", (w, t, u, f, p) => w.GetTestRslt(t).ErrLimLo().ToString(string.IsNullOrEmpty(p) ? "F1" : p)));
AllItems.Add(new WMeterRsltItemSpec(10, "Error limit Hi", (w, t, u, f, p) => w.GetTestRslt(t).ErrLimHi().ToString(string.IsNullOrEmpty(p) ? "F1" : p)));
AllItems.Add(new WMeterRsltItemSpec(11, "Uncertainty", (w, t, u, f, p) => w.GetTestRslt(t).Uncertainty().ToString(string.IsNullOrEmpty(p) ? "F2" : p)));
/// Test results
AllItems.Add(new WMeterRsltItemSpec(12, "Test start time", (w, t, u, f, p) => w.GetTestRslt(t).StartTime.ToShortTimeString()));
AllItems.Add(new WMeterRsltItemSpec(13, "Test end time", (w, t, u, f, p) => w.GetTestRslt(t).EndTime.ToShortTimeString()));
AllItems.Add(new WMeterRsltItemSpec(14, "Test time", (w, t, u, f, p) => w.GetTestRslt(t).TestTime.ToString(string.IsNullOrEmpty(p) ? "F2" : p)));
AllItems.Add(new WMeterRsltItemSpec(15, "Flow", (w, t, u, f, p) => Utils.DoubleToStr(Config.Units.ConvertTo(u, w.GetTestRslt(t).FlowVolume), 4)));
AllItems.Add(new WMeterRsltItemSpec(16, "T in", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetTestRslt(t).TempInAvrg).ToString(string.IsNullOrEmpty(p) ? "F2" : p)));
AllItems.Add(new WMeterRsltItemSpec(17, "T out", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetTestRslt(t).TempOutAvrg).ToString(string.IsNullOrEmpty(p) ? "F2" : p)));
AllItems.Add(new WMeterRsltItemSpec(18, "T div", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetTestRslt(t).TempDivAvrg).ToString(string.IsNullOrEmpty(p) ? "F2" : p)));
AllItems.Add(new WMeterRsltItemSpec(19, "P up", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetTestRslt(t).PressUpAvrg).ToString(string.IsNullOrEmpty(p) ? "F3" : p)));
AllItems.Add(new WMeterRsltItemSpec(20, "P up start", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetTestRslt(t).PressUpStart).ToString(string.IsNullOrEmpty(p) ? "F3" : p)));
AllItems.Add(new WMeterRsltItemSpec(21, "P up end", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetTestRslt(t).PressUpEnd).ToString(string.IsNullOrEmpty(p) ? "F3" : p)));
AllItems.Add(new WMeterRsltItemSpec(22, "P down", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetTestRslt(t).PressDownAvrg).ToString(string.IsNullOrEmpty(p) ? "F3" : p)));
AllItems.Add(new WMeterRsltItemSpec(23, "P down start", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetTestRslt(t).PressDownStart).ToString(string.IsNullOrEmpty(p) ? "F3" : p)));
AllItems.Add(new WMeterRsltItemSpec(24, "P down end", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetTestRslt(t).PressDownEnd).ToString(string.IsNullOrEmpty(p) ? "F3" : p)));
AllItems.Add(new WMeterRsltItemSpec(25, "Reference error", (w, t, u, f, p) => w.GetTestRslt(t).ErrorMaster.ToString(string.IsNullOrEmpty(p) ? "F3" : p)));
AllItems.Add(new WMeterRsltItemSpec(26, "Ambient temperature", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetTestRslt(t).AmbientTempAve).ToString(string.IsNullOrEmpty(p) ? "F1" : p)));
AllItems.Add(new WMeterRsltItemSpec(27, "Ambient pressure", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetTestRslt(t).AmbientPressAve).ToString(string.IsNullOrEmpty(p) ? "F0" : p)));
AllItems.Add(new WMeterRsltItemSpec(28, "Ambient humidity", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetTestRslt(t).AmbientHumiAve).ToString(string.IsNullOrEmpty(p) ? "F1" : p)));
/// Single and combined meter results
AllItems.Add(new WMeterRsltItemSpec(29, "Volume", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetMeterTestRslt(t).VolumeMeter).ToString(string.IsNullOrEmpty(p) ? "F3" : p)));
AllItems.Add(new WMeterRsltItemSpec(30, "Reference volume", (w, t, u, f, p) => Config.Units.ConvertTo(u, w.GetMeterTestRslt(t).VolumeRef).ToString(string.IsNullOrEmpty(p) ? "F3" : p)));
AllItems.Add(new WMeterRsltItemSpec(31, "Error", (w, t, u, f, p) => w.GetMeterTestRslt(t).Error.ToString(string.IsNullOrEmpty(p) ? "F2" : p)));
AllItems.Add(new WMeterRsltItemSpec(32, "Passed", (w, t, u, f, p) => w.GetMeterTestRslt(t).PassedColorStr()));
/// Water meter info
AllItems.Add(new WMeterRsltItemSpec(33, "Watermeter type", (w, t, u, f, p) => w.WaterMeterData.ProductName));
AllItems.Add(new WMeterRsltItemSpec(34, "Producer", (w, t, u, f, p) => w.WaterMeterData.Producer));
AllItems.Add(new WMeterRsltItemSpec(35, "Metrological class", (w, t, u, f, p) => w.WaterMeterData.MetrologicalClass));
AllItems.Add(new WMeterRsltItemSpec(36, "Approval info", (w, t, u, f, p) => w.WaterMeterData.ApprovalInfo));
AllItems.Add(new WMeterRsltItemSpec(37, "Q4", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.Q4_Qmax).ToString()
: Config.Units.ConvertTo(u, w.WaterMeterData.Q4_Qmax).ToString(p)));
AllItems.Add(new WMeterRsltItemSpec(38, "Q3", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.Q3).ToString()
: Config.Units.ConvertTo(u, w.WaterMeterData.Q3).ToString(p)));
AllItems.Add(new WMeterRsltItemSpec(39, "Q2", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.Q2_Qt).ToString()
: Config.Units.ConvertTo(u, w.WaterMeterData.Q2_Qt).ToString(p)));
AllItems.Add(new WMeterRsltItemSpec(40, "Q1", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.Q1_Qmin).ToString()
: Config.Units.ConvertTo(u, w.WaterMeterData.Q1_Qmin).ToString(p)));
AllItems.Add(new WMeterRsltItemSpec(41, "Qmax", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.Q4_Qmax).ToString()
: Config.Units.ConvertTo(u, w.WaterMeterData.Q4_Qmax).ToString(p)));
AllItems.Add(new WMeterRsltItemSpec(42, "Qn", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.Q3).ToString()
: Config.Units.ConvertTo(u, w.WaterMeterData.Q3).ToString(p)));
AllItems.Add(new WMeterRsltItemSpec(43, "Qt", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.Q2_Qt).ToString()
: Config.Units.ConvertTo(u, w.WaterMeterData.Q2_Qt).ToString(p)));
AllItems.Add(new WMeterRsltItemSpec(44, "Qmin", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? Config.Units.ConvertTo(u, w.WaterMeterData.Q1_Qmin).ToString()
: Config.Units.ConvertTo(u, w.WaterMeterData.Q1_Qmin).ToString(p)));
/// Water meters results
AllItems.Add(new WMeterRsltItemSpec(45, "Serial Nr", (w, t, u, f, p) => w.SerialNr));
AllItems.Add(new WMeterRsltItemSpec(46, "Purchase order", (w, t, u, f, p) => w.PurchaseOrder));
AllItems.Add(new WMeterRsltItemSpec(47, "Year of production", (w, t, u, f, p) => w.YearOfProduction.ToString()));
AllItems.Add(new WMeterRsltItemSpec(48, "WM Position", (w, t, u, f, p) => w.WMPosition.ToString()));
/// Water meters results (single)
AllItems.Add(new WMeterRsltItemSpec(49, "End state", (w, t, u, f, p) => w.EndState));
AllItems.Add(new WMeterRsltItemSpec(50, "Pulses", (w, t, u, f, p) => w.GetMeterTestRslt(t).PulsesMeter.ToString()));
AllItems.Add(new WMeterRsltItemSpec(51, "Pulses/liter", (w, t, u, f, p) => string.IsNullOrEmpty(p) ? w.GetMeterTestRslt(t).PulsesPerLiter.ToString()
: w.GetMeterTestRslt(t).PulsesPerLiter.ToString(p)));
AllItems.Add(new WMeterRsltItemSpec(52, "Reference pulses", (w, t, u, f, p) => w.GetMeterTestRslt(t).PulsesMaster.ToString()));
/// Batch info
AllItems.Add(new WMeterRsltItemSpec(53, "Batch number", (w, t, u, f, p) => w.Batch.BatchNr.ToString()));
AllItems.Add(new WMeterRsltItemSpec(54, "Test bench ID", (w, t, u, f, p) => w.Batch.TestBenchId.ToString()));
AllItems.Add(new WMeterRsltItemSpec(55, "Program version", (w, t, u, f, p) => w.Batch.ProgramVersion));
AllItems.Add(new WMeterRsltItemSpec(56, "User name", (w, t, u, f, p) => w.Batch.UserName));
AllItems.Add(new WMeterRsltItemSpec(57, "User nr.", (w, t, u, f, p) => w.Batch.UserNumber.ToString()));
AllItems.Add(new WMeterRsltItemSpec(58, "Procedure name", (w, t, u, f, p) => w.Batch.ProcedureName));
AllItems.Add(new WMeterRsltItemSpec(59, "Watermeters", (w, t, u, f, p) => w.Batch.WatermetersStr));
AllItems.Add(new WMeterRsltItemSpec(60, "Protocol title", (w, t, u, f, p) => w.Batch.ProtocolTitle));
AllItems.Add(new WMeterRsltItemSpec(61, "Batch start time", (w, t, u, f, p) => w.Batch.StartTime.ToShortTimeString()));
AllItems.Add(new WMeterRsltItemSpec(62, "Batch end time", (w, t, u, f, p) => w.Batch.EndTime.ToShortTimeString()));
}
/// <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,
items[i].Header,
items[i].TestID,
items[i].Units,
items[i].Format,
items[i].Precision,
items[i].Width,
items[i].Alignment);
}
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>();
if (strArray != null)
{
for (int i = 0; i < strArray.Length; i++)
{
string[] field = strArray[i].Split(new char[] { '~' });
try
{
WMeterRsltItemSpec item = GetItem(int.Parse(field[0]));
item.Header = 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);
}
catch
{
WMeterRsltItemSpec item = GetItem(0);
item.Format = string.Format("Parse error: {0}", strArray[i]);
result.Add(item);
}
}
}
return result;
}
private static WMeterRsltItemSpec GetItem(int uid)
{
foreach (var item in AllItems)
{
if (item.Uid == uid) return item.Clone();
}
return null;
}
}
}