@@ -157,8 +157,8 @@ int main(int argc, char* argv[]) {
157
157
std::unordered_set<hash> provided_code;
158
158
// stores all hashes from other gradeables
159
159
std::unordered_map<hash, std::unordered_map<user_id, std::vector<HashLocation>>> other_gradeables;
160
- // stores the highest match for every student, used later for generating overall_rankings.txt
161
- std::unordered_map<user_id, std::pair<int , Score>> highest_matches;
160
+ // stores the matches for every student, used later for generating overall_rankings.txt
161
+ std::unordered_map<user_id, std::vector<std:: pair<version_number , Score> >> highest_matches;
162
162
// keeps track of max matching hashes across all submissions, used for calculation of ranking score
163
163
unsigned int max_hashes_matched = 0 ;
164
164
@@ -283,7 +283,7 @@ int main(int argc, char* argv[]) {
283
283
}
284
284
}
285
285
286
- // if the hash doesn't match any of the provided code's hashes, try to find matched between other students
286
+ // if the hash doesn't match any of the provided code's hashes, try to find matches between other students
287
287
if (!provided_match_found) {
288
288
// look up that hash in the all_hashes table, loop over all other students that have the same hash
289
289
std::unordered_map<std::string, std::vector<HashLocation>> occurences = all_hashes[hash_itr->first ];
@@ -333,23 +333,6 @@ int main(int argc, char* argv[]) {
333
333
continue ;
334
334
}
335
335
336
- // Save this submissions highest percent match for later when we generate overall_rankings.txt
337
- float percentMatch = (*submission_itr)->getPercentage ();
338
- unsigned int totalMatchingHashes = (*submission_itr)->getMatchCount ();
339
- Score submission_score (totalMatchingHashes, percentMatch);
340
- if (max_hashes_matched < totalMatchingHashes) {
341
- max_hashes_matched = totalMatchingHashes;
342
- }
343
-
344
- std::unordered_map<user_id, std::pair<int , Score> >::iterator highest_matches_itr = highest_matches.find ((*submission_itr)->student ());
345
- std::pair<int , Score> new_pair = {(*submission_itr)->version (), submission_score};
346
- if (highest_matches_itr == highest_matches.end ()) {
347
- highest_matches.insert ({(*submission_itr)->student (), new_pair});
348
- }
349
- else if (submission_score > highest_matches_itr->second .second ) {
350
- highest_matches_itr->second = new_pair;
351
- }
352
-
353
336
// =========================================================================
354
337
// Write matches.json file
355
338
@@ -563,6 +546,19 @@ int main(int argc, char* argv[]) {
563
546
}
564
547
}
565
548
549
+ // =========================================================================
550
+ // Save this submission's highest percent match for later when we generate overall_rankings.txt
551
+ float percentMatch = (*submission_itr)->getPercentage ();
552
+ unsigned int totalMatchingHashes = (*submission_itr)->getMatchCount ();
553
+ Score submission_score (totalMatchingHashes, percentMatch);
554
+ if (max_hashes_matched < totalMatchingHashes) {
555
+ max_hashes_matched = totalMatchingHashes;
556
+ }
557
+
558
+ std::pair<version_number, Score> new_pair = {(*submission_itr)->version (), submission_score};
559
+ highest_matches[(*submission_itr)->student ()].push_back (new_pair);
560
+ // =========================================================================
561
+
566
562
std::sort (student_ranking.begin (), student_ranking.end (), ranking_sorter);
567
563
568
564
// create the directory and a file to write into
@@ -609,10 +605,18 @@ int main(int argc, char* argv[]) {
609
605
// take the map of highest matches and convert it to a vector so we can sort it
610
606
// by percent match and then save it to a file
611
607
std::vector<StudentRanking> ranking;
612
- for (std::unordered_map<user_id, std::pair<int , Score> >::iterator itr
608
+ for (std::unordered_map<user_id, std::vector<std:: pair<version_number , Score>> >::iterator itr
613
609
= highest_matches.begin (); itr != highest_matches.end (); ++itr) {
614
- ranking.push_back (StudentRanking (itr->first , itr->second .first , " " , itr->second .second ));
615
- ranking[ranking.size ()-1 ].score .calculateScore (max_hashes_matched);
610
+
611
+ std::pair<version_number, Score> best_score = itr->second .front ();
612
+ best_score.second .calculateScore (max_hashes_matched);
613
+ for (unsigned int i=0 ; i < itr->second .size (); i++) {
614
+ itr->second [i].second .calculateScore (max_hashes_matched);
615
+ if (itr->second [i].second > best_score.second ) {
616
+ best_score = itr->second [i];
617
+ }
618
+ }
619
+ ranking.push_back (StudentRanking (itr->first , best_score.first , " " , best_score.second ));
616
620
}
617
621
618
622
std::sort (ranking.begin (), ranking.end (), ranking_sorter);
0 commit comments