-
Notifications
You must be signed in to change notification settings - Fork 21
Expand file tree
/
Copy pathRunsWithQcModel.js
More file actions
272 lines (249 loc) · 10 KB
/
RunsWithQcModel.js
File metadata and controls
272 lines (249 loc) · 10 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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
/**
* @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 { buildUrl, RemoteData } from '/js/src/index.js';
import { NumericalComparisonFilterModel } from '../../../components/Filters/common/filters/NumericalComparisonFilterModel.js';
import { RunDetectorsSelectionModel } from '../RunDetectorsSelectionModel.js';
import { getRemoteData } from '../../../utilities/fetch/getRemoteData.js';
import { RunsOverviewModel } from './RunsOverviewModel.js';
import { runsActiveColumns as baseDataExportConfiguration } from '../ActiveColumns/runsActiveColumns.js';
import { DataExportTypes } from '../../../domain/enums/DataExportTypes.js';
/**
* Creates export configuration for runs' QC flags
*
* @param {Detector[]} detectors detectors list
* @return {DataExportConfiguration} export configuration for runs' QC flags
*/
const qcFlagsExportConfigurationFactory = (detectors) => Object.fromEntries(detectors.map(({ id: detectorId, name: detectorName }) =>
[
detectorName,
{
exportFormat: {
[DataExportTypes.JSON]: (_, run) => run.qcFlags?.[detectorId],
[DataExportTypes.CSV]: (_, { qcFlags, qcTimeStart, qcTimeEnd }) =>
qcFlags?.[detectorId]?.map(({ flagType, effectivePeriods }) =>
effectivePeriods.map(({ from, to }) => `${flagType.name} (from: ${from ?? qcTimeStart} to: ${to ?? qcTimeEnd})`))
.flat()
.sort(({ from }) => from)
.join(' | ') ?? '',
},
},
]));
import { ObservableData } from '../../../utilities/ObservableData.js';
import { DetectorType } from '../../../domain/enums/DetectorTypes.js';
import { mergeRemoteData } from '../../../utilities/mergeRemoteData.js';
/**
* Merge QC summaries
*
* @param {QcSummary[]} qcSummaries list of QC summaries
* @return {QcSummary} QC summary
*/
const mergeQcSummaries = (qcSummaries) => qcSummaries.reduce((acc, qcSummary) => {
for (const [runNumber, runQcSummary] of Object.entries(qcSummary)) {
acc[runNumber] = { ...acc[runNumber], ...runQcSummary };
}
return acc;
}, {});
/**
* RunsWithQcModel
*
* Runs overview model which stores common information for all RCT runs overviews pages
*/
export class RunsWithQcModel extends RunsOverviewModel {
/**
* Constructor
* @param {Model} model global model
*/
constructor(model) {
super(model);
this._observablesQcFlagsSummaryDependsOn$ = null;
this._mcReproducibleAsNotBad = false;
this._runDetectorsSelectionModel = new RunDetectorsSelectionModel();
this._runDetectorsSelectionModel.bubbleTo(this);
this._qcSummary$ = new ObservableData(RemoteData.notAsked());
this._qcSummary$.bubbleTo(this);
this.patchDisplayOptions({
horizontalScrollEnabled: true,
verticalScrollEnabled: true,
freezeFirstColumn: true,
});
}
/**
* @inheritdoc
*/
getRootEndpoint() {
const filter = {};
filter.detectorsQc = {
mcReproducibleAsNotBad: this._mcReproducibleAsNotBad,
};
return buildUrl(super.getRootEndpoint(), { filter, include: { effectiveQcFlags: true } });
}
/**
* Set mcReproducibleAsNotBad
*
* @param {boolean} mcReproducibleAsNotBad new value
* @return {void}
*/
setMcReproducibleAsNotBad(mcReproducibleAsNotBad) {
this._mcReproducibleAsNotBad = mcReproducibleAsNotBad;
this.load();
}
/**
* Get mcReproducibleAsNotBad
*
* @return {boolean} mcReproducibleAsNotBad
*/
get mcReproducibleAsNotBad() {
return this._mcReproducibleAsNotBad;
}
/**
* Returns the run detectors selection model
*
* @return {RunDetectorsSelectionModel} selection model
*/
get runDetectorsSelectionModel() {
return this._runDetectorsSelectionModel;
}
/**
* @inheritdoc
*/
async load() {
this._runDetectorsSelectionModel.reset();
// Only fetch QC summary manually if no observer is registered
if (!this._observablesQcFlagsSummaryDependsOn$) {
this._fetchQcSummary();
}
super.load();
}
/**
* Register not-bad fraction detectors filtering model and update it when detectors are loaded
* Also, trigger an immediate update if detectors are already loaded at the moment of registration
*
* @param {ObservableData<RemoteData<Detector>>} detectors$ detectors remote data observable
*/
registerDetectorsNotBadFractionFilterModels(detectors$) {
const callback = (observableData) => {
const current = observableData.getCurrent();
current?.apply({
Success: (detectors) => detectors.forEach(({ id }) => {
this._filteringModel.put(`detectorsQc[_${id}][notBadFraction]`, new NumericalComparisonFilterModel({
scale: 0.01,
integer: false,
}));
}),
});
};
detectors$.observe(callback);
callback(detectors$);
}
/**
* Register detectors for QC flags data export and update export configuration when detectors are loaded
* Also, trigger an immediate update if detectors are already loaded at the moment of registration
*
* @param {ObservableData<RemoteData<Detector>>} detectors$ detectors remote data observable
*/
registerDetectorsForQcFlagsDataExport(detectors$) {
const callback = (observableData) => {
const current = observableData.getCurrent();
current?.apply({
Success: (detectors) => {
this._exportModel.setDataExportConfiguration({
...baseDataExportConfiguration,
...qcFlagsExportConfigurationFactory(detectors),
});
},
Other: () => null,
});
};
detectors$.observe(callback);
// Also trigger immediately if detectors are already loaded
callback(detectors$);
}
/**
* Register observables data, which QC flags fetching operation success depends on
*
* @param {ObservableData<RemoteData<Detector>>} detectors$ observable data which QC flags fetching operation success depends on
*/
registerObservablesQcSummaryDependsOn(detectors$) {
this._observablesQcFlagsSummaryDependsOn$ = detectors$;
const callback = (observableData) => {
const current = observableData.getCurrent();
current?.apply({ Success: () => this._fetchQcSummary() });
};
this._observablesQcFlagsSummaryDependsOn$.observe(callback);
// Also trigger immediately if detectors are already loaded
callback(this._observablesQcFlagsSummaryDependsOn$);
}
/**
* Defines API filtering params to fetch QC summary for one of: a data pass, simulation pass, LHC period
*/
qcSummaryScope() {
throw Error('Method not implemented');
}
/**
* Return detectors which a model uses
*
* @returns {RemoteData<Detector[]>} remote data list of detectors
*/
get detectors() {
throw Error('Method not implemented');
}
/**
* Fetch QC summaries for given scope
*
* @return {Promise<void>} promise
*/
async _fetchQcSummary() {
const qcSummaryScopeValid = Object.entries(this.qcSummaryScope).filter(([, id]) => id).length == 1;
if (qcSummaryScopeValid && this.detectors && this._observablesQcFlagsSummaryDependsOn$?.getCurrent()) {
mergeRemoteData([this.detectors, this._observablesQcFlagsSummaryDependsOn$.getCurrent()]).match({
Success: async ([detectors]) => {
this._qcSummary$.setCurrent(RemoteData.loading());
try {
const { data: qcSummary1 } = await getRemoteData(buildUrl('/api/qcFlags/summary', {
...this.qcSummaryScope,
detectorIds: detectors
.filter(({ type }) => type === DetectorType.PHYSICAL)
.map(({ id }) => id).join(','),
mcReproducibleAsNotBad: this._mcReproducibleAsNotBad,
}));
const { data: qcSummary2 } = await getRemoteData(buildUrl('/api/qcFlags/summary', {
...this.qcSummaryScope,
detectorIds: detectors
.filter(({ type }) => [DetectorType.AOT_GLO, DetectorType.AOT_EVENT, DetectorType.MUON_GLO].includes(type))
.map(({ id }) => id).join(','),
filter: {
createdBy: {
names: 'Anonymous',
operator: 'none',
},
},
mcReproducibleAsNotBad: this._mcReproducibleAsNotBad,
}));
this._qcSummary$.setCurrent(RemoteData.success(mergeQcSummaries([qcSummary1, qcSummary2])));
} catch (error) {
this._qcSummary$.setCurrent(RemoteData.failure(error));
}
},
Other: () => null,
});
}
}
/**
* QC summary getter
*
* @return {RemoteData<QcSummary>} QC summary
*/
get qcSummary() {
return this._qcSummary$.getCurrent();
}
}