<commit_before># coding=utf-8
import pymongo
from bson.objectid import ObjectId

from django.shortcuts import render

from rest_framework.views import APIView

from django.conf import settings

from judge.judger.result import result
from judge.controller.tasks import judge
from account.decorators import login_required
from problem.models import Problem
from utils.shortcuts import serializer_invalid_response, error_response, success_response
from .serializers import  CreateSubmissionSerializer


class SubmissionnAPIView(APIView):
    def _create_mondodb_connection(self):
        mongodb_setting = settings.DATABASES["mongodb"]
        connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["PORT"])
        return connection["oj"]["oj_submission"]

    # @login_required
    def post(self, request):
        """
        提交代码
        ---
        request_serializer: CreateSubmissionSerializer
        """
        serializer = CreateSubmissionSerializer(data=request.data)
        if serializer.is_valid():
            data = serializer.data
            data["user_id"] = request.user.id
            data["result"] = result["waiting"]
            try:
                problem = Problem.objects.get(id=data["problem_id"])
            except Problem.DoesNotExist:
                return error_response(u"题目不存在")
            mongodb_setting = settings.DATABASES["mongodb"]
            connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["PORT"])
            collection = connection["oj"]["oj_submission"]
            submission_id = str(collection.insert_one(data).inserted_id)
            judge.deply(submission_id, problem.max_cpu_time, problem_)
            return success_response({"submission_id": submission_id})<commit_msg>fix typo<commit_after># coding=utf-8
import pymongo
from bson.objectid import ObjectId

from django.shortcuts import render

from rest_framework.views import APIView

from django.conf import settings

from judge.judger.result import result
from judge.controller.tasks import judge
from account.decorators import login_required
from problem.models import Problem
from utils.shortcuts import serializer_invalid_response, error_response, success_response
from .serializers import  CreateSubmissionSerializer


class SubmissionnAPIView(APIView):
    def _create_mondodb_connection(self):
        mongodb_setting = settings.DATABASES["mongodb"]
        connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["PORT"])
        return connection["oj"]["oj_submission"]

    # @login_required
    def post(self, request):
        """
        提交代码
        ---
        request_serializer: CreateSubmissionSerializer
        """
        serializer = CreateSubmissionSerializer(data=request.data)
        if serializer.is_valid():
            data = serializer.data
            data["user_id"] = request.user.id
            data["result"] = result["waiting"]
            try:
                problem = Problem.objects.get(id=data["problem_id"])
            except Problem.DoesNotExist:
                return error_response(u"题目不存在")
            mongodb_setting = settings.DATABASES["mongodb"]
            connection = pymongo.MongoClient(host=mongodb_setting["HOST"], port=mongodb_setting["PORT"])
            collection = connection["oj"]["oj_submission"]
            submission_id = str(collection.insert_one(data).inserted_id)
            judge.delay(submission_id, problem.max_cpu_time, problem.max_memory, problem.test_case_id)
            return success_response({"submission_id": submission_id})
{'fraction_non_alphanumeric': 0.09221822209914152, 'fraction_numerical': 0.0005538631957906397, 'mean_word_length': 3.4210526315789473, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1636417', 'n_tokens_mistral': 1004, 'n_tokens_neox': 985, 'n_words': 193}