File size: 2,710 Bytes
a52f96d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
Simple mock task generator for independent student testing.
"""

from interfaces import TaskGeneratorInterface, Task
import random


class MockTaskGenerator(TaskGeneratorInterface):
    """Simple task generator with templates."""
    
    def __init__(self):
        self.topics = ['history', 'science', 'literature', 'geography', 'current_events']
        self.difficulties = ['easy', 'medium', 'hard']
        
        self.passages = {
            'history': "The Industrial Revolution began in Britain in the late 18th century. It brought major changes to manufacturing and society.",
            'science': "Photosynthesis is the process by which plants use sunlight to convert carbon dioxide and water into glucose and oxygen.",
            'literature': "Shakespeare wrote numerous plays including Hamlet, Romeo and Juliet, and Macbeth during the Elizabethan era.",
            'geography': "The Amazon rainforest is the world's largest tropical rainforest, spanning nine countries in South America.",
            'current_events': "Artificial intelligence is rapidly advancing, with applications in healthcare, transportation, and education."
        }
        
        self.task_counter = 0
    
    def generate_task(self, topic: str, difficulty: str) -> Task:
        passage = self.passages.get(topic, f"This is a passage about {topic}.")
        
        questions = {
            'easy': f"What is the main topic of this passage?",
            'medium': f"What can be inferred from this passage about {topic}?",
            'hard': f"Which statement best synthesizes the information in this passage?"
        }
        
        question = questions[difficulty]
        
        # Generate choices
        correct = f"It discusses {topic}"
        wrong = [
            f"It's primarily about a different subject",
            f"The passage focuses on unrelated matters",
            f"This is not the main theme"
        ]
        
        choices = [correct] + wrong
        answer_idx = 0
        
        # Shuffle
        combined = list(enumerate(choices))
        random.shuffle(combined)
        answer_idx = [i for i, (orig, _) in enumerate(combined) if orig == 0][0]
        choices = [c for _, c in combined]
        
        self.task_counter += 1
        
        return Task(
            passage=passage,
            question=question,
            choices=choices,
            answer=answer_idx,
            topic=topic,
            difficulty=difficulty,
            task_id=f"{topic}_{difficulty}_{self.task_counter}"
        )
    
    def get_available_topics(self):
        return self.topics
    
    def get_available_difficulties(self):
        return self.difficulties