--- loncom/homework/grades.pm 2002/11/10 15:44:38 1.58 +++ loncom/homework/grades.pm 2003/02/28 21:06:28 1.70 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.58 2002/11/10 15:44:38 albertel Exp $ +# $Id: grades.pm,v 1.70 2003/02/28 21:06:28 ng Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,6 +31,8 @@ # 8/20 Gerd Kortemeyer # Year 2002 # June-August H.K. Ng +# Year 2003 +# February H.K. Ng # package Apache::grades; @@ -39,12 +41,13 @@ use Apache::style; use Apache::lonxml; use Apache::lonnet; use Apache::loncommon; +use Apache::lonnavmaps; use Apache::lonhomework; use Apache::loncoursedata; use Apache::lonmsg qw(:user_normal_msg); use Apache::Constants qw(:common); -# ----- These first few routines are general use routines.----- +# ----- These first few routines are general use routines.---- # # --- Retrieve the parts that matches stores_\d+ from the metadata file.--- sub getpartlist { @@ -269,6 +272,10 @@ sub verifyreceipt { return $string.&show_grading_menu_form($symb,$url); } +# +# Pick student and page/sequence for manual grading + + #--- This is called by a number of programs. #--- Called from the Grading Menu - View/Grade an individual student #--- Also called directly when one clicks on the subm button @@ -293,12 +300,7 @@ sub listStudents { } $result.=''; - my $viewgrade; - if ($ENV{'form.handgrade'} eq 'yes') { - $viewgrade = 'View/Grade'; - } else { - $viewgrade = 'View'; - } + my $viewgrade = $ENV{'form.handgrade'} eq 'yes' ? 'View/Grade' : 'View'; $result='

 '. $viewgrade. @@ -672,21 +674,21 @@ sub sub_page_js { pWin.document.write(""); pWin.document.write("Subject"); pWin.document.write(""); - pWin.document.write(""); + pWin.document.write(""); } function displaySavedMsg(ctr,msg,shwsel) { pWin.document.write(""); pWin.document.write(""+ctr+""); pWin.document.write(""); - pWin.document.write(""); + pWin.document.write(""); } function newMsg(newmsg,shwsel) { pWin.document.write(""); pWin.document.write("New"); pWin.document.write(""); - pWin.document.write(""); + pWin.document.write(""); } function msgTail() { @@ -846,7 +848,7 @@ sub submission { # option to display problem, only once else it cause problems # with the form later since the problem has a form. - if ($ENV{'form.vProb'} eq 'yes') { + if ($ENV{'form.vProb'} eq 'yes' or !$ENV{'form.vProb'}) { &show_problem($request,$symb,$uname,$udom,0); } @@ -1021,7 +1023,12 @@ KEYWORDS my ($ressub,$subval) = split(/:/,$_,2); $lastsubonly.='Part '. $partid.' ( ID '.$respid. - ' )   Answer: '. + ' )   '. + ($record{"resource.$partid.$respid.uploadedurl"}? + ' File uploaded by student Like all files provided by users, this file may contain virusses
':''). + 'Answer: '. &keywords_highlight($subval).''."\n" if ($ENV{'form.lastSub'} eq 'lastonly' || ($ENV{'form.lastSub'} eq 'hdgrade' && @@ -1073,53 +1080,9 @@ KEYWORDS $seen{$partid}++; next if ($$handgrade{$_} =~ /:no$/); push @partlist,$partid; - my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname); - my $wgtmsg = ($wgt > 0 ? '(problem weight)' : - 'problem weight assigned by computer'); - $wgt = ($wgt > 0 ? $wgt : '1'); - my $score = ($record{'resource.'.$partid.'.awarded'} eq '' ? - '' : $record{'resource.'.$partid.'.awarded'}*$wgt); - $result=''; - $result.=''; - $result.=''."\n"; - $result.='
Part '.$partid.' Points: '; - my $ctr = 0; - $result.=''; # display radio buttons in a nice table 10 across - while ($ctr<=$wgt) { - $result.= '\n"; - $result.=(($ctr+1)%10 == 0 ? '' : ''); - $ctr++; - } - $result.='
'.$ctr."
'; + $result=&gradeBox($symb,$uname,$udom,$counter,$partid,\%record); - $result.='
 or /'.$wgt.' '.$wgtmsg.' '; - - $result.=''; - } else { - $result.=''. - ''; - } - $result.="  \n"; - $result.=''; - $result.='
'."\n"; $request->print($result); } $result=' '. + $weight{$partid}.')"> '. ''. ''."\n"; $ctsparts++; @@ -1725,8 +1688,8 @@ sub viewstudentgrade { ''.$fullname.''. ''.$uname.''.$udom.''."\n"; - foreach my $part (@$parts) { - my ($part,$type) = &split_part_type($part); + foreach my $apart (@$parts) { + my ($part,$type) = &split_part_type($apart); my $score=$record{"resource.$part.$type"}; if ($type eq 'awarded') { my $pts = $score eq '' ? '' : $score*$$weight{$part}; @@ -2193,6 +2156,7 @@ sub gradingmenu { $result.=&view_edit_entire_class_form($symb,$url).'
'; $result.=&upcsvScores_form($symb,$url).'
'; $result.=&viewGradeaStu_form($symb,$url,$resptype,$hdgrade).'
'; + $result.=&gradeByPage_form($symb,$url,$resptype,$hdgrade).'
'; $result.=&verifyReceipt_form($symb,$url) if ((&Apache::lonnet::allowed('mgr',$ENV{'request.course.id'})) && ($symb)); @@ -2264,12 +2228,7 @@ sub viewGradeaStu_form { my $result.='
'."\n"; $result.=''."\n"; + $result.=($handgrade eq 'yes' ? 'View/Grade' : 'View').' an Individual Student\'s Submission'."\n"; $result.='
'."\n"; $result.=' '; - if ($handgrade eq 'yes') { - $result.="View/Grade "; - } else { - $result.="View "; - } - $result.='an Individual Student\'s Submission
'."\n"; $result.='
'."\n". ''."\n". @@ -2305,6 +2264,335 @@ sub viewGradeaStu_form { return $result; } +#--- Handgrading problems by page/sequence for each student --- +sub gradeByPage_form { + my ($symb,$url,$response,$handgrade) = @_; + my ($classlist,$sections) = &getclasslist('all','0'); + my $result.='
'."\n"; + $result.=''."\n"; + $result.='
'."\n"; + $result.=' '; + $result.='Handgrade an Individual Student\'s by Page/Sequence
'."\n"; + $result.=''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n"; + + $result.=' Select section: '."\n"; + + $result.='
 '."\n".''."\n"; + $result.='
'."\n"; + $result.='
'."\n"; + return $result; +} + + +sub pickStudentPage { + my ($request) = shift; + + $request->print(< + +function checkPickOne(formname) { + var user = radioSelection(formname.student); + if (user == null) { + alert("Please select the student you wish to grade."); + return; + } + var ptr = pullDownSelection(formname.selectpage); + formname.page.value = formname.eval("page"+ptr).value; + formname.title.value = formname.eval("title"+ptr).value; + formname.submit(); +} + +function radioSelection(radioButton) { + var selection=null; + for (var i=0; i +LISTJAVASCRIPT + + my ($symb,$url) = &get_symb_and_url(); + my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"}; + my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"}; + my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'}; + + my $result='

 '. + 'Manual Grading by Page or Sequence

'; + + my ($pagepath,$pagename,$type,$mapId) = ($symb =~ /(.*\/)(.*?\.(page|sequence))___(\d+)___/); + my $curtitle = &Apache::lonnet::metadata($pagepath.$pagename,'title'); + + $result.='
'."
\n"; + $result.=' Problems from: '."
\n"; + $ctr=0; + foreach (@$titles) { + my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/); + $result.=''."\n"; + $result.=''."\n"; + $ctr++; + } + $result.=''."\n"; + $result.=''."\n"; + +# $result.=' View Problems: no '."\n". +# ' yes '."
\n"; +# $result.=' Submission Details: '. +# ' last sub only'."\n". +# ' all details'."\n"; + $result.=''."\n". + ''."\n". + ''."\n". + ''."

\n"; + $request->print($result); + + my $studentTable.=' Select a Student you wish to grade
'. + '
'. + ''. + ''. + ''. + ''. + ''; + + my (undef,undef,$fullname) = &getclasslist($getsec,'0'); + my $ptr = 1; + foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) { + my ($uname,$udom) = split(/:/,$student); + $studentTable.=($ptr%4 == 1 ? '' : ''); + $ptr++; + } + $studentTable.='
 Fullname (username) Fullname (username) Fullname (username) Fullname (username)
' : ''); + $studentTable.=' '.$$fullname{$student}. + ' ('.$uname.($udom eq $cdom ? '':':'.$udom).')'."\n"; + $studentTable.=($ptr%4 == 0 ? '
   ' if ($ptr%4 == 2); + $studentTable.='  ' if ($ptr%4 == 3); + $studentTable.=' ' if ($ptr%4 == 0); + $studentTable.='
'."\n"; + $studentTable.='
 
'."\n"; + + $studentTable.=&show_grading_menu_form($symb,$url); + $request->print($studentTable); + + return ''; +} + +sub getSymbMap { + my $navmap = Apache::lonnavmaps::navmap-> new( + $ENV{'request.course.fn'}.'.db', + $ENV{'request.course.fn'}.'_parms.db',1, 1); + + my $res = $navmap->firstResource(); # temp resource to access constants + $navmap->init(); + + # End navmap using boilerplate + + my $iterator = $navmap->getIterator(undef, undef, undef, 1); + my $depth = 1; + $iterator->next(); # ignore first BEGIN_MAP + my $curRes = $iterator->next(); + + my %symbx = (); + my @titles = (); + my $minder=0; + while ($depth > 0) { + if ($curRes == $iterator->BEGIN_MAP()) {$depth++;} + if ($curRes == $iterator->END_MAP()) { $depth--; } + + if (ref($curRes) && $curRes->is_map()) { + my $title = $curRes->compTitle(); + push @titles,$minder.'.'.$title; # minder, just in case two titles are identical + $symbx{$minder.'.'.$title} = $curRes->symb(); + $minder++; + } + $curRes = $iterator->next(); + } + + $navmap->untieHashes(); + return \@titles,\%symbx; +} + +sub displayPage { + my ($request) = shift; + + my $cdom = $ENV{"course.$ENV{'request.course.id'}.domain"}; + my $cnum = $ENV{"course.$ENV{'request.course.id'}.num"}; + my $getsec = $ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'}; + my $pageTitle = $ENV{'form.page'}; + my (undef,undef,$fullname) = &getclasslist($getsec,'0'); + my ($uname,$udom) = split(/:/,$ENV{'form.student'}); + my ($idx,$showtitle) = ($pageTitle =~ /(\d+)\.(.*)/); + + my $result='

 '.$ENV{'form.title'}.'

'; + $result.='

 Student: '.$$fullname{$ENV{'form.student'}}. + ' ('.$uname.($udom eq $cdom ? '':':'.$udom).')

'."\n"; + + my $navmap = Apache::lonnavmaps::navmap-> new( + $ENV{'request.course.fn'}.'.db', + $ENV{'request.course.fn'}.'_parms.db',1, 1); + my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'}); + my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps + + my $iterator = $navmap->getIterator($map->map_start(), + $map->map_finish()); + + my $depth = 1; + $iterator->next(); # skip the first BEGIN_MAP + my $curRes = $iterator->next(); # for "current resource" + my %symbx = (); + my @titles = (); + my %parts = (); + my $ctr=0; + my $minder=0; + while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop + if($curRes == $iterator->BEGIN_MAP) { $depth++; } + if($curRes == $iterator->END_MAP) { $depth++; } + + if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) { + my $parts = $curRes->parts(); + my $title = $curRes->compTitle(); + push @titles,$minder.'.'.$title; # minder, just in case two titles are identical + if (scalar(@{$parts}) > 1) { shift @{$parts}; } + $parts{$minder.'.'.$title} = join '::',@{$parts}; + $symbx{$minder.'.'.$title} = $curRes->symb(); + $minder++; + + } + $curRes = $iterator->next(); + $ctr++; + } + + + $navmap->init(); + $request->print($result); + &sub_page_js($request); + + my $studentTable='
'."\n". + ''."\n". + ''."\n". + ''."\n". + ''."\n"; + + $studentTable.= + '
'. + ''. + ''. + ''. + ''. + ''; + my $question=1; + foreach (@titles) { + my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/); + my @parts = split(/::/,$parts{$_}); + $studentTable.=''; + $studentTable.=''; + $studentTable.=''; + + my %record = &Apache::lonnet::restore($symbx{$_},$ENV{'request.course.id'},$udom,$uname); + $studentTable.=''; + + } + + $studentTable.='
 No  Title Answer Grade
'.$question. + (scalar(@parts) == 1 ? '' : '
('.scalar(@parts).' parts)').'
 '.$showtitle.'  '. + &Apache::loncommon::get_student_answers($symbx{$_},$uname,$udom,$ENV{'request.course.id'}).' '; + foreach my $partid (@parts) { + $studentTable.=&gradeBox($symbx{$_},$uname,$udom,$question,$partid,\%record); + $question++; + } + $studentTable.='
'; + $studentTable.='
'; + + $request->print($studentTable); + + return ''; +} + +sub gradeBox { + my ($symb,$uname,$udom,$counter,$partid,$record) = @_; + my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb,$udom,$uname); + my $wgtmsg = ($wgt > 0 ? '(problem weight)' : + 'problem weight assigned by computer'); + $wgt = ($wgt > 0 ? $wgt : '1'); + my $score = ($$record{'resource.'.$partid.'.awarded'} eq '' ? + '' : $$record{'resource.'.$partid.'.awarded'}*$wgt); + my $result=''; + $result.=''; + $result.=''."\n"; + $result.='
Part '.$partid.' Points: '; + + my $ctr = 0; + $result.=''; # display radio buttons in a nice table 10 across + while ($ctr<=$wgt) { + $result.= '\n"; + $result.=(($ctr+1)%10 == 0 ? '' : ''); + $ctr++; + } + $result.='
'.$ctr."
'; + $result.='
 or /'.$wgt.' '.$wgtmsg.' '; + + $result.=''; + } else { + $result.=''. + ''; + } + $result.="  \n"; + $result.=''; + $result.='
'."\n"; + return $result; +} + #--- Form to input a receipt number --- sub verifyReceipt_form { my ($symb,$url) = @_; @@ -2392,8 +2680,14 @@ sub handler { } else { $Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'}); if ($command eq 'submission') { - &listStudents($request) if ($ENV{'form.student'} eq ''); - &submission($request,0,0) if ($ENV{'form.student'} ne ''); + ($ENV{'form.student'} eq '' ? &listStudents($request) : &submission($request,0,0)); +# if ($command eq 'submission') { +# &listStudents($request) if ($ENV{'form.student'} eq ''); +# &submission($request,0,0) if ($ENV{'form.student'} ne ''); + } elsif ($command eq 'pickStudentPage') { + &pickStudentPage($request); + } elsif ($command eq 'displayPage') { + &displayPage($request); } elsif ($command eq 'processGroup') { &processGroup($request); } elsif ($command eq 'gradingmenu') {