Skip to content

Commit

Permalink
Alphanumeric registration support (#1)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
holzbh authored and bmcutler committed Jun 14, 2018
1 parent 1df486e commit 409b0bc
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 42 deletions.
4 changes: 2 additions & 2 deletions constants_and_globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern bool LOWEST_TEST_COUNTS_HALF;
extern int QUIZ_NORMALIZE_AND_DROP;

// ==========================================================
extern std::map<int,std::string> sectionNames;
extern std::map<std::string,std::string> sectionNames;
extern std::map<std::string,std::string> sectionColors;


Expand All @@ -62,7 +62,7 @@ extern float MAX_ICLICKER_TOTAL;
// ==========================================================
// PROTOTYPES

bool validSection(int section);
bool validSection(std::string section);


#endif // __CONSTANTS_H__
54 changes: 29 additions & 25 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,25 +74,25 @@ Student* STDDEV_STUDENT_POINTER;
//====================================================================
// INFO ABOUT NUMBER OF SECTIONS

std::map<int,std::string> sectionNames;
std::map<std::string,std::string> sectionNames;
std::map<std::string,std::string> 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;

//return (sectionNames.find(section) != sectionNames.end());
}


std::string sectionName(int section) {
std::map<int,std::string>::const_iterator itr = sectionNames.find(section);
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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -761,7 +762,10 @@ void MakeRosterFile(std::vector<Student*> &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";
Expand Down Expand Up @@ -852,8 +856,7 @@ void processcustomizationfile(std::vector<Student*> &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));
Expand Down Expand Up @@ -1188,18 +1191,18 @@ void load_student_grades(std::vector<Student*> &students) {
} else if (token == "last_update") {
s->setLastUpdate(j[token].get<std::string>());
} else if (token == "registration_section") {
int a;
std::string a;
if(!j[token].is_null()) {
a = j[token].get<int>();
a = j[token].get<std::string>();
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);

Expand Down Expand Up @@ -1502,7 +1505,8 @@ void output_helper(std::vector<Student*> &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;
Expand Down Expand Up @@ -1757,10 +1761,10 @@ void suggest_curves(std::vector<Student*> &students) {
std::cout << gradeable_to_string(g) << " " << gradeable_id << " " << gradeable_name/* << " statistics & suggested curve"*/ << std::endl;
std::vector<float> scores;

std::map<int, int> section_counts;
std::map<std::string, int> 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()]++;
}
Expand Down Expand Up @@ -1797,8 +1801,8 @@ void suggest_curves(std::vector<Student*> &students) {

int total = 0;
std::cout << " ";
for (std::map<int,int>::iterator itr = section_counts.begin(); itr != section_counts.end(); itr++) {
std::cout << " sec#" << itr->first << "=" << itr->second << " ";
for (std::map<std::string,int>::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;
Expand Down
16 changes: 8 additions & 8 deletions output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,26 +256,26 @@ 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;

if (validSection(section))
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 << "<td align=center bgcolor=" << section_color << ">" << section << "&nbsp;(" << section_name << ")</td>";
} else {
ostr << "<td align=center bgcolor=" << section_color << ">&nbsp;</td>" << std::endl;
}
} else {
if (section != 0) {
if (section != "null") {
ostr << "<td align=center>" << section << "</td>";
} else {
ostr << "<td align=center bgcolor=" << section_color << ">&nbsp;</td>" << std::endl;
Expand All @@ -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];
Expand Down Expand Up @@ -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 = "";
Expand Down Expand Up @@ -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];
Expand Down Expand Up @@ -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 = "";
Expand Down
6 changes: 3 additions & 3 deletions student.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Student::Student() {
lefty = false;

// registration status
section = 0;
section = "null";
audit = false;
withdraw = false;
independentstudy = false;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
6 changes: 3 additions & 3 deletions student.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down Expand Up @@ -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; }
Expand Down Expand Up @@ -205,7 +205,7 @@ class Student {
int default_allowed_late_days;

// registration status
int section;
std::string section;
bool audit;
bool withdraw;
bool independentstudy;
Expand Down
2 changes: 1 addition & 1 deletion zone.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 << "" << " ";
Expand Down

0 comments on commit 409b0bc

Please sign in to comment.