Skip to content

Commit

Permalink
[O2B-1224] Use weighted means for ALICE efficiency in statistics (#1529)
Browse files Browse the repository at this point in the history
* [O2B-1224] Use weighted means for ALICE efficiency in statistics

* Fix
  • Loading branch information
martinboulais committed Apr 25, 2024
1 parent ddeedac commit ca80c45
Show file tree
Hide file tree
Showing 7 changed files with 113 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lib/database/adapters/LhcFillStatisticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class LhcFillStatisticsAdapter {
toEntity(databaseObject) {
const {
fillNumber,
stableBeamsDuration,
runsCoverage,
efficiency,
timeLossAtStart,
Expand All @@ -38,6 +39,8 @@ class LhcFillStatisticsAdapter {
return {
fillNumber,
// Convert to ms
stableBeamsDuration: stableBeamsDuration * 1000,
// Convert to ms
runsCoverage: runsCoverage * 1000,
efficiency: parseFloat(efficiency),
// Convert to ms
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/**
* @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.
*/

'use strict';

const ROLLBACK_FILL_STATISTICS_TO_PREVIOUS = `
Expand Down
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.
*/

'use strict';

const UPDATE_FILL_STATISTICS_VIEW = `
CREATE OR REPLACE VIEW fill_statistics AS
SELECT lf.fill_number,
-- Use max to comply with gruop by, but all the values are the same in the group
COALESCE(MAX(sbr.sb_duration), 0) stable_beams_duration,
SUM(sbr.sb_run_duration) runs_coverage,
SUM(COALESCE(sbr.sb_run_duration / sbr.sb_duration, 0)) efficiency,
COALESCE(
TO_SECONDS(MIN(sbr.sb_run_start)) - TO_SECONDS(MAX(sbr.sb_start)),
0
) time_loss_at_start,
COALESCE(
(TO_SECONDS(MIN(sbr.sb_run_start)) - TO_SECONDS(MAX(sbr.sb_start))) / MAX(sbr.sb_duration),
0
) efficiency_loss_at_start,
COALESCE(TO_SECONDS(MIN(sbr.sb_end)) - TO_SECONDS(MAX(sbr.sb_run_end)), 0) time_loss_at_end,
COALESCE(
(TO_SECONDS(MIN(sbr.sb_end)) - TO_SECONDS(MAX(sbr.sb_run_end))) / MAX(sbr.sb_duration),
0
) efficiency_loss_at_end,
COALESCE(AVG(sbr.sb_run_duration), 0) mean_run_duration,
COALESCE(SUM(r.ctf_file_size), 0) total_ctf_file_size,
COALESCE(SUM(r.tf_file_size), 0) total_tf_file_size
FROM lhc_fills lf
LEFT JOIN runs r ON r.fill_number = lf.fill_number AND r.definition = 'PHYSICS' AND r.run_quality = 'good'
LEFT JOIN stable_beam_runs sbr ON sbr.run_number = r.run_number
WHERE lf.stable_beams_start IS NOT NULL
GROUP BY lf.fill_number;
`;

const ROLLBACK_FILL_STATISTICS_TO_PREVIOUS = `
CREATE OR REPLACE VIEW fill_statistics AS
SELECT lf.fill_number,
SUM(sbr.sb_run_duration) runs_coverage,
SUM(COALESCE(sbr.sb_run_duration / sbr.sb_duration, 0)) efficiency,
COALESCE(
TO_SECONDS(MIN(sbr.sb_run_start)) - TO_SECONDS(MAX(sbr.sb_start)),
0
) time_loss_at_start,
COALESCE(
(TO_SECONDS(MIN(sbr.sb_run_start)) - TO_SECONDS(MAX(sbr.sb_start))) / MAX(sbr.sb_duration),
0
) efficiency_loss_at_start,
COALESCE(TO_SECONDS(MIN(sbr.sb_end)) - TO_SECONDS(MAX(sbr.sb_run_end)), 0) time_loss_at_end,
COALESCE(
(TO_SECONDS(MIN(sbr.sb_end)) - TO_SECONDS(MAX(sbr.sb_run_end))) / MAX(sbr.sb_duration),
0
) efficiency_loss_at_end,
COALESCE(AVG(sbr.sb_run_duration), 0) mean_run_duration,
COALESCE(SUM(r.ctf_file_size), 0) total_ctf_file_size,
COALESCE(SUM(r.tf_file_size), 0) total_tf_file_size
FROM lhc_fills lf
LEFT JOIN runs r ON r.fill_number = lf.fill_number AND r.definition = 'PHYSICS' AND r.run_quality = 'good'
LEFT JOIN stable_beam_runs sbr ON sbr.run_number = r.run_number
WHERE lf.stable_beams_start IS NOT NULL
GROUP BY lf.fill_number;
`;

/** @type {import('sequelize-cli').Migration} */
module.exports = {
up: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query(UPDATE_FILL_STATISTICS_VIEW, { transaction });
}),

down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query(ROLLBACK_FILL_STATISTICS_TO_PREVIOUS, { transaction });
}),
};
4 changes: 4 additions & 0 deletions lib/database/models/lhcFillStatistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ module.exports = (sequelize) => {
type: Sequelize.NUMBER,
primaryKey: true,
},
stableBeamsDuration: {
allowNull: false,
type: Sequelize.NUMBER,
},
runsCoverage: {
allowNull: false,
type: Sequelize.NUMBER,
Expand Down
1 change: 1 addition & 0 deletions lib/database/models/typedefs/SequelizeLhcFillStatistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @typedef SequelizeLhcFillStatistics
*
* @property {number} fillNumber the fill number to which the statistics applies to
* @property {number} stableBeamsDuration the duration of the fill stable beams
* @property {number} runsCoverage total duration covered by at least one run (in seconds)
* @property {string} efficiency efficiency of the fill
* @property {number} timeLossAtStart duration between the start of the fill and the start of the first run (in seconds)
Expand Down
1 change: 1 addition & 0 deletions lib/domain/entities/statistics/LhcFillStatistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @typedef LhcFillStatistics
*
* @property {number} fillNumber the fill number to which the statistics applies to
* @property {number} stableBeamsDuration the total stable beam duration of the fill
* @property {number} runsCoverage total duration covered by at least one run (in ms)
* @property {number} efficiency efficiency of the fill
* @property {number} timeLossAtStart duration between the start of the fill and the start of the first run (in ms)
Expand Down
12 changes: 8 additions & 4 deletions lib/public/views/Statistics/charts/efficiencyChartComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ import { formatPercentage } from '../../../utilities/formatting/formatPercentage
*/
export const efficiencyChartComponent = (statistics, onPointHover, periodLabel) => {
const points = [];
let efficiencySum = 0;
for (const { fillNumber, efficiency, efficiencyLossAtStart } of statistics) {
let totalRunsCoverage = 0;
let totalStableBeamDuration = 0;
for (const { fillNumber, stableBeamsDuration, runsCoverage, efficiency, efficiencyLossAtStart } of statistics) {
points.push({
x: fillNumber,
y: [efficiency + efficiencyLossAtStart, efficiency],
});
efficiencySum += efficiency;

totalRunsCoverage += runsCoverage;
totalStableBeamDuration += stableBeamsDuration;
}

const meanEfficiency = efficiencySum / points.length;
const meanEfficiency = totalRunsCoverage / totalStableBeamDuration;

if (points.length) {
points[0].y.push(meanEfficiency);
points[points.length - 1].y.push(meanEfficiency);
Expand Down

0 comments on commit ca80c45

Please sign in to comment.