Output.DB.SaveFlowmeterCorrections completed, ver. 2.18.818
This commit is contained in:
parent
bcc54ccd8f
commit
1a82625f39
@ -23,7 +23,6 @@ namespace TBF.BenchControl.Output.DB.SaveFlowmeterCorrections
|
||||
public override string ToString() { return string.Format("SaveFlowmeterCorr({0})", Cfg.ToString(1)); }
|
||||
|
||||
SaveFlowmeterCorrCfg myCfg;
|
||||
int rangeIx;
|
||||
|
||||
enum CurrentOp
|
||||
{
|
||||
@ -73,17 +72,18 @@ namespace TBF.BenchControl.Output.DB.SaveFlowmeterCorrections
|
||||
}
|
||||
|
||||
|
||||
IList<MeasurementCorrection> GetCorrections(Results.Entities.Batch batch, string flowmeter, int rangeIx)
|
||||
IList<MeasurementCorrection> GetCorrections(Results.Entities.Batch batch, string flowmeterName, int rngIx, double tempRngLo, double tempRngHi)
|
||||
{
|
||||
IList<MeasurementCorrection> rslt = new List<MeasurementCorrection>();
|
||||
|
||||
foreach (var tr in batch.TestRslts)
|
||||
{
|
||||
if (tr.Components.Flowmeter == flowmeter && tr.Evaluate())
|
||||
float testTempLimLo = tr.TempLimLo();
|
||||
float testTempLimHi = tr.TempLimHi();
|
||||
if (tr.Components.Flowmeter == flowmeterName && tr.Evaluate() && testTempLimLo >= tempRngLo && testTempLimHi <= tempRngHi)
|
||||
{
|
||||
float measurement = tr.FlowMean;
|
||||
float correction = (float)BenchControl.Formulas.CorrectionFromError(measurement, tr.ErrorMaster);
|
||||
rslt.Add(new MeasurementCorrection { RangeIx = rangeIx, Measurement = measurement, Correction = correction });
|
||||
double correction = BenchControl.Formulas.CorrectionFromError(tr.FlowMean, tr.ErrorMaster);
|
||||
rslt.Add(new MeasurementCorrection { RangeIx = rngIx, Measurement = tr.FlowMean, Correction = (float)correction });
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,17 +93,18 @@ namespace TBF.BenchControl.Output.DB.SaveFlowmeterCorrections
|
||||
|
||||
void DeleteExistingCorrections(ISession session, Component cmpnt, int rangeIx)
|
||||
{
|
||||
foreach (var mc in cmpnt.Corrections)
|
||||
for (int i = cmpnt.Corrections.Count - 1; i >= 0; i--)
|
||||
{
|
||||
if (mc.RangeIx == rangeIx)
|
||||
if (cmpnt.Corrections[i].RangeIx == rangeIx)
|
||||
{
|
||||
session.Delete(mc);
|
||||
cmpnt.Corrections.Remove(mc);
|
||||
session.Delete(cmpnt.Corrections[i]);
|
||||
cmpnt.Corrections.RemoveAt(i);
|
||||
}
|
||||
}
|
||||
session.SaveOrUpdate(cmpnt);
|
||||
}
|
||||
|
||||
|
||||
void SaveNewCorrections(ISession session, Component cmpnt, int rangeIx, IList<MeasurementCorrection> corrections)
|
||||
{
|
||||
if (cmpnt.Corrections == null) cmpnt.Corrections = new List<MeasurementCorrection>();
|
||||
@ -123,22 +124,13 @@ namespace TBF.BenchControl.Output.DB.SaveFlowmeterCorrections
|
||||
{
|
||||
opCompleted = false;
|
||||
anyError = false;
|
||||
|
||||
if (myCfg.Flowm1Rng1) rangeIx = 1;
|
||||
else if (myCfg.Flowm1Rng2) rangeIx = 2;
|
||||
else if (myCfg.Flowm1Rng3) rangeIx = 3;
|
||||
else if (myCfg.Flowm1Rng4) rangeIx = 4;
|
||||
else if (myCfg.Flowm1Rng5) rangeIx = 5;
|
||||
else rangeIx = 0;
|
||||
|
||||
newCorrections = GetCorrections(batch, myCfg.Flowmeter1, rangeIx);
|
||||
}
|
||||
|
||||
/// <summary>Run this operation</summary>
|
||||
/// <returns>Event.ResultsWritten or Event.Error</returns>
|
||||
public Event Run()
|
||||
{
|
||||
if (myCfg.DebugLevel == DebugMode.Simulate || newCorrections == null || newCorrections.Count == 0)
|
||||
if (myCfg.DebugLevel == DebugMode.Simulate)
|
||||
{
|
||||
opCompleted = true;
|
||||
return Event.ResultsWritten;
|
||||
@ -154,28 +146,49 @@ namespace TBF.BenchControl.Output.DB.SaveFlowmeterCorrections
|
||||
ISession session = Config.FluentCommon.CreateSession(Users.Entities.DBKind.Config);
|
||||
transaction = session.BeginTransaction();
|
||||
|
||||
var cmpnts = session.QueryOver<Component>()
|
||||
.Where(cmpnt => (cmpnt.Name == myCfg.Flowmeter1))
|
||||
.List();
|
||||
for (int fmtr = 1; fmtr <= myCfg.FlowmetersCount(); fmtr++)
|
||||
{
|
||||
string flowmeterName = myCfg.GetFlowmeterName(fmtr);
|
||||
Elde.FlowMeter.FlowMeter flowmeter = TbfComponents.FindComponent(flowmeterName) as Elde.FlowMeter.FlowMeter;
|
||||
|
||||
if (cmpnts.Count != 1) throw (new Exception(string.Format("No unique component in SaveNewCorrections(.,{0},{1})", myCfg.Flowmeter1, rangeIx)));
|
||||
if (flowmeter != null)
|
||||
{
|
||||
var cmpntEntities = session.QueryOver<Component>()
|
||||
.Where(cmpnt => (cmpnt.Name == flowmeterName))
|
||||
.List();
|
||||
|
||||
DeleteExistingCorrections(session, cmpnts[0], rangeIx);
|
||||
SaveNewCorrections(session, cmpnts[0], rangeIx, newCorrections);
|
||||
if (cmpntEntities.Count != 1)
|
||||
{
|
||||
log.ErrorFormat("No unique flowmeter named {0}", myCfg.GetFlowmeterName(fmtr));
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int rng = 0; rng <= myCfg.RangesCount(); rng++)
|
||||
{
|
||||
if (myCfg.FlowmtrRangeEnabled(fmtr, rng))
|
||||
{
|
||||
double tempRngLo = flowmeter.GetTempLo(rng);
|
||||
double tempRngHi = flowmeter.GetTempHi(rng);
|
||||
newCorrections = GetCorrections(batch, flowmeterName, rng, tempRngLo, tempRngHi);
|
||||
DeleteExistingCorrections(session, cmpntEntities[0], rng);
|
||||
SaveNewCorrections(session, cmpntEntities[0], rng, newCorrections);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
transaction.Commit();
|
||||
session.Flush();
|
||||
opCompleted = true;
|
||||
|
||||
log.ErrorFormat("Measurement corrections of {0}/{1} saved", myCfg.Flowmeter1, rangeIx);
|
||||
log.WarnFormat("Measurement corrections successfully saved");
|
||||
}
|
||||
catch (Exception exc)
|
||||
{
|
||||
if (transaction != null && !transaction.WasCommitted) transaction.Rollback();
|
||||
anyError = true;
|
||||
|
||||
log.WarnFormat("Failed to write batch {0} results to measurement {1}/{2} corrections: {3}",
|
||||
batch.BatchNr, myCfg.Flowmeter1, rangeIx, exc.Message);
|
||||
log.ErrorFormat("Failed to write corrections calculated from batch {0}: {1}", batch.BatchNr, exc.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -14,57 +14,185 @@ namespace TBF.BenchControl.Output.DB.SaveFlowmeterCorrections
|
||||
public IComponentCfgCtrl GetControl() { return new SaveFlowmeterCorrCfgCtrl(); }
|
||||
|
||||
public string Flowmeter1;
|
||||
public string Flowmeter2;
|
||||
public string Flowmeter3;
|
||||
public string Flowmeter4;
|
||||
public string Flowmeter5;
|
||||
public string Flowmeter6;
|
||||
public string Flowmeter7;
|
||||
|
||||
public bool Flowm1Rng1;
|
||||
public bool Flowm1Rng2;
|
||||
public bool Flowm1Rng3;
|
||||
public bool Flowm1Rng4;
|
||||
public bool Flowm1Rng5;
|
||||
|
||||
public string Flowmeter2;
|
||||
public bool Flowm2Rng1;
|
||||
public bool Flowm2Rng2;
|
||||
public bool Flowm2Rng3;
|
||||
public bool Flowm2Rng4;
|
||||
public bool Flowm2Rng5;
|
||||
|
||||
public string Flowmeter3;
|
||||
public bool Flowm3Rng1;
|
||||
public bool Flowm3Rng2;
|
||||
public bool Flowm3Rng3;
|
||||
public bool Flowm3Rng4;
|
||||
public bool Flowm3Rng5;
|
||||
|
||||
public string Flowmeter4;
|
||||
public bool Flowm4Rng1;
|
||||
public bool Flowm4Rng2;
|
||||
public bool Flowm4Rng3;
|
||||
public bool Flowm4Rng4;
|
||||
public bool Flowm4Rng5;
|
||||
|
||||
public string Flowmeter5;
|
||||
public bool Flowm5Rng1;
|
||||
public bool Flowm5Rng2;
|
||||
public bool Flowm5Rng3;
|
||||
public bool Flowm5Rng4;
|
||||
public bool Flowm5Rng5;
|
||||
|
||||
public string Flowmeter6;
|
||||
public bool Flowm6Rng1;
|
||||
public bool Flowm6Rng2;
|
||||
public bool Flowm6Rng3;
|
||||
public bool Flowm6Rng4;
|
||||
public bool Flowm6Rng5;
|
||||
|
||||
public string Flowmeter7;
|
||||
public bool Flowm7Rng1;
|
||||
public bool Flowm7Rng2;
|
||||
public bool Flowm7Rng3;
|
||||
public bool Flowm7Rng4;
|
||||
public bool Flowm7Rng5;
|
||||
|
||||
public int FlowmetersCount() { return 7; }
|
||||
public int RangesCount() { return 5; }
|
||||
|
||||
/// <summary>
|
||||
/// Get flowmeter name
|
||||
/// </summary>
|
||||
/// <param name="f">Flowmeter index 1 .. FlowmetersCount()==7</param>
|
||||
/// <returns>Flowmeter name or null</returns>
|
||||
public string GetFlowmeterName(int f)
|
||||
{
|
||||
switch (f)
|
||||
{
|
||||
case 1: return Flowmeter1;
|
||||
case 2: return Flowmeter2;
|
||||
case 3: return Flowmeter3;
|
||||
case 4: return Flowmeter4;
|
||||
case 5: return Flowmeter5;
|
||||
case 6: return Flowmeter6;
|
||||
case 7: return Flowmeter7;
|
||||
default: return null;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Is range enabled
|
||||
/// </summary>
|
||||
/// <param name="f">Flowmeter index 1 .. FlowmetersCount()==7</param>
|
||||
/// <param name="r">Range index 0 .. RangesCount()==5</param>
|
||||
/// <returns>ture if the range is enabled</returns>
|
||||
public bool FlowmtrRangeEnabled(int f, int r)
|
||||
{
|
||||
if (f == 1)
|
||||
{
|
||||
switch (r)
|
||||
{
|
||||
case 0: return !(Flowm1Rng1 || Flowm1Rng2 || Flowm1Rng3 || Flowm1Rng4 || Flowm1Rng5);
|
||||
case 1: return Flowm1Rng1;
|
||||
case 2: return Flowm1Rng2;
|
||||
case 3: return Flowm1Rng3;
|
||||
case 4: return Flowm1Rng4;
|
||||
case 5: return Flowm1Rng5;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
else if (f == 2)
|
||||
{
|
||||
switch (r)
|
||||
{
|
||||
case 0: return !(Flowm2Rng1 || Flowm2Rng2 || Flowm2Rng3 || Flowm2Rng4 || Flowm2Rng5);
|
||||
case 1: return Flowm2Rng1;
|
||||
case 2: return Flowm2Rng2;
|
||||
case 3: return Flowm2Rng3;
|
||||
case 4: return Flowm2Rng4;
|
||||
case 5: return Flowm2Rng5;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
else if (f == 3)
|
||||
{
|
||||
switch (r)
|
||||
{
|
||||
case 0: return !(Flowm3Rng1 || Flowm3Rng2 || Flowm3Rng3 || Flowm3Rng4 || Flowm3Rng5);
|
||||
case 1: return Flowm3Rng1;
|
||||
case 2: return Flowm3Rng2;
|
||||
case 3: return Flowm3Rng3;
|
||||
case 4: return Flowm3Rng4;
|
||||
case 5: return Flowm3Rng5;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
else if (f == 4)
|
||||
{
|
||||
switch (r)
|
||||
{
|
||||
case 0: return !(Flowm4Rng1 || Flowm4Rng2 || Flowm4Rng3 || Flowm4Rng4 || Flowm4Rng5);
|
||||
case 1: return Flowm4Rng1;
|
||||
case 2: return Flowm4Rng2;
|
||||
case 3: return Flowm4Rng3;
|
||||
case 4: return Flowm4Rng4;
|
||||
case 5: return Flowm4Rng5;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
else if (f == 5)
|
||||
{
|
||||
switch (r)
|
||||
{
|
||||
case 0: return !(Flowm5Rng1 || Flowm5Rng2 || Flowm5Rng3 || Flowm5Rng4 || Flowm5Rng5);
|
||||
case 1: return Flowm5Rng1;
|
||||
case 2: return Flowm5Rng2;
|
||||
case 3: return Flowm5Rng3;
|
||||
case 4: return Flowm5Rng4;
|
||||
case 5: return Flowm5Rng5;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
else if (f == 6)
|
||||
{
|
||||
switch (r)
|
||||
{
|
||||
case 0: return !(Flowm6Rng1 || Flowm6Rng2 || Flowm6Rng3 || Flowm6Rng4 || Flowm6Rng5);
|
||||
case 1: return Flowm6Rng1;
|
||||
case 2: return Flowm6Rng2;
|
||||
case 3: return Flowm6Rng3;
|
||||
case 4: return Flowm6Rng4;
|
||||
case 5: return Flowm6Rng5;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
else if (f == 7)
|
||||
{
|
||||
switch (r)
|
||||
{
|
||||
case 0: return !(Flowm7Rng1 || Flowm7Rng2 || Flowm7Rng3 || Flowm7Rng4 || Flowm7Rng5);
|
||||
case 1: return Flowm7Rng1;
|
||||
case 2: return Flowm7Rng2;
|
||||
case 3: return Flowm7Rng3;
|
||||
case 4: return Flowm7Rng4;
|
||||
case 5: return Flowm7Rng5;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
/// Private parameterless constructor invoked by all other (public) constructors
|
||||
SaveFlowmeterCorrCfg()
|
||||
{
|
||||
{
|
||||
ParentName = string.Empty;
|
||||
Flowmeter1 = "I1";
|
||||
Flowmeter2 = "I2";
|
||||
|
||||
@ -29,5 +29,5 @@ using System.Runtime.InteropServices;
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
[assembly: AssemblyVersion("2.18.817.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.817.0")]
|
||||
[assembly: AssemblyVersion("2.18.818.0")]
|
||||
[assembly: AssemblyFileVersion("2.18.818.0")]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user