--- loncom/homework/grades.pm 2013/05/30 05:04:31 1.688 +++ loncom/homework/grades.pm 2013/07/24 15:12:33 1.698 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.688 2013/05/30 05:04:31 raeburn Exp $ +# $Id: grades.pm,v 1.698 2013/07/24 15:12:33 kruse Exp $ # # Copyright Michigan State University Board of Trustees # @@ -736,7 +736,7 @@ sub most_similar { sub initialverifyreceipt { my ($request,$symb) = @_; &commonJSfunctions($request); - return '
"); &ssi_print_error($r); @@ -8117,7 +8403,9 @@ SCANTRONFORM ($counter,my $recording) = &verify_scantron_grading($resource,$udom,$uname,$env{'request.course.id'}, $counter,$studentdata,$partids_by_symb{$ressymb}, - \%scantron_config,\%lettdig,$numletts); + \%scantron_config,\%lettdig,$numletts, + $randomorder,$randompick,\%respnumlookup, + \%startline); $studentrecord .= $recording; } if ($studentrecord ne $studentdata) { @@ -8195,32 +8483,37 @@ sub graders_resources_pass { if this is a CODEd exam, or based on student's identity if this is a "NAMEd" exam. - Should be used when randomorder applied when the corresponding exam was - printed, prior to students completing bubblesheets for the version of the - exam the student received. + Should be used when randomorder and/or randompick applied when the + corresponding exam was printed, prior to students completing bubblesheets + for the version of the exam the student received. =cut sub users_order { - my ($user,$scancode,$mapurl,$master_seq,$ordered,$symb_to_resource) = @_; + my ($user,$scancode,$mapurl,$master_seq,$symb_to_resource,$orderedforcode) = @_; my @mapresources; - unless ((ref($ordered) eq 'HASH') && (ref($symb_to_resource) eq 'HASH')) { + unless ((ref($master_seq) eq 'ARRAY') && (ref($symb_to_resource) eq 'HASH')) { return @mapresources; - } - if (($scancode) && (ref($ordered->{$scancode}) eq 'ARRAY')) { - @mapresources = @{$ordered->{$scancode}}; - } elsif ($scancode) { - $env{'form.CODE'} = $scancode; - my $actual_seq = - &Apache::lonprintout::master_seq_to_person_seq($mapurl, - $master_seq, - $user,$scancode,1); - if (ref($actual_seq) eq 'ARRAY') { - @{$ordered->{$scancode}} = - map { $symb_to_resource->{$_}; } @{$actual_seq}; - @mapresources = @{$ordered->{$scancode}}; + } + if ($scancode) { + if ((ref($orderedforcode) eq 'HASH') && (ref($orderedforcode->{$scancode}) eq 'ARRAY')) { + @mapresources = @{$orderedforcode->{$scancode}}; + } else { + $env{'form.CODE'} = $scancode; + my $actual_seq = + &Apache::lonprintout::master_seq_to_person_seq($mapurl, + $master_seq, + $user,$scancode,1); + if (ref($actual_seq) eq 'ARRAY') { + @mapresources = map { $symb_to_resource->{$_}; } @{$actual_seq}; + if (ref($orderedforcode) eq 'HASH') { + if (@mapresources > 0) { + $orderedforcode->{$scancode} = \@mapresources; + } + } + } + delete($env{'form.CODE'}); } - delete($env{'form.CODE'}); } else { my $actual_seq = &Apache::lonprintout::master_seq_to_person_seq($mapurl, @@ -8230,12 +8523,19 @@ sub users_order { @mapresources = map { $symb_to_resource->{$_}; } @{$actual_seq}; } - } - return @mapresources; + } + return @mapresources; } sub grade_student_bubbles { - my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row) = @_; + my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row, + $randomorder,$randompick,$respnumlookup,$startline) = @_; + my $uselookup = 0; + if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH') && + (ref($startline) eq 'HASH')) { + $uselookup = 1; + } + if (ref($resources) eq 'ARRAY') { my $count = 0; foreach my $resource (@{$resources}) { @@ -8257,8 +8557,12 @@ sub grade_student_bubbles { 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}; + if ($uselookup) { + $form{'scantron_questnum_start.'.$part} = $startline->{$count} + 1; + } else { + $form{'scantron_questnum_start.'.$part} = + 1+$env{'form.scantron.first_bubble_line.'.$count}; + } $count++; } } @@ -8539,19 +8843,18 @@ sub checkscantron_results { return ''; } my $map=$navmap->getResourceByUrl($sequence); - my ($randomorder,@master_seq,%symb_to_resource); + my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb, + %grader_randomlists_by_symb,%orderedforcode); if (ref($map)) { $randomorder=$map->randomorder(); + $randompick=$map->randompick(); } my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0); - foreach my $resource (@resources) { - if (ref($resource)) { - my $ressymb = $resource->symb(); - push(@master_seq,$ressymb); - $symb_to_resource{$ressymb} = $resource; - } + my $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource); + if ($nav_error) { + $r->print(&navmap_errormsg()); + return ''; } - my (%grader_partids_by_symb,%grader_randomlists_by_symb); &graders_resources_pass(\@resources,\%grader_partids_by_symb, \%grader_randomlists_by_symb,$bubbles_per_row); my ($uname,$udom); @@ -8562,10 +8865,9 @@ sub checkscantron_results { my @delayqueue; my %completedstudents; - my $count=&Apache::grades::get_todo_count($scanlines,$scan_data); + my $count=&get_todo_count($scanlines,$scan_data); my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count); my ($username,$domain,$started,%ordered); - my $nav_error; &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse. if ($nav_error) { $r->print(&navmap_errormsg()); @@ -8588,8 +8890,8 @@ sub checkscantron_results { my $scan_record= &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config, $scan_data); - unless ($uname=&Apache::grades::scantron_find_student($scan_record,$scan_data, - \%idmap,$i)) { + unless ($uname=&scantron_find_student($scan_record,$scan_data, + \%idmap,$i)) { &Apache::grades::scantron_add_delay(\@delayqueue,$line, 'Unable to find a student that matches',1); next; @@ -8602,10 +8904,6 @@ sub checkscantron_results { my $pid = $scan_record->{'scantron.ID'}; $lastname{$pid} = $scan_record->{'scantron.LastName'}; push(@{$bylast{$lastname{$pid}}},$pid); - my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'}; - $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos); - chomp($scandata{$pid}); - $scandata{$pid} =~ s/\r$//; my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION]; my $user = $uname.':'.$usec; ($username,$domain)=split(/:/,$uname); @@ -8619,11 +8917,25 @@ sub checkscantron_results { } my @mapresources = @resources; - if ($randomorder) { + my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'}; + my %respnumlookup=(); + my %startline=(); + if ($randomorder || $randompick) { @mapresources = - &users_order($user,$scancode,$sequence,\@master_seq,\%ordered, - \%symb_to_resource); + &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource, + \%orderedforcode); + my $total = &get_respnum_lookups($sequence,$scan_data,\%idmap,$line, + $scan_record,\@master_seq,\%symb_to_resource, + \%grader_partids_by_symb,\%orderedforcode, + \%respnumlookup,\%startline); + if ($randompick && $total) { + $lastpos = $total*$scantron_config{'Qlength'}; + } } + $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos); + chomp($scandata{$pid}); + $scandata{$pid} =~ s/\r$//; + my $counter = -1; foreach my $resource (@mapresources) { my $parts; @@ -8640,7 +8952,9 @@ sub checkscantron_results { ($counter,my $recording) = &verify_scantron_grading($resource,$domain,$username,$cid,$counter, $scandata{$pid},$parts, - \%scantron_config,\%lettdig,$numletts); + \%scantron_config,\%lettdig,$numletts, + $randomorder,$randompick, + \%respnumlookup,\%startline); $record{$pid} .= $recording; } } @@ -8718,7 +9032,8 @@ sub checkscantron_results { sub verify_scantron_grading { my ($resource,$domain,$username,$cid,$counter,$scandata,$partids, - $scantron_config,$lettdig,$numletts) = @_; + $scantron_config,$lettdig,$numletts,$randomorder,$randompick, + $respnumlookup,$startline) = @_; my ($record,%expected,%startpos); return ($counter,$record) if (!ref($resource)); return ($counter,$record) if (!$resource->is_problem()); @@ -8727,15 +9042,21 @@ sub verify_scantron_grading { foreach my $part_id (@{$partids}) { $counter ++; $expected{$part_id} = 0; - if ($env{"form.scantron.sub_bubblelines.$counter"}) { - my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$counter"}); + my $respnum = $counter; + if ($randomorder || $randompick) { + $respnum = $respnumlookup->{$counter}; + $startpos{$part_id} = $startline->{$counter} + 1; + } else { + $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"}; + } + if ($env{"form.scantron.sub_bubblelines.$respnum"}) { + my @sub_lines = split(/,/,$env{"form.scantron.sub_bubblelines.$respnum"}); foreach my $item (@sub_lines) { $expected{$part_id} += $item; } } else { - $expected{$part_id} = $env{"form.scantron.bubblelines.$counter"}; + $expected{$part_id} = $env{"form.scantron.bubblelines.$respnum"}; } - $startpos{$part_id} = $env{"form.scantron.first_bubble_line.$counter"}; } if ($symb) { my %recorded; @@ -8831,7 +9152,7 @@ sub verify_scantron_grading { return ($counter,$record); } -sub letter_to_digits { +sub letter_to_digits { my %lettdig = ( A => 1, B => 2, @@ -9469,7 +9790,7 @@ ENDHEADER &mt('Found [_1] registered and [_2] unregistered clickers.',$student_count,$unknown_count); if (($env{'form.gradingmechanism'} ne 'attendance') && ($env{'form.gradingmechanism'} ne 'given')) { if ($correct_count==0) { - $errormsg.="Found no correct answers answers for grading!"; + $errormsg.="Found no correct answers for grading!"; } elsif ($correct_count>1) { $result.='