-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[O2B-1224] Use weighted means for ALICE efficiency in statistics (#1529)
* [O2B-1224] Use weighted means for ALICE efficiency in statistics * Fix
- Loading branch information
1 parent
ddeedac
commit ca80c45
Showing
7 changed files
with
113 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
lib/database/migrations/20230901090207-include-fill-without-runs-in-statistics.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
lib/database/migrations/20240423072839-add-sb-duration-to-fill-statistics-view.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }); | ||
}), | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters