Spaces:
Sleeping
Sleeping
# risk_model.py | |
import numpy as np | |
def predict_risk(temp, duration): | |
""" | |
Predicts the risk level, risk score, and alert for a given temperature and duration. | |
Args: | |
- temp (float): The maximum temperature of the heating mantle. | |
- duration (float): The duration the mantle is used. | |
Returns: | |
- tuple: (risk_level, risk_score, alert) | |
""" | |
# Define risk level, score, and alert based on temperature and duration conditions | |
if temp <= 100 and duration <= 45: | |
# Low Risk: temperature between 0°C and 100°C, and duration <= 45 minutes | |
risk_level = "Low" | |
risk_score = np.random.uniform(0, 33) # Low risk score (0 to 33%) | |
alert = "Safe" | |
elif 101 <= temp <= 150 and 46 <= duration <= 70: | |
# Moderate Risk: temperature between 101°C and 150°C, and duration between 46 and 70 minutes | |
risk_level = "Moderate" | |
risk_score = np.random.uniform(34, 66) # Moderate risk score (34 to 66%) | |
alert = "Risk" | |
else: | |
# High Risk: temperature between 151°C and 200°C, and duration > 70 minutes | |
risk_level = "High" | |
risk_score = np.random.uniform(67, 100) # High risk score (67 to 100%) | |
alert = "High Risk" | |
return risk_level, round(risk_score, 2), alert | |