@@ -159,17 +159,44 @@ class QcFlagSummaryService {
159159 ? Math . min ( 1 , Math . max ( 0 , parseFloat ( effectiveRunCoverageString ) ) )
160160 : null ;
161161
162+ const flagIds = ( summaryDb . get ( 'flagIds' ) ?. split ( ',' ) ?? [ ] )
163+ . map ( ( id ) => parseInt ( id , 10 ) )
164+ . filter ( Number . isFinite )
165+ . sort ( ( a , b ) => a - b ) ;
166+
162167 return {
163168 runNumber : summaryDb . runNumber ,
164169 detectorId : summaryDb . detectorId ,
165170 effectiveRunCoverage,
166171 bad : Boolean ( summaryDb . get ( 'bad' ) ) ,
167- flagIds : ( summaryDb . get ( 'flagIds' ) ?. split ( ',' ) ?? [ ] ) . map ( ( id ) => parseInt ( id , 10 ) ) ,
172+ flagIds,
168173 mcReproducible : Boolean ( summaryDb . get ( 'mcReproducible' ) ) ,
169174 } ;
170175 } ) ;
171176
172177 const allFlagsIds = new Set ( runDetectorSummaryList . flatMap ( ( { flagIds } ) => flagIds ) ) ;
178+
179+ const miniCommentedFlagByFlagId = new Map ( ) ;
180+ if ( allFlagsIds . size > 0 ) {
181+ const flagsWithComments = await QcFlagRepository . findAll ( {
182+ attributes : [ 'id' , 'comment' ] ,
183+ where : { id : { [ Op . in ] : [ ...allFlagsIds ] } } ,
184+ include : [ { association : 'flagType' } ] ,
185+ } ) ;
186+
187+ for ( const { id, comment, flagType : { name, color } } of flagsWithComments ) {
188+ if ( comment ?. trim ( ) ) {
189+ miniCommentedFlagByFlagId . set ( id , { comment, flagType : { name, color } } ) ;
190+ }
191+ }
192+ }
193+
194+ for ( const summaryUnit of runDetectorSummaryList ) {
195+ summaryUnit . flagComments = summaryUnit . flagIds
196+ . map ( ( id ) => ( { id, ...miniCommentedFlagByFlagId . get ( id ) } ) )
197+ . filter ( ( { comment } ) => Boolean ( comment ) ) ;
198+ }
199+
173200 const notVerifiedFlagsIds = new Set ( ( await QcFlagRepository . findAll ( {
174201 attributes : [ 'id' ] ,
175202 include : [ { association : 'verifications' , required : false , attributes : [ ] } ] ,
@@ -187,21 +214,39 @@ class QcFlagSummaryService {
187214 runNumber,
188215 detectorId,
189216 flagIds,
217+ flagComments,
190218 } = runDetectorSummaryForFlagTypesClass ;
191219 const missingVerificationsCount = flagIds . filter ( ( id ) => notVerifiedFlagsIds . has ( id ) ) . length ;
192220
193221 if ( ! summary [ runNumber ] ) {
194222 summary [ runNumber ] = { } ;
195223 }
196224 if ( ! summary [ runNumber ] [ detectorId ] ) {
197- summary [ runNumber ] [ detectorId ] = { [ QcSummarProperties . MC_REPRODUCIBLE ] : false } ;
225+ summary [ runNumber ] [ detectorId ] = {
226+ [ QcSummarProperties . MC_REPRODUCIBLE ] : false ,
227+ [ QcSummarProperties . FLAG_COMMENTS ] : [ ] ,
228+ } ;
198229 }
199230
200231 const runDetectorSummary = summary [ runNumber ] [ detectorId ] ;
201232
202233 runDetectorSummary [ QcSummarProperties . MISSING_VERIFICATIONS ] =
203234 ( runDetectorSummary [ QcSummarProperties . MISSING_VERIFICATIONS ] ?? 0 ) + missingVerificationsCount ;
204235
236+ if ( ! runDetectorSummary [ QcSummarProperties . FLAG_COMMENTS ] ) {
237+ runDetectorSummary [ QcSummarProperties . FLAG_COMMENTS ] = [ ] ;
238+ }
239+ if ( flagComments . length > 0 ) {
240+ const existingFlagComments = runDetectorSummary [ QcSummarProperties . FLAG_COMMENTS ] ;
241+ const existingIds = new Set ( existingFlagComments . map ( ( { id } ) => id ) ) ;
242+ for ( const miniCommentedFlagByFlagId of flagComments ) {
243+ if ( ! existingIds . has ( miniCommentedFlagByFlagId . id ) ) {
244+ existingFlagComments . push ( miniCommentedFlagByFlagId ) ;
245+ existingIds . add ( miniCommentedFlagByFlagId . id ) ;
246+ }
247+ }
248+ }
249+
205250 QcFlagSummaryService . mergeIntoSummaryUnit ( runDetectorSummary , runDetectorSummaryForFlagTypesClass ) ;
206251 }
207252
0 commit comments