diff --git a/Backend/settings.py b/Backend/settings.py index 2cd2d18..b3e33c6 100644 --- a/Backend/settings.py +++ b/Backend/settings.py @@ -49,6 +49,7 @@ "http://192.168.0.5:3000", "http://192.168.0.11:5173", "http://192.168.68.194:5173", + "https://grader.kanonkc.com", FRONEND_URL ] diff --git a/api/controllers/problem/import_elabsheet_problem.py b/api/controllers/problem/import_elabsheet_problem.py new file mode 100644 index 0000000..023f16a --- /dev/null +++ b/api/controllers/problem/import_elabsheet_problem.py @@ -0,0 +1,19 @@ +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 ...constant import GET,POST,PUT,DELETE +from ...models import * +from rest_framework import status +from django.forms.models import model_to_dict +from ...serializers import * + +def import_elabsheet_problem(request, problem: Problem): + print("importing elabsheet problem") + print(request.data) + # Get file + file = request.data.get('file') + problem.pdf_url = file + print(file) + print(problem.pdf_url) + return Response(status=status.HTTP_204_NO_CONTENT) \ No newline at end of file diff --git a/api/controllers/submission/submit_problem.py b/api/controllers/submission/submit_problem.py index 4cd8158..51013df 100644 --- a/api/controllers/submission/submit_problem.py +++ b/api/controllers/submission/submit_problem.py @@ -105,4 +105,8 @@ def submit_problem_function(account_id:str,problem_id:str,topic_id:str,request): return Response(testser.data,status=status.HTTP_201_CREATED) def submit_problem(account_id:str,problem_id:str,request): - return submit_problem_function(account_id,problem_id,None,request) \ No newline at end of file + try: + return submit_problem_function(account_id,problem_id,None,request) + except Exception as e: + print(e) + return Response(status=status.HTTP_500_INTERNAL_SERVER_ERROR) \ No newline at end of file diff --git a/api/difficulty_predictor/predictor.py b/api/difficulty_predictor/predictor.py index c1ff3b8..5abb256 100644 --- a/api/difficulty_predictor/predictor.py +++ b/api/difficulty_predictor/predictor.py @@ -13,4 +13,4 @@ def predict(avg_first_passed_total_attempts,avg_first_passed_time_used): if not difficulty: return 0 - return int(difficulty.predict([[avg_first_passed_total_attempts,avg_first_passed_time_used]])[0]) \ No newline at end of file + return 0 # int(difficulty.predict([[avg_first_passed_total_attempts,avg_first_passed_time_used]])[0]) \ No newline at end of file diff --git a/api/difficulty_predictor/preprocess.py b/api/difficulty_predictor/preprocess.py index 7527775..290ddd6 100644 --- a/api/difficulty_predictor/preprocess.py +++ b/api/difficulty_predictor/preprocess.py @@ -7,65 +7,66 @@ def modelgrader_preprocessor(submission_df): - if not success: - return [-1,-1] + # if not success: + # return [-1,-1] - submission_df = submission_df[['account_id', 'problem_id','is_passed','language','date','submission_code','passed_ratio']] + # submission_df = submission_df[['account_id', 'problem_id','is_passed','language','date','submission_code','passed_ratio']] - # Change submission_code to string - submission_df['submission_code'] = submission_df['submission_code'].astype(str) + # # Change submission_code to string + # submission_df['submission_code'] = submission_df['submission_code'].astype(str) - # Sort by account_id, problem_id and date - submission_df.sort_values(['account_id','problem_id','date']) + # # Sort by account_id, problem_id and date + # submission_df.sort_values(['account_id','problem_id','date']) - # Calculate the difference time between the current submission and the previous submission - submission_df['date'] = pd.to_datetime(submission_df['date']) - submission_df['diff_time'] = submission_df.groupby(['account_id','problem_id'])['date'].diff() - submission_df['diff_time'] = submission_df['diff_time'].dt.total_seconds() + # # Calculate the difference time between the current submission and the previous submission + # submission_df['date'] = pd.to_datetime(submission_df['date']) + # submission_df['diff_time'] = submission_df.groupby(['account_id','problem_id'])['date'].diff() + # submission_df['diff_time'] = submission_df['diff_time'].dt.total_seconds() - # Set all diff_time which is NaN to 0 - submission_df['diff_time'].fillna(0, inplace=True) + # # Set all diff_time which is NaN to 0 + # submission_df['diff_time'].fillna(0, inplace=True) - # Set all diff_time which has more than 3 hours to 3 - submission_df.loc[submission_df['diff_time'] > 10800, 'diff_time'] = 10801 + # # Set all diff_time which has more than 3 hours to 3 + # submission_df.loc[submission_df['diff_time'] > 10800, 'diff_time'] = 10801 - # Loop each row - current_problem_id = None - current_account_id = None - already_passed = False - previous_diff_time = -1 + # # Loop each row + # current_problem_id = None + # current_account_id = None + # already_passed = False + # previous_diff_time = -1 - for index, row in submission_df.iterrows(): - if not current_problem_id and not current_account_id: - current_problem_id = row['problem_id'] - current_account_id = row['account_id'] + # for index, row in submission_df.iterrows(): + # if not current_problem_id and not current_account_id: + # current_problem_id = row['problem_id'] + # current_account_id = row['account_id'] - if current_problem_id != row['problem_id'] or current_account_id != row['account_id']: - current_problem_id = row['problem_id'] - current_account_id = row['account_id'] - already_passed = False - elif already_passed: - # row['diff_time'] = 0 - submission_df.drop(index, inplace=True) - elif row['is_passed'] == 1: - already_passed = True - if row['diff_time'] > 10800: - row['diff_time'] = previous_diff_time + # if current_problem_id != row['problem_id'] or current_account_id != row['account_id']: + # current_problem_id = row['problem_id'] + # current_account_id = row['account_id'] + # already_passed = False + # elif already_passed: + # # row['diff_time'] = 0 + # submission_df.drop(index, inplace=True) + # elif row['is_passed'] == 1: + # already_passed = True + # if row['diff_time'] > 10800: + # row['diff_time'] = previous_diff_time - grouped_submission_df = submission_df.groupby(['account_id','problem_id']).agg({'is_passed':'sum','date':'count','diff_time':'sum'}).reset_index() + # grouped_submission_df = submission_df.groupby(['account_id','problem_id']).agg({'is_passed':'sum','date':'count','diff_time':'sum'}).reset_index() - # Rename columns - grouped_submission_df.rename(columns={'date':'first_passed_total_attempts','is_passed':'passed_submission','diff_time':'first_passed_time_used'}, inplace=True) + # # Rename columns + # grouped_submission_df.rename(columns={'date':'first_passed_total_attempts','is_passed':'passed_submission','diff_time':'first_passed_time_used'}, inplace=True) - grouped_submission_df = grouped_submission_df.groupby(['problem_id']).agg({'passed_submission':'sum','first_passed_total_attempts':'sum','first_passed_time_used':'mean'}).reset_index() + # grouped_submission_df = grouped_submission_df.groupby(['problem_id']).agg({'passed_submission':'sum','first_passed_total_attempts':'sum','first_passed_time_used':'mean'}).reset_index() - # grouped_submission_df['first_pf_ratio'] = grouped_submission_df['passed_submission'] / grouped_submission_df['first_passed_total_attempts'] - df = grouped_submission_df.drop(['passed_submission'], axis=1) + # # grouped_submission_df['first_pf_ratio'] = grouped_submission_df['passed_submission'] / grouped_submission_df['first_passed_total_attempts'] + # df = grouped_submission_df.drop(['passed_submission'], axis=1) - df.rename(columns={'first_passed_total_attempts':'avg_first_passed_total_attempts','first_passed_time_used':'avg_first_passed_time_used'}, inplace=True) + # df.rename(columns={'first_passed_total_attempts':'avg_first_passed_total_attempts','first_passed_time_used':'avg_first_passed_time_used'}, inplace=True) - # Change problem_id to index - df.set_index('problem_id', inplace=True) + # # Change problem_id to index + # df.set_index('problem_id', inplace=True) - return [df['avg_first_passed_total_attempts'][0],df['avg_first_passed_time_used'][0]] \ No newline at end of file + # return [df['avg_first_passed_total_attempts'][0],df['avg_first_passed_time_used'][0]] + return [0,0] \ No newline at end of file diff --git a/api/sandbox/grader.py b/api/sandbox/grader.py index 7ba0752..a7a8154 100644 --- a/api/sandbox/grader.py +++ b/api/sandbox/grader.py @@ -161,7 +161,7 @@ def runtime(self) -> list[RuntimeResult]: 'r' ),stderr=subprocess.DEVNULL,timeout=float(self.timeout)) result.append(RuntimeResult(self.testcases[i],runner.decode(),"OK")) - except subprocess.CalledProcessError: + except subprocess.CalledProcessError as e: result.append(RuntimeResult(self.testcases[i],None,"ERROR")) except subprocess.TimeoutExpired: result.append(RuntimeResult(self.testcases[i],None,"TIMEOUT")) diff --git a/api/urls.py b/api/urls.py index 2db7b61..0a3e6c9 100644 --- a/api/urls.py +++ b/api/urls.py @@ -33,6 +33,7 @@ path('problems',problem.all_problems_view), path('problems/validate',problem.validation_view), path('problems/',problem.one_problem_view), + path('problems//import/pdf',problem.import_pdf_view), path("problems//accounts//submissions",submission.account_problem_submission_view), path('topics//problems//accounts/',problem.problem_in_topic_account_view), diff --git a/api/utility.py b/api/utility.py index 0c11760..eed082e 100644 --- a/api/utility.py +++ b/api/utility.py @@ -12,6 +12,9 @@ def formParser(querydict): def uploadTopic(instance,filename): return f"topics/{filename}" +def uploadProblemImportPDF(instance,filename): + return f"import-pdfs/{filename}" + def regexMatching(regex:str,code:str)->bool: code = ";".join([i.strip() for i in code.split("\n") if i != ""]) return re.search(regex, code) \ No newline at end of file diff --git a/api/views/problem.py b/api/views/problem.py index 6b8ad47..e34e781 100644 --- a/api/views/problem.py +++ b/api/views/problem.py @@ -20,6 +20,7 @@ from ..controllers.problem.get_problem_in_topic_with_best_submission import * from ..controllers.problem.update_group_permission_to_problem import * from ..controllers.problem.get_problem_public import * +from ..controllers.problem.import_elabsheet_problem import * # Create your views here. @@ -76,4 +77,15 @@ def problem_in_topic_account_view(request,account_id:str,topic_id:str,problem_id def problem_group_view(request,account_id:int,problem_id:int): problem = Problem.objects.get(problem_id=problem_id) if request.method == PUT: - return update_group_permission_to_problem(problem,request) \ No newline at end of file + return update_group_permission_to_problem(problem,request) + +# @api_view([POST]) +# def import_elabsheet_problem_view(request): +# if request.method == POST: +# print(request) + +@api_view([PUT]) +def import_pdf_view(request,problem_id:int): + problem = Problem.objects.get(problem_id=problem_id) + if request.method == PUT: + return import_elabsheet_problem(request, problem) \ No newline at end of file diff --git a/api/views/submission.py b/api/views/submission.py index 1ede8e0..25756d2 100644 --- a/api/views/submission.py +++ b/api/views/submission.py @@ -22,7 +22,11 @@ @api_view([POST,GET]) def account_problem_submission_view(request,problem_id,account_id): if request.method == POST: - return submit_problem(account_id,problem_id,request) + try: + return submit_problem(account_id,problem_id,request) + except Exception as e: + print(e) + return Response({"error":str(e)},status=status.HTTP_400_BAD_REQUEST) if request.method == GET: return get_submissions_by_account_problem(account_id,problem_id)