From 409b0bcafb1d2acc9b3d407b46fe6a786e90a7e2 Mon Sep 17 00:00:00 2001 From: Buster Holzbauer Date: Thu, 14 Jun 2018 08:59:30 -0400 Subject: [PATCH] Alphanumeric registration support (#1) * WIP, done with main? * WIP: need to solve other issues and test, but registration section can now be alphanum without failing to compile * Testing done, a bit of cleanup done --- constants_and_globals.h | 4 +-- main.cpp | 54 ++++++++++++++++++++++------------------- output.cpp | 16 ++++++------ student.cpp | 6 ++--- student.h | 6 ++--- zone.cpp | 2 +- 6 files changed, 46 insertions(+), 42 deletions(-) diff --git a/constants_and_globals.h b/constants_and_globals.h index e303ce3..5b74e08 100644 --- a/constants_and_globals.h +++ b/constants_and_globals.h @@ -40,7 +40,7 @@ extern bool LOWEST_TEST_COUNTS_HALF; extern int QUIZ_NORMALIZE_AND_DROP; // ========================================================== -extern std::map sectionNames; +extern std::map sectionNames; extern std::map sectionColors; @@ -62,7 +62,7 @@ extern float MAX_ICLICKER_TOTAL; // ========================================================== // PROTOTYPES -bool validSection(int section); +bool validSection(std::string section); #endif // __CONSTANTS_H__ diff --git a/main.cpp b/main.cpp index bee53d5..f258109 100644 --- a/main.cpp +++ b/main.cpp @@ -74,16 +74,16 @@ Student* STDDEV_STUDENT_POINTER; //==================================================================== // INFO ABOUT NUMBER OF SECTIONS -std::map sectionNames; +std::map sectionNames; std::map sectionColors; -bool validSection(int section) { +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(std::to_string(section)); + nlohmann::json::iterator itr2 = itr->find(section); if (itr2 == itr->end()) return false; return true; @@ -91,8 +91,8 @@ bool validSection(int section) { } -std::string sectionName(int section) { - std::map::const_iterator itr = sectionNames.find(section); +std::string sectionName(std::string section) { + std::map::const_iterator itr = sectionNames.find(section); if (itr == sectionNames.end()) return "NONE"; return itr->second; @@ -161,8 +161,8 @@ bool by_overall(const Student* s1, const Student* s2) { if (s1_overall > s2_overall+0.0001) return true; if (fabs (s1_overall - s2_overall) < 0.0001 && - s1->getSection() == 0 && - s2->getSection() != 0) + s1->getSection() == "null" && + s2->getSection() != "null") return true; return false; @@ -175,8 +175,8 @@ bool by_test_and_exam(const Student* s1, const Student* s2) { if (val1 > val2) return true; if (fabs (val1-val2) < 0.0001 && - s1->getSection() == 0 && - s2->getSection() != 0) + s1->getSection() == "null" && + s2->getSection() != "null") return true; return false; @@ -208,15 +208,16 @@ bool by_name(const Student* s1, const Student* s2) { s1->getPreferredName() < s2->getPreferredName())); } - +//XXX: Is this going to lead to problems with section "1" vs "11" vs "2" now? +// Might be customizer's job to left-pad with zeros. 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; - if (s2->getSection() <= 0 && s1->getSection() <= 0) { + if (s2->getSection() == "null" && s1->getSection() == "null") { return by_name(s1,s2); } - if (s2->getSection() == 0) return true; - if (s1->getSection() == 0) return false; + if (s2->getSection() == "null") return true; + if (s1->getSection() == "null") return false; if (s1->getSection() < s2->getSection()) return true; if (s1->getSection() > s2->getSection()) return false; return by_name(s1,s2); @@ -761,7 +762,10 @@ void MakeRosterFile(std::vector &students) { for (unsigned int i = 0; i < students.size(); i++) { std::string foo = "active"; if (students[i]->getLastName() == "") continue; - if (students[i]->getSection() <= 0 || students[i]->getSection() > 10) continue; + + //XXX: Is this still being called? We definitely can have more than 10 sections in general... + //if (students[i]->getSection() <= 0 || students[i]->getSection() > 10) continue; + if (students[i]->getSection() == "null") continue; if (students[i]->getGradeableItemGrade(GRADEABLE_ENUM::TEST,0).getValue() < 1) { //std::cout << "STUDENT DID NOT TAKE TEST 1 " << students[i]->getUserName() << std::endl; foo = "inactive"; @@ -852,8 +856,7 @@ void processcustomizationfile(std::vector &students) { // create sections int counter = 0; for (nlohmann::json::iterator itr2 = (itr.value()).begin(); itr2 != (itr.value()).end(); itr2++) { - std::string temp = itr2.key(); - int section = std::stoi(temp); + std::string section = itr2.key(); std::string section_name = itr2.value(); std::cout << "MAKE ASSOCIATION " << section << " " << section_name << std::endl; //assert (!validSection(section)); @@ -1188,18 +1191,18 @@ void load_student_grades(std::vector &students) { } else if (token == "last_update") { s->setLastUpdate(j[token].get()); } else if (token == "registration_section") { - int a; + std::string a; if(!j[token].is_null()) { - a = j[token].get(); + a = j[token].get(); if (!validSection(a)) { // the "drop" section is 0 (really should be NULL) - if (a != 0) { + if (a != "null") { std::cerr << "WARNING: invalid section " << a << std::endl; } } } else{ - a = 0; + a = "null"; } s->setSection(a); @@ -1502,7 +1505,8 @@ void output_helper(std::vector &students, std::string &GLOBAL_sort_or start_table_output(true,students,-1,month,day,year, sp,sa,sb,sc,sd); int next_rank = 1; - int last_section = -1; + //int last_section = -1; + std::string last_section; for (int S = 0; S < (int)students.size(); S++) { //int rank = next_rank; @@ -1757,10 +1761,10 @@ void suggest_curves(std::vector &students) { std::cout << gradeable_to_string(g) << " " << gradeable_id << " " << gradeable_name/* << " statistics & suggested curve"*/ << std::endl; std::vector scores; - std::map section_counts; + std::map section_counts; for (unsigned int S = 0; S < students.size(); S++) { - if (students[S]->getSection() > 0 && students[S]->getGradeableItemGrade(g,item).getValue() > 0) { + if (students[S]->getSection() != "null" && students[S]->getGradeableItemGrade(g,item).getValue() > 0) { scores.push_back(students[S]->getGradeableItemGrade(g,item).getValue()); section_counts[students[S]->getSection()]++; } @@ -1797,8 +1801,8 @@ void suggest_curves(std::vector &students) { int total = 0; std::cout << " "; - for (std::map::iterator itr = section_counts.begin(); itr != section_counts.end(); itr++) { - std::cout << " sec#" << itr->first << "=" << itr->second << " "; + for (std::map::iterator itr = section_counts.begin(); itr != section_counts.end(); itr++) { + std::cout << " sec" << itr->first << "=" << itr->second << " "; total += itr->second; } std::cout << " TOTAL = " << total << std::endl; diff --git a/output.cpp b/output.cpp index 534d5a4..1e57789 100644 --- a/output.cpp +++ b/output.cpp @@ -256,7 +256,7 @@ void colorit_major(std::ostream &ostr, const std::string& s) { void colorit_section(std::ostream &ostr, - int section, bool for_instructor, const std::string &color) { + std::string section, bool for_instructor, const std::string &color) { std::string section_name; @@ -264,18 +264,18 @@ void colorit_section(std::ostream &ostr, section_name = sectionNames[section]; std::string section_color = sectionColors[section_name]; - if (section == 0) { + if (section == "null") { section_color=color; } if (for_instructor) { - if (section != 0) { + if (section != "null") { ostr << "" << section << " (" << section_name << ")"; } else { ostr << " " << std::endl; } } else { - if (section != 0) { + if (section != "null") { ostr << "" << section << ""; } else { ostr << " " << std::endl; @@ -284,7 +284,7 @@ void colorit_section(std::ostream &ostr, } -void colorit_section2(int section, std::string &color, std::string &label) { +void colorit_section2(std::string section, std::string &color, std::string &label) { std::string section_name; if (validSection(section)) { section_name = sectionNames[section]; @@ -378,7 +378,7 @@ void PrintExamRoomAndZoneTable(std::ofstream &ostr, Student *s, const nlohmann:: std::string time = GLOBAL_EXAM_TIME; std::string row = ""; std::string seat = ""; - if (s->getSection() == 0) { + if (s->getSection() == "null") { //room = ""; //zone = ""; time = ""; @@ -698,7 +698,7 @@ void start_table_output( bool for_instructor, int myrank = 1; int myrow = 1; - int last_section = -1; + std::string last_section = ""; for (unsigned int stu= 0; stu < students.size(); stu++) { Student *this_student = students[stu]; @@ -786,7 +786,7 @@ void start_table_output( bool for_instructor, std::string seat = ""; std::string time = GLOBAL_EXAM_TIME; - if (this_student->getSection() == 0) { //LastName() == "") { + if (this_student->getSection() == "null") { //LastName() == "") { room = ""; zone = ""; time = ""; diff --git a/student.cpp b/student.cpp index 4d6326f..3f96733 100644 --- a/student.cpp +++ b/student.cpp @@ -13,7 +13,7 @@ Student::Student() { lefty = false; // registration status - section = 0; + section = "null"; audit = false; withdraw = false; independentstudy = false; @@ -268,7 +268,7 @@ float Student::lowest_test_counts_half_pct() const { // ============================================================================================= int Student::getAllowedLateDays(int which_lecture) const { - if (getSection() == 0) return 0; + if (getSection() == "null") return 0; //int answer = 2; @@ -321,7 +321,7 @@ float Student::overall_b4_moss() const { std::string Student::grade(bool flag_b4_moss, Student *lowest_d) const { - if (section == 0) return ""; + if (section == "null") return ""; if (!flag_b4_moss && manual_grade != "") return manual_grade; diff --git a/student.h b/student.h index 584dd2c..9c79ae0 100644 --- a/student.h +++ b/student.h @@ -83,7 +83,7 @@ class Student { bool getLefty() const { return lefty; } // registration status - int getSection() const { return section; } + const std::string& getSection() const { return section; } bool getAudit() const { return audit; } bool getWithdraw() const { return withdraw; } bool getIndependentStudy() const { return independentstudy; } @@ -133,7 +133,7 @@ class Student { void setLastUpdate(const std::string &s) { lastUpdate = s; } // registration status - void setSection(int x) { section = x; } + void setSection(std::string x) { section = x; } void setAudit() { audit = true; } void setWithdraw() { withdraw = true; } void setIndependentStudy() { independentstudy = true; } @@ -205,7 +205,7 @@ class Student { int default_allowed_late_days; // registration status - int section; + std::string section; bool audit; bool withdraw; bool independentstudy; diff --git a/zone.cpp b/zone.cpp index 5c19a63..7cc5c0e 100644 --- a/zone.cpp +++ b/zone.cpp @@ -430,7 +430,7 @@ void LoadExamSeatingFile(const std::string &zone_counts_filename, ostr_zone_assignments << std::setw(20) << std::left << l << " "; ostr_zone_assignments << std::setw(15) << std::left << f << " "; ostr_zone_assignments << std::setw(12) << std::left << s->getUserName() << " "; - if (s->getSection()) + if (s->getSection() != "null") ostr_zone_assignments << std::setw(12) << std::left << s->getSection() << " "; else ostr_zone_assignments << std::setw(12) << std::left << "" << " ";