Commit be1efae85b214151d0b1d749b17e9d3664ea3047
1 parent
24244d74
Exists in
master
and in
1 other branch
new feature: in the test yaml, choose several questions from a list
instead of just one.
Showing
2 changed files
with
32 additions
and
27 deletions
Show diff stats
perguntations/app.py
| @@ -114,9 +114,11 @@ class App(): | @@ -114,9 +114,11 @@ class App(): | ||
| 114 | logger.info('Students not yet allowed to login.') | 114 | logger.info('Students not yet allowed to login.') |
| 115 | 115 | ||
| 116 | # pre-generate tests | 116 | # pre-generate tests |
| 117 | - logger.info('Generating tests for %d students...', len(self.allowed)) | ||
| 118 | - self._pregenerate_tests(len(self.allowed)) | ||
| 119 | - logger.info('Tests done.') | 117 | + if self.allowed: |
| 118 | + logger.info('Generating tests for %d students...', len(self.allowed)) | ||
| 119 | + self._pregenerate_tests(len(self.allowed)) | ||
| 120 | + else: | ||
| 121 | + logger.info('No tests were generated.') | ||
| 120 | 122 | ||
| 121 | # ------------------------------------------------------------------------ | 123 | # ------------------------------------------------------------------------ |
| 122 | async def login(self, uid, try_pw): | 124 | async def login(self, uid, try_pw): |
| @@ -458,7 +460,7 @@ class App(): | @@ -458,7 +460,7 @@ class App(): | ||
| 458 | 460 | ||
| 459 | enrolled = set(s[0] for s in self._get_all_students()) # in database | 461 | enrolled = set(s[0] for s in self._get_all_students()) # in database |
| 460 | self.allowed.update(allowed_in_file & enrolled) | 462 | self.allowed.update(allowed_in_file & enrolled) |
| 461 | - logger.info('Allowed %d students provided in %s.', len(self.allowed), | 463 | + logger.info('Allowed %d students provided in "%s"', len(self.allowed), |
| 462 | filename) | 464 | filename) |
| 463 | 465 | ||
| 464 | not_enrolled = allowed_in_file - enrolled | 466 | not_enrolled = allowed_in_file - enrolled |
perguntations/test.py
| @@ -49,7 +49,7 @@ class TestFactory(dict): | @@ -49,7 +49,7 @@ class TestFactory(dict): | ||
| 49 | 'autosubmit': False, | 49 | 'autosubmit': False, |
| 50 | 'debug': False, | 50 | 'debug': False, |
| 51 | 'show_ref': False, | 51 | 'show_ref': False, |
| 52 | - # 'allow_students': None, | 52 | + 'allow_students': [], |
| 53 | }) | 53 | }) |
| 54 | self.update(conf) | 54 | self.update(conf) |
| 55 | 55 | ||
| @@ -123,7 +123,8 @@ class TestFactory(dict): | @@ -123,7 +123,8 @@ class TestFactory(dict): | ||
| 123 | if qmissing: | 123 | if qmissing: |
| 124 | raise TestFactoryException(f'Could not find questions {qmissing}.') | 124 | raise TestFactoryException(f'Could not find questions {qmissing}.') |
| 125 | 125 | ||
| 126 | - | 126 | + # if isinstance(allow_students, str): FIXME |
| 127 | + # try to o | ||
| 127 | 128 | ||
| 128 | # ------------------------------------------------------------------------ | 129 | # ------------------------------------------------------------------------ |
| 129 | def check_test_ref(self): | 130 | def check_test_ref(self): |
| @@ -237,27 +238,29 @@ class TestFactory(dict): | @@ -237,27 +238,29 @@ class TestFactory(dict): | ||
| 237 | nerr = 0 # count errors during questions generation | 238 | nerr = 0 # count errors during questions generation |
| 238 | 239 | ||
| 239 | for qlist in self['questions']: | 240 | for qlist in self['questions']: |
| 240 | - # choose one question variant | ||
| 241 | - qref = random.choice(qlist['ref']) | ||
| 242 | - | ||
| 243 | - # generate instance of question | ||
| 244 | - try: | ||
| 245 | - question = await self.question_factory[qref].gen_async() | ||
| 246 | - except QuestionException: | ||
| 247 | - logger.error('Can\'t generate question "%s". Skipping.', qref) | ||
| 248 | - nerr += 1 | ||
| 249 | - continue | ||
| 250 | - | ||
| 251 | - # some defaults | ||
| 252 | - if question['type'] in ('information', 'success', 'warning', | ||
| 253 | - 'alert'): | ||
| 254 | - question['points'] = qlist.get('points', 0.0) | ||
| 255 | - else: | ||
| 256 | - question['points'] = qlist.get('points', 1.0) | ||
| 257 | - question['number'] = qnum # counter for non informative panels | ||
| 258 | - qnum += 1 | ||
| 259 | - | ||
| 260 | - questions.append(question) | 241 | + # choose list of question variants |
| 242 | + choose = qlist.get('choose', 1) | ||
| 243 | + qrefs = random.sample(qlist['ref'], k=choose) | ||
| 244 | + | ||
| 245 | + for qref in qrefs: | ||
| 246 | + # generate instance of question | ||
| 247 | + try: | ||
| 248 | + question = await self.question_factory[qref].gen_async() | ||
| 249 | + except QuestionException: | ||
| 250 | + logger.error('Can\'t generate question "%s". Skipping.', qref) | ||
| 251 | + nerr += 1 | ||
| 252 | + continue | ||
| 253 | + | ||
| 254 | + # some defaults | ||
| 255 | + if question['type'] in ('information', 'success', 'warning', | ||
| 256 | + 'alert'): | ||
| 257 | + question['points'] = qlist.get('points', 0.0) | ||
| 258 | + else: | ||
| 259 | + question['points'] = qlist.get('points', 1.0) | ||
| 260 | + question['number'] = qnum # counter for non informative panels | ||
| 261 | + qnum += 1 | ||
| 262 | + | ||
| 263 | + questions.append(question) | ||
| 261 | 264 | ||
| 262 | # setup scale | 265 | # setup scale |
| 263 | total_points = sum(q['points'] for q in questions) | 266 | total_points = sum(q['points'] for q in questions) |