From fbef08eef0b449ec4978d9f9c05fb69500e1f3c1 Mon Sep 17 00:00:00 2001 From: Ryan Varughese Date: Tue, 19 Nov 2024 02:59:24 -0500 Subject: [PATCH] Make a Check so that only Electronic File Uploads Have Links The logic here is that starting from DISPLAY_GRADE_DETAILS, I find a random user (the first user after AVERAGE AND STDDEV, could be the instructor who opened the course). Then, I call the getGreadeableType function to go to their summary json and scan for the gradeable id. If the gradeable id is found, I return the value of gradeable_type. --- output.cpp | 50 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/output.cpp b/output.cpp index d45dd94..d270859 100644 --- a/output.cpp +++ b/output.cpp @@ -155,6 +155,40 @@ std::tuple getCourseDetails() { 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_) {} @@ -647,6 +681,17 @@ 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++) { @@ -662,11 +707,12 @@ void start_table_output( bool /*for_instructor*/, 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; bool checkReleased = GRADEABLES[g].isReleased(gradeable_id); - if(checkReleased){ - // g != GRADEABLE_ENUM::LAB ... + if(checkReleased && gradeableType == "Electronic File"){ gradeable_name = gradeable_name + " "; gradeable_name = "" + gradeable_name + ""; }