From b2e894fec100244af6fa4a7bc45836285b5bdb60 Mon Sep 17 00:00:00 2001 From: Miguel Barão Date: Thu, 13 Oct 2016 16:56:24 +0100 Subject: [PATCH] - small code cleanup --- BUGS.md | 5 +++++ app.py | 2 +- demo/questions/questions.yaml | 12 ++++++------ questions.py | 5 ++++- serve.py | 3 +-- test.py | 6 ++++-- 6 files changed, 21 insertions(+), 12 deletions(-) diff --git a/BUGS.md b/BUGS.md index c60145b..f941ab1 100644 --- a/BUGS.md +++ b/BUGS.md @@ -1,6 +1,11 @@ # BUGS +- 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. +- se ocorrer um erro na correcçao avisar aluno para contactar o professor. +- se directorio logs não existir no directorio actual (não perguntations) rebenta. - usar thread.Lock para aceder a variaveis de estado? # TODO diff --git a/app.py b/app.py index 0cebb6a..0de331f 100644 --- a/app.py +++ b/app.py @@ -129,7 +129,7 @@ class App(object): t.update_answers(ans) grade = t.correct() - # save JSON with the test + # save test in JSON format fname = ' -- '.join((t['student']['number'], t['ref'], str(t['finish_time']))) + '.json' fpath = path.abspath(path.join(t['answers_dir'], fname)) t.save_json(fpath) diff --git a/demo/questions/questions.yaml b/demo/questions/questions.yaml index 38a69ac..5709894 100644 --- a/demo/questions/questions.yaml +++ b/demo/questions/questions.yaml @@ -145,13 +145,13 @@ ### Tabelas - ~~Não são perfeitas~~, é uma limitação do markdown. + Não têm um espaçamento perfeito, é uma limitação do markdown. - Left | Center | Right - ------------|:-------------:|-----: - A | *hello* | $1600.00 - B | **world** | $12.50 - C | `code` | $1.99 + Left | Center | Right + -----------------|:-------------:|----------: + $\sin(x^2)$ | *hello* | $1600.00 + $\frac{1}{2\pi}$ | **world** | $12.50 + $\sqrt{\pi}$ | `code` | $1.99 --- diff --git a/questions.py b/questions.py index 946393e..b63784a 100644 --- a/questions.py +++ b/questions.py @@ -373,7 +373,10 @@ class QuestionTextRegex(Question): def correct(self): super().correct() if self['answer'] is not None: - self['grade'] = 1.0 if re.match(self['correct'], self['answer']) else 0.0 + try: + self['grade'] = 1.0 if re.match(self['correct'], self['answer']) else 0.0 + except TypeError: + logger.error('While matching regex {0} with answer {1}.'.format(self['correct'], self['answer'])) return self['grade'] diff --git a/serve.py b/serve.py index effb31e..71010dc 100755 --- a/serve.py +++ b/serve.py @@ -10,7 +10,7 @@ import json try: import cherrypy - from cherrypy.lib import auth_digest + # from cherrypy.lib import auth_digest from mako.lookup import TemplateLookup except ImportError: print('Some python packages are missing. See README.md for instructions.') @@ -260,7 +260,6 @@ class Root(object): # --- ADMIN -------------------------------------------------------------- @cherrypy.expose @require(name_is('0')) - # def admin(self, **reset_pw): def admin(self): return self.template['admin'].render() diff --git a/test.py b/test.py index 6157e1a..00664c3 100644 --- a/test.py +++ b/test.py @@ -21,7 +21,7 @@ import questions from tools import load_yaml # =========================================================================== -class TestFactoryException(Exception): # FIXME unused +class TestFactoryException(Exception): pass # =========================================================================== @@ -135,6 +135,7 @@ class TestFactory(dict): # ----------------------------------------------------------------------- def normalize_questions(self): + # print(self['questions']) for i, q in enumerate(self['questions']): # normalize question to a dict and ref to a list of references if isinstance(q, str): @@ -143,6 +144,7 @@ class TestFactory(dict): q['ref'] = [q['ref']] self['questions'][i] = q + # print(self['questions']) # ----------------------------------------------------------------------- # Given a dictionary with a student id {'name':'john', 'number': 123} @@ -174,7 +176,7 @@ class TestFactory(dict): 'answers_dir': self['answers_dir'], # FIXME which ones are required? - 'practice': self['practice'], # FIXME remove? + # 'practice': self['practice'], # FIXME remove? 'show_hints': self['show_hints'], 'show_points': self['show_points'], 'show_ref': self['show_ref'], -- libgit2 0.21.2