Spaces:
Configuration error
Configuration error
File size: 1,528 Bytes
2452e46 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | from abc import ABC, abstractmethod
from typing import Dict, Any
import random
import time
class MessageGenerator(ABC):
@abstractmethod
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()
}
|