diff options
author | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2015-11-18 13:20:00 +0100 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2015-12-11 16:11:15 +0100 |
commit | fa39fe7bfedd0b2e615d369adb5b510ceb9b857f (patch) | |
tree | abf381b007d1816247cab534ac8e2152695ad596 /server | |
parent | dd723bd01634fa5ffc85402ea10947e472b257af (diff) |
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.
Diffstat (limited to 'server')
-rw-r--r-- | server/prolog_session.py | 20 |
1 files changed, 20 insertions, 0 deletions
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 <http://www.gnu.org/licenses/>. import operator +import os.path +import pickle import threading +import monkey import prolog.engine import server import server.user_session @@ -127,6 +130,15 @@ class PrologSession(server.LanguageSession): 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: hints = [{'id': 'system_error', 'args': {'message': str(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 = {} |