Commit 6f0ef3e3b25221926221b516dc67f94ad89af361
1 parent
bbe09148
Exists in
master
and in
1 other branch
- fixed bug where checkbox answers with all options unchecked would not be accepted.
- randomize question order and sample for 8 questions at maximum.
Showing
2 changed files
with
15 additions
and
9 deletions
Show diff stats
knowledge.py
| ... | ... | @@ -94,6 +94,11 @@ class StudentKnowledge(object): |
| 94 | 94 | self.correct_answers = 0 |
| 95 | 95 | self.wrong_answers = 0 |
| 96 | 96 | self.finished_questions = [] |
| 97 | + | |
| 98 | + | |
| 99 | + # TODO select a subset of question and randomize order | |
| 100 | + questionlist = random.sample(questionlist, k=min(8, len(questionlist))) | |
| 101 | + | |
| 97 | 102 | self.questions = [factory[qref].generate() for qref in questionlist] |
| 98 | 103 | logger.debug(f'Total: {len(self.questions)} questions') |
| 99 | 104 | |
| ... | ... | @@ -137,10 +142,11 @@ class StudentKnowledge(object): |
| 137 | 142 | grade = q.correct() |
| 138 | 143 | logger.debug(f'Grade = {grade:.2} ({q["ref"]})') |
| 139 | 144 | |
| 145 | + self.finished_questions.append(q) # both correct and wrong answers | |
| 146 | + | |
| 140 | 147 | # if answer is correct, get next question |
| 141 | 148 | if grade > 0.999: |
| 142 | 149 | self.correct_answers += 1 |
| 143 | - self.finished_questions.append(q) | |
| 144 | 150 | try: |
| 145 | 151 | self.current_question = self.questions.pop(0) # FIXME empty? |
| 146 | 152 | except IndexError: | ... | ... |
serve.py
| ... | ... | @@ -256,15 +256,15 @@ class QuestionHandler(BaseHandler): |
| 256 | 256 | |
| 257 | 257 | # check answer and get next question (same, new or None) |
| 258 | 258 | answer = self.get_body_arguments('answer') # list |
| 259 | - if not answer: | |
| 259 | + | |
| 260 | + # answers returned in a list. fix depending on question type | |
| 261 | + qtype = self.learn.get_student_question_type(user) | |
| 262 | + if qtype in ('success', 'information', 'info'): # FIXME unused? | |
| 260 | 263 | answer = None |
| 261 | - else: | |
| 262 | - # answers returned in a list. fix depending on question type | |
| 263 | - qtype = self.learn.get_student_question_type(user) | |
| 264 | - if qtype in ('success', 'information', 'info'): # FIXME unused? | |
| 265 | - answer = None | |
| 266 | - elif qtype != 'checkbox': # radio, text, textarea, ... | |
| 267 | - answer = answer[0] | |
| 264 | + elif qtype == 'radio' and not answer: | |
| 265 | + answer = None | |
| 266 | + elif qtype != 'checkbox': # radio, text, textarea, ... | |
| 267 | + answer = answer[0] | |
| 268 | 268 | |
| 269 | 269 | # check answer in another thread (nonblocking) |
| 270 | 270 | loop = asyncio.get_event_loop() | ... | ... |