-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathrunDetectorsAsyncQcActiveColumns.js
More file actions
177 lines (163 loc) · 8.26 KB
/
Copy pathrunDetectorsAsyncQcActiveColumns.js
File metadata and controls
177 lines (163 loc) · 8.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
/**
* @license
* Copyright CERN and copyright holders of ALICE O2. This software is
* distributed under the terms of the GNU General Public License v3 (GPL
* Version 3), copied verbatim in the file "COPYING".
*
* See http://alice-o2.web.cern.ch/license for full licensing information.
*
* In applying this license CERN does not waive the privileges and immunities
* granted to it by virtue of its status as an Intergovernmental Organization
* or submit itself to any jurisdiction.
*/
import { h, iconBan, iconX, info } from '/js/src/index.js';
import { qcFlagCreationPanelLink } from '../../../components/qcFlags/qcFlagCreationPanelLink.js';
import { tooltip } from '../../../components/common/popover/tooltip.js';
import { isRunNotSubjectToQc } from '../../../components/qcFlags/isRunNotSubjectToQc.js';
import { getQcSummaryDisplay } from './getQcSummaryDisplay.js';
import { getRunQcExclusionReason } from '../../../components/qcFlags/getRunQcExclusionReason.js';
import { qcFlagOverviewPanelLink } from '../../../components/qcFlags/qcFlagOverviewPanelLink.js';
import { remoteDplDetectorUserHasAccessTo } from '../../../services/detectors/remoteDplDetectorUserHasAccessTo.js';
import errorAlert from '../../../components/common/errorAlert.js';
import spinner from '../../../components/common/spinner.js';
import { numericalComparisonFilter } from '../../../components/Filters/common/filters/numericalComparisonFilter.js';
import { filtersSection } from '../../../components/Filters/common/filtersPanelPopover.js';
/**
* Render QC summary for given run and detector
*
* @param {object} monalisaProduction id of the production -- data pass or simulation pass
* @param {number} [monalisaProduction.dataPassId] data pass id -- exclusive with `simulationPassId`
* @param {number} [monalisaProduction.simulationPassId] simulation pass id -- exclusive with `dataPassId`
* @param {Run} run a run
* @param {number} dplDetectorId id of the detector
* @param {QcSummary} qcSummary QC summary
* @return {Component} component
*/
const runDetectorAsyncQualityDisplay = ({ dataPassId, simulationPassId }, run, dplDetectorId, qcSummary) => {
const { runNumber } = run;
let qcSummaryDisplay = getQcSummaryDisplay(qcSummary[runNumber][dplDetectorId]);
qcSummaryDisplay = isRunNotSubjectToQc(run)
? tooltip(qcSummaryDisplay, getRunQcExclusionReason(run))
: qcSummaryDisplay;
return qcFlagOverviewPanelLink(
qcSummaryDisplay,
{ dataPassId, simulationPassId, runNumber, dplDetectorId },
);
};
/**
* Factory for detectors related active columns configuration
*
* @param {RunDetectorsSelectionModel} runDetectorsSelectionModel the run/detectors selection model
* @param {DplDetector[]} dplDetectors detectors list
* @param {RemoteData<DplDetector[]>} remoteDplDetectorsUserHasAccessTo dpl detectors list remote data
* @param {object} monalisaProduction id of the production -- data pass or simulation pass
* @param {DataPass} [monalisaProduction.dataPass] data pass containing the run -- exclusive with `simulationPass`
* @param {SimulationPass} [monalisaProduction.simulationPass] simulation pass containing the run -- exclusive with `dataPass`
* @param {object} configuration display configuration
* @param {string} [configuration.profile] profile which the column is restricted to
* @param {QcSummary} [configuration.qcSummary] QC summary for given data/simulation pass
* @return {object} active columns configuration
*/
export const createRunDetectorsAsyncQcActiveColumns = (
runDetectorsSelectionModel,
dplDetectors,
remoteDplDetectorsUserHasAccessTo,
{ dataPass, simulationPass },
{ profile, qcSummary } = {},
) => {
if (!dataPass && !simulationPass) {
throw new Error('`dataPass` or `simulationPass` is required');
}
if (dataPass && simulationPass) {
throw new Error('`dataPass` and `simulationPass` are exclusive options');
}
let activeColumnEntries = dplDetectors?.map(({ name: detectorName, id: dplDetectorId }) => [
detectorName,
{
name: detectorName.toUpperCase(),
visible: true,
format: (_, run) => remoteDplDetectorUserHasAccessTo(dplDetectorId, remoteDplDetectorsUserHasAccessTo).match({
NotAsked: () => null,
Failure: (errors) => errorAlert(errors),
Success: (detectorUserHasAccessTo) => {
const detectorWasActiveDuringRun = Boolean(run.detectorsQualities.find(({ name }) => name === detectorName));
if (!detectorWasActiveDuringRun) {
return null;
}
const { runNumber } = run;
const runExcludedFromQc = isRunNotSubjectToQc(run);
const checkbox = !runExcludedFromQc && !dataPass?.isFrozen && detectorUserHasAccessTo && h(
'input.select-multi-flag',
{
type: 'checkbox',
checked: runDetectorsSelectionModel.isRunDetectorSelected(run.runNumber, dplDetectorId),
onchange: (e) => e.target.checked
? runDetectorsSelectionModel.selectRunDetector(run.runNumber, dplDetectorId)
: runDetectorsSelectionModel.unselectRunDetector(run.runNumber, dplDetectorId),
},
);
if (!qcSummary?.[runNumber]?.[dplDetectorId]) { // If there is no QC flag assigned
return runExcludedFromQc
? h('.text-center', tooltip(iconX(), getRunQcExclusionReason(run)))
: h('.flex-row.items-center.gc1', [
checkbox,
qcFlagCreationPanelLink(
{ dataPass, simulationPass },
run,
detectorUserHasAccessTo,
{
noPermissionContent: h('.text-center', tooltip(
h('.gray.badge', iconBan()),
'No QC flag was assigned. You have no permission to manage QC flag for this detector',
)),
linkClasses: ['w-100'],
},
),
]);
}
return h('.flex-row.items-center.gc1', [
checkbox,
runDetectorAsyncQualityDisplay(
{ dataPassId: dataPass?.id, simulationPassId: simulationPass?.id },
run,
dplDetectorId,
qcSummary,
),
]);
},
Loading: () => spinner(),
}),
profiles: profile,
},
]) ?? [];
const filtersEntries = dplDetectors?.map(({ name: detectorName, id: dplDetectorId }) => [
detectorName,
{
name: detectorName.toUpperCase(),
visible: false,
profiles: profile,
filter: (filteringModel) => {
const filterModel = filteringModel.get(`detectorsQc[_${dplDetectorId}][notBadFraction]`);
return filterModel
? numericalComparisonFilter(filterModel, { step: 0.1, selectorPrefix: `detectorsQc-for-${dplDetectorId}-notBadFraction` })
: null;
},
},
]) ?? [];
if (activeColumnEntries.length > 0) {
activeColumnEntries = [
[
'detectorsQc',
{
name: null,
filter: ({ filteringModel }) => [
h('.section-divider', ['Detector QC', tooltip(info(), 'not-bad fraction expressed as a percentage')]),
filtersSection(filteringModel, Object.fromEntries(filtersEntries), { profile }),
],
profiles: profile,
},
], ...activeColumnEntries,
];
}
return Object.fromEntries(activeColumnEntries);
};