Update app.py
Browse files
app.py
CHANGED
@@ -97,6 +97,16 @@ def get_forecast_data(location):
|
|
97 |
except requests.exceptions.RequestException as e:
|
98 |
raise Exception(f"Failed to fetch forecast data: {str(e)}")
|
99 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
def determine_transmission_power(image_prediction, weather_data, forecast_data=None):
|
101 |
"""
|
102 |
Determine transmission power based on current conditions and forecast
|
@@ -144,7 +154,7 @@ def determine_transmission_power(image_prediction, weather_data, forecast_data=N
|
|
144 |
last_high_risk_idx = len(high_risk_periods) - 1 - high_risk_periods[::-1].index(True)
|
145 |
duration = forecast_data[last_high_risk_idx]['timestamp'] - weather_data['timestamp']
|
146 |
|
147 |
-
explanation.append(f"High fog risk predicted to continue for {duration
|
148 |
|
149 |
# Adjust power level based on forecast
|
150 |
if sum(high_risk_periods) / len(high_risk_periods) > 0.5:
|
@@ -184,7 +194,7 @@ def integrated_prediction(image, location):
|
|
184 |
*explanation,
|
185 |
"",
|
186 |
f"Recommended Power Level: {power_level}",
|
187 |
-
f"Duration: {duration
|
188 |
"",
|
189 |
"5-Day Forecast Summary:"
|
190 |
]
|
|
|
97 |
except requests.exceptions.RequestException as e:
|
98 |
raise Exception(f"Failed to fetch forecast data: {str(e)}")
|
99 |
|
100 |
+
def format_duration(duration):
|
101 |
+
"""Format timedelta into days and hours string"""
|
102 |
+
total_hours = duration.total_seconds() / 3600
|
103 |
+
days = int(total_hours // 24)
|
104 |
+
hours = int(total_hours % 24)
|
105 |
+
|
106 |
+
if days > 0:
|
107 |
+
return f"{days} days and {hours} hours"
|
108 |
+
return f"{hours} hours"
|
109 |
+
|
110 |
def determine_transmission_power(image_prediction, weather_data, forecast_data=None):
|
111 |
"""
|
112 |
Determine transmission power based on current conditions and forecast
|
|
|
154 |
last_high_risk_idx = len(high_risk_periods) - 1 - high_risk_periods[::-1].index(True)
|
155 |
duration = forecast_data[last_high_risk_idx]['timestamp'] - weather_data['timestamp']
|
156 |
|
157 |
+
explanation.append(f"High fog risk predicted to continue for {format_duration(duration)}")
|
158 |
|
159 |
# Adjust power level based on forecast
|
160 |
if sum(high_risk_periods) / len(high_risk_periods) > 0.5:
|
|
|
194 |
*explanation,
|
195 |
"",
|
196 |
f"Recommended Power Level: {power_level}",
|
197 |
+
f"Duration: {format_duration(duration)}",
|
198 |
"",
|
199 |
"5-Day Forecast Summary:"
|
200 |
]
|