Skip to content

Commit

Permalink
SAK-43818: Updating a grade stores the total point value as the sorti…
Browse files Browse the repository at this point in the history
…ng value instead of the percentage (sakaiproject#8308)
  • Loading branch information
plukasew authored Jun 23, 2020
1 parent d29d831 commit d12180b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,10 @@
import org.sakaiproject.gradebookng.business.GradeSaveResponse;
import org.sakaiproject.gradebookng.business.util.CourseGradeFormatter;
import org.sakaiproject.gradebookng.business.util.FormatHelper;
import org.sakaiproject.gradebookng.tool.model.GradebookUiSettings;
import org.sakaiproject.gradebookng.tool.pages.GradebookPage;
import org.sakaiproject.gradebookng.business.GradebookNgBusinessService;
import org.sakaiproject.gradebookng.business.model.GbCourseGrade;
import org.sakaiproject.gradebookng.tool.model.GbGradebookData;
import org.sakaiproject.service.gradebook.shared.CategoryScoreData;
import org.sakaiproject.service.gradebook.shared.CourseGrade;
import org.sakaiproject.tool.gradebook.Gradebook;
Expand All @@ -53,20 +54,15 @@ public GradeUpdateAction() {
}

private class GradeUpdateResponse implements ActionResponse {
private String courseGrade;
private String points;
private String[] courseGradeData;
private String categoryScore;
private List<Long> droppedItems;
private boolean isOverride;
private boolean extraCredit;

public GradeUpdateResponse(final boolean extraCredit, final String courseGrade, final String points, final boolean isOverride,
final String categoryScore, List<Long> droppedItems) {
this.courseGrade = courseGrade;
public GradeUpdateResponse(final boolean extraCredit, final String[] courseGradeData, final String categoryScore, List<Long> droppedItems) {
this.courseGradeData = courseGradeData;
this.categoryScore = categoryScore;
this.droppedItems = droppedItems;
this.points = points;
this.isOverride = isOverride;
this.extraCredit = extraCredit;
}

Expand All @@ -79,9 +75,9 @@ public String toJson() {
ObjectNode result = mapper.createObjectNode();

ArrayNode courseGradeArray = mapper.createArrayNode();
courseGradeArray.add(courseGrade);
courseGradeArray.add(points);
courseGradeArray.add(isOverride ? 1 : 0);
for (String data : courseGradeData) {
courseGradeArray.add(data);
}

result.put("courseGrade", courseGradeArray);
result.put("categoryScore", categoryScore);
Expand Down Expand Up @@ -179,29 +175,17 @@ public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget
}

final CourseGrade studentCourseGrade = businessService.getCourseGrade(studentUuid);

boolean isOverride = false;
String grade = "-";
String points = "0";

if (studentCourseGrade != null) {
final GradebookUiSettings uiSettings = page.getUiSettings();
final Gradebook gradebook = businessService.getGradebook();
final CourseGradeFormatter courseGradeFormatter = new CourseGradeFormatter(
gradebook,
page.getCurrentRole(),
businessService.isCourseGradeVisible(businessService.getCurrentUser().getId()),
uiSettings.getShowPoints(),
true);

grade = courseGradeFormatter.format(studentCourseGrade);
if (studentCourseGrade.getPointsEarned() != null) {
points = FormatHelper.formatDoubleToDecimal(studentCourseGrade.getPointsEarned());
}
if (studentCourseGrade.getEnteredGrade() != null) {
isOverride = true;
}
}
final Gradebook gradebook = businessService.getGradebook();
final CourseGradeFormatter courseGradeFormatter = new CourseGradeFormatter(
gradebook,
page.getCurrentRole(),
businessService.isCourseGradeVisible(businessService.getCurrentUser().getId()),
page.getUiSettings().getShowPoints(),
true);
final GbCourseGrade gbcg = new GbCourseGrade(studentCourseGrade);
gbcg.setDisplayString(courseGradeFormatter.format(studentCourseGrade));

final String[] courseGradeData = GbGradebookData.getCourseGradeData(gbcg, gradebook.getSelectedGradeMapping().getGradeMap());

Optional<CategoryScoreData> catData = categoryId == null ?
Optional.empty() : businessService.getCategoryScoreForStudent(Long.valueOf(categoryId), studentUuid, true);
Expand All @@ -212,9 +196,7 @@ public ActionResponse handleEvent(final JsonNode params, final AjaxRequestTarget

return new GradeUpdateResponse(
result.equals(GradeSaveResponse.OVER_LIMIT),
grade,
points,
isOverride,
courseGradeData,
categoryScore,
droppedItems);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,41 +420,39 @@ public int compare(final String a, final String b) {
}
});

for (final GbStudentGradeInfo studentGradeInfo : GbGradebookData.this.studentGradeInfoList) {
// String[0] = A+ (95%) [133/140] -- display string
// String[1] = 95 -- raw percentage for sorting
// String[2] = 1 -- '1' if an override, '0' if calculated
final String[] gradeData = new String[3];

final GbCourseGrade gbCourseGrade = studentGradeInfo.getCourseGrade();
final CourseGrade courseGrade = gbCourseGrade.getCourseGrade();

gradeData[0] = gbCourseGrade.getDisplayString();

if (StringUtils.isNotBlank(courseGrade.getEnteredGrade())) {
gradeData[2] = "1";
} else {
gradeData[2] = "0";
}
for (final GbStudentGradeInfo studentGradeInfo : studentGradeInfoList) {
result.add(getCourseGradeData(studentGradeInfo.getCourseGrade(), courseGradeMap));
}

if (StringUtils.isNotBlank(courseGrade.getEnteredGrade())) {
Double mappedGrade = this.courseGradeMap.get(courseGrade.getEnteredGrade());
if (mappedGrade == null) {
mappedGrade = new Double(0);
}
gradeData[1] = FormatHelper.formatGradeForDisplay(mappedGrade);
} else {
if (courseGrade.getPointsEarned() == null) {
gradeData[1] = "0";
} else {
gradeData[1] = FormatHelper.formatGradeForDisplay(courseGrade.getCalculatedGrade());
}
}
return result;
}

result.add(gradeData);
/**
* Returns the following data about the course grade, needed by the client-side grades table:
* String[0] = A+ (95%) [133/140] -- display string
* String[1] = 95 -- raw percentage for sorting
* String[2] = 1 -- '1' if an override, '0' if calculated
* @param gbCourseGrade the course grade, with an appropriate display string already set
* @param courseGradeMap grading scale map in use
* @return course grade information
*/
public static String[] getCourseGradeData(GbCourseGrade gbCourseGrade, Map<String, Double> courseGradeMap) {
final String[] gradeData = new String[3];
gradeData[0] = gbCourseGrade.getDisplayString();
gradeData[2] = "0";

final CourseGrade courseGrade = gbCourseGrade.getCourseGrade();
if (courseGrade == null) {
gradeData[1] = "";
} else if (StringUtils.isNotBlank(courseGrade.getEnteredGrade())) {
Double mappedGrade = courseGradeMap.get(courseGrade.getEnteredGrade());
gradeData[1] = FormatHelper.formatGradeForDisplay(mappedGrade);
gradeData[2] = "1";
} else {
gradeData[1] = FormatHelper.formatGradeForDisplay(courseGrade.getCalculatedGrade());
}

return result;
return gradeData;
}

private List<Score> gradeList() {
Expand Down

0 comments on commit d12180b

Please sign in to comment.