def calculate_vendor_score(delay_percent, qa_incidents, safety_compliance, feedback_score): # Weighted scoring logic (example weights as per PMO agreement) quality_weight = 0.4 timeliness_weight = 0.3 safety_weight = 0.2 communication_weight = 0.1 # Calculate individual scores (scale to 100) quality_score = (1 - qa_incidents / 10) * 100 # Example: Fewer incidents = higher score timeliness_score = (1 - delay_percent / 100) * 100 # Example: Less delay = higher score safety_score = safety_compliance * 100 # Compliance % directly maps to score communication_score = feedback_score * 20 # Feedback (1-5 scale) to 100 # Final weighted score final_score = ( quality_score * quality_weight + timeliness_score * timeliness_weight + safety_score * safety_weight + communication_score * communication_weight ) # Trend detection (dummy logic for now, can enhance later) trend_deviation = 0 # Placeholder (compare with previous month if available) # Alert flag (if final score < 60, flag as risk) alert_flag = final_score < 60 # JSON response return { "quality_score": round(quality_score, 2), "timeliness_score": round(timeliness_score, 2), "safety_score": round(safety_score, 2), "communication_score": round(communication_score, 2), "final_score": round(final_score, 2), "trend_deviation": trend_deviation, "alert_flag": alert_flag }