Skip to content

Commit f1e32eb

Browse files
committed
Bring FloatComparison filters in line with integer one
1 parent dee055c commit f1e32eb

4 files changed

Lines changed: 38 additions & 16 deletions

File tree

lib/domain/dtos/filters/NumericalComparisonDto.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,7 @@ exports.IntegerComparisonDto = Joi.object({
2020
limit: Joi.number().integer().min(0),
2121
});
2222

23-
exports.FloatComparisonDto = Joi.object(Object.fromEntries(NUMERICAL_COMPARISON_OPERATORS.map((operator) => [operator, Joi.number()])));
23+
exports.FloatComparisonDto = Joi.object({
24+
operator: Joi.string().valid(...NUMERICAL_COMPARISON_OPERATORS),
25+
limit: Joi.number().min(0),
26+
});

lib/usecases/run/GetAllRunsUseCase.js

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -158,21 +158,25 @@ class GetAllRunsUseCase {
158158
.filter((fillNumber) => parseInt(fillNumber, 10));
159159
filteringQueryBuilder.where('fillNumber').oneOf(...fillNumbersList);
160160
}
161+
161162
if (o2start) {
162163
const from = o2start.from !== undefined ? o2start.from : 0;
163164
const to = o2start.to !== undefined ? o2start.to : new Date().getTime();
164165
filteringQueryBuilder.where('timeO2Start').between(from, to);
165166
}
167+
166168
if (o2end) {
167169
const from = o2end.from !== undefined ? o2end.from : 0;
168170
const to = o2end.to !== undefined ? o2end.to : new Date().getTime();
169171
filteringQueryBuilder.where('timeO2End').between(from, to);
170172
}
173+
171174
if (updatedAt) {
172175
const from = updatedAt.from ?? 0;
173176
const to = updatedAt.to ?? new Date().getTime();
174177
filteringQueryBuilder.where('updatedAt').between(from, to);
175178
}
179+
176180
if (triggerValues) {
177181
filteringQueryBuilder.where('triggerValue').oneOf(...triggerValues);
178182
}
@@ -202,6 +206,7 @@ class GetAllRunsUseCase {
202206
}
203207

204208
if (muInelasticInteractionRate) {
209+
const { operator, limit: muInelasticInteractionRateValue } = muInelasticInteractionRate;
205210
/**
206211
* The computed mu of inelastic interaction rate
207212
*
@@ -215,9 +220,7 @@ class GetAllRunsUseCase {
215220
`);
216221

217222
filteringQueryBuilder.include({ association: 'lhcFill' });
218-
for (const [operator, value] of Object.entries(muInelasticInteractionRate)) {
219-
filteringQueryBuilder.where(computedColumn).applyOperator(operator, value);
220-
}
223+
filteringQueryBuilder.where(computedColumn).applyOperator(operator, muInelasticInteractionRateValue);
221224
}
222225

223226
const inelFilters = {
@@ -226,12 +229,10 @@ class GetAllRunsUseCase {
226229
inelasticInteractionRateAtMid,
227230
inelasticInteractionRateAtEnd,
228231
};
229-
for (const [property, operatorsAndValues] of Object.entries(inelFilters)) {
230-
if (operatorsAndValues) {
231-
for (const [operator, value] of Object.entries(operatorsAndValues)) {
232-
filteringQueryBuilder.where(property).applyOperator(operator, value);
233-
}
234-
}
232+
for (const inelFilter of Object.entries(inelFilters)) {
233+
if (inelFilter) continue;
234+
const { operator, limit: value } = inelFilter;
235+
filteringQueryBuilder.where(inelFilter).applyOperator(operator, value);
235236
}
236237

237238
if (runDuration) {
@@ -255,6 +256,7 @@ class GetAllRunsUseCase {
255256
// Duration limit is handled in milliseconds by the API, but the query works on microseconds
256257
filteringQueryBuilder.where(computedColumn).applyOperator(operator, durationLimit * 1000);
257258
}
259+
258260
if (environmentIds) {
259261
// Search for multiple exact ids
260262
const environmentIdList = environmentIds
@@ -263,9 +265,11 @@ class GetAllRunsUseCase {
263265
.filter((environmentId) => Boolean(environmentId));
264266
filteringQueryBuilder.where('environmentId').oneOf(...environmentIdList);
265267
}
268+
266269
if (runQualities) {
267270
filteringQueryBuilder.where('runQuality').oneOf(...runQualities);
268271
}
272+
269273
const fileCountFilters = [
270274
{ field: 'nDetectors', value: nDetectors },
271275
{ field: 'nFlps', value: nFlps },
@@ -286,19 +290,23 @@ class GetAllRunsUseCase {
286290
} else if (ddflp === true) {
287291
filteringQueryBuilder.where('dd_flp').is(ddflp);
288292
}
293+
289294
if (dcs === false) {
290295
filteringQueryBuilder.where('dcs').isOrNull(dcs);
291296
} else if (dcs === true) {
292297
filteringQueryBuilder.where('dcs').is(dcs);
293298
}
299+
294300
if (epn === false) {
295301
filteringQueryBuilder.where('epn').isOrNull(false);
296302
} else if (epn === true) {
297303
filteringQueryBuilder.where('epn').is(true);
298304
}
305+
299306
if (odcTopologyFullName) {
300307
filteringQueryBuilder.where('odcTopologyFullName').substring(odcTopologyFullName);
301308
}
309+
302310
if (detectorFilter) {
303311
const { operator: detectorsOperator, values: detectorsValues } = detectorFilter;
304312
switch (detectorsOperator) {
@@ -315,6 +323,7 @@ class GetAllRunsUseCase {
315323
break;
316324
}
317325
}
326+
318327
if (lhcPeriods) {
319328
// Search for multiple exact ids
320329
const lhcPeriodsList = lhcPeriods
@@ -351,7 +360,8 @@ class GetAllRunsUseCase {
351360
const [dataPassId] = dataPassIds;
352361
const gaqSummary = await gaqService.getSummary(dataPassId, { mcReproducibleAsNotBad });
353362

354-
for (const [operator, value] of Object.entries(gaq.notBadFraction)) {
363+
if (gaq.notBadFraction) {
364+
const {operator, limit: value} = gaq.notBadFraction;
355365
const runNumbers = Object.entries(gaqSummary)
356366
.filter(([_, { badEffectiveRunCoverage }]) => {
357367
switch (operator) {

test/api/runs.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ module.exports = () => {
399399
it('should successfully filter by GAQ notBadFraction', async () => {
400400
const dataPassId = 1;
401401
{
402-
const response = await request(server).get(`/api/runs?filter[dataPassIds][]=${dataPassId}&filter[gaq][notBadFraction][<]=0.8`);
402+
const response = await request(server).get(`/api/runs?filter[dataPassIds][]=${dataPassId}&filter[gaq][notBadFraction][operator]=<&filter[gaq][notBadFraction][limit]=0.8`);
403403

404404
expect(response.status).to.equal(200);
405405
const { data: runs } = response.body;
@@ -409,7 +409,7 @@ module.exports = () => {
409409
}
410410
{
411411
const response = await request(server).get(`/api/runs?filter[dataPassIds][]=${dataPassId}` +
412-
'&filter[gaq][notBadFraction][<]=0.8&filter[gaq][mcReproducibleAsNotBad]=true');
412+
'&filter[gaq][notBadFraction][operator]=<&filter[gaq][notBadFraction][limit]=0.8&filter[gaq][mcReproducibleAsNotBad]=true');
413413

414414
expect(response.status).to.equal(200);
415415
const { data: runs } = response.body;

test/lib/usecases/run/GetAllRunsUseCase.test.js

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,16 @@ module.exports = () => {
754754
for (const [property, testParameters] of Object.entries(inelasticInteractionRateFilteringTestsParameters)) {
755755
const { operator, value, expectedRuns } = testParameters;
756756
it(`should successfully filter by ${property}`, async () => {
757-
const { runs } = await new GetAllRunsUseCase().execute({ query: { filter: { [property]: { [operator]: value } } } });
757+
const { runs } = await new GetAllRunsUseCase().execute({
758+
query: {
759+
filter: {
760+
[property]: {
761+
operator,
762+
limit: value,
763+
}
764+
}
765+
}
766+
});
758767
expect(runs).to.be.an('array');
759768
expect(runs.map(({ runNumber }) => runNumber)).to.have.all.members(expectedRuns);
760769
});
@@ -767,7 +776,7 @@ module.exports = () => {
767776
query: {
768777
filter: {
769778
dataPassIds,
770-
gaq: { notBadFraction: { '<': 0.8 } },
779+
gaq: { notBadFraction: { operator: '<', limit: 0.8 } },
771780
},
772781
},
773782
});
@@ -779,7 +788,7 @@ module.exports = () => {
779788
query: {
780789
filter: {
781790
dataPassIds,
782-
gaq: { notBadFraction: { '<': 0.8 }, mcReproducibleAsNotBad: true },
791+
gaq: { notBadFraction: { operator: '<', limit: 0.8 }, mcReproducibleAsNotBad: true },
783792
},
784793
},
785794
});

0 commit comments

Comments
 (0)