TBF.DB with 4 static session factories, sessions in UI rewritten, TODO: keep session that loads components open, etc.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user