Commit 720ccbfade51bc4749ea432c808b75b423e4d581
1 parent
b6f3badf
Exists in
master
and in
1 other branch
- more type annotations in student.py
Showing
3 changed files
with
19 additions
and
14 deletions
Show diff stats
BUGS.md
1 | 1 | ||
2 | # BUGS | 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 | - quando termina topico devia apagar as perguntas todas (se falhar a gerar novo topico, aparecem perguntas do antigo) | 5 | - quando termina topico devia apagar as perguntas todas (se falhar a gerar novo topico, aparecem perguntas do antigo) |
5 | - apos clicar no botao responder, inactivar o input (importante quando o tempo de correcção é grande) | 6 | - apos clicar no botao responder, inactivar o input (importante quando o tempo de correcção é grande) |
6 | - devia mostrar timeout para o aluno saber a razao. | 7 | - devia mostrar timeout para o aluno saber a razao. |
aprendizations/learnapp.py
@@ -195,9 +195,9 @@ class LearnApp(object): | @@ -195,9 +195,9 @@ class LearnApp(object): | ||
195 | # ------------------------------------------------------------------------ | 195 | # ------------------------------------------------------------------------ |
196 | async def check_answer(self, uid, answer): | 196 | async def check_answer(self, uid, answer): |
197 | knowledge = self.online[uid]['state'] | 197 | knowledge = self.online[uid]['state'] |
198 | + topic = knowledge.get_current_topic() | ||
198 | q, action = await knowledge.check_answer(answer) # may move questions | 199 | q, action = await knowledge.check_answer(answer) # may move questions |
199 | logger.info(f'User "{uid}" got {q["grade"]:.2} in "{q["ref"]}"') | 200 | logger.info(f'User "{uid}" got {q["grade"]:.2} in "{q["ref"]}"') |
200 | - topic = knowledge.get_current_topic() | ||
201 | 201 | ||
202 | # always save grade of answered question | 202 | # always save grade of answered question |
203 | with self.db_session() as s: | 203 | with self.db_session() as s: |
aprendizations/student.py
@@ -3,11 +3,15 @@ | @@ -3,11 +3,15 @@ | ||
3 | import random | 3 | import random |
4 | from datetime import datetime | 4 | from datetime import datetime |
5 | import logging | 5 | import logging |
6 | -from typing import List | 6 | +from typing import List, Optional |
7 | 7 | ||
8 | # third party libraries | 8 | # third party libraries |
9 | import networkx as nx | 9 | import networkx as nx |
10 | 10 | ||
11 | +# this project | ||
12 | +from .questions import Question | ||
13 | + | ||
14 | + | ||
11 | # setup logger for this module | 15 | # setup logger for this module |
12 | logger = logging.getLogger(__name__) | 16 | logger = logging.getLogger(__name__) |
13 | 17 | ||
@@ -68,12 +72,12 @@ class StudentState(object): | @@ -68,12 +72,12 @@ class StudentState(object): | ||
68 | # questions: list of generated questions to do in the topic | 72 | # questions: list of generated questions to do in the topic |
69 | # current_question: the current question to be presented | 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 | logger.debug(f'[start_topic] topic "{topic}"') | 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 | # do not allow locked topics | 82 | # do not allow locked topics |
79 | if self.is_locked(topic): | 83 | if self.is_locked(topic): |
@@ -115,7 +119,7 @@ class StudentState(object): | @@ -115,7 +119,7 @@ class StudentState(object): | ||
115 | 'level': self.correct_answers / (self.correct_answers + | 119 | 'level': self.correct_answers / (self.correct_answers + |
116 | self.wrong_answers) | 120 | self.wrong_answers) |
117 | } | 121 | } |
118 | - # self.current_topic = None | 122 | + self.current_topic = None |
119 | self.unlock_topics() | 123 | self.unlock_topics() |
120 | 124 | ||
121 | # ------------------------------------------------------------------------ | 125 | # ------------------------------------------------------------------------ |
@@ -155,9 +159,9 @@ class StudentState(object): | @@ -155,9 +159,9 @@ class StudentState(object): | ||
155 | return q, action | 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 | try: | 165 | try: |
162 | self.current_question = self.questions.pop(0) | 166 | self.current_question = self.questions.pop(0) |
163 | except IndexError: | 167 | except IndexError: |
@@ -177,7 +181,7 @@ class StudentState(object): | @@ -177,7 +181,7 @@ class StudentState(object): | ||
177 | # ======================================================================== | 181 | # ======================================================================== |
178 | 182 | ||
179 | def topic_has_finished(self) -> bool: | 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 | # compute recommended sequence of topics ['a', 'b', ...] | 187 | # compute recommended sequence of topics ['a', 'b', ...] |
@@ -196,11 +200,11 @@ class StudentState(object): | @@ -196,11 +200,11 @@ class StudentState(object): | ||
196 | return unlocked + locked | 200 | return unlocked + locked |
197 | 201 | ||
198 | # ------------------------------------------------------------------------ | 202 | # ------------------------------------------------------------------------ |
199 | - def get_current_question(self): | 203 | + def get_current_question(self) -> Optional[Question]: |
200 | return self.current_question | 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 | return self.current_topic | 208 | return self.current_topic |
205 | 209 | ||
206 | # ------------------------------------------------------------------------ | 210 | # ------------------------------------------------------------------------ |
@@ -221,12 +225,12 @@ class StudentState(object): | @@ -221,12 +225,12 @@ class StudentState(object): | ||
221 | } for ref in self.topic_sequence] | 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 | return self.correct_answers / (1 + self.correct_answers + | 229 | return self.correct_answers / (1 + self.correct_answers + |
226 | len(self.questions)) | 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 | return self.state[topic]['level'] | 234 | return self.state[topic]['level'] |
231 | 235 | ||
232 | # ------------------------------------------------------------------------ | 236 | # ------------------------------------------------------------------------ |