@@ -19,7 +19,7 @@ def __init__(self, name: str, analysis_results: dict[str, AnalysisResult]) -> No
1919 self .source_path = None
2020 self .analysis_results = analysis_results
2121 self .lang = None
22- self .sasts = []
22+ self .sast_names = []
2323 self .files = set ()
2424 self .defects = []
2525
@@ -30,12 +30,12 @@ def __init__(self, name: str, analysis_results: dict[str, AnalysisResult]) -> No
3030 else :
3131 assert analysis_result .lang == self .lang
3232 assert analysis_result .source_path == self .source_path
33- self .sasts .append (sast_name )
33+ self .sast_names .append (sast_name )
3434 self .files |= set (analysis_result .files )
3535 self .defects += analysis_result .defects
3636
3737 self .category_mapping = {}
38- for sast_name in self .sasts :
38+ for sast_name in self .sast_names :
3939 sast = SASTS_ALL [sast_name ]["sast" ]
4040 for category_name , color in sast .color_mapping .items ():
4141 if color .lower () == "red" :
@@ -55,7 +55,7 @@ def __repr__(self) -> str:
5555 return f"""{ self .__class__ .__name__ } (
5656 name: \t { self .name }
5757 lang: \t { self .lang }
58- sasts: \t { self .sasts }
58+ sasts: \t { self .sast_names }
5959 file_count: \t { len (self .files )}
6060 defect_count: \t { len (self .defects )}
6161)"""
@@ -142,11 +142,15 @@ def stats_by_scores(self) -> dict:
142142 for defect_file , defects in defect_files .items ():
143143 defects_cwes = {d .cwe for d in defects if d .cwe .id != - 1 }
144144
145- cwes_found_by_all_sasts = 0
145+ defects_same_cwe = 0
146146 for cwe in defects_cwes :
147147 cwes_sasts = {d .sast for d in defects if d .cwe == cwe }
148- if set (self .sasts ) == cwes_sasts :
149- cwes_found_by_all_sasts += 1
148+ if set (self .sast_names ) == cwes_sasts :
149+ defects_same_cwe += 1
150+ else :
151+ defects_same_cwe += (
152+ len (set (self .sast_names ) & cwes_sasts ) - 1
153+ ) / len (self .sast_names )
150154
151155 defect_locations = {}
152156 for defect in defects :
@@ -158,7 +162,7 @@ def stats_by_scores(self) -> dict:
158162 defects_same_location = 0
159163 defects_same_location_same_cwe = 0
160164 for _ , defects_ in defect_locations .items ():
161- if set (defect .sast for defect in defects_ ) == set (self .sasts ):
165+ if set (defect .sast for defect in defects_ ) == set (self .sast_names ):
162166 defects_same_location += 1
163167 defects_by_cwe = {}
164168 for defect in defects_ :
@@ -167,17 +171,27 @@ def stats_by_scores(self) -> dict:
167171 defects_by_cwe [defect .cwe ].append (defect )
168172
169173 for _ , defects_ in defects_by_cwe .items ():
170- if set (defect .sast for defect in defects_ ) == set (self .sasts ):
174+ if set (defect .sast for defect in defects_ ) == set (
175+ self .sast_names
176+ ):
171177 defects_same_location_same_cwe += 1
178+ else :
179+ defects_same_location_same_cwe += (
180+ len (
181+ set (defect .sast for defect in defects_ )
182+ & set (self .sast_names )
183+ )
184+ - 1
185+ ) / len (self .sast_names )
172186
173187 stats [defect_file ] = {
174188 "score" : {
175189 "defect_number" : len (defects ),
176- "unique_cwes_number " : len ( defects_cwes ) ,
177- "cwes_found_by_all_sasts " : cwes_found_by_all_sasts ,
178- "defects_same_location " : defects_same_location ,
179- "defects_same_location_same_cwe" : defects_same_location_same_cwe ,
180- }
190+ "defects_same_cwe " : defects_same_cwe * 2 ,
191+ "defects_same_location " : defects_same_location * 4 ,
192+ "defects_same_location_same_cwe " : defects_same_location_same_cwe
193+ * 8 ,
194+ },
181195 }
182196
183197 return stats
0 commit comments