knowledge.py
1.19 KB
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
# python standard library
import random
from datetime import datetime
# this project
import questions
# contains the kowledge state of each student.
class Knowledge(object):
def __init__(self):
self.factory = questions.QuestionFactory()
self.factory.load_files(['questions.yaml'], 'demo') # FIXME
self.current_question = None
def get_current_question(self):
return self.current_question
# --- generates a new question given the current state
def new_question(self):
# FIXME
if self.current_question is None or self.current_question.get('grade', 0.0) > 0.9999:
questions = list(self.factory)
self.current_question = self.factory.generate(random.choice(questions))
self.current_question['start_time'] = datetime.now()
return self.current_question
# --- checks answer and updates knowledge state
# returns current question with correction, time and comments updated
def check_answer(self, answer):
question = self.current_question
if question is not None:
question['finish_time'] = datetime.now()
question.correct(answer)
return question