--- loncom/homework/grades.pm 2009/02/04 13:21:40 1.549 +++ loncom/homework/grades.pm 2009/03/09 01:58:48 1.556 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.549 2009/02/04 13:21:40 hauer Exp $ +# $Id: grades.pm,v 1.556 2009/03/09 01:58:48 weissno Exp $ # # Copyright Michigan State University Board of Trustees # @@ -268,12 +268,37 @@ sub reset_caches { sub get_radiobutton_correct_foil { my ($partid,$respid,$symb,$uname,$udom)=@_; my $analyze = &get_analyze($symb,$uname,$udom); - foreach my $foil (@{&get_order($partid,$respid,$symb,$uname,$udom)}) { - if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') { - return $foil; + my $foils = &get_order($partid,$respid,$symb,$uname,$udom); + if (ref($foils) eq 'ARRAY') { + foreach my $foil (@{$foils}) { + if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') { + return $foil; + } } } } + + sub scantron_partids_tograde { + my ($resource,$cid,$uname,$udom) = @_; + my (%analysis,@parts); + if (ref($resource)) { + my $symb = $resource->symb(); + my $analyze = &get_analyze($symb,$uname,$udom); + if (ref($analyze) eq 'HASH') { + %analysis = %{$analyze}; + } + if (ref($analysis{'parts'}) eq 'ARRAY') { + foreach my $part (@{$analysis{'parts'}}) { + my ($id,$respid) = split(/\./,$part); + if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) { + push(@parts,$part); + } + } + } + } + return (\%analysis,\@parts); + } + } #--- Clean response type for display @@ -699,7 +724,7 @@ sub verifyreceipt { my $title.= '

'. - &mt('Verifying Submission Receipt [_1]',$receipt). + &mt('Verifying Receipt No. [_1]',$receipt). '

'."\n". '

'.&mt('Resource: [_1]',$env{'form.probTitle'}). '

'."\n"; @@ -2105,7 +2130,7 @@ KEYWORDS } $lastsubonly.=''.&mt('Submitted Answer:').' '. &cleanRecord($subval,$responsetype,$symb,$partid, - $respid,\%record,$order); + $respid,\%record,$order,undef,$uname,$udom); if ($similar) {$lastsubonly.="

$similar\n";} $lastsubonly.=''; } @@ -3426,7 +3451,7 @@ sub editgrades { 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)+\]//; + $display =~ s/\[Part: \Q$part\E\]//; my $narrowtext = &mt('Tries'); $display =~ s/Number of Attempts/$narrowtext/; $header .= ''.&mt('Old').' '.$display.''. @@ -3742,7 +3767,7 @@ ENDPICK sub csvupload_fields { my ($symb) = @_; my (@parts) = &getpartlist($symb); - my @fields=(['ID','Student ID'], + my @fields=(['ID','Student/Employee ID'], ['username','Student Username'], ['domain','Student Domain']); my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb); @@ -4655,10 +4680,10 @@ Next each scanline is checked for any er bubbles' (it's an error because it may have been mis-scanned because too light bubbling), 'double bubble' (each bubble line should have no more that one letter picked), invalid or duplicated CODE, -invalid student ID +invalid student/employee ID If the CODE option is used that determines the randomization of the -homework problems, either way the student ID is looked up into a +homework problems, either way the student/employee ID is looked up into a username:domain. During the validation phase the instructor can choose to skip scanlines. @@ -4728,7 +4753,7 @@ sub getSequenceDropDown { } my %bubble_lines_per_response; # no. bubble lines for each response. - # index is "symb.part_id" + # key is zero-based index - 0, 1, 2 ... my %first_bubble_line; # First bubble line no. for each bubble. @@ -4769,7 +4794,6 @@ sub restore_bubble_lines { $env{"form.scantron.responsetype.$line"}; $line++; } - } # Given the parsed scanline, get the response for @@ -4778,7 +4802,6 @@ sub restore_bubble_lines { sub get_response_bubbles { my ($parsed_line, $response) = @_; - my $bubble_line = $first_bubble_line{$response-1} +1; my $bubble_lines= $bubble_lines_per_response{$response-1}; @@ -5177,8 +5200,8 @@ sub scantron_selectphase { CODEstart - (only matter if a CODE exists) column in the line where the CODE starts CODElength - length of the CODE - IDstart - column where the student ID number starts - IDlength - length of the student ID info + IDstart - column where the student/employee ID number starts + IDlength - length of the student/employee ID info Qstart - column where the information from the bubbled 'questions' start Qlength - number of columns comprising a single bubble line from @@ -5238,7 +5261,7 @@ sub get_scantron_config { =item username_to_idmap - creates a hash keyed by student id with values of the corresponding + creates a hash keyed by student/employee ID with values of the corresponding student username:domain. Arguments: @@ -5277,7 +5300,7 @@ sub username_to_idmap { $whichline - line number of the passed in scanline $field - type of change to process (either - 'ID' -> correct the student ID number + 'ID' -> correct the student/employee ID number 'CODE' -> correct the CODE 'answer' -> fixup the submitted answers) @@ -5451,7 +5474,7 @@ sub digits_to_letters { CODE_ignore_dup - 1 if the CODE is a duplicated use when unique CODEs were selected, but the usage has been forced by the operator - ID - student ID + ID - student/employee ID PaperID - if used, the ID number printed on the sheet when the paper was scanned FirstName - first name from the sheet @@ -5487,7 +5510,8 @@ sub scantron_parse_scanline { my ($line,$whichline,$scantron_config,$scan_data,$just_header)=@_; my %record; - my $questions=substr($line,$$scantron_config{'Qstart'}-1); # Answers + my $lastpos = $env{'form.scantron_maxbubble'}*$$scantron_config{'Qlength'}; + my $questions=substr($line,$$scantron_config{'Qstart'}-1,$lastpos); # Answers my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # earlier stuff if (!($$scantron_config{'CODElocation'} eq 0 || $$scantron_config{'CODElocation'} eq 'none')) { @@ -7242,7 +7266,7 @@ sub scantron_get_maxbubble { %first_bubble_line = (); %subdivided_bubble_lines = (); %responsetype_per_response = (); - + my $response_number = 0; my $bubble_line = 0; foreach my $resource (@resources) { @@ -7301,7 +7325,7 @@ sub scantron_get_maxbubble { } } } - &Apache::lonnet::delenv('scantron\.'); + &Apache::lonnet::delenv('scantron.'); &save_bubble_lines(); $env{'form.scantron_maxbubble'} = @@ -7309,33 +7333,6 @@ sub scantron_get_maxbubble { return $env{'form.scantron_maxbubble'}; } -sub scantron_partids_tograde { - my ($resource,$cid,$uname,$udom) = @_; - my (%analysis,@parts); - - if (ref($resource)) { - my $symb = $resource->symb(); - my $result=&ssi_with_retries($resource->src(), $ssi_retries, - ('symb' => $symb, - 'grade_target' => 'analyze', - 'grade_courseid' => $cid, - 'grade_domain' => $udom, - 'grade_username' => $uname)); - my (undef, $an) = split(/_HASH_REF__/,$result, 2); - %analysis = &Apache::lonnet::str2hash($an); - - if (ref($analysis{'parts'}) eq 'ARRAY') { - foreach my $part (@{$analysis{'parts'}}) { - my ($id,$respid) = split(/\./,$part); - if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) { - push(@parts,$part); - } - } - } - } - return (\%analysis,\@parts); -} - sub scantron_validate_missingbubbles { my ($r,$currentphase) = @_; #get student info @@ -7407,15 +7404,8 @@ sub scantron_process_students { my $navmap=Apache::lonnavmaps::navmap->new(); my $map=$navmap->getResourceByUrl($sequence); my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0); - - my ($uname,$udom,%partids_by_symb); - foreach my $resource (@resources) { - my $ressymb = $resource->symb(); - my ($analysis,$parts) = - &scantron_partids_tograde($resource,$env{'request.course.id'},$uname,$udom); - $partids_by_symb{$ressymb} = $parts; - } # $r->print("geto ".scalar(@resources)."
"); + my ($uname,$udom); my $result= < @@ -7439,7 +7429,6 @@ SCANTRONFORM my $started; &scantron_get_maxbubble(); # Need the bubble lines array to parse. - # If an ssi failed in scantron_get_maxbubble, put an error message out to # the user and return. @@ -7480,6 +7469,13 @@ SCANTRONFORM } ($uname,$udom)=split(/:/,$uname); + my %partids_by_symb; + foreach my $resource (@resources) { + my $ressymb = $resource->symb(); + my ($analysis,$parts) = + &scantron_partids_tograde($resource,$env{'request.course.id'},$uname,$udom); $partids_by_symb{$ressymb} = $parts; + } + &Apache::lonxml::clear_problem_counter(); &Apache::lonnet::appenv($scan_record); @@ -7496,7 +7492,7 @@ SCANTRONFORM } if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode, - @resources) eq 'ssi_error') { + \@resources,\%partids_by_symb) eq 'ssi_error') { $ssi_error = 0; # So end of handler error message does not trigger. $r->print(""); &ssi_print_error($r); @@ -7514,19 +7510,32 @@ SCANTRONFORM my $studentrecord = ''; my $counter = -1; foreach my $resource (@resources) { + my $ressymb = $resource->symb(); ($counter,my $recording) = &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'}, - $counter,$studentdata,\%partids_by_symb, + $counter,$studentdata,$partids_by_symb{$ressymb}, \%scantron_config,\%lettdig,$numletts); $studentrecord .= $recording; } if ($studentrecord ne $studentdata) { + &Apache::lonxml::clear_problem_counter(); + if (&grade_student_bubbles($r,$uname,$udom,$scan_record,$scancode, + \@resources,\%partids_by_symb) eq 'ssi_error') { + $ssi_error = 0; # So end of handler error message does not trigger. + $r->print(""); + &ssi_print_error($r); + $r->print(&show_grading_menu_form($symb)); + &Apache::lonnet::remove_lock($lock); + delete($completedstudents{$uname}); + return ''; + } $counter = -1; $studentrecord = ''; foreach my $resource (@resources) { + my $ressymb = $resource->symb(); ($counter,my $recording) = &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'}, - $counter,$studentdata,\%partids_by_symb, + $counter,$studentdata,$partids_by_symb{$ressymb}, \%scantron_config,\%lettdig,$numletts); $studentrecord .= $recording; } @@ -7563,7 +7572,7 @@ SCANTRONFORM if (&Apache::loncommon::connection_aborted($r)) { last; } } continue { &Apache::lonxml::clear_problem_counter(); - &Apache::lonnet::delenv('scantron\.'); + &Apache::lonnet::delenv('scantron.'); } &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); &Apache::lonnet::remove_lock($lock); @@ -7576,18 +7585,32 @@ SCANTRONFORM } sub grade_student_bubbles { - my ($r,$uname,$udom,$scan_record,$scancode,@resources) = @_; - foreach my $resource (@resources) { - my %form = ('submitted' => 'scantron', - 'grade_target' => 'grade', - 'grade_username'=> $uname, - 'grade_domain' => $udom, - 'grade_courseid'=> $env{'request.course.id'}, - 'grade_symb' => $resource->symb(), - 'CODE' => $scancode); - my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form); - return 'ssi_error' if ($ssi_error); - last if (&Apache::loncommon::connection_aborted($r)); + my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts) = @_; + if (ref($resources) eq 'ARRAY') { + my $count = 0; + foreach my $resource (@{$resources}) { + my $ressymb = $resource->symb(); + my %form = ('submitted' => 'scantron', + 'grade_target' => 'grade', + 'grade_username' => $uname, + 'grade_domain' => $udom, + 'grade_courseid' => $env{'request.course.id'}, + 'grade_symb' => $ressymb, + 'CODE' => $scancode + ); + if (ref($parts) eq 'HASH') { + if (ref($parts->{$ressymb}) eq 'ARRAY') { + foreach my $part (@{$parts->{$ressymb}}) { + $form{'scantron_questnum_start.'.$part} = + 1+$env{'form.scantron.first_bubble_line.'.$count}; + $count++; + } + } + } + my $result=&ssi_with_retries($resource->src(),$ssi_retries,%form); + return 'ssi_error' if ($ssi_error); + last if (&Apache::loncommon::connection_aborted($r)); + } } return; } @@ -7760,13 +7783,7 @@ sub checkscantron_results { my $navmap=Apache::lonnavmaps::navmap->new(); my $map=$navmap->getResourceByUrl($sequence); my @resources=$navmap->retrieveResources($map,undef,1,0); - my ($uname,$udom,%partids_by_symb); - foreach my $resource (@resources) { - my $ressymb = $resource->symb(); - my ($analysis,$parts) = - &scantron_partids_tograde($resource,$env{'request.course.id'},$uname,$udom); - $partids_by_symb{$ressymb} = $parts; - } + my ($uname,$udom); my (%scandata,%lastname,%bylast); $r->print('
'."\n"); @@ -7821,9 +7838,12 @@ sub checkscantron_results { ($username,$domain)=split(/:/,$uname); my $counter = -1; foreach my $resource (@resources) { + my $ressymb = $resource->symb(); + my ($analysis,$parts) = + &scantron_partids_tograde($resource,$env{'request.course.id'},$username,$domain); ($counter,my $recording) = &verify_scantron_grading($resource,$domain,$username,$cid,$counter, - $scandata{$pid},\%partids_by_symb, + $scandata{$pid},$parts, \%scantron_config,\%lettdig,$numletts); $record{$pid} .= $recording; } @@ -7888,15 +7908,14 @@ sub checkscantron_results { } sub verify_scantron_grading { - my ($resource,$domain,$username,$cid,$counter,$scandata,$partids_by_symb, + my ($resource,$domain,$username,$cid,$counter,$scandata,$partids, $scantron_config,$lettdig,$numletts) = @_; my ($record,%expected,%startpos); return ($counter,$record) if (!ref($resource)); return ($counter,$record) if (!$resource->is_problem()); my $symb = $resource->symb(); - return ($counter,$record) if (ref($partids_by_symb) ne 'HASH'); - return ($counter,$record) if (ref($partids_by_symb->{$symb}) ne 'ARRAY'); - foreach my $part_id (@{$partids_by_symb->{$symb}}) { + return ($counter,$record) if (ref($partids) ne 'ARRAY'); + foreach my $part_id (@{$partids}) { $counter ++; $expected{$part_id} = 0; if ($env{"form.scantron.sub_bubblelines.$counter"}) { @@ -7989,7 +8008,7 @@ sub verify_scantron_grading { } } } - foreach my $part_id (@{$partids_by_symb->{$symb}}) { + foreach my $part_id (@{$partids}) { if ($recorded{$part_id} eq '') { for (my $i=0; $i<$expected{$part_id}; $i++) { for (my $j=0; $j<$scantron_config->{'Qlength'}; $j++) { @@ -9158,7 +9177,7 @@ ssi_with_retries() =item scantron_validate_ID() : Validates all scanlines in the selected file to not have any - invalid or underspecified student IDs + invalid or underspecified student/employee IDs =back