"""
LearningProgressTracker
Generated by Eden via recursive self-improvement
2025-10-27 22:05:47.297166
"""

from datetime import datetime, timedelta
from collections import defaultdict

class LearningProgressTracker:
    """
    A class to track and analyze daily learning progress.
    
    Attributes:
        logs (list): List of learning logs, each containing date, topic, time spent, and notes.
        
    Methods:
        log_daily_learning(date, topic, minutes, notes):
            Logs daily learning activities with timestamp, duration, and notes.
            
        get_weekly_progress():
            Retrieves learning progress for the past week, including total time spent and frequency of study sessions.
            
        generate_learning_report(days_ago=7):
            Generates a report summarizing recent learning activities within a specified timeframe.
    """
    
    def __init__(self):
        self.logs = []
        
    def log_daily_learning(self, date, topic, minutes, notes):
        """Log daily learning activities with timestamp, duration, and notes."""
        self.logs.append({
            'date': datetime.fromisoformat(date),
            'topic': topic,
            'time_spent': minutes,
            'notes': notes
        })
        
    def get_weekly_progress(self):
        """Retrieves learning progress for the past week."""
        today = datetime.today()
        last_week = today - timedelta(days=7)
        weekly_logs = [log for log in self.logs if log['date'] >= last_week]
        
        total_time = sum(log['time_spent'] for log in weekly_logs)
        frequency = len(weekly_logs)
        latest_topics = list(set([log['topic'] for log in weekly_logs]))
        
        return {
            'total_study_time': total_time,
            'study_frequency': frequency,
            'recent_topics': latest_topics
        }
        
    def generate_learning_report(self, days_ago=7):
        """Generates a report summarizing recent learning activities."""
        today = datetime.today()
        cutoff_date = today - timedelta(days=days_ago)
        
        relevant_logs = [log for log in self.logs if log['date'] >= cutoff_date]
        topics_distribution = defaultdict(int)
        
        for log in relevant_logs:
            topics_distribution[log['topic']] += log['time_spent']
            
        return {
            'number_of_learning_days': len(relevant_logs),
            'total_study_time': sum(log['time_spent'] for log in relevant_logs),
            'topics_with_highest_engagement': dict(sorted(topics_distribution.items(), key=lambda x: -x[1])[:3])
        }
        
# Example usage:
if __name__ == "__main__":
    tracker = LearningProgressTracker()
    
    # Log some example learning activities
    tracker.log_daily_learning("2023-10-01", "Python", 60, "Completed basic Python tutorial")
    tracker.log_daily_learning("2023-10-02", "AI", 45, "Started with Machine Learning basics")
    tracker.log_daily_learning("2023-10-03", "Python", 30, " practiced lists and dictionaries")
    
    # Example report generation
    weekly_progress = tracker.get_weekly_progress()
    print("Weekly Progress:")
    print(f"Total study time: {weekly_progress['total_study_time']} minutes")
    print(f"Number of study sessions: {weekly_progress['study_frequency']}")
    print(f"Recent topics studied: {', '.join(weekly_progress['recent_topics'])}\n")
    
    learning_report = tracker.generate_learning_report(days_ago=3)
    print("Learning Report (last 3 days):")
    print(f"Number of learning days: {learning_report['number_of_learning_days']}")
    print(f"Total study time: {learning_report['total_study_time']} minutes")
    print(f"Highest engagement topics: {', '.join(learning_report['topics_with_highest_engagement'].keys())}")