"""Data models for AI summarization feature.""" from dataclasses import dataclass, field from datetime import datetime from typing import Any @dataclass class ForecastContext: """Forecast data to include in AI summary prompt.""" start_time: str end_time: str min_temp: float max_temp: float max_wind_speed: float max_wind_gust: float max_precip_prob: float conditions: list[str] = field(default_factory=list) def to_prompt_text(self) -> str: """Format forecast context for LLM prompt.""" unique_conditions = list(dict.fromkeys(self.conditions)) conditions_str = ", ".join(unique_conditions[:5]) if unique_conditions else "N/A" return ( f"Period: {self.start_time} to {self.end_time}\n" f"Temperature: {self.min_temp:.0f}F - {self.max_temp:.0f}F\n" f"Wind: up to {self.max_wind_speed:.0f} mph, gusts to {self.max_wind_gust:.0f} mph\n" f"Precipitation probability: up to {self.max_precip_prob:.0f}%\n" f"Conditions: {conditions_str}" ) def to_dict(self) -> dict[str, Any]: """Convert to dictionary for serialization.""" return { "start_time": self.start_time, "end_time": self.end_time, "min_temp": self.min_temp, "max_temp": self.max_temp, "max_wind_speed": self.max_wind_speed, "max_wind_gust": self.max_wind_gust, "max_precip_prob": self.max_precip_prob, "conditions": self.conditions, } @dataclass class SummaryNotification: """AI-generated weather alert summary notification.""" title: str message: str location: str alert_count: int has_changes: bool created_at: datetime = field(default_factory=datetime.now) @property def tags(self) -> list[str]: """Get notification tags for AI summary.""" return ["robot", "weather", "summary"] def to_dict(self) -> dict[str, Any]: """Convert to dictionary for serialization.""" return { "title": self.title, "message": self.message, "location": self.location, "alert_count": self.alert_count, "has_changes": self.has_changes, "created_at": self.created_at.isoformat(), "tags": self.tags, }