CoolFace
Apppublic

pcb-defect-detector-project/Finql-Project

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
severity.py25 linesDownload Raw Back to core
1# core/severity.py2from typing import List3from models.schemas import Detection4from core.config import DEFECT_SEVERITY, RECOMMENDATIONS5 6def calculate_severity(detections: List[Detection]) -> List[Detection]:7    """8    حساب الخطورة والأولوية لكل عيب9    """10    for d in detections:11        severity = DEFECT_SEVERITY.get(d.defect_type, {12            "score": 5.0, "level": "medium", "color": "#gray", "icon": "⚠️",13            "description_ar": "عيب غير معروف"14        })15        d.severity_score = severity["score"]16        d.severity_level = severity["level"]17        d.severity_color = severity["color"]18        d.severity_icon = severity["icon"]19        d.description_ar = severity["description_ar"]20        21        rec = RECOMMENDATIONS.get(d.defect_type, {})22        d.recommendation_ar = rec.get("ar", "يرجى مراجعة العيب وإصلاحه.")23    24    detections.sort(key=lambda x: x.severity_score, reverse=True)25    return detections