Spaces:
Configuration error
Configuration error
| from abc import ABC, abstractmethod | |
| from typing import Dict, Any | |
| import random | |
| import time | |
| class MessageGenerator(ABC): | |
| def generate_message(self) -> Dict[str, Any]: | |
| pass | |
| class OrderMessageGenerator(MessageGenerator): | |
| def generate_message(self) -> Dict[str, Any]: | |
| order_id = f"ORD-{random.randint(1000, 9999)}" | |
| return { | |
| "order_id": order_id, | |
| "customer_id": f"CUST-{random.randint(100, 999)}", | |
| "amount": round(random.uniform(10.0, 1000.0), 2), | |
| "items": random.randint(1, 10), | |
| "timestamp": time.time() | |
| } | |
| class NotificationMessageGenerator(MessageGenerator): | |
| def generate_message(self) -> Dict[str, Any]: | |
| return { | |
| "notification_id": f"NOTIF-{random.randint(1000, 9999)}", | |
| "user_id": f"USER-{random.randint(100, 999)}", | |
| "type": random.choice(["email", "sms", "push"]), | |
| "priority": random.choice(["high", "medium", "low"]), | |
| "timestamp": time.time() | |
| } | |
| class AnalyticsMessageGenerator(MessageGenerator): | |
| def generate_message(self) -> Dict[str, Any]: | |
| return { | |
| "event_id": f"EVT-{random.randint(1000, 9999)}", | |
| "event_type": random.choice(["page_view", "click", "purchase", "login"]), | |
| "user_id": f"USER-{random.randint(100, 999)}", | |
| "session_id": f"SESSION-{random.randint(1000, 9999)}", | |
| "timestamp": time.time() | |
| } | |