public static CompilerType[] GetCompatibleCompilerTypes(this PlagiarismDetectorType plagiarismDetectorType) { switch (plagiarismDetectorType) { case PlagiarismDetectorType.CSharpCompileDisassemble: return(new[] { CompilerType.CSharp }); case PlagiarismDetectorType.JavaCompileDisassemble: return(new[] { CompilerType.Java }); case PlagiarismDetectorType.PlainText: return(new[] { CompilerType.None, CompilerType.CSharp, CompilerType.CPlusPlusGcc, CompilerType.Java, }); default: throw new ArgumentOutOfRangeException( nameof(plagiarismDetectorType), plagiarismDetectorType, null); } }
private IPlagiarismDetector GetPlagiarismDetector(PlagiarismDetectorType type) { var plagiarismDetectorCreationContext = this.CreatePlagiarismDetectorCreationContext(type); var plagiarismDetector = this.plagiarismDetectorFactory.CreatePlagiarismDetector(plagiarismDetectorCreationContext); return(plagiarismDetector); }
public PlagiarismDetectorCreationContext(PlagiarismDetectorType type, ISimilarityFinder similarityFinder) { if (similarityFinder == null) { throw new ArgumentNullException(nameof(similarityFinder)); } this.Type = type; this.SimilarityFinder = similarityFinder; }
private IQueryable <Submission> GetSimilarSubmissions( IEnumerable <int> contestIds, PlagiarismDetectorType plagiarismDetectorType) { var orExpressionContestIds = ExpressionBuilder.BuildOrExpression <Submission, int>( contestIds, s => s.Participant.ContestId); var plagiarismDetectorTypeCompatibleCompilerTypes = plagiarismDetectorType.GetCompatibleCompilerTypes(); var orExpressionCompilerTypes = ExpressionBuilder.BuildOrExpression <Submission, CompilerType>( plagiarismDetectorTypeCompatibleCompilerTypes, s => s.SubmissionType.CompilerType); var result = this.Data.Submissions .All() .Where(orExpressionContestIds) .Where(orExpressionCompilerTypes) .Where(s => s.Participant.IsOfficial && s.Points >= MinSubmissionPointsToCheckForSimilarity); return(result); }
public ActionResult RenderSubmissionsSimilaritiesGrid(int[] contestIds, PlagiarismDetectorType plagiarismDetectorType) { this.Server.ScriptTimeout = RenderSubmissionsSimilaritiesGridTimeOut; var participantsSimilarSubmissionGroups = this.GetSimilarSubmissions(contestIds, plagiarismDetectorType) .Select(s => new { s.Id, s.ProblemId, s.ParticipantId, s.Points, s.Content, s.CreatedOn, ParticipantName = s.Participant.User.UserName, ProblemName = s.Problem.Name, TestRuns = s.TestRuns.OrderBy(t => t.TestId).Select(t => new { t.TestId, t.ResultType }) }) .GroupBy(s => new { s.ProblemId, s.ParticipantId }) .Select(g => g.OrderByDescending(s => s.Points).ThenByDescending(s => s.CreatedOn).FirstOrDefault()) .GroupBy(s => new { s.ProblemId, s.Points }) .ToList(); var plagiarismDetector = this.GetPlagiarismDetector(plagiarismDetectorType); var similarities = new List <SubmissionSimilarityViewModel>(); for (var index = 0; index < participantsSimilarSubmissionGroups.Count; index++) { var groupOfSubmissions = participantsSimilarSubmissionGroups[index].ToList(); for (var i = 0; i < groupOfSubmissions.Count; i++) { for (var j = i + 1; j < groupOfSubmissions.Count; j++) { var result = plagiarismDetector.DetectPlagiarism( groupOfSubmissions[i].Content.Decompress(), groupOfSubmissions[j].Content.Decompress(), new List <IDetectPlagiarismVisitor> { new SortAndTrimLinesVisitor() }); var save = true; var firstTestRuns = groupOfSubmissions[i].TestRuns.ToList(); var secondTestRuns = groupOfSubmissions[j].TestRuns.ToList(); if (firstTestRuns.Count < secondTestRuns.Count) { secondTestRuns = secondTestRuns .Where(x => firstTestRuns.Any(y => y.TestId == x.TestId)) .OrderBy(x => x.TestId) .ToList(); } else if (firstTestRuns.Count > secondTestRuns.Count) { firstTestRuns = firstTestRuns .Where(x => secondTestRuns.Any(y => y.TestId == x.TestId)) .OrderBy(x => x.TestId) .ToList(); } for (var k = 0; k < firstTestRuns.Count; k++) { if (firstTestRuns[k].ResultType != secondTestRuns[k].ResultType) { save = false; break; } } if (save && result.SimilarityPercentage != 0) { similarities.Add(new SubmissionSimilarityViewModel { ProblemName = groupOfSubmissions[i].ProblemName, Points = groupOfSubmissions[i].Points, Differences = result.Differences.Count, Percentage = result.SimilarityPercentage, FirstSubmissionId = groupOfSubmissions[i].Id, FirstParticipantName = groupOfSubmissions[i].ParticipantName, FirstSubmissionCreatedOn = groupOfSubmissions[i].CreatedOn, SecondSubmissionId = groupOfSubmissions[j].Id, SecondParticipantName = groupOfSubmissions[j].ParticipantName, SecondSubmissionCreatedOn = groupOfSubmissions[j].CreatedOn, }); } } } } return(this.PartialView("_SubmissionsGrid", similarities.GroupBy(g => g.ProblemName))); }
private PlagiarismDetectorCreationContext CreatePlagiarismDetectorCreationContext(PlagiarismDetectorType type) { var result = new PlagiarismDetectorCreationContext(type, this.similarityFinder); switch (type) { case PlagiarismDetectorType.CSharpCompileDisassemble: result.CompilerPath = Settings.CSharpCompilerPath; result.DisassemblerPath = Settings.DotNetDisassemblerPath; break; case PlagiarismDetectorType.CSharpDotNetCoreCompileDisassemble: result.CompilerPath = Settings.DotNetCompilerPath; result.DisassemblerPath = Settings.DotNetDisassemblerPath; break; case PlagiarismDetectorType.JavaCompileDisassemble: result.CompilerPath = Settings.JavaCompilerPath; result.DisassemblerPath = Settings.JavaDisassemblerPath; break; case PlagiarismDetectorType.PlainText: break; } return(result); }