Skip to content

Commit eae424b

Browse files
authored
[O2B-1094] Add runs counts to lhc periods view (#1334)
* calculate runsCount * add some color * add color * add test * amend test * rename
1 parent bab2c91 commit eae424b

9 files changed

Lines changed: 53 additions & 7 deletions

File tree

lib/database/adapters/LhcPeriodStatisticsAdapter.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,13 @@ class LhcPeriodStatisticsAdapter {
3333
const { id, avgCenterOfMassEnergy, lhcPeriod } = databaseObject;
3434
const distinctEnergies = databaseObject.get('distinctEnergies');
3535
const beamType = databaseObject.get('beamType');
36+
const runsCount = databaseObject.get('runsCount');
3637
const entity = {
3738
id,
3839
avgCenterOfMassEnergy,
3940
distinctEnergies: distinctEnergies?.split(',').map((energy) => Number(energy)) ?? [],
4041
beamType,
42+
runsCount,
4143
};
4244
entity.lhcPeriod = lhcPeriod ? this.lhcPeriodAdapter.toEntity(lhcPeriod) : null;
4345
return entity;

lib/database/models/typedefs/SequelizeLhcPeriodStatistics.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
* @property {number|null} avgCenterOfMassEnergy
1919
* @property {number[]|null} distinctEnergies
2020
* @property {SequelizeLhcPeriod} lhcPeriod
21+
* @property {number} runsCount
2122
*/

lib/domain/entities/LhcPeriodStatistics.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@
1818
* @property {number|null} avgCenterOfMassEnergy
1919
* @property {number[]} distinctEnergies
2020
* @property {LhcPeriod} lhcPeriod
21+
* @property {number} runsCount
2122
*/

lib/public/app.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ html, body {
2424
.b-underline-good { border-bottom: 4px solid var(--color-success); }
2525
.b-underline-bad { border-bottom: 4px dashed var(--color-danger); }
2626

27+
.bg-light-blue {
28+
background-color: var(--color-light-blue) !important;
29+
}
30+
2731
.overflow {
2832
height: 1.5rem;
2933
overflow: hidden;

lib/public/views/lhcPeriods/ActiveColumns/lhcPeriodsActiveColumns.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,15 @@ export const lhcPeriodsActiveColumns = {
2424
name: {
2525
name: 'Name',
2626
visible: true,
27-
format: (name) => h('.flex-row.flex-wrap', [
27+
format: (name, { runsCount }) => h('.flex-row.flex-wrap', [
2828
h('.ph1.mh1.w-10', name),
2929
h('.mh4'),
30-
frontLink('runs', 'runs-per-lhc-period', { lhcPeriodName: name }, { class: 'btn mh1' }),
30+
frontLink(
31+
['runs', h('sub', `[${runsCount}]`)],
32+
'runs-per-lhc-period',
33+
{ lhcPeriodName: name },
34+
{ class: `btn mh1 ${runsCount > 0 ? 'bg-light-blue' : ''}` },
35+
),
3136
]),
3237
sortable: true,
3338
filter: ({ namesFilterModel }) => textFilter(

lib/server/services/lhcPeriod/LhcPeriodStatisticsService.js

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,18 @@ const PDP_BEAM_TYPES_IN_STATISTICS_SUBQUERY = `
5353
LIMIT 1
5454
)`;
5555

56+
/**
57+
* Subquery to calculate number of runs associated with given LHC Period
58+
*/
59+
const RUNS_COUNT_SUBQUERY = `
60+
(SELECT COUNT(r.run_number)
61+
FROM runs as r
62+
WHERE r.lhc_period_id = lhcPeriod.id
63+
AND r.definition = 'PHYSICS'
64+
AND r.run_quality = 'good'
65+
)
66+
`;
67+
5668
/**
5769
* @typedef LhcPeriodIdentifier object to uniquely identify a lhc period
5870
* @property {string} [name] the lhc period name
@@ -89,6 +101,10 @@ class LhcPeriodStatisticsService {
89101
query: PDP_BEAM_TYPES_IN_STATISTICS_SUBQUERY,
90102
alias: 'beamType',
91103
});
104+
queryBuilder.includeAttribute({
105+
query: RUNS_COUNT_SUBQUERY,
106+
alias: 'runsCount',
107+
});
92108

93109
const data = await LhcPeriodStatisticsRepository.findOne(queryBuilder);
94110
return data ? lhcPeriodStatisticsAdapter.toEntity(data) : null;
@@ -191,6 +207,11 @@ class LhcPeriodStatisticsService {
191207
alias: 'beamType',
192208
});
193209

210+
queryBuilder.includeAttribute({
211+
query: RUNS_COUNT_SUBQUERY,
212+
alias: 'runsCount',
213+
});
214+
194215
const { count, rows } = await LhcPeriodStatisticsRepository.findAndCountAll(queryBuilder);
195216

196217
return {

test/api/lhcPeriodsStatistics.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const lhcPeriod_LHC22b = {
2525
id: 2,
2626
name: 'LHC22b',
2727
},
28+
runsCount: 1,
2829
};
2930

3031
const lhcPeriod_LHC22a = {
@@ -39,6 +40,7 @@ const lhcPeriod_LHC22a = {
3940
id: 1,
4041
name: 'LHC22a',
4142
},
43+
runsCount: 3,
4244
};
4345

4446
const lhcPeriod_LHC23f = {
@@ -50,6 +52,7 @@ const lhcPeriod_LHC23f = {
5052
id: 3,
5153
name: 'LHC23f',
5254
},
55+
runsCount: 0,
5356
};
5457

5558
module.exports = () => {

test/lib/server/services/lhcPeriod/LhcPeriodStatisticsService.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const lhcPeriod_LHC22b = {
2626
id: 2,
2727
name: 'LHC22b',
2828
},
29+
runsCount: 1,
2930
};
3031

3132
const lhcPeriod_LHC22a = {
@@ -40,6 +41,7 @@ const lhcPeriod_LHC22a = {
4041
id: 1,
4142
name: 'LHC22a',
4243
},
44+
runsCount: 3,
4345
};
4446

4547
const lhcPeriod_LHC23f = {
@@ -51,6 +53,7 @@ const lhcPeriod_LHC23f = {
5153
id: 3,
5254
name: 'LHC23f',
5355
},
56+
runsCount: 0,
5457
};
5558

5659
module.exports = () => {

test/public/lhcPeriods/overview.test.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,23 +192,29 @@ module.exports = () => {
192192

193193
await page.waitForTimeout(100);
194194

195+
const countsPerLhcPeriod = {
196+
LHC22b: 1,
197+
LHC22a: 3,
198+
LHC23f: 0,
199+
};
200+
195201
/**
196202
* As @see getAllDataFields returns innerText from cells, in case of lhcPeriod.name column, text from inner buttons is also taken.
197203
* @param {string[]} periodNames list of names
198204
* @return {string[]} cells content
199205
*/
200-
const appendButtonsText = (periodNames) => periodNames.map((p) => `${p}\nruns`);
206+
const appendButtonsText = (periodNames) => periodNames.map((name) => `${name}\nruns[${countsPerLhcPeriod[name]}]`);
201207

202-
let allLhcPeriodNames = await getAllDataFields(page, 'name');
203-
expect(allLhcPeriodNames).to.has.all.deep.members(appendButtonsText(['LHC22a']));
208+
let allLhcPeriodNameCellsContent = await getAllDataFields(page, 'name');
209+
expect(allLhcPeriodNameCellsContent).to.has.all.deep.members(appendButtonsText(['LHC22a']));
204210

205211
const resetFiltersButton = await page.$('#reset-filters');
206212
expect(resetFiltersButton).to.not.be.null;
207213
await resetFiltersButton.evaluate((button) => button.click());
208214
await page.waitForTimeout(100);
209215

210-
allLhcPeriodNames = await getAllDataFields(page, 'name');
211-
expect(allLhcPeriodNames).to.has.all.deep.members(appendButtonsText(['LHC22a', 'LHC22b', 'LHC23f']));
216+
allLhcPeriodNameCellsContent = await getAllDataFields(page, 'name');
217+
expect(allLhcPeriodNameCellsContent).to.has.all.deep.members(appendButtonsText(['LHC22a', 'LHC22b', 'LHC23f']));
212218
});
213219

214220
it('should successfuly apply lhc period year filter', async () => {

0 commit comments

Comments
 (0)