Skip to content

Commit 7896fbd

Browse files
authored
[Bugfix:Plagiarism] Not Creating Files for No Matches (#33)
* Ensure no files are created when no matches found * Switch to empty overall rankings file
1 parent 08324d0 commit 7896fbd

File tree

1 file changed

+24
-17
lines changed

1 file changed

+24
-17
lines changed

compare_hashes/compare_hashes.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -525,15 +525,16 @@ int main(int argc, char* argv[]) {
525525

526526
float percentMatch = submission_itr->getPercentage();
527527

528-
std::unordered_map<std::string, std::pair<int, float> >::iterator highest_matches_itr
529-
= highest_matches.find(submission_itr->student());
530-
if (highest_matches_itr == highest_matches.end()) {
531-
highest_matches[submission_itr->student()].first = submission_itr->version();
532-
highest_matches[submission_itr->student()].second = percentMatch;
533-
}
534-
else if (percentMatch > highest_matches_itr->second.second) {
535-
highest_matches_itr->second.first = submission_itr->version();
536-
highest_matches_itr->second.second = percentMatch;
528+
if (percentMatch > 0.0) {
529+
std::unordered_map<std::string, std::pair<int, float> >::iterator highest_matches_itr = highest_matches.find(submission_itr->student());
530+
if (highest_matches_itr == highest_matches.end()) {
531+
highest_matches[submission_itr->student()].first = submission_itr->version();
532+
highest_matches[submission_itr->student()].second = percentMatch;
533+
}
534+
else if (percentMatch > highest_matches_itr->second.second) {
535+
highest_matches_itr->second.first = submission_itr->version();
536+
highest_matches_itr->second.second = percentMatch;
537+
}
537538
}
538539
}
539540

@@ -554,24 +555,22 @@ int main(int argc, char* argv[]) {
554555
<< std::setw(3) << std::right << ranking[i].version << std::endl;
555556
}
556557

557-
558558
// ---------------------------------------------------------------------------
559559
// create a rankings file for every submission. the file contains all the other
560560
// students share matches, sorted by decreasing order of the percent match
561561

562562
for (std::vector<Submission>::iterator submission_itr = all_submissions.begin();
563563
submission_itr != all_submissions.end(); ++submission_itr) {
564564

565-
// create the directory and a file to write into
566-
std::string ranking_student_dir = "/var/local/submitty/courses/"+semester+"/"+course+"/lichen/ranking/"
567-
+gradeable+"/"+submission_itr->student()+"/"+std::to_string(submission_itr->version())+"/";
568-
std::string ranking_student_file = ranking_student_dir+submission_itr->student()+"_"+std::to_string(submission_itr->version())+".txt";
569-
boost::filesystem::create_directories(ranking_student_dir);
570-
std::ofstream ranking_student_ostr(ranking_student_file);
571-
572565
// find and sort the other submissions it matches with
573566
std::vector<StudentRanking> student_ranking;
574567
std::unordered_map<std::string, std::unordered_map<int, std::unordered_set<hash>>> matches = submission_itr->getStudentsMatched();
568+
569+
// no need to create a file for students with no matches
570+
if (matches.size() == 0) {
571+
continue;
572+
}
573+
575574
for (std::unordered_map<std::string, std::unordered_map<int, std::unordered_set<hash>>>::const_iterator matches_itr = matches.begin();
576575
matches_itr != matches.end(); ++matches_itr) {
577576

@@ -598,6 +597,13 @@ int main(int argc, char* argv[]) {
598597

599598
std::sort(student_ranking.begin(), student_ranking.end(), ranking_sorter);
600599

600+
// create the directory and a file to write into
601+
std::string ranking_student_dir = "/var/local/submitty/courses/"+semester+"/"+course+"/lichen/ranking/"
602+
+gradeable+"/"+submission_itr->student()+"/"+std::to_string(submission_itr->version())+"/";
603+
std::string ranking_student_file = ranking_student_dir+submission_itr->student()+"_"+std::to_string(submission_itr->version())+".txt";
604+
boost::filesystem::create_directories(ranking_student_dir);
605+
std::ofstream ranking_student_ostr(ranking_student_file);
606+
601607
// finally, write the file of ranking for this submission
602608
for (unsigned int i = 0; i < student_ranking.size(); i++) {
603609
ranking_student_ostr
@@ -606,6 +612,7 @@ int main(int argc, char* argv[]) {
606612
<< std::setw(3) << std::right << student_ranking[i].version << std::endl;
607613
}
608614
}
615+
609616

610617

611618
// ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)