Skip to content

Commit ebe79c1

Browse files
committed
cleanup, test disable
1 parent d65a014 commit ebe79c1

3 files changed

Lines changed: 39 additions & 195 deletions

File tree

lib/database/repositories/QcFlagRepository.js

Lines changed: 13 additions & 168 deletions
Original file line numberDiff line numberDiff line change
@@ -26,69 +26,17 @@ const Repository = require('./Repository');
2626
*/
2727

2828
/**
29-
* @typedef RunGaqSubSummary aggregation of QC flags information by QcFlagType property `bad`
29+
* @typedef RunGaqSubSummary aggregation of QC flags information by QcFlagType property `bad` and `mc_reproducible`
3030
*
31-
* @property {number} runNumber
32-
* @property {number} bad
33-
* @property {number} effectiveRunCoverage
31+
* @property {number} badCoverage
32+
* @property {number} mcReproducibleCoverage
33+
* @property {number} goodCoverage
34+
* @property {number} totalCoverage
35+
* @property {number} undefinedQualityPeriodsCount
3436
* @property {number[]} flagsIds
3537
* @property {number[]} verifiedFlagsIds
36-
* @property {number} mcReproducible
3738
*/
3839

39-
const GAQ_PERIODS_VIEW = `
40-
SELECT * FROM (
41-
SELECT
42-
data_pass_id,
43-
run_number,
44-
LAG(timestamp) OVER w AS \`from\`,
45-
timestamp AS \`to\`,
46-
LAG(ordering_timestamp) OVER w AS from_ordering_timestamp
47-
FROM (
48-
(
49-
SELECT gaqd.data_pass_id,
50-
gaqd.run_number,
51-
COALESCE(qcfep.\`from\`, r.qc_time_start) AS timestamp,
52-
COALESCE(qcfep.\`from\`, r.qc_time_start, '0001-01-01 00:00:00.000') AS ordering_timestamp
53-
FROM quality_control_flag_effective_periods AS qcfep
54-
INNER JOIN quality_control_flags AS qcf ON qcf.id = qcfep.flag_id
55-
INNER JOIN runs AS r ON qcf.run_number = r.run_number
56-
INNER JOIN data_pass_quality_control_flag AS dpqcf ON dpqcf.quality_control_flag_id = qcf.id
57-
-- Only flags of detectors which are defined in global_aggregated_quality_detectors
58-
-- should be taken into account for calculation of gaq_effective_periods
59-
INNER JOIN global_aggregated_quality_detectors AS gaqd
60-
ON gaqd.data_pass_id = dpqcf.data_pass_id
61-
AND gaqd.run_number = qcf.run_number
62-
AND gaqd.detector_id = qcf.detector_id
63-
)
64-
UNION
65-
(
66-
SELECT gaqd.data_pass_id,
67-
gaqd.run_number,
68-
COALESCE(qcfep.\`to\`, r.qc_time_end) AS timestamp,
69-
COALESCE(qcfep.\`to\`, r.qc_time_end, NOW()) AS ordering_timestamp
70-
FROM quality_control_flag_effective_periods AS qcfep
71-
INNER JOIN quality_control_flags AS qcf ON qcf.id = qcfep.flag_id
72-
INNER JOIN runs AS r ON qcf.run_number = r.run_number
73-
INNER JOIN data_pass_quality_control_flag AS dpqcf ON dpqcf.quality_control_flag_id = qcf.id
74-
-- Only flags of detectors which are defined in global_aggregated_quality_detectors
75-
-- should be taken into account for calculation of gaq_effective_periods
76-
INNER JOIN global_aggregated_quality_detectors AS gaqd
77-
ON gaqd.data_pass_id = dpqcf.data_pass_id
78-
AND gaqd.run_number = qcf.run_number
79-
AND gaqd.detector_id = qcf.detector_id
80-
)
81-
ORDER BY ordering_timestamp
82-
) AS ap
83-
WINDOW w AS (
84-
PARTITION BY data_pass_id,
85-
run_number
86-
ORDER BY ap.ordering_timestamp
87-
)
88-
) as gaq_periods_with_last_nullish_row
89-
WHERE gaq_periods_with_last_nullish_row.from_ordering_timestamp IS NOT NULL
90-
`;
91-
9240
/**
9341
* Sequelize implementation of the QcFlagRepository
9442
*/
@@ -154,118 +102,15 @@ class QcFlagRepository extends Repository {
154102
}));
155103
}
156104

157-
/**
158-
* Get GAQ sub-summaries for given data pass
159-
*
160-
* @param {number} dataPassId id of data pass id
161-
* @param {object} [options] additional options
162-
* @param {boolean} [options.mcReproducibleAsNotBad = false] if set to true,
163-
* `Limited Acceptance MC Reproducible` flag type is treated as good one
164-
* @return {Promise<RunGaqSubSummary[]>} Resolves with the GAQ sub-summaries
165-
*/
166-
async _old_getRunGaqSubSummaries(dataPassId, { mcReproducibleAsNotBad = false } = {}) {
167-
const effectivePeriodsWithTypeSubQuery = `
168-
SELECT
169-
gaq_periods.data_pass_id AS dataPassId,
170-
gaq_periods.run_number AS runNumber,
171-
gaq_periods.\`from\` AS \`from\`,
172-
gaq_periods.\`to\` AS \`to\`,
173-
SUM(IF(qcft.monte_carlo_reproducible AND :mcReproducibleAsNotBad, false, qcft.bad)) >= 1 AS bad,
174-
SUM(qcft.bad) = SUM(qcft.monte_carlo_reproducible) AND SUM(qcft.monte_carlo_reproducible) AS mcReproducible,
175-
GROUP_CONCAT( DISTINCT qcfv.flag_id ) AS verifiedFlagsList,
176-
GROUP_CONCAT( DISTINCT qcf.id ) AS flagsList
177-
178-
FROM quality_control_flags AS qcf
179-
INNER JOIN quality_control_flag_types AS qcft
180-
ON qcft.id = qcf.flag_type_id
181-
LEFT JOIN quality_control_flag_verifications AS qcfv
182-
ON qcfv.flag_id = qcf.id
183-
INNER JOIN quality_control_flag_effective_periods AS qcfep
184-
ON qcf.id = qcfep.flag_id
185-
INNER JOIN data_pass_quality_control_flag AS dpqcf
186-
ON dpqcf.quality_control_flag_id = qcf.id
187-
INNER JOIN (${GAQ_PERIODS_VIEW}) AS gaq_periods
188-
ON gaq_periods.data_pass_id = dpqcf.data_pass_id
189-
INNER JOIN global_aggregated_quality_detectors AS gaqd
190-
ON gaqd.data_pass_id = gaq_periods.data_pass_id
191-
AND gaqd.run_number = gaq_periods.run_number
192-
AND gaqd.detector_id = qcf.detector_id
193-
AND gaq_periods.run_number = qcf.run_number
194-
AND (qcfep.\`from\` IS NULL OR qcfep.\`from\` <= gaq_periods.\`from\`)
195-
AND (qcfep.\`to\` IS NULL OR gaq_periods.\`to\` <= qcfep.\`to\`)
196-
197-
GROUP BY
198-
gaq_periods.data_pass_id,
199-
gaq_periods.run_number,
200-
gaq_periods.\`from\`,
201-
gaq_periods.\`to\`
202-
`;
203-
204-
const query = `
205-
SELECT
206-
effectivePeriods.runNumber,
207-
effectivePeriods.dataPassId,
208-
effectivePeriods.bad,
209-
SUM(effectivePeriods.mcReproducible) > 0 AS mcReproducible,
210-
GROUP_CONCAT(effectivePeriods.verifiedFlagsList) AS verifiedFlagsList,
211-
GROUP_CONCAT(effectivePeriods.flagsList) AS flagsList,
212-
213-
IF(
214-
run.qc_time_start IS NULL OR run.qc_time_end IS NULL,
215-
IF(
216-
effectivePeriods.\`from\` IS NULL AND effectivePeriods.\`to\` IS NULL,
217-
1,
218-
null
219-
),
220-
SUM(
221-
UNIX_TIMESTAMP(COALESCE(effectivePeriods.\`to\`,run.qc_time_end))
222-
- UNIX_TIMESTAMP(COALESCE(effectivePeriods.\`from\`, run.qc_time_start))
223-
) / (UNIX_TIMESTAMP(run.qc_time_end) - UNIX_TIMESTAMP(run.qc_time_start))
224-
) AS effectiveRunCoverage
225-
226-
FROM (${effectivePeriodsWithTypeSubQuery}) AS effectivePeriods
227-
INNER JOIN runs AS run ON run.run_number = effectivePeriods.runNumber
228-
229-
WHERE effectivePeriods.dataPassId = :dataPassId
230-
231-
GROUP BY
232-
effectivePeriods.dataPassId,
233-
effectivePeriods.runNumber,
234-
effectivePeriods.bad
235-
`;
236-
237-
const [rows] = await this.model.sequelize.query(query, { replacements: { dataPassId, mcReproducibleAsNotBad } });
238-
return rows.map(({
239-
runNumber,
240-
bad,
241-
effectiveRunCoverage,
242-
mcReproducible,
243-
flagsList,
244-
verifiedFlagsList,
245-
}) => {
246-
if ((effectiveRunCoverage ?? null) != null) {
247-
effectiveRunCoverage = Math.min(1, Math.max(0, parseFloat(effectiveRunCoverage)));
248-
}
249-
250-
return {
251-
runNumber,
252-
bad,
253-
effectiveRunCoverage,
254-
mcReproducible: Boolean(mcReproducible),
255-
flagsIds: [...new Set(flagsList.split(','))],
256-
verifiedFlagsIds: verifiedFlagsList ? [...new Set(verifiedFlagsList.split(','))] : [],
257-
};
258-
});
259-
}
260-
261105
/**
262106
* Return the good, bad and MC reproducible coverage per runs for a given data pass
107+
* and informtion about missing and unverified flags
263108
*
264-
* @param {number} dataPassId the id of the data-pass
265-
* @return {Promise<Map<number, RunGaqSummary>>} resolves with the map between run number and the corresponding run GAQ summary
109+
* @param {number} dataPassId the id of a data-pass
110+
* @return {Promise<Object.<number, RunGaqSubSummary>>} resolves with the map between run number and the corresponding run GAQ summary
266111
*/
267112
async getGaqCoverages(dataPassId) {
268-
const innerQuery = `
113+
const blockAggregationQuery = `
269114
SELECT
270115
gp.data_pass_id,
271116
gp.run_number,
@@ -299,7 +144,7 @@ class QcFlagRepository extends Repository {
299144
GROUP BY gp.data_pass_id, gp.run_number, gp.\`from\`, gp.to
300145
`;
301146

302-
const query = `
147+
const summaryQuery = `
303148
SELECT
304149
data_pass_id,
305150
run_number,
@@ -311,10 +156,10 @@ class QcFlagRepository extends Repository {
311156
GROUP_CONCAT(verified_flags_list) AS verified_flags_list,
312157
GROUP_CONCAT(flags_list) AS flags_list
313158
314-
FROM (${innerQuery}) AS gaq
159+
FROM (${blockAggregationQuery}) AS gaq
315160
GROUP BY gaq.data_pass_id, gaq.run_number;
316161
`;
317-
const [rows] = await this.model.sequelize.query(query, { replacements: { dataPassId } });
162+
const [rows] = await this.model.sequelize.query(summaryQuery, { replacements: { dataPassId } });
318163
const entries = rows.map(
319164
({
320165
run_number,

lib/database/seeders/20240404100811-qc-flags.js

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -269,32 +269,32 @@ module.exports = {
269269
to: null,
270270
},
271271

272-
{
273-
id: 10,
274-
flag_id: 10,
275-
from: '2019-08-08 20:30:00',
276-
to: '2019-08-08 21:00:00',
277-
},
278-
{
279-
id: 13,
280-
flag_id: 13,
281-
from: '2019-08-08 20:00:00',
282-
to: '2019-08-08 20:30:00',
283-
},
284-
285-
{
286-
id: 11,
287-
flag_id: 11,
288-
from: '2019-08-08 20:00:00',
289-
to: '2019-08-08 20:30:00',
290-
},
291-
292-
{
293-
id: 12,
294-
flag_id: 12,
295-
from: '2019-08-08 20:30:00',
296-
to: '2019-08-08 21:00:00',
297-
},
272+
// {
273+
// id: 10,
274+
// flag_id: 10,
275+
// from: '2019-08-08 20:30:00',
276+
// to: '2019-08-08 21:00:00',
277+
// },
278+
// {
279+
// id: 13,
280+
// flag_id: 13,
281+
// from: '2019-08-08 20:00:00',
282+
// to: '2019-08-08 20:30:00',
283+
// },
284+
285+
// {
286+
// id: 11,
287+
// flag_id: 11,
288+
// from: '2019-08-08 20:00:00',
289+
// to: '2019-08-08 20:30:00',
290+
// },
291+
292+
// {
293+
// id: 12,
294+
// flag_id: 12,
295+
// from: '2019-08-08 20:30:00',
296+
// to: '2019-08-08 21:00:00',
297+
// },
298298

299299
/** Synchronous */
300300
// Run : 56, FT0

lib/server/controllers/qcFlag.controller.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,6 @@ const getGaqSummaryHandler = async (request, response) => {
377377
const { dataPassId, mcReproducibleAsNotBad = false } = validatedDTO.query;
378378

379379
const data = await gaqService.getSummary(dataPassId, { mcReproducibleAsNotBad });
380-
381380
response.json({ data });
382381
} catch (error) {
383382
updateExpressResponseFromNativeError(response, error);

0 commit comments

Comments
 (0)