From edb18080ea9eeff08a328ae93371b85ab66db07b Mon Sep 17 00:00:00 2001 From: Rucha-Ambaliya Date: Tue, 14 Jan 2025 14:57:40 +0530 Subject: [PATCH 1/2] Configured database_setup.py to delete old indexex+reinsert them and delete old objects from each collection+reinsert them --- database_setup.py | 295 +++++++++++------ image_data.py | 681 +++++++++++++++++++++++++-------------- models/analyticsVideo.py | 2 +- models/listing.py | 1 - models/product.py | 2 +- models/video.py | 2 +- models/videoListing.py | 2 +- video_data.py | 340 ++++++++++++++----- 8 files changed, 902 insertions(+), 423 deletions(-) diff --git a/database_setup.py b/database_setup.py index 2e57d9a..100caa9 100644 --- a/database_setup.py +++ b/database_setup.py @@ -2,6 +2,23 @@ from pymongo.server_api import ServerApi import logging import os +from models.listing import ProductListing +from models.analytics import Analytics, SalesPerformance, CustomerBehavior, MarketingMetrics, Demographics +from models.review import RecentReview +from models.videoListing import VideoListing, ProductLink +from models.analyticsVideo import VideoAnalytics, VideoAudience, VideoEngagement, VideoPerformance +from image_data import( + sample_products, + product_listings, + product_reviews, + product_analytics, +) +from video_data import( + sample_videos, + video_listings, + video_analytics, +) + from dotenv import load_dotenv load_dotenv() @@ -26,9 +43,18 @@ def setup_product_database(): video_collection = db["videos"] video_listings_collection = db["video_listings"] video_analytics_collection = db["video_analytics"] + + # Delete indexes + product_collection.drop_indexes() + listing_collection.drop_indexes() + analytics_collection.drop_indexes() + review_collection.drop_indexes() + video_collection.drop_indexes() + video_listings_collection.drop_indexes() + video_analytics_collection.drop_indexes() # Create indexes for products - product_collection.create_index([("id", ASCENDING)], unique=True) + product_collection.create_index([("id", ASCENDING)]) product_collection.create_index([("title", ASCENDING)]) product_collection.create_index([("category", ASCENDING)]) product_collection.create_index([("subcategory", ASCENDING)]) @@ -41,14 +67,14 @@ def setup_product_database(): listing_collection.create_index([("product_id", ASCENDING), ("created_at", ASCENDING)]) listing_collection.create_index([("price", ASCENDING), ("updated_at", ASCENDING)]) listing_collection.create_index([("features", ASCENDING), ("title", ASCENDING)]) - listing_collection.create_index([("id", ASCENDING)], unique=True) + listing_collection.create_index([("id", ASCENDING)]) listing_collection.create_index([("title", ASCENDING)]) listing_collection.create_index([("price", ASCENDING)]) listing_collection.create_index([("features", ASCENDING)], name="features_index") # Create indexes for analytics analytics_collection.create_index([("id", ASCENDING), ("product_id", ASCENDING)]) analytics_collection.create_index([("product_id", ASCENDING), ("created_at", ASCENDING)]) - analytics_collection.create_index([("id", ASCENDING)], unique=True) + analytics_collection.create_index([("id", ASCENDING)]) analytics_collection.create_index([("product_id", ASCENDING)], unique=True) analytics_collection.create_index([("created_at", ASCENDING)]) analytics_collection.create_index([("updated_at", ASCENDING)]) @@ -63,7 +89,7 @@ def setup_product_database(): # Create indexes for review review_collection.create_index([("product_id", ASCENDING), ("rating", ASCENDING)]) review_collection.create_index([("user_id", ASCENDING), ("product_id", ASCENDING)]) - review_collection.create_index([("id", ASCENDING)], unique=True) + review_collection.create_index([("id", ASCENDING)]) review_collection.create_index([("product_id", ASCENDING)]) review_collection.create_index([("user_id", ASCENDING)]) review_collection.create_index([("rating", ASCENDING)]) @@ -75,7 +101,7 @@ def setup_product_database(): # Create indexes for video video_collection.create_index([("title", ASCENDING), ("views", ASCENDING)]) video_collection.create_index([("views", ASCENDING), ("rating", ASCENDING)]) - video_collection.create_index([("id", ASCENDING)], unique=True) + video_collection.create_index([("id", ASCENDING)]) video_collection.create_index([("title", ASCENDING)]) video_collection.create_index([("category", ASCENDING)]) video_collection.create_index([("subcategory", ASCENDING)]) @@ -88,9 +114,9 @@ def setup_product_database(): video_collection.create_index([("key_features", ASCENDING)]) video_collection.create_index([("highlights", ASCENDING)]) # Create indexes for video listing - video_listings_collection.create_index([("product_id", ASCENDING), ("id", ASCENDING)]) - video_listings_collection.create_index([("id", ASCENDING)], unique=True) - video_listings_collection.create_index([("product_id", ASCENDING)]) + video_listings_collection.create_index([("video_id", ASCENDING), ("id", ASCENDING)]) + video_listings_collection.create_index([("id", ASCENDING)]) + video_listings_collection.create_index([("video_id", ASCENDING)], unique=True) video_listings_collection.create_index([("platform", ASCENDING)]) video_listings_collection.create_index([("title", ASCENDING)]) video_listings_collection.create_index([("views", ASCENDING)]) @@ -99,11 +125,11 @@ def setup_product_database(): video_listings_collection.create_index([("updated_at", ASCENDING)]) video_listings_collection.create_index([("product_links.price", ASCENDING)]) # Create indexes for video analytics - video_analytics_collection.create_index([("id", ASCENDING), ("product_id", ASCENDING)]) + video_analytics_collection.create_index([("id", ASCENDING), ("video_id", ASCENDING)]) video_analytics_collection.create_index([("engagement.views", ASCENDING), ("engagement.likes", ASCENDING)]) video_analytics_collection.create_index([("performance.retention_rate", ASCENDING), ("performance.click_through_rate", ASCENDING)]) - video_analytics_collection.create_index([("id", ASCENDING)], unique=True) - video_analytics_collection.create_index([("product_id", ASCENDING)]) + video_analytics_collection.create_index([("id", ASCENDING)]) + video_analytics_collection.create_index([("video_id", ASCENDING)], unique=True) video_analytics_collection.create_index([("created_at", ASCENDING)]) video_analytics_collection.create_index([("updated_at", ASCENDING)]) video_analytics_collection.create_index([("engagement.views", ASCENDING)]) @@ -115,95 +141,172 @@ def setup_product_database(): video_analytics_collection.create_index([("performance.retention_rate", ASCENDING)]) video_analytics_collection.create_index([("performance.click_through_rate", ASCENDING)]) - # Sample product reference data - sample_products = [ - { - "category": "Electronics", - "subcategory": "Smartphones", - "brand_options": ["Samsung Galaxy S24", "iPhone 15", "Google Pixel 8"], - "price_ranges": { - "budget": {"min": 299, "max": 499}, - "mid_range": {"min": 500, "max": 799}, - "premium": {"min": 800, "max": 1299} - }, - "common_features": [ - "5G Connectivity", - "AI-Enhanced Camera", - "AMOLED Display", - "Fast Charging", - "Wireless Charging" - ], - "keywords": ["smartphone", "mobile phone", "cell phone", "android", "ios"] - }, - { - "category": "Electronics", - "subcategory": "Wireless Earbuds", - "brand_options": ["Apple AirPods Pro", "Samsung Galaxy Buds", "Google Pixel Buds"], - "price_ranges": { - "budget": {"min": 49, "max": 99}, - "mid_range": {"min": 100, "max": 199}, - "premium": {"min": 200, "max": 299} - }, - "common_features": [ - "Active Noise Cancellation", - "Touch Controls", - "Wireless Charging Case", - "Water Resistance", - "Voice Assistant Support" - ], - "keywords": ["earbuds", "wireless earphones", "tws", "headphones"] - }, - { - "category": "Electronics", - "subcategory": "Smartwatches", - "brand_options": ["Apple Watch Series 9", "Samsung Galaxy Watch 6", "Google Pixel Watch"], - "price_ranges": { - "budget": {"min": 149, "max": 249}, - "mid_range": {"min": 250, "max": 399}, - "premium": {"min": 400, "max": 799} - }, - "common_features": [ - "Health Monitoring", - "Fitness Tracking", - "GPS", - "Always-On Display", - "Water Resistance" - ], - "keywords": ["smartwatch", "fitness tracker", "smart watch", "wearable"] - } - ] + + # Clear Existing Products + product_collection.delete_many({}) + # Insert Sample Products + product_collection.insert_many([product.model_dump() for product in sample_products]) + logger.info("sample_products inserted") + + #-------------------------------- + + # Clear Existing Product Listings + listing_collection.delete_many({}) + + # Generate sample_product_listings + sample_product_listings = [] + for listing in product_listings: + # Fetch the _id of the product from the database + result = product_collection.find_one({"title": listing["title"]}, {"_id": 1}) + + if result: + sample_product_listings.append( + ProductListing( + product_id=str(result["_id"]), + title=listing["title"], + price=listing["price"], + description=listing["description"], + features=listing["features"] + ) + ) - # Clear existing data - # product_references.delete_many({}) - # listings.delete_many({}) + # Insert sample_product_listings + listing_collection.insert_many([listing.model_dump() for listing in sample_product_listings]) + logger.info("sample_product_listings inserted") + + #-------------------------------- - # Insert sample data - # product_references.insert_many(sample_products) - logger.info("Sample product references inserted successfully") + # Clear Existing Analytics + analytics_collection.delete_many({}) + + # Generate sample_product_analytics + sample_product_analytics = [] + for analytic in product_analytics: + # Fetch the _id of the product from the database + result = product_collection.find_one({"title": analytic["title"]}, {"_id": 1}) + + if result: + sample_product_analytics.append( + Analytics( + product_id=str(result["_id"]), + sales_performance=SalesPerformance( + total_sales=analytic["sales_performance"]["total_sales"], + revenue=analytic["sales_performance"]["revenue"], + average_price=analytic["sales_performance"]["average_price"], + growth_rate=analytic["sales_performance"]["growth_rate"] + ), + customer_behavior=CustomerBehavior( + view_to_purchase_rate=analytic["customer_behavior"]["view_to_purchase_rate"], + cart_abandonment_rate=analytic["customer_behavior"]["cart_abandonment_rate"], + repeat_purchase_rate=analytic["customer_behavior"]["repeat_purchase_rate"], + average_rating=analytic["customer_behavior"]["average_rating"] + ), + demographics=Demographics( + age_groups=analytic["demographics"]["age_groups"], + top_locations=analytic["demographics"]["top_locations"] + ), + marketing_metrics=MarketingMetrics( + click_through_rate=analytic["marketing_metrics"]["click_through_rate"], + conversion_rate=analytic["marketing_metrics"]["conversion_rate"], + return_on_ad_spend=analytic["marketing_metrics"]["return_on_ad_spend"], + social_media_engagement=analytic["marketing_metrics"]["social_media_engagement"] + ) + ) + ) - # Insert sample listings - # sample_listings = [ - # { - # "product_id": str(product_references.find_one({"brand_options": "iPhone 15"})["_id"]), - # "title": "iPhone 15 Pro Max", - # "category": "Electronics", - # "subcategory": "Smartphones", - # "description": "Latest iPhone with A17 Pro chip and titanium design", - # "price": "$999", - # "features": [ - # "48MP Main Camera", - # "Titanium Design", - # "Action Button" - # ], - # "keywords": ["iphone", "smartphone", "apple"], - # "original_caption": "Just got the new iPhone 15 Pro! Amazing camera system!", - # "created_at": datetime.utcnow(), - # "status": "active" - # } - # ] + # Insert sample_product_analytics + analytics_collection.insert_many([analytic.model_dump() for analytic in sample_product_analytics]) + logger.info("sample_product_analytics inserted") + + #-------------------------------- - # listings.insert_many(sample_listings) - # logger.info("Sample listings inserted successfully") + # Clear Existing Reviews + review_collection.delete_many({}) + + # Generate sample_reviews + sample_reviews = [] + for review in product_reviews: + # Fetch the _id of the product from the database + result = product_collection.find_one({"title": review["product_title"]}, {"_id": 1}) + if result: + sample_reviews.append( + RecentReview( + product_id=str(result["_id"]), + user_id=review["user_id"], + rating=review["rating"], + title=review["title"], + comment=review["comment"], + verified_purchase=review["verified_purchase"] + ) + ) + # Insert sample_reviews + review_collection.insert_many([review.model_dump() for review in sample_reviews]) + logger.info("sample_reviews inserted") + + # ================= Videos ================= + + # Clear Existing Videos + video_collection.delete_many({}) + # Insert sample_videos + video_collection.insert_many([video.model_dump() for video in sample_videos]) + logger.info("sample_videos inserted") + + #-------------------------------- + + # Clear Existing video_listings + video_listings_collection.delete_many({}) + + # Generate sample_reviews + sample_video_listings = [] + for video_listing in video_listings: + # Fetch the _id of the video from the database + result = video_collection.find_one({"title": video_listing["title"]}, {"_id": 1}) + if result: + sample_video_listings.append( + VideoListing( + video_id=str(result["_id"]), + platform=video_listing["platform"], + title=video_listing["title"], + views=video_listing["views"], + rating=video_listing["rating"], + key_timestamps={ + "00:00": "Introduction", + "02:00": "Main features", + "04:00": "Conclusion" + }, + product_links=[ + ProductLink(store="Amazon", price="$199"), + ProductLink(store="Best Buy", price="$205"), + ] + ) + ) + + # Insert sample_video_listings + video_listings_collection.insert_many([video_listing.model_dump() for video_listing in sample_video_listings]) + logger.info("sample_video_listings inserted") + + #-------------------------------- + + # Clear Existing video_analytics + video_analytics_collection.delete_many({}) + + # Generate sample_video_analytics + sample_video_analytics = [] + for video_analytic in video_analytics: + # Fetch the _id of the video from the database + result = video_collection.find_one({"title": video_analytic["title"]}, {"_id": 1}) + if result: + analytics = VideoAnalytics( + video_id=str(result["_id"]), + engagement=VideoEngagement(**video_analytic["engagement"]), + audience=VideoAudience(**video_analytic["audience"]), + performance=VideoPerformance(**video_analytic["performance"]) + ) + sample_video_analytics.append(analytics) + + # Insert sample_video_analytics + video_analytics_collection.insert_many([video_analitic.model_dump() for video_analitic in sample_video_analytics]) + logger.info("sample_video_analytics inserted") except Exception as e: logger.error(f"Error setting up database: {e}") diff --git a/image_data.py b/image_data.py index d181ec3..09e4ffc 100644 --- a/image_data.py +++ b/image_data.py @@ -1,249 +1,4 @@ -# image_data.py - -# Product Database by Category -PRODUCT_DATABASE = { - "electronics": [ - {"id": "elec_123", "title": "Sony WH-1000XM4", "category": "Headphones", "price_range": "$299 - $349"}, - {"id": "elec_124", "title": "Samsung Galaxy Watch 6", "category": "Smartwatch", "price_range": "$299 - $449"}, - {"id": "elec_125", "title": "Apple iPad Air", "category": "Tablets", "price_range": "$599 - $749"} - ], - "fashion": [ - {"id": "fash_123", "title": "Nike Air Max 270", "category": "Sneakers", "price_range": "$150 - $170"}, - {"id": "fash_124", "title": "Zara Oversized Blazer", "category": "Clothing", "price_range": "$89 - $129"}, - {"id": "fash_125", "title": "Adidas Ultraboost", "category": "Running Shoes", "price_range": "$180 - $200"} - ], - "home_decor": [ - {"id": "decor_123", "title": "Scandinavian Floor Lamp", "category": "Lighting", "price_range": "$199 - $249"}, - {"id": "decor_124", "title": "Persian Area Rug 5x8", "category": "Rugs", "price_range": "$299 - $499"}, - {"id": "decor_125", "title": "Modern Wall Mirror", "category": "Mirrors", "price_range": "$149 - $199"} - ], - "beauty": [ - {"id": "beauty_123", "title": "MAC Ruby Woo Lipstick", "category": "Makeup", "price_range": "$19 - $22"}, - {"id": "beauty_124", "title": "L'Oreal Telescopic Mascara", "category": "Makeup", "price_range": "$11 - $13"}, - {"id": "beauty_125", "title": "Maybelline Fit Me Foundation", "category": "Makeup", "price_range": "$8 - $10"} - ], - "sports": [ - {"id": "sports_123", "title": "Wilson Evolution Basketball", "category": "Basketball", "price_range": "$59 - $69"}, - {"id": "sports_124", "title": "Nike Mercurial Soccer Cleats", "category": "Soccer", "price_range": "$89 - $129"}, - {"id": "sports_125", "title": "Adidas Tennis Racket", "category": "Tennis", "price_range": "$199 - $249"} - ] -} - -# Listings Database -LISTINGS_DATABASE = { - "elec_123": { - "id": "list_123", - "title": "Sony WH-1000XM4", - "price": "$349", - "description": "Industry-leading noise cancelling headphones", - "features": ["30-hour Battery Life", "Touch Controls", "Speak-to-chat"] - }, - "elec_124": { - "id": "list_124", - "title": "Samsung Galaxy Watch 6", - "price": "$399", - "description": "Advanced smartwatch with comprehensive health tracking", - "features": ["Sleep Tracking", "ECG Monitor", "Durable Design"] - }, - "elec_125": { - "id": "list_125", - "title": "Apple iPad Air", - "price": "$599", - "description": "Powerful tablet for creativity and productivity", - "features": ["M1 Chip", "10.9-inch Display", "Apple Pencil Support"] - }, - - # Fashion - "fash_123": { - "id": "list_126", - "title": "Nike Air Max 270", - "price": "$150", - "description": "Iconic lifestyle sneakers with visible Air unit", - "features": ["Air Cushioning", "Mesh Upper", "Rubber Outsole"] - }, - "fash_124": { - "id": "list_127", - "title": "Zara Oversized Blazer", - "price": "$99", - "description": "Versatile oversized blazer for any occasion", - "features": ["Premium Fabric", "Relaxed Fit", "Multiple Pockets"] - }, - "fash_125": { - "id": "list_128", - "title": "Adidas Ultraboost", - "price": "$180", - "description": "Premium running shoes with responsive cushioning", - "features": ["Boost Midsole", "Primeknit Upper", "Continental Rubber"] - }, - - # Home Decor - "decor_123": { - "id": "list_129", - "title": "Scandinavian Floor Lamp", - "price": "$199", - "description": "Modern minimalist floor lamp with wooden accents", - "features": ["LED Compatible", "Natural Wood", "Adjustable Height"] - }, - "decor_124": { - "id": "list_130", - "title": "Persian Area Rug 5x8", - "price": "$399", - "description": "Traditional Persian rug with intricate patterns", - "features": ["Hand-Knotted", "Wool Blend", "Fade Resistant"] - }, - "decor_125": { - "id": "list_131", - "title": "Modern Wall Mirror", - "price": "$179", - "description": "Contemporary wall mirror with elegant frame", - "features": ["Beveled Edge", "Easy Mounting", "Anti-Fog Coating"] - }, - - # Beauty - "beauty_123": { - "id": "list_132", - "title": "MAC Ruby Woo Lipstick", - "price": "$19", - "description": "Iconic matte red lipstick", - "features": ["Long-lasting", "Matte Finish", "Highly Pigmented"] - }, - "beauty_124": { - "id": "list_133", - "title": "L'Oreal Telescopic Mascara", - "price": "$11", - "description": "Lengthening mascara for dramatic lashes", - "features": ["Precision Brush", "Smudge-proof", "Easy Removal"] - }, - "beauty_125": { - "id": "list_134", - "title": "Maybelline Fit Me Foundation", - "price": "$8", - "description": "Lightweight foundation for natural coverage", - "features": ["Oil-Free", "SPF 18", "Natural Finish"] - }, - - # Sports - "sports_123": { - "id": "list_135", - "title": "Wilson Evolution Basketball", - "price": "$59.99", - "description": "Premium indoor game basketball", - "features": ["Composite Leather", "Cushion Core", "Maximum Grip"] - }, - "sports_124": { - "id": "list_136", - "title": "Nike Mercurial Soccer Cleats", - "price": "$89", - "description": "Professional soccer cleats for speed", - "features": ["Lightweight Design", "Studded Sole", "Dynamic Fit"] - }, - "sports_125": { - "id": "list_137", - "title": "Adidas Tennis Racket", - "price": "$199", - "description": "Professional grade tennis racket", - "features": ["Graphite Frame", "Perfect Balance", "Spin Friendly"] - } -} - -# Comparable Products Database -COMPARABLE_DATABASE = { - "elec_123": [ - { - "id": "elec_126", - "name": "Bose QuietComfort 45", - "price_range": "$279 - $329", - "features": ["Noise Cancellation", "24-hour Battery", "Bluetooth 5.1"] - }, - { - "id": "elec_127", - "name": "Apple AirPods Max", - "price_range": "$549 - $599", - "features": ["Active Noise Cancellation", "Spatial Audio", "20-hour Battery"] - } - ], - "fash_123": [ - { - "id": "fash_126", - "name": "Adidas NMD R1", - "price_range": "$140 - $160", - "features": ["Boost Cushioning", "Knit Upper", "Streetwear Style"] - }, - { - "id": "fash_127", - "name": "Puma RS-X", - "price_range": "$110 - $130", - "features": ["Retro Design", "Running System Tech", "Mesh Construction"] - } - ], - # Add entries for all other products... - - # Home Decor Comparisons - "decor_123": [ - { - "id": "decor_126", - "name": "Industrial Tripod Floor Lamp", - "price_range": "$179 - $229", - "features": ["Metal Construction", "Adjustable Height", "Vintage Style"] - }, - { - "id": "decor_127", - "name": "Modern Arc Floor Lamp", - "price_range": "$249 - $299", - "features": ["Arched Design", "Marble Base", "Dimmable Light"] - }, - { - "id": "decor_128", - "name": "Contemporary LED Floor Lamp", - "price_range": "$159 - $199", - "features": ["Touch Control", "Color Temperature Adjustment", "Energy Efficient"] - } - ], - - # Beauty Comparisons - "beauty_123": [ - { - "id": "beauty_126", - "name": "NARS Red Square", - "price_range": "$26 - $30", - "features": ["Velvet Matte", "Long Wear", "Rich Pigment"] - }, - { - "id": "beauty_127", - "name": "Charlotte Tilbury Red Carpet Red", - "price_range": "$34 - $38", - "features": ["Creamy Texture", "Moisturizing", "Celebrity Favorite"] - }, - { - "id": "beauty_128", - "name": "Fenty Beauty Stunna Lip Paint", - "price_range": "$24 - $28", - "features": ["Liquid Formula", "12-Hour Wear", "Universal Red"] - } - ], - - # Sports Comparisons - "sports_123": [ - { - "id": "sports_126", - "name": "Spalding NBA Official Game Ball", - "price_range": "$49 - $59", - "features": ["Full Grain Leather", "Official Size", "Indoor/Outdoor"] - }, - { - "id": "sports_127", - "name": "Molten X-Series Basketball", - "price_range": "$39 - $49", - "features": ["FIBA Approved", "Premium Grip", "Consistent Bounce"] - }, - { - "id": "sports_128", - "name": "Nike Elite Competition Ball", - "price_range": "$59 - $69", - "features": ["Nike Grip Technology", "Deep Channel Design", "Indoor Only"] - } - ] -} +from models.product import Product # Sample Responses for Image Upload SAMPLE_RESPONSES = { @@ -289,3 +44,437 @@ "features": ["Moisture-Wicking", "Superior Grip", "Indoor Use"] } } + +# Sample products +sample_products = [ + # Category: Electronics + # Subcategory: Smartphones + Product( + title="Samsung Galaxy S24", + category="Electronics", + subcategory="Smartphones", + features=["5G Connectivity", "AI-Enhanced Camera", "AMOLED Display", "Fast Charging", "Wireless Charging"], + price_range="premium" + ), + Product( + title="iPhone 15", + category="Electronics", + subcategory="Smartphones", + features=["5G Connectivity", "AI-Enhanced Camera", "AMOLED Display", "Fast Charging", "Wireless Charging"], + price_range="premium" + ), + # Subcategory: Wireless Earbuds + Product( + title="Apple AirPods Pro", + category="Electronics", + subcategory="Wireless Earbuds", + features=["Active Noise Cancellation", "Touch Controls", "Wireless Charging Case", "Water Resistance", "Voice Assistant Support"], + price_range="mid_range" + ), + Product( + title="Samsung Galaxy Buds", + category="Electronics", + subcategory="Wireless Earbuds", + features=["Active Noise Cancellation", "Touch Controls", "Wireless Charging Case", "Water Resistance", "Voice Assistant Support"], + price_range="budget" + ), + # Category: Wearables + # Subcategory: Smartwatches + Product( + title="Apple Watch Series 9", + category="Wearables", + subcategory="Smartwatches", + features=["Health Monitoring", "Fitness Tracking", "GPS", "Always-On Display", "Water Resistance"], + price_range="premium" + ), + Product( + title="Samsung Galaxy Watch 6", + category="Wearables", + subcategory="Smartwatches", + features=["Health Monitoring", "Fitness Tracking", "GPS", "Always-On Display", "Water Resistance"], + price_range="mid_range" + ), + # Subcategory: Fitness Bands + Product( + title="Fitbit Charge 6", + category="Wearables", + subcategory="Fitness Bands", + features=["Heart Rate Monitoring", "Step Tracking", "Sleep Analysis", "Long Battery Life", "Water Resistance"], + price_range="budget" + ), + Product( + title="Xiaomi Mi Band 8", + category="Wearables", + subcategory="Fitness Bands", + features=["Heart Rate Monitoring", "Step Tracking", "Sleep Analysis", "Long Battery Life", "Water Resistance"], + price_range="budget" + ), +] + +# Product Analytics +product_analytics = [ + { + "title": "Samsung Galaxy S24", + "sales_performance": { + "total_sales": "$5M", + "revenue": "$4.8M", + "average_price": "$349", + "growth_rate": "12%" + }, + "customer_behavior": { + "view_to_purchase_rate": "2:1", + "cart_abandonment_rate": "25%", + "repeat_purchase_rate": "15%", + "average_rating": 4.7 + }, + "demographics": { + "age_groups": { + "18-24": "35%", + "25-34": "45%", + "35-44": "15%", + "45+": "5%" + }, + "top_locations": ["USA", "UK", "Germany", "South Korea"] + }, + "marketing_metrics": { + "click_through_rate": "1.2%", + "conversion_rate": "5%", + "return_on_ad_spend": "3.5", + "social_media_engagement": "High" + } + }, + { + "title": "iPhone 15", + "sales_performance": { + "total_sales": "$6M", + "revenue": "$5.5M", + "average_price": "$399", + "growth_rate": "8%" + }, + "customer_behavior": { + "view_to_purchase_rate": "1.5:1", + "cart_abandonment_rate": "20%", + "repeat_purchase_rate": "18%", + "average_rating": 4.8 + }, + "demographics": { + "age_groups": { + "18-24": "30%", + "25-34": "50%", + "35-44": "10%", + "45+": "10%" + }, + "top_locations": ["USA", "China", "Japan", "India"] + }, + "marketing_metrics": { + "click_through_rate": "1.0%", + "conversion_rate": "4.5%", + "return_on_ad_spend": "4.0", + "social_media_engagement": "Moderate" + } + }, + { + "title": "Apple AirPods Pro", + "sales_performance": { + "total_sales": "$2M", + "revenue": "$1.9M", + "average_price": "$249", + "growth_rate": "18%" + }, + "customer_behavior": { + "view_to_purchase_rate": "3:1", + "cart_abandonment_rate": "18%", + "repeat_purchase_rate": "20%", + "average_rating": 4.6 + }, + "demographics": { + "age_groups": { + "18-24": "40%", + "25-34": "40%", + "35-44": "10%", + "45+": "10%" + }, + "top_locations": ["USA", "UK", "Canada", "Australia"] + }, + "marketing_metrics": { + "click_through_rate": "1.5%", + "conversion_rate": "6%", + "return_on_ad_spend": "5.0", + "social_media_engagement": "High" + } + }, + { + "title": "Samsung Galaxy Buds", + "sales_performance": { + "total_sales": "$5M", + "revenue": "$4.8M", + "average_price": "$349", + "growth_rate": "12%" + }, + "customer_behavior": { + "view_to_purchase_rate": "2:1", + "cart_abandonment_rate": "25%", + "repeat_purchase_rate": "15%", + "average_rating": 4.7 + }, + "demographics": { + "age_groups": { + "18-24": "35%", + "25-34": "45%", + "35-44": "15%", + "45+": "5%" + }, + "top_locations": ["USA", "UK", "Germany", "South Korea"] + }, + "marketing_metrics": { + "click_through_rate": "1.2%", + "conversion_rate": "5%", + "return_on_ad_spend": "3.5", + "social_media_engagement": "High" + } + }, + { + "title": "Apple Watch Series 9", + "sales_performance": { + "total_sales": "$6M", + "revenue": "$5.5M", + "average_price": "$399", + "growth_rate": "8%" + }, + "customer_behavior": { + "view_to_purchase_rate": "1.5:1", + "cart_abandonment_rate": "20%", + "repeat_purchase_rate": "18%", + "average_rating": 4.8 + }, + "demographics": { + "age_groups": { + "18-24": "30%", + "25-34": "50%", + "35-44": "10%", + "45+": "10%" + }, + "top_locations": ["USA", "China", "Japan", "India"] + }, + "marketing_metrics": { + "click_through_rate": "1.0%", + "conversion_rate": "4.5%", + "return_on_ad_spend": "4.0", + "social_media_engagement": "Moderate" + } + }, + { + "title": "Samsung Galaxy Watch 6", + "sales_performance": { + "total_sales": "$2M", + "revenue": "$1.9M", + "average_price": "$249", + "growth_rate": "18%" + }, + "customer_behavior": { + "view_to_purchase_rate": "3:1", + "cart_abandonment_rate": "18%", + "repeat_purchase_rate": "20%", + "average_rating": 4.6 + }, + "demographics": { + "age_groups": { + "18-24": "40%", + "25-34": "40%", + "35-44": "10%", + "45+": "10%" + }, + "top_locations": ["USA", "UK", "Canada", "Australia"] + }, + "marketing_metrics": { + "click_through_rate": "1.5%", + "conversion_rate": "6%", + "return_on_ad_spend": "5.0", + "social_media_engagement": "High" + } + }, + { + "title": "Fitbit Charge 6", + "sales_performance": { + "total_sales": "$2.5M", + "revenue": "$2.2M", + "average_price": "$129", + "growth_rate": "15%" + }, + "customer_behavior": { + "view_to_purchase_rate": "4:1", + "cart_abandonment_rate": "12%", + "repeat_purchase_rate": "25%", + "average_rating": 4.7 + }, + "demographics": { + "age_groups": { + "18-24": "45%", + "25-34": "40%", + "35-44": "10%", + "45+": "5%" + }, + "top_locations": ["USA", "India", "UK", "Australia"] + }, + "marketing_metrics": { + "click_through_rate": "2.0%", + "conversion_rate": "5.5%", + "return_on_ad_spend": "4.2", + "social_media_engagement": "Moderate" + } + }, + { + "title": "Xiaomi Mi Band 8", + "sales_performance": { + "total_sales": "$1.8M", + "revenue": "$1.6M", + "average_price": "$79", + "growth_rate": "10%" + }, + "customer_behavior": { + "view_to_purchase_rate": "3:1", + "cart_abandonment_rate": "22%", + "repeat_purchase_rate": "18%", + "average_rating": 4.4 + }, + "demographics": { + "age_groups": { + "18-24": "40%", + "25-34": "35%", + "35-44": "15%", + "45+": "10%" + }, + "top_locations": ["USA", "China", "Brazil", "Russia"] + }, + "marketing_metrics": { + "click_through_rate": "1.8%", + "conversion_rate": "4.2%", + "return_on_ad_spend": "3.8", + "social_media_engagement": "Low" + } + } +] + +# Product Listings +product_listings = [ + { + "title": "Samsung Galaxy S24", + "price": "$349", + "description": "The latest Samsung flagship smartphone with top-tier performance.", + "features": ["5G Connectivity", "AI Camera", "AMOLED Display", "Fast Charging"] + }, + { + "title": "iPhone 15", + "price": "$399", + "description": "Apple's new iPhone with a stunning display and powerful A16 Bionic chip.", + "features": ["OLED Display", "AI-Enhanced Camera", "5G Connectivity", "Ceramic Shield"] + }, + { + "title": "Apple AirPods Pro", + "price": "$249", + "description": "Noise-cancelling wireless earbuds with excellent sound quality and comfort.", + "features": ["Active Noise Cancellation", "Spatial Audio", "Touch Controls", "Sweat & Water Resistant"] + }, + { + "title": "Samsung Galaxy Buds", + "price": "$179", + "description": "Wireless earbuds with a comfortable fit and great sound quality for everyday use.", + "features": ["Noise Cancellation", "Long Battery Life", "Touch Controls", "Water-Resistant"] + }, + { + "title": "Apple Watch Series 9", + "price": "$399", + "description": "A powerful smartwatch with fitness tracking, health monitoring, and app integration.", + "features": ["Health Monitoring", "Fitness Tracking", "GPS", "Always-On Display"] + }, + { + "title": "Samsung Galaxy Watch 6", + "price": "$349", + "description": "Advanced smartwatch featuring comprehensive fitness tracking and a sleek design.", + "features": ["Sleep Tracking", "ECG Monitor", "Fitness Tracking", "Water-Resistant"] + }, + { + "title": "Fitbit Charge 6", + "price": "$129", + "description": "A fitness tracker with heart rate monitoring, step counting, and sleep analysis.", + "features": ["Heart Rate Monitor", "Step Tracking", "Sleep Tracking", "Water-Resistant"] + }, + { + "title": "Xiaomi Mi Band 8", + "price": "$79", + "description": "Affordable fitness tracker with advanced health features and long battery life.", + "features": ["Heart Rate Monitor", "Step Counting", "Sleep Tracking", "Waterproof"] + } +] + +# Reviews +product_reviews = [ + { + "product_title": "Samsung Galaxy S24", + "user_id": "user_1", + "rating": 4.5, + "title": "Great phone with amazing display", + "comment": "The Samsung Galaxy S24 has a vibrant AMOLED display, and the camera is great for everyday use.", + "verified_purchase": True + }, + { + "product_title": "iPhone 15", + "user_id": "user_2", + "rating": 4.8, + "title": "Appleā€™s best iPhone yet", + "comment": "The iPhone 15 has an excellent camera and performance. The battery life is impressive too.", + "verified_purchase": True + }, + { + "product_title": "Apple AirPods Pro", + "user_id": "user_3", + "rating": 4.7, + "title": "Best wireless earbuds!", + "comment": "These AirPods are fantastic. The noise cancellation feature is great, and they are comfortable to wear.", + "verified_purchase": True + }, + { + "product_title": "Samsung Galaxy Buds", + "user_id": "user_4", + "rating": 4.3, + "title": "Good but could be better", + "comment": "The sound quality is good, but I found the fit a little uncomfortable for long sessions.", + "verified_purchase": True + }, + { + "product_title": "Apple Watch Series 9", + "user_id": "user_5", + "rating": 4.9, + "title": "Fantastic smartwatch for fitness tracking", + "comment": "The fitness tracking features of the Apple Watch Series 9 are top-notch. Highly recommend it.", + "verified_purchase": True + }, + { + "product_title": "Samsung Galaxy Watch 6", + "user_id": "user_6", + "rating": 4.6, + "title": "Sleek and functional", + "comment": "The Samsung Galaxy Watch 6 is a great fitness tracker, and the design is sleek and comfortable.", + "verified_purchase": True + }, + { + "product_title": "Fitbit Charge 6", + "user_id": "user_7", + "rating": 4.2, + "title": "Decent fitness tracker", + "comment": "The Fitbit Charge 6 works well for basic tracking but could use some improvements in the app.", + "verified_purchase": False + }, + { + "product_title": "Xiaomi Mi Band 8", + "user_id": "user_8", + "rating": 4.0, + "title": "Affordable and decent", + "comment": "Great value for money. Does the job well, but lacks some advanced features.", + "verified_purchase": True + } +] + + + + diff --git a/models/analyticsVideo.py b/models/analyticsVideo.py index 1db61d3..d70f71e 100644 --- a/models/analyticsVideo.py +++ b/models/analyticsVideo.py @@ -18,7 +18,7 @@ class VideoPerformance(BaseModel): conversion_rate: str class VideoAnalytics(BaseModel): - product_id: str + video_id: str engagement: VideoEngagement audience: VideoAudience performance: VideoPerformance diff --git a/models/listing.py b/models/listing.py index 10d4185..0d0c229 100644 --- a/models/listing.py +++ b/models/listing.py @@ -4,7 +4,6 @@ class ProductListing(BaseModel): product_id: str # Refers to Product's ID - id: str title: str price: str description: str diff --git a/models/product.py b/models/product.py index 431725f..490d066 100644 --- a/models/product.py +++ b/models/product.py @@ -3,7 +3,7 @@ from datetime import datetime class Product(BaseModel): - id: str + id: Optional[str] = None title: str category: str subcategory: str diff --git a/models/video.py b/models/video.py index ee38d4e..e36390e 100644 --- a/models/video.py +++ b/models/video.py @@ -3,7 +3,7 @@ from datetime import datetime class Video(BaseModel): - id: str + id: Optional[str] = None title: str category: str subcategory: str diff --git a/models/videoListing.py b/models/videoListing.py index 5ee0a37..9c04083 100644 --- a/models/videoListing.py +++ b/models/videoListing.py @@ -11,7 +11,7 @@ class KeyTimestamp(BaseModel): description: str class VideoListing(BaseModel): - product_id: str + video_id: str platform: str title: str views: str diff --git a/video_data.py b/video_data.py index 2da91f2..c155309 100644 --- a/video_data.py +++ b/video_data.py @@ -1,4 +1,4 @@ -# video_data.py +from models.video import Video # Video Database by Category VIDEO_DATABASE = { @@ -87,82 +87,153 @@ } } +# Sample Videos +sample_videos = [ + # Electronics - Smartphones + Video( + title="Samsung Galaxy S24 Ultra Features", + category="Electronics", + subcategory="Smartphones", + duration="11:40", + views="1.2M", + highlights=[ + "Camera zoom comparison", + "Gaming performance test", + "Battery endurance", + "New design elements" + ], + transcript_summary="Overview of the features and improvements in Samsung Galaxy S24 Ultra...", + key_features=[ + "200MP camera", + "Snapdragon 8 Gen 3", + "5000mAh battery", + "120Hz AMOLED display" + ], + price_range="$1199 - $1399" + ), + Video( + title="Google Pixel 8 Pro Review", + category="Electronics", + subcategory="Smartphones", + duration="9:30", + views="900K", + highlights=[ + "AI camera capabilities", + "Real-world performance test", + "Software features", + "Sustainability highlights" + ], + transcript_summary="A comprehensive review of Google Pixel 8 Pro...", + key_features=[ + "Tensor G3 chip", + "Real Tone photography", + "7-year updates", + "Recycled materials" + ], + price_range="$999 - $1099" + ), + # Fashion - Sneakers + Video( + title="Adidas Ultraboost 23 Review", + category="Fashion", + subcategory="Sneakers", + duration="7:50", + views="500K", + highlights=[ + "Comfort analysis", + "Performance for running", + "Material durability test", + "Style versatility" + ], + transcript_summary="In-depth review of the new Adidas Ultraboost 23...", + key_features=[ + "Boost midsole technology", + "Primeknit upper", + "Lightweight design", + "Eco-friendly materials" + ], + price_range="$180 - $220" + ), + Video( + title="Gucci Fall Collection 2025", + category="Fashion", + subcategory="Clothing", + duration="15:20", + views="2.3M", + highlights=[ + "Runway looks", + "Fabric details", + "Seasonal colors", + "Styling tips" + ], + transcript_summary="Showcase of Gucci's Fall Collection 2025...", + key_features=[ + "Luxury fabrics", + "Bold patterns", + "Exclusive designs", + "Seasonal accessories" + ], + price_range="$500 - $5000" + ), + # Beauty - Skincare and Makeup + Video( + title="Winter Skincare Routine", + category="Beauty", + subcategory="Skincare", + duration="10:15", + views="800K", + highlights=[ + "Product recommendations", + "Application techniques", + "Hydration tips", + "SPF for winter" + ], + transcript_summary="Detailed guide for maintaining healthy skin during winter...", + key_features=[ + "Moisturizing creams", + "SPF 50 sunscreen", + "Soothing serums", + "Gentle exfoliation" + ], + price_range="$15 - $100" + ), + Video( + title="Evening Glam Makeup Tutorial", + category="Beauty", + subcategory="Makeup", + duration="13:45", + views="1.1M", + highlights=[ + "Step-by-step guide", + "Product choices", + "Blending techniques", + "Finishing touches" + ], + transcript_summary="A tutorial to achieve a flawless evening glam look...", + key_features=[ + "Smokey eyeshadow", + "Long-lasting foundation", + "Bold lipsticks", + "Highlighter application" + ], + price_range="$25 - $200" + ) +] -# Video Listings Database -VIDEO_LISTINGS_DATABASE = { - "video_123": [ - { - "id": "vlist_123", - "platform": "YouTube", - "title": "iPhone 15 Pro Detailed Review", - "views": "1.2M", - "rating": 4.8, - "key_timestamps": { - "unboxing": "0:00", - "camera_test": "3:45", - "performance": "7:30", - "conclusion": "9:15" - }, - "product_links": [ - {"store": "Apple", "price": "$999"}, - {"store": "Amazon", "price": "$989"}, - {"store": "Best Buy", "price": "$999"} - ] - }, - { - "id": "vlist_124", - "platform": "TikTok", - "title": "iPhone 15 Pro Quick Review", - "views": "500K", - "rating": 4.7, - "key_timestamps": { - "features": "0:00", - "camera": "1:30", - "verdict": "2:45" - }, - "product_links": [ - {"store": "Apple", "price": "$999"}, - {"store": "Walmart", "price": "$979"} - ] - } - ] -} +# Video Listings +video_listings = [ + {"title": "Samsung Galaxy S24 Ultra Features", "views": "1.2M", "rating": 4.8, "platform": "YouTube"}, + {"title": "Google Pixel 8 Pro Review", "views": "900K", "rating": 4.7, "platform": "Instagram"}, + {"title": "Adidas Ultraboost 23 Review", "views": "500K", "rating": 4.5, "platform": "Twitter"}, + {"title": "Gucci Fall Collection 2025", "views": "2.3M", "rating": 4.9, "platform": "YouTube"}, + {"title": "Winter Skincare Routine", "views": "800K", "rating": 4.6, "platform": "Instagram"}, + {"title": "Evening Glam Makeup Tutorial", "views": "1.1M", "rating": 4.8, "platform": "Twitter"}, +] -# Comparable Videos Database -COMPARABLE_VIDEOS_DATABASE = { - "video_123": [ - { - "id": "video_127", - "title": "Samsung S24 Ultra Review", - "duration": "11:30", - "views": "900K", - "comparison_points": [ - "Camera quality", - "Performance", - "Battery life", - "Price value" - ], - "price_range": "$1199 - $1299" - }, - { - "id": "video_128", - "title": "Google Pixel 8 Pro Review", - "duration": "9:45", - "views": "750K", - "comparison_points": [ - "AI features", - "Photo capabilities", - "Software experience", - "Battery efficiency" - ], - "price_range": "$999 - $1099" - } - ] -} - -# Video Analytics Database -VIDEO_ANALYTICS_DATABASE = { - "video_123": { +# Video Analytics +video_analytics = [ + { + "title": "Samsung Galaxy S24 Ultra Features", "engagement": { "views": "1.2M", "likes": "50K", @@ -183,5 +254,122 @@ "click_through_rate": "4.2%", "conversion_rate": "2.8%" } + }, + { + "title": "Google Pixel 8 Pro Review", + "engagement": { + "views": "900K", + "likes": "40K", + "comments": "2.5K", + "average_watch_time": "7:50" + }, + "audience": { + "demographics": { + "18-24": "28%", + "25-34": "50%", + "35-44": "12%", + "45+": "10%" + }, + "top_regions": ["US", "India", "Germany", "UK"] + }, + "performance": { + "retention_rate": "72%", + "click_through_rate": "4.5%", + "conversion_rate": "3.0%" + } + }, + { + "title": "Adidas Ultraboost 23 Review", + "engagement": { + "views": "500K", + "likes": "20K", + "comments": "1.1K", + "average_watch_time": "6:10" + }, + "audience": { + "demographics": { + "18-24": "35%", + "25-34": "40%", + "35-44": "15%", + "45+": "10%" + }, + "top_regions": ["US", "Canada", "UK", "Australia"] + }, + "performance": { + "retention_rate": "60%", + "click_through_rate": "3.8%", + "conversion_rate": "2.5%" + } + }, + { + "title": "Gucci Fall Collection 2025", + "engagement": { + "views": "500K", + "likes": "20K", + "comments": "1.1K", + "average_watch_time": "6:10" + }, + "audience": { + "demographics": { + "18-24": "35%", + "25-34": "40%", + "35-44": "15%", + "45+": "10%" + }, + "top_regions": ["US", "Canada", "UK", "Australia"] + }, + "performance": { + "retention_rate": "60%", + "click_through_rate": "3.8%", + "conversion_rate": "2.5%" + } + }, + { + "title": "Winter Skincare Routine", + "engagement": { + "views": "500K", + "likes": "20K", + "comments": "1.1K", + "average_watch_time": "6:10" + }, + "audience": { + "demographics": { + "18-24": "35%", + "25-34": "40%", + "35-44": "15%", + "45+": "10%" + }, + "top_regions": ["US", "Canada", "UK", "Australia"] + }, + "performance": { + "retention_rate": "60%", + "click_through_rate": "3.8%", + "conversion_rate": "2.5%" + } + }, + { + "title": "Evening Glam Makeup Tutorial", + "engagement": { + "views": "500K", + "likes": "20K", + "comments": "1.1K", + "average_watch_time": "6:10" + }, + "audience": { + "demographics": { + "18-24": "35%", + "25-34": "40%", + "35-44": "15%", + "45+": "10%" + }, + "top_regions": ["US", "Canada", "UK", "Australia"] + }, + "performance": { + "retention_rate": "60%", + "click_through_rate": "3.8%", + "conversion_rate": "2.5%" + } } -} +] + + From c7e4e717e515d7374a09dae43156c304a3597d9d Mon Sep 17 00:00:00 2001 From: Rucha-Ambaliya Date: Tue, 14 Jan 2025 16:23:52 +0530 Subject: [PATCH 2/2] Solved video_id field missing error --- schemas/video.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/schemas/video.py b/schemas/video.py index eaf33de..528bad6 100644 --- a/schemas/video.py +++ b/schemas/video.py @@ -233,7 +233,7 @@ async def get_video_listings(video_id: str): # Default response if no listing is found default_listing = VideoListing( - product_id=f"prod_{abs(hash(video_id))}", + video_id=f"prod_{abs(hash(video_id))}", platform="YouTube", title="Product Review", views="10K", @@ -336,15 +336,15 @@ async def get_comparable_videos(video_id: str, limit: int = 3): async def get_video_analytics(video_id: str): from main import db - try: - # Validate and convert the video_id to ObjectId - object_id = ObjectId(video_id) - except Exception: - raise HTTPException(status_code=400, detail="Invalid video ID format") + # try: + # # Validate and convert the video_id to ObjectId + # object_id = ObjectId(video_id) + # except Exception: + # raise HTTPException(status_code=400, detail="Invalid video ID format") try: # Fetch video analytics from the database - video_analytics_data = await db["video_analytics"].find_one({"_id": object_id}) + video_analytics_data = await db["video_analytics"].find_one({"video_id": video_id}) if video_analytics_data: # Prepare analytics data @@ -361,7 +361,7 @@ async def get_video_analytics(video_id: str): # Default analytics response if no data is found default_analytics = VideoAnalytics( - product_id=video_id, + video_id=video_id, engagement=VideoEngagement( views="5K", likes="500",