File size: 1,676 Bytes
67f3964
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# In data/users.py
import firebase_admin
from firebase_admin import credentials, firestore

class UserManager:
    def __init__(self):
        # Initialize Firebase (if not already initialized)
        if not firebase_admin._apps:
            cred = credentials.Certificate("path/to/serviceAccountKey.json")
            firebase_admin.initialize_app(cred)
        
        self.db = firestore.client()
        self.collection = self.db.collection('users')
    
    def create_user(self, user_data):
        """Create a new user"""
        doc_ref = self.collection.document()
        doc_ref.set(user_data)
        return doc_ref.id
    
    def get_user(self, user_id):
        """Get user by ID"""
        doc = self.collection.document(user_id).get()
        return doc.to_dict() if doc.exists else None
    
    def update_progress(self, user_id, module_id, completion):
        """Update user progress on a module"""
        self.collection.document(user_id).update({
            f'progress.{module_id}': completion
        })
    
    def get_recommended_modules(self, user_id, num_recommendations=3):
        """Get recommended modules based on user progress"""
        user = self.get_user(user_id)
        
        if not user:
            return []
            
        # Simple recommendation strategy:
        # 1. Get modules user hasn't completed
        # 2. Prioritize those with prerequisites the user has completed
        # 3. Sort by difficulty appropriate to user's level
        
        # This would need to be implemented with a query to the content collection
        # For now, returning a placeholder
        return ["module1", "module2", "module3"]