Skip to content

Commit

Permalink
[O2B-1377] Store phase shift for beam 1 and 2 (#1772)
Browse files Browse the repository at this point in the history
* [O2B-1377] Store phase shift for beam 1 and 2

* Fix seeders

* Fix tests
  • Loading branch information
martinboulais authored Sep 30, 2024
1 parent 7dad09b commit f36aaee
Show file tree
Hide file tree
Showing 11 changed files with 149 additions and 28 deletions.
18 changes: 12 additions & 6 deletions lib/database/adapters/RunAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,10 @@ class RunAdapter {
crossSection,
triggerEfficiency,
triggerAcceptance,
phaseShiftAtStart,
phaseShiftAtEnd,
phaseShiftAtStartBeam1,
phaseShiftAtStartBeam2,
phaseShiftAtEndBeam1,
phaseShiftAtEndBeam2,
} = databaseObject;

const entityObject = {
Expand Down Expand Up @@ -212,8 +214,10 @@ class RunAdapter {
crossSection,
triggerEfficiency,
triggerAcceptance,
phaseShiftAtStart,
phaseShiftAtEnd,
phaseShiftAtStartBeam1,
phaseShiftAtStartBeam2,
phaseShiftAtEndBeam1,
phaseShiftAtEndBeam2,
};

if (detectors) {
Expand Down Expand Up @@ -327,8 +331,10 @@ class RunAdapter {
crossSection: entityObject.crossSection,
triggerEfficiency: entityObject.triggerEfficiency,
triggerAcceptance: entityObject.triggerAcceptance,
phaseShiftAtStart: entityObject.phaseShiftAtStart,
phaseShiftAtEnd: entityObject.phaseShiftAtEnd,
phaseShiftAtStartBeam1: entityObject.phaseShiftAtStartBeam1,
phaseShiftAtStartBeam2: entityObject.phaseShiftAtStartBeam2,
phaseShiftAtEndBeam1: entityObject.phaseShiftAtEndBeam1,
phaseShiftAtEndBeam2: entityObject.phaseShiftAtEndBeam2,
};
}

Expand Down
64 changes: 64 additions & 0 deletions lib/database/migrations/20240930082704-update-run-phase-shift.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface, Sequelize) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.renameColumn(
'runs',
'phase_shift_at_start',
'phase_shift_at_start_beam1',
{ transaction },
);
await queryInterface.addColumn(
'runs',
'phase_shift_at_start_beam2',
{
type: Sequelize.DOUBLE,
allowNull: true,
},
{ transaction },
);

await queryInterface.renameColumn(
'runs',
'phase_shift_at_end',
'phase_shift_at_end_beam1',
{ transaction },
);
await queryInterface.addColumn(
'runs',
'phase_shift_at_end_beam2',
{
type: Sequelize.DOUBLE,
allowNull: true,
},
{ transaction },
);
}),

down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.renameColumn(
'runs',
'phase_shift_at_start_beam1',
'phase_shift_at_start',
{ transaction },
);
await queryInterface.removeColumn(
'runs',
'phase_shift_at_start_beam2',
{ transaction },
);

await queryInterface.renameColumn(
'runs',
'phase_shift_at_end_beam1',
'phase_shift_at_end',
{ transaction },
);
await queryInterface.removeColumn(
'runs',
'phase_shift_at_end_beam2',
{ transaction },
);
}),
};
14 changes: 12 additions & 2 deletions lib/database/models/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,22 @@ module.exports = (sequelize) => {
allowNull: true,
default: null,
},
phaseShiftAtStart: {
phaseShiftAtStartBeam1: {
type: Sequelize.DECIMAL,
allowNull: true,
default: null,
},
phaseShiftAtEnd: {
phaseShiftAtStartBeam2: {
type: Sequelize.DECIMAL,
allowNull: true,
default: null,
},
phaseShiftAtEndBeam1: {
type: Sequelize.DECIMAL,
allowNull: true,
default: null,
},
phaseShiftAtEndBeam2: {
type: Sequelize.DECIMAL,
allowNull: true,
default: null,
Expand Down
6 changes: 4 additions & 2 deletions lib/database/models/typedefs/SequelizeRun.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@
* @property {number|null} crossSection
* @property {number|null} triggerEfficiency
* @property {number|null} triggerAcceptance
* @property {number|null} phaseShiftAtEnd
* @property {number|null} phaseShiftAtStart
* @property {number|null} phaseShiftAtEndBeam1
* @property {number|null} phaseShiftAtEndBeam2
* @property {number|null} phaseShiftAtStartBeam1
* @property {number|null} phaseShiftAtStartBeam2
* @property {string} createdAt
* @property {string} updatedAt
* @property {number|null} runDuration
Expand Down
6 changes: 4 additions & 2 deletions lib/database/seeders/20200713103855-runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,10 @@ module.exports = {
cross_section: 1.23,
trigger_efficiency: 2.34,
trigger_acceptance: 3.45,
phase_shift_at_start: 4.56,
phase_shift_at_end: 5.67,
phase_shift_at_start_beam1: 4.56,
phase_shift_at_start_beam2: -1.23,
phase_shift_at_end_beam1: 5.67,
phase_shift_at_end_beam2: -1.23,
updated_at: '2022-03-22 15:00:00',
created_at: '2022-03-22 15:00:00',
},
Expand Down
9 changes: 7 additions & 2 deletions lib/domain/dtos/UpdateRunByRunNumberDto.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
const Joi = require('joi');
const { RUN_QUALITIES } = require('../enums/RunQualities.js');

const PhaseShiftDto = Joi.object({
beam1: Joi.number(),
beam2: Joi.number(),
}).optional();

const BodyDto = Joi.object({
runQuality: Joi.string().valid(...RUN_QUALITIES).optional(),
lhcBeamEnergy: Joi.number().optional(),
Expand All @@ -35,8 +40,8 @@ const BodyDto = Joi.object({
crossSection: Joi.number().optional(),
triggerEfficiency: Joi.number().optional(),
triggerAcceptance: Joi.number().optional(),
phaseShiftAtStart: Joi.number().optional(),
phaseShiftAtEnd: Joi.number().optional(),
phaseShiftAtStart: PhaseShiftDto,
phaseShiftAtEnd: PhaseShiftDto,
});

const QueryDto = Joi.object({
Expand Down
6 changes: 4 additions & 2 deletions lib/domain/entities/Run.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,10 @@
* @property {number|null} crossSection
* @property {number|null} triggerEfficiency
* @property {number|null} triggerAcceptance
* @property {number|null} phaseShiftAtEnd
* @property {number|null} phaseShiftAtStart
* @property {number|null} phaseShiftAtStartBeam1
* @property {number|null} phaseShiftAtStartBeam2
* @property {number|null} phaseShiftAtEndBeam1
* @property {number|null} phaseShiftAtEndBeam2
* @property {Date} updatedAt
* @property {Date} createdAt
* @property {number|null} runDuration
Expand Down
10 changes: 10 additions & 0 deletions lib/usecases/run/UpdateRunUseCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,20 @@ class UpdateRunUseCase {
runQualityChangeReason,
calibrationStatusChangeReason,
detectorsQualitiesChangeReason,
phaseShiftAtStart,
phaseShiftAtEnd,
} = body;
delete body.eorReasons;
delete body.tags;
delete body.detectorsQualities;
delete body.phaseShiftAtStart;
delete body.phaseShiftAtEnd;

body.phaseShiftAtStartBeam1 = phaseShiftAtStart?.beam1;
body.phaseShiftAtStartBeam2 = phaseShiftAtStart?.beam2;
body.phaseShiftAtEndBeam1 = phaseShiftAtEnd?.beam1;
body.phaseShiftAtEndBeam2 = phaseShiftAtEnd?.beam2;

const run = await runService.update(
{ runNumber },
{
Expand Down
16 changes: 12 additions & 4 deletions test/api/runs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1206,8 +1206,14 @@ module.exports = () => {
crossSection: 0.1,
triggerEfficiency: 0.2,
triggerAcceptance: 0.3,
phaseShiftAtStart: 0.4,
phaseShiftAtEnd: 0.5,
phaseShiftAtStart: {
beam1: 0.4,
beam2: -0.2,
},
phaseShiftAtEnd: {
beam1: 0.5,
beam2: -0.25,
},
});

expect(response.status).to.equal(200);
Expand All @@ -1231,8 +1237,10 @@ module.exports = () => {
expect(data.otherFileSize).to.equal(BIG_INT_NUMBER);
expect(data.triggerEfficiency).to.equal(0.2);
expect(data.triggerAcceptance).to.equal(0.3);
expect(data.phaseShiftAtStart).to.equal(0.4);
expect(data.phaseShiftAtEnd).to.equal(0.5);
expect(data.phaseShiftAtStartBeam1).to.equal(0.4);
expect(data.phaseShiftAtStartBeam2).to.equal(-0.2);
expect(data.phaseShiftAtEndBeam1).to.equal(0.5);
expect(data.phaseShiftAtEndBeam2).to.equal(-0.25);
});
});

Expand Down
12 changes: 8 additions & 4 deletions test/lib/server/services/run/RunService.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,13 +649,17 @@ module.exports = () => {
{ runNumber },
{
runPatch: {
phaseShiftAtStart: 0.0004,
phaseShiftAtEnd: 0.0005,
phaseShiftAtStartBeam1: 0.0004,
phaseShiftAtStartBeam2: -0.0001,
phaseShiftAtEndBeam1: 0.0005,
phaseShiftAtEndBeam2: -0.0002,
},
},
);
expect(run.phaseShiftAtStart).to.equal(0.0004);
expect(run.phaseShiftAtEnd).to.equal(0.0005);
expect(run.phaseShiftAtStartBeam1).to.equal(0.0004);
expect(run.phaseShiftAtStartBeam2).to.equal(-0.0001);
expect(run.phaseShiftAtEndBeam1).to.equal(0.0005);
expect(run.phaseShiftAtEndBeam2).to.equal(-0.0002);
});

it('should successfully update run cross section and trigger acceptance', async () => {
Expand Down
16 changes: 12 additions & 4 deletions test/lib/usecases/run/UpdateRunUseCase.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,14 @@ module.exports = () => {
crossSection: 0.1,
triggerEfficiency: 0.2,
triggerAcceptance: 0.3,
phaseShiftAtStart: 0.4,
phaseShiftAtEnd: 0.5,
phaseShiftAtStart: {
beam1: 0.4,
beam2: -0.1,
},
phaseShiftAtEnd: {
beam1: 0.5,
beam2: -0.2,
},
},
});
});
Expand Down Expand Up @@ -321,8 +327,10 @@ module.exports = () => {
expect(result.crossSection).to.equal(0.1);
expect(result.triggerEfficiency).to.equal(0.2);
expect(result.triggerAcceptance).to.equal(0.3);
expect(result.phaseShiftAtStart).to.equal(0.4);
expect(result.phaseShiftAtEnd).to.equal(0.5);
expect(result.phaseShiftAtStartBeam1).to.equal(0.4);
expect(result.phaseShiftAtStartBeam2).to.equal(-0.1);
expect(result.phaseShiftAtEndBeam1).to.equal(0.5);
expect(result.phaseShiftAtEndBeam2).to.equal(-0.2);
});

it('Should give an error when the id of the run can not be found', async () => {
Expand Down

0 comments on commit f36aaee

Please sign in to comment.