Skip to content
Browse files

MDL-7571 - shuffles 'mode' before displaying, also moves some code to…

… avoid a duplicate foreach loop
  • Loading branch information...
1 parent 54d264e commit f1591379e8b7ce72c9e48a2b13738c801de172f7 arborrow committed
Showing with 12 additions and 12 deletions.
  1. +12 −12 grade/lib.php
View
24 grade/lib.php
@@ -1530,6 +1530,16 @@ function grade_get_stats($category='all') {
$stats['all']['all_scores'] = $grades_by_student[$student]['student_data']['points'];
$stats['all']['all_scores_weighted'] = $grades_by_student[$student]['student_data']['weighted'];
}
+ if(isset($grades_by_student[$student][$category]['stats'])) {
+ if (isset($stats[$category]['sum'])) {
+ $stats[$category]['sum'] = $stats[$category]['sum'] + $grades_by_student[$student][$category]['stats']['points'];
+ }
+ else {
+ $stats[$category]['sum'] = $grades_by_student[$student][$category]['stats']['points'];
+ }
+ $stats[$category]['items'] = $grades_by_student[$student][$category]['stats']['grade_items'];
+ $stats[$category]['totalpoints'] = $grades_by_student[$student][$category]['stats']['totalpoints'];
+ }
}
$stats['all']['avgsqddev']=$stats['all']['avgsqddev']/$stats['all']['students'];
$stats['all']['avgsqddev_weighted']=$stats['all']['avgsqddev_weighted']/$stats['all']['students'];
@@ -1551,18 +1561,7 @@ function grade_get_stats($category='all') {
{
// get the stats for category
//populate the sum of student points, # items and totalpoints for each category
- foreach($grades_by_student as $student=>$categories) {
- if(isset($grades_by_student[$student][$category]['stats'])) {
- if (isset($stats[$category]['sum'])) {
- $stats[$category]['sum'] = $stats[$category]['sum'] + $grades_by_student[$student][$category]['stats']['points'];
- }
- else {
- $stats[$category]['sum'] = $grades_by_student[$student][$category]['stats']['points'];
- }
- $stats[$category]['items'] = $grades_by_student[$student][$category]['stats']['grade_items'];
- $stats[$category]['totalpoints'] = $grades_by_student[$student][$category]['stats']['totalpoints'];
- }
- }
+
$stats[$category]['students'] = count($grades_by_student);
$stats[$category]['average'] = $stats[$category]['sum']/$stats[$category]['students'];
@@ -1656,6 +1655,7 @@ function grade_get_stats($category='all') {
// returns a comma seperated list of the most common values in $items, $items is expected to be a comma sperated list of numbers
function grade_mode($items) {
$all_scores = explode(',',$items);
+ shuffle($all_scores); //MDL-7571 - shuffle scores
foreach($all_scores as $value) {
if (isset($frequency[$value])) {
$frequency[$value]++;

0 comments on commit f159137

Please sign in to comment.
Something went wrong with that request. Please try again.