File size: 1,961 Bytes
8ef7934 1eaee2c 8ef7934 4248ca3 8ef7934 b3db405 8ef7934 b3db405 |
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 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
import sys
def generate_recommendation(
risk_score,
region,
recent_incidents=None,
weather_alert=None,
intent=None,
origin=None,
destination=None
):
if origin and destination:
region_str = f"{origin} to {destination}"
else:
region_str = region
if risk_score >= 0.8:
level = "High risk"
message = (
f"{level} detected for {region_str}! Recent incidents or delays increase disruption probability. "
"Immediate mitigation advised—consider rerouting, switching suppliers, or delaying shipment."
)
action = "reroute/switch_supplier/delay"
elif risk_score >= 0.6:
level = "Elevated risk"
message = (
f"{level} in {region_str}. Monitor closely and prioritize more reliable suppliers and routes."
)
action = "monitor_prioritize"
elif risk_score >= 0.3:
level = "Moderate risk"
message = (
f"{level} for {region_str}. Standard operations are feasible, but stay alert for escalating risks."
)
action = "continue_monitor"
else:
level = "Low risk"
message = f"{level} for {region_str}. Proceed with routine operations."
action = "proceed"
if weather_alert:
message += f"\nWeather Alert: {weather_alert}"
if recent_incidents:
message += f"\nRecent incidents: {', '.join(recent_incidents[:3])}"
if recent_incidents and risk_score >= 0.8:
message += "\nSupply chain disruption likely due to recent incidents. Take immediate action to mitigate risk."
if intent == "mitigation_help" and risk_score >= 0.5:
message += "\nWould you like to view alternate routes or suppliers for mitigation?"
return {
"message": message,
"action": action,
"risk_score": risk_score,
"region": region_str
}
if __name__ == "__main__":
main()
|