From 720ccbfade51bc4749ea432c808b75b423e4d581 Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Mon, 15 Jul 2019 17:17:38 +0100 Subject: [PATCH] - more type annotations in student.py --- BUGS.md | 1 + aprendizations/learnapp.py | 2 +- aprendizations/student.py | 30 +++++++++++++++++------------- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/BUGS.md b/BUGS.md index 67bbe58..acb3a27 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,6 +1,7 @@ # BUGS +- 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 - quando termina topico devia apagar as perguntas todas (se falhar a gerar novo topico, aparecem perguntas do antigo) - apos clicar no botao responder, inactivar o input (importante quando o tempo de correcção é grande) - devia mostrar timeout para o aluno saber a razao. diff --git a/aprendizations/learnapp.py b/aprendizations/learnapp.py index 9991be3..cf81899 100644 --- a/aprendizations/learnapp.py +++ b/aprendizations/learnapp.py @@ -195,9 +195,9 @@ class LearnApp(object): # ------------------------------------------------------------------------ async def check_answer(self, uid, answer): knowledge = self.online[uid]['state'] + topic = knowledge.get_current_topic() q, action = await knowledge.check_answer(answer) # may move questions logger.info(f'User "{uid}" got {q["grade"]:.2} in "{q["ref"]}"') - topic = knowledge.get_current_topic() # always save grade of answered question with self.db_session() as s: diff --git a/aprendizations/student.py b/aprendizations/student.py index 9bc1a63..957520d 100644 --- a/aprendizations/student.py +++ b/aprendizations/student.py @@ -3,11 +3,15 @@ import random from datetime import datetime import logging -from typing import List +from typing import List, Optional # third party libraries import networkx as nx +# this project +from .questions import Question + + # setup logger for this module logger = logging.getLogger(__name__) @@ -68,12 +72,12 @@ class StudentState(object): # questions: list of generated questions to do in the topic # current_question: the current question to be presented # ------------------------------------------------------------------------ - async def start_topic(self, topic): + async def start_topic(self, topic: str): logger.debug(f'[start_topic] topic "{topic}"') - if self.current_topic == topic: - logger.info('Restarting current topic is not allowed.') - return + # if self.current_topic == topic: + # logger.info('Restarting current topic is not allowed.') + # return # do not allow locked topics if self.is_locked(topic): @@ -115,7 +119,7 @@ class StudentState(object): 'level': self.correct_answers / (self.correct_answers + self.wrong_answers) } - # self.current_topic = None + self.current_topic = None self.unlock_topics() # ------------------------------------------------------------------------ @@ -155,9 +159,9 @@ class StudentState(object): return q, action # ------------------------------------------------------------------------ - # Move to next question + # Move to next question, or None # ------------------------------------------------------------------------ - def next_question(self): + def next_question(self) -> Optional[Question]: try: self.current_question = self.questions.pop(0) except IndexError: @@ -177,7 +181,7 @@ class StudentState(object): # ======================================================================== def topic_has_finished(self) -> bool: - return self.current_question is None + return self.current_topic is None # ------------------------------------------------------------------------ # compute recommended sequence of topics ['a', 'b', ...] @@ -196,11 +200,11 @@ class StudentState(object): return unlocked + locked # ------------------------------------------------------------------------ - def get_current_question(self): + def get_current_question(self) -> Optional[Question]: return self.current_question # ------------------------------------------------------------------------ - def get_current_topic(self) -> str: + def get_current_topic(self) -> Optional[str]: return self.current_topic # ------------------------------------------------------------------------ @@ -221,12 +225,12 @@ class StudentState(object): } for ref in self.topic_sequence] # ------------------------------------------------------------------------ - def get_topic_progress(self): + def get_topic_progress(self) -> float: return self.correct_answers / (1 + self.correct_answers + len(self.questions)) # ------------------------------------------------------------------------ - def get_topic_level(self, topic): + def get_topic_level(self, topic: str) -> float: return self.state[topic]['level'] # ------------------------------------------------------------------------ -- libgit2 0.21.2