Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
03ca36e
use tf_timestamps
xsalonx Dec 3, 2024
2436041
use miliseconds
xsalonx Dec 3, 2024
06268f2
remove names
xsalonx Dec 3, 2024
d6e7fcb
use views
xsalonx Dec 3, 2024
1658d1d
fix tests, preserve previous functionalties
xsalonx Dec 3, 2024
068d48c
fix
xsalonx Dec 3, 2024
4ee19e7
fix test
xsalonx Dec 3, 2024
10be130
fix test
xsalonx Dec 3, 2024
a7a7b54
fix test
xsalonx Dec 3, 2024
1ee8bab
fix seeders
xsalonx Dec 3, 2024
e152c6e
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx Dec 4, 2024
3fb54a5
use timeframe timestamps
xsalonx Dec 11, 2024
e34e920
Merge branch 'tmp' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx Dec 11, 2024
db84fcc
ref
xsalonx Dec 11, 2024
5f900f8
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx Dec 11, 2024
4199b3f
cleanup
xsalonx Dec 11, 2024
53f093a
a
xsalonx Dec 11, 2024
9de457c
cleanup; fix
xsalonx Dec 11, 2024
dc33aa6
a
xsalonx Dec 11, 2024
86cb1fc
use correct field
xsalonx Dec 11, 2024
b56bc51
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
martinboulais Jan 28, 2025
4a9ea38
Update lib/database/migrations/20241127123000-create-gaq-views.js
xsalonx Feb 19, 2025
ccc1e9f
merge WIP
xsalonx Apr 30, 2025
b947915
WIP
xsalonx Apr 30, 2025
0843796
WIP
xsalonx Apr 30, 2025
85a99d3
use significance aggregate functions for gaq calculation
xsalonx May 19, 2025
104bf3b
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx May 19, 2025
c7646f9
cleanup
xsalonx May 19, 2025
9d82581
count periods of undefined quality
xsalonx May 19, 2025
d65a014
add QC and GAQ summaries typdefs
xsalonx May 19, 2025
ebe79c1
cleanup, test disable
xsalonx May 19, 2025
95b6235
fix view name
xsalonx May 19, 2025
2e33ad9
revert test changes
xsalonx May 19, 2025
36a7615
cleanup
xsalonx May 19, 2025
4868232
add diaply for debugging
xsalonx May 19, 2025
9f7b448
fix sql queries
xsalonx May 19, 2025
cd11cfd
fixes
xsalonx May 19, 2025
df09904
try to fix test
xsalonx May 20, 2025
d544933
Merge branch 'x' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx May 20, 2025
e66a585
fix
xsalonx May 20, 2025
8b94ca3
fix
xsalonx May 21, 2025
7c2e0d1
Revert "try to fix test"
xsalonx May 21, 2025
4ad018e
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx May 21, 2025
08cbbda
cleanup
xsalonx May 21, 2025
686d09e
rename enum
xsalonx May 29, 2025
009e635
move enum
xsalonx May 29, 2025
71090a6
cleanup
xsalonx May 29, 2025
93acd3f
fix
xsalonx May 29, 2025
df62090
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx May 29, 2025
b3c7e02
temporarly skipsome tests
xsalonx May 30, 2025
2b0a0d3
cleanup
xsalonx May 30, 2025
0379fd5
simplify
xsalonx Jun 4, 2025
e572efb
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx Jun 4, 2025
d0e4393
Merge branch 'main' of github.com:AliceO2Group/Bookkeeping into xsalo…
graduta Jun 27, 2025
f9889f6
Fix lint
graduta Jun 27, 2025
810f663
remove unnecessary test skips
xsalonx Jul 17, 2025
d11eafc
rename
xsalonx Jul 17, 2025
d722819
linter
xsalonx Jul 17, 2025
7f51328
Merge branch 'main' into xsalonx/gaq/O2B-1365/just-gaq-views
xsalonx Jul 17, 2025
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
168 changes: 168 additions & 0 deletions lib/database/migrations/v1/20250518123000-create-gaq-views.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
'use strict';

const SELECT_RUNS_START_TIMESTAMPS_FOR_GAQ_PERIODS = `
SELECT
gaqd.data_pass_id,
gaqd.run_number,
r.qc_time_start AS timestamp,
COALESCE(r.qc_time_start, '0001-01-01 00:00:00.000') AS ordering_timestamp,
r.qc_time_start AS qc_run_start,
r.qc_time_end AS qc_run_end
FROM global_aggregated_quality_detectors AS gaqd
INNER JOIN runs as r ON gaqd.run_number = r.run_number
INNER JOIN quality_control_flags AS qcf ON qcf.run_number = r.run_number
INNER JOIN data_pass_quality_control_flag AS dpqcf
ON dpqcf.quality_control_flag_id = qcf.id AND dpqcf.data_pass_id = gaqd.data_pass_id
`;

const SELECT_RUNS_END_TIMESTAMPS_FOR_GAQ_PERIODS = `
SELECT
gaqd.data_pass_id,
gaqd.run_number,
r.qc_time_end AS timestamp,
COALESCE(r.qc_time_end, NOW(3)) AS ordering_timestamp,
r.qc_time_start AS qc_run_start,
r.qc_time_end AS qc_run_end
FROM global_aggregated_quality_detectors AS gaqd
INNER JOIN runs as r ON gaqd.run_number = r.run_number
INNER JOIN quality_control_flags AS qcf ON qcf.run_number = r.run_number
INNER JOIN data_pass_quality_control_flag AS dpqcf
ON dpqcf.quality_control_flag_id = qcf.id AND dpqcf.data_pass_id = gaqd.data_pass_id
`;

const SELECT_QCF_EFFECTIVE_PERIODS_START_TIMESTAMPS_FOR_GAQ_PERIODS = `
SELECT gaqd.data_pass_id,
gaqd.run_number,
COALESCE(qcfep.\`from\`, r.qc_time_start) AS timestamp,
COALESCE(qcfep.\`from\`, r.qc_time_start, '0001-01-01 00:00:00.000') AS ordering_timestamp,
r.qc_time_start AS qc_run_start,
r.qc_time_end AS qc_run_end
FROM quality_control_flag_effective_periods AS qcfep
INNER JOIN quality_control_flags AS qcf ON qcf.id = qcfep.flag_id
INNER JOIN runs AS r ON qcf.run_number = r.run_number
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
`;

const SELECT_QCF_EFFECTIVE_PERIODS_END_TIMESTAMPS_FOR_GAQ_PERIODS = `
SELECT gaqd.data_pass_id,
gaqd.run_number,
COALESCE(qcfep.\`to\`, r.qc_time_end) AS timestamp,
COALESCE(qcfep.\`to\`, r.qc_time_end, NOW(3)) AS ordering_timestamp,
r.qc_time_start AS qc_run_start,
r.qc_time_end AS qc_run_end
FROM quality_control_flag_effective_periods AS qcfep
INNER JOIN quality_control_flags AS qcf ON qcf.id = qcfep.flag_id
INNER JOIN runs AS r ON qcf.run_number = r.run_number
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
`;

const CREATE_GAQ_PERIODS_VIEW = `
CREATE OR REPLACE VIEW gaq_periods AS
SELECT
data_pass_id,
run_number,
\`from\`,
\`to\`,
from_ordering_timestamp,
(UNIX_TIMESTAMP(\`to\`) - UNIX_TIMESTAMP(\`from\`)) / (UNIX_TIMESTAMP(qc_run_end) - UNIX_TIMESTAMP(qc_run_start)) AS coverage_ratio
FROM (
SELECT
data_pass_id,
run_number,
LAG(timestamp) OVER w AS \`from\`,
timestamp AS \`to\`,
LAG(ordering_timestamp) OVER w AS from_ordering_timestamp,
qc_run_start,
qc_run_end
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_RUNS_START_TIMESTAMPS_FOR_GAQ_PERIODS} )
UNION
( ${SELECT_RUNS_END_TIMESTAMPS_FOR_GAQ_PERIODS} )
UNION
-- Two selects for timestamps of QC flags' effective periods
( ${SELECT_QCF_EFFECTIVE_PERIODS_START_TIMESTAMPS_FOR_GAQ_PERIODS} )
UNION
( ${SELECT_QCF_EFFECTIVE_PERIODS_END_TIMESTAMPS_FOR_GAQ_PERIODS} )

ORDER BY ordering_timestamp
) AS ap
WINDOW w AS (
PARTITION BY data_pass_id,
run_number
ORDER BY ap.ordering_timestamp
)
) as gaq_periods_with_last_nullish_row
WHERE gaq_periods_with_last_nullish_row.from_ordering_timestamp IS NOT NULL
`;

const DROP_GAQ_PERIODS_VIEW = 'DROP VIEW gaq_periods';

const CREATE_QC_FLAG_BLOCK_SIGNIFCANCE_AGGREGATE_FUNCTION = `
CREATE OR REPLACE AGGREGATE FUNCTION qc_flag_block_significance(
row_bad TINYINT(1),
row_mc_reproducible TINYINT(1)
) RETURNS ENUM ('bad', 'mcr', 'good')
BEGIN
DECLARE mc_reproducible TINYINT(1) DEFAULT 0;
DECLARE bad TINYINT(1) DEFAULT 0;
DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN IF(bad, 'bad', IF(mc_reproducible, 'mcr', 'good'));
LOOP
FETCH group NEXT ROW;
IF row_mc_reproducible THEN
SET mc_reproducible = 1;
ELSEIF row_bad THEN
SET bad = 1;
END IF;
END LOOP;
END
`;

const DROP_QC_FLAG_BLOCK_SIGNIFCANCE_AGGREGATE_FUNCTION = 'DROP FUNCTION qc_flag_block_significance';

const CREATE_QC_FLAG_BLOCK_SIGNIFCANCE_COVERAGE_AGGREGATE_FUNCTION = `
CREATE OR REPLACE AGGREGATE FUNCTION qc_flag_block_significance_coverage(
row_significance ENUM ('bad', 'mcr', 'good'), -- The significance of the row
coverage_ratio FLOAT, -- The coverage ratio of the row
significance ENUM ('bad', 'mcr', 'good') -- The significance to aggregate over
) RETURNS FLOAT
BEGIN
DECLARE coverage FLOAT DEFAULT 0;
DECLARE CONTINUE HANDLER FOR NOT FOUND RETURN coverage;
LOOP
FETCH group NEXT ROW;
IF row_significance = significance THEN
SET coverage = coverage + coverage_ratio;
END IF;
END LOOP;
END
`;

const DROP_QC_FLAG_BLOCK_SIGNIFCANCE_COVERAGE_AGGREGATE_FUNCTION = 'DROP FUNCTION qc_flag_block_significance_coverage';

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

down: async (queryInterface) => queryInterface.sequelize.transaction(async (transaction) => {
await queryInterface.sequelize.query(DROP_GAQ_PERIODS_VIEW, { transaction });
await queryInterface.sequelize.query(DROP_QC_FLAG_BLOCK_SIGNIFCANCE_AGGREGATE_FUNCTION, { transaction });
await queryInterface.sequelize.query(DROP_QC_FLAG_BLOCK_SIGNIFCANCE_COVERAGE_AGGREGATE_FUNCTION, { transaction });
}),
};
Loading