diff options
author | Timotej Lazar <timotej.lazar@araneo.org> | 2015-01-15 13:36:15 +0100 |
---|---|---|
committer | Aleš Smodiš <aless@guru.si> | 2015-08-11 14:26:01 +0200 |
commit | abbaf8c97c708e0e02476a6d6a85dfa18d631169 (patch) | |
tree | b0eb4b8e774ae522f325c0af2a9a8c8e61d91d62 /monkey | |
parent | 888ad29be0bfaaa9a361ec4cae3755b59b71dadb (diff) |
Rewrite monkey.action test code to use Django db
Diffstat (limited to 'monkey')
-rwxr-xr-x | monkey/action.py | 41 |
1 files changed, 13 insertions, 28 deletions
diff --git a/monkey/action.py b/monkey/action.py index 057ed0e..403c015 100755 --- a/monkey/action.py +++ b/monkey/action.py @@ -226,48 +226,33 @@ def compress(actions): # some sample code if __name__ == '__main__': - import sys - if len(sys.argv) < 2: - print('usage: ' + sys.argv[0] + ' <database>') - sys.exit(1) + import os + import django + os.environ['DJANGO_SETTINGS_MODULE'] = 'webmonkey.settings' + django.setup() - import sqlite3 - conn = sqlite3.connect(sys.argv[1]) - conn.text_factory = bytes - c = conn.cursor() + from tutor.models import Problem, Attempt # print all problem ids print('problems:') - c.execute('select * from problems') - for problem in c.fetchall(): - # problem = (id, name, description, details, solution, library) - # name: predicate name + arity (e.g. conc/2) - # desc: one-line problem description - # details: detailed problem description - # solution: official solution - # library: fact database for testing (e.g. for parent, brother, … relations) - print(' ' + str(problem[0]) + '\t' + str(problem[1], encoding='utf-8')) + for problem in Problem.objects.all(): + print(' {}\t{}'.format(problem.pk, problem.name)) print() pid = input('enter problem id: ') - c.execute('select id from attempts where problem=?', (pid,)) - attempts = list(c.fetchall()) + problem = Problem.objects.get(pk=pid) # print all attempt ids for the selected problem print('attempts for problem ' + str(pid) + ':') - print(', '.join([str(attempt[0]) for attempt in attempts])) + attempts = Attempt.objects.filter(problem=problem) + print(', '.join([str(attempt.pk) for attempt in attempts])) print() aid = input('enter attempt id: ') - c.execute('select * from attempts where id=?', (aid,)) - attempt = c.fetchone() - # attempt = (id, problem_id, user_id, log, content, done, session) - # log: action sequence log - # content: final version for this attempt - # done: did any version of the program pass all tests? - # session: irrelevant + attempt = Attempt.objects.get(pk=aid) + try: - actions = parse(attempt[3]) + actions = parse(attempt.trace) print('read ' + str(len(actions)) + ' actions from log') compress(actions) print('after compression: ' + str(len(actions)) + ' actions') |