Results.BatchResults.NewFromProcedure(...) added, BenchId -> TestBenchId, BenchName -> TestBenchName, etc.

This commit is contained in:
Milan Hanajik
2016-01-02 19:21:43 +01:00
parent 61bfa51fa7
commit 494c6edf76
26 changed files with 480 additions and 225 deletions
+170
View File
@@ -0,0 +1,170 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Results.Entities;
namespace Results
{
public class BatchResults
{
public IList<Entities.TestData> TestDataList;
public IList<Entities.Components> ComponentsList;
public IList<Entities.WaterMeterData> WaterMeterDataList;
public IDictionary<string, TestRslt> TestRsltsMap;
public IDictionary<string, MeterTestRslt>[] MeterTestRsltsMap;
public IDictionary<string, MeterTestRslt>[] MainMeterTestRsltsMap;
public IDictionary<string, MeterTestRslt>[] AuxMeterTestRsltsMap;
private BatchResults()
{
TestDataList = new List<Entities.TestData>();
ComponentsList = new List<Entities.Components>();
WaterMeterDataList = new List<Entities.WaterMeterData>();
TestRsltsMap = new Dictionary<string, TestRslt>();
}
public int WMPositionsCount;
public Batch Batch;
public WaterMeter[] WaterMeters;
public IList<TestRslt> TestRslts;
public IList<TestRslt> MeterTestRslts;
public static BatchResults NewFromProcedure(int batchNr,
int benchId,
string user,
string programVer,
Config.Entities.Procedure procedure,
WaterMeterData[] waterMeterDatas,
int[] waterMeterParts)
{
BatchResults d = new BatchResults();
d.WMPositionsCount = waterMeterDatas.Length;
///
d.MeterTestRsltsMap = new Dictionary<string, MeterTestRslt>[d.WMPositionsCount];
d.MainMeterTestRsltsMap = new Dictionary<string, MeterTestRslt>[d.WMPositionsCount];
d.AuxMeterTestRsltsMap = new Dictionary<string, MeterTestRslt>[d.WMPositionsCount];
for (int wmnr = 0; wmnr < d.WMPositionsCount; wmnr++)
{
d.MeterTestRsltsMap[wmnr] = new Dictionary<string, MeterTestRslt>();
d.MainMeterTestRsltsMap[wmnr] = new Dictionary<string, MeterTestRslt>();
d.AuxMeterTestRsltsMap[wmnr] = new Dictionary<string, MeterTestRslt>();
}
/// Create new batch
d.Batch = new Batch()
{
TestBenchId = benchId,
BatchNr = batchNr,
ProgramVersion = programVer,
UserName = user,
ProcedureName = procedure.Name,
ProcedureRevision = procedure.Revision,
StartTime = DateTime.Now,
};
///
/// Add watermeter to an array, array index is WM position.
/// AddWaterMetersToBatch() has to be used before saving results.
///
d.WaterMeters = new WaterMeter[d.WMPositionsCount];
for (int i = 0; i < d.WMPositionsCount; i++)
{
if (waterMeterDatas[i] == null) continue;
WaterMeterData wmd = WaterMeterData.UpdateList(d.WaterMeterDataList, waterMeterDatas[i]);
d.WaterMeters[i] = new WaterMeter() { Batch = d.Batch, WaterMeterData = wmd, WMPosition = i + 1 };
}
foreach (var t in procedure.Tests)
{
if (t.Publish)
{
TestData td = TestData.UpdateList(d.TestDataList, new TestData(t));
for (int rnr = 1; rnr <= t.Repeats; rnr++)
{
/// Create an empty test result and add it to the list
TestRslt tr = new TestRslt(d.Batch, td, t.Part, rnr);
d.TestRslts.Add(tr);
d.TestRsltsMap.Add(tr.Name(), tr);
for (int i = 0; i < d.WMPositionsCount; i++)
{
if (d.WaterMeters[i] == null) continue;
if (t.Part != 0 && waterMeterParts[i] != 0 && t.Part != waterMeterParts[i]) continue;
/// Create empty watermeter test results and add them to the list and to dictionaries
if (procedure.MetersKind == Config.Entities.MetersKind.Single)
{
MeterTestRslt mtr = new MeterTestRslt(d.WaterMeters[i], tr, Config.Entities.CompoundMeterId.Single);
d.WaterMeters[i].MeterTestRslts.Add(mtr);
d.MeterTestRsltsMap[i].Add(tr.Name(), mtr);
}
else
{
MeterTestRslt mainMTR = new MeterTestRslt(d.WaterMeters[i], tr, Config.Entities.CompoundMeterId.CompoundMain);
d.WaterMeters[i].MeterTestRslts.Add(mainMTR);
d.MainMeterTestRsltsMap[i].Add(tr.Name(), mainMTR);
MeterTestRslt auxMTR = new MeterTestRslt(d.WaterMeters[i], tr, Config.Entities.CompoundMeterId.CompoundAux);
d.WaterMeters[i].MeterTestRslts.Add(auxMTR);
d.MainMeterTestRsltsMap[i].Add(tr.Name(), auxMTR);
MeterTestRslt cmpdMTR = new MeterTestRslt(d.WaterMeters[i], tr, Config.Entities.CompoundMeterId.Compound);
d.WaterMeters[i].MeterTestRslts.Add(cmpdMTR);
d.MainMeterTestRsltsMap[i].Add(tr.Name(), cmpdMTR);
}
}
}
}
}
return d;
}
public TestRslt GetTestRslt(string name, int part)
{
foreach (var tr in TestRslts)
{
if (part == tr.Part && name.Equals(tr.Name())) return tr;
}
return null;
}
public MeterTestRslt GetMeterTestRslt(string name, int wmnr0, Config.Entities.CompoundMeterId meterId)
{
if (WaterMeters[wmnr0] != null)
{
foreach (var mtr in WaterMeters[wmnr0].MeterTestRslts)
{
if (mtr.CompoundMeterId == (byte)meterId && name.Equals(mtr.Name())) return mtr;
}
}
return null;
}
/// <summary>
/// Adds non-null water meters from an array to a Batch water meters list.
/// This method should be used when results are prepared and
/// all disabled water meters are deleted.
/// </summary>
public void AddWaterMetersToBatch()
{
for (int i = 0; i < WMPositionsCount; i++)
{
if (WaterMeters[i] != null) Batch.WaterMeters.Add(WaterMeters[i]);
}
}
}
}
-98
View File
@@ -1,98 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Results.Entities;
namespace Results
{
public class Data
{
public int WMPositionsCount;
public Batch Batch;
public IList<TestRslt> TestRslts;
public IList<TestRslt> MeterTestRslts;
public WaterMeter[] WaterMeters;
public IDictionary<string, TestRslt> TestRsltsMap;
public IDictionary<string, MeterTestRslt> MeterTestRsltsMap;
public Data()
{
TestRsltsMap = new Dictionary<string, TestRslt>();
MeterTestRsltsMap = new Dictionary<string, MeterTestRslt>();
}
public static Data NewFromProcedure(Config.Entities.Procedure procedure,
WaterMeterData[] waterMeterDatas,
int batchNr,
int benchId,
string programVer,
string user)
{
Data d = new Data();
d.WMPositionsCount = waterMeterDatas.Length;
d.Batch = new Batch()
{
BenchId = benchId,
BatchNr = batchNr,
ProgramVersion = programVer,
UserName = user,
ProcedureName = procedure.Name,
ProcedureRevision = procedure.Revision,
StartTime = DateTime.Now
};
foreach (var t in procedure.Tests)
{
}
d.WaterMeters = new WaterMeter[d.WMPositionsCount];
for (int i = 0; i < d.WMPositionsCount; i++)
{
if (waterMeterDatas[i] != null)
{
d.WaterMeters[i] = new WaterMeter(d.Batch, waterMeterDatas[i]);
}
}
foreach (var t in procedure.Tests)
{
if (t.Publish)
{
d.Batch.Tests.Add(new TestData(t));
for (int i = 0; i < d.WMPositionsCount; i++)
{
if (d.WaterMeters[i] != null)
{
if (procedure.MetersKind == Config.Entities.MetersKind.Single)
{
//d.WaterMeters[i].MeterTestRslts.Add(
}
//else
//{
//}
}
}
}
}
return d;
}
/// <summary>
/// Adds non-null water meters from the array to a Batch water meters list.
/// This method should be used when results are prepared and
/// all disabled water meters are deleted.
/// </summary>
public void AddWaterMetersToBatch()
{
for (int i = 0; i < WMPositionsCount; i++)
{
if (WaterMeters[i] != null) Batch.WaterMeters.Add(WaterMeters[i]);
}
}
}
}
+1 -1
View File
@@ -9,8 +9,8 @@ namespace Results.Entities
public class Batch
{
public virtual int Id { get; protected set; }
public virtual int BenchId { get; set; }
public virtual int BatchNr { get; set; }
public virtual int TestBenchId { get; set; }
public virtual string ProgramVersion { get; set; }
public virtual string UserName { get; set; }
public virtual string ProcedureName { get; set; }
+32 -8
View File
@@ -3,14 +3,15 @@
///
using System;
using System.Collections.Generic;
using System.Linq;
namespace Results.Entities
{
public class Components
{
public virtual int Id { get; protected set; }
public virtual int BenchId { get; set; }
public virtual string BenchName { get; set; }
public virtual int TestBenchId { get; set; }
public virtual string TestBenchName { get; set; }
public virtual string Pump { get; set; }
public virtual string RegValve { get; set; }
public virtual string Flowmeter { get; set; }
@@ -22,8 +23,8 @@ namespace Results.Entities
protected Components()
{
BenchId = 0;
BenchName = string.Empty;
TestBenchId = 0;
TestBenchName = string.Empty;
Pump = string.Empty;
RegValve = string.Empty;
Flowmeter = string.Empty;
@@ -37,8 +38,8 @@ namespace Results.Entities
public Components(int benchId, string benchName, string pump, string flowmeter,
string scale, string regValve, string diverter)
{
BenchId = benchId;
BenchName = benchName;
TestBenchId = benchId;
TestBenchName = benchName;
Pump = pump;
RegValve = regValve;
Flowmeter = flowmeter;
@@ -49,10 +50,16 @@ namespace Results.Entities
Custom3 = string.Empty;
}
/// <summary>
/// Method to compare the content of two entities
/// </summary>
/// <param name="wmd">Second entity to compare with</param>
/// <returns>first = two entities are equal (except of Id)</returns>
public virtual bool Equals(Components bc)
{
if (BenchId != bc.BenchId) return false;
if (!BenchName.Equals(bc.BenchName)) return false;
if (TestBenchId != bc.TestBenchId) return false;
if (!TestBenchName.Equals(bc.TestBenchName)) return false;
if (!Pump.Equals(bc.Pump)) return false;
if (!RegValve.Equals(bc.RegValve)) return false;
if (!Flowmeter.Equals(bc.Flowmeter)) return false;
@@ -64,5 +71,22 @@ namespace Results.Entities
return true;
}
/// <summary>
/// Adds an item to the list if it does not occur there
/// </summary>
/// <param name="list">List of items</param>
/// <param name="item">Item to add to the list or find there</param>
/// <returns>Item from the list (existing or added)</returns>
public static Components UpdateList(IList<Components> list, Components item)
{
Components found = list.FirstOrDefault<Components>(x => x.Equals(item));
if (found != null) return found;
list.Add(item);
return item;
}
}
}
+8 -4
View File
@@ -20,7 +20,8 @@ namespace Results.Entities
public virtual double TimestampEnd { get; set; } /// sec.
public virtual double TestTime { get; set; } /// sec.
public virtual double Error { get; set; } /// %
public virtual bool Passed { get; set; } /// true=test passed - Not mapped to DB !!!
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
@@ -48,15 +49,18 @@ namespace Results.Entities
public virtual double Uncertainty() { return TestData().Uncertainty; }
protected MeterTestRslt()
public MeterTestRslt()
{
TestDone = false;
Passed = false;
}
public MeterTestRslt(WaterMeter waterMeterRslt, TestRslt testRslt)
public MeterTestRslt(WaterMeter waterMeterRslt, TestRslt testRslt, Config.Entities.CompoundMeterId compoundMeterId)
: this()
{
WaterMeter = waterMeterRslt;
TestRslt = testRslt;
}
CompoundMeterId = (byte)compoundMeterId;
}
}
}
+25 -1
View File
@@ -1,8 +1,9 @@
///
/// Copyright (c) 2015 Sensus Metering Systems
/// Copyright (c) 2016 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.Linq;
namespace Results.Entities
{
@@ -47,6 +48,12 @@ namespace Results.Entities
Evaluate = test.Evaluate;
}
/// <summary>
/// Method to compare the content of two entities
/// </summary>
/// <param name="wmd">Second entity to compare with</param>
/// <returns>first = two entities are equal (except of Id)</returns>
public virtual bool Equals(TestData td)
{
if (!Name.Equals(td.Name)) return false;
@@ -63,5 +70,22 @@ namespace Results.Entities
return true;
}
/// <summary>
/// Adds an item to the list if it does not occur there
/// </summary>
/// <param name="list">List of items</param>
/// <param name="item">Item to add to the list or find there</param>
/// <returns>Item from the list (existing or added)</returns>
public static TestData UpdateList(IList<TestData> list, TestData item)
{
TestData found = list.FirstOrDefault<TestData>(x => x.Equals(item));
if (found != null) return found;
list.Add(item);
return item;
}
}
}
+4 -21
View File
@@ -21,6 +21,7 @@ namespace Results.Entities
public virtual int SerialNrEx { get; set; } /// iPerl : This is the serial number assigned later
public virtual double OrigCalibFactor { get; set; } /// iPerl calibration factor used during the test - Not mapped to DB !!!
public virtual double CalibFactor { get; set; } /// iPerl calibration factor used during the test - Not mapped to DB !!!
public virtual bool Q2CorrectionDone { get; set; } /// true = iPerl Q2 correction was done
public virtual double Q2Correction { get; set; } /// iPerl Q2 correction used during the test - Not mapped to DB !!!
#endif
@@ -43,7 +44,7 @@ namespace Results.Entities
public virtual bool Compound() { return WaterMeterData.Compound; }
public virtual int BatchNr() { return Batch.BatchNr; }
public virtual int BenchId() { return Batch.BenchId; }
public virtual int BenchId() { return Batch.TestBenchId; }
public virtual string ProcedureName() { return Batch.ProcedureName; }
public virtual int ProcedureRevision() { return Batch.ProcedureRevision; }
public virtual DateTime StartTime() { return Batch.StartTime; }
@@ -67,31 +68,13 @@ namespace Results.Entities
/// <summary>
/// Private constructor, initializes a list, used as a base
/// Constructor, initializes a list, used as a base for other constructors
/// </summary>
protected WaterMeter()
public WaterMeter()
{
MeterTestRslts = new List<MeterTestRslt>();
}
/// <summary>
/// Constructor used to construct WaterMeterResults from the first meter test result
/// </summary>
public WaterMeter(Batch batch, WaterMeterData waterMeterData)
: this()
{
Batch = batch;
WaterMeterData = waterMeterData;
}
/// <summary>
/// Function to append result to a list of results and update start/end dates
/// </summary>
public virtual void Append(MeterTestResult meterTestResult)
{
/// TODO
}
public override string ToString()
{
+41 -1
View File
@@ -1,8 +1,9 @@
///
/// Copyright (c) 2015 Sensus Metering Systems
/// Copyright (c) 2016 Sensus Metering Systems
///
using System;
using System.Collections.Generic;
using System.Linq;
namespace Results.Entities
{
@@ -27,5 +28,44 @@ namespace Results.Entities
public WaterMeterData()
{
}
/// <summary>
/// Method to compare the content of two entities
/// </summary>
/// <param name="wmd">Second entity to compare with</param>
/// <returns>first = two entities are equal (except of Id)</returns>
public virtual bool Equals(WaterMeterData wmd)
{
if (!ProductName.Equals(wmd.ProductName)) return false;
if (!Producer.Equals(wmd.Producer)) return false;
if (!MetrologicalClass.Equals(wmd.MetrologicalClass)) return false;
if (!ApprovalInfo.Equals(wmd.ApprovalInfo)) return false;
if (Q4_Qmax != wmd.Q4_Qmax) return false;
if (Qn != wmd.Qn) return false;
if (Q3 != wmd.Q3) return false;
if (Q2_Qt != wmd.Q2_Qt) return false;
if (Q1_Qmin != wmd.Q1_Qmin) return false;
if (Compound != wmd.Compound) return false;
return true;
}
/// <summary>
/// Adds an item to the list if it does not occur there
/// </summary>
/// <param name="list">List of items</param>
/// <param name="item">Item to add to the list or find there</param>
/// <returns>Item from the list (existing or added)</returns>
public static WaterMeterData UpdateList(IList<WaterMeterData> list, WaterMeterData item)
{
WaterMeterData found = list.FirstOrDefault<WaterMeterData>(x => x.Equals(item));
if (found != null) return found;
list.Add(item);
return item;
}
}
}
+1 -1
View File
@@ -11,8 +11,8 @@ namespace Results.Mappings
public BatchMap()
{
Id(x => x.Id);
Map(x => x.BenchId);
Map(x => x.BatchNr);
Map(x => x.TestBenchId);
Map(x => x.ProgramVersion);
Map(x => x.UserName);
Map(x => x.ProcedureName);
+2 -2
View File
@@ -11,8 +11,8 @@ namespace Results.Mappings
public ComponentsMap()
{
Id(x => x.Id);
Map(x => x.BenchId);
Map(x => x.BenchName);
Map(x => x.TestBenchId);
Map(x => x.TestBenchName);
Map(x => x.Pump);
Map(x => x.RegValve);
Map(x => x.Flowmeter);
+1
View File
@@ -22,6 +22,7 @@ namespace Results.Mappings
Map(x => x.TimestampEnd);
Map(x => x.TestTime);
Map(x => x.Error);
Map(x => x.TestDone);
Map(x => x.Passed);
References(x => x.WaterMeter);
+1
View File
@@ -23,6 +23,7 @@ namespace Results.Mappings
Map(x => x.SerialNrEx);
Map(x => x.OrigCalibFactor);
Map(x => x.CalibFactor);
Map(x =? x.Q2CorrectionDone);
Map(x => x.Q2Correction);
#endif
References(x => x.WaterMeterData);
+1 -1
View File
@@ -56,7 +56,7 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="Data.cs" />
<Compile Include="BatchResults.cs" />
<Compile Include="Entities\Batch.cs" />
<Compile Include="Entities\Components.cs" />
<Compile Include="Entities\MeterTestRslt.cs" />