Commit 65fc5e2e1db72c62fc793c3a43703554126c2c20

Authored by Miguel Barao
1 parent e530d705
Exists in master and in 1 other branch dev

- Allow total points of test to be zero, but logs an error.

- If type of question does not exist, logs error and ignores question.
Showing 3 changed files with 16 additions and 5 deletions   Show diff stats
BUGS.md
1 1  
2 2 # BUGS
3   -- se submeter um teste so com information, da divisao por zero.
4   -- se pergunta for 'type: info' rebenta
5 3 - 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:
6 4 {'ref1': 'resposta1', 'ref2': ['resposta2a', 'resposta2b']}
7 5 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"
28 26  
29 27 # FIXED
30 28  
  29 +- se pergunta tiver 'type:' errado, rebenta.
  30 +- se submeter um teste so com information, da divisao por zero.
31 31 - se save_answers nao existir, da warning que nao serao gravados, mas sao sempre gravados! pagina de administracao diz --not being saved--
32 32 - first login é INFO e não WARNING
33 33 - /review não mostra imagens porque precisa que teste esteja a decorrer...
... ...
questions.py
... ... @@ -154,8 +154,9 @@ class QuestionFactory(dict):
154 154 # Finally we create an instance of Question()
155 155 try:
156 156 qinstance = types[q['type']](q) # instance with correct class
157   - except KeyError:
  157 + except KeyError as e:
158 158 logger.error('Unknown question type "{0}" in "{1}:{2}".'.format(q['type'], q['filename'], q['ref']))
  159 + raise e
159 160 except:
160 161 logger.error('Failed to create question "{0}" from file "{1}".'.format(q['ref'], q['filename']))
161 162 else:
... ...
test.py
... ... @@ -149,7 +149,12 @@ class TestFactory(dict):
149 149 n = 1
150 150 for i, qq in enumerate(self['questions']):
151 151 # generate Question() selected randomly from list of references
152   - q = self.question_factory.generate(random.choice(qq['ref']))
  152 + qref = random.choice(qq['ref'])
  153 + try:
  154 + q = self.question_factory.generate(qref)
  155 + except Exception:
  156 + logger.error('Cannot generate question with reference "{}". Skipping.'.format(qref))
  157 + continue
153 158  
154 159 # some defaults
155 160 if q['type'] in ('information', 'warning', 'alert'):
... ... @@ -228,7 +233,12 @@ class Test(dict):
228 233 grade += q.correct() * q['points']
229 234 total_points += q['points']
230 235  
231   - self['grade'] = round(20.0 * max(grade / total_points, 0.0), 1)
  236 + if total_points > 0.0:
  237 + self['grade'] = round(20.0 * max(grade / total_points, 0.0), 1)
  238 + else:
  239 + logger.error('Student {}: division by zero during correction. Total points must be positive.'.format(self['student']['number']))
  240 + self['grade'] = 0.0
  241 +
232 242 logger.info('Student {}: correction gave {} points.'.format(self['student']['number'], self['grade']))
233 243 return self['grade']
234 244  
... ...