From 873760ded90bb48cab57999838a745588a0ab86e Mon Sep 17 00:00:00 2001 From: Jaimos Skriletz Date: Sun, 11 Feb 2024 17:57:52 -0700 Subject: [PATCH] Don't filter out include_in_stats to early. It should still be possible to see the stats or progress of users not included in stats, as they should only be filtered out when computing stats for the whole class or showing progress for a single set. This moves the include_in_stats filter to a more appropriate time. --- lib/WeBWorK/ContentGenerator/Instructor/Stats.pm | 14 ++++++++------ .../Instructor/StudentProgress.pm | 15 ++++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/lib/WeBWorK/ContentGenerator/Instructor/Stats.pm b/lib/WeBWorK/ContentGenerator/Instructor/Stats.pm index efd891303f..b880efe9d1 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/Stats.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/Stats.pm @@ -39,9 +39,9 @@ sub initialize ($c) { # Cache a list of all users except set level proctors and practice users, and restrict to the sections or # recitations that are allowed for the user if such restrictions are defined. This list is sorted by last_name, # then first_name, then user_id. This is used in multiple places in this module, and is guaranteed to be used at - # least once. So it is done here to prevent extra database access. Filter out users not included in stats. + # least once. So it is done here to prevent extra database access. $c->{student_records} = [ - grep { $ce->status_abbrev_has_behavior($_->status, 'include_in_stats') } $db->getUsersWhere( + $db->getUsersWhere( { user_id => [ -and => { not_like => 'set_id:%' }, { not_like => "$ce->{practiceUserPrefix}\%" } ], $ce->{viewable_sections}{$user} || $ce->{viewable_recitations}{$user} @@ -104,14 +104,16 @@ sub siblings ($c) { # Apply the currently selected filter to the student records, and return a reference to the # list of students and a reference to the array of section/recitation filters. sub filter_students ($c) { - my $filter = $c->param('filter') || 'all'; - my @students = - $filter eq 'all' ? @{ $c->{student_records} } : filterRecords($c, 0, [$filter], @{ $c->{student_records} }); + my $ce = $c->ce; + my $filter = $c->param('filter') || 'all'; + my @students = grep { $ce->status_abbrev_has_behavior($_->status, 'include_in_stats') } @{ $c->{student_records} }; # Change visible name of the first 'all' filter. - my $filters = getFiltersForClass($c, [ 'section', 'recitation' ], @{ $c->{student_records} }); + my $filters = getFiltersForClass($c, [ 'section', 'recitation' ], @students); $filters->[0][0] = $c->maketext('All students'); + @students = filterRecords($c, 0, [$filter], @students) unless $filter eq 'all'; + return (\@students, $filters); } diff --git a/lib/WeBWorK/ContentGenerator/Instructor/StudentProgress.pm b/lib/WeBWorK/ContentGenerator/Instructor/StudentProgress.pm index 45af2e115c..e4868ac791 100644 --- a/lib/WeBWorK/ContentGenerator/Instructor/StudentProgress.pm +++ b/lib/WeBWorK/ContentGenerator/Instructor/StudentProgress.pm @@ -37,9 +37,9 @@ sub initialize ($c) { # Cache a list of all users except set level proctors and practice users, and restrict to the sections or # recitations that are allowed for the user if such restrictions are defined. This list is sorted by last_name, # then first_name, then user_id. This is used in multiple places in this module, and is guaranteed to be used at - # least once. So it is done here to prevent extra database access. Filter out users not included in stats. + # least once. So it is done here to prevent extra database access. $c->{student_records} = [ - grep { $ce->status_abbrev_has_behavior($_->status, 'include_in_stats') } $db->getUsersWhere( + $db->getUsersWhere( { user_id => [ -and => { not_like => 'set_id:%' }, { not_like => "$ce->{practiceUserPrefix}\%" } ], $ce->{viewable_sections}{$user} || $ce->{viewable_recitations}{$user} @@ -116,20 +116,21 @@ sub displaySets ($c) { : (date => 0, testtime => 0, timeleft => 0, problems => 1, section => 1, recit => 1, login => 1); my $showBestOnly = $setIsVersioned ? $c->param('show_best_only') : 0; - my $filter = $c->param('filter') || 'all'; + # Only show students who are included in stats. my @student_records = - $filter eq 'all' ? @{ $c->{student_records} } : filterRecords($c, 0, [$filter], @{ $c->{student_records} }); + grep { $ce->status_abbrev_has_behavior($_->status, 'include_in_stats') } @{ $c->{student_records} }; # Change visible name of the first 'all' filter. - my $filters = getFiltersForClass($c, [ 'section', 'recitation' ], @{ $c->{student_records} }); + my $filter = $c->param('filter') || 'all'; + my $filters = getFiltersForClass($c, [ 'section', 'recitation' ], @student_records); $filters->[0][0] = $c->maketext('All students'); + @student_records = filterRecords($c, 0, [$filter], @student_records) unless $filter eq 'all'; + my @score_list; my @user_set_list; for my $studentRecord (@student_records) { - next unless $ce->status_abbrev_has_behavior($studentRecord->status, 'include_in_stats'); - my $studentName = $studentRecord->user_id; my ($allSetVersionNames, $notAssignedSet) = list_set_versions($db, $studentName, $c->stash('setID'), $setIsVersioned);