--- loncom/interface/lonquickgrades.pm 2021/12/14 02:44:05 1.49.6.8 +++ loncom/interface/lonquickgrades.pm 2017/12/18 23:51:14 1.112 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # Quick Student Grades Display # -# $Id: lonquickgrades.pm,v 1.49.6.8 2021/12/14 02:44:05 raeburn Exp $ +# $Id: lonquickgrades.pm,v 1.112 2017/12/18 23:51:14 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,8 +35,26 @@ use Apache::loncommon; use Apache::lonlocal; use Apache::lonnet; use Apache::grades; +use Apache::loncoursedata; +use Apache::lonstudentassessment; use Apache::lonuserstate; +use Time::HiRes; +use Spreadsheet::WriteExcel; +use Spreadsheet::WriteExcel::Utility(); +# +# Excel data +# +my $excel_sheet; +my $excel_workbook; +my $filename; +my $format; +my $request_aborted; +my $header_row; +my $cols_output; +my %prog_state; + + sub handler { my $r = shift; return real_handler($r); @@ -60,32 +78,14 @@ sub real_handler { my $cangrade=&Apache::lonnet::allowed('mgr'); my $showPoints = - $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard'; + (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard') + || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories')); my $reinitresult; - if ($env{'request.course.id'}) { - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; - my $clientip = &Apache::lonnet::get_requestor_ip($r); - my ($blocked,$blocktext) = - &Apache::loncommon::blocking_status('grades',$clientip,$cnum,$cdom); - if ($blocked) { - my $checkrole = "cm./$cdom/$cnum"; - if ($env{'request.course.sec'} ne '') { - $checkrole .= "/$env{'request.course.sec'}"; - } - unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) && - ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) { - &grades_blocked($r,$blocktext,$showPoints); - return OK; - } - } - } - unless ($cangrade) { # Check for critical messages and redirect if present. - my ($redirect,$url) = &Apache::loncommon::critical_redirect(300); + my ($redirect,$url) = &Apache::loncommon::critical_redirect(300,'grades'); if ($redirect) { &Apache::loncommon::content_type($r,'text/html'); $r->header_out(Location => $url); @@ -111,13 +111,13 @@ sub real_handler { my $preamble = '
'.&mt('Sections').''. + &Apache::loncommon::help_open_topic("Chart_Sections"). + ' | '. + ''.&mt('Groups').''. + ' | '. + ''.&mt('Student Data').''. + &Apache::loncommon::help_open_topic("Chart_Student_Data"). + ' | '. + ''.&mt('Access Status').''. + &Apache::loncommon::help_open_topic("Chart_Enrollment_Status"). + ' | '. + ''.&mt('Output Format').''. + &Apache::loncommon::help_open_topic("Chart_Output_Formats"). + ' | |
'."\n". + &Apache::lonstatistics::SectionSelect('Section','multiple',5). + ' | '. + &Apache::lonstatistics::GroupSelect('Group','multiple',5). + ' | '. + &Apache::lonstatistics::StudentDataSelect('StudentData','multiple',5,undef). + ' | '."\n". + &Apache::lonhtmlcommon::StatusOptions(undef,undef,5). + ' | '."\n". + &Apache::lonstudentassessment::CreateAndParseOutputSelector(). + ' | '. + ''. + ' |
'.&mt("Unknown Student/Employee ID: [_1]",$stdid).'
'); $stdid=''; } - if (($uname eq '') && ($udom eq '')) { - $uname = $env{'user.name'}; - $udom = $env{'user.domain'}; - } $r->print('\n"); } - my $requrl = $r->uri; - $env{'user.error.msg'} = "$requrl:bre:0:0:Navmap initialization failed."; - return HTTP_NOT_ACCEPTABLE; + &outputTable($r,$showPoints,$notshowTotals, + $navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted); } if ($cangrade) { $r->print("\n\n"); } &endGradeScreen($r); return OK; + +} + +sub getStudentCatGrade { + my ($uname,$udom,%categories)=@_; + my ($navmap,$totalParts,$totalPossible,$totalRight,$totalAttempted,$topLevelParts,$topLevelRight,$topLevelAttempted)= + &getData(1,$uname,$udom); + return &output_category_table(undef,0,$navmap,0,%categories); +} + +sub getAllStudentData { + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; + + my %categories=&Apache::lonnet::dump('grading_categories',$cdom,$cnum); + + my $classlist = &Apache::loncoursedata::get_classlist(); + + my $statusidx = &Apache::loncoursedata::CL_STATUS(); + my $usernameidx = &Apache::loncoursedata::CL_SNAME(); + my $domainidx = &Apache::loncoursedata::CL_SDOM(); + my $fullnameidx = &Apache::loncoursedata::CL_FULLNAME(); + + foreach my $key (keys(%{$classlist})) { + my $student = $classlist->{$key}; + my $perc=&getStudentCatGrade($classlist->{$student}->[$usernameidx], + $classlist->{$student}->[$domainidx], + %categories); + } +} + +sub startpage { + my ($r,$showPoints) = @_; + my $title = "Grading and Statistics";#$showPoints ? "Points Display" : "Completed Problems Display"; + my $brcrum = [{href=>"/adm/quickgrades",text => "Points Display"}]; + $r->print(&Apache::loncommon::start_page($title,undef, + {'bread_crumbs' => $brcrum}) + ); +} + +sub startGradeScreen { + my ($r,$mode)=@_; + + my $showPoints = + $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'standard'; + my $notshowSPRSlink = + (($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'external') + || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals') + || ($env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories')); + my $notshowTotals= + $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'externalnototals'; + my $showCategories= + $env{'course.'.$env{'request.course.id'}.'.grading'} eq 'categories'; + + my $allowed_to_view = &Apache::lonnet::allowed('vgr',$env{'request.course.id'}); + my $allowed_to_edit = &Apache::lonnet::allowed('mgr',$env{'request.course.id'}); + + if ($allowed_to_view) { + my @notes; + push(@notes,&mt('Students do not see total points.')) if ($notshowTotals); + push(@notes,&mt('Students do not see link to spreadsheet.')) if ($notshowSPRSlink); + push(@notes,&mt('Students will see points based on problem weights.')) if ($showPoints); + push(@notes,&mt('Students will see points based on categories.')) if ($showCategories); + push(@notes, &Apache::lonhtmlcommon::coursepreflink(&mt('Grade display settings'),'grading')); + $r->print(&Apache::loncommon::head_subbox(join(' ',@notes))); + } + + + $r->print("\n".''.&mt('Total raw points: [_1]/[_2]',&numberout($totalcorrect),&numberout($totalpossible)).'
'); + $r->print(''.&mt('Adjusted raw points: [_1]/[_2]',&numberout($totalcorrect),&numberout($totalpossible)).'
'); + } + + +# Calculation + if ($output) { $r->print(''.&mt('Calculated points: [_1]/[_2]',&numberout($totalcorrect),&numberout($totalpossible)).'
'); + $r->print(''); + if ($type eq 'percent') { + my $perc='---'; + if ($totalpossible) { + $perc=100.*$totalcorrect/$totalpossible; + } + $r->print(&mt('[_1] percent',&numberout($perc))); + } else { + $r->print(&mt('[_1]/[_2] points',&numberout($totalcorrect),&numberout($totalpossible))); + } + $r->print('
'); + } + if ($output) { $r->print('