-
Notifications
You must be signed in to change notification settings - Fork 9
/
main.cpp
2006 lines (1681 loc) · 73.8 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <iostream>
#include <cassert>
#include <fstream>
#include <sstream>
#include <string>
#include <vector>
#include <iomanip>
#include <map>
#include <algorithm>
#include <ctime>
#include <cmath>
#include "benchmark.h"
#include "submini_polls.h"
std::string GLOBAL_sort_order;
int GLOBAL_ACTIVE_TEST_ZONE = 0;
std::string GLOBAL_ACTIVE_TEST_ID = "";
#include "student.h"
#include "gradeable.h"
#include "grade.h"
#include <nlohmann/json.hpp>
std::string ReadQuoted(std::istream &istr);
void suggest_curves(std::vector<Student*> &students);
void assign_ranks(std::vector<Student*> &students);
std::string GLOBAL_recommend_id = "";
std::vector<std::string> OMIT_SECTION_FROM_STATS;
//====================================================================
// DIRECTORIES & FILES
std::string OUTPUT_FILE = "./output.html";
std::string OUTPUT_CSV_FILE = "./output.csv";
std::string CUSTOMIZATION_FILE = "./customization_no_comments.json";
std::string RG_VERSION_FILE = "./RG_version.json";
std::string RAW_DATA_DIRECTORY = "./raw_data/all_grades/";
std::string INDIVIDUAL_FILES_OUTPUT_DIRECTORY = "./individual_summary_html/";
std::string ALL_STUDENTS_OUTPUT_DIRECTORY = "./all_students_summary_html/";
std::string ALL_STUDENTS_OUTPUT_DIRECTORY_CSV = "./all_students_summary_csv/";
nlohmann::json GLOBAL_CUSTOMIZATION_JSON;
//====================================================================
// INFO ABOUT GRADING FOR COURSE
std::vector<GRADEABLE_ENUM> ALL_GRADEABLES;
std::map<GRADEABLE_ENUM,Gradeable> GRADEABLES;
float LATE_DAY_PERCENTAGE_PENALTY = 0;
bool TEST_IMPROVEMENT_AVERAGING_ADJUSTMENT = false;
bool LOWEST_TEST_COUNTS_HALF = false;
int QUIZ_NORMALIZE_AND_DROP = 0;
std::map<std::string,float> CUTOFFS;
std::map<GRADEABLE_ENUM,float> OVERALL_FAIL_CUTOFFS;
std::map<Grade,int> grade_counts;
std::map<Grade,float> grade_avg;
int took_final = 0;
int auditors = 0;
int dropped = 0;
Student* PERFECT_STUDENT_POINTER;
Student* AVERAGE_STUDENT_POINTER;
Student* STDDEV_STUDENT_POINTER;
//====================================================================
// INFO ABOUT NUMBER OF SECTIONS
std::map<std::string,std::string> sectionNames;
std::map<std::string,std::string> sectionColors;
bool validSection(std::string section) {
nlohmann::json::iterator itr = GLOBAL_CUSTOMIZATION_JSON.find("section");
assert (itr != GLOBAL_CUSTOMIZATION_JSON.end());
assert (itr->is_object());
nlohmann::json::iterator itr2 = itr->find(section);
if (itr2 == itr->end()) return false;
return true;
//return (sectionNames.find(section) != sectionNames.end());
}
std::string sectionName(std::string section) {
std::map<std::string,std::string>::const_iterator itr = sectionNames.find(section);
if (itr == sectionNames.end())
return "NONE";
return itr->second;
}
//====================================================================
std::string GLOBAL_EXAM_TITLE = "exam title uninitialized";
std::string GLOBAL_EXAM_DATE = "exam date uninitialized";
std::string GLOBAL_EXAM_TIME = "exam time uninitialized";
std::string GLOBAL_EXAM_DEFAULT_ROOM = "exam default room uninitialized";
std::string GLOBAL_EXAM_DEFAULT_BUILDING = "exam default building uninitialized";
std::string GLOBAL_EXAM_SEATING = "";
std::string GLOBAL_SEATING_SPACING = "";
std::string GLOBAL_EXAM_SEATING_COUNT = "";
std::string GLOBAL_LEFT_RIGHT_HANDEDNESS = "";
float GLOBAL_MIN_OVERALL_FOR_ZONE_ASSIGNMENT = 0.1;
int BONUS_WHICH_LECTURE = -1;
std::string BONUS_FILE;
//====================================================================
// INFO ABOUT OUTPUT FORMATTING
bool DISPLAY_INSTRUCTOR_NOTES = false;
bool DISPLAY_EXAM_SEATING = false;
bool DISPLAY_ACADEMIC_SANCTION_DETAILS = false;
bool DISPLAY_FINAL_GRADE = false;
bool DISPLAY_GRADE_SUMMARY = false;
bool DISPLAY_GRADE_DETAILS = false;
bool DISPLAY_LATE_DAYS = false;
bool DISPLAY_RANK_TO_INDIVIDUAL = false;
std::vector<std::string> MESSAGES;
//====================================================================
//void PrintExamRoomAndZoneTable(std::ofstream &ostr, Student *s, const nlohmann::json &special_message);
void PrintExamRoomAndZoneTable(const std::string &id, nlohmann::json &mj, Student *s, const nlohmann::json &special_message);
//====================================================================
//====================================================================
// sorting routines
bool by_overall(const Student* s1, const Student* s2) {
float s1_overall = s1->overall_b4_academic_sanction();
float s2_overall = s2->overall_b4_academic_sanction();
if (s1 == AVERAGE_STUDENT_POINTER) return true;
if (s2 == AVERAGE_STUDENT_POINTER) return false;
if (s1 == STDDEV_STUDENT_POINTER) return true;
if (s2 == STDDEV_STUDENT_POINTER) return false;
if (s1_overall > s2_overall+0.0001) return true;
if (fabs (s1_overall - s2_overall) < 0.0001 &&
s1->getSection() == "null" &&
s2->getSection() != "null")
return true;
return false;
}
bool by_test_and_exam(const Student* s1, const Student* s2) {
float val1 = s1->GradeablePercent(GRADEABLE_ENUM::TEST) + s1->GradeablePercent(GRADEABLE_ENUM::EXAM);
float val2 = s2->GradeablePercent(GRADEABLE_ENUM::TEST) + s2->GradeablePercent(GRADEABLE_ENUM::EXAM);
if (val1 > val2) return true;
if (fabs (val1-val2) < 0.0001 &&
s1->getSection() == "null" &&
s2->getSection() != "null")
return true;
return false;
}
// FOR GRADEABLES
class GradeableSorter {
public:
GradeableSorter(GRADEABLE_ENUM g) : g_(g) {}
bool operator()(Student *s1, Student *s2) {
return (s1->GradeablePercent(g_) > s2->GradeablePercent(g_) ||
(s1->GradeablePercent(g_) == s2->GradeablePercent(g_) &&
by_overall(s1,s2)));
}
private:
GRADEABLE_ENUM g_;
};
// FOR OTHER THINGS
std::string lowerCase(std::string str) {
for(unsigned int i=0;i<str.length();i++){
str[i] = std::tolower(str[i]);
}
return str;
}
bool by_name(const Student* s1, const Student* s2) {
return (lowerCase(s1->getPreferredLastName()) < lowerCase(s2->getPreferredLastName()) ||
(lowerCase(s1->getPreferredLastName()) == lowerCase(s2->getPreferredLastName()) &&
lowerCase(s1->getPreferredFirstName()) < lowerCase(s2->getPreferredFirstName())));
}
std::string padifonlydigits(const std::string& s, unsigned int n) {
for (std::string::size_type i = 0; i < s.size(); i++) {
if (s[i] < '0' || s[i] > '9') return s;
}
if (s.size() < n) {
return std::string(n-s.size(),'0') + s;
}
return s;
}
bool by_section(const Student *s1, const Student *s2) {
if (s2->getIndependentStudy() == true && s1->getIndependentStudy() == false) return false;
if (s2->getIndependentStudy() == false && s1->getIndependentStudy() == true) return false;
std::string S1 = s1->getSection();
std::string S2 = s2->getSection();
if (S2 == "null" && S1 == "null") {
return by_name(s1,s2);
}
if (S2 == "null") return true;
if (S1 == "null") return false;
S1 = padifonlydigits(S1,3);
S2 = padifonlydigits(S2,3);
if (S1 < S2) return true;
if (S1 > S2) return false;
return by_name(s1,s2);
}
// sorting function for letter grades
bool operator< (const Grade &a, const Grade &b) {
if (a.value == b.value) return false;
if (a.value == "A") return true;
if (b.value == "A") return false;
if (a.value == "A-") return true;
if (b.value == "A-") return false;
if (a.value == "B+") return true;
if (b.value == "B+") return false;
if (a.value == "B") return true;
if (b.value == "B") return false;
if (a.value == "B-") return true;
if (b.value == "B-") return false;
if (a.value == "C+") return true;
if (b.value == "C+") return false;
if (a.value == "C") return true;
if (b.value == "C") return false;
if (a.value == "C-") return true;
if (b.value == "C-") return false;
if (a.value == "D+") return true;
if (b.value == "D+") return false;
if (a.value == "D") return true;
if (b.value == "D") return false;
if (a.value == "F") return true;
if (b.value == "F") return false;
return false;
}
//====================================================================
/*
void gradeable_helper(std::ifstream& istr, GRADEABLE_ENUM g) {
int c; float p, m;
istr >> c >> p >> m;
assert (GRADEABLES.find(g) == GRADEABLES.end());
Gradeable answer (c,p,m);
GRADEABLES.insert(std::make_pair(g,answer));
assert (GRADEABLES[g].getCount() >= 0);
assert (GRADEABLES[g].getPercent() >= 0.0 && GRADEABLES[g].getPercent() <= 1.0);
assert (GRADEABLES[g].getMaximum() >= 0.0);
}
*/
bool string_to_gradeable_enum(const std::string &s, GRADEABLE_ENUM &return_value) {
std::string s2;
for (unsigned int i = 0; i < s.size(); ++i) {
s2.push_back(std::tolower(s[i]));
}
std::replace( s2.begin(), s2.end(), '-', '_');
if (s2 == "hw" || s2 == "homework") { return_value = GRADEABLE_ENUM::HOMEWORK; return true; }
if (s2 == "assignment") { return_value = GRADEABLE_ENUM::ASSIGNMENT; return true; }
if (s2 == "problem_set") { return_value = GRADEABLE_ENUM::PROBLEM_SET; return true; }
if (s2 == "quiz" || s2 == "quizze") { return_value = GRADEABLE_ENUM::QUIZ; return true; }
if (s2 == "test") { return_value = GRADEABLE_ENUM::TEST; return true; }
if (s2 == "exam") { return_value = GRADEABLE_ENUM::EXAM; return true; }
if (s2 == "exercise") { return_value = GRADEABLE_ENUM::EXERCISE; return true; }
if (s2 == "lecture_exercise") { return_value = GRADEABLE_ENUM::LECTURE_EXERCISE; return true; }
if (s2 == "reading") { return_value = GRADEABLE_ENUM::READING; return true; }
if (s2 == "worksheet") { return_value = GRADEABLE_ENUM::WORKSHEET; return true; }
if (s2 == "lab") { return_value = GRADEABLE_ENUM::LAB; return true; }
if (s2 == "recitation") { return_value = GRADEABLE_ENUM::RECITATION; return true; }
if (s2 == "project") { return_value = GRADEABLE_ENUM::PROJECT; return true; }
if (s2 == "participation") { return_value = GRADEABLE_ENUM::PARTICIPATION; return true; }
if (s2 == "instructor_note" || s2 == "note") { return_value = GRADEABLE_ENUM::NOTE; return true; }
if (s2 == "note") { return_value = GRADEABLE_ENUM::NOTE; return true; }
if (s2.substr(0,4) == "none") { return_value = GRADEABLE_ENUM::NOTE; return true; }
return false;
}
//====================================================================
void preprocesscustomizationfile(const std::string &now_string,
std::vector<Student*> &students) {
/*
std::ifstream istr(CUSTOMIZATION_FILE.c_str());
assert (istr);
std::string token;
while (istr >> token) {
if (token[0] == '#') {
// comment line!
char line[MAX_STRING_LENGTH];
istr.getline(line,MAX_STRING_LENGTH);
} else if (token.size() > 4 && token.substr(0,4) == "num_") {
GRADEABLE_ENUM g;
// also take 's' off the end
bool success = string_to_gradeable_enum(token.substr(4,token.size()-5),g);
if (success) {
gradeable_helper(istr,g);
ALL_GRADEABLES.push_back(g);
} else {
std::cout << "UNKNOWN GRADEABLE: " << token.substr(4,token.size()-5) << std::endl;
exit(0);
}
} else if (token == "hackmaxprojects") {
char line[MAX_STRING_LENGTH];
istr.getline(line,MAX_STRING_LENGTH);
std::stringstream ss(line);
std::vector<std::string> items;
std::string i;
while (ss >> i) {
items.push_back(i);
}
std::cout << "HACK MAX " << items.size() << std::endl;
std::cout << " HMP=" << HACKMAXPROJECTS.size() << std::endl;
HACKMAXPROJECTS.push_back(items);
} else if (token == "display") {
istr >> token;
if (token == "instructor_notes") {
DISPLAY_INSTRUCTOR_NOTES = true;
} else if (token == "exam_seating") {
DISPLAY_EXAM_SEATING = true;
} else if (token == "academic_sanction_details") {
DISPLAY_ACADEMIC_SANCTION_DETAILS = true;
} else if (token == "final_grade") {
DISPLAY_FINAL_GRADE = true;
} else if (token == "grade_summary") {
DISPLAY_GRADE_SUMMARY = true;
} else if (token == "grade_details") {
DISPLAY_GRADE_DETAILS = true;
} else {
std::cout << "OOPS " << token << std::endl;
exit(0);
}
char line[MAX_STRING_LENGTH];
istr.getline(line,MAX_STRING_LENGTH);
} else if (token == "display_benchmark") {
istr >> token;
DisplayBenchmark(token);
} else if (token == "benchmark_percent") {
istr >> token;
float value;
istr >> value;
SetBenchmarkPercentage(token,value);
} else if (token == "benchmark_color") {
istr >> token;
std::string color;
istr >> color;
SetBenchmarkColor(token,color);
} else if (token == "use") {
istr >> token;
if (token == "late_day_penalty") {
istr >> LATE_DAY_PERCENTAGE_PENALTY;
assert (LATE_DAY_PERCENTAGE_PENALTY >= 0.0 && LATE_DAY_PERCENTAGE_PENALTY < 0.25);
char line[MAX_STRING_LENGTH];
istr.getline(line,MAX_STRING_LENGTH);
} else if (token == "test_improvement_averaging_adjustment") {
TEST_IMPROVEMENT_AVERAGING_ADJUSTMENT = true;
} else if (token == "quiz_normalize_and_drop_two") {
QUIZ_NORMALIZE_AND_DROP_TWO = true;
} else if (token == "lowest_test_counts_half") {
LOWEST_TEST_COUNTS_HALF = true;
} else {
std::cout << "ERROR: unknown use " << token << std::endl;
exit(0);
}
} else if (token == "remove_lowest") {
istr >> token;
if (token == "HOMEWORK") {
int num;
istr >> num;
assert (num >= 0 && num < GRADEABLES[GRADEABLE_ENUM::HOMEWORK].getCount());
GRADEABLES[GRADEABLE_ENUM::HOMEWORK].setRemoveLowest(num);
}
}
}
*/
// ---------------------------------------------------------------------------------------
std::ifstream istr(CUSTOMIZATION_FILE.c_str());
assert (istr.good());
nlohmann::json j = nlohmann::json::parse(istr);
std::string token;
float p_score,a_score,b_score,c_score,d_score;
Student *perfect = GetStudent(students,"PERFECT");
Student *student_average = GetStudent(students,"AVERAGE");
Student *student_stddev = GetStudent(students,"STDDEV");
Student *lowest_a = GetStudent(students,"LOWEST A-");
Student *lowest_b = GetStudent(students,"LOWEST B-");
Student *lowest_c = GetStudent(students,"LOWEST C-");
Student *lowest_d = GetStudent(students,"LOWEST D");
//std::cout << "0" << std::endl;
// load gradeables
nlohmann::json all_gradeables = j["gradeables"];
int num_gradeables = all_gradeables.size();
float sum_of_percents = 0;
for (int i = 0; i < num_gradeables; i++) {
nlohmann::json one_gradeable_type = all_gradeables[i];
GRADEABLE_ENUM g;
// TYPE
nlohmann::json::iterator itr = one_gradeable_type.find("type");
assert (itr != one_gradeable_type.end());
std::string gradeable_type = itr->get<std::string>();
bool success = string_to_gradeable_enum(gradeable_type, g);
if (!success) {
std::cout << "UNKNOWN GRADEABLE TYPE: " << gradeable_type << std::endl;
exit(0);
}
// PERCENT
itr = one_gradeable_type.find("percent");
assert (itr != one_gradeable_type.end());
float gradeable_total_percent = itr->get<float>();
assert (gradeable_total_percent >= 0);
sum_of_percents += gradeable_total_percent;
int parse_count = one_gradeable_type.value("count",-1);
unsigned int count = 0;
nlohmann::json ids_list = one_gradeable_type["ids"];
for (unsigned int k = 0; k < ids_list.size(); k++) {
nlohmann::json ids = ids_list[k];
std::string gradeable_id = ids.value("id","");
assert (gradeable_id != "");
}
if (parse_count == -1) {
count = ids_list.size();
}
else{
count = parse_count;
}
assert (ids_list.size() <= count);
Gradeable answer (count,gradeable_total_percent); //,m);
GRADEABLES.insert(std::make_pair(g,answer));
assert (GRADEABLES[g].getCount() >= 0);
assert (GRADEABLES[g].getPercent() >= 0.0 && GRADEABLES[g].getPercent() <= 1.0);
//SORTED WEIGHTS
itr = one_gradeable_type.find("sorted_weights");
if(itr != one_gradeable_type.end()){
//Verify that we have as many weights as the count in the bucket
nlohmann::json weight_array = one_gradeable_type["sorted_weights"];
assert(weight_array.size() == count && "NUMBER OF SORTED WEIGHTS DOES NOT MATCH COUNT IN GRADEABLE CATEGORY");
//Extract the array of weights
float scaled_weights_sum = 0.0;
float prev_weight;
float weight;
for(unsigned int k=0; k < weight_array.size(); k++){
if(k>0){
prev_weight = weight;
}
nlohmann::json sorted_weight = weight_array[k];
weight = sorted_weight.get<float>();
scaled_weights_sum += weight;
GRADEABLES[g].addSortedWeight(weight);
if(k>0){
assert(prev_weight <= weight && "SORTED WEIGHTS MUST BE IN INCREASING ORDER");
}
}
//Verify that weights sum to close to the bucket percentage
assert(fabs(scaled_weights_sum - gradeable_total_percent) < 0.001 && "SCALED WEIGHTS SHOULD SUM TO GRADEABLE CATEGORY TOTAL PERCENTAGE");
}
// Set remove lowest for gradeable
int num = one_gradeable_type.value("remove_lowest", 0);
assert (num == 0 || (num >= 0 && num < GRADEABLES[g].getCount()));
assert ((num == 0 || !GRADEABLES[g].hasSortedWeight()) && "CANNOT USE remove_lowest AND sorted_weights IN THE SAME GRADEABLE CATEGORY");
GRADEABLES[g].setRemoveLowest(num);
ALL_GRADEABLES.push_back(g);
// Used to clamp extra credit. For example, if there are 3 gradeables of a category, each worth 1/2
// percentage of a total score, a student could earn 1.5x the value for the gradeable category.
// We can clamp that by setting bucket_percentage_upper_clamp to a value less than 1.5.
nlohmann::json::iterator upper_clamp_itr = one_gradeable_type.find("bucket_percentage_upper_clamp");
float bucket_percentage_upper_clamp = -1;
if (upper_clamp_itr != one_gradeable_type.end()){
bucket_percentage_upper_clamp = upper_clamp_itr->get<float>();
}
GRADEABLES[g].setBucketPercentageUpperClamp(bucket_percentage_upper_clamp);
//Parse out the min grade required for passing in this category
float overall_cutoff = one_gradeable_type.value("overall_cutoff", 0.0);
assert(0.0 <= overall_cutoff && overall_cutoff <= 1.0);
OVERALL_FAIL_CUTOFFS.insert(std::make_pair(g,overall_cutoff));
}
// Set Benchmark Percent
std::vector<std::string> benchmark_percents;
nlohmann::json benchmarkPercent = j["benchmark_percent"];
for (nlohmann::json::iterator itr = benchmarkPercent.begin(); itr != benchmarkPercent.end(); itr++) {
token = itr.key();
float value;
value = itr.value();
SetBenchmarkPercentage(token,value);
benchmark_percents.push_back(token);
}
perfect = new Student();perfect->setUserName("PERFECT");
student_average = new Student();student_average->setUserName("AVERAGE");
student_stddev = new Student();student_stddev->setUserName("STDDEV");
lowest_a = new Student();lowest_a->setUserName("LOWEST A-");lowest_a->setLegalFirstName("approximate");
lowest_b = new Student();lowest_b->setUserName("LOWEST B-");lowest_b->setLegalFirstName("approximate");
lowest_c = new Student();lowest_c->setUserName("LOWEST C-");lowest_c->setLegalFirstName("approximate");
lowest_d = new Student();lowest_d->setUserName("LOWEST D"); lowest_d->setLegalFirstName("approximate");
PERFECT_STUDENT_POINTER = perfect;
AVERAGE_STUDENT_POINTER = student_average;
STDDEV_STUDENT_POINTER = student_stddev;
for (int i = 0; i < num_gradeables; i++) {
nlohmann::json one_gradeable_type = all_gradeables[i];
GRADEABLE_ENUM g;
nlohmann::json::iterator itr = one_gradeable_type.find("type");
assert (itr != one_gradeable_type.end());
std::string gradeable_type = itr->get<std::string>();
bool success = string_to_gradeable_enum(gradeable_type, g);
if (!success) {
std::cout << "UNKNOWN GRADEABLE: " << gradeable_type << std::endl;
exit(0);
}
nlohmann::json ids_list = one_gradeable_type["ids"];
for (unsigned int k = 0; k < ids_list.size(); k++) {
nlohmann::json grade_id = ids_list[k];
std::string token_key = grade_id.value("id","");
//std::cout << token_key << std::endl;
assert (token_key != "");
int which = GRADEABLES[g].setCorrespondence(token_key);
p_score = grade_id.value("max", 0.0);
std::vector<float> curve = grade_id.value("curve",std::vector<float>());
a_score = GetBenchmarkPercentage("lowest_a-")*p_score;
b_score = GetBenchmarkPercentage("lowest_b-")*p_score;
c_score = GetBenchmarkPercentage("lowest_c-")*p_score;
d_score = GetBenchmarkPercentage("lowest_d")*p_score;
if (!curve.empty()) {
assert(curve.size() == benchmark_percents.size());
for (std::size_t x = 0; x < benchmark_percents.size(); x++) {
if (benchmark_percents[x] == "lowest_a-") a_score = curve[x];
if (benchmark_percents[x] == "lowest_b-") b_score = curve[x];
if (benchmark_percents[x] == "lowest_c-") c_score = curve[x];
if (benchmark_percents[x] == "lowest_d") d_score = curve[x];
}
}
c_score = std::min(b_score,c_score);
d_score = std::min(c_score,d_score);
bool released = grade_id.value("released",true);
std::string release_date = grade_id.value("release_date","");
if (release_date != "") {
//std::cout << "RELEASE DATE " << release_date << std::endl;
if (release_date < now_string) {
//std::cout << "RELEASED!" << std::endl;
GRADEABLES[g].setReleased(token_key,true);
} else {
//std::cout << "not released" << std::endl;
GRADEABLES[g].setReleased(token_key,false);
}
} else {
GRADEABLES[g].setReleased(token_key,released);
}
float maximum = grade_id.value("max",0.0);
GRADEABLES[g].setMaximum(token_key,maximum);
if (grade_id.find("scale_max") != grade_id.end()) {
float scale_maximum = grade_id.value("scale_max",0.0);
assert (scale_maximum > 0);
GRADEABLES[g].setScaleMaximum(token_key,scale_maximum);
}
if (grade_id.find("percent") != grade_id.end()) {
assert(!GRADEABLES[g].hasSortedWeight() &&
"GRADE CATEGORY HAS sorted_weights FIELD WHICH WOULD OVERRIDE GRADEABLE-SPECIFIC percent FIELD");
float item_percentage = grade_id.value("percent",-1.0);
assert (item_percentage >= 0 && item_percentage <= 1.0);
GRADEABLES[g].setItemPercentage(token_key,item_percentage);
}
float clamp = grade_id.value("clamp",-1);
GRADEABLES[g].setClamp(token_key,clamp);
if (grade_id.find("autograde_replacement_percentage") != grade_id.end()) {
assert (grade_id.find("original_id") != grade_id.end());
assert (grade_id.find("resubmit_id") != grade_id.end());
assert (grade_id.find("title") != grade_id.end());
std::string o_id = grade_id.value("original_id","");
std::string r_id = grade_id.value("resubmit_id","");
std::string t = grade_id.value("title","");
float a_r_p = grade_id.value("autograde_replacement_percentage",0.5);
GRADEABLES[g].setResubmissionValues(token_key,o_id,r_id,t,a_r_p);
}
assert (p_score >= a_score &&
a_score >= b_score &&
b_score >= c_score &&
c_score >= d_score);
assert (which >= 0 && which < GRADEABLES[g].getCount());
if (GRADEABLES[g].isReleased(token_key)) {
perfect->setGradeableItemGrade(g,which, p_score);
lowest_a->setGradeableItemGrade(g,which, a_score);
lowest_b->setGradeableItemGrade(g,which, b_score);
lowest_c->setGradeableItemGrade(g,which, c_score);
lowest_d->setGradeableItemGrade(g,which, d_score);
}
//std::cout << "it makes it to exam data" << std::endl;
nlohmann::json exam_data = grade_id["exam_data"];
//std::cout << exam_data << std::endl;
if (!exam_data.empty()) {
//std::cout << "makes it into exam data" << std::endl;
int active = exam_data["active"].get<int>();
if (active == 1) {
GLOBAL_ACTIVE_TEST_ZONE = k;
GLOBAL_ACTIVE_TEST_ID = grade_id["id"].get<std::string>();
for (nlohmann::json::iterator itr2 = (exam_data).begin(); itr2 != (exam_data).end(); itr2++) {
std::string token2 = itr2.key();
//std::cout << token2 << std::endl;
if (token2 == "exam_title") {
std::string value = itr2.value();
GLOBAL_EXAM_TITLE = value;
} else if (token2 == "exam_date") {
std::string value = itr2.value();
GLOBAL_EXAM_DATE = value;
} else if (token2 == "exam_time") {
std::string value = itr2.value();
GLOBAL_EXAM_TIME = value;
} else if (token2 == "exam_default_building") {
std::string value = itr2.value();
GLOBAL_EXAM_DEFAULT_BUILDING = value;
} else if (token2 == "exam_default_room") {
std::string value = itr2.value();
GLOBAL_EXAM_DEFAULT_ROOM = value;
} else if (token2 == "min_overall_for_zone_assignment") {
float value = itr2.value();
GLOBAL_MIN_OVERALL_FOR_ZONE_ASSIGNMENT = value;
} else if (token2 == "exam_seating") {
std::cout << "TOKEN IS EXAM SEATING" << std::endl;
std::string value = itr2.value();
GLOBAL_EXAM_SEATING = value;
} else if (token2 == "seating_spacing") {
std::cout << "TOKEN IS SEATING SPACING" << std::endl;
std::string value = itr2.value();
GLOBAL_SEATING_SPACING = value;
} else if (token2 == "exam_seating_count") {
std::cout << "TOKEN IS EXAM SEATING COUNT" << std::endl;
std::string value = itr2.value();
GLOBAL_EXAM_SEATING_COUNT = value;
} else if (token2 == "left_right_handedness") {
std::cout << "TOKEN IS LEFT RIGHT HANDEDNESS" << std::endl;
std::string value = itr2.value();
GLOBAL_LEFT_RIGHT_HANDEDNESS = value;
}
}
}
}
}
}
students.push_back(perfect);
students.push_back(student_average);
students.push_back(student_stddev);
students.push_back(lowest_a);
students.push_back(lowest_b);
students.push_back(lowest_c);
students.push_back(lowest_d);
//std::cout << "3" << std::endl;
// get display options
std::vector<std::string> displays = j["display"].get<std::vector<std::string> >();
for (std::size_t i=0; i<displays.size(); i++) {
token = displays[i];
if (token == "instructor_notes") {
DISPLAY_INSTRUCTOR_NOTES = true;
} else if (token == "exam_seating") {
DISPLAY_EXAM_SEATING = true;
} else if (token == "academic_sanction_details" || token == "moss_details") {
DISPLAY_ACADEMIC_SANCTION_DETAILS = true;
} else if (token == "final_grade") {
DISPLAY_FINAL_GRADE = true;
} else if (token == "grade_summary") {
DISPLAY_GRADE_SUMMARY = true;
} else if (token == "grade_details") {
DISPLAY_GRADE_DETAILS = true;
} else if (token == "display_rank_to_individual"){
DISPLAY_RANK_TO_INDIVIDUAL = true;
} else if (token == "display_benchmark") {
continue;
} else if (token == "section") {
continue;
} else if (token == "messages") {
continue;
} else if (token == "warning") {
continue;
} else if (token == "manual_grade"){
continue;
} else if (token == "final_cutoff"){
continue;
} else {
std::cout << "OOPS " << token << std::endl;
exit(0);
}
}
//std::cout << "4" << std::endl;
// Set Display Benchmark
std::vector<std::string> displayBenchmark = j["display_benchmark"].get<std::vector<std::string> >();
for (std::size_t i=0; i<displayBenchmark.size(); i++) {
token = displayBenchmark[i];
DisplayBenchmark(token);
}
if (j.find("omit_section_from_stats") != j.end()) {
for (unsigned int i = 0; i < j["omit_section_from_stats"].size(); i++) {
OMIT_SECTION_FROM_STATS.push_back(j["omit_section_from_stats"][i]);
}
}
//std::cout << "5" << std::endl;
//std::cout << "6" << std::endl;
// Set Benchmark Color
nlohmann::json benchmarkColor = j["benchmark_color"];
for (nlohmann::json::iterator itr = benchmarkColor.begin(); itr != benchmarkColor.end(); itr++) {
token = itr.key();
std::string color;
color = itr.value().get<std::string>();
SetBenchmarkColor(token,color);
}
//std::cout << "7" << std::endl;
//std::cout << "8" << std::endl;
nlohmann::json useJSON = j["use"];
for (nlohmann::json::iterator itr = useJSON.begin(); itr != useJSON.end(); itr++) {
token = itr.key();
if (token == "late_day_penalty") {
LATE_DAY_PERCENTAGE_PENALTY = itr.value();
assert (LATE_DAY_PERCENTAGE_PENALTY >= 0.0 && LATE_DAY_PERCENTAGE_PENALTY <= 0.5);
} else if (token == "test_improvement_averaging_adjustment") {
TEST_IMPROVEMENT_AVERAGING_ADJUSTMENT = itr.value();
} else if (token == "quiz_normalize_and_drop") {
QUIZ_NORMALIZE_AND_DROP = itr.value();
} else if (token == "lowest_test_counts_half") {
LOWEST_TEST_COUNTS_HALF = true;
} else {
std::cout << "ERROR: unknown use " << token << std::endl;
exit(0);
}
}
//std::cout << "9" << std::endl;
}
bool OmitSectionFromStats(const std::string §ion) {
for (std::vector<std::string>::size_type i = 0; i < OMIT_SECTION_FROM_STATS.size(); i++) {
if (OMIT_SECTION_FROM_STATS[i] == section) return true;
}
return false;
}
// defined in zone.cpp
void LoadExamSeatingFile(const std::string &zone_counts_filename,
const std::string &zone_assignments_filename,
const std::string &seating_spacing,
const std::string &left_right_handedness,
std::vector<Student*> &students);
void load_student_grades(std::vector<Student*> &students);
void load_bonus_late_day(std::vector<Student*> &students, int which_lecture, std::string bonus_late_day_file);
void processcustomizationfile(const std::string &now_string,
std::vector<Student*> &students) {
std::ifstream istr(CUSTOMIZATION_FILE.c_str());
assert (istr.good());
nlohmann::json j = nlohmann::json::parse(istr);
GLOBAL_CUSTOMIZATION_JSON = j;
SetBenchmarkPercentage("lowest_a-",0.9);
SetBenchmarkPercentage("lowest_b-",0.8);
SetBenchmarkPercentage("lowest_c-",0.7);
SetBenchmarkPercentage("lowest_d",0.6);
SetBenchmarkColor("extracredit","aa88ff"); // dark purple
SetBenchmarkColor("perfect" ,"c8c8ff"); // purple
SetBenchmarkColor("lowest_a-" ,"c8ffc8"); // green
SetBenchmarkColor("lowest_b-" ,"ffffc8"); // yellow
SetBenchmarkColor("lowest_c-" ,"ffc8c8"); // orange
SetBenchmarkColor("lowest_d" ,"ff0000"); // red
SetBenchmarkColor("failing" ,"c80000"); // dark red
preprocesscustomizationfile(now_string,students);
load_student_grades(students);
std::string token,token2;
for (nlohmann::json::iterator itr = j.begin(); itr != j.end(); itr++) {
token = itr.key();
//std::cout << token << std::endl;
if (token == "section") {
// create sections
int counter = 0;
for (nlohmann::json::iterator itr2 = (itr.value()).begin(); itr2 != (itr.value()).end(); itr2++) {
std::string section = itr2.key();
std::string section_name = itr2.value();
//std::cout << "MAKE ASSOCIATION " << section << " " << section_name << std::endl;
//assert (!validSection(section));
sectionNames[section] = section_name;
if (sectionColors.find(section_name) == sectionColors.end()) {
if (counter == 0) {
sectionColors[section_name] = "ccffcc"; // lt green
} else if (counter == 1) {
sectionColors[section_name] = "ffcccc"; // lt salmon
} else if (counter == 2) {
sectionColors[section_name] = "ffffaa"; // lt yellow
} else if (counter == 3) {
sectionColors[section_name] = "ccccff"; // lt blue-purple
} else if (counter == 4) {
sectionColors[section_name] = "aaffff"; // lt cyan
} else if (counter == 5) {
sectionColors[section_name] = "ffaaff"; // lt magenta
} else if (counter == 6) {
sectionColors[section_name] = "88ccff"; // blue
} else if (counter == 7) {
sectionColors[section_name] = "cc88ff"; // purple
} else if (counter == 8) {
sectionColors[section_name] = "88ffcc"; // mint
} else if (counter == 9) {
sectionColors[section_name] = "ccff88"; // yellow green
} else if (counter == 10) {
sectionColors[section_name] = "ff88cc"; // pink
} else if (counter == 11) {
sectionColors[section_name] = "ffcc88"; // orange
} else if (counter == 12) {
sectionColors[section_name] = "ffff33"; // yellow
} else if (counter == 13) {
sectionColors[section_name] = "ff33ff"; // magenta
} else if (counter == 14) {
sectionColors[section_name] = "33ffff"; // cyan
} else if (counter == 15) {
sectionColors[section_name] = "6666ff"; // blue-purple
} else if (counter == 16) {
sectionColors[section_name] = "66ff66"; // green
} else if (counter == 17) {
sectionColors[section_name] = "ff6666"; // red
} else {
sectionColors[section_name] = "aaaaaa"; // grey
}
counter++;
}
}
} else if (token == "messages") {
// general message at the top of the file
for (nlohmann::json::iterator itr2 = (itr.value()).begin(); itr2 != (itr.value()).end(); itr2++) {
MESSAGES.push_back(*itr2);
}
} else if (token == "warning") {
// EWS early warning system [ per student ]
std::vector<nlohmann::json> warning_list = j[token].get<std::vector<nlohmann::json> >();
for (std::size_t i = 0; i<warning_list.size(); i++) {
nlohmann::json warning = warning_list[i];
//std::string username = warning_user["user"].get<std::string>();
std::string message = warning["msg"].get<std::string>();
std::vector<std::string> ids;
float value = warning["value"].get<float>();
nlohmann::json j_ids = warning["ids"];
for (std::size_t k = 0; k < j_ids.size(); k++) {
ids.push_back(j_ids[k].get<std::string>());
}
std::cout << "search for " << message << std::endl;
for (unsigned int S = 0; S < students.size(); S++) {
Student *s = students[S];
if (!validSection(students[S]->getSection())) continue;
//std::cout << "student " << s->getUserName() << std::endl;
float v = 0;
for (std::size_t k = 0; k < ids.size(); k++) {
GRADEABLE_ENUM g;
int item;
//std::cout << "GRADEABLE_ENUM " << (int)g << " " << item << std::endl;
LookupGradeable(ids[k],g,item);
v += s->getGradeableItemGrade(g,item).getValue();
}
if (v < value) {
std::stringstream ss;
ss << " " << v << " < " << value;
s->addWarning(message + ss.str());
}
}
}
} else if (token == "recommend") {