From 65fc5e2e1db72c62fc793c3a43703554126c2c20 Mon Sep 17 00:00:00 2001 From: Miguel Barao Date: Thu, 20 Oct 2016 18:35:48 +0100 Subject: [PATCH] - Allow total points of test to be zero, but logs an error. - If type of question does not exist, logs error and ignores question. --- BUGS.md | 4 ++-- questions.py | 3 ++- test.py | 14 ++++++++++++-- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/BUGS.md b/BUGS.md index 201e7c7..de058c2 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,7 +1,5 @@ # BUGS -- se submeter um teste so com information, da divisao por zero. -- se pergunta for 'type: info' rebenta - se um teste tiver a mesma pergunta (ref igual) varias vezes, rebenta na correcçao. As respostas são agregadas numa lista para cada ref. Ex: {'ref1': 'resposta1', 'ref2': ['resposta2a', 'resposta2b']} possivelmente as referencias das perguntas deveriam ser o "testeRef:numPergunta"... é preciso ver como depois estao associadas às correcções. @@ -28,6 +26,8 @@ possivelmente as referencias das perguntas deveriam ser o "testeRef:numPergunta" # FIXED +- se pergunta tiver 'type:' errado, rebenta. +- se submeter um teste so com information, da divisao por zero. - se save_answers nao existir, da warning que nao serao gravados, mas sao sempre gravados! pagina de administracao diz --not being saved-- - first login é INFO e não WARNING - /review não mostra imagens porque precisa que teste esteja a decorrer... diff --git a/questions.py b/questions.py index b63784a..f9fa9c0 100644 --- a/questions.py +++ b/questions.py @@ -154,8 +154,9 @@ class QuestionFactory(dict): # Finally we create an instance of Question() try: qinstance = types[q['type']](q) # instance with correct class - except KeyError: + except KeyError as e: logger.error('Unknown question type "{0}" in "{1}:{2}".'.format(q['type'], q['filename'], q['ref'])) + raise e except: logger.error('Failed to create question "{0}" from file "{1}".'.format(q['ref'], q['filename'])) else: diff --git a/test.py b/test.py index 417451b..eeebd79 100644 --- a/test.py +++ b/test.py @@ -149,7 +149,12 @@ class TestFactory(dict): n = 1 for i, qq in enumerate(self['questions']): # generate Question() selected randomly from list of references - q = self.question_factory.generate(random.choice(qq['ref'])) + qref = random.choice(qq['ref']) + try: + q = self.question_factory.generate(qref) + except Exception: + logger.error('Cannot generate question with reference "{}". Skipping.'.format(qref)) + continue # some defaults if q['type'] in ('information', 'warning', 'alert'): @@ -228,7 +233,12 @@ class Test(dict): grade += q.correct() * q['points'] total_points += q['points'] - self['grade'] = round(20.0 * max(grade / total_points, 0.0), 1) + if total_points > 0.0: + self['grade'] = round(20.0 * max(grade / total_points, 0.0), 1) + else: + logger.error('Student {}: division by zero during correction. Total points must be positive.'.format(self['student']['number'])) + self['grade'] = 0.0 + logger.info('Student {}: correction gave {} points.'.format(self['student']['number'], self['grade'])) return self['grade'] -- libgit2 0.21.2