summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/prolog_session.py22
-rw-r--r--server/python_session.py18
-rw-r--r--server/robot_session.py21
3 files changed, 54 insertions, 7 deletions
diff --git a/server/prolog_session.py b/server/prolog_session.py
index ac18400..6cf6651 100644
--- a/server/prolog_session.py
+++ b/server/prolog_session.py
@@ -121,17 +121,32 @@ class PrologSession(server.LanguageSession):
problem_module = load_problem(problem.language, problem.group, problem.identifier, 'common')
aux_code = self._aux_code(session.get_uid(), problem, program)
+ # experiment support for allowing none/automatic/manual/all hints
+ # descriptor: {'id': 'hints', 'group': 'none|automatic|manual|all'}
+ allowed_hints = 'all'
+ for experiment in session.get_experiments():
+ if experiment.get('id') == 'hints':
+ allowed_hints = experiment.get('group')
+ break
+
# check if the program is correct
n_correct, n_all, msgs = problem_module.test(program, aux_code=aux_code)
if n_correct == n_all:
session.update_solution(problem_id, solution=program, done=True)
else:
hints = []
+ # syntax check
if not hints and hasattr(language_module, 'check_syntax'):
hints = language_module.check_syntax(program, aux_code=aux_code)
- if not hints and hasattr(problem_module, 'hint'):
+
+ # manually defined problem-specific hints
+ if not hints and hasattr(problem_module, 'hint') and \
+ allowed_hints in ('all', 'manual'):
hints = problem_module.hint(program, aux_code=aux_code)
- if not hints and problem_id in _edits:
+
+ # 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)
@@ -140,8 +155,11 @@ class PrologSession(server.LanguageSession):
program, _edits[problem_id], tester, timeout=3)
if solution and steps:
hints = [{'id': 'monkey_main'}] + monkey.fix_hints(program, steps)
+
+ # generic language hints (style etc.)
if not hints and hasattr(language_module, 'hint'):
hints = language_module.hint(program, aux_code=aux_code)
+
if hints:
msgs.extend(hints)
diff --git a/server/python_session.py b/server/python_session.py
index 52a54de..ecb075a 100644
--- a/server/python_session.py
+++ b/server/python_session.py
@@ -102,21 +102,35 @@ class PythonSession(server.LanguageSession):
return []
def test(self, sid, problem_id, program):
+ session = server.user_session.get_session_by_id(sid)
p = Problem.get(id=problem_id)
+
language_module = server.problems.load_language(p.language, 'common')
problem_module = server.problems.load_problem(p.language, p.group, p.identifier, 'common')
+ # experiment support for allowing none/automatic/manual/all hints
+ # descriptor: {'id': 'hints', 'group': 'none|automatic|manual|all'}
+ allowed_hints = 'all'
+ for experiment in session.get_experiments():
+ if experiment.get('id') == 'hints':
+ allowed_hints = experiment.get('group')
+ break
+
# check if the program is correct
passed, msgs = problem_module.test(self.run, program)
if passed:
- session = server.user_session.get_session_by_id(sid)
session.update_solution(problem_id, solution=program, done=True)
else:
hints = []
+ # manually defined problem-specific hints
if not hints and hasattr(language_module, 'hint'):
hints = language_module.hint(self.run, program)
- if not hints and hasattr(problem_module, 'hint'):
+
+ # generic language hints (style etc.)
+ if not hints and hasattr(problem_module, 'hint') and \
+ allowed_hints in ('all', 'manual'):
hints = problem_module.hint(self.run, program)
+
if hints:
msgs.extend(hints)
diff --git a/server/robot_session.py b/server/robot_session.py
index 649159a..5477c72 100644
--- a/server/robot_session.py
+++ b/server/robot_session.py
@@ -40,15 +40,30 @@ class RobotSession(server.LanguageSession):
pass
def hint(self, sid, problem_id, program):
+ session = server.user_session.get_session_by_id(sid)
p = Problem.get(id=problem_id)
+
language_module = server.problems.load_language(p.language, 'common')
problem_module = server.problems.load_problem(p.language, p.group, p.identifier, 'common')
+ # experiment support for allowing none/automatic/manual/all hints
+ # descriptor: {'id': 'hints', 'group': 'none|automatic|manual|all'}
+ allowed_hints = 'all'
+ for experiment in session.get_experiments():
+ if experiment.get('id') == 'hints':
+ allowed_hints = experiment.get('group')
+ break
+
hints = []
- if hasattr(language_module, 'hint'):
- hints = language_module.hint(program)
- if not hints and hasattr(problem_module, 'hint'):
+ # manually defined problem-specific hints
+ if not hints and hasattr(problem_module, 'hint') and \
+ allowed_hints in ('all', 'manual'):
hints = problem_module.hint(program)
+
+ # generic language hints (style etc.)
+ if not hints and hasattr(language_module, 'hint'):
+ hints = language_module.hint(program)
+
if not hints:
hints = [{'id': 'no_hint'}]