From ca8dcfdf819dae2aed6c864a3a11f1e30c632e96 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Thu, 15 Oct 2015 15:47:47 +0200 Subject: Store identifiers instead of IDs in Problem model --- monkey/edits.py | 4 ++-- monkey/test.py | 25 ++++++++++++------------- 2 files changed, 14 insertions(+), 15 deletions(-) (limited to 'monkey') diff --git a/monkey/edits.py b/monkey/edits.py index 8412f8a..5d07bfd 100644 --- a/monkey/edits.py +++ b/monkey/edits.py @@ -257,10 +257,10 @@ if __name__ == '__main__': solutions = Solution.filter(problem_id=pid, done=True) traces = [s.trace for s in solutions if s.codeq_user_id not in ignored_users] if not traces: - print('No traces for {}'.format(problem.name)) + print('No traces for {}'.format(problem.identifier)) continue - print('Analyzing traces for {}… '.format(problem.name), end='', flush=True) + print('Analyzing traces for {}… '.format(problem.identifier), end='', flush=True) try: edits[pid], submissions[pid], queries[pid], names[pid] = get_edits_from_traces(traces) print('{} edits, {} submissions, {} queries, {} names'.format( diff --git a/monkey/test.py b/monkey/test.py index 9936cdc..03f3571 100755 --- a/monkey/test.py +++ b/monkey/test.py @@ -18,30 +18,29 @@ from .util import indent if len(sys.argv) < 2: print('usage: ' + sys.argv[0] + ' ') sys.exit(1) -pid = int(sys.argv[1]) -language, problem_group, problem = Problem.get_identifier(pid) +problem = Problem.get(id=sys.argv[1]) -solved_problems = [p for p in CodeqUser.solved_problems(1, language) - if p != (problem_group, problem)] -other_solutions = server.problems.solutions_for_problems(language, solved_problems) -problem_module = server.problems.load_problem(language, problem_group, problem, 'common') -name = server.problems.load_problem(language, problem_group, problem, 'en').name +solved_problems = [p for p in CodeqUser.solved_problems(1, problem.language) + if p != (problem.group, problem.identifier)] +other_solutions = server.problems.solutions_for_problems(problem.language, solved_problems) +problem_module = server.problems.load_problem(problem.language, problem.group, problem.identifier, 'common') +name = server.problems.load_problem(problem.language, problem.group, problem.identifier, 'en').name # Testing function. def test(code): correct, hints = problem_module.test(code, solved_problems) return correct -traces = [s.trace for s in Solution.filter(problem_id=pid)] +traces = [s.trace for s in Solution.filter(problem_id=problem.id)] # Load hint database stored in edits.pickle. edits, submissions, queries, names = pickle.load(open('edits.pickle', 'rb')) -edits, submissions, queries, names = edits[pid], submissions[pid], queries[pid], names[pid] +edits, submissions, queries, names = edits[problem.id], submissions[problem.id], queries[problem.id], names[problem.id] # Load current status (programs for which a hint was found). try: - done = pickle.load(open('status-'+str(problem.pk)+'.pickle', 'rb')) + done = pickle.load(open('status-'+str(problem.id)+'.pickle', 'rb')) except: done = [] @@ -106,7 +105,7 @@ elif sys.argv[2] == 'test': print_hint(program, solution, steps, fix_time, n_tested) print() - pickle.dump(done, open('status-'+str(problem.pk)+'.pickle', 'wb')) + pickle.dump(done, open('status-'+str(problem.id)+'.pickle', 'wb')) print('Found hints for ' + str(len(done)) + ' of ' + str(len(incorrect)) + ' incorrect programs') @@ -115,7 +114,7 @@ elif sys.argv[2] == 'info': # With no additional arguments, print some stats. if len(sys.argv) == 3: print('Problem {} ({}): {} edits and {} unique submissions in {} traces'.format( - pid, colored(name, 'yellow'), + problem.id, colored(name, 'yellow'), colored(str(len(edits)), 'yellow'), colored(str(len(submissions)), 'yellow'), colored(str(len(traces)), 'yellow'))) @@ -146,7 +145,7 @@ elif sys.argv[2] == 'info': # Print the edit graph in graphviz dot syntax. elif sys.argv[2] == 'graph' and len(sys.argv) == 4: uid = int(sys.argv[3]) - solution = Solution.get(problem_id=pid, codeq_user_id=uid) + solution = Solution.get(problem_id=problem.id, codeq_user_id=uid) nodes, submissions, queries = trace_graph(solution.trace) -- cgit v1.2.1