Skip to content
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

[O2B-1325] GAQ Summary API #1683

Merged
merged 183 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
183 commits
Select commit Hold shift + click to select a range
04a3fa7
add
xsalonx Jun 20, 2024
ccc0718
Merge branch 'main' into xsalonx/QCF/O2B-1274/add-AGQ
xsalonx Jul 2, 2024
56a561e
rm AGQ adapter|
xsalonx Jul 2, 2024
5c830fb
add func to Qcservice
xsalonx Jul 2, 2024
983efc2
Merge branch 'main' into xsalonx/QCF/O2B-1274/add-AGQ
xsalonx Jul 8, 2024
2507a8d
WIP
xsalonx Jul 8, 2024
e99b517
fix
xsalonx Jul 8, 2024
8c9a949
typo
xsalonx Jul 9, 2024
6b07738
rename, reF
xsalonx Jul 9, 2024
ce0d25c
rename
xsalonx Jul 9, 2024
3940e0f
Merge branch 'main' into xsalonx/QCF/O2B-1274/add-AGQ
xsalonx Jul 9, 2024
e82e9c0
cleanup
xsalonx Jul 9, 2024
2001d11
add controller
xsalonx Jul 9, 2024
c11aebf
expose controller
xsalonx Jul 10, 2024
8abf8af
fix
xsalonx Jul 10, 2024
444065f
add test
xsalonx Jul 10, 2024
f3a0011
test
xsalonx Jul 10, 2024
d1f4ce2
typo
xsalonx Jul 10, 2024
29f24a9
cleanup
xsalonx Jul 10, 2024
7e1a3ff
factorize
xsalonx Jul 10, 2024
f707b40
docs
xsalonx Jul 10, 2024
f7159d2
validation
xsalonx Jul 10, 2024
235e14b
docs
xsalonx Jul 10, 2024
0e06d95
change path
xsalonx Jul 10, 2024
f9c823a
fix test
xsalonx Jul 10, 2024
376a56b
docs fix
xsalonx Jul 10, 2024
71f965f
add typdefs
xsalonx Jul 10, 2024
ad94c0d
alph-order
xsalonx Jul 10, 2024
e8af9d8
w
xsalonx Jul 10, 2024
987d59f
a
xsalonx Jul 10, 2024
879747a
cleanup
xsalonx Jul 10, 2024
5fae045
cleanup
xsalonx Jul 10, 2024
68fff29
expose
xsalonx Jul 10, 2024
6281c86
use ehole flag
xsalonx Jul 10, 2024
70f83b0
add front
xsalonx Jul 10, 2024
58e7dfd
add display
xsalonx Jul 10, 2024
646fe9d
docs
xsalonx Jul 10, 2024
c653500
expose
xsalonx Jul 10, 2024
c805f87
add act
xsalonx Jul 10, 2024
b7df127
exp, TODO use no PAGE model
xsalonx Jul 10, 2024
1fd84b1
test WIP
xsalonx Jul 11, 2024
f231180
test WIP
xsalonx Jul 11, 2024
6fab826
simp
xsalonx Jul 11, 2024
b54c0fe
newline
xsalonx Jul 11, 2024
5afddd0
merge main
xsalonx Jul 11, 2024
ec0a478
test ok
xsalonx Jul 11, 2024
af7a3eb
Merge branch 'main' into xsalonx/QCF/O2B-1274/api-for-fetching-agq-qc
xsalonx Jul 11, 2024
63422f8
Merge branch 'main' into xsalonx/QCF/O2B-1274/api-for-fetching-agq-qc
xsalonx Jul 12, 2024
af08254
fix
xsalonx Jul 12, 2024
d08342a
cleanup
xsalonx Jul 12, 2024
fbe4595
fix
xsalonx Jul 12, 2024
9565f6c
fix
xsalonx Jul 12, 2024
803c347
add method to repo
xsalonx Jul 12, 2024
eaecd2c
cleanup
xsalonx Jul 12, 2024
08c26d6
ref
xsalonx Jul 12, 2024
84f1357
cleanup
xsalonx Jul 12, 2024
3b87f32
refactor
xsalonx Jul 12, 2024
d56a083
ues in service
xsalonx Jul 12, 2024
d7dbcff
cleanup
xsalonx Jul 12, 2024
3a574e8
cleanup
xsalonx Jul 12, 2024
0a6008e
a
xsalonx Jul 12, 2024
22e83d1
fix test
xsalonx Jul 12, 2024
03a96e6
ref
xsalonx Jul 15, 2024
fca035c
Merge branch 'xsalonx/QCF/O2B-1274/api-for-fetching-agq-qc' into xsal…
xsalonx Jul 15, 2024
8c32bc1
fix
xsalonx Jul 15, 2024
b9e7036
ref
xsalonx Jul 15, 2024
2e444ba
cleanup
xsalonx Jul 15, 2024
48ccdfd
add API
xsalonx Jul 15, 2024
500ca3e
handle
xsalonx Jul 15, 2024
be80617
wip
xsalonx Jul 15, 2024
71dd34a
a
xsalonx Jul 15, 2024
35bbcd9
simp
xsalonx Jul 15, 2024
a401b8b
simp
xsalonx Jul 15, 2024
652c540
style
xsalonx Jul 15, 2024
3ca6acc
a
xsalonx Jul 15, 2024
bd86ce0
ref
xsalonx Jul 15, 2024
7e3ba21
add mc reproducible
xsalonx Jul 15, 2024
1b86d92
merge pred
xsalonx Jul 15, 2024
009fce1
ref
xsalonx Jul 16, 2024
8cc06c2
cleanup
xsalonx Jul 16, 2024
becc0cb
docs
xsalonx Jul 16, 2024
338605f
a
xsalonx Jul 16, 2024
4a26ed2
a
xsalonx Jul 16, 2024
dd9f0ef
Merge branch 'xsalonx/QCF/O2B-1274/api-for-fetching-agq-qc--with-view…
xsalonx Jul 16, 2024
ea30ff8
fx
xsalonx Jul 16, 2024
a1a9454
Merge branch 'xsalonx/QCF/O2B-1274/api-for-fetching-agq-qc--with-view…
xsalonx Jul 16, 2024
054507c
fix
xsalonx Jul 16, 2024
675d22f
add tests
xsalonx Jul 16, 2024
e8503bb
Merge branch 'xsalonx/bugfix/qc-flag-delete' into xsalonx/QCF/O2B-127…
xsalonx Jul 16, 2024
ab1571f
ref
xsalonx Jul 16, 2024
264c5d6
cleanup
xsalonx Jul 16, 2024
edfbd52
add default GAQ detectors
xsalonx Jul 16, 2024
e1ab86b
restyle
xsalonx Jul 16, 2024
b55f6b4
merge main
xsalonx Jul 23, 2024
87043ef
rev
xsalonx Jul 23, 2024
b457313
restyle
xsalonx Jul 23, 2024
fc8711b
simp
xsalonx Jul 23, 2024
331f91b
simp
xsalonx Jul 23, 2024
7192e5a
fix
xsalonx Jul 23, 2024
01fa0a5
add seeders
xsalonx Jul 23, 2024
26a6a02
fix
xsalonx Jul 23, 2024
a13bd4e
fix
xsalonx Jul 23, 2024
2c9f224
fix
xsalonx Jul 23, 2024
d7a01b4
add test
xsalonx Jul 23, 2024
950b18b
basic test ok
xsalonx Jul 23, 2024
017b6ad
extend
xsalonx Jul 23, 2024
d0bd758
extended test ok|
xsalonx Jul 23, 2024
31ed7c7
fix
xsalonx Jul 25, 2024
1859da0
fix
xsalonx Jul 25, 2024
efe923c
test
xsalonx Jul 25, 2024
40a203a
fix
xsalonx Jul 25, 2024
c724281
Merge branch 'main' into xsalonx/QCF/O2B-1274/gaq-display
xsalonx Jul 26, 2024
b587a6f
test
xsalonx Jul 26, 2024
297dc5e
fix
xsalonx Jul 26, 2024
21f915b
test
xsalonx Jul 26, 2024
a83f761
add test method
xsalonx Jul 26, 2024
a8dbbe6
cleanup
xsalonx Jul 26, 2024
54bef5e
ref
xsalonx Jul 26, 2024
4bed4fe
ref
xsalonx Jul 26, 2024
c7a8aa3
fact
xsalonx Jul 26, 2024
8721436
rename
xsalonx Jul 26, 2024
6f80ce8
ref
xsalonx Jul 29, 2024
333465c
merge main
xsalonx Jul 29, 2024
eb77510
fix seeders
xsalonx Jul 29, 2024
bfa3c0f
wIP
xsalonx Jul 29, 2024
4e01382
ref:
xsalonx Jul 29, 2024
0873d9d
fix
xsalonx Jul 29, 2024
13c8701
a
xsalonx Jul 29, 2024
fcb7d57
fix
xsalonx Jul 29, 2024
e43f526
fix mc
xsalonx Jul 29, 2024
7eb3eb0
merged #1684
xsalonx Jul 29, 2024
cb10877
docs
xsalonx Jul 29, 2024
5ca48ee
docs
xsalonx Jul 29, 2024
d65363a
docs
xsalonx Jul 29, 2024
b7437a0
Merge branch 'main' into xsalonx/QCF/O2B-1274/gaq-display
xsalonx Jul 29, 2024
ea639c7
Merge branch 'xsalonx/QCF/O2B-1274/gaq-display' into xsalonx/gaq/O2B-…
xsalonx Jul 29, 2024
5a27b83
docs
xsalonx Jul 29, 2024
cc9907f
wip
xsalonx Jul 29, 2024
26b5366
test
xsalonx Jul 29, 2024
be1bc95
testok
xsalonx Jul 29, 2024
5c18304
tst ok
xsalonx Jul 29, 2024
d303dc1
simp
xsalonx Jul 30, 2024
4468991
Merge branch 'xsalonx/QCF/O2B-1274/gaq-display' into xsalonx/gaq/O2B-…
xsalonx Jul 30, 2024
ef16af1
fix
xsalonx Jul 30, 2024
bf0c408
rename
xsalonx Jul 30, 2024
f4ef884
test wip
xsalonx Jul 30, 2024
08d7027
merge seeders
xsalonx Jul 30, 2024
901bef5
Merge branch 'xsalonx/QCF/O2B-1274/gaq-display' into xsalonx/gaq/O2B-…
xsalonx Jul 30, 2024
5535f7b
fix
xsalonx Jul 30, 2024
779c556
add API
xsalonx Jul 30, 2024
cff97c3
docs
xsalonx Jul 30, 2024
91707df
fix
xsalonx Jul 30, 2024
463b64c
fix
xsalonx Jul 30, 2024
82bc643
fix
xsalonx Jul 30, 2024
70355cb
cleanup
xsalonx Jul 30, 2024
047f017
docs
xsalonx Jul 31, 2024
1650469
ref
xsalonx Jul 31, 2024
8bb780c
fix
xsalonx Jul 31, 2024
3545da2
docs
xsalonx Jul 31, 2024
0721555
Update lib/public/views/QcFlags/ActiveColumns/gaqFlagsActiveColumns.js
xsalonx Jul 31, 2024
43b627e
typo|
xsalonx Jul 31, 2024
018b82b
typo
xsalonx Jul 31, 2024
0ccf0f8
explicit async
xsalonx Jul 31, 2024
e1a5c0d
Merge branch 'xsalonx/QCF/O2B-1274/gaq-display' into xsalonx/gaq/O2B-…
xsalonx Jul 31, 2024
8dd75b4
merge main
xsalonx Jul 31, 2024
612866c
typos
xsalonx Jul 31, 2024
86e835e
typos
xsalonx Jul 31, 2024
38f9784
typos
xsalonx Jul 31, 2024
974976a
typos
xsalonx Jul 31, 2024
429aeb4
rename
xsalonx Jul 31, 2024
0173339
Merge branch 'main' into xsalonx/gaq/O2B-1325/summary-backend
xsalonx Jul 31, 2024
8365ada
rename
xsalonx Jul 31, 2024
5212e71
rename
xsalonx Jul 31, 2024
2ded971
Merge branch 'main' into xsalonx/gaq/O2B-1325/summary-backend
xsalonx Jul 31, 2024
33d8e29
docs
xsalonx Jul 31, 2024
280f99a
Merge branch 'tmp' into xsalonx/gaq/O2B-1325/summary-backend
xsalonx Jul 31, 2024
17658ba
docs
xsalonx Jul 31, 2024
4179a74
Update lib/server/services/qualityControlFlag/QcFlagService.js
xsalonx Aug 1, 2024
afb2c90
ref
xsalonx Aug 1, 2024
624221e
add replacements
xsalonx Aug 1, 2024
81f017a
Merge branch 'main' into xsalonx/gaq/O2B-1325/summary-backend
xsalonx Aug 5, 2024
4df6589
Merge branch 'main' into xsalonx/gaq/O2B-1325/summary-backend
xsalonx Aug 5, 2024
552c0af
Merge branch 'main' into xsalonx/gaq/O2B-1325/summary-backend
xsalonx Aug 5, 2024
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
191 changes: 157 additions & 34 deletions lib/database/repositories/QcFlagRepository.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,39 @@ const { Op } = require('sequelize');
const { models: { QcFlag } } = require('..');
const Repository = require('./Repository');

const GAQ_PERIODS_VIEW = `
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 (
(
SELECT data_pass_id,
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
)
UNION
graduta marked this conversation as resolved.
Show resolved Hide resolved
(
SELECT data_pass_id,
run_number,
UNIX_TIMESTAMP(COALESCE(qcfep.\`to\`, NOW())) 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
)
ORDER BY timestamp
) AS ap
`;

/**
* @typedef GaqPeriod
*
Expand All @@ -25,6 +58,17 @@ const Repository = require('./Repository');
* @property {number[]} contributingFlagIds IDs of QC flags which together define global aggregated quality in the period [from, to]
*/

/**
* @typedef RunGaqSubSummary aggregation of QC flags information by QcFlagType property `bad`
*
* @property {number} runNumber
* @property {number} bad
* @property {number} effectiveRunCoverage
* @property {number[]} flagsIds
* @property {number[]} verifiedFlagsIds
* @property {number} mcReproducible
*/

/**
* Sequelize implementation of the QcFlagRepository
*/
Expand All @@ -44,39 +88,6 @@ class QcFlagRepository extends Repository {
* @return {Promise<GaqPeriod[]>} Resolves with the GAQ periods
*/
async findGaqPeriods(dataPassId, runNumber) {
const gaqPeriodsSubQuery = `
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 (
(
SELECT data_pass_id,
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
)
UNION
(
SELECT data_pass_id,
run_number,
UNIX_TIMESTAMP(COALESCE(qcfep.\`to\`, NOW())) 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
)
ORDER BY timestamp
) AS ap
`;

const query = `
SELECT
gaq_periods.data_pass_id AS dataPassId,
Expand All @@ -89,7 +100,7 @@ class QcFlagRepository extends Repository {
INNER JOIN quality_control_flag_effective_periods AS qcfep
ON qcf.id = qcfep.flag_id
INNER JOIN data_pass_quality_control_flag AS dpqcf ON dpqcf.quality_control_flag_id = qcf.id
INNER JOIN (${gaqPeriodsSubQuery}) AS gaq_periods ON gaq_periods.data_pass_id = dpqcf.data_pass_id
INNER JOIN (${GAQ_PERIODS_VIEW}) AS gaq_periods ON gaq_periods.data_pass_id = dpqcf.data_pass_id
INNER JOIN global_aggregated_quality_detectors AS gaqd
ON gaqd.data_pass_id = gaq_periods.data_pass_id
AND gaqd.run_number = gaq_periods.run_number
Expand Down Expand Up @@ -123,6 +134,118 @@ class QcFlagRepository extends Repository {
}));
}

/**
* Get GAQ sub-summaries for given data pass
*
* @param {number} dataPassId id of data pass id
* @return {Promise<RunGaqSubSummary[]>} Resolves with the GAQ sub-summaries
*/
async getRunGaqSubSummaries(dataPassId) {
const effectivePeriodsWithTypeSubQuery = `
SELECT
gaq_periods.data_pass_id AS dataPassId,
gaq_periods.run_number AS runNumber,
IF(gaq_periods.\`from\` = 0, null, gaq_periods.\`from\`) AS \`from\`,
IF(gaq_periods.\`to\` = UNIX_TIMESTAMP(NOW()), null, gaq_periods.\`to\`) AS \`to\`,
SUM(qcft.bad) >= 1 AS bad,
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 qcf.id ) AS flagsList

FROM quality_control_flags AS qcf
INNER JOIN quality_control_flag_types AS qcft
ON qcft.id = qcf.flag_type_id
LEFT JOIN quality_control_flag_verifications AS qcfv
ON qcfv.flag_id = qcf.id
INNER JOIN quality_control_flag_effective_periods AS qcfep
ON qcf.id = qcfep.flag_id
INNER JOIN data_pass_quality_control_flag AS dpqcf
ON dpqcf.quality_control_flag_id = qcf.id
INNER JOIN (${GAQ_PERIODS_VIEW}) AS gaq_periods
ON gaq_periods.data_pass_id = dpqcf.data_pass_id
INNER JOIN global_aggregated_quality_detectors AS gaqd
ON gaqd.data_pass_id = gaq_periods.data_pass_id
AND gaqd.run_number = gaq_periods.run_number
AND gaqd.detector_id = qcf.detector_id
AND gaq_periods.run_number = qcf.run_number
AND (qcfep.\`from\` IS NULL OR UNIX_TIMESTAMP(qcfep.\`from\`) <= gaq_periods.\`from\`)
AND (qcfep.\`to\` IS NULL OR gaq_periods.\`to\` <= UNIX_TIMESTAMP(qcfep.\`to\`))

GROUP BY
gaq_periods.data_pass_id,
gaq_periods.run_number,
gaq_periods.\`from\`,
gaq_periods.\`to\`
`;

const query = `
SELECT
effectivePeriods.runNumber,
effectivePeriods.dataPassId,
effectivePeriods.bad,
SUM(effectivePeriods.mcReproducible) > 0 AS mcReproducible,
GROUP_CONCAT(effectivePeriods.verifiedFlagsList) AS verifiedFlagsList,
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
),
IF(
SUM(
COALESCE(effectivePeriods.\`to\` , 0)
+ COALESCE(effectivePeriods.\`from\`, 0)
) = 0,
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)
)
) / (
UNIX_TIMESTAMP(COALESCE(run.time_trg_end, run.time_o2_end))
- UNIX_TIMESTAMP(COALESCE(run.time_trg_start, run.time_o2_start))
)
) AS effectiveRunCoverage

FROM (${effectivePeriodsWithTypeSubQuery}) AS effectivePeriods
INNER JOIN runs AS run ON run.run_number = effectivePeriods.runNumber

WHERE effectivePeriods.dataPassId = :dataPassId

GROUP BY
effectivePeriods.dataPassId,
effectivePeriods.runNumber,
effectivePeriods.bad
`;

const [rows] = await this.model.sequelize.query(query, { replacements: { dataPassId } });
return rows.map(({
runNumber,
bad,
effectiveRunCoverage,
mcReproducible,
flagsList,
verifiedFlagsList,
}) => ({
runNumber,
bad,
effectiveRunCoverage,
mcReproducible: Boolean(mcReproducible),
flagsIds: [...new Set(flagsList.split(','))],
verifiedFlagsIds: verifiedFlagsList ? [...new Set(verifiedFlagsList.split(','))] : [],
}));
}

/**
* Find all QC flags created before and after given one for the same run, detector, data/simulation pass.
* Flags are orted by createdAt property in ascedning manner
Expand Down
9 changes: 9 additions & 0 deletions lib/database/seeders/20240716124000-gaq-detectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ module.exports = {
updated_at: '2024-07-16 12:45:00',
},

{
run_number: 54,
data_pass_id: 3,
detector_id: 4,

created_at: '2024-07-16 12:45:00',
updated_at: '2024-07-16 12:45:00',
},

{
run_number: 106,
data_pass_id: 1,
Expand Down
23 changes: 23 additions & 0 deletions lib/server/controllers/qcFlag.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,28 @@
}
};

// eslint-disable-next-line valid-jsdoc
/**
* Get GAQ summary for given data pass
*/
const getGaqSummaryHandler = async (request, response) => {
const validatedDTO = await dtoValidator(
DtoFactory.queryOnly(Joi.object({ dataPassId: Joi.number().required() })),
request,
response,
);
if (validatedDTO) {
try {
const { dataPassId } = validatedDTO.query;

const data = await qcFlagService.getGaqSummary(dataPassId);
graduta marked this conversation as resolved.
Show resolved Hide resolved
response.json({ data });
} catch (error) {
updateExpressResponseFromNativeError(response, error);

Check warning on line 293 in lib/server/controllers/qcFlag.controller.js

View check run for this annotation

Codecov / codecov/patch

lib/server/controllers/qcFlag.controller.js#L293

Added line #L293 was not covered by tests
}
}
};

exports.QcFlagController = {
getQcFlagByIdHandler,
listQcFlagsPerDataPassHandler,
Expand All @@ -282,4 +304,5 @@
verifyQcFlagHandler,
getQcFlagsSummaryHandler,
getGaqQcFlagsHandler,
getGaqSummaryHandler,
};
8 changes: 8 additions & 0 deletions lib/server/routers/qcFlag.router.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@ exports.qcFlagsRouter = {
path: 'summary',
method: 'get',
controller: QcFlagController.getQcFlagsSummaryHandler,

children: [
{
path: 'gaq',
method: 'get',
controller: QcFlagController.getGaqSummaryHandler,
},
],
},
{
path: 'perDataPass',
Expand Down
75 changes: 75 additions & 0 deletions lib/server/services/qualityControlFlag/QcFlagService.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ const QC_SUMMARY_PROPERTIES = {
* @property {QcFlag[]} contributingFlags
*/

/**
* @typedef RunGaqSummary
* @property {number} badEffectiveRunCoverage - fraction of run's data, which aggregated quality is bad
* @property {number} explicitlyNotBadEffectiveRunCoverage - fraction of run's data, which aggregated quality is explicitly good
* @property {number} missingVerificationsCount - number of not verified QC flags which are not discarded
* @property {boolean} mcReproducible - states whether some aggregation of QC flags is Limited Acceptance MC Reproducible
*/

/**
* @typedef GaqSummary aggregated global quality summaries for given data pass
* @type {Object<number, RunGaqSummary>} runNumber to RunGaqSummary mapping
*/

/**
* Quality control flags service
*/
Expand Down Expand Up @@ -586,6 +599,68 @@ class QcFlagService {
}));
}

/**
* Get GAQ summary
*
* @param {number} dataPassId id of data pass id
* @return {Promise<GaqSummary[]>} Resolves with the GAQ Summary
*/
async getGaqSummary(dataPassId) {
await getOneDataPassOrFail({ id: dataPassId });
const runGaqSubSummaries = await QcFlagRepository.getRunGaqSubSummaries(dataPassId);

const summary = {};
const flagsAndVerifications = {};

// Fold list of subSummaries into one summary
for (const subSummary of runGaqSubSummaries) {
const {
runNumber,
bad,
effectiveRunCoverage,
flagsIds,
verifiedFlagsIds,
mcReproducible,
} = subSummary;

if (!summary[runNumber]) {
summary[runNumber] = { [QC_SUMMARY_PROPERTIES.mcReproducible]: false };
}
if (!flagsAndVerifications[runNumber]) {
flagsAndVerifications[runNumber] = {};
}

const runSummary = summary[runNumber];

const distinctRunFlagsIds = flagsAndVerifications[runNumber]?.distinctFlagsIds ?? [];
const distinctRunVerifiedFlagsIds = flagsAndVerifications[runNumber]?.distinctVerifiedFlagsIds ?? [];

flagsAndVerifications[runNumber] = {
distinctFlagsIds: new Set([...distinctRunFlagsIds, ...flagsIds]),
distinctVerifiedFlagsIds: new Set([...distinctRunVerifiedFlagsIds, ...verifiedFlagsIds]),
};

if (bad) {
runSummary[QC_SUMMARY_PROPERTIES.badEffectiveRunCoverage] = parseFloat(effectiveRunCoverage);
runSummary[QC_SUMMARY_PROPERTIES.mcReproducible] = mcReproducible;
} else {
runSummary[QC_SUMMARY_PROPERTIES.explicitlyNotBadEffectiveRunCoverage] = parseFloat(effectiveRunCoverage);
}
if (runSummary[QC_SUMMARY_PROPERTIES.badEffectiveRunCoverage] === undefined) {
runSummary[QC_SUMMARY_PROPERTIES.badEffectiveRunCoverage] = 0;
}
if (runSummary[QC_SUMMARY_PROPERTIES.explicitlyNotBadEffectiveRunCoverage] === undefined) {
runSummary[QC_SUMMARY_PROPERTIES.explicitlyNotBadEffectiveRunCoverage] = 0;
}
}

for (const [runNumber, { distinctFlagsIds, distinctVerifiedFlagsIds }] of Object.entries(flagsAndVerifications)) {
summary[runNumber][QC_SUMMARY_PROPERTIES.missingVerificationsCount] = distinctFlagsIds.size - distinctVerifiedFlagsIds.size;
}

return summary;
}

/**
* Return a paginated list of QC flags related to a given simulation pass, run and dpl detector
*
Expand Down
Loading