Spaces:
Sleeping
Sleeping
#!/usr/bin/env python3 | |
""" | |
Mock Data Service | |
Provides sample customer data for testing when external backend is not available | |
""" | |
import json | |
import random | |
from datetime import datetime, timedelta | |
from typing import List, Dict, Any | |
class MockDataService: | |
def __init__(self): | |
self.sample_properties = [ | |
{ | |
"propertyId": 1, | |
"propertyName": "Luxury Villa in Palm Jumeirah", | |
"propertyTypeName": "Villa", | |
"price": 15000000, | |
"viewCount": 15, | |
"totalDuration": 4500, | |
"lastViewedAt": "2024-01-15T10:30:00Z", | |
"location": "Palm Jumeirah", | |
"bedrooms": 5, | |
"bathrooms": 6, | |
"area": 8500, | |
"features": ["Private Pool", "Garden", "Gym", "Security"] | |
}, | |
{ | |
"propertyId": 2, | |
"propertyName": "Modern Apartment in Downtown", | |
"propertyTypeName": "Apartment", | |
"price": 3500000, | |
"viewCount": 8, | |
"totalDuration": 2800, | |
"lastViewedAt": "2024-01-14T14:20:00Z", | |
"location": "Downtown Dubai", | |
"bedrooms": 2, | |
"bathrooms": 2, | |
"area": 1200, | |
"features": ["Balcony", "Gym", "Pool", "Parking"] | |
}, | |
{ | |
"propertyId": 3, | |
"propertyName": "Beachfront Penthouse", | |
"propertyTypeName": "Penthouse", | |
"price": 25000000, | |
"viewCount": 12, | |
"totalDuration": 5200, | |
"lastViewedAt": "2024-01-13T16:45:00Z", | |
"location": "JBR", | |
"bedrooms": 4, | |
"bathrooms": 5, | |
"area": 3200, | |
"features": ["Beach Access", "Private Terrace", "Concierge", "Spa"] | |
}, | |
{ | |
"propertyId": 4, | |
"propertyName": "Family Villa in Emirates Hills", | |
"propertyTypeName": "Villa", | |
"price": 18000000, | |
"viewCount": 6, | |
"totalDuration": 3800, | |
"lastViewedAt": "2024-01-12T11:15:00Z", | |
"location": "Emirates Hills", | |
"bedrooms": 6, | |
"bathrooms": 7, | |
"area": 9500, | |
"features": ["Garden", "Pool", "Gym", "Staff Quarters"] | |
}, | |
{ | |
"propertyId": 5, | |
"propertyName": "Investment Apartment", | |
"propertyTypeName": "Apartment", | |
"price": 2200000, | |
"viewCount": 4, | |
"totalDuration": 1500, | |
"lastViewedAt": "2024-01-11T09:30:00Z", | |
"location": "Dubai Marina", | |
"bedrooms": 1, | |
"bathrooms": 1, | |
"area": 800, | |
"features": ["Marina View", "Gym", "Pool", "Rental Ready"] | |
}, | |
{ | |
"propertyId": 6, | |
"propertyName": "Luxury Townhouse", | |
"propertyTypeName": "Townhouse", | |
"price": 8500000, | |
"viewCount": 10, | |
"totalDuration": 4200, | |
"lastViewedAt": "2024-01-10T13:20:00Z", | |
"location": "Arabian Ranches", | |
"bedrooms": 4, | |
"bathrooms": 4, | |
"area": 2800, | |
"features": ["Garden", "Pool", "Golf Course", "Community"] | |
}, | |
{ | |
"propertyId": 7, | |
"propertyName": "Premium Office Space", | |
"propertyTypeName": "Office", | |
"price": 12000000, | |
"viewCount": 3, | |
"totalDuration": 1800, | |
"lastViewedAt": "2024-01-09T15:45:00Z", | |
"location": "DIFC", | |
"bedrooms": 0, | |
"bathrooms": 2, | |
"area": 5000, | |
"features": ["Premium Location", "Security", "Parking", "Meeting Rooms"] | |
}, | |
{ | |
"propertyId": 8, | |
"propertyName": "Retail Space in Mall", | |
"propertyTypeName": "Retail", | |
"price": 8000000, | |
"viewCount": 2, | |
"totalDuration": 1200, | |
"lastViewedAt": "2024-01-08T12:00:00Z", | |
"location": "Dubai Mall", | |
"bedrooms": 0, | |
"bathrooms": 1, | |
"area": 3000, | |
"features": ["High Foot Traffic", "Premium Location", "Storage", "Security"] | |
} | |
] | |
def get_customer_data(self, customer_id: int) -> List[Dict[str, Any]]: | |
"""Get mock customer data based on customer ID""" | |
# Generate different data based on customer ID | |
if customer_id == 105: | |
# High-value customer with luxury preferences | |
return self.sample_properties[:4] # First 4 properties (luxury) | |
elif customer_id == 106: | |
# Mid-range customer | |
return self.sample_properties[1:5] # Properties 2-5 | |
elif customer_id == 107: | |
# Investment-focused customer | |
return [self.sample_properties[4], self.sample_properties[6], self.sample_properties[7]] | |
elif customer_id == 108: | |
# Budget-conscious customer | |
return [self.sample_properties[1], self.sample_properties[4]] | |
else: | |
# Random selection for other customer IDs | |
num_properties = random.randint(2, 6) | |
return random.sample(self.sample_properties, num_properties) | |
def get_customer_profile(self, customer_id: int) -> Dict[str, Any]: | |
"""Get customer profile information""" | |
profiles = { | |
105: { | |
"customerName": "Ahmed Al Mansouri", | |
"email": "[email protected]", | |
"phone": "+971501234567", | |
"preferredLocation": "Palm Jumeirah", | |
"budgetRange": "15M-25M", | |
"propertyType": "Villa", | |
"leadSource": "Website", | |
"lastContact": "2024-01-15T10:30:00Z" | |
}, | |
106: { | |
"customerName": "Sarah Johnson", | |
"email": "[email protected]", | |
"phone": "+971502345678", | |
"preferredLocation": "Downtown Dubai", | |
"budgetRange": "3M-8M", | |
"propertyType": "Apartment", | |
"leadSource": "Referral", | |
"lastContact": "2024-01-14T14:20:00Z" | |
}, | |
107: { | |
"customerName": "Mohammed Rahman", | |
"email": "[email protected]", | |
"phone": "+971503456789", | |
"preferredLocation": "Dubai Marina", | |
"budgetRange": "2M-15M", | |
"propertyType": "Mixed", | |
"leadSource": "Investment Portal", | |
"lastContact": "2024-01-13T16:45:00Z" | |
}, | |
108: { | |
"customerName": "Fatima Hassan", | |
"email": "[email protected]", | |
"phone": "+971504567890", | |
"preferredLocation": "Dubai Marina", | |
"budgetRange": "2M-4M", | |
"propertyType": "Apartment", | |
"leadSource": "Social Media", | |
"lastContact": "2024-01-12T11:15:00Z" | |
} | |
} | |
return profiles.get(customer_id, { | |
"customerName": f"Customer {customer_id}", | |
"email": f"customer{customer_id}@email.com", | |
"phone": f"+97150{random.randint(1000000, 9999999)}", | |
"preferredLocation": random.choice(["Dubai Marina", "Downtown Dubai", "Palm Jumeirah", "JBR"]), | |
"budgetRange": random.choice(["2M-5M", "5M-10M", "10M-20M", "20M+"]), | |
"propertyType": random.choice(["Apartment", "Villa", "Townhouse", "Mixed"]), | |
"leadSource": random.choice(["Website", "Referral", "Social Media", "Advertisement"]), | |
"lastContact": datetime.now().isoformat() | |
}) | |
def generate_engagement_metrics(self, customer_id: int) -> Dict[str, Any]: | |
"""Generate engagement metrics for the customer""" | |
base_engagement = random.randint(30, 90) | |
# Adjust based on customer ID | |
if customer_id == 105: | |
base_engagement = 85 # High engagement | |
elif customer_id == 106: | |
base_engagement = 65 # Medium engagement | |
elif customer_id == 107: | |
base_engagement = 45 # Lower engagement | |
elif customer_id == 108: | |
base_engagement = 55 # Medium-low engagement | |
return { | |
"totalViews": random.randint(5, 25), | |
"totalDuration": random.randint(1800, 7200), # 30 minutes to 2 hours | |
"engagementScore": base_engagement, | |
"lastActivity": datetime.now().isoformat(), | |
"favoriteProperties": random.randint(1, 4), | |
"searchQueries": random.randint(3, 12), | |
"emailOpens": random.randint(1, 8), | |
"websiteVisits": random.randint(2, 15) | |
} | |
# Global instance | |
mock_data_service = MockDataService() |