Skip to content

Commit

Permalink
Make a Check so that only Electronic File Uploads Have Links
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ryvaru committed Nov 19, 2024
1 parent 10d30cd commit fbef08e
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions output.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,40 @@ std::tuple<std::string, std::string, std::string> 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<std::string>() == gradeableID) {
if (item.contains("gradeable_type") && item["gradeable_type"].is_string()) {
gradeableType = item["gradeable_type"].get<std::string>();
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_) {}
Expand Down Expand Up @@ -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++) {
Expand All @@ -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 + " <i class='fa-solid fa-arrow-up-right-from-square' style='color:blue;'></i>";
gradeable_name = "<a href=\"" + fullUrl + "\" style=\"color:black; text-decoration:none;\" title=\"View Gradeable\">" + gradeable_name + "</a>";
}
Expand Down

0 comments on commit fbef08e

Please sign in to comment.