diff --git a/api/controllers/problem/update_problem.py b/api/controllers/problem/update_problem.py index cd4a1a5..ea8468b 100644 --- a/api/controllers/problem/update_problem.py +++ b/api/controllers/problem/update_problem.py @@ -1,7 +1,7 @@ from api.utility import passwordEncryption from rest_framework.response import Response from rest_framework.decorators import api_view -from api.sandbox.grader import PythonGrader +from api.sandbox.grader import Grader from ...constant import GET,POST,PUT,DELETE from ...models import * from rest_framework import status @@ -27,7 +27,7 @@ def update_problem(problem:Problem,request): problem.updated_date = timezone.now() if 'testcases' in request.data: - running_result = PythonGrader(problem.solution,request.data['testcases'],1,1.5).generate_output() + running_result = Grader[request.data['language']](problem.solution,request.data['testcases'],1,1.5).generate_output() # if not running_result.runnable: # return Response({'detail': 'Error during editing. Your code may has an error/timeout!'},status=status.HTTP_406_NOT_ACCEPTABLE) @@ -53,7 +53,7 @@ def update_problem(problem:Problem,request): if 'solution' in request.data: testcases = Testcase.objects.filter(problem=problem,deprecated=False) program_input = [i.input for i in testcases] - running_result = PythonGrader(problem.solution,program_input,1,1.5).generate_output() + running_result = Grader[request.data['language']](problem.solution,program_input,1,1.5).generate_output() if not running_result.runnable: return Response({'detail': 'Error during editing. Your code may has an error/timeout!'},status=status.HTTP_406_NOT_ACCEPTABLE) diff --git a/api/difficulty_predictor/difficulty_predictor_667.sav b/api/difficulty_predictor/difficulty_predictor_667.sav new file mode 100644 index 0000000..764ed75 Binary files /dev/null and b/api/difficulty_predictor/difficulty_predictor_667.sav differ diff --git a/api/difficulty_predictor/predictor.py b/api/difficulty_predictor/predictor.py index 732ac9e..5a68bad 100644 --- a/api/difficulty_predictor/predictor.py +++ b/api/difficulty_predictor/predictor.py @@ -2,7 +2,7 @@ # Read sav -with open('./api/difficulty_predictor/difficulty_predictor.sav', 'rb') as f: +with open('./api/difficulty_predictor/difficulty_predictor_667.sav', 'rb') as f: difficulty = pickle.load(f) # Predict some model diff --git a/api/views/script.py b/api/views/script.py index e871e9e..b2b2741 100644 --- a/api/views/script.py +++ b/api/views/script.py @@ -66,10 +66,20 @@ # problem.save() # return Response({'message': 'Success!'},status=status.HTTP_201_CREATED) +# @api_view([POST]) +# def run_script(request): +# problems = Problem.objects.all() +# for problem in problems: +# update_problem_difficulty(problem) + +# return Response({'message': 'Success!'},status=status.HTTP_201_CREATED) + @api_view([POST]) def run_script(request): problems = Problem.objects.all() for problem in problems: - update_problem_difficulty(problem) + if problem.language == "py": + problem.language = "python" + problem.save() return Response({'message': 'Success!'},status=status.HTTP_201_CREATED)