@@ -22,6 +22,7 @@ import { SkimmingStage } from '../../../domain/enums/SkimmingStage.js';
2222import { NumericalComparisonFilterModel } from '../../../components/Filters/common/filters/NumericalComparisonFilterModel.js' ;
2323import { jsonFetch } from '../../../utilities/fetch/jsonFetch.js' ;
2424import { mergeRemoteData } from '../../../utilities/mergeRemoteData.js' ;
25+ import { RemoteDataSource } from '../../../utilities/fetch/RemoteDataSource.js' ;
2526import { DetectorType } from '../../../domain/enums/DetectorTypes.js' ;
2627
2728const ALL_CPASS_PRODUCTIONS_REGEX = / c p a s s \d + / ;
@@ -58,6 +59,12 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
5859 this . _markAsSkimmableRequestResult$ = new ObservableData ( RemoteData . notAsked ( ) ) ;
5960 this . _markAsSkimmableRequestResult$ . bubbleTo ( this ) ;
6061
62+ this . _gaqSummary$ = new ObservableData ( { } ) ;
63+ this . _gaqSummary$ . bubbleTo ( this ) ;
64+
65+ this . _gaqSummarySources = { } ;
66+ this . _gaqSequenceAbortController = null ;
67+
6168 this . _skimmableRuns$ = new ObservableData ( RemoteData . notAsked ( ) ) ;
6269 this . _skimmableRuns$ . bubbleTo ( this ) ;
6370
@@ -71,6 +78,8 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
7178
7279 this . _discardAllQcFlagsActionState$ = new ObservableData ( RemoteData . notAsked ( ) ) ;
7380 this . _discardAllQcFlagsActionState$ . bubbleTo ( this ) ;
81+
82+ this . _item$ . observe ( ( ) => this . _fetchGaqSummaryForCurrentRuns ( ) ) ;
7483 }
7584
7685 /**
@@ -321,6 +330,83 @@ export class RunsPerDataPassOverviewModel extends FixedPdpBeamTypeRunsOverviewMo
321330 }
322331 }
323332
333+ /**
334+ * Cancel all ongoing and future GAQ summary fetches
335+ * @return {void } promise
336+ */
337+ _abortGaqFetches ( ) {
338+ // Aborts the overall sequence fetch, i.e. stops further individual run fetches
339+ this . _gaqSequenceAbortController ?. abort ( ) ;
340+
341+ // Aborts individual run fetches in-flight
342+ for ( const runNumber in this . _gaqSummarySources ) {
343+ this . _gaqSummarySources [ runNumber ] ?. _abortController ?. abort ( ) ;
344+ }
345+ }
346+
347+ /**
348+ * Fetch GAQ summary for given data pass and run
349+ * @param {number } [runNumber] run number to filter by
350+ * @return {Promise<void> } resolves once data has been fetched
351+ */
352+ async _fetchGaqSummary ( runNumber ) {
353+ this . _gaqSummarySources [ runNumber ] = new RemoteDataSource ( ) ;
354+ // Pipe the result into the correct slot in the gaqSummary$ observable
355+ this . _gaqSummarySources [ runNumber ] . pipe ( {
356+ setCurrent : ( remoteData ) => {
357+ const current = this . _gaqSummary$ . getCurrent ( ) ;
358+ this . _gaqSummary$ . setCurrent ( {
359+ ...current ,
360+ [ runNumber ] : remoteData . apply ( { Success : ( response ) => response . data } ) ,
361+ } ) ;
362+ } ,
363+ } ) ;
364+ const url = buildUrl ( '/api/qcFlags/summary/gaq' , {
365+ dataPassId : this . _dataPassId ,
366+ mcReproducibleAsNotBad : this . _mcReproducibleAsNotBad ,
367+ runNumber : runNumber ,
368+ } ) ;
369+ await this . _gaqSummarySources [ runNumber ] . fetch ( url ) ;
370+ }
371+
372+ /**
373+ * Fetch GAQ summary for currently displayed (paginated) runs
374+ * @return {void }
375+ */
376+ _fetchGaqSummaryForCurrentRuns ( ) {
377+ // Stop any previous fetch (quickly changing filters, pagination, etc)
378+ this . _abortGaqFetches ( ) ;
379+
380+ // Reset abort controller
381+ this . _gaqSequenceAbortController = new AbortController ( ) ;
382+ const { signal } = this . _gaqSequenceAbortController ;
383+
384+ this . _item$ . getCurrent ( ) . match ( {
385+ Success : async ( runs ) => {
386+ const runNumbers = runs . map ( ( run ) => run . runNumber ) ;
387+
388+ // Prepare GAQ summary object with NotAsked RemoteData state for all runs
389+ let gaqSummary = { } ;
390+ for ( const runNumber of runNumbers ) {
391+ gaqSummary = { ...gaqSummary , [ runNumber ] : RemoteData . notAsked ( ) } ;
392+ }
393+ this . _gaqSummary$ . setCurrent ( gaqSummary ) ;
394+
395+ // Trigger GAQ summary fetch for each run
396+ for ( const runNumber of runNumbers ) {
397+ if ( signal . aborted ) {
398+ return ;
399+ }
400+
401+ await this . _fetchGaqSummary ( runNumber ) ;
402+ }
403+ } ,
404+ Other : ( ) => {
405+ // Don't fetch if runs haven't loaded successfully yet
406+ } ,
407+ } ) ;
408+ }
409+
324410 /**
325411 * Fetch skimmable runs for given data pass
326412 * @return {Promise<void> } resolves once data are fetched
0 commit comments