Skip to content

Commit 86f2ad5

Browse files
committed
[O2B-1506] Run duration filter tests + backend
1 parent 867a0f6 commit 86f2ad5

5 files changed

Lines changed: 79 additions & 7 deletions

File tree

lib/domain/dtos/filters/LhcFillsFilterDto.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,8 @@ exports.LhcFillsFilterDto = Joi.object({
2323
'any.invalid': '{{#message}}',
2424
}),
2525
beamDurationOperator: Joi.string().trim().min(1).max(2),
26+
runDuration: Joi.string().trim().min(8).max(8).custom(validateTime).messages({
27+
'any.invalid': '{{#message}}',
28+
}),
29+
runDurationOperator: Joi.string().trim().min(1).max(2),
2630
});

lib/public/views/LhcFills/ActiveColumns/lhcFillsActiveColumns.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,17 @@ export const lhcFillsActiveColumns = {
140140
visible: true,
141141
size: 'w-8',
142142
format: (duration) => formatDuration(duration),
143-
filter: (lhcFillModel) => runDurationFilter(
144-
lhcFillModel.filteringModel.get('runDuration'),
145-
lhcFillModel.getRunDurationOperator(),
146-
(value) => lhcFillModel.setRunDurationOperator(value),
147-
),
148143
},
149144
runsCoverage: {
150145
name: 'Total runs duration',
151146
visible: true,
152147
size: 'w-8',
153148
format: (duration) => formatDuration(duration),
149+
filter: (lhcFillModel) => runDurationFilter(
150+
lhcFillModel.filteringModel.get('runDuration'),
151+
lhcFillModel.getRunDurationOperator(),
152+
(value) => lhcFillModel.setRunDurationOperator(value),
153+
),
154154
},
155155
efficiency: {
156156
name: 'Fill Efficiency',

lib/usecases/lhcFill/GetAllLhcFillsUseCase.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ class GetAllLhcFillsUseCase {
4242

4343
const queryBuilder = new QueryBuilder();
4444

45+
let associatedStatisticsRequired = false;
46+
4547
if (filter) {
46-
const { hasStableBeams, fillNumbers, beamDurationOperator, beamDuration } = filter;
48+
const { hasStableBeams, fillNumbers, beamDurationOperator, beamDuration, runDurationOperator, runDuration } = filter;
4749
if (hasStableBeams) {
4850
// For now, if a stableBeamsStart is present, then a beam is stable
4951
queryBuilder.where('stableBeamsStart').not().is(null);
@@ -84,6 +86,12 @@ class GetAllLhcFillsUseCase {
8486
}
8587
}
8688

89+
// Run duration filter and corresponding operator.
90+
if (runDuration && runDurationOperator) {
91+
associatedStatisticsRequired = true;
92+
queryBuilder.whereAssociation('statistics', 'runsCoverage').applyOperator(runDurationOperator, runDuration);
93+
}
94+
8795
// Beam duration filter and corresponding operator.
8896
if (beamDuration && beamDurationOperator) {
8997
queryBuilder.where('stableBeamsDuration').applyOperator(beamDurationOperator, beamDuration);
@@ -96,6 +104,11 @@ class GetAllLhcFillsUseCase {
96104
where: { definition: RunDefinition.PHYSICS },
97105
required: false,
98106
});
107+
queryBuilder.include({
108+
association: 'statistics',
109+
required: associatedStatisticsRequired,
110+
});
111+
99112
queryBuilder.orderBy('fillNumber', 'desc');
100113
queryBuilder.limit(limit);
101114
queryBuilder.offset(offset);

test/lib/usecases/lhcFill/GetAllLhcFillsUseCase.test.js

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,55 @@ module.exports = () => {
149149
expect(lhcFill.stableBeamsDuration).greaterThan(100)
150150
});
151151
})
152+
153+
it('should only contain specified total run duration, > 04:00:00', async () => {
154+
getAllLhcFillsDto.query = { filter: { runDuration: '14400', runDurationOperator: '>' } };
155+
const { lhcFills } = await new GetAllLhcFillsUseCase().execute(getAllLhcFillsDto)
156+
157+
expect(lhcFills).to.be.an('array').and.lengthOf(1)
158+
lhcFills.forEach((lhcFill) => {
159+
expect(lhcFill.runDuration).greaterThan(14400)
160+
});
161+
})
162+
163+
it('should only contain specified total run duration, >= 05:00:00', async () => {
164+
getAllLhcFillsDto.query = { filter: { runDuration: '18000', runDurationOperator: '>=' } };
165+
const { lhcFills } = await new GetAllLhcFillsUseCase().execute(getAllLhcFillsDto)
166+
167+
expect(lhcFills).to.be.an('array').and.lengthOf(1)
168+
lhcFills.forEach((lhcFill) => {
169+
expect(lhcFill.runDuration).greaterThan(18000)
170+
});
171+
})
172+
173+
it('should only contain specified total run duration, = 05:00:00', async () => {
174+
getAllLhcFillsDto.query = { filter: { runDuration: '18000', runDurationOperator: '=' } };
175+
const { lhcFills } = await new GetAllLhcFillsUseCase().execute(getAllLhcFillsDto)
176+
177+
expect(lhcFills).to.be.an('array').and.lengthOf(1)
178+
lhcFills.forEach((lhcFill) => {
179+
expect(lhcFill.runDuration).greaterThan(18000)
180+
});
181+
})
182+
183+
184+
it('should only contain specified total run duration, <= 05:00:00', async () => {
185+
getAllLhcFillsDto.query = { filter: { runDuration: '18000', runDurationOperator: '<=' } };
186+
const { lhcFills } = await new GetAllLhcFillsUseCase().execute(getAllLhcFillsDto)
187+
188+
expect(lhcFills).to.be.an('array').and.lengthOf(1)
189+
lhcFills.forEach((lhcFill) => {
190+
expect(lhcFill.runDuration).greaterThan(18000)
191+
});
192+
})
193+
194+
it('should only contain specified total run duration, < 06:30:59', async () => {
195+
getAllLhcFillsDto.query = { filter: { runDuration: '23459', runDurationOperator: '<' } };
196+
const { lhcFills } = await new GetAllLhcFillsUseCase().execute(getAllLhcFillsDto)
197+
198+
expect(lhcFills).to.be.an('array').and.lengthOf(1)
199+
lhcFills.forEach((lhcFill) => {
200+
expect(lhcFill.runDuration).greaterThan(23459)
201+
});
202+
})
152203
};

test/public/lhcFills/overview.test.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,9 @@ module.exports = () => {
270270
const filterSBExpect = { selector: 'div.items-baseline:nth-child(2) > div:nth-child(1)', value: 'Stable Beams Only' };
271271
const filterFillNRExpect = {selector: 'div.items-baseline:nth-child(1) > div:nth-child(1)', value: 'Fill #'}
272272
const filterSBDurationExpect = {selector: 'div.items-baseline:nth-child(3) > div:nth-child(1)', value: 'SB Duration'}
273-
const filterSBDurationPlaceholderExpect = {selector: 'input.w-100:nth-child(2)', value: 'e.g 16:14:15 (HH:MM:SS)'}
273+
const filterSBDurationPlaceholderExpect = {selector: '.beam-duration-filter', value: 'e.g 16:14:15 (HH:MM:SS)'}
274+
const filterRunDurationExpect = {selector: 'div.flex-row:nth-child(4) > div:nth-child(1)', value: 'Total runs duration'}
275+
const filterRunDurationPlaceholderExpect = {selector: '.run-duration-filter', value: 'e.g 16:14:15 (HH:MM:SS)'}
274276

275277

276278
await goToPage(page, 'lhc-fill-overview');
@@ -280,6 +282,8 @@ module.exports = () => {
280282
await expectInnerText(page, filterFillNRExpect.selector, filterFillNRExpect.value);
281283
await expectInnerText(page, filterSBDurationExpect.selector, filterSBDurationExpect.value);
282284
await expectAttributeValue(page, filterSBDurationPlaceholderExpect.selector, 'placeholder', filterSBDurationPlaceholderExpect.value);
285+
await expectInnerText(page, filterRunDurationExpect.selector, filterRunDurationExpect.value);
286+
await expectAttributeValue(page, filterRunDurationPlaceholderExpect.selector, 'placeholder', filterRunDurationPlaceholderExpect.value);
283287
});
284288

285289

0 commit comments

Comments
 (0)