--- loncom/homework/grades.pm 2003/09/19 21:54:07 1.140 +++ loncom/homework/grades.pm 2003/11/07 19:23:56 1.151 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.140 2003/09/19 21:54:07 albertel Exp $ +# $Id: grades.pm,v 1.151 2003/11/07 19:23:56 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -55,17 +55,35 @@ my %perm=(); # ----- These first few routines are general use routines.---- # -# --- Retrieve the parts that matches stores_\d+ from the metadata file.--- +# --- Retrieve the parts from the metadata file.--- sub getpartlist { - my ($url) = @_; - my @parts =(); - my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys')); - foreach my $key (@metakeys) { - if ( $key =~ m/stores_(\w+)_.*/) { - push(@parts,$key); + my ($url,$symb) = @_; + my $partorder = &Apache::lonnet::metadata($url, 'partorder'); + my @parts; + if ($partorder) { + for my $part (split (/,/,$partorder)) { + if (!&Apache::loncommon::check_if_partid_hidden($part,$symb)) { + push(@parts, $part); + } + } + } else { + my $metadata = &Apache::lonnet::metadata($url, 'packages'); + foreach (split(/\,/,$metadata)) { + if ($_ =~ /^part_(.*)$/) { + if (!&Apache::loncommon::check_if_partid_hidden($1,$symb)) { + push(@parts, $1); + } + } } } - return @parts; + my @stores; + foreach my $part (@parts) { + my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys')); + foreach my $key (@metakeys) { + if ($key =~ m/^stores_\Q$part\E_/) { push(@stores,$key); } + } + } + return @stores; } # --- Get the symbolic name of a problem and the url @@ -115,20 +133,25 @@ sub response_type { $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url))) if ($symb eq ''); my $allkeys = &Apache::lonnet::metadata($url,'keys'); my %seen = (); - my (@partlist,%handgrade); + my (@partlist,%handgrade,%responseType); foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) { - if (/^\w+response_\w+.*/) { + if (/^\w+response_.*/) { my ($responsetype,$part) = split(/_/,$_,2); my ($partid,$respid) = split(/_/,$part); + if (&Apache::loncommon::check_if_partid_hidden($partid,$symb)) { + next; + } $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'); + $handgrade{$part} = ($value eq 'yes' ? 'yes' : 'no'); + if (!exists($responseType{$partid})) { $responseType{$partid}={}; } + $responseType{$partid}->{$respid}=$responsetype; next if ($seen{$partid} > 0); $seen{$partid}++; push @partlist,$partid; } } - return \@partlist,\%handgrade; + return \@partlist,\%handgrade,\%responseType; } #--- Show resource title @@ -137,42 +160,104 @@ sub showResourceInfo { my ($url,$probTitle) = @_; my $result ='
Current Resource: '.$probTitle.' | ||
Part '.$partID.' | '. + $result.='||
Part '.$partID.' '. + $resID.' | '. 'Type: '.$responsetype.' | Handgrade: '.$handgrade.' | '; } $result.='
'; - } - if ($response eq 'essay') { + ''. - '
'. - ' Answer '. - (join ' ',@ans).' '. - ' '.$grayFont.'Option ID '.$grayFont. - (join ' '.$grayFont,@IDs).'
'; + } elsif ($response eq 'radiobutton') { + my %answer=&Apache::lonnet::str2hash($answer); + my ($toprow,$bottomrow); + my $correct=($order->[0])+1; + for (my $i=1;$i<=$#$order;$i++) { + my $foil=$order->[$i]; + if (exists($answer{$foil})) { + if ($i == $correct) { + $toprow.=''. + '
'. + ' Answer '.$toprow.''. + ' '.$grayFont.'Item ID '. + $middlerow.''.' '.$grayFont.'Option ID '. + $bottomrow.'
'; + } elsif ($response eq 'essay') { if (! exists ($ENV{'form.'.$symb})) { my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade', $ENV{'course.'.$ENV{'request.course.id'}.'.domain'}, @@ -185,7 +270,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 ''. + '
'. + ' Answer '.$toprow.''.' '.$grayFont.'Option ID '. + $grayFont.$bottomrow.'
'.&keywords_highlight($answer).''; + return '
'; } return $answer; } @@ -507,9 +592,12 @@ LISTJAVASCRIPT my $checkhdgrade = ($ENV{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked' : ''; my $checklastsub = $checkhdgrade eq '' ? 'checked' : ''; my $gradeTable='||g; $rendered=~s|name="submit"|name="would_have_been_submit"|g; } - my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom, - $ENV{'request.course.id'}); + my $companswer; + if ($mode eq 'both' or $mode eq 'answer') { + $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom, + $ENV{'request.course.id'}); + } if ($removeform) { $companswer=~s|||g; - $rendered=~s|name="submit"|name="would_have_been_submit"|g; + $companswer=~s|name="submit"|name="would_have_been_submit"|g; } my $result.=''.&keywords_highlight($answer).'
';
$result.='
|
'; @@ -1431,78 +1562,78 @@ KEYWORDS # (3) Last submission plus the parts info # (4) The whole record for this student if ($ENV{'form.lastSub'} =~ /^(lastonly|hdgrade)$/) { - if ($ENV{'form.'.$uname.':'.$udom.':submitted_by'}) { - my $submitby=''. - 'Collaborative submission by: '. - ''. - $$fullname{$ENV{'form.'.$uname.':'.$udom.':submitted_by'}}.''; - $request->print($submitby); + my ($string,$timestamp)= &get_last_submission(\%record); + my $lastsubonly=''. + ($$timestamp eq '' ? '' : 'Date Submitted: '. + $$timestamp)." | |||||||
'.$$string[0]; } else { - my ($string,$timestamp)= &get_last_submission (\%record); - my $lastsubonly=''. - ($$timestamp eq '' ? '' : 'Date Submitted: '. - $$timestamp)." | |||||||
'.$$string[0];
- } else {
- for my $part (sort keys(%$handgrade)) {
- my ($responsetype,$foo) = split(/:/,$$handgrade{$part});
- my ($partid,$respid) = split(/_/,$part);
- if (!exists($record{'resource.'.$partid.'.'.$respid.'.submission'})) {
+ my %seenparts;
+ for my $part (sort keys(%$handgrade)) {
+ my ($partid,$respid) = split(/_/,$part);
+ if ($ENV{"form.$uname:$udom:$partid:submitted_by"}) {
+ if (exists($seenparts{$partid})) { next; }
+ $seenparts{$partid}=1;
+ my $submitby='Part '.$partid.
+ ' Collaborative submission by: '.
+ ''.
+ $$fullname{$ENV{"form.$uname:$udom:$partid:submitted_by"}}.' '; + $request->print($submitby); + next; + } + my $responsetype = $responseType->{$partid}->{$respid}; + if (!exists($record{"resource.$partid.$respid.submission"})) { + $lastsubonly.=' | |||||||
Part '.
+ $partid.' ( ID '.$respid.
+ ' ) '.
+ 'Nothing submitted - no attempts '; + next; + } + foreach (@$string) { + my ($partid,$respid) = /^resource\.([^\.]*)\.([^\.]*)\.submission/; + if ($part ne ($partid.'_'.$respid)) { next; } + my ($ressub,$subval) = split(/:/,$_,2); + # Similarity check + my $similar=''; + if($ENV{'form.checkPlag'}){ + 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 $order=&get_order($partid,$respid,$symb,$uname,$udom); + if ($ENV{'form.lastSub'} eq 'lastonly' || + ($ENV{'form.lastSub'} eq 'hdgrade' && + $$handgrade{$part} eq 'yes')) { $lastsubonly.=' | |||||||
Part '.
$partid.' ( ID '.$respid.
- ' ) '.
- 'Nothing submitted - no attempts '; - } else { - foreach (@$string) { - my ($partid,$respid) = /^resource\.(\w+)\.(\w+)\.submission/; - if ($part eq ($partid.'_'.$respid)) { - my ($ressub,$subval) = split(/:/,$_,2); - # Similarity check - my $similar=''; - 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.
- ' ) '.
- ($record{"resource.$partid.$respid.uploadedurl"}?
- ' File uploaded by student '.
- 'Like all files provided by users, '.
- 'this file may contain virusses ':''). - 'Submitted Answer: '. - &cleanRecord($subval,$responsetype,$symb). - ' '.$similar."\n" - if ($ENV{'form.lastSub'} eq 'lastonly' || - ($ENV{'form.lastSub'} eq 'hdgrade' && - $$handgrade{$part} =~ /:yes$/)); - } + ' ) '; + if ($record{"resource.$partid.$respid.uploadedurl"}) { + $lastsubonly.=' File uploaded by student Like all files provided by users, this file may contain virusses '; } + $lastsubonly.='Submitted Answer: '. + &cleanRecord($subval,$responsetype,$symb,$partid, + $respid,\%record,$order); + if ($similar) {$lastsubonly.=" $similar\n";} } } } - $lastsubonly.=' | |||||||
'."\n"; - $request->print($lastsubonly); } + $lastsubonly.=' | |||||||
'."\n";
+ $request->print($lastsubonly);
} elsif ($ENV{'form.lastSub'} eq 'datesub') {
my (undef,$responseType,undef,$parts) = &showResourceInfo($url);
- $request->print(&displaySubByDates(\$symb,\%record,$parts,$responseType,$checkIcon));
+ $request->print(&displaySubByDates($symb,\%record,$parts,$responseType,$checkIcon,$uname,$udom));
} elsif ($ENV{'form.lastSub'} =~ /^(last|all)$/) {
$request->print(&Apache::loncommon::get_previous_attempt($symb,$uname,$udom,
$ENV{'request.course.id'},
@@ -1675,18 +1806,27 @@ sub processHandGrade {
$ENV{'form.msgsub'},$message);
}
if ($ENV{'form.collaborator'.$ctr}) {
- my (@collaborators) = split(/:/,$ENV{'form.collaborator'.$ctr});
- foreach (@collaborators) {
- my ($errorflag,$pts,$wgt) =
- &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,$ENV{'form.unamedom'.$ctr});
- if ($errorflag eq 'not_allowed') {
- $request->print("Not allowed to modify grades for $_:$udom");
- next;
- } else {
- if ($message ne '') {
- $msgstatus = &Apache::lonmsg::user_normal_msg ($_,$udom,
- $ENV{'form.msgsub'},
- $message);
+ &Apache::lonnet::logthis('collab '.(join(':',@{ $ENV{'form.collaborator'.$ctr} })));
+ my @collabstrs;
+ if (ref($ENV{'form.collaborator'.$ctr}) eq 'ARRAY') {
+ @collabstrs=@{$ENV{'form.collaborator'.$ctr}};
+ } else {
+ @collabstrs=$ENV{'form.collaborator'.$ctr};
+ }
+ foreach my $collabstr (@collabstrs) {
+ my ($part,@collaborators) = split(/:/,$collabstr);
+ foreach (@collaborators) {
+ my ($errorflag,$pts,$wgt) =
+ &saveHandGrade($request,$url,$symb,$_,$udom,$ctr,
+ $ENV{'form.unamedom'.$ctr},$part);
+ if ($errorflag eq 'not_allowed') {
+ $request->print("Not allowed to modify grades for $_:$udom");
+ next;
+ } else {
+ if ($message ne '') {
+ $msgstatus = &Apache::lonmsg::user_normal_msg($_,$udom,$ENV{'form.msgsub'},$message);
+ }
+
}
}
}
@@ -1790,15 +1930,25 @@ sub processHandGrade {
}
$ctr = 0;
@parsedlist = reverse @parsedlist if ($button eq 'Previous');
+ my ($partlist) = &response_type($url);
foreach my $student (@parsedlist) {
+ my $submitonly=$ENV{'form.submitonly'};
my ($uname,$udom) = split(/:/,$student);
- if ($ENV{'form.submitonly'} eq 'yes') {
- my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
- my $statusflg = '';
- foreach (split(/:/,$ENV{'form.gradePartRespid'})){
- $statusflg = 1 if (exists ($record{'resource.'.$_.'.submission'}));
+ if ($submitonly =~ /^(yes|graded)$/) {
+# my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
+ my %status=&student_gradeStatus($url,$symb,$udom,$uname,$partlist);
+ my $submitted = 0;
+ my $graded = 1;
+ foreach (keys(%status)) {
+ $submitted = 1 if ($status{$_} ne 'nothing');
+ $graded = 0 if ($status{$_} =~ /^correct/);
+ my ($foo,$partid,$foo1) = split(/\./,$_);
+ if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
+ $submitted = 0;
+ }
}
- next if ($statusflg eq '');
+ next if (!$submitted && ($submitonly eq 'yes' || $submitonly eq 'graded'));
+ next if (!$graded && $submitonly eq 'graded');
}
push @nextlist,$student if ($ctr < $ntstu);
last if ($ctr == $ntstu);
@@ -1828,7 +1978,7 @@ sub processHandGrade {
#---- Save the score and award for each student, if changed
sub saveHandGrade {
- my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
+ my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter,$part) = @_;
my $usec = &Apache::lonnet::getsection($domain,$stuname,
$ENV{'request.course.id'});
if (!&canmodify($usec)) { return('not_allowed'); }
@@ -1836,6 +1986,9 @@ sub saveHandGrade {
my %newrecord = ();
my ($pts,$wgt) = ('','');
foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
+ &Apache::lonnet::logthis("-$submitter-$stuname-$part-$_");
+ #collaborator may vary for different parts
+ if ($submitter && $_ ne $part) { next; }
my $dropMenu = $ENV{'form.GD_SEL'.$newflg.'_'.$_};
if ($dropMenu eq 'excused') {
if ($record{'resource.'.$_.'.solved'} ne 'excused') {
@@ -1871,6 +2024,7 @@ sub saveHandGrade {
$newrecord{$reckey} = 'correct_by_override'
if ($record{$reckey} ne 'correct_by_override');
}
+
$newrecord{'resource.'.$_.'.submitted_by'} = $submitter
if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter));
$newrecord{'resource.'.$_.'.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
@@ -2098,7 +2252,7 @@ sub viewgrades {
my ($partid,$respid) = split (/_/,$_,2);
next if $seen{$partid};
$seen{$partid}++;
- my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
+ my $handgrade=$$handgrade{$_};
my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
$weight{$partid} = $wgt eq '' ? '1' : $wgt;
@@ -2140,7 +2294,7 @@ sub viewgrades {
$result.= '
|