コード例 #1
0
        public async Task <IActionResult> GetSubmissionPlagiarisms(GetSubmissionPlagiarismsParameters parameters)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var submission = await submissionsRepo.FindSubmissionByIdAsync(parameters.SubmissionId);

            if (submission == null || submission.ClientId != client.Id)
            {
                return(Json(ApiError.Create("Invalid submission id")));
            }

            var suspicionLevels = await GetSuspicionLevelsAsync(submission.TaskId);

            if (suspicionLevels == null)
            {
                return(Json(ApiError.Create("Not enough statistics for defining suspicion levels")));
            }

            var result = new GetSubmissionPlagiarismsResult
            {
                SubmissionInfo    = submission.GetSubmissionInfoForApi(),
                Plagiarisms       = await plagiarismDetector.GetPlagiarismsAsync(submission, suspicionLevels),
                TokensPositions   = plagiarismDetector.GetNeededTokensPositions(submission.ProgramText),
                SuspicionLevels   = suspicionLevels,
                AnalyzedCodeUnits = GetAnalyzedCodeUnits(submission),
            };

            return(Json(result));
        }
コード例 #2
0
ファイル: ApiController.cs プロジェクト: samstikhin/Ulearn
        public async Task <IActionResult> GetSubmissionPlagiarisms([FromQuery] GetSubmissionPlagiarismsParameters parameters)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var submission = await submissionsRepo.FindSubmissionByIdAsync(parameters.SubmissionId).ConfigureAwait(false);

            if (submission == null || submission.ClientId != client.Id)
            {
                return(NotFound(new ErrorResponse("Invalid submission id")));
            }

            var suspicionLevels = await GetSuspicionLevelsAsync(submission.TaskId).ConfigureAwait(false);

            var result = new GetSubmissionPlagiarismsResponse
            {
                SubmissionInfo    = submission.GetSubmissionInfoForApi(),
                Plagiarisms       = await plagiarismDetector.GetPlagiarismsAsync(submission, suspicionLevels, configuration.AntiPlagiarism.SubmissionInfluenceLimitInMonths).ConfigureAwait(false),
                TokensPositions   = plagiarismDetector.GetNeededTokensPositions(submission.ProgramText, submission.Language),
                SuspicionLevels   = suspicionLevels,
                AnalyzedCodeUnits = GetAnalyzedCodeUnits(submission),
            };

            return(Json(result));
        }