AjaykumarPilla commited on
Commit
756af64
·
verified ·
1 Parent(s): f9e5b26

Update model.py

Browse files
Files changed (1) hide show
  1. model.py +23 -1
model.py CHANGED
@@ -5,6 +5,7 @@ import torch.nn as nn
5
  import numpy as np
6
  import pickle
7
  from sklearn.preprocessing import StandardScaler
 
8
 
9
  # Configure logging
10
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
@@ -60,7 +61,8 @@ def get_weather_condition(score: int) -> str:
60
  def call_ai_model_for_insights(input_data: Dict, delay_risk: float) -> List[str]:
61
  """
62
  Generate detailed hardcoded insights based on input data and delay risk.
63
- Returns 3-5 prioritized, phase/task-specific insights tailored to conditions, with enhanced weather focus.
 
64
  """
65
  logger.info("Generating detailed hardcoded AI insights")
66
  phase = input_data.get("phase", "")
@@ -74,6 +76,7 @@ def call_ai_model_for_insights(input_data: Dict, delay_risk: float) -> List[str]
74
  weather_score = input_data.get("weather_impact_score", 0)
75
  weather_condition = input_data.get("weather_condition", get_weather_condition(weather_score))
76
  project_location = input_data.get("project_location", "Unknown")
 
77
 
78
  # Initialize insights with scores for prioritization
79
  insights = []
@@ -82,6 +85,25 @@ def call_ai_model_for_insights(input_data: Dict, delay_risk: float) -> List[str]
82
  def add_insight(message: str, priority: float):
83
  insights.append((message, priority))
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
  # Delay risk-based insights
86
  if delay_risk > 75:
87
  add_insight(f"Urgent: High delay risk detected for {phase}: {task} in {project_location}. Take immediate action.", 1.0)
 
5
  import numpy as np
6
  import pickle
7
  from sklearn.preprocessing import StandardScaler
8
+ from datetime import datetime, timedelta
9
 
10
  # Configure logging
11
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
 
61
  def call_ai_model_for_insights(input_data: Dict, delay_risk: float) -> List[str]:
62
  """
63
  Generate detailed hardcoded insights based on input data and delay risk.
64
+ Includes a 2-week risk alert if weather_forecast_date is within 14 days.
65
+ Returns 3-5 prioritized, phase/task-specific insights.
66
  """
67
  logger.info("Generating detailed hardcoded AI insights")
68
  phase = input_data.get("phase", "")
 
76
  weather_score = input_data.get("weather_impact_score", 0)
77
  weather_condition = input_data.get("weather_condition", get_weather_condition(weather_score))
78
  project_location = input_data.get("project_location", "Unknown")
79
+ weather_forecast_date = input_data.get("weather_forecast_date", "")
80
 
81
  # Initialize insights with scores for prioritization
82
  insights = []
 
85
  def add_insight(message: str, priority: float):
86
  insights.append((message, priority))
87
 
88
+ # 2-week risk alert
89
+ try:
90
+ forecast_date = datetime.strptime(weather_forecast_date, "%Y-%m-%d")
91
+ current_date = datetime(2025, 5, 26) # Fixed date as per system
92
+ two_weeks_later = current_date + timedelta(days=14)
93
+ if current_date <= forecast_date <= two_weeks_later:
94
+ if delay_risk > 75 or weather_score > 75:
95
+ add_insight(
96
+ f"⚠️ Critical 2-Week Risk Alert: High risk of delay for {phase}: {task} in {project_location} by {weather_forecast_date} due to {'severe weather' if weather_score > 75 else 'high delay probability'}. Implement contingency plans immediately.",
97
+ 1.2
98
+ )
99
+ elif delay_risk > 50 or weather_score > 50:
100
+ add_insight(
101
+ f"⚠️ 2-Week Risk Alert: Moderate risk of delay for {phase}: {task} in {project_location} by {weather_forecast_date}. Monitor closely and prepare mitigation measures.",
102
+ 1.1
103
+ )
104
+ except ValueError:
105
+ logger.warning("Invalid weather_forecast_date format; skipping 2-week risk alert")
106
+
107
  # Delay risk-based insights
108
  if delay_risk > 75:
109
  add_insight(f"Urgent: High delay risk detected for {phase}: {task} in {project_location}. Take immediate action.", 1.0)