Skip to content

Commit 6b6b438

Browse files
committed
use api
1 parent 5c460f6 commit 6b6b438

5 files changed

Lines changed: 93 additions & 83 deletions

File tree

lib/public/views/Runs/Overview/RunsWithQcModel.js

Lines changed: 76 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,25 @@
1111
* or submit itself to any jurisdiction.
1212
*/
1313

14-
import { buildUrl } from '/js/src/index.js';
14+
import { buildUrl, RemoteData } from '/js/src/index.js';
1515
import { NumericalComparisonFilterModel } from '../../../components/Filters/common/filters/NumericalComparisonFilterModel.js';
1616
import { RunDetectorsSelectionModel } from '../RunDetectorsSelectionModel.js';
17+
import { getRemoteData } from '../../../utilities/fetch/getRemoteData.js';
1718
import { RunsOverviewModel } from './RunsOverviewModel.js';
19+
import { ObservableData } from '../../../utilities/ObservableData.js';
20+
import { DetectorType } from '../../../domain/enums/DetectorTypes.js';
21+
22+
/**
23+
* Merge QC summaries
24+
* @param {QcSummary[]} qcSummaries list of QC summaries
25+
* @return {QcSummary} QC summary
26+
*/
27+
const mergeQcSummaries = (qcSummaries) => qcSummaries.reduce((acc, qcSummary) => {
28+
for (const [runNumber, runQcSummary] of Object.entries(qcSummary)) {
29+
acc[runNumber] = { ...acc[runNumber], ...runQcSummary };
30+
}
31+
return acc;
32+
}, {});
1833

1934
/**
2035
* RunsWithQcModel
@@ -34,6 +49,9 @@ export class RunsWithQcModel extends RunsOverviewModel {
3449
this._runDetectorsSelectionModel = new RunDetectorsSelectionModel();
3550
this._runDetectorsSelectionModel.bubbleTo(this);
3651

52+
this._qcSummary$ = new ObservableData(RemoteData.notAsked());
53+
this._qcSummary$.bubbleTo(this);
54+
3755
this.patchDisplayOptions({
3856
horizontalScrollEnabled: true,
3957
verticalScrollEnabled: true,
@@ -104,4 +122,61 @@ export class RunsWithQcModel extends RunsOverviewModel {
104122
}),
105123
}));
106124
}
125+
126+
/**
127+
* Abstract
128+
*/
129+
qcSummaryScope() {
130+
throw Error('Method not implemented');
131+
}
132+
133+
/**
134+
* Fetch QC summaries for given data pass
135+
* @return {Promise<void>} promise
136+
*/
137+
async _fetchQcSummary() {
138+
this._qcSummary$.setCurrent(RemoteData.loading());
139+
try {
140+
const { data: qcSummary1 } = await getRemoteData(buildUrl('/api/qcFlags/summary', {
141+
...this.qcSummaryScope(),
142+
detectorIds: this.detectors.match({
143+
Success: (detectors) => detectors
144+
.filter(({ type }) => type === DetectorType.PHYSICAL)
145+
.map(({ id }) => id).join(','),
146+
Other: () => undefined,
147+
}),
148+
mcReproducibleAsNotBad: this._mcReproducibleAsNotBad,
149+
}));
150+
151+
const { data: qcSummary2 } = await getRemoteData(buildUrl('/api/qcFlags/summary', {
152+
...this.qcSummaryScope(),
153+
detectorIds: this.detectors.match({
154+
Success: (detectors) => detectors
155+
.filter(({ type }) => [DetectorType.AOT_GLO, DetectorType.AOT_EVENT, DetectorType.MUON_GLO].includes(type))
156+
.map(({ id }) => id).join(','),
157+
Other: () => undefined,
158+
}),
159+
filter: {
160+
createdBy: {
161+
names: 'Anonymous',
162+
operator: 'none',
163+
},
164+
},
165+
mcReproducibleAsNotBad: this._mcReproducibleAsNotBad,
166+
}));
167+
console.log(qcSummary1)
168+
console.log(qcSummary2)
169+
this._qcSummary$.setCurrent(RemoteData.success(mergeQcSummaries([qcSummary1, qcSummary2])));
170+
} catch (error) {
171+
this._qcSummary$.setCurrent(RemoteData.failure(error));
172+
}
173+
}
174+
175+
/**
176+
* QC summary getter
177+
* @return {RemoteData<QcSummary>} QC summary
178+
*/
179+
get qcSummary() {
180+
return this._qcSummary$.getCurrent();
181+
}
107182
}

lib/public/views/Runs/RunPerDataPass/RunsPerDataPassOverviewModel.js

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
5353
this._detectors$.bubbleTo(this);
5454
this.registerDetectorsNotBadFractionFilterModels(this._detectors$);
5555

56-
this._qcSummary$ = new ObservableData(RemoteData.notAsked());
57-
this._qcSummary$.bubbleTo(this);
58-
5956
this._gaqSummary$ = new ObservableData(RemoteData.notAsked());
6057
this._gaqSummary$.bubbleTo(this);
6158

@@ -289,14 +286,6 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
289286
return this._detectors$.getCurrent();
290287
}
291288

292-
/**
293-
* QC summary getter
294-
* @return {RemoteData<QcSummary>} QC summary
295-
*/
296-
get qcSummary() {
297-
return this._qcSummary$.getCurrent();
298-
}
299-
300289
/**
301290
* GAQ summary getter
302291
* @return {RemoteData<GaqSummary>} GAQ summary
@@ -327,23 +316,6 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
327316
}
328317
}
329318

330-
/**
331-
* Fetch QC summaries for given data pass
332-
* @return {Promise<void>} promise
333-
*/
334-
async _fetchQcSummary() {
335-
this._qcSummary$.setCurrent(RemoteData.loading());
336-
try {
337-
const { data: qcSummary } = await getRemoteData(buildUrl('/api/qcFlags/summary', {
338-
dataPassId: this._dataPassId,
339-
mcReproducibleAsNotBad: this._mcReproducibleAsNotBad,
340-
}));
341-
this._qcSummary$.setCurrent(RemoteData.success(qcSummary));
342-
} catch (error) {
343-
this._qcSummary$.setCurrent(RemoteData.failure(error));
344-
}
345-
}
346-
347319
/**
348320
* Fetch GAQ summary for given data pass
349321
* @return {Promise<void>} resolves once data are fetched
@@ -376,4 +348,11 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
376348
this._skimmableRuns$.setCurrent(RemoteData.failure(error));
377349
}
378350
}
351+
352+
/**
353+
* @inheritdoc
354+
*/
355+
qcSummaryScope() {
356+
return { dataPassId: this.dataPassId };
357+
}
379358
}

lib/public/views/Runs/RunPerPeriod/RunsPerLhcPeriodOverviewModel.js

Lines changed: 3 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -170,44 +170,19 @@ class RunsPerLhcPeriodTabbedPanelModel extends TabbedPanelModel {
170170
this.currentPanelData = null;
171171
break;
172172
case RUNS_PER_LHC_PERIOD_PANELS_KEYS.SYNCHRONOUS_FLAGS:
173-
this._fetchSynchronousQcSummary();
173+
// this._fetchSynchronousQcSummary();
174174
break;
175175
}
176176
}
177177

178-
/**
179-
* Fetch QC summary for synchronous QC flags
180-
*
181-
* @return {Promise<void>} resolved once data are fetched
182-
*/
183-
async _fetchSynchronousQcSummary() {
184-
if (this._lhcPeriodId) {
185-
this.currentPanelData = RemoteData.loading();
186-
this.notify();
187-
try {
188-
const { data: qcSummary } = await jsonFetch(buildUrl(
189-
'/api/qcFlags/summary',
190-
{
191-
lhcPeriodId: this._lhcPeriodId,
192-
mcReproducibleAsNotBad: this._mcReproducibleAsNotBad,
193-
},
194-
));
195-
this.currentPanelData = RemoteData.success(qcSummary);
196-
} catch (errors) {
197-
this.currentPanelData = RemoteData.failure(errors);
198-
}
199-
this.notify();
200-
}
201-
}
202-
203178
/**
204179
* Set LHC period id
205180
*
206181
* @param {id} lhcPeriodId id of LHC period
207182
*/
208183
set lhcPeriodId(lhcPeriodId) {
209184
this._lhcPeriodId = lhcPeriodId;
210-
this._fetchCurrentPanelData();
185+
// this._fetchCurrentPanelData();
211186
}
212187

213188
/**
@@ -217,6 +192,6 @@ class RunsPerLhcPeriodTabbedPanelModel extends TabbedPanelModel {
217192
*/
218193
set mcReproducibleAsNotBad(mcReproducibleAsNotBad) {
219194
this._mcReproducibleAsNotBad = mcReproducibleAsNotBad;
220-
this._fetchCurrentPanelData();
195+
// this._fetchCurrentPanelData();
221196
}
222197
}

lib/public/views/Runs/RunsPerSimulationPass/RunsPerSimulationPassOverviewModel.js

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ export class RunsPerSimulationPassOverviewModel extends RunsWithQcModel {
3333

3434
this._simulationPass$ = new ObservableData(RemoteData.notAsked());
3535
this._simulationPass$.bubbleTo(this);
36-
37-
this._qcSummary$ = new ObservableData(RemoteData.NotAsked());
38-
this._qcSummary$.bubbleTo(this);
3936
}
4037

4138
/**
@@ -52,23 +49,6 @@ export class RunsPerSimulationPassOverviewModel extends RunsWithQcModel {
5249
}
5350
}
5451

55-
/**
56-
* Fetch QC summaries for given simulation pass
57-
* @return {Promise<void>} promise
58-
*/
59-
async _fetchQcSummary() {
60-
this._qcSummary$.setCurrent(RemoteData.loading());
61-
try {
62-
const { data: qcSummary } = await getRemoteData(buildUrl('/api/qcFlags/summary', {
63-
simulationPassId: this._simulationPassId,
64-
mcReproducibleAsNotBad: this._mcReproducibleAsNotBad,
65-
}));
66-
this._qcSummary$.setCurrent(RemoteData.success(qcSummary));
67-
} catch (error) {
68-
this._qcSummary$.setCurrent(RemoteData.failure(error));
69-
}
70-
}
71-
7252
/**
7353
* @inheritdoc
7454
*/
@@ -124,10 +104,9 @@ export class RunsPerSimulationPassOverviewModel extends RunsWithQcModel {
124104
}
125105

126106
/**
127-
* QC summary getter
128-
* @return {RemoteData<QcSummary>} QC summary
107+
* @inheritdoc
129108
*/
130-
get qcSummary() {
131-
return this._qcSummary$.getCurrent();
109+
qcSummaryScope() {
110+
return { simulationPassId: this.simulationPassId };
132111
}
133112
}

lib/server/controllers/qcFlag.controller.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,9 @@ const getQcFlagsSummaryHandler = async (req, res) => {
320320
DtoFactory.queryOnly(Joi.object({
321321
dataPassId: Joi.number(),
322322
simulationPassId: Joi.number(),
323-
mcReproducibleAsNotBad: Joi.boolean().optional(),
324323
lhcPeriodId: Joi.number(),
324+
detectorIds: Joi.string().trim().custom((value) => value.split(',').map((s) => s.trim())),
325+
mcReproducibleAsNotBad: Joi.boolean().optional(),
325326
filter: qcFlagFilterDTO,
326327
}).xor('dataPassId', 'simulationPassId', 'lhcPeriodId')),
327328
req,
@@ -333,12 +334,13 @@ const getQcFlagsSummaryHandler = async (req, res) => {
333334
dataPassId,
334335
simulationPassId,
335336
lhcPeriodId,
337+
detectorIds,
336338
mcReproducibleAsNotBad = false,
337339
filter,
338340
} = validatedDTO.query;
339341

340342
const data = await qcFlagSummaryService.getSummary(
341-
{ dataPassId, simulationPassId, lhcPeriodId },
343+
{ dataPassId, simulationPassId, lhcPeriodId, detectorIds },
342344
{ mcReproducibleAsNotBad },
343345
filter,
344346
);

0 commit comments

Comments
 (0)