Skip to content
Snippets Groups Projects
Commit 6aa1fd49 authored by Jan Maximilian Michal's avatar Jan Maximilian Michal
Browse files

Main functionality is now implemented

parent 1ecb8d82
No related branches found
No related tags found
No related merge requests found
...@@ -10,28 +10,28 @@ file_regex = re.compile( ...@@ -10,28 +10,28 @@ file_regex = re.compile(
r'(\d+)__(\d+)__(?P<data>results|qti|tst)_(?P<id>\d+).xml') r'(\d+)__(\d+)__(?P<data>results|qti|tst)_(?P<id>\d+).xml')
task_id_regex = re.compile(r'il_\d+_qst_(?P<task_id>\d+)') task_id_regex = re.compile(r'il_\d+_qst_(?P<task_id>\d+)')
tasks_path = ('./assessment/section/item/itemmetadata/qtimetadata/' tasks_path = ('./assessment/section')
'qtimetadatafield/fieldlabel[text()="QUESTIONTYPE"]'
'/../../../../..')
users = './tst_active/row' users = './tst_active/row'
solutions = './tst_solutions/row[@question_fi="%s"]' solutions = './tst_solutions/row[@question_fi="%s"]'
lecturer_xpath = './MetaData/Lifecycle/Contribute[@Role="Author"]/Entity/text()'
def eat_qti(tree): def eat_qti(tree, only_of_type=('assSourceCode',), **kwargs):
tasks = tree.xpath(tasks_path)[0] tasks = tree.xpath(tasks_path)[0]
titles = tasks.xpath('./item/@title') titles = tasks.xpath('./item/@title')
types = tasks.xpath( types = tasks.xpath(
'./item/itemmetadata/qtimetadata/qtimetadatafield/' './item/itemmetadata/qtimetadata/qtimetadatafield/'
'fieldlabel[text()="QUESTIONTYPE"]/../fieldentry/text()') 'fieldlabel[text()="QUESTIONTYPE"]/../fieldentry/text()')
ids = [re.search(task_id_regex, ident).group('task_id') ids = [re.search(task_id_regex, ident).group('task_id')
for ident in tasks.xpath('./item/@ident')] for ident in tasks.xpath('./item/@ident')]
texts = ['\n'.join(flow.xpath('./material/mattext/text()')) texts = ['\n'.join(flow.xpath('./material/mattext/text()'))
for flow in tasks.xpath('./item/presentation/flow')] for flow in tasks.xpath('./item/presentation/flow')]
return {id: {'title': title, 'text': text, 'type': type} return {id: {'title': title, 'text': text, 'type': type}
for id, type, title, text in zip(ids, types, titles, texts)} for id, type, title, text in zip(ids, types, titles, texts)
if not only_of_type or type in only_of_type}
def eat_users(results_tree): def eat_users(results_tree):
...@@ -44,7 +44,8 @@ def eat_solutions(results_tree, task_id): ...@@ -44,7 +44,8 @@ def eat_solutions(results_tree, task_id):
for row in results_tree.xpath(solutions % task_id)} for row in results_tree.xpath(solutions % task_id)}
def eat_results(tree, questions=("17639",)): def eat_results(tree, qti=(), **kwargs):
questions = qti
users = eat_users(tree) users = eat_users(tree)
for user in users.values(): for user in users.values():
user['submissions'] = {} user['submissions'] = {}
...@@ -57,18 +58,30 @@ def eat_results(tree, questions=("17639",)): ...@@ -57,18 +58,30 @@ def eat_results(tree, questions=("17639",)):
def eat_tst(tree): def eat_tst(tree):
title = tree.xpath('./MetaData/General/Title/text()') title = tree.xpath('./MetaData/General/Title/text()')
lecturer = tree.xpath( lecturer = tree.xpath(lecturer_xpath)
'./MetaData/Lifecycle/Contribute[@Role="Author"]/Entity/text()')
return {'exam': title[0], 'author': lecturer[0]} return {'exam': title[0], 'author': lecturer[0]}
def eval_file(archive, match, cache):
funcname = 'eat_' + match.group('data')
with archive.open(match.string) as datafile:
tree = etree.parse(datafile)
return globals()[funcname](tree, **cache)
def eat_archive(archive): def eat_archive(archive):
for match in filter(bool, (re.search(file_regex, name) files = {match.group('data'): match
for name in archive.NameToInfo)): for match in (re.search(file_regex, name)
funcname = 'eat_' + match.group('data') for name in archive.NameToInfo)
with archive.open(match.string) as datafile: if match}
tree = etree.parse(datafile)
yield match.group('data'), globals()[funcname](tree) order = ('tst', 'qti', 'results')
cache = {}
for key in order:
cache[key] = eval_file(archive, files[key], cache)
return cache
def add_meta(base, data): def add_meta(base, data):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment