diff --git a/Results/BatchResults.cs b/Results/BatchResults.cs index b579e069e..794c05987 100644 --- a/Results/BatchResults.cs +++ b/Results/BatchResults.cs @@ -1,4 +1,7 @@ -using System; +/// +/// Copyright (c) 2021 Sensus Slovensko a.s. +/// +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -40,7 +43,7 @@ namespace Results public static BatchResults NewFromProcedure(int batchNr, int benchId, string benchName, string a1, string a2, string a3, string a4, string a5, string user, int userNr, string programVer, Config.Entities.Procedure procedure, - WaterMeterData[] waterMeterDatas, int[] waterMeterParts, double densityCorr) + WaterMeterData[] waterMeterDatas, int[] waterMeterParts, double realDensity, double atTemperature, double buoyancy) { BatchResults d = new BatchResults(waterMeterDatas.Length); int year = DateTime.Now.Year; @@ -65,8 +68,10 @@ namespace Results ProcedureRevision = procedure.Revision, ProtocolTitle = string.Empty, StartTime = DateTime.Now, - DensityCorr = (float)densityCorr, - Compound = (procedure.MetersKind == Config.Entities.MetersKind.Combined), + RealDensity = realDensity, + AtTemperature = atTemperature, + Buoyancy = buoyancy, + Compound = (procedure.MetersKind == Config.Entities.MetersKind.Combined), #if HEAT_METERS HeatMeter = (procedure.MetersKind == Config.Entities.MetersKind.HeatMeter), #endif @@ -156,10 +161,10 @@ namespace Results if (batch.WaterMeters[wmNr0].WMPosition > wmNr0 + 1) { batch.WaterMeters.Insert(wmNr0, new WaterMeter() { Batch = batch, - WaterMeterData = null, - WMPosition = wmNr0 + 1, - YearOfProduction = 0, - Disabled = true, }); + WaterMeterData = null, + WMPosition = wmNr0 + 1, + YearOfProduction = 0, + Disabled = true, }); } } diff --git a/Results/Entities/Batch.cs b/Results/Entities/Batch.cs index f7f8e00d3..0f56ae466 100644 --- a/Results/Entities/Batch.cs +++ b/Results/Entities/Batch.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2015-2020 Sensus Slovensko a.s. +/// Copyright (c) 2015-2021 Sensus Slovensko a.s. /// using System; using System.Collections.Generic; @@ -28,9 +28,9 @@ namespace Results.Entities public virtual string WatermetersStr { get; set; } /// CEVAK, not mapped to DB public virtual string ProtocolTitle { get; set; } public virtual string Remark { get; set; } - public virtual float DensityCorr { get; set; } /// Density correction in [kg/m3] - public virtual float Custom2 { get; set; } - public virtual float Custom3 { get; set; } + public virtual double RealDensity { get; set; } /// Density correction in [kg/m3] + public virtual double AtTemperature { get; set; } + public virtual double Buoyancy { get; set; } public virtual int Counter6 { get; set; } public virtual int Counter7 { get; set; } public virtual int Counter8 { get; set; } @@ -117,6 +117,9 @@ namespace Results.Entities ProtocolTitle = string.Empty; ProtocolTitle = string.Empty; Remark = string.Empty; + RealDensity = Config.Data.RealDensity; + AtTemperature = Config.Data.AtTemperature; + Buoyancy = Config.Data.Buoyancy; } public virtual int PassedMetersCount() @@ -263,24 +266,6 @@ namespace Results.Entities return 0; } - public virtual double Buoyancy() - { - double timeSum = 0; - double sum = 0; - - foreach (var tr in TestRslts) - { - if (tr.TestData.Evaluate && tr.TestDone) - { - double duration = (tr.EndTime - tr.StartTime).TotalSeconds; - timeSum += duration; - sum += (tr.Buoyancy * duration); - } - } - - return (timeSum == 0) ? 0 : (sum / timeSum); - } - public virtual TestRslt GetTestRslt(string name, int part) { foreach (var tr in TestRslts) @@ -297,10 +282,10 @@ namespace Results.Entities public virtual string ToString(int i) { - return string.Format("Batch: BatchNr={0} ProgramVersion={1} TestBenchId={2} UserName={3} UserNumber={4} ProcedureName={5}{6} ProcRev={7} ProtocolTitle={8} Remark={9} DensityCorr={10} Custom2={11} Custom3={12} StartTime={13} EndTime={14} Dirty={15} RsltsSent={16} RsltsPrinted={17}", + return string.Format("Batch: BatchNr={0} ProgramVersion={1} TestBenchId={2} UserName={3} UserNumber={4} ProcedureName={5}{6} ProcRev={7} ProtocolTitle={8} Remark={9} RealDensity={10} AtTemperature={11} Buoyancy={12} StartTime={13} EndTime={14} Dirty={15} RsltsSent={16} RsltsPrinted={17}", BatchNr, ProgramVersion, TestBenchId, UserName, UserNumber, ProcedureName, (IsRemoteProcedure ? "(R)" : ""), ProcedureRevision, - ProtocolTitle, Remark, DensityCorr, Custom2, Custom3, + ProtocolTitle, Remark, RealDensity, AtTemperature, Buoyancy, StartTime, EndTime, Dirty, RsltsSent, RsltsPrinted); } @@ -325,9 +310,9 @@ namespace Results.Entities writer.Write((WatermetersStr != null) ? WatermetersStr : string.Empty); writer.Write((ProtocolTitle != null) ? ProtocolTitle : string.Empty); writer.Write((Remark != null) ? Remark : string.Empty); - writer.Write(DensityCorr); - writer.Write(Custom2); - writer.Write(Custom3); + writer.Write(RealDensity); + writer.Write(AtTemperature); + writer.Write(Buoyancy); writer.Write(Counter6); writer.Write(Counter7); writer.Write(Counter8); @@ -392,9 +377,9 @@ namespace Results.Entities WatermetersStr = reader.ReadString(); ProtocolTitle = reader.ReadString(); Remark = reader.ReadString(); - DensityCorr = reader.ReadInt32(); - Custom2 = reader.ReadInt32(); - Custom3 = reader.ReadInt32(); + RealDensity = reader.ReadDouble(); + AtTemperature = reader.ReadDouble(); + Buoyancy = reader.ReadDouble(); Counter6 = reader.ReadInt32(); Counter7 = reader.ReadInt32(); Counter8 = reader.ReadInt32(); diff --git a/Results/Mappings/BatchMap.cs b/Results/Mappings/BatchMap.cs index 25845ed47..385861e16 100644 --- a/Results/Mappings/BatchMap.cs +++ b/Results/Mappings/BatchMap.cs @@ -1,5 +1,5 @@ /// -/// Copyright (c) 2019 Sensus Slovensko a.s. +/// Copyright (c) 2015-2021 Sensus Slovensko a.s. /// using FluentNHibernate.Mapping; using Results.Entities; @@ -22,10 +22,10 @@ namespace Results.Mappings Map(x => x.Remark) .CustomType("StringClob") .CustomSqlType("varchar(2000)"); - Map(x => x.DensityCorr) - .Column("Custom1"); ; - Map(x => x.Custom2); - Map(x => x.Custom3); + + Map(x => x.RealDensity).Column("Custom1"); + Map(x => x.AtTemperature).Column("Custom2"); + Map(x => x.Buoyancy).Column("Custom3"); Map(x => x.Counter6); Map(x => x.Counter7); diff --git a/Results/WMeterRsltItemSpec.cs b/Results/WMeterRsltItemSpec.cs index bc2da64f4..fc7656fcc 100644 --- a/Results/WMeterRsltItemSpec.cs +++ b/Results/WMeterRsltItemSpec.cs @@ -43,13 +43,6 @@ namespace Results return item2; } - - /// This is to show RealDensity and AtTemperatire in reports. - public static double RealDensity; /// true water density [kg/m3] - public static double AtTemperature; /// measured at temperature [°C] - public static double Buoyancy; - - /// /// Function to pick a MeterTestResult field and convert it into a string /// @@ -182,9 +175,9 @@ namespace Results /// Density /// AllItems.Add(new WMeterRsltItemSpec(ItemID.Density, Strings.Density + " ()", Quantity.Density, ItemCategory.TestResult, (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : FormatDbl(u, f, p, "V4", w.GetTestRslt(t).DensityLine))); - AllItems.Add(new WMeterRsltItemSpec(ItemID.Density_correction, Strings.Density_correction + " ()", Quantity.Density, ItemCategory.TestResult, (w, t, u, f, p) => FormatDbl(u, f, p, "V3", (w.Batch.DensityCorr)))); - AllItems.Add(new WMeterRsltItemSpec(ItemID.Rho_Wa_calc, string.Format("{0} of sample", Strings.Density), Quantity.Density, ItemCategory.TestResult, (w, t, u, f, p) => FormatDbl(u, f, p, "V4", RealDensity))); - AllItems.Add(new WMeterRsltItemSpec(ItemID.RhoDistilledWtrAtMeLineTemp, string.Format("{0} of distilled water at T line", Strings.Density), Quantity.Density, ItemCategory.TestResult, (w, t, u, f, p) => FormatDbl(u, f, p, "V4", (w.GetTestRslt(t) == null) ? 0 : Config.Formulas.DistilledWaterDensityFromTemp((w.GetTestRslt(t).TempUpMean + w.GetTestRslt(t).TempDownMean) / 2)))); + AllItems.Add(new WMeterRsltItemSpec(ItemID.Density_correction, Strings.Density_correction + " ()", Quantity.Density, ItemCategory.BenchData, (w, t, u, f, p) => FormatDbl(u, f, p, "V3", Config.Formulas.DensityCorrection(w.Batch.RealDensity, w.Batch.AtTemperature)))); + AllItems.Add(new WMeterRsltItemSpec(ItemID.Rho_Wa_calc, string.Format("{0} of sample", Strings.Density), Quantity.Density, ItemCategory.TestResult, (w, t, u, f, p) => FormatDbl(u, f, p, "V4", w.Batch.RealDensity))); + AllItems.Add(new WMeterRsltItemSpec(ItemID.RhoDistilledWtrAtMeLineTemp, string.Format("{0} of distilled water at T line", Strings.Density), Quantity.Density, ItemCategory.BenchData, (w, t, u, f, p) => FormatDbl(u, f, p, "V4", (w.GetTestRslt(t) == null) ? 0 : Config.Formulas.DistilledWaterDensityFromTemp((w.GetTestRslt(t).TempUpMean + w.GetTestRslt(t).TempDownMean) / 2)))); /// /// Date and time @@ -259,7 +252,7 @@ namespace Results AllItems.Add(new WMeterRsltItemSpec(ItemID.T_div_avg, string.Format("{0} DI avg ()", Strings.VName_Temp), Strings.Tooltip_T_di_avg, Quantity.Temperature, ItemCategory.TestResult, (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : FormatDbl(u, f, p, "V3", (w.GetTestRslt(t).TempDivStart + w.GetTestRslt(t).TempDivEnd) / 2))); AllItems.Add(new WMeterRsltItemSpec(ItemID.T_div_min, string.Format("{0} DI min ()", Strings.VName_Temp), Strings.Tooltip_T_di_min, Quantity.Temperature, ItemCategory.TestResult, (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : FormatDbl(u, f, p, "V3", w.GetTestRslt(t).TempDivMin))); AllItems.Add(new WMeterRsltItemSpec(ItemID.T_div_max, string.Format("{0} DI max ()", Strings.VName_Temp), Strings.Tooltip_T_di_max, Quantity.Temperature, ItemCategory.TestResult, (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : FormatDbl(u, f, p, "V3", w.GetTestRslt(t).TempDivMax))); - AllItems.Add(new WMeterRsltItemSpec(ItemID.T_rho_0, string.Format("{0} RO0", Strings.VName_Temp), Strings.Tooltip_T_rho_0, Quantity.Temperature, ItemCategory.TestResult, (w, t, u, f, p) => FormatDbl(u, f, p, "V3", AtTemperature))); + AllItems.Add(new WMeterRsltItemSpec(ItemID.T_rho_0, string.Format("{0} RO0", Strings.VName_Temp), Strings.Tooltip_T_rho_0, Quantity.Temperature, ItemCategory.BenchData, (w, t, u, f, p) => FormatDbl(u, f, p, "V3", w.Batch.AtTemperature))); #if HEAT_METERS AllItems.Add(new WMeterRsltItemSpec(ItemID.T_Hi_mean, string.Format("{0} hi me", Strings.VName_Temp), Quantity.Temperature, ItemCategory.Other, (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : FormatDbl(u, f, p, "F3", w.GetTestRslt(t).Custom1))); AllItems.Add(new WMeterRsltItemSpec(ItemID.T_Hi_start, string.Format("{0} hi st", Strings.VName_Temp), Quantity.Temperature, ItemCategory.Other, (w, t, u, f, p) => (w.GetTestRslt(t) == null) ? "" : FormatDbl(u, f, p, "F3", w.GetTestRslt(t).Custom2))); @@ -316,7 +309,7 @@ namespace Results AllItems.Add(new WMeterRsltItemSpec(ItemID.Amb_temp_start_end, string.Format("{0} Amb ST/EN", Strings.VName_Temp), Quantity.Temperature, ItemCategory.TestResult, (w, t, u, f, p) => FormatDbl(u, f, p, "V3", (w.GetTestRslt(t) == null) ? w.Batch.AmbTempStart() : w.GetTestRslt(t).AmbTempStart, (w.GetTestRslt(t) == null) ? w.Batch.AmbTempEnd() : w.GetTestRslt(t).AmbTempEnd))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Amb_press_start_end, string.Format("{0} Amb ST/EN", Strings.VName_Press), Quantity.Pressure, ItemCategory.TestResult, (w, t, u, f, p) => FormatDbl(u, f, p, "V4", (w.GetTestRslt(t) == null) ? w.Batch.AmbPressStart(): w.GetTestRslt(t).AmbPressStart, (w.GetTestRslt(t) == null) ? w.Batch.AmbPressEnd() : w.GetTestRslt(t).AmbPressEnd))); AllItems.Add(new WMeterRsltItemSpec(ItemID.Amb_humi_start_end, string.Format("{0} Amb ST/EN", Strings.VName_Humi), Quantity.Humidity, ItemCategory.TestResult, (w, t, u, f, p) => FormatDbl(u, f, p, "V2", (w.GetTestRslt(t) == null) ? w.Batch.AmbHumiStart() : w.GetTestRslt(t).AmbHumiStart, (w.GetTestRslt(t) == null) ? w.Batch.AmbHumiEnd() : w.GetTestRslt(t).AmbHumiEnd))); - AllItems.Add(new WMeterRsltItemSpec(ItemID.Buoyancy, "Buoyancy ()", Quantity.Number, ItemCategory.TestResult, (w, t, u, f, p) => string.IsNullOrEmpty(t) ? FormatDbl(u, f, p, "V6", w.Batch.Buoyancy()) : ((w.GetTestRslt(t) != null) ? FormatDbl(u, f, p, "V6", (w.GetTestRslt(t).Buoyancy)) : ""))); + AllItems.Add(new WMeterRsltItemSpec(ItemID.Buoyancy, "Buoyancy", Quantity.Number, ItemCategory.BenchData, (w, t, u, f, p) => FormatDbl(u, f, p, "V6", w.Batch.Buoyancy))); /// /// Error diff --git a/TBF/BenchControl/DataContainers/Buoyancy/Component.cs b/TBF/BenchControl/DataContainers/Buoyancy/Component.cs index d078b5512..af159a5d0 100644 --- a/TBF/BenchControl/DataContainers/Buoyancy/Component.cs +++ b/TBF/BenchControl/DataContainers/Buoyancy/Component.cs @@ -32,9 +32,6 @@ namespace TBF.BenchControl.DataContainers.Buoyancy /// This is to use data in formulas Config.Data.Buoyancy = Buoyancy; - /// This is to have data in reports - Results.WMeterRsltItemSpec.Buoyancy = Buoyancy; - log.Warn(this.ToString()); } diff --git a/TBF/BenchControl/DataContainers/Density/Component.cs b/TBF/BenchControl/DataContainers/Density/Component.cs index 7ca85423a..b3721b78e 100644 --- a/TBF/BenchControl/DataContainers/Density/Component.cs +++ b/TBF/BenchControl/DataContainers/Density/Component.cs @@ -34,10 +34,6 @@ namespace TBF.BenchControl.DataContainers.Density Config.Data.RealDensity = RealDensity; Config.Data.AtTemperature = AtTemperature; - /// This is to have data in reports - Results.WMeterRsltItemSpec.RealDensity = RealDensity; - Results.WMeterRsltItemSpec.AtTemperature = AtTemperature; - log.Warn(this.ToString()); } diff --git a/TBF/BenchControl/Sequences/MainSeqUtils.cs b/TBF/BenchControl/Sequences/MainSeqUtils.cs index 8da0b9a7d..39c10d36a 100644 --- a/TBF/BenchControl/Sequences/MainSeqUtils.cs +++ b/TBF/BenchControl/Sequences/MainSeqUtils.cs @@ -636,8 +636,9 @@ namespace TBF.BenchControl.Sequences StateMachine.Procedure, waterMeterData, waterMeterParts, - Config.Formulas.DensityCorrection(Config.Formulas.RealDensity(), - Config.Formulas.AtTemperature())); + Config.Formulas.RealDensity(), + Config.Formulas.AtTemperature(), + Config.Formulas.Buoyancy()); } /// diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgBuoyancyTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgBuoyancyTab.cs index 2727ac6e9..0e932cf73 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgBuoyancyTab.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgBuoyancyTab.cs @@ -84,8 +84,7 @@ namespace TBF.UI.Bench.Metrology { double buoyancy = Utils.ParseUDouble(buoyancyTextBox.Text); - Results.WMeterRsltItemSpec.Buoyancy = - Config.Data.Buoyancy = BuoyancyCfg.Buoyancy = buoyancy; + Config.Data.Buoyancy = BuoyancyCfg.Buoyancy = buoyancy; Component modified = BuoyancyCfg.CreateDbEntity(); MeterEntity.Parameters = modified.Parameters; diff --git a/TBF/UI/Bench/Metrology/MetrologyDlgDensityTab.cs b/TBF/UI/Bench/Metrology/MetrologyDlgDensityTab.cs index c49365c21..1e50d839d 100644 --- a/TBF/UI/Bench/Metrology/MetrologyDlgDensityTab.cs +++ b/TBF/UI/Bench/Metrology/MetrologyDlgDensityTab.cs @@ -113,11 +113,9 @@ namespace TBF.UI.Bench.Metrology double realDensity = Utils.ParseUDouble(densityTextBox.Text); double atTemperature = Utils.ParseUDouble(temperatureTextBox.Text); - Results.WMeterRsltItemSpec.RealDensity = - Config.Data.RealDensity = DensityCfg.RealDensity = realDensity; - - Results.WMeterRsltItemSpec.AtTemperature = - Config.Data.AtTemperature = DensityCfg.AtTemperature = atTemperature; + Config.Data.RealDensity = DensityCfg.RealDensity = realDensity; + Config.Data.AtTemperature = DensityCfg.AtTemperature = atTemperature; + DensityCfg.CalibCertificateNr = calibCertificateNrTextBox.Text; DensityCfg.CalibDate = calibDateTimePicker.Value.Date; DensityCfg.CalibValidDate = calibExpirationDateTimePicker.Value.Date;