diff --git a/aprendizations/learnapp.py b/aprendizations/learnapp.py index b112e6f..d2314c4 100644 --- a/aprendizations/learnapp.py +++ b/aprendizations/learnapp.py @@ -125,7 +125,7 @@ class LearnApp(): for qref, qfactory in self.factory.items(): logger.debug('checking %s...', qref) try: - question = qfactory.generate() + question = asyncio.run(qfactory.generate()) except QuestionException as exc: logger.error(exc) errors += 1 diff --git a/aprendizations/questions.py b/aprendizations/questions.py index 920bec1..85eef1f 100644 --- a/aprendizations/questions.py +++ b/aprendizations/questions.py @@ -5,6 +5,7 @@ Description: Classes the implement several types of questions. # python standard library +import asyncio from datetime import datetime import logging from os import path @@ -14,7 +15,7 @@ from typing import Any, Dict, NewType import uuid # this project -from aprendizations.tools import run_script, run_script_async +from aprendizations.tools import run_script_async # setup logger for this module logger = logging.getLogger(__name__) @@ -506,36 +507,39 @@ class QuestionTextArea(Question): self['correct'] = path.join(self['path'], self['correct']) # ------------------------------------------------------------------------ - def correct(self) -> None: - super().correct() - - if self['answer'] is not None: # correct answer and parse yaml ouput - out = run_script( - script=self['correct'], - args=self['args'], - stdin=self['answer'], - timeout=self['timeout'] - ) - - if out is None: - logger.warning('No grade after running "%s".', self["correct"]) - self['comments'] = ('Erro interno durante a correcção. ' - 'Por favor reporte este erro') - self['grade'] = 0.0 - elif isinstance(out, dict): - self['comments'] = out.get('comments', '') - try: - self['grade'] = float(out['grade']) - except ValueError: - logger.error('Output error in "%s".', self["correct"]) - except KeyError: - logger.error('No grade in "%s".', self["correct"]) - else: - try: - self['grade'] = float(out) - except (TypeError, ValueError): - logger.error('Invalid grade in "%s".', self["correct"]) - + # def correct(self) -> None: + # super().correct() + # + # if self['answer'] is not None: # correct answer and parse yaml ouput + # out = run_script( + # script=self['correct'], + # args=self['args'], + # stdin=self['answer'], + # timeout=self['timeout'] + # ) + # + # if out is None: + # logger.warning('No grade after running "%s".', self["correct"]) + # self['comments'] = ('Erro interno durante a correcção. ' + # 'Por favor reporte este erro') + # self['grade'] = 0.0 + # elif isinstance(out, dict): + # self['comments'] = out.get('comments', '') + # try: + # self['grade'] = float(out['grade']) + # except ValueError: + # logger.error('Output error in "%s".', self["correct"]) + # except KeyError: + # logger.error('No grade in "%s".', self["correct"]) + # else: + # try: + # self['grade'] = float(out) + # except (TypeError, ValueError): + # logger.error('Invalid grade in "%s".', self["correct"]) + # + def correct(self) -> None: # FIXME + asyncio.run(self.correct_async()) + # ------------------------------------------------------------------------ async def correct_async(self) -> None: super().correct() @@ -663,7 +667,7 @@ class QFactory(): self.qdict = qdict # ------------------------------------------------------------------------ - async def gen_async(self) -> Question: + async def generate(self) -> Question: ''' generates a question instance of QuestionRadio, QuestionCheckbox, ..., which is a descendent of base class Question. diff --git a/aprendizations/student.py b/aprendizations/student.py index 0b78720..0a6fd96 100644 --- a/aprendizations/student.py +++ b/aprendizations/student.py @@ -114,7 +114,7 @@ class StudentState(): questions = topic['questions'][:k] logger.debug('selected questions: %s', ', '.join(questions)) - self.questions: List[Question] = [await self.factory[ref].gen_async() + self.questions: List[Question] = [await self.factory[ref].generate() for ref in questions] logger.debug('generated %s questions', len(self.questions)) @@ -171,7 +171,7 @@ class StudentState(): elif question['status'] == 'wrong': if question['append_wrong']: logger.debug(' wrong answer => append new question') - new_question = await self.factory[question['ref']].gen_async() + new_question = await self.factory[question['ref']].generate() self.questions.append(new_question) self.next_question() -- libgit2 0.21.2