Spaces:
Sleeping
Sleeping
| import numpy as np | |
| class RuleBasedQualityEvaluator: | |
| def evaluate(self, f: dict, shape: str): | |
| shape = shape.lower() | |
| if shape == "circle": | |
| circ = f["circularity"] | |
| ecc = f["eccentricity"] | |
| score = np.clip((circ - 0.8) / 0.2, 0, 1) | |
| if circ >= 0.95 and ecc < 0.3: | |
| return "perfect", float(score) | |
| elif circ >= 0.85: | |
| return "medium", float(score * 0.8) | |
| else: | |
| return "irregular", float(score * 0.6) | |
| if shape in ["square", "rectangle"]: | |
| ang = f["angle_error"] | |
| side_var = f["side_length_variance"] | |
| score = 1 - np.clip((ang/30 + side_var) / 2, 0, 1) | |
| if ang <= 5 and side_var <= 0.05: | |
| return "perfect", float(score) | |
| elif ang <= 15 and side_var <= 0.15: | |
| return "medium", float(score * 0.8) | |
| else: | |
| return "irregular", float(score * 0.6) | |
| if shape == "triangle": | |
| ang = f["angle_error"] | |
| side_var = f["side_length_variance"] | |
| score = 1 - np.clip((ang/25 + side_var) / 2, 0, 1) | |
| if ang <= 5 and side_var <= 0.05: | |
| return "perfect", float(score) | |
| elif ang <= 15 and side_var <= 0.15: | |
| return "medium", float(score * 0.8) | |
| else: | |
| return "irregular", float(score * 0.6) | |
| return "unknown", 0.0 | |