diff --git a/output.cpp b/output.cpp index 73cce94..3bfef33 100644 --- a/output.cpp +++ b/output.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include "student.h" #include "grade.h" @@ -140,6 +141,54 @@ int convertMajor(const std::string &major) { // ========================================================== +std::tuple getCourseDetails() { + const char* reportsDir = std::getenv("REPORTS_DIRECTORY"); + std::string path = std::string(reportsDir) + "/base_url.json"; + std::ifstream i(path); + + nlohmann::json j; + i >> j; + std::string baseUrl = j["base_url"].get(); + std::string term = j["term"].get(); + std::string course = j["course"].get(); + + return {baseUrl, term, course}; +} + +std::string getGradeableType(const std::string &firstUserName, const std::string &gradeableID) { + const char* reportsDir = std::getenv("REPORTS_DIRECTORY"); + + std::string path = std::string(reportsDir) + "/../rainbow_grades/raw_data/all_grades/" + firstUserName + "_summary.json"; + std::ifstream i(path); + + nlohmann::json j; + i >> j; + + std::string gradeableType = ""; + + for (auto it = j.begin(); it != j.end(); ++it) { + if (!it.value().is_array()) { + continue; + } + + for (const auto& item : it.value()) { + if (item.contains("id") && item["id"].is_string() && + item["id"].get() == gradeableID) { + if (item.contains("gradeable_type") && item["gradeable_type"].is_string()) { + gradeableType = item["gradeable_type"].get(); + break; + } + } + } + + if (!gradeableType.empty()) { + break; + } + } + + return gradeableType; +} + class Color { public: Color(int r_=0, int g_=0, int b_=0) : r(r_),g(g_),b(b_) {} @@ -633,18 +682,43 @@ void start_table_output( bool /*for_instructor*/, // ---------------------------- // DETAILS OF EACH GRADEABLE if (DISPLAY_GRADE_DETAILS) { + std::string firstUserName = ""; + for(unsigned int stu = 0; stu < students.size(); stu++){ + Student *this_student = students[stu]; + if(this_student->getUserName() == "AVERAGE" || this_student->getUserName() == "STDDEV"){ + continue; + } + else{ + firstUserName = this_student->getUserName(); + break; + } + } for (unsigned int i = 0; i < ALL_GRADEABLES.size(); i++) { GRADEABLE_ENUM g = ALL_GRADEABLES[i]; for (int j = 0; j < GRADEABLES[g].getCount(); j++) { if (g != GRADEABLE_ENUM::NOTE) { student_data.push_back(counter); } + std::string gradeable_id = GRADEABLES[g].getID(j); std::string gradeable_name = ""; + auto courseDetails = getCourseDetails(); + std::string base_url = std::get<0>(courseDetails); + std::string semester = std::get<1>(courseDetails); + std::string course = std::get<2>(courseDetails); + std::string fullUrl = base_url + "courses/" + semester + "/" + course + "/gradeable/" + gradeable_id; + + std::string gradeableType = getGradeableType(firstUserName, gradeable_id); + if (GRADEABLES[g].hasCorrespondence(gradeable_id)) { gradeable_name = GRADEABLES[g].getCorrespondence(gradeable_id).second; - //gradeable_name = spacify(gradeable_name); + bool checkReleased = GRADEABLES[g].isReleased(gradeable_id); + if(checkReleased && gradeableType == "Electronic File"){ + gradeable_name = gradeable_name + " "; + gradeable_name = "" + gradeable_name + ""; + } } + if (gradeable_name == "") gradeable_name = "future " + tolower(gradeable_to_string(g)) + "";