Beispiel #1
0
        public async Task <ActionResult> Details(string courseId, int submissionId)
        {
            var submission = userSolutionsRepo.FindSubmissionById(submissionId);

            if (!submission.CourseId.EqualsIgnoreCase(courseId))
            {
                return(HttpNotFound());
            }

            var antiPlagiarismsResult = await GetAuthorPlagiarismsAsync(submission);

            var mostSimilarSubmissionsHistogramData = await GetMostSimilarSubmissionsHistogramData(submission.SlideId, 100);

            //var mostSimilarSubmissionsHistogramData = GetMostSimilarSubmissionsHistogramDataMock(100);
            var suspicionLevelsResponse = await antiPlagiarismClient.GetSuspicionLevelsAsync(new GetSuspicionLevelsParameters { TaskId = submission.SlideId });

            var antiPlagiarismSubmissionInfos = antiPlagiarismsResult.ResearchedSubmissions.Select(s => s.SubmissionInfo);
            var plagiarismsSubmissionInfos    = antiPlagiarismsResult.ResearchedSubmissions
                                                .SelectMany(s => s.Plagiarisms).Select(p => p.SubmissionInfo);

            var submissionsIds = antiPlagiarismSubmissionInfos.Concat(plagiarismsSubmissionInfos)
                                 .Select(si => si.SubmissionId)
                                 .Distinct()
                                 .ToList();

            var submissions = userSolutionsRepo.FindSubmissionsByIds(submissionsIds)
                              .ToDictionary(s => s.Id);

            submissions[submissionId] = submission;

            var userIds = new HashSet <string>(antiPlagiarismsResult.ResearchedSubmissions.SelectMany(s => s.Plagiarisms).Select(s => s.SubmissionInfo.AuthorId.ToString()));

            userIds.Add(submission.UserId);
            /* Use special MockUserCanSeeAllGroups() instead of User because we want to show all users groups, not only available */
            var usersGroups         = groupsRepo.GetUsersGroupsNamesAsStrings(courseId, userIds, new MockUserCanSeeAllGroups(), actual: true, archived: false).ToDefaultDictionary();
            var usersArchivedGroups = groupsRepo.GetUsersGroupsNamesAsStrings(courseId, userIds, new MockUserCanSeeAllGroups(), actual: false, archived: true).ToDefaultDictionary();
            var isCourseOrSysAdmin  = User.HasAccessFor(courseId, CourseRole.CourseAdmin);

            var course  = courseManager.FindCourse(courseId);
            var slide   = course?.FindSlideById(submission.SlideId, true);
            var details = new AntiPlagiarismDetailsModel
            {
                Course                 = course,
                Slide                  = slide,
                SubmissionId           = submissionId,
                Submissions            = submissions,
                UsersGroups            = usersGroups,
                UsersArchivedGroups    = usersArchivedGroups,
                AntiPlagiarismResponse = antiPlagiarismsResult,
                MostSimilarSubmissionsHistogramData = mostSimilarSubmissionsHistogramData,
                CanEditSuspicionLevels    = isCourseOrSysAdmin,
                SuspicionLevels           = suspicionLevelsResponse.SuspicionLevels,
                MaxAuthorSubmissionWeight = antiPlagiarismsResult.ResearchedSubmissions.Select(s => s.Plagiarisms.Select(p => p.Weight).DefaultIfEmpty(0).Max()).Max()
            };

            return(View(details));
        }