--- loncom/homework/grades.pm 2002/09/06 21:01:09 1.46.2.1 +++ loncom/homework/grades.pm 2002/10/04 06:22:12 1.54 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.46.2.1 2002/09/06 21:01:09 albertel Exp $ +# $Id: grades.pm,v 1.54 2002/10/04 06:22:12 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -51,7 +51,7 @@ sub getpartlist { my @parts =(); my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys')); foreach my $key (@metakeys) { - if ( $key =~ m/stores_([0-9]+)_.*/) { + if ( $key =~ m/stores_(\w+)_.*/) { push(@parts,$key); } } @@ -91,7 +91,7 @@ sub response_type { my %seen = (); my (@partlist,%handgrade); foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) { - if (/^\w+response_\d+.*/) { + if (/^\w+response_\w+.*/) { my ($responsetype,$part) = split(/_/,$_,2); my ($partid,$respid) = split(/_/,$part); $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no'); @@ -111,6 +111,10 @@ sub getclasslist { my %classlist=&Apache::lonnet::dump('classlist', $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, $ENV{'course.'.$ENV{'request.course.id'}.'.num'}); + my ($tmp) = keys(%classlist); + # Bail out if we were unable to get the classlist + return if ($tmp =~ /^(con_lost|error|no_such_host)/i); + # codes to check for fields in the classlist # should contain end:start:id:section:fullname for (keys %classlist) { @@ -261,7 +265,7 @@ sub verifyreceipt { my ($string,$contents,$matches) = ('','',0); my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist('all','0'); - foreach (sort {$$fullname{$a} cmp $$fullname{$b} } keys %$fullname) { + foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) { my ($uname,$udom)=split(/\:/); if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) { @@ -288,7 +292,7 @@ sub verifyreceipt { $contents. ''."\n"; } - return $string.&show_grading_menu_form ($symb,$url); + return $string.&show_grading_menu_form($symb,$url); } #--- This is called by a number of programs. @@ -297,6 +301,37 @@ sub verifyreceipt { # on the problem page. sub listStudents { my ($request) = shift; + + 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 $submitonly= $ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'}; + + my $result; + my ($partlist,$handgrade) = &response_type($url); + for (sort keys(%$handgrade)) { + my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_}); + $ENV{'form.handgrade'} = 'yes' if ($handgrade eq 'yes'); + $result.='Part '.(split(/_/))[0].''. + 'Type: '.$responsetype.''. + 'Handgrade: '.$handgrade.''; + } + $result.=''; + + my $viewgrade; + if ($ENV{'form.handgrade'} eq 'yes') { + $viewgrade = 'View/Grade'; + } else { + $viewgrade = 'View'; + } + + $result='

 '. + $viewgrade. + ' Submissions for a Student or a Group of Students

'. + ''.$result; + $request->print(< function checkSelect(checkBox) { @@ -316,7 +351,7 @@ sub listStudents { sense = "the student"; } if (ctr == 0) { - alert("Please select "+sense+" before clicking on the View/Grade button."); + alert("Please select "+sense+" before clicking on the $viewgrade button."); return false; } document.gradesub.submit(); @@ -324,26 +359,6 @@ sub listStudents { 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 $submitonly= $ENV{'form.submitonly'} eq '' ? 'all' : $ENV{'form.submitonly'}; - - my $result='

 '. - 'View/Grade Submissions for a Student or a Group of Students

'; - $result.='
'. + 'Resource: '.$url.'
'; - $result.=''; - my ($partlist,$handgrade) = &response_type($url); - for (sort keys(%$handgrade)) { - my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_}); - $ENV{'form.handgrade'} = 'yes' if ($handgrade eq 'yes'); - $result.=''. - ''. - ''; - } - $result.='
'. - 'Resource: '.$url.'
Part '.(split(/_/))[0].'Type: '.$responsetype.'Handgrade: '.$handgrade.'
'; $request->print($result); my $checkhdgrade = $ENV{'form.handgrade'} eq 'yes' ? 'checked' : ''; @@ -352,9 +367,11 @@ LISTJAVASCRIPT my $gradeTable='
'."\n". ' View Problem: no '."\n". ' yes
'."\n". - ' Submissions: '."\n". - ' handgrade only'."\n". - ' last sub only'."\n". + ' Submissions: '."\n"; + if ($ENV{'form.handgrade'} eq 'yes') { + $gradeTable.=' handgrade only'."\n"; + } + $gradeTable.=' last sub only'."\n". ' last sub & parts info'."\n". ' all details'."\n". ''."\n". @@ -364,13 +381,13 @@ LISTJAVASCRIPT '
'."\n". ''."\n". ''."\n". - 'To view/grade a submission, click on the check box next to the student\'s name. Then '."\n". - 'click on the View/Grade button. To view the submissions for a group of students, click'."\n". + '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". ''."\n". ''."\n"; + 'value="'.$viewgrade.'" />'."\n"; my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($getsec,'0'); @@ -384,7 +401,7 @@ LISTJAVASCRIPT $gradeTable.=''."\n"; my $ctr = 0; - foreach my $student (sort {$$fullname{$a} cmp $$fullname{$b} } keys %$fullname) { + foreach my $student (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) { my ($uname,$udom) = split(/:/,$student); my (%status) =&student_gradeStatus($url,$symb,$udom,$uname,$partlist); my $statusflg = ''; @@ -419,14 +436,14 @@ LISTJAVASCRIPT $gradeTable.=''. ''."\n"; + 'value="'.$viewgrade.'" />
'."\n"; if ($ctr == 0) { $gradeTable='
 '. 'No submission found for this resource.
'; - $gradeTable.=&show_grading_menu_form($symb,$url); } elsif ($ctr == 1) { $gradeTable =~ s/type=checkbox/type=checkbox checked/; } + $gradeTable.=&show_grading_menu_form($symb,$url); $request->print($gradeTable); return ''; } @@ -1128,6 +1145,7 @@ KEYWORDS $endform.='(Next and Previous do not save the scores.)'."\n" if ($ENV{'form.handgrade'} eq 'yes'); $endform.=''; + $endform.=&show_grading_menu_form($symb,$url); $request->print($endform); } return ''; @@ -1282,7 +1300,7 @@ sub processHandGrade { my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0'); my (@parsedlist,@nextlist); my ($nextflg) = 0; - foreach (sort {$$fullname{$a} cmp $$fullname{$b} } keys %$fullname) { + foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) { if ($nextflg == 1 && $button =~ /Next$/) { push @parsedlist,$_; } @@ -1423,10 +1441,10 @@ sub viewgrades_js { for (i=0;i'."\n". ''."\n". ''."\n"; - $result.='To assign the same score for all the students use the radio buttons or '. - 'text box below. To assign scores individually fill in the score boxes for '. - 'each student in the table below. A part that has already '. - 'been graded does not get changed using the radio buttons or text box. '. - 'If needed, it has to be changed individually.'; - + $result.='

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

'; + } elsif ($ENV{'form.section'} eq 'no') { + $result.='Students in no Section '; + } else { + $result.='Students in Section '.$ENV{'form.section'}.''; + } + $result.= '
'."\n". + ''."\n"; $result.= ''."\n"; $ctsparts++; } - $result.='
'; +# $result.='To assign the same score for all the students use the radio buttons or '. +# 'text box below. To assign scores individually fill in the score boxes for '. +# 'each student in the table below. A part that has already '. +# 'been graded does not get changed using the radio buttons or text box. '. +# 'If needed, it has to be changed individually.'; +# $result.='
'; #radio buttons/text box for assigning points for a section or class. #handles different parts of a problem my ($partlist,$handgrade) = &response_type($ENV{'form.url'}); @@ -1580,7 +1608,7 @@ sub viewgrades { $result.=''; my %seen = (); for (sort keys(%$handgrade)) { - my ($partid,$respid) = split (/_/); + my ($partid,$respid) = split (/_/,$_,2); next if $seen{$partid}; $seen{$partid}++; my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_}); @@ -1596,24 +1624,25 @@ sub viewgrades { my $ctr = 0; while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across $result.= '\n"; $result.=(($ctr+1)%10 == 0 ? '' : ''); $ctr++; } $result.='
'.$ctr."
'; $result.= '
or /'. + $partid.'" size="4" '.'onChange="javascript:writePoint(\''. + $partid.'\','.$weight{$partid}.',\'textval\')" /> /'. $weight{$partid}.' (problem weight)
'; + $result.='
'.''.''."\n". + ''; $result.='    '; $result.=''; + } $result.= '
'."\n". ''. ''."\n"; my (@parts) = sort(&getpartlist($url)); foreach my $part (@parts) { my $display=&Apache::lonnet::metadata($url,$part.'.display'); - next if ($display =~ /^Number of Attempts/); if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); } if ($display =~ /^Partial Credit Factor/) { - $_ = $display; - my ($partid) = /.*?(\d+).*/; - $result.=''."\n"; next; } - $display =~ s/Problem Status/Grade Status
/; + $display =~ s|Problem Status|Grade Status
|; $result.=''."\n"; } $result.=''; @@ -1645,7 +1680,7 @@ sub viewgrades { #list all the students - with points and grade status my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($ENV{'form.section'},'0'); my $ctr = 0; - foreach (sort {$$fullname{$a} cmp $$fullname{$b} } keys %$fullname) { + foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) { my ($uname,$udom) = split(/:/); $result.=''."\n"; $result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'}, @@ -1670,30 +1705,36 @@ sub viewstudentgrade { '\')"; TARGET=_self>'.$fullname.''. ''."\n"; foreach my $part (@$parts) { - my ($temp,$part,$type)=split(/_/,$part); + my ($part,$type) = &split_part_type($part); my $score=$record{"resource.$part.$type"}; - next if $type eq 'tries'; if ($type eq 'awarded') { my $pts = $score eq '' ? '' : $score*$$weight{$part}; $result.=''."\n"; + 'GD_'.$uname.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n"; $result.=''."\n"; } elsif ($type eq 'solved') { my ($status,$foo)=split(/_/,$score,2); $status = 'nothing' if ($status eq ''); - $result.=''."\n"; + $result.=''."\n"; $result.='\n"; + } else { + $result.=''. + "\n"; + $result.=''."\n"; } } $result.=''; @@ -1726,20 +1767,40 @@ sub editgrades { my (@partid); my %weight = (); + my %columns = (); my ($i,$ctr,$count,$rec_update) = (0,0,0,0); + + my (@parts) = sort(&getpartlist($url)); + my $header; while ($ctr < $ENV{'form.totalparts'}) { my $partid = $ENV{'form.partid_'.$ctr}; push @partid,$partid; $weight{$partid} = $ENV{'form.weight_'.$partid}; $ctr++; - $result .= ''; } - $result .= ''; - foreach (@partid) { - $result .= ''. + foreach my $partid (@partid) { + $header .= ''. ''; + $columns{$partid}=2; + foreach my $stores (@parts) { + my ($part,$type) = &split_part_type($stores); + if ($part !~ m/^\Q$partid\E/) { next;} + if ($type eq 'awarded' || $type eq 'solved') { next; } + my $display=&Apache::lonnet::metadata($url,$stores.'.display'); + $display =~ s/\[Part: (\w)+\]//; + $header .= ''. + ''; + $columns{$partid}+=2; + } + } + foreach my $partid (@partid) { + $result .= ''; + } + $result .= ''; + $result .= $header; $result .= ''."\n"; for ($i=0; $i<$ENV{'form.total'}; $i++) { @@ -1747,38 +1808,54 @@ sub editgrades { my %newrecord; my $updateflag = 0; my @userdom = grep /^$user:/,keys %$classlist; - my ($foo,$udom) = split(/:/,$userdom[0]); + my (undef,$udom) = split(/:/,$userdom[0]); $result .= ''; - foreach (@partid) { - my $old_aw = $ENV{'form.GD_'.$user.'_'.$_.'_aw_s'}; - my $old_part = $old_aw eq '' ? '' : $old_aw/$weight{$_}; - my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_sv_s'}}; - - my $awarded = $ENV{'form.GD_'.$user.'_'.$_.'_aw'}; - my $partial = $awarded eq '' ? '' : $awarded/$weight{$_}; + my $old_aw = $ENV{'form.GD_'.$user.'_'.$_.'_awarded_s'}; + my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1); + my $old_part = $old_aw eq '' ? '' : $old_part_pcr; + my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}}; + + my $awarded = $ENV{'form.GD_'.$user.'_'.$_.'_awarded'}; + my $pcr = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1); + my $partial = $awarded eq '' ? '' : $pcr; my $score; if ($partial eq '') { - $score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_sv_s'}}; + $score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}}; } elsif ($partial > 0) { $score = 'correct_by_override'; } elsif ($partial == 0) { $score = 'incorrect_by_override'; } - $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_sv'} eq 'excused') && + $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_solved'} eq 'excused') && ($score ne 'excused')); $result .= ''. ''; - next if ($old_part eq $partial && $old_score eq $score); - - $updateflag = 1; - $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne ''; - $newrecord{'resource.'.$_.'.solved'} = $score; - $rec_update++; + if (!($old_part eq $partial && $old_score eq $score)) { + $updateflag = 1; + $newrecord{'resource.'.$_.'.awarded'} = $partial if $partial ne ''; + $newrecord{'resource.'.$_.'.solved'} = $score; + $rec_update++; + } + + my $partid=$_; + foreach my $stores (@parts) { + my ($part,$type) = &split_part_type($stores); + if ($part !~ m/^\Q$partid\E/) { next;} + if ($type eq 'awarded' || $type eq 'solved') { next; } + my $old_aw = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'}; + my $awarded = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type}; + if ($awarded ne '' && $awarded ne $old_aw) { + $newrecord{'resource.'.$part.'.'.$type}= $awarded; + $updateflag=1; + } + $result .= ''. + ''; + } } $result .= ''."\n"; if ($updateflag) { @@ -1794,6 +1871,15 @@ sub editgrades { 'Total number of students = '.$ENV{'form.total'}.'
'; return $title.$msg.$result; } + +sub split_part_type { + my ($partstr) = @_; + my ($temp,@allparts)=split(/_/,$partstr); + my $type=pop(@allparts); + my $part=join('.',@allparts); + return ($part,$type); +} + #------------- end of section for handling grading by section/class --------- # #---------------------------------------------------------------------------- @@ -2098,18 +2184,20 @@ sub view_edit_entire_class_form { my ($classlist,$sections) = &getclasslist('all','0'); my $result.='
FullnameUsernameDomainScore Part '.$partid.'
(weight = '. + my ($partid) = &split_part_type($part); + $result.='
Score Part '.$partid.'
(weight = '. $weight{$partid}.')
'.$display.'
'.$uname.''.$udom.'
Part '.$partid. - ' (Weight = '.$weight{$partid}.')
 Old Score  Old Score  New Score  Old '.$display.'  New '.$display.' Part '.$partid. + ' (Weight = '.$weight{$partid}.')
'.$user.' '. $$fullname{$userdom[0]}.' '.$old_aw.' '.$awarded. ($score eq 'excused' ? $score : '').' '.$old_aw.' '.$awarded.' 
'."\n"; $result.=''."\n"; + $result.=' Grade Entire Section or Class'."\n"; $result.='
'."\n"; - $result.=' View/Grade Entire Section/Class
'."\n"; $result.='
'."\n". ''."\n". ''."\n". ''."\n"; $result.=' Select section: '."
\n"; - $result.=' 
'."\n"; + $result.=' '."\n"; $result.='
'."\n"; $result.='
'."\n"; return $result; @@ -2154,7 +2242,13 @@ sub viewGradeaStu_form { my ($classlist,$sections) = &getclasslist('all','0'); my $result.='
'."\n"; $result.=''."\n"; + $result.=' '; + if ($handgrade eq 'yes') { + $result.="View/Grade "; + } else { + $result.="View "; + } + $result.='an Individual Student\'s Submission'."\n"; $result.='
'."\n"; - $result.=' View/Grade an Individual Student\'s Submission
'."\n"; $result.='
'."\n". ''."\n". @@ -2165,18 +2259,26 @@ sub viewGradeaStu_form { ''."\n"; $result.=' Select section: '."\n"; $result.='  Display students who has: '. ' submitted'. ' everybody
'; - $result.=' (Section "no" implies the students were not assigned a section.)
' - if (grep /no/,@$sections); - - $result.='
 '."\n". - '
'."\n"; + if (ref($sections)) { + $result.=' (Section "no" implies the students were not assigned a section.)
' + if (grep /no/,@$sections); + } + + + $result.='
 '."\n"; $result.='
'."\n"; $result.='
'."\n"; return $result; @@ -2316,7 +2418,7 @@ sub send_header { #remotewindow=open('','homeworkremote'); #remotewindow.close(); #"); - $request->print(''); + $request->print(&Apache::loncommon::bodytag('Grading')); } sub send_footer {