File size: 1,263 Bytes
495526b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
from backend.app.models.schemas import RiskAssessmentResponse

HAZARD_BASE = {
    "earthquake": 0.78,
    "flood": 0.72,
    "wildfire": 0.7,
    "hurricane": 0.75,
    "cyclone": 0.73,
    "pandemic": 0.8,
    "chemical spill": 0.68,
    "nuclear incident": 0.9,
}


def compute_risk(hazard_type: str, vulnerability_index: float, exposure_index: float) -> RiskAssessmentResponse:
    hazard_weight = HAZARD_BASE.get(hazard_type.strip().lower(), 0.6)
    raw_score = 0.4 * hazard_weight + 0.3 * vulnerability_index + 0.3 * exposure_index
    risk_score = round(min(max(raw_score, 0.0), 1.0), 3)

    if risk_score < 0.3:
        level = "low"
        recommendation = "Maintain preparedness drills and monitor regional advisories."
    elif risk_score < 0.55:
        level = "moderate"
        recommendation = "Pre-position supplies and activate local coordination channels."
    elif risk_score < 0.8:
        level = "high"
        recommendation = "Activate emergency response teams and prepare evacuation plans."
    else:
        level = "critical"
        recommendation = "Issue immediate alerts, mobilize cross-agency command, and request aid."

    return RiskAssessmentResponse(risk_score=risk_score, risk_level=level, recommendation=recommendation)