1414#include " boost/filesystem/path.hpp"
1515#include " nlohmann/json.hpp"
1616
17+ #include " lichen_config.h"
1718#include " submission.h"
1819#include " hash_location.h"
1920
@@ -101,11 +102,13 @@ int main(int argc, char* argv[]) {
101102 time_t overall_start, overall_end;
102103 time (&overall_start);
103104
105+
104106 // ===========================================================================
105107 // load Lichen config data
106108 std::ifstream lichen_config_istr (" ./lichen_config.json" );
107109 assert (lichen_config_istr.good ());
108110 nlohmann::json lichen_config = nlohmann::json::parse (lichen_config_istr);
111+ LichenConfig config;
109112
110113 // ===========================================================================
111114 // load config info
@@ -119,11 +122,11 @@ int main(int argc, char* argv[]) {
119122 assert (istr.good ());
120123 nlohmann::json config_file_json = nlohmann::json::parse (istr);
121124
122- std::string semester = config_file_json.value (" semester" , " ERROR" );
123- std::string course = config_file_json.value (" course" , " ERROR" );
124- std::string gradeable = config_file_json.value (" gradeable" , " ERROR" );
125- int sequence_length = config_file_json.value (" sequence_length" , 1 );
126- int threshold = config_file_json.value (" threshold" , 5 );
125+ config. semester = config_file_json.value (" semester" , " ERROR" );
126+ config. course = config_file_json.value (" course" , " ERROR" );
127+ config. gradeable = config_file_json.value (" gradeable" , " ERROR" );
128+ config. sequence_length = config_file_json.value (" sequence_length" , 1 );
129+ config. threshold = config_file_json.value (" threshold" , 5 );
127130
128131 // error checking, confirm there are hashes to work with
129132 boost::filesystem::path users_root_directory = lichen_gradeable_path / " users" ;
@@ -136,7 +139,7 @@ int main(int argc, char* argv[]) {
136139 // the file path where we expect to find the hashed instructor provided code file
137140 boost::filesystem::path provided_code_file = lichen_gradeable_path / " provided_code" / " hashes.txt" ;
138141 // if file exists in that location, the provided code mode is enabled.
139- bool provided_code_enabled = boost::filesystem::exists (provided_code_file);
142+ config. provided_code_enabled = boost::filesystem::exists (provided_code_file);
140143 // path to prior gradeables' data
141144 boost::filesystem::path prior_terms_dir = lichen_gradeable_path / " other_gradeables" ;
142145
@@ -158,7 +161,7 @@ int main(int argc, char* argv[]) {
158161 time_t start, end;
159162 time (&start);
160163
161- if (provided_code_enabled) {
164+ if (config. provided_code_enabled ) {
162165 // load the instructor provided code's hashes
163166 std::ifstream istr (provided_code_file.string ());
164167 assert (istr.good ());
@@ -221,7 +224,7 @@ int main(int argc, char* argv[]) {
221224 assert (version > 0 );
222225
223226 // create a submission object and load to the main submissions structure
224- Submission* curr_submission = new Submission (username, version);
227+ Submission* curr_submission = new Submission (username, version, config );
225228
226229 // load the hashes from this submission
227230 boost::filesystem::path hash_file = version_path;
@@ -233,7 +236,7 @@ int main(int argc, char* argv[]) {
233236 while (istr >> input_hash_str) {
234237 hash input_hash = (unsigned int )(stoul (input_hash_str, 0 , 16 ));
235238 location++;
236- all_hashes[input_hash][username].push_back (HashLocation (username, version, location, semester+ " __" + course+ " __" + gradeable));
239+ all_hashes[input_hash][username].push_back (HashLocation (username, version, location, config. semester + " __" + config. course + " __" + config. gradeable ));
237240 curr_submission->addHash (input_hash, location);
238241 }
239242
@@ -267,7 +270,7 @@ int main(int argc, char* argv[]) {
267270
268271 // if provided code was enabled, look for the submission hash in the provided code's hashes
269272 bool provided_match_found = false ;
270- if (provided_code_enabled) {
273+ if (config. provided_code_enabled ) {
271274 std::unordered_set<hash>::iterator provided_match_itr = provided_code.find (hash_itr->first );
272275 if (provided_match_itr != provided_code.end ()) {
273276 provided_match_found = true ;
@@ -292,7 +295,7 @@ int main(int argc, char* argv[]) {
292295 std::vector<HashLocation>::iterator itr = occurences_itr->second .begin ();
293296 for (; itr != occurences_itr->second .end (); ++itr) {
294297
295- if (occurences.size () > (unsigned int )threshold) {
298+ if (occurences.size () > (unsigned int ) config. threshold ) {
296299 // if the number of students with matching code is more
297300 // than the threshold, it is considered common code
298301 (*submission_itr)->addCommonMatch (hash_itr->second );
@@ -368,7 +371,7 @@ int main(int argc, char* argv[]) {
368371 std::vector<nlohmann::json> matchingpositions;
369372 nlohmann::json position;
370373 position[" start" ] = matching_positions_itr->location ;
371- position[" end" ] = matching_positions_itr->location + sequence_length - 1 ;
374+ position[" end" ] = matching_positions_itr->location + config. sequence_length - 1 ;
372375 matchingpositions.push_back (position);
373376
374377 // search for all matching positions of the suspicious match in other submissions
@@ -400,7 +403,7 @@ int main(int argc, char* argv[]) {
400403 other[" source_gradeable" ] = matching_positions_itr->source_gradeable ;
401404 }
402405 position[" start" ] = matching_positions_itr->location ;
403- position[" end" ] = matching_positions_itr->location + sequence_length - 1 ;
406+ position[" end" ] = matching_positions_itr->location + config. sequence_length - 1 ;
404407 matchingpositions.push_back (position);
405408 }
406409 }
@@ -411,7 +414,7 @@ int main(int argc, char* argv[]) {
411414
412415 nlohmann::json info;
413416 info[" start" ] = location_itr->first ;
414- info[" end" ] = location_itr->first + sequence_length - 1 ;
417+ info[" end" ] = location_itr->first + config. sequence_length - 1 ;
415418 info[" type" ] = " match" ;
416419 info[" others" ] = others;
417420
@@ -428,7 +431,7 @@ int main(int argc, char* argv[]) {
428431
429432 nlohmann::json info;
430433 info[" start" ] = *location_itr;
431- info[" end" ] = *location_itr + sequence_length - 1 ;
434+ info[" end" ] = *location_itr + config. sequence_length - 1 ;
432435 info[" type" ] = " common" ;
433436
434437 result.push_back (info);
@@ -444,7 +447,7 @@ int main(int argc, char* argv[]) {
444447
445448 nlohmann::json info;
446449 info[" start" ] = *location_itr;
447- info[" end" ] = *location_itr + sequence_length - 1 ;
450+ info[" end" ] = *location_itr + config. sequence_length - 1 ;
448451 info[" type" ] = " provided" ;
449452
450453 result.push_back (info);
@@ -456,7 +459,7 @@ int main(int argc, char* argv[]) {
456459 // Done creating the JSON file/objects, now we merge them to shrink them in size
457460
458461 // Merge matching regions:
459- if (result.size () > 0 ) { // check to make sure that there are more than 1 positions (if it's 1, we can't merge anyway)
462+ if (! result.empty () ) { // check to make sure that there are more than 1 positions (if it's 1, we can't merge anyway)
460463 // loop through all positions
461464 for (unsigned int position = 1 ; position < result.size (); position++) {
462465 nlohmann::json* prevPosition = &result[position - 1 ];
0 commit comments