From be1efae85b214151d0b1d749b17e9d3664ea3047 Mon Sep 17 00:00:00 2001 From: Miguel BarĂ£o Date: Sun, 8 Nov 2020 16:29:19 +0000 Subject: [PATCH] new feature: in the test yaml, choose several questions from a list instead of just one. --- perguntations/app.py | 10 ++++++---- perguntations/test.py | 49 ++++++++++++++++++++++++++----------------------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/perguntations/app.py b/perguntations/app.py index 9091f89..8d89f6e 100644 --- a/perguntations/app.py +++ b/perguntations/app.py @@ -114,9 +114,11 @@ class App(): logger.info('Students not yet allowed to login.') # pre-generate tests - logger.info('Generating tests for %d students...', len(self.allowed)) - self._pregenerate_tests(len(self.allowed)) - logger.info('Tests done.') + if self.allowed: + logger.info('Generating tests for %d students...', len(self.allowed)) + self._pregenerate_tests(len(self.allowed)) + else: + logger.info('No tests were generated.') # ------------------------------------------------------------------------ async def login(self, uid, try_pw): @@ -458,7 +460,7 @@ class App(): enrolled = set(s[0] for s in self._get_all_students()) # in database self.allowed.update(allowed_in_file & enrolled) - logger.info('Allowed %d students provided in %s.', len(self.allowed), + logger.info('Allowed %d students provided in "%s"', len(self.allowed), filename) not_enrolled = allowed_in_file - enrolled diff --git a/perguntations/test.py b/perguntations/test.py index 63c278c..9fd45b0 100644 --- a/perguntations/test.py +++ b/perguntations/test.py @@ -49,7 +49,7 @@ class TestFactory(dict): 'autosubmit': False, 'debug': False, 'show_ref': False, - # 'allow_students': None, + 'allow_students': [], }) self.update(conf) @@ -123,7 +123,8 @@ class TestFactory(dict): if qmissing: raise TestFactoryException(f'Could not find questions {qmissing}.') - + # if isinstance(allow_students, str): FIXME + # try to o # ------------------------------------------------------------------------ def check_test_ref(self): @@ -237,27 +238,29 @@ class TestFactory(dict): nerr = 0 # count errors during questions generation for qlist in self['questions']: - # choose one question variant - qref = random.choice(qlist['ref']) - - # generate instance of question - try: - question = await self.question_factory[qref].gen_async() - except QuestionException: - logger.error('Can\'t generate question "%s". Skipping.', qref) - nerr += 1 - continue - - # some defaults - if question['type'] in ('information', 'success', 'warning', - 'alert'): - question['points'] = qlist.get('points', 0.0) - else: - question['points'] = qlist.get('points', 1.0) - question['number'] = qnum # counter for non informative panels - qnum += 1 - - questions.append(question) + # choose list of question variants + choose = qlist.get('choose', 1) + qrefs = random.sample(qlist['ref'], k=choose) + + for qref in qrefs: + # generate instance of question + try: + question = await self.question_factory[qref].gen_async() + except QuestionException: + logger.error('Can\'t generate question "%s". Skipping.', qref) + nerr += 1 + continue + + # some defaults + if question['type'] in ('information', 'success', 'warning', + 'alert'): + question['points'] = qlist.get('points', 0.0) + else: + question['points'] = qlist.get('points', 1.0) + question['number'] = qnum # counter for non informative panels + qnum += 1 + + questions.append(question) # setup scale total_points = sum(q['points'] for q in questions) -- libgit2 0.21.2