Skip to content

Commit

Permalink
Feature/refresh stats (sakaiproject#5221)
Browse files Browse the repository at this point in the history
* #3432 Make sure mapped grades are not null when they are collected.

Mapped grades will be null if the student doesn't have a course grade yet.

* Updated stats section

Moved the stats section into a wicket container.
Fixed the calculateStatistics method by filtering out empty grades.

Issue: SAK-33473
  • Loading branch information
amiedavis authored and steveswinsburg committed Jan 16, 2018
1 parent a740b40 commit b0d8f92
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,26 @@ <h3 class="panel-title">
</div>

<!-- other stats -->
<dl class="dl-horizontal">
<wicket:enclosure>
<dt><wicket:message key="label.statistics.coursegrade.averagegpa"></wicket:message></dt>
<dd wicket:id="averagegpa"></dd>
</wicket:enclosure>
<dt><wicket:message key="label.statistics.coursegrade.average"></wicket:message></dt>
<dd wicket:id="average"></dd>
<dt><wicket:message key="label.statistics.coursegrade.median"></wicket:message></dt>
<dd wicket:id="median"></dd>
<dt><wicket:message key="label.statistics.coursegrade.deviation"></wicket:message></dt>
<dd wicket:id="deviation"></dd>
<dt><wicket:message key="label.statistics.coursegrade.lowest"></wicket:message></dt>
<dd wicket:id="lowest"></dd>
<dt><wicket:message key="label.statistics.coursegrade.highest"></wicket:message></dt>
<dd wicket:id="highest"></dd>
<dt><wicket:message key="label.statistics.coursegrade.graded"></wicket:message></dt>
<dd wicket:id="graded"></dd>
</dl>
<div wicket:id="statsWrap">
<dl class="dl-horizontal">
<wicket:enclosure>
<dt><wicket:message key="label.statistics.coursegrade.averagegpa"></wicket:message></dt>
<dd wicket:id="averagegpa"></dd>
</wicket:enclosure>
<dt><wicket:message key="label.statistics.coursegrade.average"></wicket:message></dt>
<dd wicket:id="average"></dd>
<dt><wicket:message key="label.statistics.coursegrade.median"></wicket:message></dt>
<dd wicket:id="median"></dd>
<dt><wicket:message key="label.statistics.coursegrade.deviation"></wicket:message></dt>
<dd wicket:id="deviation"></dd>
<dt><wicket:message key="label.statistics.coursegrade.lowest"></wicket:message></dt>
<dd wicket:id="lowest"></dd>
<dt><wicket:message key="label.statistics.coursegrade.highest"></wicket:message></dt>
<dd wicket:id="highest"></dd>
<dt><wicket:message key="label.statistics.coursegrade.graded"></wicket:message></dt>
<dd wicket:id="graded"></dd>
</dl>
</div>

<div class="messageWarning"><wicket:message key="settingspage.gradingschema.refresh" /></div>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,12 @@ public class SettingsGradingSchemaPanel extends BasePanel implements IFormModelU
IModel<GbSettings> model;

WebMarkupContainer schemaWrap;
WebMarkupContainer statsWrap;
ListView<GbGradingSchemaEntry> schemaView;
List<GradeMappingDefinition> gradeMappings;
private boolean expanded;
String gradingSchemaName;
DescriptiveStatistics statistics;

/**
* This is the currently PERSISTED grade mapping id that is persisted for this gradebook
Expand Down Expand Up @@ -111,6 +113,12 @@ public void onInitialize() {
// setup the grading scale schema entries
this.model.getObject().setGradingSchemaEntries(getGradingSchemaEntries());

// get the course grade map
this.courseGradeMap = getCourseGrades();

// get the total number of course grades
this.total = getTotalCourseGrades(this.courseGradeMap);

// create map of grading scales to use for the dropdown
final Map<String, String> gradeMappingMap = new LinkedHashMap<>();
for (final GradeMappingDefinition gradeMapping : this.gradeMappings) {
Expand Down Expand Up @@ -222,9 +230,6 @@ protected void onUpdate(final AjaxRequestTarget target) {
}
});

// get the course grade map as we are about to use it a lot
this.courseGradeMap = getCourseGrades();

// if there are no grades, display message instead of chart
settingsGradingSchemaPanel
.add(new Label("noStudentsWithGradesMessage", new ResourceModel("settingspage.gradingschema.emptychart")) {
Expand All @@ -238,22 +243,26 @@ public boolean isVisible() {

// other stats
// TODO this could be in a panel/fragment of its own
final DescriptiveStatistics stats = calculateStatistics();
this.statsWrap = new WebMarkupContainer("statsWrap");
this.statsWrap.setOutputMarkupId(true);
settingsGradingSchemaPanel.add(this.statsWrap);

this.statistics = calculateStatistics();

settingsGradingSchemaPanel.add(new Label("averagegpa", getAverageGPA()) {
this.statsWrap.add(new Label("averagegpa", getAverageGPA()) {
private static final long serialVersionUID = 1L;

@Override
public boolean isVisible() {
return StringUtils.equals(SettingsGradingSchemaPanel.this.gradingSchemaName, "Grade Points");
}
});
settingsGradingSchemaPanel.add(new Label("average", getMean(stats)));
settingsGradingSchemaPanel.add(new Label("median", getMedian(stats)));
settingsGradingSchemaPanel.add(new Label("lowest", getMin(stats)));
settingsGradingSchemaPanel.add(new Label("highest", getMax(stats)));
settingsGradingSchemaPanel.add(new Label("deviation", getStandardDeviation(stats)));
settingsGradingSchemaPanel.add(new Label("graded", String.valueOf(this.total)));
this.statsWrap.add(new Label("average", getMean(this.statistics)));
this.statsWrap.add(new Label("median", getMedian(this.statistics)));
this.statsWrap.add(new Label("lowest", getMin(this.statistics)));
this.statsWrap.add(new Label("highest", getMax(this.statistics)));
this.statsWrap.add(new Label("deviation", getStandardDeviation(this.statistics)));
this.statsWrap.add(new Label("graded", String.valueOf(this.total)));

// if there are course grade overrides, add the list of students
final List<GbUser> usersWithOverrides = getStudentsWithCourseGradeOverrides();
Expand Down Expand Up @@ -395,13 +404,14 @@ private Map<String, CourseGrade> getCourseGrades() {
}

/**
* Calculates stats based on the calculated course grade values
* Calculates stats based on the calculated course grade values, excluding any empty grades
*
* @return
* @return {@link DescriptiveStatistics}
*/
private DescriptiveStatistics calculateStatistics() {

final List<Double> grades = this.courseGradeMap.values().stream().map(c -> NumberUtils.toDouble(c.getCalculatedGrade()))
final List<Double> grades = this.courseGradeMap.values().stream().filter(c -> StringUtils.isNotBlank(c.getMappedGrade()))
.map(c -> NumberUtils.toDouble(c.getCalculatedGrade()))
.collect(Collectors.toList());

final DescriptiveStatistics stats = new DescriptiveStatistics();
Expand Down Expand Up @@ -521,10 +531,18 @@ private Map<String, Double> getGPAScoresMap() {
*/
private List<GbGradingSchemaEntry> asList(final Map<String, Double> bottomPercents) {
final List<GbGradingSchemaEntry> rval = new ArrayList<>();
for (final Map.Entry<String, Double> entry : bottomPercents.entrySet()) {
rval.add(new GbGradingSchemaEntry(entry.getKey(), entry.getValue()));
}
bottomPercents.forEach((k, v) -> rval.add(new GbGradingSchemaEntry(k, v)));
return rval;
}

/**
* Get the total number of course grades, excluding empty grades
*
* @param map
* @return
*/
private int getTotalCourseGrades(final Map<String, CourseGrade> map) {
return map.values().stream().filter(c -> StringUtils.isNotBlank(c.getMappedGrade()))
.collect(Collectors.toList()).size();
}
}

0 comments on commit b0d8f92

Please sign in to comment.