diff options
author | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2017-02-27 11:51:28 +0100 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@fri.uni-lj.si> | 2017-02-27 11:51:28 +0100 |
commit | ecdc0b2a576cfddabc9b9763a32b28ae30fee3c0 (patch) | |
tree | f479c62949dd7851e66df5ee7f9211230b3cc5ad /server | |
parent | 488c40522f831d7ef84efdd07f895479b79391c1 (diff) |
Implement pattern-based hints (see AIED2017)
Diffstat (limited to 'server')
-rw-r--r-- | server/problems.py | 8 | ||||
-rw-r--r-- | server/prolog_session.py | 30 |
2 files changed, 16 insertions, 22 deletions
diff --git a/server/problems.py b/server/problems.py index 10dec0d..9cccc21 100644 --- a/server/problems.py +++ b/server/problems.py @@ -65,6 +65,14 @@ def load_problem(language, problem_group, problem, tail_module): def load_facts(language, fact_module): return load_module('{0}.facts.{1}'.format(language, fact_module)) +def load_file(language, group, problem, name): + path = os.path.join(_path_prefix, language, 'problems', group, problem, name) + try: + with open(path, 'r') as f: + return f.read() + except: + return None + def load_problems(language, tuples, tail_module): modules = [] for problem_group, problem in tuples: diff --git a/server/prolog_session.py b/server/prolog_session.py index 6cb1592..8c101c6 100644 --- a/server/prolog_session.py +++ b/server/prolog_session.py @@ -14,19 +14,19 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +import json import operator import os.path -import pickle import threading from db.models import CodeqUser, Problem from db.util import make_identifier -import monkey +import monkey.rules import prolog.engine from prolog.util import used_predicates import server import server.user_session -from server.problems import get_facts, load_language, load_problem, solutions_for_problems +from server.problems import get_facts, load_file, load_language, load_problem, solutions_for_problems __all__ = ['PrologSession'] @@ -145,16 +145,11 @@ class PrologSession(server.LanguageSession): hints = problem_module.hint(program, aux_code=aux_code) # automatic hints - if not hints and problem_id in _edits and \ - allowed_hints in ('all', 'automatic'): - # Testing function for monkey. - def tester(code): - n_correct, n_all, _ = problem_module.test(code, aux_code=aux_code) - return n_correct, n_all - solution, steps, fix_time, n_tested = monkey.fix( - program, _edits[problem_id], tester, timeout=3) - if solution and steps: - hints = [{'id': 'monkey_main'}] + monkey.fix_hints(program, steps) + if not hints and allowed_hints in ('all', 'automatic'): + bug_data = load_file(problem.language, problem.group, problem.identifier, 'bugs.json') + if bug_data is not None: + bugs = json.loads(bug_data) + hints = monkey.rules.suggest(bugs, program) # generic language hints (style etc.) if not hints and hasattr(language_module, 'hint'): @@ -205,12 +200,3 @@ 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() - -# Load edit data. -try: - _edits, _submissions, _queries = pickle.load( - open(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', 'edits.pickle'), 'rb')) -except: - _edits = {} - _submissions = {} - _queries = {} |