Download tools/task_validator.py from Ngwese175/Btc175: direct link, hf CLI and curl.
- Browser
- Download file 3.52 kB
-
https://huggingface.co/spaces/Ngwese175/Btc175/resolve/main/tools/task_validator.py
- Command line
-
hf download hf://spaces/Ngwese175/Btc175/tools/task_validator.py
-
curl -L -o task_validator.py https://huggingface.co/spaces/Ngwese175/Btc175/resolve/main/tools/task_validator.py
3.52 kB
| from typing import Dict, List | |
| import re | |
| from datetime import datetime | |
| class TaskValidator: | |
| def __init__(self): | |
| self.completion_criteria = { | |
| "code_review": self._validate_code_review, | |
| "bug_fix": self._validate_bug_fix, | |
| "feature_dev": self._validate_feature, | |
| "testing": self._validate_testing | |
| } | |
| def validate_completion(self, task_type: str, submission: Dict) -> Dict: | |
| """Validate if a task was completed successfully""" | |
| if task_type not in self.completion_criteria: | |
| return {"valid": False, "reason": "Unknown task type"} | |
| validator = self.completion_criteria[task_type] | |
| return validator(submission) | |
| def _validate_code_review(self, submission: Dict) -> Dict: | |
| """Validate code review completion""" | |
| required_fields = ["review_comments", "lines_reviewed", "security_issues_found"] | |
| for field in required_fields: | |
| if field not in submission: | |
| return {"valid": False, "reason": f"Missing {field}"} | |
| quality_score = self._calculate_quality_score(submission) | |
| return { | |
| "valid": quality_score >= 0.7, | |
| "quality_score": quality_score, | |
| "feedback": "Code review completed" if quality_score >= 0.7 else "Review needs improvement" | |
| } | |
| def _validate_bug_fix(self, submission: Dict) -> Dict: | |
| """Validate bug fix completion""" | |
| if not submission.get("pull_request_url"): | |
| return {"valid": False, "reason": "No PR submitted"} | |
| if not submission.get("tests_passed", False): | |
| return {"valid": False, "reason": "Tests not passing"} | |
| return { | |
| "valid": True, | |
| "quality_score": 1.0, | |
| "feedback": "Bug fix verified" | |
| } | |
| def _validate_feature(self, submission: Dict) -> Dict: | |
| """Validate feature development""" | |
| requirements_met = submission.get("requirements_met", []) | |
| total_requirements = submission.get("total_requirements", 1) | |
| completion_rate = len(requirements_met) / total_requirements if total_requirements > 0 else 0 | |
| return { | |
| "valid": completion_rate >= 0.9, | |
| "completion_rate": completion_rate, | |
| "feedback": f"Completed {completion_rate*100}% of requirements" | |
| } | |
| def _validate_testing(self, submission: Dict) -> Dict: | |
| """Validate testing completion""" | |
| coverage = submission.get("test_coverage", 0) | |
| passed_tests = submission.get("passed_tests", 0) | |
| total_tests = submission.get("total_tests", 1) | |
| test_pass_rate = passed_tests / total_tests if total_tests > 0 else 0 | |
| return { | |
| "valid": coverage >= 80 and test_pass_rate == 1.0, | |
| "coverage": coverage, | |
| "pass_rate": test_pass_rate, | |
| "feedback": "Testing validated" if coverage >= 80 else f"Coverage too low: {coverage}%" | |
| } | |
| def _calculate_quality_score(self, submission: Dict) -> float: | |
| """Calculate overall quality score""" | |
| score = 0.5 # Base score | |
| if submission.get("review_comments", 0) > 10: | |
| score += 0.2 | |
| if submission.get("lines_reviewed", 0) > 500: | |
| score += 0.15 | |
| if submission.get("security_issues_found", 0) > 0: | |
| score += 0.15 | |
| return min(score, 1.0) |