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' ;
1515import { NumericalComparisonFilterModel } from '../../../components/Filters/common/filters/NumericalComparisonFilterModel.js' ;
1616import { RunDetectorsSelectionModel } from '../RunDetectorsSelectionModel.js' ;
17+ import { getRemoteData } from '../../../utilities/fetch/getRemoteData.js' ;
1718import { 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}
0 commit comments