From fa39fe7bfedd0b2e615d369adb5b510ceb9b857f Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Wed, 18 Nov 2015 13:20:00 +0100 Subject: Use a more general method for extracting edits This is a large overhaul of monkey code. Before, only edits within individual lines were tracked, which required a Prolog-specific method for splitting a program into a list of lines for every rule. In this version, modifications can be tracked within arbitrary code ranges. Ranges to be tracked are determined by selecting "interesting" subtrees in the AST of the starting code version. The new method is simpler, less language-dependent and easier to extend. The downside is that a program must be syntactically correct before we can attempt to fix it (the previous approach could handle programs with syntax errors in some cases). This commit also integrates a call to monkey.fix in prolog_session.hint, by running it if no other hint is found. --- server/prolog_session.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'server') diff --git a/server/prolog_session.py b/server/prolog_session.py index 7e0af90..1a76130 100644 --- a/server/prolog_session.py +++ b/server/prolog_session.py @@ -15,8 +15,11 @@ # along with this program. If not, see . import operator +import os.path +import pickle import threading +import monkey import prolog.engine import server import server.user_session @@ -126,6 +129,15 @@ class PrologSession(server.LanguageSession): hints = language_module.hint(program, solved_problems) if not hints and hasattr(problem_module, 'hint'): hints = problem_module.hint(program, solved_problems) + if not hints: + # Testing function for monkey. + def tester(code): + passed, hints = problem_module.test(code, solved_problems) + return passed + solution, steps, fix_time, n_tested = monkey.fix( + program, _edits[problem_id], tester, timeout=5, debug=True) + if solution and steps: + hints = [{'id': 'monkey_main'}] + monkey.fix_hints(program, steps) if not hints: hints = [{'id': 'no_hint'}] except Exception as ex: @@ -186,3 +198,11 @@ class PrologSession(server.LanguageSession): return messages, status, have_more server.language_session_handlers['prolog'] = lambda user_session, problem_id, language_identifier, group_identifier, problem_identifier: PrologSession() + +try: + _edits, _submissions, _queries = pickle.load( + open(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'edits.pickle'), 'rb')) +except: + _edits = {} + _submissions = {} + _queries = {} -- cgit v1.2.1