@@ -44,8 +44,10 @@ class GetAllLhcFillsUseCase {
4444
4545 const queryBuilder = new QueryBuilder ( ) ;
4646
47+ let associatedStatisticsRequired = false ;
48+
4749 if ( filter ) {
48- const { hasStableBeams, fillNumbers, beamDuration } = filter ;
50+ const { hasStableBeams, fillNumbers, beamDuration, runDuration } = filter ;
4951 if ( hasStableBeams ) {
5052 // For now, if a stableBeamsStart is present, then a beam is stable
5153 queryBuilder . where ( 'stableBeamsStart' ) . not ( ) . is ( null ) ;
@@ -62,6 +64,23 @@ class GetAllLhcFillsUseCase {
6264 : queryBuilder . where ( 'fillNumber' ) . oneOf ( ...finalFillnumberList ) ;
6365 }
6466 }
67+
68+ if ( runDuration ?. limit !== undefined && runDuration ?. operator ) {
69+ associatedStatisticsRequired = true ;
70+ // 00:00:00 aka 0 value is saved in the DB as null (bookkeeping.fill_statistics.runs_coverage)
71+ if ( runDuration . operator === '<=' && Number ( runDuration . limit ) === 0 ) {
72+ queryBuilder . whereAssociation ( 'statistics' , 'runsCoverage' ) . lowerThanOrNull ( 0 , false ) ;
73+ } else if ( runDuration . operator === '>=' && Number ( runDuration . limit ) === 0 ) {
74+ queryBuilder . whereAssociation ( 'statistics' , 'runsCoverage' ) . greaterThanOrNull ( 0 , false ) ;
75+ } else if ( ( runDuration . operator === '>' || runDuration . operator === '<' ) && Number ( runDuration . limit ) === 0 ) {
76+ queryBuilder . whereAssociation ( 'statistics' , 'runsCoverage' ) . applyOperator ( runDuration . operator , 0 ) ;
77+ } else if ( Number ( runDuration . limit ) === 0 ) {
78+ queryBuilder . whereAssociation ( 'statistics' , 'runsCoverage' ) . applyOperator ( runDuration . operator , null ) ;
79+ } else {
80+ queryBuilder . whereAssociation ( 'statistics' , 'runsCoverage' ) . applyOperator ( runDuration . operator , runDuration . limit ) ;
81+ }
82+ }
83+
6584 // Beam duration filter, limit and corresponding operator.
6685 if ( beamDuration ?. limit !== undefined && beamDuration ?. operator ) {
6786 queryBuilder . where ( 'stableBeamsDuration' ) . applyOperator ( beamDuration . operator , beamDuration . limit ) ;
@@ -74,6 +93,14 @@ class GetAllLhcFillsUseCase {
7493 where : { definition : RunDefinition . PHYSICS } ,
7594 required : false ,
7695 } ) ;
96+
97+ if ( associatedStatisticsRequired ) {
98+ queryBuilder . include ( {
99+ association : 'statistics' ,
100+ required : true ,
101+ } ) ;
102+ }
103+
77104 queryBuilder . orderBy ( 'fillNumber' , 'desc' ) ;
78105 queryBuilder . limit ( limit ) ;
79106 queryBuilder . offset ( offset ) ;
0 commit comments