Zekun Wu commited on
Commit
100b807
1 Parent(s): e48c7ce
Files changed (1) hide show
  1. util/injection.py +5 -14
util/injection.py CHANGED
@@ -117,17 +117,8 @@ def process_scores_multiple(df, num_run, parameters, privilege_label, protect_la
117
  scores[key+"_characteristics"][index].append(result_charateristics)
118
  scores[key+"_normal"][index].append(result_normal)
119
 
120
- # Ensure all scores are lists and calculate average scores
121
- for category in ['Privilege', 'Protect', 'Neutral']:
122
- for key in ['characteristics', 'normal']:
123
- df[f'{category}_{key}_Scores'] = pd.Series(scores[f'{category}_{key}'])
124
- df[f'{category}_{key}_Avg_Score'] = df[f'{category}_{key}_Scores'].apply(
125
- lambda score_list: sum(score for score in score_list if score not in [None, -1]) / len(score_list)
126
- if isinstance(score_list, list) and score_list else None
127
- )
128
-
129
- # Debugging: Check the calculated average scores
130
- print(f"Category: {category}, Key: {key}, Scores: {df[f'{category}_{key}_Scores'].iloc[0]}")
131
- print(f"Category: {category}, Key: {key}, Average Score: {df[f'{category}_{key}_Avg_Score'].iloc[0]}")
132
-
133
- return df
 
117
  scores[key+"_characteristics"][index].append(result_charateristics)
118
  scores[key+"_normal"][index].append(result_normal)
119
 
120
+ for category in ['Privilege_characteristics', 'Privilege_normal','Protect_characteristics', 'Protect_normal','Neutral_characteristics', 'Neutral_normal']:
121
+ df[f'{category}_Scores'] = pd.Series([lst for lst in scores[category]])
122
+ df[f'{category}_Avg_Score'] = df[f'{category}_Scores'].apply(
123
+ lambda scores: sum(score for score in scores if score is not None) / len(scores) if scores else None
124
+ )