Beispiel #1
0
        public async Task <IActionResult> GetAuthorPlagiarisms([FromQuery] GetAuthorPlagiarismsParameters parameters)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var maxLastSubmissionsCount = configuration.Actions.GetAuthorPlagiarisms.MaxLastSubmissionsCount;

            if (parameters.LastSubmissionsCount <= 0 || parameters.LastSubmissionsCount > maxLastSubmissionsCount)
            {
                return(Json(ApiError.Create(
                                $"Invalid last_submissions_count. This value should be at least 1 and at most {maxLastSubmissionsCount}"
                                )));
            }

            var suspicionLevels = await GetSuspicionLevelsAsync(parameters.TaskId);

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

            var submissions = await submissionsRepo.GetSubmissionsByAuthorAndTaskAsync(client.Id, parameters.AuthorId, parameters.TaskId, parameters.LastSubmissionsCount);

            var result = new GetAuthorPlagiarismsResult
            {
                SuspicionLevels = suspicionLevels,
            };

            foreach (var submission in submissions)
            {
                using (var scope = serviceScopeFactory.CreateScope())
                {
                    /* Create internal plagiarismDetector for preventing memory leaks */
                    var internalPlagiarismDetector = scope.ServiceProvider.GetService <PlagiarismDetector>();

                    result.ResearchedSubmissions.Add(new ResearchedSubmission
                    {
                        SubmissionInfo    = submission.GetSubmissionInfoForApi(),
                        Plagiarisms       = await internalPlagiarismDetector.GetPlagiarismsAsync(submission, suspicionLevels),
                        TokensPositions   = internalPlagiarismDetector.GetNeededTokensPositions(submission.ProgramText),
                        AnalyzedCodeUnits = GetAnalyzedCodeUnits(submission),
                    });
                }
            }

            return(Json(result));
        }
Beispiel #2
0
 public Task <GetAuthorPlagiarismsResponse> GetAuthorPlagiarismsAsync(GetAuthorPlagiarismsParameters parameters)
 {
     return(MakeRequestAsync <GetAuthorPlagiarismsParameters, GetAuthorPlagiarismsResponse>(HttpMethod.Get, Urls.GetAuthorPlagiarisms, parameters));
 }
 public Task <GetAuthorPlagiarismsResult> GetAuthorPlagiarismsAsync(GetAuthorPlagiarismsParameters parameters)
 {
     return(MakeRequestAsync <GetAuthorPlagiarismsParameters, GetAuthorPlagiarismsResult>(Urls.GetAuthorPlagiarisms, parameters, HttpMethod.Get));
 }