"""UserHistory — normalised view of a user's feedback events for inference.""" from __future__ import annotations from dataclasses import dataclass, field from datetime import datetime, timezone @dataclass class FeedbackEvent: action: str # 'done' | 'dismiss' | 'snooze' | 'helpful' | 'not_helpful' dwell_ms: int | None created_at: str # ISO 8601 @property def hour(self) -> int: """Hour of day (0-23) when the feedback was recorded.""" try: dt = datetime.fromisoformat(self.created_at.replace("Z", "+00:00")) except ValueError: return 12 if dt.tzinfo is None: dt = dt.replace(tzinfo=timezone.utc) return dt.hour @dataclass class UserHistory: user_id: str events: list[FeedbackEvent] = field(default_factory=list)