diff --git a/aprendizations/learnapp.py b/aprendizations/learnapp.py index 0a8a66f..6a4050a 100644 --- a/aprendizations/learnapp.py +++ b/aprendizations/learnapp.py @@ -31,11 +31,11 @@ async def _bcrypt_hash(a, b): a.encode('utf-8'), b) -async def check_password(try_pw, pw): +async def check_password(try_pw: str, pw: str) -> bool: return pw == await _bcrypt_hash(try_pw, pw) -async def bcrypt_hash_gen(new_pw): +async def bcrypt_hash_gen(new_pw: str): return await _bcrypt_hash(new_pw, bcrypt.gensalt()) @@ -75,7 +75,10 @@ class LearnApp(object): for c in config_files: self.populate_graph(c) - self.factory = self.make_factory() # for all questions all topics + # factory is a dict with question generators for all topics + self.factory = self.make_factory() # {'qref': QFactory()} + + # if graph has topics that are not in the database, add them self.db_add_missing_topics(self.deps.nodes()) if check: @@ -83,14 +86,19 @@ class LearnApp(object): # ------------------------------------------------------------------------ def sanity_check_questions(self): - for qref, q in self.factory.items(): - logger.info(f'Generating {qref}...') + def check_question(qref, q): + logger.debug(f'Generating {qref}...') try: q.generate() except Exception as e: logger.error(f'Sanity check failed in "{qref}"') raise e + logger.info('Starting sanity checks...') + for qref, q in self.factory.items(): + check_question(qref, q) + logger.info('Sanity checks passed.') + # ------------------------------------------------------------------------ # login # ------------------------------------------------------------------------ @@ -226,11 +234,13 @@ class LearnApp(object): # ------------------------------------------------------------------------ def db_add_missing_topics(self, topics): with self.db_session() as s: - dbtopics = [t[0] for t in s.query(Topic.id)] # get topics from DB - missing_topics = [Topic(id=t) for t in topics if t not in dbtopics] - if missing_topics: - s.add_all(missing_topics) - logger.info(f'Added {len(missing_topics)} new topics') + new_topics = [Topic(id=t) for t in topics + if (t,) not in s.query(Topic.id)] + + if new_topics: + s.add_all(new_topics) + logger.info(f'Added {len(new_topics)} new topics to the ' + f'database') # ------------------------------------------------------------------------ # setup and check database diff --git a/aprendizations/questions.py b/aprendizations/questions.py index 06df2d5..30a16d4 100644 --- a/aprendizations/questions.py +++ b/aprendizations/questions.py @@ -121,7 +121,7 @@ class QuestionRadio(Question): # ------------------------------------------------------------------------ # can return negative values for wrong answers - def correct(self): + def correct(self) -> None: super().correct() if self['answer'] is not None: @@ -187,7 +187,7 @@ class QuestionCheckbox(Question): # ------------------------------------------------------------------------ # can return negative values for wrong answers - def correct(self): + def correct(self) -> None: super().correct() if self['answer'] is not None: @@ -234,7 +234,7 @@ class QuestionText(Question): self['correct'] = [str(a) for a in self['correct']] # ------------------------------------------------------------------------ - def correct(self): + def correct(self) -> None: super().correct() if self['answer'] is not None: @@ -260,7 +260,7 @@ class QuestionTextRegex(Question): }) # ------------------------------------------------------------------------ - def correct(self): + def correct(self) -> None: super().correct() if self['answer'] is not None: try: @@ -291,7 +291,7 @@ class QuestionNumericInterval(Question): }) # ------------------------------------------------------------------------ - def correct(self): + def correct(self) -> None: super().correct() if self['answer'] is not None: lower, upper = self['correct'] @@ -331,7 +331,7 @@ class QuestionTextArea(Question): self['correct'] = path.join(self['path'], self['correct']) # FIXME # ------------------------------------------------------------------------ - def correct(self): + def correct(self) -> None: super().correct() if self['answer'] is not None: # correct answer and parse yaml ouput @@ -368,7 +368,7 @@ class QuestionInformation(Question): # ------------------------------------------------------------------------ # can return negative values for wrong answers - def correct(self): + def correct(self) -> None: super().correct() self['grade'] = 1.0 # always "correct" but points should be zero! diff --git a/aprendizations/serve.py b/aprendizations/serve.py index 4e78f93..d58dda4 100644 --- a/aprendizations/serve.py +++ b/aprendizations/serve.py @@ -96,12 +96,10 @@ class RankingsHandler(BaseHandler): def get(self): uid = self.current_user rankings = self.learn.get_rankings(uid) - # performance = self.learn.get_performance() self.render('rankings.html', uid=uid, name=self.learn.get_student_name(uid), rankings=rankings) - # performance=performance) # ---------------------------------------------------------------------------- -- libgit2 0.21.2