diff --git a/Results/DB.cs b/Results/DB.cs
new file mode 100644
index 000000000..eb33d1bb7
--- /dev/null
+++ b/Results/DB.cs
@@ -0,0 +1,167 @@
+///
+/// Copyright (c) 2013-2015 Sensus Metering Systems
+///
+using System;
+using FluentNHibernate.Cfg;
+using FluentNHibernate.Cfg.Db;
+using NHibernate;
+using NHibernate.Cfg;
+using NHibernate.Tool.hbm2ddl;
+
+namespace Results
+{
+ ///
+ /// Identifies the type of a database
+ ///
+ public enum DBType
+ {
+ SQLite, /// SQLite
+ MySql, /// MySQL database
+ DbTypesCount,
+ }
+
+
+ public static class DB
+ {
+ /// Session factory for all regular sessions, not for CreateEmptyResultsDB().
+ public static ISessionFactory SessionFactory;
+
+ /// Connection string for all sessions
+ private static string connectionString;
+ ///
+ public static string ConnectionString
+ {
+ get { return connectionString; }
+ set
+ {
+ connectionString = value;
+ SessionFactory = null;
+ }
+ }
+
+ ///
+ /// NHibernate session factory (to create the database session 'SessionFactory')
+ ///
+ /// A database session
+ static ISessionFactory CreateSessionFactory(DBType dbType)
+ {
+ return CreateSessionFactory(dbType, false);
+ }
+
+ ///
+ /// NHibernate session factory (to create the database session 'SessionFactory')
+ ///
+ /// A database session
+ public static ISessionFactory CreateSessionFactory(DBType dbType, bool createDB)
+ {
+ FluentConfiguration cfg = Fluently.Configure();
+
+ switch (dbType)
+ {
+ default:
+ case DBType.SQLite:
+ cfg = cfg.Database(SQLiteConfiguration.Standard.UsingFile(connectionString));
+ break;
+ case DBType.MySql:
+ cfg = cfg.Database(MySQLConfiguration.Standard.ConnectionString(connectionString));
+ break;
+ }
+
+ cfg = cfg.Mappings(m => m.FluentMappings.AddFromAssemblyOf());
+
+ if (createDB)
+ {
+ return cfg.ExposeConfiguration(BuildSchemaCreate).BuildSessionFactory();
+ }
+ else
+ {
+ return cfg.ExposeConfiguration(BuildSchema).BuildSessionFactory();
+ }
+ }
+
+ public delegate void BuildSchemaDlgt(Configuration config);
+
+ static void BuildSchema(Configuration config)
+ {
+ /// This NHibernate tool takes a configuration (with mapping info in)
+ /// and exports a database schema from it
+ new SchemaExport(config).SetOutputFile("db_schema");
+ }
+
+ static void BuildSchemaCreate(Configuration config)
+ {
+ /// This NHibernate tool takes a configuration (with mapping info in)
+ /// and exports a database schema from it
+ new SchemaExport(config).Create(true, true);
+ }
+
+ /// Create a NHibernate session for the given database
+ public static ISession CreateSession()
+ {
+ if (string.IsNullOrEmpty(connectionString))
+ {
+ throw new Exception("Connection string was not specified");
+ }
+
+ if (SessionFactory == null)
+ {
+ SessionFactory = CreateSessionFactory(DBType.MySql);
+ }
+
+ return SessionFactory.OpenSession();
+ }
+
+ public static void SaveObject(object obj)
+ {
+ SaveObject(CreateSession(), obj);
+ }
+
+ public static void SaveObject(ISession session, object obj)
+ {
+ using (var transaction = session.BeginTransaction())
+ {
+ session.SaveOrUpdate(obj);
+ try { transaction.Commit(); }
+ catch { }
+ }
+ }
+
+ public static void DeleteObject(object obj)
+ {
+ DeleteObject(CreateSession(), obj);
+ }
+
+ public static void DeleteObject(ISession session, object obj)
+ {
+ using (var transaction = session.BeginTransaction())
+ {
+ session.Delete(obj);
+ transaction.Commit();
+ }
+ }
+
+ ///
+ /// Create an empty users database.
+ /// Database contains only the user 'admin' and the control board component 'CB'.
+ ///
+ /// DBType.SQLite or DBType.MySql
+ /// Connection string
+ /// true=success, false=error
+ public static bool CreateEmptyResultsDB(DBType dbType)
+ {
+ ISessionFactory sessionFactory = CreateSessionFactory(dbType, true);
+ if (sessionFactory == null) return false;
+
+ /// Populate the database
+ using (var session = sessionFactory.OpenSession())
+ {
+ using (var transaction = session.BeginTransaction())
+ {
+ transaction.Commit();
+ }
+ }
+
+ return true;
+ }
+ }
+}
diff --git a/Results/Class1.cs b/Results/DataDeposit.cs
similarity index 81%
rename from Results/Class1.cs
rename to Results/DataDeposit.cs
index 0d6c6312b..a24660188 100644
--- a/Results/Class1.cs
+++ b/Results/DataDeposit.cs
@@ -5,7 +5,7 @@ using System.Text;
namespace Results
{
- public class Class1
+ public class DataDeposit
{
}
}
diff --git a/Results/Entities/Batch.cs b/Results/Entities/Batch.cs
new file mode 100644
index 000000000..231c928bc
--- /dev/null
+++ b/Results/Entities/Batch.cs
@@ -0,0 +1,29 @@
+///
+/// Copyright (c) 2015 Sensus Metering Systems
+///
+using System;
+using System.Collections.Generic;
+
+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 string ProcedureName { get; set; }
+ public virtual int ProcedureRevision { get; set; }
+ public virtual DateTime StartTime { get; set; }
+ public virtual DateTime EndTime { get; set; }
+ public virtual IList Tests { get; set; }
+ public virtual IList WaterMeters { get; set; }
+ public virtual IList TestRslts { get; set; }
+
+ public Batch()
+ {
+ Tests = new List();
+ WaterMeters = new List();
+ TestRslts = new List();
+ }
+ }
+}
diff --git a/Results/Entities/MeterTestRslt.cs b/Results/Entities/MeterTestRslt.cs
new file mode 100644
index 000000000..548055875
--- /dev/null
+++ b/Results/Entities/MeterTestRslt.cs
@@ -0,0 +1,63 @@
+///
+/// Copyright (c) 2013-2015 Sensus Metering Systems
+///
+using System;
+
+namespace Results.Entities
+{
+ public class MeterTestRslt
+ {
+ public virtual int Id { get; protected set; }
+
+ public virtual double PulsesMeter { get; set; } /// # of pulses
+ public virtual double PulsesMaster { get; set; }
+ public virtual double VolumeStart { get; set; } /// liter
+ public virtual double VolumeEnd { get; set; } /// liter
+ public virtual double VolumeMeter { get; set; } /// liter
+ public virtual double VolumeRef { get; set; } /// liter
+ public virtual double TimestampStart { get; set; } /// sec.
+ 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 WaterMeter WaterMeter { get; set; } /// reference to the TestData entity
+ public virtual TestRslt TestRslt { get; set; } /// reference to the TestData entity
+
+ /// Wrappers
+ public string Name() { return TestRslt.Name(); }
+ public DateTime StartTime() { return TestRslt.StartTime; }
+ public DateTime EndTime() { return TestRslt.EndTime; }
+ public double FlowSetTime() { return TestRslt.FlowSetTime; }
+ public double FlowMass() { return TestRslt.FlowMass; }
+ public double FlowCTV() { return TestRslt.FlowCTV; }
+ public double FlowMin() { return TestRslt.FlowMin; }
+ public double FlowMax() { return TestRslt.FlowMax; }
+ public double ErrorMaster() { return TestRslt.ErrorMaster; }
+ ///
+ private TestData TestData() { return TestRslt.TestData; }
+ ///
+ public double Qfrom() { return TestData().Qfrom; }
+ public double Qto() { return TestData().Qto; }
+ public double TargetVolume() { return TestData().TargetVolume; }
+ public double TargetTime() { return TestData().TargetTime; }
+ public int Repeats() { return TestData().Repeats; }
+ public string Method() { return TestData().Method; }
+ public double ErrLimLo() { return TestData().ErrLimLo; }
+ public double ErrLimHi() { return TestData().ErrLimHi; }
+ public double Uncertainty() { return TestData().Uncertainty; }
+ public string Components() { return TestData().Components; }
+
+
+ private MeterTestRslt()
+ {
+ }
+
+ public MeterTestRslt(WaterMeter waterMeterRslt, TestRslt testRslt)
+ : this()
+ {
+ WaterMeter = waterMeterRslt;
+ TestRslt = testRslt;
+ }
+ }
+}
diff --git a/Results/Entities/TestData.cs b/Results/Entities/TestData.cs
new file mode 100644
index 000000000..3bb32e0eb
--- /dev/null
+++ b/Results/Entities/TestData.cs
@@ -0,0 +1,50 @@
+///
+/// Copyright (c) 2015 Sensus Metering Systems
+///
+using System;
+using System.Collections.Generic;
+
+namespace Results.Entities
+{
+ ///
+ /// Test, consisting of one or more repetitions of the test 'SingleTest'.
+ ///
+ public class TestData
+ {
+ public virtual int Id { get; protected set; }
+ public virtual string Name { get; set; }
+ public virtual double Qfrom { get; set; } /// [m3/h] flow range low limit
+ public virtual double Qto { get; set; } /// [m3/h] flow range high limit
+ public virtual double TargetVolume { get; set; } /// [l] target test volume
+ public virtual double TargetTime { get; set; } /// [s] target test time
+ public virtual int Repeats { get; set; }
+ public virtual string Method { get; set; }
+ public virtual double ErrLimLo { get; set; } /// [%] (usually < 0)
+ public virtual double ErrLimHi { get; set; } /// [%] (usually > 0)
+ public virtual double Uncertainty { get; set; } /// [%] makes error limits tighter: 0 <= Uncertainty <= abs(ErrLimXx)
+ public virtual string Components { get; set; } /// TODO: Representation of components
+
+
+ private TestData()
+ {
+ }
+
+ public TestData(Config.Entities.Test test, string components)
+ : this()
+ {
+ Name = test.Name;
+ Qfrom = (double)test.Qfrom;
+ Qto = (double)test.Qto;
+ TargetVolume = test.Volume;
+ TargetTime = (double)test.TstTime;
+ Repeats = test.Repeats;
+ Method = test.Method;
+ ErrLimLo = (double)test.ErrLimLo;
+ ErrLimHi = (double)test.ErrLimHi;
+ Uncertainty = (double)test.Uncertainty;
+
+ /// TODO:
+ Components = components;
+ }
+ }
+}
diff --git a/Results/Entities/TestRslt.cs b/Results/Entities/TestRslt.cs
new file mode 100644
index 000000000..d815b5dfe
--- /dev/null
+++ b/Results/Entities/TestRslt.cs
@@ -0,0 +1,107 @@
+///
+/// Copyright (c) 2015 Sensus Metering Systems
+///
+using System;
+using System.Collections.Generic;
+
+namespace Results.Entities
+{
+ public class TestRslt
+ {
+ /// Identity
+ public virtual int Id { get; protected set; }
+ public virtual Batch Batch { get; set; }
+ public virtual TestData TestData { get; set; }
+ public virtual int Part { get; set; }
+ public virtual int RepetitionNr { get; set; } /// Repetition number from the set of repeated tests (1...)
+
+ /// Results
+ public virtual DateTime StartTime { get; set; } /// Date and time of the test start
+ public virtual DateTime EndTime { get; set; } /// Date and time of the test end
+ public virtual double FlowSetTime { get; set; } /// [s] Measurement time in seconds
+ public virtual double TestTime { get; set; } /// [s] Measurement time in seconds
+ public virtual float AmbientTempAve { get; set; } /// [deg.C] Average ambient air temperature
+ public virtual float AmbientPressAve { get; set; } /// Average ambient air pressure
+ public virtual float AmbientHumiAve { get; set; } /// [%] Average ambient air relative humidity
+ public virtual float PressUpAvrg { get; set; } /// [Bar] Input water pressure (average)
+ public virtual float PressUpStart { get; set; } /// [Bar]
+ public virtual float PressUpEnd { get; set; } /// [Bar]
+ public virtual float PressUpMin { get; set; } /// [Bar]
+ public virtual float PressUpMax { get; set; } /// [Bar]
+ public virtual float PressDownAvrg { get; set; } /// [Bar]
+ public virtual float PressDownStart { get; set; } /// [Bar]
+ public virtual float PressDownEnd { get; set; } /// [Bar]
+ public virtual float PressDownMin { get; set; } /// [Bar]
+ public virtual float PressDownMax { get; set; } /// [Bar]
+ public virtual float TempInAvrg { get; set; } /// [deg.C]
+ public virtual float TempInStart { get; set; } /// [deg.C]
+ public virtual float TempInEnd { get; set; } /// [deg.C]
+ public virtual float TempInMin { get; set; } /// [deg.C]
+ public virtual float TempInMax { get; set; } /// [deg.C]
+ public virtual float TempOutAvrg { get; set; } /// [deg.C]
+ public virtual float TempOutStart { get; set; } /// [deg.C]
+ public virtual float TempOutEnd { get; set; } /// [deg.C]
+ public virtual float TempOutMin { get; set; } /// [deg.C]
+ public virtual float TempOutMax { get; set; } /// [deg.C]
+ public virtual float TempDivAvrg { get; set; } /// [deg.C]
+ public virtual float TempDivStart { get; set; } /// [deg.C]
+ public virtual float TempDivEnd { get; set; } /// [deg.C]
+ public virtual float TempDivMin { get; set; } /// [deg.C]
+ public virtual float TempDivMax { get; set; } /// [deg.C]
+ public virtual double MassStartRaw { get; set; } /// [kg]
+ public virtual double MassStart { get; set; } /// [kg]
+ public virtual double MassEndRaw { get; set; } /// [kg]
+ public virtual double MassEnd { get; set; } /// [kg]
+ public virtual double MassDiff { get; set; } /// [kg]
+ public virtual double DensityIn { get; set; } /// [kg/m3]
+ public virtual double DensityOut { get; set; } /// [kg/m3]
+ public virtual double DensityDiv { get; set; } /// [kg/m3]
+ public virtual double Buoyancy { get; set; }
+ public virtual double FlowMass { get; set; } /// [kg/h] calculated from conventional true value
+ public virtual double FlowCTV { get; set; } /// [l/h] calculated from conventional true value
+ public virtual double FlowMin { get; set; } /// [l/h] minimum flow
+ public virtual double FlowMax { get; set; } /// [l/h] maximum flow
+ public virtual double VolumeCTV { get; set; } /// [l] Volume conventional true value
+ public virtual double VolumeMaster { get; set; } /// [l] Volume from the master flow meter
+ public virtual double ErrorMaster { get; set; } /// [%]
+ public virtual double PulsesMaster { get; set; }
+ public virtual double ConstMaster { get; set; } /// [pls/l] Pulses per liter master flow meter
+
+
+ /// Wrappers
+ public string Name()
+ {
+ if (TestData.Repeats == 1) { return TestData.Name; }
+ else { return string.Format("{0} ({1}/{2})", TestData.Name, RepetitionNr, TestData.Repeats); }
+ }
+ public double Qfrom() { return TestData.Qfrom; }
+ public double Qto() { return TestData.Qto; }
+ public double TargetVolume() { return TestData.TargetVolume; }
+ public double TargetTime() { return TestData.TargetTime; }
+ public int Repeats() { return TestData.Repeats; }
+ public string Method() { return TestData.Method; }
+ public double ErrLimLo() { return TestData.ErrLimLo; }
+ public double ErrLimHi() { return TestData.ErrLimHi; }
+ public double Uncertainty() { return TestData.Uncertainty; }
+ public string Components() { return TestData.Components; }
+
+
+ public TestRslt()
+ {
+ }
+
+ public TestRslt(Batch batch, TestData testData, int part, int repetitionNr)
+ : this()
+ {
+ Batch = batch;
+ TestData = testData;
+ Part = part;
+ RepetitionNr = repetitionNr;
+ }
+
+ public override string ToString()
+ {
+ return string.Format("batch={0}, procedure={1}, test={2}, {3} {4}", Batch.BatchNr, Batch.ProcedureName, Name(), StartTime.ToShortDateString(), StartTime.ToShortTimeString());
+ }
+ }
+}
diff --git a/Results/Entities/WaterMeter.cs b/Results/Entities/WaterMeter.cs
new file mode 100644
index 000000000..d82f0dd70
--- /dev/null
+++ b/Results/Entities/WaterMeter.cs
@@ -0,0 +1,107 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using Config.Entities;
+
+namespace Results.Entities
+{
+ public class WaterMeter
+ {
+ public virtual int Id { get; protected set; }
+ public virtual string SerialNr { get; set; } /// PCB Number for iPerl water meter
+ public virtual string PurchaseOrder { get; set; }
+ public virtual string EndState { get; set; }
+ public virtual double QRise { get; set; } /// [l/h] detected Q_rise of a composed meter
+ public virtual double QFall { get; set; } /// [l/h] detected Q_fall of a composed meter
+ public virtual int YearOfProduction { get; set; }
+ public virtual bool Passed { get; set; }
+#if IPERLST
+ public virtual int SerialNrEx { get; set; } /// iPerl : This is the serial number assigned later
+ public virtual double CalibFactor { get; set; } /// iPerl calibration factor used during the test - Not mapped to DB !!!
+ public virtual double Q2Correction { get; set; } /// iPerl Q2 correction used during the test - Not mapped to DB !!!
+#endif
+
+ public virtual WaterMeterData WaterMeterData { get; set; }
+ public virtual Batch Batch { get; set; }
+ public virtual IList MeterTestRslts { get; set; }
+
+ ///
+ /// Wrappers
+ ///
+ public string ProductName() { return WaterMeterData.ProductName; }
+ public string Producer() { return WaterMeterData.Producer; }
+ public string MetrologicalClass() { return WaterMeterData.MetrologicalClass; }
+ public string ApprovalInfo() { return WaterMeterData.ApprovalInfo; }
+ public double Q4_Qmax() { return WaterMeterData.Q4_Qmax; }
+ public double Qn() { return WaterMeterData.Qn; }
+ public double Q3() { return WaterMeterData.Q3; }
+ public double Q2_Qt() { return WaterMeterData.Q2_Qt; }
+ public double Q1_Qmin() { return WaterMeterData.Q1_Qmin; }
+ public bool Compound() { return WaterMeterData.Compound; }
+
+ public int BatchNr() { return Batch.BatchNr; }
+ public int BenchId() { return Batch.BenchId; }
+ public string ProcedureName() { return Batch.ProcedureName; }
+ public int ProcedureRevision() { return Batch.ProcedureRevision; }
+ public DateTime StartTime() { return Batch.StartTime; }
+ public DateTime EndTime() { return Batch.EndTime; }
+
+ public MeterTestRslt MeterTestRslt(string testName)
+ {
+ foreach (var tr in MeterTestRslts)
+ {
+ if (tr.Name().ToLower().Equals(testName.ToLower())) return tr;
+ }
+ return null;
+ }
+
+ public TestRslt TestRslt(string testName)
+ {
+ MeterTestRslt mtr = MeterTestRslt(testName);
+ if (mtr != null) return mtr.TestRslt;
+ return null;
+ }
+
+
+ ///
+ /// Private constructor, initializes a list, used as a base
+ ///
+ private WaterMeter()
+ {
+ MeterTestRslts = new List();
+ }
+
+ ///
+ /// Constructor used to construct WaterMeterResults from the first meter test result
+ ///
+ public WaterMeter(MeterTestResult meterTestResult, int benchId)
+ : this()
+ {
+ /// TODO
+ }
+
+ ///
+ /// Function to append result to a list of results and update start/end dates
+ ///
+ public void Append(MeterTestResult meterTestResult)
+ {
+ /// TODO
+ }
+
+
+ public override string ToString()
+ {
+ StringBuilder sb = new StringBuilder(80);
+#if IPERLST
+ sb.AppendFormat("PCB:{0} S/N:{1} ", SerialNr, SerialNrEx);
+#else
+ sb.AppendFormat("S/N:{0} ", SerialNr);
+#endif
+
+ foreach (var tr in MeterTestRslts) sb.AppendFormat(" {0}:{1}%", tr.Name(), tr.Error.ToString("F1"));
+ sb.AppendFormat(" test start: {0} {1} batch={2}", StartTime().ToShortDateString(), StartTime().ToShortTimeString(), BatchNr());
+ return sb.ToString();
+ }
+ }
+}
diff --git a/Results/Entities/WaterMeterData.cs b/Results/Entities/WaterMeterData.cs
new file mode 100644
index 000000000..43b2a4dc1
--- /dev/null
+++ b/Results/Entities/WaterMeterData.cs
@@ -0,0 +1,27 @@
+///
+/// Copyright (c) 2015 Sensus Metering Systems
+///
+using System;
+using System.Collections.Generic;
+
+namespace Results.Entities
+{
+ public class WaterMeterData
+ {
+ public virtual int Id { get; protected set; }
+ public virtual string ProductName { get; set; }
+ public virtual string Producer { get; set; }
+ public virtual string MetrologicalClass { get; set; }
+ public virtual string ApprovalInfo { get; set; }
+ public virtual double Q4_Qmax { get; set; } /// [m3/h]
+ public virtual double Qn { get; set; } /// [m3/h]
+ public virtual double Q3 { get; set; } /// [m3/h]
+ public virtual double Q2_Qt { get; set; } /// [m3/h]
+ public virtual double Q1_Qmin { get; set; } /// [m3/h]
+ public bool Compound { get; set; }
+
+ public WaterMeterData()
+ {
+ }
+ }
+}
diff --git a/Results/Entities/WaterMeterResult.cs b/Results/Entities/WaterMeterResult.cs
deleted file mode 100644
index 6940e4daa..000000000
--- a/Results/Entities/WaterMeterResult.cs
+++ /dev/null
@@ -1,113 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using Config.Entities;
-
-namespace Results.Entities
-{
- public class WaterMeterResult
- {
- /// Set only once, used as a reference in some getters
- private readonly MeterTestResult firstMeterTestResult;
-
- ///
- /// Hard water meter data
- ///
- public string SerialNr; /// iPerl : This is PCB Number
- public int SerialNrEx; /// iPerl : This is the serial number assigned later
- public int BenchId;
- public int BatchNr { get { return firstMeterTestResult.TestResult.BatchNr; } }
- public string ProcedureName { get { return firstMeterTestResult.TestResult.ProcedureName; } }
- public DateTime TestStart;
- public DateTime TestEnd;
- public IList MeterTestResults;
-
- ///
- /// Soft water meter data
- ///
- public string Type;
- public string TypeApproval;
- public string MetrologicalClass;
- public string ProtocolTitle { get { return firstMeterTestResult.TestResult.ProtocolTitle; } }
- public string PurchaseOrder;
-
-
- public TestResult TestResult(string testName)
- {
- foreach (var tr in MeterTestResults)
- {
- if (tr.TestResult.TestName.ToLower().Equals(testName.ToLower())) return tr.TestResult;
- }
- return null;
- }
-
- public MeterTestResult MeterTestResult(string testName)
- {
- foreach (var tr in MeterTestResults)
- {
- if (tr.TestResult.TestName.ToLower().Equals(testName.ToLower())) return tr;
- }
- return null;
- }
-
-
- ///
- /// Private constructor, initializes a list, used as a base
- ///
- private WaterMeterResult()
- {
- MeterTestResults = new List();
- }
-
- ///
- /// Constructor used to construct WaterMeterResults from the first meter test result
- ///
- public WaterMeterResult(MeterTestResult meterTestResult, int benchId)
- : this()
- {
- if (meterTestResult == null) throw new Exception("meterTestResult cannot be null");
- MeterTestResults.Add(firstMeterTestResult = meterTestResult);
-
- SerialNr = meterTestResult.SerialNr;
- BenchId = (benchId == 5) ? 20033 : ((benchId == 6) ? 20034 : 0);
- TestStart = meterTestResult.TestResult.TimeStart;
- TestEnd = meterTestResult.TestResult.TimeEnd;
- }
-
- ///
- /// Function to append result to a list of results and update start/end dates
- ///
- public void Append(MeterTestResult meterTestResult)
- {
- MeterTestResults.Add(meterTestResult);
- if (meterTestResult.TestResult.TimeStart < TestStart) TestStart = meterTestResult.TestResult.TimeStart;
- if (meterTestResult.TestResult.TimeEnd > TestEnd) TestEnd = meterTestResult.TestResult.TimeEnd;
- }
-
- ///
- /// Returns 'tests passed' information based on so far appended results
- ///
- public bool Passed()
- {
- bool passed = true;
- foreach (var tr in MeterTestResults)
- {
- if (tr.TestResult.DoNotEvaluate) continue;
- if (tr.VolumeErrorPct < tr.TestResult.ErrLimLo || tr.VolumeErrorPct > tr.TestResult.ErrLimHi) passed = false;
- }
- return passed;
- }
-
-
- public override string ToString()
- {
- StringBuilder sb = new StringBuilder(80);
- sb.AppendFormat("PCB:{0} s/n:{1} ", SerialNr, SerialNrEx);
-
- foreach (var tr in MeterTestResults) sb.AppendFormat(" {0}:{1}%", tr.TestResult.TestName, tr.VolumeErrorPct.ToString("F1"));
- sb.AppendFormat(" test start: {0} {1} batch={2}", TestStart.ToShortDateString(), TestStart.ToShortTimeString(), BatchNr);
- return sb.ToString();
- }
- }
-}
diff --git a/Results/Mappings/BatchMap.cs b/Results/Mappings/BatchMap.cs
new file mode 100644
index 000000000..9147ca4d8
--- /dev/null
+++ b/Results/Mappings/BatchMap.cs
@@ -0,0 +1,28 @@
+///
+/// Copyright (c) 2015 Sensus Metering Systems
+///
+using FluentNHibernate.Mapping;
+using Results.Entities;
+
+namespace Results.Mappings
+{
+ class BatchMap : ClassMap
+ {
+ public BatchMap()
+ {
+ Id(x => x.Id);
+ Map(x => x.BenchId);
+ Map(x => x.BatchNr);
+ Map(x => x.ProcedureName);
+ Map(x => x.ProcedureRevision);
+ Map(x => x.StartTime);
+ Map(x => x.EndTime);
+ HasMany(x => x.Tests)
+ .Cascade.All();
+ HasMany(x => x.WaterMeters)
+ .Cascade.All();
+ HasMany(x => x.TestRslts)
+ .Cascade.All();
+ }
+ }
+}
diff --git a/Results/Mappings/MeterTestRsltMap.cs b/Results/Mappings/MeterTestRsltMap.cs
new file mode 100644
index 000000000..d9b819cb3
--- /dev/null
+++ b/Results/Mappings/MeterTestRsltMap.cs
@@ -0,0 +1,30 @@
+///
+/// Copyright (c) 2015 Sensus Metering Systems
+///
+using FluentNHibernate.Mapping;
+using Results.Entities;
+
+namespace Results.Mappings
+{
+ class MeterTestRsltMap : ClassMap
+ {
+ public MeterTestRsltMap()
+ {
+ Id(x => x.Id);
+ Map(x => x.PulsesMeter);
+ Map(x => x.PulsesMaster);
+ Map(x => x.VolumeStart);
+ Map(x => x.VolumeEnd);
+ Map(x => x.VolumeMeter);
+ Map(x => x.VolumeRef);
+ Map(x => x.TimestampStart);
+ Map(x => x.TimestampEnd);
+ Map(x => x.TestTime);
+ Map(x => x.Error);
+ Map(x => x.Passed);
+
+ References(x => x.WaterMeter);
+ References(x => x.TestRslt);
+ }
+ }
+}
diff --git a/Results/Mappings/TestDataMap.cs b/Results/Mappings/TestDataMap.cs
new file mode 100644
index 000000000..b114ec9e7
--- /dev/null
+++ b/Results/Mappings/TestDataMap.cs
@@ -0,0 +1,27 @@
+///
+/// Copyright (c) 2015 Sensus Metering Systems
+///
+using FluentNHibernate.Mapping;
+using Results.Entities;
+
+namespace Results.Mappings
+{
+ class TestDataMap : ClassMap
+ {
+ public TestDataMap()
+ {
+ Id(x => x.Id);
+ Map(x => x.Name);
+ Map(x => x.Qfrom);
+ Map(x => x.Qto);
+ Map(x => x.TargetVolume);
+ Map(x => x.TargetTime);
+ Map(x => x.Repeats);
+ Map(x => x.Method);
+ Map(x => x.ErrLimLo);
+ Map(x => x.ErrLimHi);
+ Map(x => x.Uncertainty);
+ Map(x => x.Components);
+ }
+ }
+}
diff --git a/Results/Mappings/TestRsltMap.cs b/Results/Mappings/TestRsltMap.cs
new file mode 100644
index 000000000..36241044f
--- /dev/null
+++ b/Results/Mappings/TestRsltMap.cs
@@ -0,0 +1,70 @@
+///
+/// Copyright (c) 2015 Sensus Metering Systems
+///
+using FluentNHibernate.Mapping;
+using Results.Entities;
+
+namespace Results.Mappings
+{
+ class TestRsltMap : ClassMap
+ {
+ public TestRsltMap()
+ {
+ Id(x => x.Id);
+ References(x => x.Batch);
+ References(x => x.TestData);
+ Map(x => x.Part);
+ Map(x => x.RepetitionNr);
+ Map(x => x.StartTime);
+ Map(x => x.EndTime);
+ Map(x => x.FlowSetTime);
+ Map(x => x.TestTime);
+ Map(x => x.AmbientTempAve);
+ Map(x => x.AmbientPressAve);
+ Map(x => x.AmbientHumiAve);
+ Map(x => x.PressUpAvrg);
+ Map(x => x.PressUpStart);
+ Map(x => x.PressUpEnd);
+ Map(x => x.PressUpMin);
+ Map(x => x.PressUpMax);
+ Map(x => x.PressDownAvrg);
+ Map(x => x.PressDownStart);
+ Map(x => x.PressDownEnd);
+ Map(x => x.PressDownMin);
+ Map(x => x.PressDownMax);
+ Map(x => x.TempInAvrg);
+ Map(x => x.TempInStart);
+ Map(x => x.TempInEnd);
+ Map(x => x.TempInMin);
+ Map(x => x.TempInMax);
+ Map(x => x.TempOutAvrg);
+ Map(x => x.TempOutStart);
+ Map(x => x.TempOutEnd);
+ Map(x => x.TempOutMin);
+ Map(x => x.TempOutMax);
+ Map(x => x.TempDivAvrg);
+ Map(x => x.TempDivStart);
+ Map(x => x.TempDivEnd);
+ Map(x => x.TempDivMin);
+ Map(x => x.TempDivMax);
+ Map(x => x.MassStartRaw);
+ Map(x => x.MassStart);
+ Map(x => x.MassEndRaw);
+ Map(x => x.MassEnd);
+ Map(x => x.MassDiff);
+ Map(x => x.DensityIn);
+ Map(x => x.DensityOut);
+ Map(x => x.DensityDiv);
+ Map(x => x.Buoyancy);
+ Map(x => x.FlowMass);
+ Map(x => x.FlowCTV);
+ Map(x => x.FlowMin);
+ Map(x => x.FlowMax);
+ Map(x => x.VolumeCTV);
+ Map(x => x.VolumeMaster);
+ Map(x => x.ErrorMaster);
+ Map(x => x.PulsesMaster);
+ Map(x => x.ConstMaster);
+ }
+ }
+}
diff --git a/Results/Mappings/WaterMeterDataMap.cs b/Results/Mappings/WaterMeterDataMap.cs
new file mode 100644
index 000000000..b3b4fcc60
--- /dev/null
+++ b/Results/Mappings/WaterMeterDataMap.cs
@@ -0,0 +1,26 @@
+///
+/// Copyright (c) 2015 Sensus Metering Systems
+///
+using FluentNHibernate.Mapping;
+using Results.Entities;
+
+namespace Results.Mappings
+{
+ class WaterMeterDataMap : ClassMap
+ {
+ public WaterMeterDataMap()
+ {
+ Id(x => x.Id);
+ Map(x => x.ProductName);
+ Map(x => x.Producer);
+ Map(x => x.MetrologicalClass);
+ Map(x => x.ApprovalInfo);
+ Map(x => x.Q4_Qmax);
+ Map(x => x.Qn);
+ Map(x => x.Q3);
+ Map(x => x.Q2_Qt);
+ Map(x => x.Q1_Qmin);
+ Map(x => x.Compound);
+ }
+ }
+}
diff --git a/Results/Mappings/WaterMeterMap.cs b/Results/Mappings/WaterMeterMap.cs
new file mode 100644
index 000000000..79eca72b9
--- /dev/null
+++ b/Results/Mappings/WaterMeterMap.cs
@@ -0,0 +1,31 @@
+///
+/// Copyright (c) 2015 Sensus Metering Systems
+///
+using FluentNHibernate.Mapping;
+using Results.Entities;
+
+namespace Results.Mappings
+{
+ class WaterMeterMap : ClassMap
+ {
+ public WaterMeterMap()
+ {
+ Id(x => x.Id);
+ Map(x => x.SerialNr);
+ Map(x => x.PurchaseOrder);
+ Map(x => x.EndState);
+ Map(x => x.QRise);
+ Map(x => x.QFall);
+ Map(x => x.Passed);
+#if IPERLST
+ Map(x => x.SerialNrEx);
+ Map(x => x.CalibFactor);
+ Map(x => x.Q2Correction);
+#endif
+ References(x => x.WaterMeterData);
+ References(x => x.Batch);
+ HasMany(x => x.MeterTestRslts)
+ .Cascade.All();
+ }
+ }
+}
diff --git a/Results/Results.csproj b/Results/Results.csproj
index 75aad9438..898c778af 100644
--- a/Results/Results.csproj
+++ b/Results/Results.csproj
@@ -53,8 +53,20 @@
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -65,7 +77,6 @@
-
diff --git a/ResultsBrowser/DataDeposit.cs b/ResultsBrowser/DataDeposit.cs
index 2148cd963..d7c83ca59 100644
--- a/ResultsBrowser/DataDeposit.cs
+++ b/ResultsBrowser/DataDeposit.cs
@@ -13,10 +13,10 @@ namespace ResultsBrowser
public static class DataDeposit
{
public static IList ReportTestResults;
- public static IList ReportWaterMeterResults;
+ public static IList ReportWaterMeterResults;
public static IList QueryTestResults;
- public static IList QueryWaterMeterResults;
+ public static IList QueryWaterMeterResults;
static DataDeposit()
{
@@ -26,10 +26,10 @@ namespace ResultsBrowser
public static void Clear()
{
ReportTestResults = new List();
- ReportWaterMeterResults = new List();
+ ReportWaterMeterResults = new List();
QueryTestResults = new List();
- QueryWaterMeterResults = new List();
+ QueryWaterMeterResults = new List();
}
public static void ProcessQueryTestResults(IList testResults, bool resolveManually)
@@ -60,7 +60,7 @@ namespace ResultsBrowser
///
foreach (var batchNr in batchNrs)
{
- IList wmResults = new List();
+ IList wmResults = new List();
bool waterMetersCreated = false;
foreach (var tr in selectedTestResults)
@@ -71,7 +71,7 @@ namespace ResultsBrowser
{
if (!waterMetersCreated)
{
- foreach (var mtr in tr.Meters) wmResults.Add(new Results.Entities.WaterMeterResult(mtr, 5));
+ foreach (var mtr in tr.Meters) wmResults.Add(new Results.Entities.WaterMeter(mtr, 5));
waterMetersCreated = true;
}
else
@@ -88,7 +88,7 @@ namespace ResultsBrowser
/// Exclude 'failed' water meters
for (int i = wmResults.Count - 1; i >= 0; i--)
{
- if (string.IsNullOrEmpty(wmResults[i].SerialNr) || !wmResults[i].Passed())
+ if (string.IsNullOrEmpty(wmResults[i].SerialNr) || !wmResults[i].Passed)
{
wmResults.RemoveAt(i);
}
@@ -101,12 +101,12 @@ namespace ResultsBrowser
foreach (var tr in selectedTestResults) QueryTestResults.Add(tr);
}
- public static int AddWMResultsAvoidDuplicates(IList wmResults, bool resolveManually)
+ public static int AddWMResultsAvoidDuplicates(IList wmResults, bool resolveManually)
{
int added = 0;
foreach (var wmr in wmResults)
{
- Results.Entities.WaterMeterResult foundWM = null;
+ Results.Entities.WaterMeter foundWM = null;
foreach (var wm in QueryWaterMeterResults)
{
diff --git a/ResultsBrowser/MainWnd.cs b/ResultsBrowser/MainWnd.cs
index 49b40788f..464bf3456 100644
--- a/ResultsBrowser/MainWnd.cs
+++ b/ResultsBrowser/MainWnd.cs
@@ -298,6 +298,7 @@ namespace ResultsBrowser
private void addOracleDataButton_Click(object sender, EventArgs e)
{
+#if IPERLST
if (DataDeposit.ReportWaterMeterResults.Count == 0) return;
const int Step = 100;
@@ -311,7 +312,7 @@ namespace ResultsBrowser
for (int j = i; j < Math.Min(j + Step, DataDeposit.ReportWaterMeterResults.Count); j++)
{
- Results.Entities.WaterMeterResult wm = DataDeposit.ReportWaterMeterResults[j];
+ Results.Entities.WaterMeter wm = DataDeposit.ReportWaterMeterResults[j];
IList serialNrExes = new List();
{
@@ -343,6 +344,7 @@ namespace ResultsBrowser
}
RedrawLists();
+#endif
}
private void makeAscFileButton_Click(object sender, EventArgs e)
@@ -364,9 +366,10 @@ namespace ResultsBrowser
{
foreach (var wm in DataDeposit.ReportWaterMeterResults)
{
- wm.Type = dlg.Type;
- wm.TypeApproval = dlg.TypeApproval;
- wm.MetrologicalClass = dlg.MetrologicalClass;
+ /// TODO: Rewrite
+ //wm.Type = dlg.Type;
+ //wm.ApprovalInfo() = dlg.TypeApproval;
+ //wm.MetrologicalClass = dlg.MetrologicalClass;
}
}
@@ -378,26 +381,30 @@ namespace ResultsBrowser
{
StringBuilder sb = new StringBuilder();
+#if IPERLST
sb.Append(wm.SerialNrEx);
- sb.Append(';'); sb.Append(wm.Type);
- sb.Append(';'); sb.Append(wm.TypeApproval);
- sb.Append(';'); sb.Append(wm.MetrologicalClass);
+#else
+ sb.Append(wm.SerialNr);
+#endif
+ sb.Append(';'); sb.Append(wm.ProductName());
+ sb.Append(';'); sb.Append(wm.ApprovalInfo());
+ sb.Append(';'); sb.Append(wm.MetrologicalClass());
sb.Append(';'); sb.Append("0");
- sb.Append(';'); sb.Append((1000 * (wm.TestResult("q1") != null ? wm.TestResult("q1").Qfrom : 0)).ToString("F0")); /// Q1 nominal
- sb.Append(';'); sb.Append((1000 * (wm.TestResult("q2") != null ? wm.TestResult("q2").Qfrom : 0)).ToString("F0")); /// Q2 nominal
- sb.Append(';'); sb.Append((1000 * (wm.TestResult("q3") != null ? wm.TestResult("q3").Qto : 0)).ToString("F0")); /// Q3 nominal
+ sb.Append(';'); sb.Append((1000 * (wm.TestRslt("q1") != null ? wm.TestRslt("q1").Qfrom() : 0)).ToString("F0")); /// Q1 nominal
+ sb.Append(';'); sb.Append((1000 * (wm.TestRslt("q2") != null ? wm.TestRslt("q2").Qfrom() : 0)).ToString("F0")); /// Q2 nominal
+ sb.Append(';'); sb.Append((1000 * (wm.TestRslt("q3") != null ? wm.TestRslt("q3").Qto() : 0)).ToString("F0")); /// Q3 nominal
sb.Append(';'); sb.Append("0"); /// Q4 nominal
sb.Append(';'); sb.Append("6"); /// Worker code
- sb.Append(';'); sb.Append(ToShortStr(wm.TestEnd));
- sb.Append(';'); sb.Append((wm.MeterTestResult("q1") != null ? wm.MeterTestResult("q1").VolumeErrorPct : 99).ToString("F1")); /// Q1 Error [%]
- sb.Append(';'); sb.Append((wm.MeterTestResult("q2") != null ? wm.MeterTestResult("q2").VolumeErrorPct : 99).ToString("F1")); /// Q2 Error [%]
- sb.Append(';'); sb.Append((wm.MeterTestResult("q3") != null ? wm.MeterTestResult("q3").VolumeErrorPct : 99).ToString("F1")); /// Q3 Error [%]
+ sb.Append(';'); sb.Append(ToShortStr(wm.EndTime()));
+ sb.Append(';'); sb.Append((wm.MeterTestRslt("q1") != null ? wm.MeterTestRslt("q1").Error : 99).ToString("F1")); /// Q1 Error [%]
+ sb.Append(';'); sb.Append((wm.MeterTestRslt("q2") != null ? wm.MeterTestRslt("q2").Error : 99).ToString("F1")); /// Q2 Error [%]
+ sb.Append(';'); sb.Append((wm.MeterTestRslt("q3") != null ? wm.MeterTestRslt("q3").Error : 99).ToString("F1")); /// Q3 Error [%]
sb.Append(';'); sb.Append("0"); /// Q4 Error [%]
- sb.Append(';'); sb.Append(wm.BenchId.ToString()); ///
+ sb.Append(';'); sb.Append(wm.BenchId().ToString()); ///
sb.Append(';'); sb.Append(wm.PurchaseOrder);
sb.Append(';'); sb.Append("");
sb.Append(';'); sb.Append("10000");
- sb.Append(';'); sb.Append(wm.ProcedureName.Substring(0, 8));
+ sb.Append(';'); sb.Append(wm.ProcedureName().Substring(0, 8));
sb.Append(";\""); sb.Append(wm.SerialNr); sb.Append('"');
report.WriteLine(sb);
@@ -439,16 +446,20 @@ namespace ResultsBrowser
{
StringBuilder sb = new StringBuilder();
+#if IPERLST
sb.Append(wm.SerialNrEx);
- sb.Append(";\""); sb.Append(wm.SerialNr); sb.Append('"'); /// PCB number
- sb.Append(";\""); sb.Append(wm.ProcedureName); sb.Append('"'); /// Procedure name
- sb.Append(';'); sb.Append((1000 * (wm.TestResult("q3") != null ? wm.TestResult("q3").Qto : 0)).ToString("F0")); /// Q3 nominal
- sb.Append(';'); sb.Append((wm.MeterTestResult("adjustment") != null ? wm.MeterTestResult("adjustment").VolumeErrorPct : 99).ToString("F2"));/// Adjustment Error [%]
- sb.Append(';'); sb.Append((wm.MeterTestResult("q3") != null ? wm.MeterTestResult("q1").VolumeErrorPct : 99).ToString("F2")); /// Q1 Error [%]
- sb.Append(';'); sb.Append((wm.MeterTestResult("q2") != null ? wm.MeterTestResult("q2").VolumeErrorPct : 99).ToString("F2")); /// Q2 Error [%]
- sb.Append(';'); sb.Append((wm.MeterTestResult("q1") != null ? wm.MeterTestResult("q3").VolumeErrorPct : 99).ToString("F2")); /// Q3 Error [%]
- sb.Append(';'); sb.Append(wm.TestStart.ToShortTimeString());
- sb.Append(';'); sb.Append(wm.TestEnd.ToShortTimeString());
+#else
+ sb.Append(wm.SerialNr);
+#endif
+ sb.Append(";\""); sb.Append(wm.SerialNr); sb.Append('"'); /// PCB number
+ sb.Append(";\""); sb.Append(wm.ProcedureName()); sb.Append('"'); /// Procedure name
+ sb.Append(';'); sb.Append((1000 * (wm.TestRslt("q3") != null ? wm.TestRslt("q3").Qto() : 0)).ToString("F0")); /// Q3 nominal
+ sb.Append(';'); sb.Append((wm.MeterTestRslt("adjustment") != null ? wm.MeterTestRslt("adjustment").Error : 99).ToString("F2"));/// Adjustment Error [%]
+ sb.Append(';'); sb.Append((wm.MeterTestRslt("q3") != null ? wm.MeterTestRslt("q1").Error : 99).ToString("F2")); /// Q1 Error [%]
+ sb.Append(';'); sb.Append((wm.MeterTestRslt("q2") != null ? wm.MeterTestRslt("q2").Error : 99).ToString("F2")); /// Q2 Error [%]
+ sb.Append(';'); sb.Append((wm.MeterTestRslt("q1") != null ? wm.MeterTestRslt("q3").Error : 99).ToString("F2")); /// Q3 Error [%]
+ sb.Append(';'); sb.Append(wm.StartTime().ToShortTimeString());
+ sb.Append(';'); sb.Append(wm.EndTime().ToShortTimeString());
report.WriteLine(sb);
}
diff --git a/ResultsBrowser/ResultsBrowser.csproj b/ResultsBrowser/ResultsBrowser.csproj
index ee5864895..188cd6683 100644
--- a/ResultsBrowser/ResultsBrowser.csproj
+++ b/ResultsBrowser/ResultsBrowser.csproj
@@ -182,6 +182,9 @@
Results
+
+
+