diff --git a/knowledge.py b/knowledge.py index c91f2c1..9ef0b64 100644 --- a/knowledge.py +++ b/knowledge.py @@ -94,6 +94,11 @@ class StudentKnowledge(object): self.correct_answers = 0 self.wrong_answers = 0 self.finished_questions = [] + + + # TODO select a subset of question and randomize order + questionlist = random.sample(questionlist, k=min(8, len(questionlist))) + self.questions = [factory[qref].generate() for qref in questionlist] logger.debug(f'Total: {len(self.questions)} questions') @@ -137,10 +142,11 @@ class StudentKnowledge(object): grade = q.correct() logger.debug(f'Grade = {grade:.2} ({q["ref"]})') + self.finished_questions.append(q) # both correct and wrong answers + # if answer is correct, get next question if grade > 0.999: self.correct_answers += 1 - self.finished_questions.append(q) try: self.current_question = self.questions.pop(0) # FIXME empty? except IndexError: diff --git a/serve.py b/serve.py index 26fd166..61411bc 100755 --- a/serve.py +++ b/serve.py @@ -256,15 +256,15 @@ class QuestionHandler(BaseHandler): # check answer and get next question (same, new or None) answer = self.get_body_arguments('answer') # list - if not answer: + + # answers returned in a list. fix depending on question type + qtype = self.learn.get_student_question_type(user) + if qtype in ('success', 'information', 'info'): # FIXME unused? answer = None - else: - # answers returned in a list. fix depending on question type - qtype = self.learn.get_student_question_type(user) - if qtype in ('success', 'information', 'info'): # FIXME unused? - answer = None - elif qtype != 'checkbox': # radio, text, textarea, ... - answer = answer[0] + elif qtype == 'radio' and not answer: + answer = None + elif qtype != 'checkbox': # radio, text, textarea, ... + answer = answer[0] # check answer in another thread (nonblocking) loop = asyncio.get_event_loop() -- libgit2 0.21.2