--- loncom/homework/grades.pm 2003/07/25 20:35:40 1.125 +++ loncom/homework/grades.pm 2003/08/21 18:21:39 1.135 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.125 2003/07/25 20:35:40 ng Exp $ +# $Id: grades.pm,v 1.135 2003/08/21 18:21:39 bowersj2 Exp $ # # Copyright Michigan State University Board of Trustees # @@ -96,6 +96,18 @@ sub get_fullname { return $fullname; } +#--- Format fullname, username:domain if different for display +#--- Use anywhere where the student names are listed +sub nameUserString { + my ($type,$fullname,$uname,$udom) = @_; + if ($type eq 'header') { + return ' Fullname (Username) '; + } else { + return ' '.$fullname.' ('.$uname. + ($ENV{'user.domain'} eq $udom ? '' : ' ('.$udom.')').')'; + } +} + #--- Get the partlist and the response type for a given problem. --- #--- Indicate if a response type is coded handgraded or not. --- sub response_type { @@ -109,9 +121,8 @@ sub response_type { my ($responsetype,$part) = split(/_/,$_,2); my ($partid,$respid) = split(/_/,$part); $responsetype =~ s/response$//; # make it compatible w/ navmaps - should move to that!! -# my ($value) = &Apache::lonnet::EXT('resource.'.$part.'.handgrade',$symb); -# $handgrade{$part} = $responsetype.':'.($value eq 'yes' ? 'yes' : 'no'); #a bug $value is 'yes' regardless - $handgrade{$part} = $responsetype.':'.(($allkeys =~ /parameter_$part\_handgrade/) ? 'yes' : 'no'); + my ($value) = &Apache::lonnet::EXT('resource.'.$part.'.handgrade',$symb); + $handgrade{$part} = $responsetype.':'.($value eq 'yes' ? 'yes' : 'no'); next if ($seen{$partid} > 0); $seen{$partid}++; push @partlist,$partid; @@ -127,7 +138,7 @@ sub showResourceInfo { my $result =''. ''."\n"; my ($partlist,$handgrade) = &response_type($url); - my %resptype = (); #,$hdgrade)=('','no'); + my %resptype = (); my $hdgrade='no'; for (sort keys(%$handgrade)) { my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_}); @@ -154,12 +165,12 @@ sub cleanRecord { push @ans,$ans; } my $grayFont = ''; - return '
Current Resource: '.$probTitle.'
'. + return '
'. ''. ''. - '
Answer'. (join '',@ans).'
'.$grayFont.'Option ID'.$grayFont. (join ''.$grayFont,@IDs).'
'; + ''; } if ($response eq 'essay') { if (! exists ($ENV{'form.'.$symb})) { @@ -174,7 +185,7 @@ sub cleanRecord { $ENV{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : ''; $ENV{'form.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob. } - return &keywords_highlight($answer); + return '

'.&keywords_highlight($answer).'
'; } return $answer; } @@ -299,7 +310,7 @@ sub student_gradeStatus { my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname); my %partstatus = (); foreach (@$partlist) { - my ($status,$foo) = split(/_/,$record{"resource.$_.solved"},2); + my ($status,undef) = split(/_/,$record{"resource.$_.solved"},2); $status = 'nothing' if ($status eq ''); $partstatus{$_} = $status; my $subkey = "resource.$_.submitted_by"; @@ -475,7 +486,7 @@ sub listStudents { sense = "the student"; } if (ctr == 0) { - alert("Please select "+sense+" before clicking on the $viewgrade button."); + alert("Please select "+sense+" before clicking on the Next button."); return false; } document.gradesub.submit(); @@ -506,8 +517,8 @@ LISTJAVASCRIPT my $saveStatus = $ENV{'form.Status'} eq '' ? 'Active' : $ENV{'form.Status'}; $ENV{'form.Status'} = $saveStatus; - $gradeTable.=' last sub only'."\n". - ' last sub & parts info'."\n". + $gradeTable.=' last submission only'."\n". + ' last submission & parts info'."\n". ' by dates and submissions'."\n". ' all details'."\n". ''."\n". @@ -527,27 +538,27 @@ LISTJAVASCRIPT &Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,'javascript:reLoadList(this.form);').'
'; } - $gradeTable.='To '.lc($viewgrade).' a submission, click on the check box next to the student\'s name. Then '."\n". - 'click on the '.$viewgrade.' button. To view the submissions for a group of students, click'."\n". - ' on the check boxes for the group of students.
'."\n". + $gradeTable.='To '.lc($viewgrade).' a submission or a group of submissions, click on the check box(es) '. + 'next to the student\'s name(s). Then click on the Next button.
'."\n". ''."\n"; $gradeTable.=''."\n"; - + 'value="Next->" />'."\n"; + $gradeTable.='Check For Plagiarism'; my (undef, undef, $fullname) = &getclasslist($getsec,'1'); $gradeTable.='
'. ''; my $loop = 0; while ($loop < 2) { - $gradeTable.=''; + $gradeTable.=''. + ''; if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') { foreach (sort(@$partlist)) { $gradeTable.=''; } } $loop++; +# $gradeTable.='' if ($loop%2 ==1); } $gradeTable.=''."\n"; @@ -574,10 +585,10 @@ LISTJAVASCRIPT $ctr++; if ( $perm{'vgr'} eq 'F' ) { $gradeTable.='' if ($ctr%2 ==1); - $gradeTable.=''. + ''."\n". - ''."\n"; + ''."\n"; if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') { foreach (sort keys(%status)) { @@ -585,11 +596,12 @@ LISTJAVASCRIPT $gradeTable.=''."\n"; } } +# $gradeTable.='' if ($ctr%2 ==1); $gradeTable.=''."\n" if ($ctr%2 ==0); } } if ($ctr%2 ==1) { - $gradeTable.=''; + $gradeTable.=''; if ($ENV{'form.showgrading'} eq 'yes' && $submitonly ne 'all') { foreach (@$partlist) { $gradeTable.=''; @@ -601,7 +613,7 @@ LISTJAVASCRIPT $gradeTable.='
 Select  Fullname '. - '(Username)  No.  Select '.&nameUserString('header').' Part '.(split(/_/))[0].' Status 
'.$ctr.'  '.$$fullname{$student}.' '."\n". - '('.$uname.')'.&nameUserString(undef,$$fullname{$student},$uname,$udom).' '.$status{$_}.' 
      
'. ''."\n"; + 'value="Next->" />'."\n"; if ($ctr == 0) { my $num_students=(scalar(keys(%$fullname))); if ($num_students eq 0) { @@ -752,12 +764,13 @@ sub sub_page_js { for (i=0;i<=total;i++) { for (j=0;j"); pDoc.write("Message Central"); @@ -1027,6 +1036,7 @@ sub sub_page_kw_js { pDoc.write("

"); pDoc.write(""); pDoc.write(""); + pDoc.close(); } //====================== Script for keyword highlight options ============== @@ -1070,6 +1080,7 @@ sub sub_page_kw_js { hwdWin = window.open('', 'KeywordHighlightCentral', 'toolbar=no,location=no,scrollbars=no,width=400,height=300,screenx='+xpos+',screeny='+ypos); hwdWin.focus(); var hDoc = hwdWin.document; + hDoc.open('text/html','replace'); hDoc.write(""); hDoc.write("Highlight Central"); @@ -1118,6 +1129,7 @@ sub sub_page_kw_js { hDoc.write("

"); hDoc.write(""); hDoc.write(""); + hDoc.close(); } @@ -1351,9 +1363,7 @@ KEYWORDS my $result=''; } @@ -3006,13 +3007,12 @@ sub updateGradeByPage { return; } my $result='

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

'; - $result.='

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

'."\n"; + $result.='

 Student: '.&nameUserString(undef,$ENV{'form.fullname'},$uname,$udom). + '

'."\n"; $request->print($result); - my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db', - $ENV{'request.course.fn'}.'_parms.db',1, 1); + my $navmap = Apache::lonnavmaps::navmap->new(); my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'}); my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps @@ -3062,7 +3062,6 @@ sub updateGradeByPage { $score = 'excused'; } elsif ($dropMenu eq 'reset status' && $ENV{'form.solved'.$question.'_'.$partid} ne '') { #update only if previous record exists - print "got to reset = $ENV{'form.solved'.$question.'_'.$partid}:
"; $newrecord{'resource.'.$partid.'.tries'} = 0; $newrecord{'resource.'.$partid.'.solved'} = ''; $newrecord{'resource.'.$partid.'.award'} = ''; @@ -3332,7 +3331,7 @@ sub scantron_process_students { my @scanlines=<$scanlines>; my $classlist=&Apache::loncoursedata::get_classlist(); my %idmap=&username_to_idmap($classlist); - my $navmap=Apache::lonnavmaps::navmap->new($ENV{'request.course.fn'}.'.db',$ENV{'request.course.fn'}.'_parms.db',1, 1); + my $navmap=Apache::lonnavmaps::navmap->new(); my $map=$navmap->getResourceByUrl($sequence); my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0); $r->print("geto ".scalar(@resources)."
"); @@ -3563,7 +3562,7 @@ GRADINGMENUJS 'The complete set/page/sequence: For one student'."\n"; $result.='
'."\n". '
'."\n"; - $result.='Fullname: '.$ENV{'form.fullname'}. - '   Username: '.$uname. - ($ENV{'user.domain'} eq $udom ? '' : ' ('.$udom.')').'
'."\n"; + $result.='Fullname: '.&nameUserString(undef,$ENV{'form.fullname'},$uname,$udom).'
'."\n"; $result.=''."\n"; @@ -1451,13 +1461,20 @@ KEYWORDS my ($ressub,$subval) = split(/:/,$_,2); # Similarity check my $similar=''; - my ($oname,$odom,$ocrsid,$oessay,$osim)=&most_similar($uname,$udom,$subval); - if ($osim) { - $osim=int($osim*100.0); - $similar='

Essay is '.$osim. - '% similar to an essay by '.&Apache::loncommon::plainname($oname,$odom). - '

'. - &keywords_highlight($oessay).'

'; + my $oname; + my $odom; + my $ocrsid; + my $oessay; + my $osim; + if($ENV{'form.checkPlag'}){ + ($oname,$odom,$ocrsid,$oessay,$osim)=&most_similar($uname,$udom,$subval); + if ($osim) { + $osim=int($osim*100.0); + $similar='

Essay is '.$osim. + '% similar to an essay by '.&Apache::loncommon::plainname($oname,$odom). + '

'. + &keywords_highlight($oessay).'

'; + } } $lastsubonly.='
Part '. $partid.' ( ID '.$respid. @@ -1468,11 +1485,9 @@ KEYWORDS '"> File uploaded by student '. 'Like all files provided by users, '. 'this file may contain virusses
':''). - 'Submitted Answer: '.($responsetype =~ /^(essay|option)$/ ? - '
' : ''). + 'Submitted Answer: '. &cleanRecord($subval,$responsetype,$symb). - ($responsetype =~ /^(essay|option)$/ ? '

' : - '

').$similar."\n" + '

'.$similar."\n" if ($ENV{'form.lastSub'} eq 'lastonly' || ($ENV{'form.lastSub'} eq 'hdgrade' && $$handgrade{$part} =~ /:yes$/)); @@ -1519,7 +1534,6 @@ KEYWORDS $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.'; } $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript -# $result.='
'."\n". $result=''."\n". ''."\n"; $result.=' '."\n"; + $result.=''."\n" if ($counter == 0); my $ctr = 0; while ($ctr < scalar(@partlist)) { $result.='$nsel  '."\n". - '  '; - $endform.='(Next and Previous do not save the scores.)'."\n" ; + $endform.='  '."\n". + '  '; + $endform.='(Next and Previous (student) do not save the scores.)'."\n" ; $endform.='
'; $endform.=&show_grading_menu_form($symb,$url); $request->print($endform); @@ -1770,21 +1788,19 @@ sub processHandGrade { } } $ctr = 0; - my ($partlist,$handgrade) = &response_type($ENV{'form.url'},$symb); @parsedlist = reverse @parsedlist if ($button eq 'Previous'); foreach my $student (@parsedlist) { my ($uname,$udom) = split(/:/,$student); if ($ENV{'form.submitonly'} eq 'yes') { - my (%status) = &student_gradeStatus($ENV{'form.url'},$symb,$udom,$uname,$partlist) ; + my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname); my $statusflg = ''; - foreach (keys(%status)) { - $statusflg = 1 if ($status{$_} ne 'nothing'); - my ($foo,$partid,$foo1) = split(/\./); - $statusflg = '' if ($status{'resource.'.$partid.'.submitted_by'} ne ''); + foreach (split(/:/,$ENV{'form.gradePartRespid'})){ + $statusflg = 1 if (exists ($record{'resource.'.$_.'.submission'})); } next if ($statusflg eq ''); } push @nextlist,$student if ($ctr < $ntstu); + last if ($ctr == $ntstu); $ctr++; } @@ -2059,14 +2075,15 @@ sub viewgrades { ''."\n". ''."\n"; - $result.='

Assign Common Grade To '; + my $sectionClass; if ($ENV{'form.section'} eq 'all') { - $result.='Class

'; + $sectionClass='Class '; } elsif ($ENV{'form.section'} eq 'no') { - $result.='Students in no Section '; + $sectionClass='Students in no Section '; } else { - $result.='Students in Section '.$ENV{'form.section'}.''; + $sectionClass='Students in Section '.$ENV{'form.section'}.''; } + $result.='

Assign Common Grade To '.$sectionClass; $result.= ''."\n"; @@ -2197,17 +2206,13 @@ sub viewstudentgrade { $status = 'nothing' if ($status eq ''); $result.=''."\n"; - $result.='\n"; + $result.=" \n"; } else { $result.=''. @@ -2231,9 +2236,11 @@ sub editgrades { my $title='

Current Grade Status

'; $title.='Current Resource: '.$ENV{'form.probTitle'}.'
'."\n"; $title.='Section: '.$ENV{'form.section'}.''."\n"; + my $result= '
'."\n". ''."\n"; ''. ''."\n"; $ctsparts++; @@ -2119,21 +2135,14 @@ sub viewgrades { #table listing all the students in a section/class #header of table - $result.= '

Assign Grade to Specific Students in '; - if ($ENV{'form.section'} eq 'all') { - $result.='the Class

'; - } elsif ($ENV{'form.section'} eq 'no') { - $result.='no Section '; - } else { - $result.='Section '.$ENV{'form.section'}.''; - } + $result.= '

Assign Grade to Specific Students in '.$sectionClass; $result.= '

'; #radio buttons/text box for assigning points for a section or class. @@ -2107,7 +2124,6 @@ sub viewgrades { 'onChange="javascript:writeRadText(\''.$partid.'\','. $weight{$partid}.')"> '. ''. -# '
'."\n". - ''. - ''."\n"; + '
Fullname (Username)
'. + '\n"; my (@parts) = sort(&getpartlist($url)); foreach my $part (@parts) { my $display=&Apache::lonnet::metadata($url,$part.'.display'); - $display =~ s/^Number of Attempts/Tries/; # makes the column narrower + $display =~ s|^Number of Attempts|Tries
|; # makes the column narrower if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); } if ($display =~ /^Partial Credit Factor/) { my ($partid) = &split_part_type($part); @@ -2154,13 +2163,13 @@ sub viewgrades { my $uname = $_; $uname=~s/:/_/; $result.=''."\n"; - $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'}, - $_,$$fullname{$_},\@parts,\%weight); $ctr++; + $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'}, + $_,$$fullname{$_},\@parts,\%weight,$ctr); } $result.='
 No. '.&nameUserString('header')."
'; $result.=''."\n"; - $result.=''."\n"; if (scalar(%$fullname) eq 0) { my $colspan=3+scalar(@parts); @@ -2173,11 +2182,11 @@ sub viewgrades { #--- call by previous routine to display each student sub viewstudentgrade { - my ($url,$symb,$courseid,$student,$fullname,$parts,$weight) = @_; + my ($url,$symb,$courseid,$student,$fullname,$parts,$weight,$ctr) = @_; my ($uname,$udom) = split(/:/,$student); $student=~s/:/_/; my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname); - my $result='
'. + my $result='
'.$ctr.'  '. ''.$fullname.' '. '('.$uname.($ENV{'user.domain'} eq $udom ? '' : ':'.$udom).')'."\n"; -# my $optsel = ''."\n"; -# $optsel = ''."\n" -# if ($status eq 'excused'); -# $result.=$optsel; $result.= (($status eq 'excused') ? '' : '')."\n"; $result.=''; - $result.="
'."\n"; $result.= ''. - ''."\n"; + ''. + '\n"; my %scoreptr = ( 'correct' =>'correct_by_override', @@ -2283,6 +2290,7 @@ sub editgrades { $result .= $header; $result .= ''."\n"; my $noupdate; + my ($updateCtr,$noupdateCtr) = (1,1); for ($i=0; $i<$ENV{'form.total'}; $i++) { my $line; my $user = $ENV{'form.ctr'.$i}; @@ -2291,12 +2299,10 @@ sub editgrades { my ($uname,$udom)=split(/_/,$user); my %newrecord; my $updateflag = 0; - $line .= ''; + $line .= ''; my $usec=$classlist->{"$uname:$udom"}[5]; if (!&canmodify($usec)) { - my $numcols=scalar(@partid)*(scalar(@parts)-1)*2; + my $numcols=scalar(@partid)*4+2; $noupdate.=$line.""; next; } @@ -2322,7 +2328,6 @@ sub editgrades { if ($dropMenu eq 'reset status' && $old_score ne '') { # ignore if no previous attempts => nothing to reset - print "reset status
"; $newrecord{'resource.'.$_.'.tries'} = 0; $newrecord{'resource.'.$_.'.solved'} = ''; $newrecord{'resource.'.$_.'.award'} = ''; @@ -2363,14 +2368,17 @@ sub editgrades { $count++; &Apache::lonnet::cstore(\%newrecord,$symb,$ENV{'request.course.id'}, $udom,$uname); - $result.=$line; + $result.=''.$line; + $updateCtr++; } else { - $noupdate.=$line; + $noupdate.=''.$line; + $noupdateCtr++; } } if ($noupdate) { - my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3; - $result .= ''.$noupdate; +# my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3; + my $numcols=scalar(@partid)*4+2; + $result .= ''.$noupdate; } $result .= '
UsernameDomainFullname No. '.&nameUserString('header')."
'.$uname.' '. - $udom.' '. - $$fullname{$usercolon}.' '.&nameUserString(undef,$$fullname{$usercolon},$uname,$udom).'Not allowed to modify student
 '.$updateCtr.' 
 '.$noupdateCtr.' 
No Changes Occured For the Students Below
No Changes Occurred For the Students Below
'."\n". &show_grading_menu_form ($symb,$url); @@ -2509,7 +2517,6 @@ to this page if the data selected is ins $javascript ENDPICK - $request->print(&show_grading_menu_form($symb,$url)); return ''; } @@ -2762,34 +2769,33 @@ LISTJAVASCRIPT ''."
\n"; $result.=' 
'."\n"; + 'onClick="javascript:checkPickOne(this.form);"value="Next->" />
'."\n"; $request->print($result); - my $studentTable.=' Select a student you wish to grade
'. + my $studentTable.=' Select a student you wish to grade and then click on the Next button.
'. '
'. ''. - ''. - ''. - ''. - ''; + ''. + ''. + ''. + ''; my (undef,undef,$fullname) = &getclasslist($getsec,'1'); 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 ? '' : ''); + $studentTable.=($ptr%2 == 1 ? '' : ''); + $studentTable.=''; + $studentTable.='' : ''); $ptr++; } - $studentTable.='
 Fullname (username) Fullname (username) Fullname (username) Fullname (username)
 No.'.&nameUserString('header').' No.'.&nameUserString('header').'
' : ''); - $studentTable.=' '.$$fullname{$student}. - ' ('.$uname.($udom eq $cdom ? '':':'.$udom).')'."\n"; - $studentTable.=($ptr%4 == 0 ? '
'.$ptr.'   ' + .&nameUserString(undef,$$fullname{$student},$uname,$udom)."\n"; + $studentTable.=($ptr%2 == 0 ? '
   ' if ($ptr%4 == 2); - $studentTable.='  ' if ($ptr%4 == 3); - $studentTable.=' ' if ($ptr%4 == 0); + $studentTable.='  ' if ($ptr%2 == 0); $studentTable.='
'."\n"; - $studentTable.='
'."\n"; + $studentTable.=''."\n"; $studentTable.=&show_grading_menu_form($symb,$url); $request->print($studentTable); @@ -2799,9 +2805,7 @@ LISTJAVASCRIPT sub getSymbMap { my ($request) = @_; - my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db', - $ENV{'request.course.fn'}.'_parms.db'); - $navmap->init(); + my $navmap = Apache::lonnavmaps::navmap->new(); my %symbx = (); my @titles = (); @@ -2841,14 +2845,12 @@ sub displayPage { return; } my $result='

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

'; - $result.='

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

'."\n"; - + $result.='

 Student: '.&nameUserString(undef,$$fullname{$ENV{'form.student'}},$uname,$udom). + '

'."\n"; &sub_page_js($request); $request->print($result); - my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db', - $ENV{'request.course.fn'}.'_parms.db',1, 1); + my $navmap = Apache::lonnavmaps::navmap->new(); my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'}); my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps @@ -2883,7 +2885,6 @@ sub displayPage { if($curRes == $iterator->BEGIN_MAP) { $depth++; } if($curRes == $iterator->END_MAP) { $depth--; } -# if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) { if (ref($curRes) && $curRes->is_problem()) { my $parts = $curRes->parts(); my $title = $curRes->compTitle(); @@ -2982,7 +2983,7 @@ sub displaySubByDates { $$record{"$version:resource.$partid.regrader"}.' (Part: '.$partid.')' : ''; } $displaySub[2].=(exists $$record{"$version:resource.regrader"}) ? - $$record{"$version:resource.regrader"} : ''; + $$record{"$version:resource.regrader"} : ''; # needed because old essay regrader has not parts info $studentTable.='
'.$displaySub[0].' '.$displaySub[1]. ($displaySub[2] eq '' ? '' : 'Manually graded by '.$displaySub[2]).' 

'. - ''. + ''. '
'."\n"; $result.='';