Commit 4ff14f271aab2bb07212cccbbf10567ee0090990

Authored by Miguel Barão
1 parent d5cd0d10
Exists in master and in 1 other branch dev

- fixed previous comments reset on each new answer submission

BUGS.md
... ... @@ -2,7 +2,6 @@
2 2 # BUGS
3 3  
4 4 - default prefix should be obtained from each course (yaml conf)?
5   -- quando a pergunta devolve comments, este é apresentado, mas fica persistente nas tentativas seguintes. devia ser limpo apos a segunda submissao.
6 5 - a opcao max_tries na especificacao das perguntas é cumbersome... usar antes tries?
7 6 - tabelas nas perguntas radio/checkbox não ocupam todo o espaço como em question.
8 7 - nas perguntas de código, quando erra nao se devia acrescentar mesma pergunta no fim.
... ... @@ -29,6 +28,8 @@
29 28 - normalizar com perguntations.
30 29  
31 30 # FIXED
  31 +
  32 +- quando a pergunta devolve comments, este é apresentado, mas fica persistente nas tentativas seguintes. devia ser limpo apos a segunda submissao.
32 33 - na definicao dos topicos, indicar:
33 34 "file: questions.yaml" (default questions.yaml)
34 35 "shuffle: True/False" (default False)
... ...
knowledge.py
... ... @@ -104,7 +104,6 @@ class StudentKnowledge(object):
104 104 def finish_topic(self):
105 105 logger.debug(f'StudentKnowledge.finish_topic({self.current_topic})')
106 106  
107   - self.current_question = None
108 107 self.state[self.current_topic] = {
109 108 'date': datetime.now(),
110 109 'level': self.correct_answers / (self.correct_answers + self.wrong_answers)
... ... @@ -128,29 +127,27 @@ class StudentKnowledge(object):
128 127  
129 128 logger.debug(f'Grade {grade:.2} ({q["ref"]})')
130 129  
131   - # if answer is correct, get next question
132 130 if grade > 0.999:
133 131 self.correct_answers += 1
134 132 self.next_question()
  133 + action = 'new_question'
135 134  
136   - # if wrong, keep same question and append a similar one at the end
137 135 else:
138 136 self.wrong_answers += 1
139   -
140 137 self.current_question['tries'] -= 1
141   -
142 138 logger.debug(f'Wrong answers = {self.wrong_answers}; Tries = {self.current_question["tries"]}')
143 139  
144   - # append a new instance of the current question to the end and
145   - # move to the next question
146 140 if self.current_question['tries'] <= 0:
147 141 logger.debug("Appending new instance of this question to the end")
148   - factory = self.factory # self.deps.node[self.current_topic]['factory']
149   - self.questions.append(factory[q['ref']].generate())
  142 + self.questions.append(self.factory[q['ref']].generate())
150 143 self.next_question()
  144 + action = 'new_question'
  145 +
  146 + else:
  147 + action = 'wrong'
151 148  
152 149 # returns answered and corrected question (not new one)
153   - return q
  150 + return q, action
154 151  
155 152  
156 153 # ------------------------------------------------------------------------
... ... @@ -160,12 +157,14 @@ class StudentKnowledge(object):
160 157 try:
161 158 self.current_question = self.questions.pop(0)
162 159 except IndexError:
  160 + self.current_question = None
163 161 self.finish_topic()
164 162 else:
165 163 self.current_question['start_time'] = datetime.now()
166 164 self.current_question['tries'] = self.current_question.get('max_tries', 3) # FIXME hardcoded 3
167 165 logger.debug(f'Next question is "{self.current_question["ref"]}"')
168 166  
  167 + return self.current_question # question or None
169 168  
170 169 # ========================================================================
171 170 # pure functions of the state (no side effects)
... ...
learnapp.py
... ... @@ -136,7 +136,7 @@ class LearnApp(object):
136 136 # ------------------------------------------------------------------------
137 137 async def check_answer(self, uid, answer):
138 138 knowledge = self.online[uid]['state']
139   - q = await knowledge.check_answer(answer) # also moves to next question
  139 + q, action = await knowledge.check_answer(answer) # also moves to next question
140 140 logger.info(f'User "{uid}" got {q["grade"]:.2} in question "{q["ref"]}"')
141 141 topic = knowledge.get_current_topic()
142 142  
... ... @@ -175,15 +175,10 @@ class LearnApp(object):
175 175 s.add(a)
176 176  
177 177 logger.debug(f'Saved topic "{topic}" into database')
178   - return 'finished_topic'
  178 + action = 'finished_topic' # FIXME
  179 +
  180 + return action
179 181  
180   - if q['tries'] > 0 and q['grade'] <= 0.999:
181   - return 'wrong'
182   - # elif q['tries'] <= 0 and q['grade'] <= 0.999:
183   - # return 'max_tries_exceeded'
184   - else:
185   - return 'new_question'
186   - # return q['grade']
187 182  
188 183 # ------------------------------------------------------------------------
189 184 # Start new topic
... ... @@ -252,11 +247,11 @@ class LearnApp(object):
252 247 topics = config.get('topics', {})
253 248 g = self.deps # the dependency graph
254 249  
  250 + g.add_nodes_from(topics.keys())
255 251 for tref, attr in topics.items():
256   - # g.add_node(tref)
257 252 g.add_edges_from((d,tref) for d in attr.get('deps', []))
258 253  
259   - t = g.node[tref] # current topic node
  254 + t = g.node[tref] # get current topic node
260 255 t['type'] = attr.get('type', 'topic')
261 256 t['name'] = attr.get('name', tref)
262 257 t['path'] = path.join(g.graph['prefix'], tref) # prefix/topic
... ...
questions.py
... ... @@ -47,6 +47,7 @@ class Question(dict):
47 47 # self['answer'] = answer
48 48  
49 49 def correct(self):
  50 + self['comments'] = ''
50 51 self['grade'] = 0.0
51 52 return 0.0
52 53  
... ...