class Video:
def __init__(self, video_id, title, views, likes, shares, watch_time):
self.video_id = video_id
self.title = title
self.views = views
self.likes = likes
self.shares = shares
self.watch_time = watch_time # average watch time in seconds
def calculate_score(self):
# Weighted sum of engagement metrics
score = (0.1 * self.views) + (1 * self.likes) + (1.5 * self.shares) + (0.05 * self.watch_time)
return score
class User:
def __init__(self, user_id, interests):
self.user_id = user_id
self.interests = interests # list of interest keywords
class RecommendationSystem:
def __init__(self, videos, users):
self.videos = videos
self.users = users
def recommend(self, user):
scored_videos = []
for video in self.videos:
score = video.calculate_score()
# Check if any interest keyword matches the video title
interest_match = any(keyword.lower() in video.title.lower() for keyword in user.interests)
if interest_match:
scored_videos.append((score, video.title))
# Sort by score descending
scored_videos.sort(reverse=True, key=lambda x: x[0])
# Return top 3 recommendations
return [title for score, title in scored_videos[:3]]
# Sample data
videos = [
Video(1, "Amazing dance video", 1000, 150, 20, 180),
Video(2, "Funny cat compilation", 1500, 300, 50, 200),
Video(3, "Learn Python coding", 500, 200, 30, 240),
Video(4, "Motivational speech", 800, 100, 10, 300),
]
users = [
User(1, ["dance", "funny", "coding"]),
User(2, ["motivational", "speech"]),
]
rec_sys = RecommendationSystem(videos, users)
# Get recommendations for user 1
recommendations_user_1 = rec_sys.recommend(users[0])
print(recommendations_user_1) # Output: ['Funny cat compilation', 'Learn Python coding', 'Amazing dance video'] #❤️Love You ज़िंदगी ❤️ #🥰Express Emotion #🚀SC बूस्ट के साथ Views को सुपरचार्ज करें #👫चैटरूम चिटचैट✨ #🎁चैटरूम: अर्न & लर्न🤑
Haryanvi wedding dance #🚀SC बूस्ट के साथ Views को सुपरचार्ज करें #👫चैटरूम चिटचैट✨ #🎁चैटरूम: अर्न & लर्न🤑 #💔 हार्ट ब्रेक स्टेटस #❤️Love You ज़िंदगी ❤️
#📲मेरा पहला पोस्ट😍 Punjabi weeding dance #❤️Love You ज़िंदगी ❤️ #Dance #viral #😇 चाणक्य नीति



