Skip to content

Commit

Permalink
Add option to allow instructors to clamp maximum percentage score (#26)
Browse files Browse the repository at this point in the history
* Added maximum percentage score option

* Simplify code, allow to work with sorted weights.

* updated new variable name to bucket_percentage_upper_clamp
  • Loading branch information
emaicus authored Apr 7, 2020
1 parent b6a232c commit fd4cab8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
8 changes: 8 additions & 0 deletions gradeable.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Gradeable {
// ACCESSORS
int getCount() const { return count; }
float getPercent() const { return percent; }
float getBucketPercentageUpperClamp() const { return this->bucket_percentage_upper_clamp; }
float getMaximum() const {
if (maximums.size() == 0) return 0;
assert (maximums.size() > 0);
Expand Down Expand Up @@ -162,6 +163,12 @@ class Gradeable {
return index;
}

// Set the max percentage that can be received for a gradeable type.
// If the value is less than 0, it should be ignored.
void setBucketPercentageUpperClamp(float bucket_percentage_upper_clamp) {
this->bucket_percentage_upper_clamp = bucket_percentage_upper_clamp;
}

void setCorrespondenceName(const std::string& id, const std::string& name) {
assert (hasCorrespondence(id));
assert (correspondences[id].second == "");
Expand Down Expand Up @@ -215,6 +222,7 @@ class Gradeable {
int count;
float percent;
int remove_lowest;
float bucket_percentage_upper_clamp;
std::map<std::string,std::pair<int,std::string> > correspondences;
std::map<std::string,float> maximums;
std::map<std::string,float> scale_maximums;
Expand Down
10 changes: 10 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,16 @@ void preprocesscustomizationfile(const std::string &now_string,
GRADEABLES[g].setRemoveLowest(num);
ALL_GRADEABLES.push_back(g);

// Used to clamp extra credit. For example, if there are 3 gradeables of a category, each worth 1/2
// percentage of a total score, a student could earn 1.5x the value for the gradeable category.
// We can clamp that by setting bucket_percentage_upper_clamp to a value less than 1.5.
nlohmann::json::iterator upper_clamp_itr = one_gradeable_type.find("bucket_percentage_upper_clamp");
float bucket_percentage_upper_clamp = -1;
if (upper_clamp_itr != one_gradeable_type.end()){
bucket_percentage_upper_clamp = upper_clamp_itr->get<float>();
}
GRADEABLES[g].setBucketPercentageUpperClamp(bucket_percentage_upper_clamp);

//Parse out the min grade required for passing in this category
float overall_cutoff = one_gradeable_type.value("overall_cutoff", 0.0);
assert(0.0 <= overall_cutoff && overall_cutoff <= 1.0);
Expand Down
10 changes: 5 additions & 5 deletions student.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,12 +207,12 @@ float Student::GradeablePercent(GRADEABLE_ENUM g) const {
}
}

if(GRADEABLES[g].hasSortedWeight()){
return 100*sum;
}
else {
return 100 * GRADEABLES[g].getPercent() * sum;
float percentage = GRADEABLES[g].hasSortedWeight() ? sum : GRADEABLES[g].getPercent() * sum;
float percentage_upper_clamp = GRADEABLES[g].getBucketPercentageUpperClamp();
if (percentage_upper_clamp > 0) {
percentage = std::min(percentage, percentage_upper_clamp);
}
return 100 * percentage;
}


Expand Down

0 comments on commit fd4cab8

Please sign in to comment.