diff --git a/demo/demo.yaml b/demo/demo.yaml index 5a1f205..7ca8ce9 100644 --- a/demo/demo.yaml +++ b/demo/demo.yaml @@ -1,38 +1,44 @@ --- # ============================================================================ -# The test reference should be a unique identifier. It is saved in the database -# so that queries can be done in the terminal like -# sqlite3 students.db "select * from tests where ref='demo'" +# Unique identifier of the test. +# Database queries can be done in the terminal with +# sqlite3 students.db "select * from tests where ref='tutorial'" ref: tutorial -# Database with student credentials and grades of all questions and tests done -# The database is an sqlite3 file generate with the command initdb +# Database file that includes student credentials, tests and questions grades. +# It's a sqlite3 database generated with the command 'initdb' database: students.db -# Directory where the tests including submitted answers and grades are stored. -# The submitted tests and their corrections can be reviewed later. +# Directory where the submitted and corrected test are stored for later review. answers_dir: ans # --- optional settings: ----------------------------------------------------- -# You may wish to refer the course, year or kind of test +# Title of this test, e.g. course name, year or test number # (default: '') title: Teste de demonstração (tutorial) # Duration in minutes. # (0 or undefined means infinite time) duration: 2 -autosubmit: true -# Show points for each question, scale 0-20. +# Automatic test submission after the timeout 'duration'? # (default: false) +autosubmit: true + +# Show points for each question (min and max). +# (default: true) show_points: true -# scale final grade to the interval [scale_min, scale_max] -# (default: scale to [0,20]) -scale_max: 20 -scale_min: 0 -scale_points: true +# scale final grade to an interval, e.g. [0, 20], keeping the relative weight +# of the points declared in the questions below. +# (default: no scaling, just use question points) +scale: [0, 5] + +# DEPRECATED: old version, to be removed +# scale_max: 20 +# scale_min: 0 +# scale_points: true # ---------------------------------------------------------------------------- # Base path applied to the questions files and all the scripts @@ -50,7 +56,7 @@ files: # The order is preserved. # There are several ways to define each question (explained below). questions: - - tut-test + - ref: tut-test - tut-questions - tut-radio diff --git a/demo/questions/correct/correct-question.py b/demo/questions/correct/correct-question.py index 8319a2f..df55039 100755 --- a/demo/questions/correct/correct-question.py +++ b/demo/questions/correct/correct-question.py @@ -1,24 +1,27 @@ #!/usr/bin/env python3 +''' +Demonstação de um script de correcção +''' + import re import sys -msg1 = '''--- -grade: 1.0 -comments: Muito bem! -''' +s = sys.stdin.read() -msg0 = ''' -grade: 0.0 -comments: A resposta correcta é "red green blue". -''' +ans = set(re.findall(r'[\w]+', s.lower())) # get words in lowercase +rgb = set(['red', 'green', 'blue']) # the correct answer -s = sys.stdin.read() +# a nota é o número de cores certas menos o número de erradas +grade = max(0, + len(rgb.intersection(ans)) - len(ans.difference(rgb))) / 3 -answer = set(re.findall(r'[\w]+', s.lower())) # get words in lowercase -rgb_colors = set(['red', 'green', 'blue']) # the correct answer +if ans == rgb: + print('---\n' + 'grade: 1.0\n' + 'comments: Muito bem!') -if answer == rgb_colors: - print(msg1) else: - print(msg0) + print('---\n' + f'grade: {grade}\n' + 'comments: A resposta correcta é "red green blue".') diff --git a/demo/questions/generators/generate-question.py b/demo/questions/generators/generate-question.py index 36b8082..3161ce4 100755 --- a/demo/questions/generators/generate-question.py +++ b/demo/questions/generators/generate-question.py @@ -18,10 +18,11 @@ print(f"""--- type: text title: Geradores de perguntas text: | - Existe a possibilidade da pergunta ser gerada por um programa externo. - Este programa deve escrever no `stdout` uma pergunta em formato `yaml` como - os anteriores. Pode também receber argumentos para parametrizar a geração da - pergunta. Aqui está um exemplo de uma pergunta gerada por um script python: + Existe a possibilidade da pergunta ser gerada por um programa externo. Este + programa deve escrever no `stdout` uma pergunta em formato `yaml` como nos + exemplos anteriores. Pode também receber argumentos para parametrizar a + geração da pergunta. Aqui está um exemplo de uma pergunta gerada por um + script python: ```python #!/usr/bin/env python3 diff --git a/perguntations/app.py b/perguntations/app.py index deeac3c..b170e03 100644 --- a/perguntations/app.py +++ b/perguntations/app.py @@ -86,7 +86,12 @@ class App(): self.allowed = set([]) # '0' is hardcoded to allowed elsewhere logger.info('Loading test configuration "%s".', conf["testfile"]) - testconf = load_yaml(conf['testfile']) + try: + testconf = load_yaml(conf['testfile']) + except Exception as exc: + logger.critical('Error loading test configuration YAML.') + raise AppException(exc) + testconf.update(conf) # command line options override configuration # start test factory diff --git a/perguntations/templates/grade.html b/perguntations/templates/grade.html index 48d6caa..eb3863f 100644 --- a/perguntations/templates/grade.html +++ b/perguntations/templates/grade.html @@ -43,11 +43,11 @@ {% if t['state'] == 'FINISHED' %}
O seu teste foi registado.
Pode fechar o browser e desligar o computador.