summaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/prolog_session.py36
-rw-r--r--server/python_session.py12
-rw-r--r--server/robot_session.py12
3 files changed, 28 insertions, 32 deletions
diff --git a/server/prolog_session.py b/server/prolog_session.py
index 0faad5c..dfb7c28 100644
--- a/server/prolog_session.py
+++ b/server/prolog_session.py
@@ -93,12 +93,12 @@ class PrologSession(server.LanguageSession):
def hint(self, sid, problem_id, program):
session = server.user_session.get_session_by_id(sid)
- language, problem_group, problem = Problem.get_identifier(problem_id)
- language_module = problems.load_language(language, 'common')
- problem_module = problems.load_problem(language, problem_group, problem, 'common')
+ p = Problem.get(id=problem_id)
+ language_module = problems.load_language(p.language, 'common')
+ problem_module = problems.load_problem(p.language, p.group, p.identifier, 'common')
- solved_problems = [p for p in CodeqUser.solved_problems(session.get_uid(), language)
- if p != (problem_group, problem)]
+ solved_problems = [pp for pp in CodeqUser.solved_problems(session.get_uid(), p.language)
+ if pp != (p.group, p.identifier)]
hints = []
# check if the program is already correct
@@ -118,12 +118,12 @@ class PrologSession(server.LanguageSession):
def test(self, sid, problem_id, program):
session = server.user_session.get_session_by_id(sid)
- language, problem_group, problem = Problem.get_identifier(problem_id)
- language_module = problems.load_language(language, 'common')
- problem_module = problems.load_problem(language, problem_group, problem, 'common')
+ p = Problem.get(id=problem_id)
+ language_module = problems.load_language(p.language, 'common')
+ problem_module = problems.load_problem(p.language, p.group, p.identifier, 'common')
- solved_problems = [p for p in CodeqUser.solved_problems(session.get_uid(), language)
- if p != (problem_group, problem)]
+ solved_problems = [pp for pp in CodeqUser.solved_problems(session.get_uid(), p.language)
+ if pp != (p.group, p.identifier)]
try:
passed, hints = problem_module.test(program, solved_problems)
except AttributeError as ex:
@@ -147,13 +147,13 @@ class PrologSession(server.LanguageSession):
"""A "shorthand" method to start a Prolog session, load correct solutions of all user's solved
problems and the given program, and ask a query.
"""
- language, problem_group, problem = Problem.get_identifier(problem_id)
- problem_module = problems.load_problem(language, problem_group, problem, 'common')
+ p = Problem.get(id=problem_id)
+ problem_module = problems.load_problem(p.language, p.group, p.identifier, 'common')
- solved_problems = [p for p in CodeqUser.solved_problems(user_id, language)
- if p != (problem_group, problem)]
- other_solutions = problems.solutions_for_problems(language, solved_problems)
- problem_facts = problems.get_facts(language, problem_module) or ''
+ solved_problems = [pp for pp in CodeqUser.solved_problems(user_id, p.language)
+ if pp != (p.group, p.identifier)]
+ other_solutions = problems.solutions_for_problems(p.language, solved_problems)
+ problem_facts = problems.get_facts(p.language, problem_module) or ''
code = program + '\n' + other_solutions + '\n' + problem_facts
messages, status, have_more = self.run(code)
@@ -163,8 +163,4 @@ class PrologSession(server.LanguageSession):
self._problem_id = problem_id
return messages, status, have_more
- def get_problem_id(self):
- return self._problem_id
-
server.language_session_handlers['prolog'] = lambda user_session, problem_id, language_identifier, group_identifier, problem_identifier: PrologSession()
-
diff --git a/server/python_session.py b/server/python_session.py
index 39bd8f4..f7ec53f 100644
--- a/server/python_session.py
+++ b/server/python_session.py
@@ -83,9 +83,9 @@ class PythonSession(server.LanguageSession):
self.destroy()
def hint(self, sid, problem_id, program):
- language, problem_group, problem = Problem.get_identifier(problem_id)
- language_module = server.problems.load_language(language, 'common')
- problem_module = server.problems.load_problem(language, problem_group, problem, 'common')
+ 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')
hints = []
# check if the program is already correct
@@ -104,9 +104,9 @@ class PythonSession(server.LanguageSession):
return hints
def test(self, sid, problem_id, program):
- language, problem_group, problem = Problem.get_identifier(problem_id)
- language_module = server.problems.load_language(language, 'common')
- problem_module = server.problems.load_problem(language, problem_group, problem, 'common')
+ 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')
try:
passed, hints = problem_module.test(self.run, program)
diff --git a/server/robot_session.py b/server/robot_session.py
index b41e233..26da36e 100644
--- a/server/robot_session.py
+++ b/server/robot_session.py
@@ -25,9 +25,9 @@ class RobotSession(server.LanguageSession):
pass
def hint(self, sid, problem_id, program):
- language, problem_group, problem = Problem.get_identifier(problem_id)
- language_module = server.problems.load_language(language, 'common')
- problem_module = server.problems.load_problem(language, problem_group, problem, 'common')
+ 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')
hints = []
if hasattr(language_module, 'hint'):
@@ -41,9 +41,9 @@ class RobotSession(server.LanguageSession):
return hints
def test(self, sid, problem_id, program):
- language, problem_group, problem = Problem.get_identifier(problem_id)
- language_module = server.problems.load_language(language, 'common')
- problem_module = server.problems.load_problem(language, problem_group, problem, 'common')
+ 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')
try:
passed, hints = problem_module.test(program)