Created
October 31, 2022 13:00
-
-
Save christianp/ed3c8a663186d3b9f72813b7efd68ae8 to your computer and use it in GitHub Desktop.
Get the order of questions shown in each attempt of a Numbas LTI attempt data dump
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
Get the order of questions shown in each attempt of a Numbas LTI attempt data dump. | |
Prints a CSV file, with a header row and a row for each attempt. | |
The first column is the ID of the attempt, and subsequent columns represent each of the questions, in the order they appear in the editor. The value in the column for a particular question gives the index at which that question appeared in that attempt. | |
""" | |
import sys | |
import csv | |
import json | |
import argparse | |
parser = argparse.ArgumentParser() | |
parser.add_argument('filename') | |
args = parser.parse_args() | |
with open(args.filename) as f: | |
data = json.load(f) | |
def summary(a): | |
pk = a['attempt'] | |
order = a['suspend_data']['questionSubsets'][0] | |
inverted_order = [order.index(n) for n in range(len(order))] | |
return [pk]+inverted_order | |
a = data['attempts'][0] | |
order = summary(a)[1:] | |
names = [a['suspend_data']['questions'][order[n]]['name'] for n in range(len(order))] | |
w = csv.writer(sys.stdout) | |
w.writerow(['Attempt ID']+names) | |
for a in data['attempts']: | |
w.writerow(summary(a)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment