Skip to content

Tikfoot #100

@kibou1982

Description

@kibou1982

class TikTokLikeApp:
def init(self):
self.user_profiles = {} # تخزين بيانات المستخدمين
self.content_pool = [] # قاعدة بيانات المحتوى
self.current_user = None

def login(self, user_id):
    """تسجيل دخول المستخدم"""
    self.current_user = self.user_profiles.get(user_id)
    if not self.current_user:
        self.user_profiles[user_id] = {
            'watch_history': [],
            'interactions': {},
            'preferences': {}
        }
        self.current_user = self.user_profiles[user_id]

def update_preferences(self, video_id, interaction_type, watch_duration):
    """تحديث تفضيلات المستخدم بناءً على تفاعلاته"""
    video = self.get_video(video_id)
    
    # تسجيل التفاعل
    self.current_user['watch_history'].append({
        'video_id': video_id,
        'duration': watch_duration,
        'interaction': interaction_type
    })
    
    # تحديث التفضيلات
    for tag in video['tags']:
        if tag in self.current_user['preferences']:
            self.current_user['preferences'][tag] += interaction_type.value * watch_duration
        else:
            self.current_user['preferences'][tag] = interaction_type.value * watch_duration

def get_next_video(self):
    """الحصول على الفيديو التالي للتوصية"""
    if not self.current_user:
        return self.get_trending_video()
        
    # حساب درجات المحتوى
    scored_videos = []
    for video in self.content_pool:
        score = self.calculate_video_score(video)
        scored_videos.append((score, video))
    
    # ترتيب الفيديوهات حسب الدرجة
    scored_videos.sort(reverse=True, key=lambda x: x[0])
    
    return scored_videos[0][1] if scored_videos else None

def calculate_video_score(self, video):
    """حساب درجة الفيديو للمستخدم الحالي"""
    relevance = 0
    for tag in video['tags']:
        relevance += self.current_user['preferences'].get(tag, 0)
    
    popularity = video['likes'] / (video['views'] + 1)
    recency = 1 / (time.now() - video['upload_time'] + 1)
    
    return (relevance * 0.6) + (popularity * 0.3) + (recency * 0.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions