--- loncom/homework/response.pm 2011/06/06 17:43:51 1.224 +++ loncom/homework/response.pm 2011/11/14 03:08:01 1.227 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # various response type definitons response definition # -# $Id: response.pm,v 1.224 2011/06/06 17:43:51 www Exp $ +# $Id: response.pm,v 1.227 2011/11/14 03:08:01 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -322,7 +322,7 @@ sub check_for_previous { next if (($questiontype eq 'randomizetry') && ($curr_rndseed ne $Apache::lonhomework::history{"$history:resource.$partid.rndseed"})); push (@{$previous{'versionci'}},$history); - $previous{'awardci'} = $Apache::lonhomework::history{"resource.$partid.$id.awarddetail"}; + $previous{'awardci'} = $Apache::lonhomework::history{"$history:resource.$partid.$id.awarddetail"}; $previous{'usedci'} = 1; } } @@ -494,8 +494,8 @@ sub end_customresponse { } if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') { - &Apache::lonxml::increment_counter(&Apache::response::repetition(), - "$part.$id"); + my $repetition = &repetition(); + &Apache::lonxml::increment_counter($repetition,"$part.$id"); if ($target eq 'analyze') { $Apache::lonhomework::analyze{"$part.$id.type"} = 'customresponse'; &Apache::lonhomework::set_bubble_lines(); @@ -1003,16 +1003,18 @@ sub getresponse { $Apache::lonhomework::results{"resource.$part.$id.scantron"}.= $response; if ($resulttype ne 'letter') { - if ($resulttype eq 'A is 1') { - $response = $let_to_num{$response}+1; - } else { - $response = $let_to_num{$response}; + $response = $let_to_num{$response}; + if ($resulttype eq 'A is 1') { + if ($response ne "") { + $response = $response+1; + } } if ($response ne "") { $response += $line * $bubbles_per_line; } } else { if ($response ne "") { + my $raw = $response; $response = chr(ord($response) + $line * $bubbles_per_line); } } @@ -1032,8 +1034,17 @@ sub getresponse { =item &repetition(); -Returns the number of lines that are required to encode the weight. -(Currently expects that there are 10 bubbles per line) +In scalar context: + +returns: the number of lines that are required to encode the weight. +(Default is for 10 bubbles per bubblesheet item; other (integer) +values can be specified by using a custom Bubblesheet format file +with an eighteenth entry (BubblesPerRow) set to the integer +appropriate for the bubblesheets which will be used to assign weights. + +In array context: + +returns: number of lines required to encode weight, and bubbles/line. =cut @@ -1041,9 +1052,25 @@ sub repetition { my $id = $Apache::inputtags::part; my $weight = &Apache::lonnet::EXT("resource.$id.weight"); if (!defined($weight) || ($weight eq '')) { $weight=1; } - my $repetition = int($weight/10); - if ($weight % 10 != 0) { $repetition++; } + my $bubbles_per_row; + if (($env{'form.bubbles_per_row'} =~ /^\d+$/) && + ($env{'form.bubbles_per_row'} > 0)) { + $bubbles_per_row = $env{'form.bubbles_per_row'}; + } else { + $bubbles_per_row = 10; + } + my $denominator = $bubbles_per_row; + if (($env{'form.scantron_lastbubblepoints'} == 0) && + ($bubbles_per_row > 1)) { + $denominator = $bubbles_per_row - 1; + } + my $repetition = int($weight/$denominator); + if ($weight % $denominator != 0) { $repetition++; } + if (wantarray) { + return ($repetition,$bubbles_per_row); + } return $repetition; + } =pod @@ -1073,11 +1100,24 @@ Arguments sub scored_response { my ($part,$id)=@_; my $repetition=&repetition(); + my $bubbles_per_row; + if (($env{'form.bubbles_per_row'} =~ /^\d+$/) && + ($env{'form.bubbles_per_row'} > 0)) { + $bubbles_per_row = $env{'form.bubbles_per_row'}; + } else { + $bubbles_per_row = 10; + } my $score=0; for (my $i=0;$i<$repetition;$i++) { - # A is 1, B is 2, etc. (get response return 0-9 and then we add 1) + # A is 1, B is 2, etc. my $increase=&Apache::response::getresponse($i+1); - if ($increase ne '') { $score+=$increase+1; } + unless (($increase == $bubbles_per_row-1) && + ($env{'form.scantron_lastbubblepoints'} == 0)) { + # (get response return 0-9 and then we add 1) + if ($increase ne '') { + $score+=$increase+1; + } + } } my $weight = &Apache::lonnet::EXT("resource.$part.weight"); if (!defined($weight) || $weight eq '' || $weight eq 0) { $weight = 1; }