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

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