14
14
#include " boost/filesystem/path.hpp"
15
15
#include " nlohmann/json.hpp"
16
16
17
+ #include " lichen_config.h"
17
18
#include " submission.h"
18
19
#include " hash_location.h"
19
20
@@ -101,11 +102,13 @@ int main(int argc, char* argv[]) {
101
102
time_t overall_start, overall_end;
102
103
time (&overall_start);
103
104
105
+
104
106
// ===========================================================================
105
107
// load Lichen config data
106
108
std::ifstream lichen_config_istr (" ./lichen_config.json" );
107
109
assert (lichen_config_istr.good ());
108
110
nlohmann::json lichen_config = nlohmann::json::parse (lichen_config_istr);
111
+ LichenConfig config;
109
112
110
113
// ===========================================================================
111
114
// load config info
@@ -119,11 +122,11 @@ int main(int argc, char* argv[]) {
119
122
assert (istr.good ());
120
123
nlohmann::json config_file_json = nlohmann::json::parse (istr);
121
124
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 );
127
130
128
131
// error checking, confirm there are hashes to work with
129
132
boost::filesystem::path users_root_directory = lichen_gradeable_path / " users" ;
@@ -136,7 +139,7 @@ int main(int argc, char* argv[]) {
136
139
// the file path where we expect to find the hashed instructor provided code file
137
140
boost::filesystem::path provided_code_file = lichen_gradeable_path / " provided_code" / " hashes.txt" ;
138
141
// 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);
140
143
// path to prior gradeables' data
141
144
boost::filesystem::path prior_terms_dir = lichen_gradeable_path / " other_gradeables" ;
142
145
@@ -158,7 +161,7 @@ int main(int argc, char* argv[]) {
158
161
time_t start, end;
159
162
time (&start);
160
163
161
- if (provided_code_enabled) {
164
+ if (config. provided_code_enabled ) {
162
165
// load the instructor provided code's hashes
163
166
std::ifstream istr (provided_code_file.string ());
164
167
assert (istr.good ());
@@ -221,7 +224,7 @@ int main(int argc, char* argv[]) {
221
224
assert (version > 0 );
222
225
223
226
// 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 );
225
228
226
229
// load the hashes from this submission
227
230
boost::filesystem::path hash_file = version_path;
@@ -233,7 +236,7 @@ int main(int argc, char* argv[]) {
233
236
while (istr >> input_hash_str) {
234
237
hash input_hash = (unsigned int )(stoul (input_hash_str, 0 , 16 ));
235
238
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 ));
237
240
curr_submission->addHash (input_hash, location);
238
241
}
239
242
@@ -267,7 +270,7 @@ int main(int argc, char* argv[]) {
267
270
268
271
// if provided code was enabled, look for the submission hash in the provided code's hashes
269
272
bool provided_match_found = false ;
270
- if (provided_code_enabled) {
273
+ if (config. provided_code_enabled ) {
271
274
std::unordered_set<hash>::iterator provided_match_itr = provided_code.find (hash_itr->first );
272
275
if (provided_match_itr != provided_code.end ()) {
273
276
provided_match_found = true ;
@@ -292,7 +295,7 @@ int main(int argc, char* argv[]) {
292
295
std::vector<HashLocation>::iterator itr = occurences_itr->second .begin ();
293
296
for (; itr != occurences_itr->second .end (); ++itr) {
294
297
295
- if (occurences.size () > (unsigned int )threshold) {
298
+ if (occurences.size () > (unsigned int ) config. threshold ) {
296
299
// if the number of students with matching code is more
297
300
// than the threshold, it is considered common code
298
301
(*submission_itr)->addCommonMatch (hash_itr->second );
@@ -368,7 +371,7 @@ int main(int argc, char* argv[]) {
368
371
std::vector<nlohmann::json> matchingpositions;
369
372
nlohmann::json position;
370
373
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 ;
372
375
matchingpositions.push_back (position);
373
376
374
377
// search for all matching positions of the suspicious match in other submissions
@@ -400,7 +403,7 @@ int main(int argc, char* argv[]) {
400
403
other[" source_gradeable" ] = matching_positions_itr->source_gradeable ;
401
404
}
402
405
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 ;
404
407
matchingpositions.push_back (position);
405
408
}
406
409
}
@@ -411,7 +414,7 @@ int main(int argc, char* argv[]) {
411
414
412
415
nlohmann::json info;
413
416
info[" start" ] = location_itr->first ;
414
- info[" end" ] = location_itr->first + sequence_length - 1 ;
417
+ info[" end" ] = location_itr->first + config. sequence_length - 1 ;
415
418
info[" type" ] = " match" ;
416
419
info[" others" ] = others;
417
420
@@ -428,7 +431,7 @@ int main(int argc, char* argv[]) {
428
431
429
432
nlohmann::json info;
430
433
info[" start" ] = *location_itr;
431
- info[" end" ] = *location_itr + sequence_length - 1 ;
434
+ info[" end" ] = *location_itr + config. sequence_length - 1 ;
432
435
info[" type" ] = " common" ;
433
436
434
437
result.push_back (info);
@@ -444,7 +447,7 @@ int main(int argc, char* argv[]) {
444
447
445
448
nlohmann::json info;
446
449
info[" start" ] = *location_itr;
447
- info[" end" ] = *location_itr + sequence_length - 1 ;
450
+ info[" end" ] = *location_itr + config. sequence_length - 1 ;
448
451
info[" type" ] = " provided" ;
449
452
450
453
result.push_back (info);
@@ -456,7 +459,7 @@ int main(int argc, char* argv[]) {
456
459
// Done creating the JSON file/objects, now we merge them to shrink them in size
457
460
458
461
// 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)
460
463
// loop through all positions
461
464
for (unsigned int position = 1 ; position < result.size (); position++) {
462
465
nlohmann::json* prevPosition = &result[position - 1 ];
0 commit comments