public IActionResult CheckPlagiarism(string userFileId, string subjectId, bool isCp = false) { try { var path = Guid.NewGuid().ToString("N"); var subjectName = SubjectManagementService.GetSubject(int.Parse(subjectId)).ShortName; Directory.CreateDirectory(PlagiarismTempPath + path); var userFile = SubjectManagementService.GetUserLabFile(int.Parse(userFileId)); var usersFiles = SubjectManagementService.GetUserLabFiles(0, int.Parse(subjectId)) .Where(e => e.IsReceived && e.Id != userFile.Id && e.IsCoursProject == isCp); var filesPaths = usersFiles.Select(e => e.Attachments); foreach (var filesPath in filesPaths) { foreach (var srcPath in Directory.GetFiles(FileUploadPath + filesPath)) { System.IO.File.Copy(srcPath, srcPath.Replace(FileUploadPath + filesPath, PlagiarismTempPath + path), true); } } var firstFileName = Directory.GetFiles(FileUploadPath + userFile.Attachments) .Select(fi => fi) .FirstOrDefault(); var plagiarismController = new PlagiarismController(); var result = plagiarismController.CheckBySingleDoc(firstFileName, new[] { PlagiarismTempPath + path }.ToList(), 10, 10); var data = new List <ResultPlag>(); foreach (var res in result) { var resPlag = new ResultPlag(); var fileName = Path.GetFileName(res.Doc); var name = FilesManagementService.GetFileDisplayName(fileName); resPlag.doc = name; resPlag.subjectName = subjectName; resPlag.coeff = res.Coeff.ToString(); var pathName = FilesManagementService.GetPathName(fileName); var userFileT = SubjectManagementService.GetUserLabFile(pathName); var userId = userFileT.UserId; var user = StudentManagementService.GetStudent(userId); resPlag.author = user.FullName; resPlag.groupName = user.Group.Name; data.Add(resPlag); } var resultData = data.ToList(); return(Ok(resultData)); } catch (Exception ex) { return(ServerError500(ex.Message)); } }
public IActionResult CheckPlagiarismSubjects(string subjectId, string type, string threshold) { try { var path = Guid.NewGuid().ToString("N"); var subjectName = SubjectManagementService.GetSubject(int.Parse(subjectId)).ShortName; Directory.CreateDirectory(PlagiarismTempPath + path); var usersFiles = SubjectManagementService.GetUserLabFiles(0, int.Parse(subjectId)) .Where(e => e.IsReceived); var filesPaths = usersFiles.Select(e => e.Attachments); foreach (var filesPath in filesPaths) { if (Directory.Exists(FileUploadPath + filesPath)) { foreach (var srcPath in Directory.GetFiles(FileUploadPath + filesPath)) { System.IO.File.Copy(srcPath, srcPath.Replace(FileUploadPath + filesPath, PlagiarismTempPath + path), true); } } } var plagiarismController = new PlagiarismController(); var result = plagiarismController.CheckByDirectory(new[] { PlagiarismTempPath + path }.ToList(), int.Parse(threshold), 10, int.Parse(type)); var data = new ResultPlagSubjectClu { clusters = new ResultPlagSubject[result.Count] }; for (var i = 0; i < result.Count; ++i) { data.clusters[i] = new ResultPlagSubject { correctDocs = new List <ResultPlag>() }; foreach (var doc in result[i].Docs) { var resultS = new ResultPlag(); var fileName = Path.GetFileName(doc); var name = FilesManagementService.GetFileDisplayName(fileName); resultS.subjectName = subjectName; resultS.doc = name; var pathName = FilesManagementService.GetPathName(fileName); var userFileT = SubjectManagementService.GetUserLabFile(pathName); var userId = userFileT.UserId; var user = StudentManagementService.GetStudent(userId); resultS.author = user.FullName; resultS.groupName = user.Group.Name; data.clusters[i].correctDocs.Add(resultS); } } var resultData = data.clusters.ToList(); return(Ok(resultData)); } catch (Exception ex) { return(ServerError500(ex.Message)); } }