Merge branch 'master-2-Clean-up-of-MySQL-DB-sessions' into master-2, ver. 2.33.2057

# Conflicts:
#	Config/FluentCommon.cs
#	TBF/Properties/AssemblyInfo.cs
#	TBF/Resources/Strings.resx
#	TBF/Rig/Output/DB/ProductionTracing/Tracing.cs
#	TBF/UI/Procedures/ProcedureDlg.cs
This commit is contained in:
Milan Hanajik
2023-06-07 16:21:54 +02:00
85 changed files with 2248 additions and 1673 deletions
+16 -13
View File
@@ -64,19 +64,22 @@ namespace TBF.Rig.TestMethods.Endurance
seqStepsCtrl = new CycleStepsCtrl() as ITabWithListViewEx;
/// Prepare a list of valves for the endurance test
TbfComponents = Rig.TbfComponents.LoadComponentsFromDB(TBF.DB.CreateSession(Common.DBKind.Config));
Valves = new List<IValve>();
for (int bitNr = 0; bitNr < 8; bitNr++)
{
foreach (var vlv in TbfComponents)
{
if (vlv is Rig.Elde.Valve.Valve && (vlv as Rig.Elde.Valve.Valve).BitPosition == bitNr)
{
Valves.Add(vlv as IValve);
break;
}
}
}
using (var session = TBF.DB.ConfigDBSessionFactory.OpenSession())
{
TbfComponents = Rig.TbfComponents.LoadComponentsFromDB(session);
Valves = new List<IValve>();
for (int bitNr = 0; bitNr < 8; bitNr++)
{
foreach (var vlv in TbfComponents)
{
if (vlv is Rig.Elde.Valve.Valve && (vlv as Rig.Elde.Valve.Valve).BitPosition == bitNr)
{
Valves.Add(vlv as IValve);
break;
}
}
}
}
EnduranceCycle = (cycle != null) ? cycle : new List<CycleStep>(); /// TODO: Load from component parameters
@@ -112,65 +112,65 @@ namespace TBF.Rig.TestMethods.Q2CorrectionFromHistory
/// Invalidate any previous Q2 Pre-Corrections
IsQ2PreCorrectionCalculated = false;
ISession session = null;
try
{
using (ISession session = Results.DB.CreateSession())
session = TBF.DB.ResultsDBSessionFactory.OpenSession();
Batch btc = null;
var batches = session.QueryOver<Batch>(() => btc)
.Where(bb => (bb.ProcedureName == cfg.ProcedureName))
.List();
if (!string.IsNullOrEmpty(cfg.ProcedureNameAlt1))
{
Batch btc = null;
var batches = session.QueryOver<Batch>(() => btc)
.Where(bb => (bb.ProcedureName == cfg.ProcedureName))
.List();
IList<Batch> batches2 = session.QueryOver<Batch>(() => btc)
.Where(bb => (bb.ProcedureName == cfg.ProcedureNameAlt1))
.List();
foreach (var b in batches2) batches.Add(b);
}
if (!string.IsNullOrEmpty(cfg.ProcedureNameAlt2))
{
IList<Batch> batches3 = session.QueryOver<Batch>(() => btc)
.Where(bb => (bb.ProcedureName == cfg.ProcedureNameAlt2))
.List();
foreach (var b in batches3) batches.Add(b);
}
if (!string.IsNullOrEmpty(cfg.ProcedureNameAlt1))
{
IList<Batch> batches2 = session.QueryOver<Batch>(() => btc)
.Where(bb => (bb.ProcedureName == cfg.ProcedureNameAlt1))
.List();
foreach (var b in batches2) batches.Add(b);
}
if (!string.IsNullOrEmpty(cfg.ProcedureNameAlt2))
{
IList<Batch> batches3 = session.QueryOver<Batch>(() => btc)
.Where(bb => (bb.ProcedureName == cfg.ProcedureNameAlt2))
.List();
foreach (var b in batches3) batches.Add(b);
}
int samplesCount = 0;
double q2CorrLRsum = 0;
double q2CorrRLsum = 0;
int samplesCount = 0;
double q2CorrLRsum = 0;
double q2CorrRLsum = 0;
var sortedBatches = batches.OrderByDescending(b => b.EndTime);
foreach (var b in sortedBatches)
var sortedBatches = batches.OrderByDescending(b => b.EndTime);
foreach (var b in sortedBatches)
{
foreach (var wm in b.WaterMeters)
{
foreach (var wm in b.WaterMeters)
if ((wm != null) && !wm.Disabled && wm.Passed)
{
if ((wm != null) && !wm.Disabled && wm.Passed)
{
#if IPERL
q2CorrLRsum += wm.Q2CorrLR;
q2CorrRLsum += wm.Q2CorrRL;
q2CorrLRsum += wm.Q2CorrLR;
q2CorrRLsum += wm.Q2CorrRL;
#endif
samplesCount++;
}
samplesCount++;
}
if (samplesCount >= 200) break;
}
if (samplesCount >= 200)
{
IsQ2PreCorrectionCalculated = true;
CalculatedQ2PreCorrectionLR = (int)Math.Round(q2CorrLRsum / samplesCount);
CalculatedQ2PreCorrectionRL = (int)Math.Round(q2CorrRLsum / samplesCount);
log.WarnFormat("Q2 corrections calculated OK: LR = {0}, RL = {1}", CalculatedQ2PreCorrectionLR, CalculatedQ2PreCorrectionRL);
return true;
}
else
{
log.ErrorFormat("Not enough samples to calculate Q2 corrections ({0})", samplesCount);
return false;
}
if (samplesCount >= 200) break;
}
if (samplesCount >= 200)
{
IsQ2PreCorrectionCalculated = true;
CalculatedQ2PreCorrectionLR = (int)Math.Round(q2CorrLRsum / samplesCount);
CalculatedQ2PreCorrectionRL = (int)Math.Round(q2CorrRLsum / samplesCount);
log.WarnFormat("Q2 corrections calculated OK: LR = {0}, RL = {1}", CalculatedQ2PreCorrectionLR, CalculatedQ2PreCorrectionRL);
return true;
}
else
{
log.ErrorFormat("Not enough samples to calculate Q2 corrections ({0})", samplesCount);
return false;
}
}
catch (Exception exc)
@@ -178,6 +178,10 @@ namespace TBF.Rig.TestMethods.Q2CorrectionFromHistory
log.ErrorFormat("Failed to calculate Q2 corrections: {0}", exc.Message);
return false;
}
finally
{
if (session != null && session.IsOpen) session.Close();
}
}
}
}