@@ -166,17 +166,44 @@ class QcFlagSummaryService {
166166 ? Math . min ( 1 , Math . max ( 0 , parseFloat ( effectiveRunCoverageString ) ) )
167167 : null ;
168168
169+ const flagIds = ( summaryDb . get ( 'flagIds' ) ?. split ( ',' ) ?? [ ] )
170+ . map ( ( id ) => parseInt ( id , 10 ) )
171+ . filter ( Number . isFinite )
172+ . sort ( ( a , b ) => a - b ) ;
173+
169174 return {
170175 runNumber : summaryDb . runNumber ,
171176 detectorId : summaryDb . detectorId ,
172177 effectiveRunCoverage,
173178 bad : Boolean ( summaryDb . get ( 'bad' ) ) ,
174- flagIds : ( summaryDb . get ( 'flagIds' ) ?. split ( ',' ) ?? [ ] ) . map ( ( id ) => parseInt ( id , 10 ) ) ,
179+ flagIds,
175180 mcReproducible : Boolean ( summaryDb . get ( 'mcReproducible' ) ) ,
176181 } ;
177182 } ) ;
178183
179184 const allFlagsIds = new Set ( runDetectorSummaryList . flatMap ( ( { flagIds } ) => flagIds ) ) ;
185+
186+ const miniCommentedFlagByFlagId = new Map ( ) ;
187+ if ( allFlagsIds . size > 0 ) {
188+ const flagsWithComments = await QcFlagRepository . findAll ( {
189+ attributes : [ 'id' , 'comment' ] ,
190+ where : { id : { [ Op . in ] : [ ...allFlagsIds ] } } ,
191+ include : [ { association : 'flagType' } ] ,
192+ } ) ;
193+
194+ for ( const { id, comment, flagType : { name, color } } of flagsWithComments ) {
195+ if ( comment ?. trim ( ) ) {
196+ miniCommentedFlagByFlagId . set ( id , { comment, flagType : { name, color } } ) ;
197+ }
198+ }
199+ }
200+
201+ for ( const summaryUnit of runDetectorSummaryList ) {
202+ summaryUnit . minifiedFlags = summaryUnit . flagIds
203+ . map ( ( id ) => ( { id, ...miniCommentedFlagByFlagId . get ( id ) } ) )
204+ . filter ( ( { comment } ) => Boolean ( comment ) ) ;
205+ }
206+
180207 const notVerifiedFlagsIds = new Set ( ( await QcFlagRepository . findAll ( {
181208 attributes : [ 'id' ] ,
182209 include : [ { association : 'verifications' , required : false , attributes : [ ] } ] ,
@@ -194,21 +221,39 @@ class QcFlagSummaryService {
194221 runNumber,
195222 detectorId,
196223 flagIds,
224+ minifiedFlags,
197225 } = runDetectorSummaryForFlagTypesClass ;
198226 const missingVerificationsCount = flagIds . filter ( ( id ) => notVerifiedFlagsIds . has ( id ) ) . length ;
199227
200228 if ( ! summary [ runNumber ] ) {
201229 summary [ runNumber ] = { } ;
202230 }
203231 if ( ! summary [ runNumber ] [ detectorId ] ) {
204- summary [ runNumber ] [ detectorId ] = { [ QcSummarProperties . MC_REPRODUCIBLE ] : false } ;
232+ summary [ runNumber ] [ detectorId ] = {
233+ [ QcSummarProperties . MC_REPRODUCIBLE ] : false ,
234+ [ QcSummarProperties . MINIFIED_FLAGS ] : [ ] ,
235+ } ;
205236 }
206237
207238 const runDetectorSummary = summary [ runNumber ] [ detectorId ] ;
208239
209240 runDetectorSummary [ QcSummarProperties . MISSING_VERIFICATIONS ] =
210241 ( runDetectorSummary [ QcSummarProperties . MISSING_VERIFICATIONS ] ?? 0 ) + missingVerificationsCount ;
211242
243+ if ( ! runDetectorSummary [ QcSummarProperties . MINIFIED_FLAGS ] ) {
244+ runDetectorSummary [ QcSummarProperties . MINIFIED_FLAGS ] = [ ] ;
245+ }
246+ if ( minifiedFlags . length > 0 ) {
247+ const existingFlagComments = runDetectorSummary [ QcSummarProperties . MINIFIED_FLAGS ] ;
248+ const existingIds = new Set ( existingFlagComments . map ( ( { id } ) => id ) ) ;
249+ for ( const miniCommentedFlagByFlagId of minifiedFlags ) {
250+ if ( ! existingIds . has ( miniCommentedFlagByFlagId . id ) ) {
251+ existingFlagComments . push ( miniCommentedFlagByFlagId ) ;
252+ existingIds . add ( miniCommentedFlagByFlagId . id ) ;
253+ }
254+ }
255+ }
256+
212257 QcFlagSummaryService . mergeIntoSummaryUnit ( runDetectorSummary , runDetectorSummaryForFlagTypesClass ) ;
213258 }
214259
0 commit comments