107 lines
4.2 KiB
Python
107 lines
4.2 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Demo script to showcase the enhanced user identification and analytics features
|
|
of the Joke Bot v4.0
|
|
"""
|
|
|
|
import sqlite3
|
|
import os
|
|
|
|
def demo_user_identification():
|
|
"""Demonstrate the new user identification features"""
|
|
print("🎭 Joke Bot v4.0 - User Identification Demo 🎭")
|
|
print("=" * 50)
|
|
|
|
# Import the main module functions
|
|
import sys
|
|
sys.path.append('.')
|
|
|
|
# Reinitialize database for demo
|
|
if os.path.exists('jokes.db'):
|
|
os.remove('jokes.db')
|
|
print("🗑️ Cleaned existing database for demo")
|
|
|
|
from jokes import initialize_database, add_user_sentiment, get_user_sentiment_for_joke
|
|
from jokes import get_detailed_sentiment_stats, get_user_sentiment_history
|
|
from jokes import get_popular_jokes_by_user, get_top_users_by_joke_preference
|
|
|
|
# Initialize database
|
|
print("\n🔧 Initializing database with enhanced schema...")
|
|
initialize_database()
|
|
|
|
db = sqlite3.connect('jokes.db')
|
|
|
|
print("\n🎯 Demonstrating User Identification Features:")
|
|
print("-" * 40)
|
|
|
|
# Simulate different users rating the same joke
|
|
joke_id = 1 # First joke in our sample data
|
|
test_users = ['Alice', 'Bob', 'Charlie', 'Diana', 'Eve']
|
|
test_ratings = ['up', 'up', 'down', 'up', 'neutral']
|
|
|
|
print(f"\n📋 Simulating ratings for joke #{joke_id}:")
|
|
for user, rating in zip(test_users, test_ratings):
|
|
success, action = add_user_sentiment(db, joke_id, rating, user)
|
|
rating_emoji = {'up': '👍', 'down': '👎', 'neutral': '😐'}[rating]
|
|
print(f" {rating_emoji} {user} rated: {rating} ({action})")
|
|
|
|
# Show community sentiment
|
|
avg_sentiment, total_votes = get_user_sentiment_for_joke(db, joke_id)
|
|
print(f"\n👥 Community Rating: {avg_sentiment} ({total_votes} votes)")
|
|
|
|
# Show detailed breakdown
|
|
detailed_stats = get_detailed_sentiment_stats(db, joke_id)
|
|
print("🔍 Detailed Breakdown:")
|
|
for sentiment, count, users in detailed_stats:
|
|
sentiment_emoji = {'up': '👍', 'down': '👎', 'neutral': '😐'}[sentiment]
|
|
print(f" {sentiment_emoji} {sentiment.capitalize()}: {count} votes by {users}")
|
|
|
|
print("\n👤 Individual User Analytics:")
|
|
print("-" * 30)
|
|
|
|
# Show Alice's rating history
|
|
alice_history = get_user_sentiment_history(db, 'Alice')
|
|
print(f"\n📝 Alice's Rating History ({len(alice_history)} ratings):")
|
|
for joke_id, joke_text, sentiment, created_at in alice_history:
|
|
sentiment_emoji = {'up': '👍', 'down': '👎', 'neutral': '😐'}[sentiment]
|
|
print(f" {sentiment_emoji} {joke_text[:40]}...")
|
|
|
|
# Show Bob's favorite jokes
|
|
bob_favorites = get_popular_jokes_by_user(db, 'Bob')
|
|
print(f"\n😄 Bob's Favorite Jokes ({len(bob_favorites)} likes):")
|
|
for joke_id, joke_text, contributor, sentiment, created_at in bob_favorites:
|
|
print(f" 👍 {joke_text[:50]}...")
|
|
print(f" By: {contributor}")
|
|
|
|
print("\n🏆 Community Leaderboard:")
|
|
print("-" * 25)
|
|
|
|
# Show top users by positivity
|
|
top_users = get_top_users_by_joke_preference(db)
|
|
if top_users:
|
|
for i, (username, total, positive, negative, positivity_pct) in enumerate(top_users, 1):
|
|
print(f"{i}. {username}: {positivity_pct}% positive ({positive}/{total} ratings)")
|
|
|
|
# Test duplicate rating prevention
|
|
print(f"\n🔄 Testing Rating Update Feature:")
|
|
print("-" * 35)
|
|
success, action = add_user_sentiment(db, joke_id, 'down', 'Alice') # Change Alice's rating
|
|
print(f"Alice changed her rating: {action}")
|
|
|
|
# Show updated stats
|
|
avg_sentiment, total_votes = get_user_sentiment_for_joke(db, joke_id)
|
|
print(f"Updated Community Rating: {avg_sentiment} ({total_votes} votes)")
|
|
|
|
db.close()
|
|
|
|
print("\n🎉 Demo Complete!")
|
|
print("✨ Key Features Demonstrated:")
|
|
print(" • User identification for each sentiment")
|
|
print(" • Personal rating history tracking")
|
|
print(" • Favorite joke identification")
|
|
print(" • Community analytics and leaderboards")
|
|
print(" • Duplicate rating prevention with update capability")
|
|
print(" • Detailed sentiment breakdowns")
|
|
|
|
if __name__ == "__main__":
|
|
demo_user_identification() |