AIMLxDIV commited on
Commit
a42de15
·
unverified ·
2 Parent(s): 970a67069f5dde

Merge pull request #17 from DsThakurRawat/add-grader-bug

Browse files
codereview_env/graders/bug_grader.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from typing import List
2
+ from codereview_env.models import Scenario, ActionRecord, Category
3
+ from codereview_env.graders.grader_utils import find_best_match
4
+
5
+ def grade_bug_detection(scenario: Scenario, history: List[ActionRecord]) -> float:
6
+ """Grade bug detection: 0.4 * coverage + 0.6 * precision."""
7
+ flagged_actions = [r for r in history if r.category == Category.BUG]
8
+ if not scenario.ground_truth_issues:
9
+ return 1.0 if not flagged_actions else 0.0
10
+
11
+ found_ids = set()
12
+ matches = 0
13
+ already_matched = set()
14
+
15
+ for action in flagged_actions:
16
+ match = find_best_match(action, scenario.ground_truth_issues, already_matched)
17
+ if match:
18
+ matches += 1
19
+ found_ids.add(match.id)
20
+ already_matched.add(match.id)
21
+
22
+ recall = len(found_ids) / len(scenario.ground_truth_issues)
23
+ precision = matches / len(flagged_actions) if flagged_actions else 0.0
24
+
25
+ return round(0.7 * recall + 0.3 * precision, 4)