Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
5a7d625
[O2B-1545] Add GAQ summary models, adapters and migration
isaachilly Mar 5, 2026
e00313d
[O2B-1545] Add GAQ summary repositories and timestamps
isaachilly Mar 16, 2026
d595ca4
[O2B-1545] Use default Sequelize createdAt/updatedAt instead of compu…
isaachilly Mar 17, 2026
3a6e9fd
[O2B-1545] Use mcReproducibleCoverage float instead of boolean
isaachilly Mar 17, 2026
b1ce92d
[O2B-1545] Remove mcReproducible field
isaachilly Mar 17, 2026
c2bfb63
[O2B-1545] Rename GAQ summary coverage fields
isaachilly Mar 18, 2026
e1cf34e
Add calculationFailed to GAQ summaries
isaachilly Apr 17, 2026
9f7b71b
[O2B-1545] Make GAQ summary columns nullable
isaachilly Apr 17, 2026
59ab212
[O2B-1545] Add invalidatedAt to gaq_summaries, remove invalidation table
isaachilly May 4, 2026
e83c3bb
[O2B-1545] Rename calculationFailed to notComputable
isaachilly May 4, 2026
6884ea4
[O2B-1545] Remove unused GaqSummaryInvalidation files and imports
isaachilly May 4, 2026
6a7ce78
[O2B-1545] Add index on gaq_summaries.invalidated_at
isaachilly May 5, 2026
85bbb13
[O2B-1545] Add a composite primary key on GAQSummary table
isaachilly Jun 18, 2026
0b0b4a1
Update migration file to latest timestamp to show in order of applica…
graduta Dec 2, 2026
fe3a888
Bring model in-line with migration file
graduta Dec 2, 2026
d7d7049
Add typedef equivalents and record as to not conflict with existing ones
graduta Dec 2, 2026
90cd08f
Fix missing timestamp calculation on adapter
graduta Dec 2, 2026
8a4b788
Add flag for computedAt to be used in UI as to decide if a recalculat…
graduta Dec 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions lib/database/adapters/GaqSummaryAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

/**
* GaqSummaryAdapter
*/
class GaqSummaryAdapter {
/**
* Constructor
*/
constructor() {
this.toEntity = this.toEntity.bind(this);
}

/**
* Converts the given database object to an entity object.
*
* @param {SequelizeGaqSummary} databaseObject Object to convert.
* @returns {GaqSummaryRecord} Converted entity object.
*/
toEntity(databaseObject) {
const {
dataPassId,
runNumber,
badRunCoverage,
explicitlyNotBadRunCoverage,
mcReproducibleCoverage,
missingVerificationsCount,
undefinedQualityPeriodsCount,
notComputable,
invalidatedAt,
computedAt,
createdAt,
updatedAt,
} = databaseObject;

return {
dataPassId,
runNumber,
badRunCoverage,
explicitlyNotBadRunCoverage,
mcReproducibleCoverage,
missingVerificationsCount,
undefinedQualityPeriodsCount,
notComputable,
invalidatedAt: invalidatedAt ? new Date(invalidatedAt).getTime() : null,
computedAt: computedAt ? new Date(computedAt).getTime() : null,
createdAt: new Date(createdAt).getTime(),
updatedAt: new Date(updatedAt).getTime(),
};
}
}

module.exports = { GaqSummaryAdapter };
3 changes: 3 additions & 0 deletions lib/database/adapters/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const EorReasonAdapter = require('./EorReasonAdapter');
const FlpRoleAdapter = require('./FlpRoleAdapter');
const { HostAdapter } = require('./HostAdapter.js');
const { GaqDetectorAdapter } = require('./GaqDetectorAdapter.js');
const { GaqSummaryAdapter } = require('./GaqSummaryAdapter.js');
const { LhcFillAdapter } = require('./LhcFillAdapter.js');
const { LhcFillStatisticsAdapter } = require('./LhcFillStatisticsAdapter.js');
const LhcPeriodAdapter = require('./LhcPeriodAdapter');
Expand Down Expand Up @@ -63,6 +64,7 @@ const environmentHistoryItemAdapter = new EnvironmentHistoryItemAdapter();
const eorReasonAdapter = new EorReasonAdapter();
const flpRoleAdapter = new FlpRoleAdapter();
const gaqDetectorAdapter = new GaqDetectorAdapter();
const gaqSummaryAdapter = new GaqSummaryAdapter();
const hostAdapter = new HostAdapter();
const lhcFillAdapter = new LhcFillAdapter();
const lhcFillStatisticsAdapter = new LhcFillStatisticsAdapter();
Expand Down Expand Up @@ -164,6 +166,7 @@ module.exports = {
eorReasonAdapter,
flpRoleAdapter,
gaqDetectorAdapter,
gaqSummaryAdapter,
hostAdapter,
lhcFillAdapter,
lhcFillStatisticsAdapter,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface, Sequelize) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.createTable('gaq_summaries', {
data_pass_id: {
type: Sequelize.INTEGER,
primaryKey: true,
allowNull: false,
references: {
model: 'data_passes',
key: 'id',
},
},
run_number: {
type: Sequelize.INTEGER,
primaryKey: true,
allowNull: false,
references: {
model: 'runs',
key: 'run_number',
},
},
bad_run_coverage: {
type: Sequelize.FLOAT,
},
explicitly_not_bad_run_coverage: {
type: Sequelize.FLOAT,
},
mc_reproducible_coverage: {
type: Sequelize.FLOAT,
},
missing_verifications_count: {
type: Sequelize.INTEGER,
},
undefined_quality_periods_count: {
type: Sequelize.INTEGER,
},
not_computable: {
type: Sequelize.BOOLEAN,
allowNull: false,
defaultValue: false,
},
invalidated_at: {
type: Sequelize.DATE(3),
allowNull: true,
defaultValue: null,
},
computed_at: {
type: Sequelize.DATE(3),
allowNull: true,
defaultValue: null,
},
created_at: {
type: Sequelize.DATE(3),
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP(3)'),
},
updated_at: {
type: Sequelize.DATE(3),
allowNull: false,
defaultValue: Sequelize.literal('CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3)'),
},
}, { transaction });

await queryInterface.addIndex('gaq_summaries', {
name: 'gaq_summaries_invalidated_at_idx',
fields: ['invalidated_at'],
}, { transaction });
}),

down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.dropTable('gaq_summaries', { transaction });
}),
};
83 changes: 83 additions & 0 deletions lib/database/models/gaqSummary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

/*
* Stored GAQ (Global Aggregated Quality) summary, one row per run in a data pass
*
* - The three coverages (`badRunCoverage`, `explicitlyNotBadRunCoverage`, `mcReproducibleCoverage`) are the raw split of the run's
* data and are not combined: `badRunCoverage` does not include the mc reproducible part. The `mcReproducibleAsNotBad` option is
* applied when reading, so it must never be baked into the stored values
* - Null coverages and counts mean that the summary has never been computed, or is not computable (see `notComputable`)
* - `invalidatedAt` not null means that the summary is stale since that moment, and is to be recomputed
* - `computedAt` is the moment of the last successful computation, null if never computed. It is needed because `updatedAt`
* cannot tell it: `updatedAt` changes on any write to the row, including the ones that only set or clear `invalidatedAt`.
* It allows to display when the values were calculated, and to tell how old they are (`computedAt` against `invalidatedAt`)
* when investigating stale summaries
*/
module.exports = (sequelize) => {
const Sequelize = require('sequelize');

const GaqSummary = sequelize.define('GaqSummary', {
dataPassId: {
type: Sequelize.INTEGER,
primaryKey: true,
},
runNumber: {
type: Sequelize.INTEGER,
primaryKey: true,
},
badRunCoverage: {
type: Sequelize.FLOAT,
},
explicitlyNotBadRunCoverage: {
type: Sequelize.FLOAT,
},
mcReproducibleCoverage: {
type: Sequelize.FLOAT,
},
missingVerificationsCount: {
type: Sequelize.INTEGER,
},
undefinedQualityPeriodsCount: {
type: Sequelize.INTEGER,
},
notComputable: {
type: Sequelize.BOOLEAN,
allowNull: false,
defaultValue: false,
},
invalidatedAt: {
type: Sequelize.DATE(3),
},
computedAt: {
type: Sequelize.DATE(3),
},
}, {
tableName: 'gaq_summaries',
indexes: [
{
name: 'gaq_summaries_invalidated_at_idx',
fields: ['invalidated_at'],
},
],
});

GaqSummary.removeAttribute('id');

GaqSummary.associate = (models) => {
GaqSummary.belongsTo(models.Run, { foreignKey: 'runNumber', as: 'run' });
GaqSummary.belongsTo(models.DataPass, { foreignKey: 'dataPassId', as: 'dataPass' });
};

return GaqSummary;
};
2 changes: 2 additions & 0 deletions lib/database/models/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const EorReason = require('./eorreason');
const EpnRoleSession = require('./epnrolesession');
const FlpRole = require('./flprole');
const GaqDetector = require('./gaqDetector.js');
const GaqSummary = require('./gaqSummary.js');
const Host = require('./host.js');
const LhcFill = require('./lhcFill');
const LhcFillStatistics = require('./lhcFillStatistics.js');
Expand Down Expand Up @@ -66,6 +67,7 @@ module.exports = (sequelize) => {
EpnRoleSessionkey: EpnRoleSession(sequelize),
FlpRole: FlpRole(sequelize),
GaqDetector: GaqDetector(sequelize),
GaqSummary: GaqSummary(sequelize),
Host: Host(sequelize),
LhcFill: LhcFill(sequelize),
LhcFillStatistics: LhcFillStatistics(sequelize),
Expand Down
37 changes: 37 additions & 0 deletions lib/database/models/typedefs/SequelizeGaqSummary.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

/**
* @typedef SequelizeGaqSummary GAQ: Global Aggregated Quality, stored summary of a run in a data pass
*
* The three coverages are the raw split of the run's data by aggregated quality (bad, mc reproducible and explicitly
* not bad), and are NOT combined: `badRunCoverage` does not include `mcReproducibleCoverage`. Combining them according to
* `mcReproducibleAsNotBad` is done when the summary is read, so that toggling it does not require a recomputation.
*
* Coverages and counts are null when the summary has never been computed, or when it is not computable (see `notComputable`).
*
* @property {number} dataPassId
* @property {number} runNumber
* @property {number|null} badRunCoverage - fraction of run's data with aggregated quality bad, excluding mc reproducible
* @property {number|null} explicitlyNotBadRunCoverage - fraction of run's data with aggregated quality explicitly not bad
* @property {number|null} mcReproducibleCoverage - fraction of run's data with aggregated quality mc reproducible
* @property {number|null} missingVerificationsCount - number of QC flags that are unverified and have not been discarded
* @property {number|null} undefinedQualityPeriodsCount - number of GAQ periods with no QC flag, counted once per detector without flag
* @property {boolean} notComputable - true if the last computation could not produce a summary, coverages and counts are then null
* @property {Date|null} invalidatedAt - null if the summary is up to date, otherwise the moment since which it is stale
* @property {Date|null} computedAt - moment of the last successful computation, null if never computed. Unlike `updatedAt`, which
* changes on any write (including setting or clearing `invalidatedAt`), it changes only when the values are computed. It allows
* to display when the values were calculated and to tell how old they are when investigating stale summaries
* @property {Date} createdAt
* @property {Date} updatedAt
*/
33 changes: 33 additions & 0 deletions lib/database/repositories/GaqSummaryRepository.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

const {
models: {
GaqSummary,
},
} = require('..');
const Repository = require('./Repository');

/**
* GaqSummary repository
*/
class GaqSummaryRepository extends Repository {
/**
* Creates a new `GaqSummaryRepository` instance.
*/
constructor() {
super(GaqSummary);
}
}

module.exports = new GaqSummaryRepository();
2 changes: 2 additions & 0 deletions lib/database/repositories/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const EnvironmentRepository = require('./EnvironmentRepository');
const EorReasonRepository = require('./EorReasonRepository');
const FlpRoleRepository = require('./FlpRoleRepository');
const GaqDetectorRepository = require('./GaqDetectorRepository.js');
const GaqSummaryRepository = require('./GaqSummaryRepository.js');
const HostRepository = require('./HostRepository.js');
const LhcFillRepository = require('./LhcFillRepository');
const LhcFillStatisticsRepository = require('./LhcFillStatisticsRepository.js');
Expand Down Expand Up @@ -72,6 +73,7 @@ module.exports = {
EorReasonRepository,
FlpRoleRepository,
GaqDetectorRepository,
GaqSummaryRepository,
HostRepository,
LhcFillRepository,
LhcFillStatisticsRepository,
Expand Down
38 changes: 38 additions & 0 deletions lib/domain/entities/GaqSummaryRecord.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/

/**
* @typedef GaqSummaryRecord GAQ: Global Aggregated Quality, stored summary of a run in a data pass
*
* Not to be confused with `GaqSummary` (see QcSummary.js), which is the mapping from run number to the summary served by the API.
*
* The three coverages are the raw split of the run's data by aggregated quality (bad, mc reproducible and explicitly
* not bad), and are NOT combined: `badRunCoverage` does not include `mcReproducibleCoverage`.
*
* Coverages and counts are null when the summary has never been computed, or when it is not computable (see `notComputable`).
*
* @property {number} dataPassId
* @property {number} runNumber
* @property {number|null} badRunCoverage - fraction of run's data with aggregated quality bad, excluding mc reproducible
* @property {number|null} explicitlyNotBadRunCoverage - fraction of run's data with aggregated quality explicitly not bad
* @property {number|null} mcReproducibleCoverage - fraction of run's data with aggregated quality mc reproducible
* @property {number|null} missingVerificationsCount - number of QC flags that are unverified and have not been discarded
* @property {number|null} undefinedQualityPeriodsCount - number of GAQ periods with no QC flag, counted once per detector without flag
* @property {boolean} notComputable - true if the last computation could not produce a summary, coverages and counts are then null
* @property {number|null} invalidatedAt - null if the summary is up to date, otherwise the timestamp since which it is stale
* @property {number|null} computedAt - timestamp of the last successful computation, null if never computed. Unlike `updatedAt`,
* which changes on any write (including setting or clearing `invalidatedAt`), it changes only when the values are computed. It allows
* to display when the values were calculated and to tell how old they are when investigating stale summaries
* @property {number} createdAt
* @property {number} updatedAt
*/