-
Notifications
You must be signed in to change notification settings - Fork 22
[O2B-1365] Implement GAQ periods views #1808
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
59 commits
Select commit
Hold shift + click to select a range
03ca36e
use tf_timestamps
xsalonx 2436041
use miliseconds
xsalonx 06268f2
remove names
xsalonx d6e7fcb
use views
xsalonx 1658d1d
fix tests, preserve previous functionalties
xsalonx 068d48c
fix
xsalonx 4ee19e7
fix test
xsalonx 10be130
fix test
xsalonx a7a7b54
fix test
xsalonx 1ee8bab
fix seeders
xsalonx e152c6e
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx 3fb54a5
use timeframe timestamps
xsalonx e34e920
Merge branch 'tmp' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx db84fcc
ref
xsalonx 5f900f8
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx 4199b3f
cleanup
xsalonx 53f093a
a
xsalonx 9de457c
cleanup; fix
xsalonx dc33aa6
a
xsalonx 86cb1fc
use correct field
xsalonx b56bc51
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
martinboulais 4a9ea38
Update lib/database/migrations/20241127123000-create-gaq-views.js
xsalonx ccc1e9f
merge WIP
xsalonx b947915
WIP
xsalonx 0843796
WIP
xsalonx 85a99d3
use significance aggregate functions for gaq calculation
xsalonx 104bf3b
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx c7646f9
cleanup
xsalonx 9d82581
count periods of undefined quality
xsalonx d65a014
add QC and GAQ summaries typdefs
xsalonx ebe79c1
cleanup, test disable
xsalonx 95b6235
fix view name
xsalonx 2e33ad9
revert test changes
xsalonx 36a7615
cleanup
xsalonx 4868232
add diaply for debugging
xsalonx 9f7b448
fix sql queries
xsalonx cd11cfd
fixes
xsalonx df09904
try to fix test
xsalonx d544933
Merge branch 'x' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx e66a585
fix
xsalonx 8b94ca3
fix
xsalonx 7c2e0d1
Revert "try to fix test"
xsalonx 4ad018e
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx 08cbbda
cleanup
xsalonx 686d09e
rename enum
xsalonx 009e635
move enum
xsalonx 71090a6
cleanup
xsalonx 93acd3f
fix
xsalonx df62090
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx b3c7e02
temporarly skipsome tests
xsalonx 2b0a0d3
cleanup
xsalonx 0379fd5
simplify
xsalonx e572efb
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx d0e4393
Merge branch 'main' of github.com:AliceO2Group/Bookkeeping into xsalo…
graduta f9889f6
Fix lint
graduta 810f663
remove unnecessary test skips
xsalonx d11eafc
rename
xsalonx d722819
linter
xsalonx 7f51328
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
135 changes: 135 additions & 0 deletions
135
lib/database/migrations/20241127123000-create-gaq-views.js
This file contains hidden or 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,135 @@ | ||
| 'use strict'; | ||
|
|
||
| const CREATE_GAQ_PERIODS_TIMESTAMPS_VIEW = ` | ||
| CREATE OR REPLACE VIEW gaq_periods_timestamps AS | ||
| SELECT | ||
| data_pass_id, | ||
| run_number, | ||
| timestamp AS \`from\`, | ||
| NTH_VALUE(timestamp, 2) OVER ( | ||
| PARTITION BY data_pass_id, | ||
| run_number | ||
| ORDER BY ap.timestamp | ||
| ROWS BETWEEN CURRENT ROW AND 1 FOLLOWING | ||
| ) AS \`to\` | ||
| FROM ( | ||
| -- Two selects for runs' timestamps (in case QC flag's eff. period doesn't start at run's start or end at run's end ) | ||
| ( | ||
| SELECT gaqd.data_pass_id, | ||
| gaqd.run_number, | ||
| COALESCE(UNIX_TIMESTAMP(first_tf_timestamp), UNIX_TIMESTAMP(time_start), 0) AS timestamp | ||
| FROM global_aggregated_quality_detectors AS gaqd | ||
| INNER JOIN runs as r | ||
| ON gaqd.run_number = r.run_number | ||
| ) | ||
| UNION | ||
| ( | ||
| SELECT gaqd.data_pass_id, | ||
| gaqd.run_number, | ||
| UNIX_TIMESTAMP(COALESCE(last_tf_timestamp, time_end, NOW(3))) AS timestamp | ||
| FROM global_aggregated_quality_detectors AS gaqd | ||
| INNER JOIN runs as r | ||
| ON gaqd.run_number = r.run_number | ||
| ) | ||
| UNION | ||
| -- Two selectes for timestamps of QC flags' effective periods | ||
|
xsalonx marked this conversation as resolved.
Outdated
|
||
| ( | ||
| SELECT gaqd.data_pass_id, | ||
| gaqd.run_number, | ||
| COALESCE(UNIX_TIMESTAMP(qcfep.\`from\`), 0) AS timestamp | ||
| FROM quality_control_flag_effective_periods AS qcfep | ||
| INNER JOIN quality_control_flags AS qcf ON qcf.id = qcfep.flag_id | ||
| INNER JOIN data_pass_quality_control_flag AS dpqcf ON dpqcf.quality_control_flag_id = qcf.id | ||
| -- Only flags of detectors which are defined in global_aggregated_quality_detectors | ||
| -- should be taken into account for calculation of gaq_effective_periods | ||
| INNER JOIN global_aggregated_quality_detectors AS gaqd | ||
| ON gaqd.data_pass_id = dpqcf.data_pass_id | ||
| AND gaqd.run_number = qcf.run_number | ||
| AND gaqd.detector_id = qcf.detector_id | ||
| ) | ||
| UNION | ||
| ( | ||
| SELECT gaqd.data_pass_id, | ||
| gaqd.run_number, | ||
| UNIX_TIMESTAMP(COALESCE(qcfep.\`to\`, NOW(3))) AS timestamp | ||
| FROM quality_control_flag_effective_periods AS qcfep | ||
| INNER JOIN quality_control_flags AS qcf ON qcf.id = qcfep.flag_id | ||
| INNER JOIN data_pass_quality_control_flag AS dpqcf ON dpqcf.quality_control_flag_id = qcf.id | ||
| -- Only flags of detectors which are defined in global_aggregated_quality_detectors | ||
| -- should be taken into account for calculation of gaq_effective_periods | ||
| INNER JOIN global_aggregated_quality_detectors AS gaqd | ||
| ON gaqd.data_pass_id = dpqcf.data_pass_id | ||
| AND gaqd.run_number = qcf.run_number | ||
| AND gaqd.detector_id = qcf.detector_id | ||
| ) | ||
| ORDER BY timestamp | ||
| ) AS ap | ||
| `; | ||
|
|
||
| const DROP_GAQ_PERIODS_TIMESTAMPS_VIEW = 'DROP VIEW gaq_periods_timestamps'; | ||
|
|
||
| const CREATE_GAQ_PERIODS_VIEW = ` | ||
| CREATE OR REPLACE VIEW gaq_periods AS | ||
| SELECT | ||
| gaq_periods_timestamps.data_pass_id AS dataPassId, | ||
| gaq_periods_timestamps.run_number AS runNumber, | ||
| IF(gaq_periods_timestamps.\`from\` = 0, null, gaq_periods_timestamps.\`from\`) AS \`from\`, | ||
| IF(gaq_periods_timestamps.\`to\` = UNIX_TIMESTAMP(NOW(3)), null, gaq_periods_timestamps.\`to\`) AS \`to\`, | ||
| IF(COUNT( DISTINCT gaqd.detector_id ) > COUNT( DISTINCT qcfep.flag_id ), | ||
| null, | ||
| SUM(qcft.bad) >= 1 | ||
| ) AS bad, | ||
| IF(COUNT( DISTINCT gaqd.detector_id ) > COUNT( DISTINCT qcfep.flag_id ), | ||
| null, | ||
| SUM(IF(qcft.monte_carlo_reproducible, false, qcft.bad)) >= 1 | ||
| ) AS badWhenMcReproducibleAsNotBad, | ||
| SUM(qcft.bad) = SUM(qcft.monte_carlo_reproducible) AND SUM(qcft.monte_carlo_reproducible) AS mcReproducible, | ||
| GROUP_CONCAT( DISTINCT qcfv.flag_id ) AS verifiedFlagsList, | ||
| GROUP_CONCAT( DISTINCT qcfep.flag_id ) AS flagsList | ||
|
|
||
| FROM gaq_periods_timestamps | ||
| INNER JOIN global_aggregated_quality_detectors AS gaqd | ||
| ON gaqd.data_pass_id = gaq_periods_timestamps.data_pass_id | ||
| AND gaqd.run_number = gaq_periods_timestamps.run_number | ||
|
|
||
| LEFT JOIN ( | ||
| data_pass_quality_control_flag AS dpqcf | ||
| INNER JOIN quality_control_flags AS qcf | ||
| ON dpqcf.quality_control_flag_id = qcf.id | ||
| INNER JOIN quality_control_flag_types AS qcft | ||
| ON qcft.id = qcf.flag_type_id | ||
| INNER JOIN quality_control_flag_effective_periods AS qcfep | ||
| ON qcf.id = qcfep.flag_id | ||
| LEFT JOIN quality_control_flag_verifications AS qcfv | ||
| ON qcfv.flag_id = qcf.id | ||
| ) | ||
| ON gaq_periods_timestamps.data_pass_id = dpqcf.data_pass_id | ||
| AND qcf.run_number = gaq_periods_timestamps.run_number | ||
| AND gaqd.detector_id = qcf.detector_id | ||
| AND gaq_periods_timestamps.run_number = qcf.run_number | ||
| AND (qcfep.\`from\` IS NULL OR UNIX_TIMESTAMP(qcfep.\`from\`) <= gaq_periods_timestamps.\`from\`) | ||
| AND (qcfep.\`to\` IS NULL OR gaq_periods_timestamps.\`to\` <= UNIX_TIMESTAMP(qcfep.\`to\`)) | ||
|
|
||
| WHERE gaq_periods_timestamps.\`to\` IS NOT null | ||
|
|
||
| GROUP BY | ||
| gaq_periods_timestamps.data_pass_id, | ||
| gaq_periods_timestamps.run_number, | ||
| IF(gaq_periods_timestamps.\`from\` = 0, null, gaq_periods_timestamps.\`from\`), | ||
| IF(gaq_periods_timestamps.\`to\` = UNIX_TIMESTAMP(NOW(3)), null, gaq_periods_timestamps.\`to\`) | ||
| `; | ||
|
|
||
| const DROP_GAQ_PERIODS_VIEW = 'DROP VIEW gaq_periods'; | ||
|
|
||
| /** @type {import('sequelize-cli').Migration} */ | ||
| module.exports = { | ||
| up: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => { | ||
| await queryInterface.sequelize.query(CREATE_GAQ_PERIODS_TIMESTAMPS_VIEW, { transaction }); | ||
| await queryInterface.sequelize.query(CREATE_GAQ_PERIODS_VIEW, { transaction }); | ||
| }), | ||
|
|
||
| down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => { | ||
| await queryInterface.sequelize.query(DROP_GAQ_PERIODS_VIEW, { transaction }); | ||
| await queryInterface.sequelize.query(DROP_GAQ_PERIODS_TIMESTAMPS_VIEW, { transaction }); | ||
| }), | ||
| }; | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.