diff --git a/BUGS.md b/BUGS.md index d28bc8e..c1afd25 100644 --- a/BUGS.md +++ b/BUGS.md @@ -11,41 +11,6 @@ # TODO -```yaml -# constroi pergunta com opções indicadas e pontuação dada em baixo caso resposta -# marque essa opção ou o seu simétrico se não marcar -type: checkbox -options: - - option1 - - option2 - - option3 -correct: [1, -1, 1] - - -# Para cada opção escolhe aleatoriamente right ou wrong e controi pergunta como -# em cima. A ideia é wrongN ser a mesma pergunta mas ao contrário de rightN. -type: checkbox -options: - - [right1, wrong1] - - [right2, wrong2] - - [right3, wrong3] -correct: [1, 1.5, 1] - - -# randomly choose 1 right_option and choose more 2 from wrong_options. -type: radio -right_options: - - right1 - - right2 - - right3 -wrong_options: - - wrong1 - - wrong2 - - wrong3 - - wrong4 -choose: 3 -``` - - servir imagens/ficheiros. - session management. close after inactive time. - each topic only loads a sample of K questions (max) in random order. @@ -65,6 +30,7 @@ choose: 3 # FIXED +- radio: suporte para multiplas opcoes correctas e erradas, escolhendo-se uma selecção aleatoria destas (so com 1 certa). - checkbox: cada opção pode ser uma dupla (certo, errado) sendo escolhida uma aleatória. - async/threadpool no bcrypt do initdb. - numero de estrelas depende da proporcao entre certas e erradas. diff --git a/README.md b/README.md index 5f4ecfc..e01123c 100644 --- a/README.md +++ b/README.md @@ -132,7 +132,7 @@ Edit `rc.conf` pflog_flags="" pflog_logfile="/var/log/pflog" -Reboot. +Reboot or `sudo service pf start`. ## Troubleshooting diff --git a/demo/math/questions.yaml b/demo/math/questions.yaml index 4aa74bf..88bd0f9 100644 --- a/demo/math/questions.yaml +++ b/demo/math/questions.yaml @@ -1,36 +1,41 @@ -- ref: numbers - type: checkbox - title: Números pares e primos - text: Indique as afirmações verdadeiras. +# --------------------------------------------------------------------------- +- ref: distributive_property + type: radio + title: Propriedade distributiva + text: | + Qual das seguintes opções usa a propriedade distributiva para calcular $9\times 2 - 2\times 3$? options: - - ['3 é primo', '4 é primo'] - - ['2 é par', '3 é par'] - - ['1 é ímpar', '2 é ímpar'] - correct: [1,1,1] + # correct + - $2\times(9 - 3)$ + - $(9-3)\times 2$ + # wrong + - $18 - 6 = 12$ + - $2\times 9 - 2\times 3$ + - $2\times(9-2\times 3)$ + correct: [1,1,0,0,0] + choose: 3 -- - ref: prime_numbers - type: radio - title: Números primos - text: Qual dos seguintes números é primo? - options: - - 13 - - 12 - - 14 - - 1, a **unidade** +# - ref: numbers +# type: checkbox +# title: Números pares e primos +# text: Indique as afirmações verdadeiras. +# options: +# - ['3 é primo', '4 é primo'] +# - ['2 é par', '3 é par'] +# - ['1 é ímpar', '2 é ímpar'] +# correct: [1,1,1] -# # --------------------------------------------------------------------------- # - -# ref: distributive_property +# ref: prime_numbers # type: radio -# title: Propriedade distributiva -# text: | -# Qual das seguintes opções usa a propriedade distributiva para calcular $9\times 2 - 2\times 3$? +# title: Números primos +# text: Qual dos seguintes números é primo? # options: -# - $2\times(9 - 3)$ -# - $18 - 6 = 12$ -# - $2\times 9 - 2\times 3$ -# - $2\times(9-2\times 3)$ +# - 13 +# - 12 +# - 14 +# - 1, a **unidade** + # # --------------------------------------------------------------------------- # - diff --git a/questions.py b/questions.py index bf56800..464481e 100644 --- a/questions.py +++ b/questions.py @@ -61,16 +61,19 @@ class QuestionRadio(Question): type (str) text (str) options (list of strings) - shuffle (bool, default=True) correct (list of floats) discount (bool, default=True) answer (None or an actual answer) + shuffle (bool, default=True) + choose (int) # only used if shuffle=True ''' #------------------------------------------------------------------------ def __init__(self, q): super().__init__(q) + n = len(self['options']) + # set defaults if missing self.set_defaults({ 'text': '', @@ -79,23 +82,33 @@ class QuestionRadio(Question): 'discount': True, }) - n = len(self['options']) - # always convert to list, e.g. correct: 2 --> correct: [0,0,1,0,0] # correctness levels from 0.0 to 1.0 (no discount here!) if isinstance(self['correct'], int): self['correct'] = [1.0 if x==self['correct'] else 0.0 for x in range(n)] - elif len(self['correct']) != n: - logger.error(f'Number of options and correct mismatch in "{self["ref"]}", file "{self["filename"]}".') - - # generate random permutation, e.g. [2,1,4,0,3] - # and apply to `options` and `correct` if self['shuffle']: - perm = list(range(n)) - random.shuffle(perm) - self['options'] = [ str(self['options'][i]) for i in perm ] - self['correct'] = [ float(self['correct'][i]) for i in perm ] + # separate right from wrong options + right = [i for i in range(n) if self['correct'][i] == 1] + wrong = [i for i in range(n) if self['correct'][i] < 1] + + self.set_defaults({'choose': 1+len(wrong)}) + + # choose 1 correct option + r = random.choice(right) + options = [ self['options'][r] ] + correct = [ 1.0 ] + + # choose remaining wrong options + random.shuffle(wrong) + nwrong = self['choose']-1 + options.extend(self['options'][i] for i in wrong[:nwrong]) + correct.extend(self['correct'][i] for i in wrong[:nwrong]) + + # final shuffle of the options + perm = random.sample(range(self['choose']), self['choose']) + self['options'] = [ str(options[i]) for i in perm ] + self['correct'] = [ float(correct[i]) for i in perm ] #------------------------------------------------------------------------ # can return negative values for wrong answers -- libgit2 0.21.2