| from radon.complexity import cc_visit | |
| from src.universal_refactor.patch_generator import PatchGenerator | |
| def compute_complexity(c): | |
| try: return sum(b.complexity for b in cc_visit(c)) | |
| except: return 0 | |
| def evaluate_pair(a,b): | |
| diff=PatchGenerator.unified_diff(a,b) | |
| oc,nc=compute_complexity(a),compute_complexity(b) | |
| red=(oc-nc)/oc if oc else 0 | |
| ch=sum(1 for l in diff.splitlines() if l.startswith('+') or l.startswith('-')) | |
| clean=max(0,1-min(ch/400,1)) | |
| return {'complexity_reduction':red,'patch_cleanliness':clean,'diff':diff} | |