From 4ff14f271aab2bb07212cccbbf10567ee0090990 Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Tue, 4 Dec 2018 14:12:33 +0000 Subject: [PATCH] - fixed previous comments reset on each new answer submission --- BUGS.md | 3 ++- knowledge.py | 19 +++++++++---------- learnapp.py | 17 ++++++----------- questions.py | 1 + 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/BUGS.md b/BUGS.md index 7d9e5e9..6b6c033 100644 --- a/BUGS.md +++ b/BUGS.md @@ -2,7 +2,6 @@ # BUGS - default prefix should be obtained from each course (yaml conf)? -- quando a pergunta devolve comments, este é apresentado, mas fica persistente nas tentativas seguintes. devia ser limpo apos a segunda submissao. - a opcao max_tries na especificacao das perguntas é cumbersome... usar antes tries? - tabelas nas perguntas radio/checkbox não ocupam todo o espaço como em question. - nas perguntas de código, quando erra nao se devia acrescentar mesma pergunta no fim. @@ -29,6 +28,8 @@ - normalizar com perguntations. # FIXED + +- quando a pergunta devolve comments, este é apresentado, mas fica persistente nas tentativas seguintes. devia ser limpo apos a segunda submissao. - na definicao dos topicos, indicar: "file: questions.yaml" (default questions.yaml) "shuffle: True/False" (default False) diff --git a/knowledge.py b/knowledge.py index 083d326..d2ec4cc 100644 --- a/knowledge.py +++ b/knowledge.py @@ -104,7 +104,6 @@ class StudentKnowledge(object): def finish_topic(self): logger.debug(f'StudentKnowledge.finish_topic({self.current_topic})') - self.current_question = None self.state[self.current_topic] = { 'date': datetime.now(), 'level': self.correct_answers / (self.correct_answers + self.wrong_answers) @@ -128,29 +127,27 @@ class StudentKnowledge(object): logger.debug(f'Grade {grade:.2} ({q["ref"]})') - # if answer is correct, get next question if grade > 0.999: self.correct_answers += 1 self.next_question() + action = 'new_question' - # if wrong, keep same question and append a similar one at the end else: self.wrong_answers += 1 - self.current_question['tries'] -= 1 - logger.debug(f'Wrong answers = {self.wrong_answers}; Tries = {self.current_question["tries"]}') - # append a new instance of the current question to the end and - # move to the next question if self.current_question['tries'] <= 0: logger.debug("Appending new instance of this question to the end") - factory = self.factory # self.deps.node[self.current_topic]['factory'] - self.questions.append(factory[q['ref']].generate()) + self.questions.append(self.factory[q['ref']].generate()) self.next_question() + action = 'new_question' + + else: + action = 'wrong' # returns answered and corrected question (not new one) - return q + return q, action # ------------------------------------------------------------------------ @@ -160,12 +157,14 @@ class StudentKnowledge(object): try: self.current_question = self.questions.pop(0) except IndexError: + self.current_question = None self.finish_topic() else: self.current_question['start_time'] = datetime.now() self.current_question['tries'] = self.current_question.get('max_tries', 3) # FIXME hardcoded 3 logger.debug(f'Next question is "{self.current_question["ref"]}"') + return self.current_question # question or None # ======================================================================== # pure functions of the state (no side effects) diff --git a/learnapp.py b/learnapp.py index 9626ba7..f2e1a79 100644 --- a/learnapp.py +++ b/learnapp.py @@ -136,7 +136,7 @@ class LearnApp(object): # ------------------------------------------------------------------------ async def check_answer(self, uid, answer): knowledge = self.online[uid]['state'] - q = await knowledge.check_answer(answer) # also moves to next question + q, action = await knowledge.check_answer(answer) # also moves to next question logger.info(f'User "{uid}" got {q["grade"]:.2} in question "{q["ref"]}"') topic = knowledge.get_current_topic() @@ -175,15 +175,10 @@ class LearnApp(object): s.add(a) logger.debug(f'Saved topic "{topic}" into database') - return 'finished_topic' + action = 'finished_topic' # FIXME + + return action - if q['tries'] > 0 and q['grade'] <= 0.999: - return 'wrong' - # elif q['tries'] <= 0 and q['grade'] <= 0.999: - # return 'max_tries_exceeded' - else: - return 'new_question' - # return q['grade'] # ------------------------------------------------------------------------ # Start new topic @@ -252,11 +247,11 @@ class LearnApp(object): topics = config.get('topics', {}) g = self.deps # the dependency graph + g.add_nodes_from(topics.keys()) for tref, attr in topics.items(): - # g.add_node(tref) g.add_edges_from((d,tref) for d in attr.get('deps', [])) - t = g.node[tref] # current topic node + t = g.node[tref] # get current topic node t['type'] = attr.get('type', 'topic') t['name'] = attr.get('name', tref) t['path'] = path.join(g.graph['prefix'], tref) # prefix/topic diff --git a/questions.py b/questions.py index 2d37fe4..cbe6ccc 100644 --- a/questions.py +++ b/questions.py @@ -47,6 +47,7 @@ class Question(dict): # self['answer'] = answer def correct(self): + self['comments'] = '' self['grade'] = 0.0 return 0.0 -- libgit2 0.21.2