# 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