Commit c0b02a51 authored by Michael Völske's avatar Michael Völske

tools/exams: use yaml keys as variable names

parent 5abee276
......@@ -32,34 +32,41 @@ def exams():
'ATTENTION: use latin-1 encoding!', required=True)
def generate_variants(pool_yaml, output_dir, student_list_file):
""" Generate a variant-list-file, where each student in the
student-list-file gets a unique sample of problems, one from each pool defined in the pool_yaml
student-list-file gets a unique sample of problems, one from each pool
defined in the pool_yaml
:param pool_yaml: A yaml file that contains the pools and associated problem sets, i.e.:
:param pool_yaml: A yaml file that contains the pools and associated
problem sets, i.e.:
\b
pool1:
- 'exam-de-db-introduction-general-questions001-var001-5pts'
- ...
:param output_dir: Path to a directory where to put the generated student-list-file
:param output_dir: Path to a directory where to put the generated
student-list-file
:param student_list_file: An Example student-list-file may look like this:
\b
STUDENT_NAME\\tSTUDENT_EMAIL
Donald Duck\\tdonald@example.com
Mickey Mouse\\tmickey@example.com
"""
pools = yaml.load(open(pool_yaml, 'r', encoding='latin1'), Loader=yaml.Loader)
pools = yaml.load(open(pool_yaml, 'r', encoding='latin1'),
Loader=yaml.Loader)
dialect = csv.Sniffer().sniff(
next(open(student_list_file, encoding='latin1')))
items = list(csv.DictReader(open(student_list_file, encoding='latin1'),
dialect=dialect))
os.makedirs(output_dir, exist_ok=True)
with open('variant-list-file.csv', 'w', newline='', encoding='latin1') as of:
with open('variant-list-file.csv', 'w',
newline='', encoding='latin1') as of:
writer = csv.writer(of, delimiter='\t', dialect=dialect)
variable_string = ["VAR" + str(i) for i in range(1, len(pools.keys())+1)]
variable_string = list(pools.keys())
writer.writerow(['STUDENT_NAME', 'STUDENT_EMAIL'] + variable_string)
for env in tqdm(items, desc='generating variants'):
variant_string = [f'{choice(variants)}' for variants in pools.values()]
writer.writerow([env['STUDENT_NAME'], env['STUDENT_EMAIL']] + variant_string)
variant_string = [f'{choice(variants)}'
for variants in pools.values()]
writer.writerow([env['STUDENT_NAME'],
env['STUDENT_EMAIL']] + variant_string)
########################################################################
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment