diff --git a/lib/database/repositories/QcFlagRepository.js b/lib/database/repositories/QcFlagRepository.js index 04b94b12bf..d031982c25 100644 --- a/lib/database/repositories/QcFlagRepository.js +++ b/lib/database/repositories/QcFlagRepository.js @@ -203,32 +203,17 @@ class QcFlagRepository extends Repository { GROUP_CONCAT(effectivePeriods.flagsList) AS flagsList, IF( - ( - COALESCE(run.time_trg_end, run.time_o2_end ) IS NULL - OR COALESCE(run.time_trg_start, run.time_o2_start) IS NULL - ), + run.time_start IS NULL OR run.time_end IS NULL, IF( - SUM( - COALESCE(effectivePeriods.\`to\` , 0) - + COALESCE(effectivePeriods.\`from\`, 0) - ) = 0, + effectivePeriods.\`from\` IS NULL AND effectivePeriods.\`to\` IS NULL, 1, null ), SUM( - COALESCE( - effectivePeriods.\`to\`, - UNIX_TIMESTAMP(run.time_trg_end), - UNIX_TIMESTAMP(run.time_o2_end) - ) - - COALESCE( - effectivePeriods.\`from\`, - UNIX_TIMESTAMP(run.time_trg_start), - UNIX_TIMESTAMP(run.time_o2_start) - ) + COALESCE(effectivePeriods.\`to\`, UNIX_TIMESTAMP(run.time_end)) + - COALESCE(effectivePeriods.\`from\`, UNIX_TIMESTAMP(run.time_start)) ) / ( - UNIX_TIMESTAMP(COALESCE(run.time_trg_end, run.time_o2_end)) - - UNIX_TIMESTAMP(COALESCE(run.time_trg_start, run.time_o2_start)) + UNIX_TIMESTAMP(run.time_end) - UNIX_TIMESTAMP(run.time_start) ) ) AS effectiveRunCoverage diff --git a/lib/server/services/qualityControlFlag/QcFlagService.js b/lib/server/services/qualityControlFlag/QcFlagService.js index 4481618791..87416847eb 100644 --- a/lib/server/services/qualityControlFlag/QcFlagService.js +++ b/lib/server/services/qualityControlFlag/QcFlagService.js @@ -264,35 +264,20 @@ class QcFlagService { [ sequelize.literal(` IF( - ( - COALESCE(run.time_trg_end, run.time_o2_end ) IS NULL - OR COALESCE(run.time_trg_start, run.time_o2_start) IS NULL - ), + run.time_start IS NULL OR run.time_end IS NULL, IF( - SUM( - COALESCE(UNIX_TIMESTAMP(effectivePeriods.\`to\` ), 0) - + COALESCE(UNIX_TIMESTAMP(effectivePeriods.\`from\`), 0) - ) = 0, + effectivePeriods.\`from\` IS NULL AND effectivePeriods.\`to\` IS NULL, 1, null ), SUM( - UNIX_TIMESTAMP(COALESCE( - effectivePeriods.\`to\`, - run.time_trg_end, - run.time_o2_end - )) - - UNIX_TIMESTAMP(COALESCE( - effectivePeriods.\`from\`, - run.time_trg_start, - run.time_o2_start - )) + UNIX_TIMESTAMP(COALESCE(effectivePeriods.\`to\`, run.time_end)) + - UNIX_TIMESTAMP(COALESCE(effectivePeriods.\`from\`, run.time_start)) ) / ( - UNIX_TIMESTAMP(COALESCE(run.time_trg_end, run.time_o2_end)) - - UNIX_TIMESTAMP(COALESCE(run.time_trg_start, run.time_o2_start)) + UNIX_TIMESTAMP(run.time_end) - UNIX_TIMESTAMP(run.time_start) ) ) - `), + `), 'effectiveRunCoverage', ], [ diff --git a/lib/server/services/run/setO2StopOfLostRuns.js b/lib/server/services/run/setO2StopOfLostRuns.js index 439ae79e68..282ee166db 100644 --- a/lib/server/services/run/setO2StopOfLostRuns.js +++ b/lib/server/services/run/setO2StopOfLostRuns.js @@ -28,9 +28,9 @@ exports.setO2StopOfLostRuns = async (runNumbersOfRunningRuns, modificationTimePe FROM runs WHERE time_o2_end IS NULL AND time_trg_end IS NULL - AND COALESCE(time_trg_start, time_o2_start) IS NOT NULL - AND COALESCE(time_trg_start, time_o2_start) >= '${timestampToMysql(modificationTimePeriod.from, true)}' - AND COALESCE(time_trg_start, time_o2_start) < '${timestampToMysql(modificationTimePeriod.to, true)}' + AND time_start IS NOT NULL + AND time_start >= '${timestampToMysql(modificationTimePeriod.from, true)}' + AND time_start < '${timestampToMysql(modificationTimePeriod.to, true)}' `; if (runNumbersOfRunningRuns.length > 0) { fetchQuery += ` AND run_number NOT IN (${runNumbersOfRunningRuns.join(',')})`;