Weather Integration Agent
Overview
The Weather Integration Agent integrates real-time weather data from multiple sources to enhance traffic predictions and provide context for traffic conditions. It correlates weather patterns with traffic incidents and congestion.
Features
- Multi-Source Integration: OpenWeatherMap, AccuWeather, local weather stations
- Real-time Updates: Weather data refresh every 5 minutes
- Historical Data: Weather pattern analysis for predictive modeling
- Severe Weather Alerts: Automatic notification system for extreme conditions
- Weather-Traffic Correlation: Link weather conditions to traffic patterns
- Air Quality Integration: Combined weather and air quality metrics
Architecture
graph TB
A[OpenWeatherMap API] --> D[Weather Agent]
B[AccuWeather API] --> D
C[Local Stations] --> D
D --> E[Data Normalizer]
E --> F[Weather Cache]
E --> G[MongoDB Storage]
F --> H[Traffic Correlation]
G --> H
H --> I[Pattern Recognition]
Configuration
File: config/data_sources.yaml
weather_sources:
openweathermap:
api_key: "${OPENWEATHER_API_KEY}"
base_url: "https://api.openweathermap.org/data/2.5"
endpoints:
current: "/weather"
forecast: "/forecast"
onecall: "/onecall"
units: "metric"
language: "vi"
update_intervals:
current_weather: 300 # 5 minutes
hourly_forecast: 3600 # 1 hour
daily_forecast: 21600 # 6 hours
severe_alerts: 60 # 1 minute
locations:
- name: "District 1"
lat: 10.7769
lon: 106.7009
- name: "Tan Son Nhat Airport"
lat: 10.8184
lon: 106.6520
thresholds:
heavy_rain_mm: 50
strong_wind_kmh: 40
high_temperature_c: 35
low_visibility_m: 1000
Usage
Basic Usage
from src.agents.data_collection.weather_integration_agent import WeatherIntegrationAgent
# Initialize agent
agent = WeatherIntegrationAgent()
# Get current weather for HCMC
weather = agent.get_current_weather(
lat=10.8231,
lon=106.6297
)
print(f"Temperature: {weather.temperature}°C")
print(f"Humidity: {weather.humidity}%")
print(f"Conditions: {weather.description}")
Weather Forecasting
# Get hourly forecast
hourly_forecast = agent.get_hourly_forecast(
lat=10.8231,
lon=106.6297,
hours=24
)
for hour in hourly_forecast:
print(f"{hour.timestamp}: {hour.temperature}°C, {hour.rain_probability}%")
# Get daily forecast
daily_forecast = agent.get_daily_forecast(
lat=10.8231,
lon=106.6297,
days=7
)
Severe Weather Monitoring
# Check for severe weather alerts
alerts = agent.get_severe_weather_alerts(location="HCMC")
for alert in alerts:
print(f"Alert: {alert.type}")
print(f"Severity: {alert.severity}")
print(f"Start: {alert.start_time}")
print(f"End: {alert.end_time}")
print(f"Description: {alert.description}")
Weather-Traffic Correlation
# Analyze weather impact on traffic
correlation = agent.analyze_weather_traffic_impact(
date_range=("2025-11-20", "2025-12-05"),
location="District 1"
)
print(f"Rain Impact: {correlation.rain_congestion_correlation}")
print(f"Temperature Impact: {correlation.temperature_speed_correlation}")
print(f"Peak Impact Hours: {correlation.peak_impact_hours}")