@@ -92,6 +92,23 @@ def to_json(self) -> Json:
9292 }
9393
9494
95+ @define
96+ class BenchmarkScore :
97+ score : int
98+ failed_checks : Dict [ReportSeverity , int ]
99+ failed_resources : Dict [ReportSeverity , int ]
100+
101+ def to_json (self ) -> Json :
102+ return {
103+ "score" : self .score ,
104+ "failed" : {
105+ severity .value : {"checks" : count , "resources" : fr }
106+ for severity , count in self .failed_checks .items ()
107+ if (fr := self .failed_resources .get (severity , 0 )) and count > 0
108+ },
109+ }
110+
111+
95112@define
96113class Remediation :
97114 kind : ClassVar [str ] = "fix_core_report_check_remediation"
@@ -368,23 +385,27 @@ def visit_check_collection(collection: CheckCollectionResult) -> None:
368385 visit_check_collection (self )
369386 return result
370387
371- def score_for (self , account : str ) -> int :
372- failing : Dict [ReportSeverity , int ] = defaultdict (int )
388+ # score, failed_checks, failed_resources
389+ def score_for (self , account : str ) -> BenchmarkScore :
390+ failing_checks : Dict [ReportSeverity , int ] = defaultdict (int )
391+ failing_resources : Dict [ReportSeverity , int ] = defaultdict (int )
373392 available : Dict [ReportSeverity , int ] = defaultdict (int )
374393
375394 def available_failing (check : CheckCollectionResult ) -> None :
376395 for result in check .checks :
396+ fr = result .number_of_resources_failing_by_account .get (account , 0 )
377397 available [result .check .severity ] += 1
378- failing [result .check .severity ] += (
379- 1 if result .number_of_resources_failing_by_account .get (account , 0 ) else 0
380- )
398+ failing_checks [result .check .severity ] += 1 if fr else 0
399+ failing_resources [result .check .severity ] += fr
381400 for child in check .children :
382401 available_failing (child )
383402
384403 available_failing (self ) # walk the benchmark hierarchy
385- missing = sum (severity .score * count for severity , count in failing .items ())
404+ missing = sum (severity .score * count for severity , count in failing_checks .items ())
386405 total = sum (severity .score * count for severity , count in available .items ())
387- return int ((max (0 , total - missing ) * 100 ) // total ) if total > 0 else 100
406+ return BenchmarkScore (
407+ int ((max (0 , total - missing ) * 100 ) // total ) if total > 0 else 100 , failing_checks , failing_resources
408+ )
388409
389410
390411class Inspector (ABC ):
0 commit comments