Skip to content

Commit

Permalink
[O2B-912] Display user that started/stopped run (#1839)
Browse files Browse the repository at this point in the history
  • Loading branch information
martinboulais authored Jan 23, 2025
1 parent 6d7dec2 commit d342491
Show file tree
Hide file tree
Showing 11 changed files with 75 additions and 9 deletions.
24 changes: 19 additions & 5 deletions lib/database/adapters/RunAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class RunAdapter {
*/
this.lhcPeriodAdapter = null;

/**
* @type {UserAdapter|null}
*/
this.userAdapter = null;

this.toEntity = this.toEntity.bind(this);
this.toDatabase = this.toDatabase.bind(this);
this.toMinifiedEntity = this.toMinifiedEntity.bind(this);
Expand Down Expand Up @@ -157,8 +162,13 @@ class RunAdapter {
phaseShiftAtStartBeam2,
phaseShiftAtEndBeam1,
phaseShiftAtEndBeam2,
userStart,
userStop,
} = databaseObject;

/**
* @type {Run}
*/
const entityObject = {
id,
runNumber,
Expand Down Expand Up @@ -249,6 +259,8 @@ class RunAdapter {
entityObject.lhcFill = lhcFill ? this.lhcFillAdapter.toEntity(lhcFill) : lhcFill;
entityObject.flpRoles = flpRoles ? flpRoles.map(this.flpRoleAdapter.toEntity) : [];
entityObject.lhcPeriod = lhcPeriod ? this.lhcPeriodAdapter.toEntity(lhcPeriod) : lhcPeriod;
entityObject.userStart = userStart ? this.userAdapter.toNameOnly(userStart) : userStart;
entityObject.userStop = userStop ? this.userAdapter.toNameOnly(userStop) : userStop;

entityObject.inelasticInteractionRateAvg = inelasticInteractionRateAvg;
entityObject.inelasticInteractionRateAtStart = inelasticInteractionRateAtStart;
Expand Down Expand Up @@ -310,7 +322,6 @@ class RunAdapter {
pdpTopologyDescriptionLibraryFile: entityObject.pdpTopologyDescriptionLibraryFile,
tfbDdMode: entityObject.tfbDdMode,
lhcPeriodId: entityObject.lhcPeriodId,
lhcPeriod: entityObject.lhcPeriod ? this.lhcPeriodAdapter.toDatabase(entityObject.lhcPeriod) : entityObject.lhcPeriod,
triggerValue: entityObject.triggerValue,
odcTopologyFullName: entityObject.odcTopologyFullName,
pdpWorkflowParameters: entityObject.pdpWorkflowParameters,
Expand All @@ -329,10 +340,6 @@ class RunAdapter {
definition: entityObject.definition,
calibrationStatus: entityObject.calibrationStatus,

logs: entityObject.logs?.map(this.logAdapter.toDatabase),
tags: entityObject.tags?.map(this.tagAdapter.toDatabase),
lhcFill: entityObject.lhcFill ? this.lhcFillAdapter.toDatabase(entityObject.lhcFill) : entityObject.lhcFill,

inelasticInteractionRateAvg: entityObject.inelasticInteractionRateAvg,
inelasticInteractionRateAtStart: entityObject.inelasticInteractionRateAtStart,
inelasticInteractionRateAtMid: entityObject.inelasticInteractionRateAtMid,
Expand All @@ -344,6 +351,13 @@ class RunAdapter {
phaseShiftAtStartBeam2: entityObject.phaseShiftAtStartBeam2,
phaseShiftAtEndBeam1: entityObject.phaseShiftAtEndBeam1,
phaseShiftAtEndBeam2: entityObject.phaseShiftAtEndBeam2,

logs: entityObject.logs?.map(this.logAdapter.toDatabase),
tags: entityObject.tags?.map(this.tagAdapter.toDatabase),
lhcFill: entityObject.lhcFill ? this.lhcFillAdapter.toDatabase(entityObject.lhcFill) : entityObject.lhcFill,
lhcPeriod: entityObject.lhcPeriod ? this.lhcPeriodAdapter.toDatabase(entityObject.lhcPeriod) : entityObject.lhcPeriod,
userStart: entityObject.userStart ? this.userAdapter.toDatabase(entityObject.userStart) : entityObject.userStart,
userStop: entityObject.userStop ? this.userAdapter.toDatabase(entityObject.userStop) : entityObject.userStop,
};
}

Expand Down
10 changes: 10 additions & 0 deletions lib/database/adapters/UserAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ class UserAdapter {
}
}

/**
* Return a user object by keeping only its name
*
* @param {SequelizeUser} databaseObject the full user object
* @return {{name: string}} the user with only name property
*/
toNameOnly(databaseObject) {
return { name: databaseObject.name };
}

/**
* Converts the given entity object to a database object.
*
Expand Down
1 change: 1 addition & 0 deletions lib/database/adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ runAdapter.lhcPeriodAdapter = lhcPeriodAdapter;
runAdapter.logAdapter = logAdapter;
runAdapter.runTypeAdapter = runTypeAdapter;
runAdapter.tagAdapter = tagAdapter;
runAdapter.userAdapter = userAdapter;

simulationPassQcFlagAdapter.simulationPassAdapter = simulationPassAdapter;
simulationPassQcFlagAdapter.qcFlagAdapter = qcFlagAdapter;
Expand Down
2 changes: 2 additions & 0 deletions lib/database/models/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,8 @@ module.exports = (sequelize) => {
foreignKey: 'run_number',
through: 'simulation_passes_runs',
});
Run.belongsTo(models.User, { as: 'userStart', foreignKey: 'userIdO2Start' });
Run.belongsTo(models.User, { as: 'userStop', foreignKey: 'userIdO2Stop' });
};

return Run;
Expand Down
2 changes: 2 additions & 0 deletions lib/database/models/typedefs/SequelizeRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,7 @@
* @property {SequelizeLhcFill|null} lhcFill
* @property {SequelizeRunType|null} runType
* @property {SequelizeLog[]|null} logs
* @property {SequelizeUser[]|null} userStart
* @property {SequelizeUser[]|null} userStop
*
*/
2 changes: 2 additions & 0 deletions lib/database/seeders/20200713103855-runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ module.exports = {
phase_shift_at_start_beam2: -1.23,
phase_shift_at_end_beam1: 5.67,
phase_shift_at_end_beam2: -1.23,
user_id_o2_start: 1,
user_id_o2_stop: 2,
updated_at: '2022-03-22 15:00:00',
created_at: '2022-03-22 15:00:00',
},
Expand Down
2 changes: 2 additions & 0 deletions lib/domain/entities/Run.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@
* @property {EorReason[]} eorReasons
* @property {RunType|null} runType
* @property {LhcFill} lhcFill
* @property {User} userStart
* @property {User} userStop
*/

/**
Expand Down
19 changes: 16 additions & 3 deletions lib/public/views/Runs/Details/runDetailsComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
* or submit itself to any jurisdiction.
*/

import { h, iconChevronRight, iconExternalLink } from '/js/src/index.js';
import { h, iconChevronRight, iconExternalLink, info } from '/js/src/index.js';
import { tabbedPanelComponent } from '../../../components/TabbedPanel/tabbedPanelComponent.js';
import { RUN_DETAILS_PANELS_KEYS } from './RunDetailsModel.js';
import { table } from '../../../components/common/table/table.js';
Expand Down Expand Up @@ -45,6 +45,7 @@ import { formatEorReason } from '../format/formatEorReason.mjs';
import { selectionDropdown } from '../../../components/common/selection/dropdown/selectionDropdown.js';
import { formatRunCalibrationStatus } from '../format/formatRunCalibrationStatus.js';
import { BeamModes } from '../../../domain/enums/BeamModes.js';
import { tooltip } from '../../../components/common/popover/tooltip.js';

const GREEK_LOWER_MU_ENCODING = '\u03BC';

Expand Down Expand Up @@ -158,7 +159,13 @@ export const runDetailsComponent = (runDetailsModel, router) => runDetailsModel.
h('.panel-header', 'Timeline'),
h('.flex-row.flex-wrap.p2.items-center.g3', [
h('.flex-column.items-center.flex-grow', [
h('strong', 'O2 Start'),
h('strong.flex-row.items-center.g2', [
'O2 Start',
run.userStart?.name && h(
'#user-start-tooltip.badge.bg-gray-light',
tooltip(info(), `Run started by ${run.userStart?.name}`),
),
]),
formatTimestamp(run.timeO2Start),
]),
iconChevronRight(),
Expand All @@ -178,7 +185,13 @@ export const runDetailsComponent = (runDetailsModel, router) => runDetailsModel.
]),
iconChevronRight(),
h('.flex-column.items-center.flex-grow', [
h('strong', 'O2 End'),
h('strong.flex-row.items-center.g2', [
'O2 end',
run.userStop?.name && h(
'#user-stop-tooltip.badge.bg-gray-light',
tooltip(info(), `Run stopped by ${run.userStop?.name}`),
),
]),
formatTimestamp(run.timeO2End),
]),
iconChevronRight(),
Expand Down
4 changes: 3 additions & 1 deletion lib/usecases/run/GetRunUseCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,9 @@ class GetRunUseCase {
},
})
.include('lhcFill')
.include('lhcPeriod');
.include('lhcPeriod')
.include('userStart')
.include('userStop');

if (runNumber) {
queryBuilder.where('runNumber').is(runNumber);
Expand Down
6 changes: 6 additions & 0 deletions test/lib/usecases/run/GetRunUseCase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,10 @@ module.exports = () => {
expect(result.detectors).to.equal('ACO,CPV,CTP,EMC,FIT,HMP,ITS,MCH,MFT,MID,PHS,TOF,TPC,TRD,ZDC');
expect(result.runDuration).to.equal(result.timeTrgEnd - result.timeTrgStart);
});

it('should successfully return an object that contains name of user that started and stopped it', async () => {
const result = await new GetRunUseCase().execute(getRunDto);
expect(result.userStart.name).to.equal('John Doe');
expect(result.userStop.name).to.equal('Jan Jansen');
});
};
12 changes: 12 additions & 0 deletions test/public/runs/detail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,18 @@ module.exports = () => {
expect(popoverContent).to.equal('Duration based on o2 start AND stop because of missing trigger information');
});

it('should successfully display user that started run', async () => {
await goToRunDetails(page, 1);
const popoverContent = await getPopoverContent(await page.waitForSelector('#user-start-tooltip .popover-trigger'));
expect(popoverContent).to.equal('Run started by John Doe');
});

it('should successfully display user that stopped run', async () => {
await goToRunDetails(page, 1);
const popoverContent = await getPopoverContent(await page.waitForSelector('#user-stop-tooltip .popover-trigger'));
expect(popoverContent).to.equal('Run stopped by Jan Jansen');
});

it('should display OFF in the nEPNs field when EPNs is null', async () => {
await goToRunDetails(page, 3);
await expectInnerText(page, '#n-epns', '# EPNs\nOFF');
Expand Down

0 comments on commit d342491

Please sign in to comment.