Commit 720ccbfade51bc4749ea432c808b75b423e4d581

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

- more type annotations in student.py

BUGS.md
1 1  
2 2 # BUGS
3 3  
  4 +- duplo clicks no botao "responder" dessincroniza as questões, ver debounce em https://stackoverflow.com/questions/20281546/how-to-prevent-calling-of-en-event-handler-twice-on-fast-clicks
4 5 - quando termina topico devia apagar as perguntas todas (se falhar a gerar novo topico, aparecem perguntas do antigo)
5 6 - apos clicar no botao responder, inactivar o input (importante quando o tempo de correcção é grande)
6 7 - devia mostrar timeout para o aluno saber a razao.
... ...
aprendizations/learnapp.py
... ... @@ -195,9 +195,9 @@ class LearnApp(object):
195 195 # ------------------------------------------------------------------------
196 196 async def check_answer(self, uid, answer):
197 197 knowledge = self.online[uid]['state']
  198 + topic = knowledge.get_current_topic()
198 199 q, action = await knowledge.check_answer(answer) # may move questions
199 200 logger.info(f'User "{uid}" got {q["grade"]:.2} in "{q["ref"]}"')
200   - topic = knowledge.get_current_topic()
201 201  
202 202 # always save grade of answered question
203 203 with self.db_session() as s:
... ...
aprendizations/student.py
... ... @@ -3,11 +3,15 @@
3 3 import random
4 4 from datetime import datetime
5 5 import logging
6   -from typing import List
  6 +from typing import List, Optional
7 7  
8 8 # third party libraries
9 9 import networkx as nx
10 10  
  11 +# this project
  12 +from .questions import Question
  13 +
  14 +
11 15 # setup logger for this module
12 16 logger = logging.getLogger(__name__)
13 17  
... ... @@ -68,12 +72,12 @@ class StudentState(object):
68 72 # questions: list of generated questions to do in the topic
69 73 # current_question: the current question to be presented
70 74 # ------------------------------------------------------------------------
71   - async def start_topic(self, topic):
  75 + async def start_topic(self, topic: str):
72 76 logger.debug(f'[start_topic] topic "{topic}"')
73 77  
74   - if self.current_topic == topic:
75   - logger.info('Restarting current topic is not allowed.')
76   - return
  78 + # if self.current_topic == topic:
  79 + # logger.info('Restarting current topic is not allowed.')
  80 + # return
77 81  
78 82 # do not allow locked topics
79 83 if self.is_locked(topic):
... ... @@ -115,7 +119,7 @@ class StudentState(object):
115 119 'level': self.correct_answers / (self.correct_answers +
116 120 self.wrong_answers)
117 121 }
118   - # self.current_topic = None
  122 + self.current_topic = None
119 123 self.unlock_topics()
120 124  
121 125 # ------------------------------------------------------------------------
... ... @@ -155,9 +159,9 @@ class StudentState(object):
155 159 return q, action
156 160  
157 161 # ------------------------------------------------------------------------
158   - # Move to next question
  162 + # Move to next question, or None
159 163 # ------------------------------------------------------------------------
160   - def next_question(self):
  164 + def next_question(self) -> Optional[Question]:
161 165 try:
162 166 self.current_question = self.questions.pop(0)
163 167 except IndexError:
... ... @@ -177,7 +181,7 @@ class StudentState(object):
177 181 # ========================================================================
178 182  
179 183 def topic_has_finished(self) -> bool:
180   - return self.current_question is None
  184 + return self.current_topic is None
181 185  
182 186 # ------------------------------------------------------------------------
183 187 # compute recommended sequence of topics ['a', 'b', ...]
... ... @@ -196,11 +200,11 @@ class StudentState(object):
196 200 return unlocked + locked
197 201  
198 202 # ------------------------------------------------------------------------
199   - def get_current_question(self):
  203 + def get_current_question(self) -> Optional[Question]:
200 204 return self.current_question
201 205  
202 206 # ------------------------------------------------------------------------
203   - def get_current_topic(self) -> str:
  207 + def get_current_topic(self) -> Optional[str]:
204 208 return self.current_topic
205 209  
206 210 # ------------------------------------------------------------------------
... ... @@ -221,12 +225,12 @@ class StudentState(object):
221 225 } for ref in self.topic_sequence]
222 226  
223 227 # ------------------------------------------------------------------------
224   - def get_topic_progress(self):
  228 + def get_topic_progress(self) -> float:
225 229 return self.correct_answers / (1 + self.correct_answers +
226 230 len(self.questions))
227 231  
228 232 # ------------------------------------------------------------------------
229   - def get_topic_level(self, topic):
  233 + def get_topic_level(self, topic: str) -> float:
230 234 return self.state[topic]['level']
231 235  
232 236 # ------------------------------------------------------------------------
... ...