version 1.198, 2006/12/04 23:56:20
|
version 1.206, 2007/01/23 22:00:16
|
Line 33 use Safe::Hole;
|
Line 33 use Safe::Hole;
|
use Apache::lonmaxima(); |
use Apache::lonmaxima(); |
use Apache::lonlocal; |
use Apache::lonlocal; |
use Apache::lonnet; |
use Apache::lonnet; |
|
use Apache::response(); |
use Storable qw(dclone); |
use Storable qw(dclone); |
|
|
BEGIN { |
BEGIN { |
Line 40 BEGIN {
|
Line 41 BEGIN {
|
} |
} |
|
|
my %answer; |
my %answer; |
|
my @answers; |
|
sub get_answer { return %answer; }; |
|
sub push_answer{ push(@answers,dclone(\%answer)); undef(%answer) } |
|
sub pop_answer { %answer = %{pop(@answers)}; }; |
|
|
my $cur_name; |
my $cur_name; |
my $tag_internal_answer_name = 'INTERNAL'; |
my $tag_internal_answer_name = 'INTERNAL'; |
|
|
Line 231 sub set_answertext {
|
Line 237 sub set_answertext {
|
$response_level) = @_; |
$response_level) = @_; |
&add_in_tag_answer($parstack,$safeeval,$response_level); |
&add_in_tag_answer($parstack,$safeeval,$response_level); |
|
|
|
if ($name eq '' || !ref($answer{$name})) { |
|
if (ref($answer{$tag_internal_answer_name})) { |
|
$name = $tag_internal_answer_name; |
|
} else { |
|
$name = (sort(keys(%answer)))[0]; |
|
} |
|
} |
return if ($name eq '' || !ref($answer{$name})); |
return if ($name eq '' || !ref($answer{$name})); |
|
|
my (@formats)=&Apache::lonxml::get_param_var('format',$parstack, |
my (@formats)=&Apache::lonxml::get_param_var('format',$parstack, |
Line 324 sub check_submission {
|
Line 337 sub check_submission {
|
} |
} |
|
|
if ($tag eq 'formularesponse') { |
if ($tag eq 'formularesponse') { |
# if ($$args_ref{'samples'}) { |
if ($$args_ref{'samples'}) { |
$$args_ref{'type'}='fml'; |
$$args_ref{'type'}='fml'; |
# } else { |
} else { |
# $$args_ref{'type'}='math'; |
$$args_ref{'type'}='math'; |
# } |
} |
} elsif ($tag eq 'numericalresponse') { |
} elsif ($tag eq 'numericalresponse') { |
$$args_ref{'type'}='float'; |
$$args_ref{'type'}='float'; |
} |
} |
Line 372 sub add_in_tag_answer {
|
Line 385 sub add_in_tag_answer {
|
} |
} |
} |
} |
|
|
|
sub capa_formula_fix { |
|
my ($expression)=@_; |
|
return &Apache::response::implicit_multiplication($expression); |
|
} |
|
|
sub end_numericalresponse { |
sub end_numericalresponse { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $increment=1; |
my $increment=1; |
Line 384 sub end_numericalresponse {
|
Line 402 sub end_numericalresponse {
|
my $tag; |
my $tag; |
my $safehole = new Safe::Hole; |
my $safehole = new Safe::Hole; |
$safeeval->share_from('capa',['&caparesponse_capa_check_answer']); |
$safeeval->share_from('capa',['&caparesponse_capa_check_answer']); |
$safehole->wrap(\&Apache::lonmaxima::maxima_check,$safeeval,'&maxima_check'); |
|
|
|
if (scalar(@$tagstack)) { $tag=$$tagstack[-1]; } |
if (scalar(@$tagstack)) { $tag=$$tagstack[-1]; } |
if ( $target eq 'grade' && &Apache::response::submitted() ) { |
if ( $target eq 'grade' && &Apache::response::submitted() ) { |
Line 524 sub end_numericalresponse {
|
Line 541 sub end_numericalresponse {
|
} |
} |
foreach my $name (sort(keys(%answer))) { |
foreach my $name (sort(keys(%answer))) { |
my @answers = @{ $answer{$name}{'answers'} }; |
my @answers = @{ $answer{$name}{'answers'} }; |
|
if ($target eq 'analyze') { |
|
foreach my $info ('answer','ans_high','ans_low','format') { |
|
$Apache::lonhomework::analyze{"$part_id.$info"}{$name}=[]; |
|
} |
|
} |
my ($sigline,$tolline); |
my ($sigline,$tolline); |
if ($name ne $tag_internal_answer_name |
if ($name ne $tag_internal_answer_name |
|| scalar(keys(%answer)) > 1) { |
|| scalar(keys(%answer)) > 1) { |
Line 543 sub end_numericalresponse {
|
Line 565 sub end_numericalresponse {
|
} else { |
} else { |
@vector = ($ans); |
@vector = ($ans); |
} |
} |
if ($target eq 'answer') { |
my @all_answer_info; |
my @all_answer_info; |
foreach my $element (@vector) { |
foreach my $element (@vector) { |
my ($high,$low); |
my ($high,$low); |
if ($Apache::inputtags::params{'tol'}) { |
if ($Apache::inputtags::params{'tol'}) { |
($high,$low)=&get_tolrange($element,$Apache::inputtags::params{'tol'}); |
($high,$low)=&get_tolrange($element,$Apache::inputtags::params{'tol'}); |
} |
} |
if ($target eq 'answer') { |
if ($fmt && $tag eq 'numericalresponse') { |
if ($fmt && $tag eq 'numericalresponse') { |
$fmt=~s/e/E/g; |
$fmt=~s/e/E/g; |
if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; } |
if ($unit=~/\$/) { $fmt="\$".$fmt; $unit=~s/\$//g; } |
Line 573 sub end_numericalresponse {
|
Line 595 sub end_numericalresponse {
|
} |
} |
} |
} |
push(@all_answer_info,$element); |
push(@all_answer_info,$element); |
|
|
|
} elsif ($target eq 'analyze') { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.answer"}{$name}[$i] }, $element); |
|
if ($high) { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.ans_high"}{$name}[$i] }, $high); |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.ans_low"}{$name}[$i] }, $low); |
|
} |
|
if ($fmt) { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.format"}{$name}[$i] }, $fmt); |
|
} |
} |
} |
|
} |
|
if ($target eq 'answer') { |
$result.= &Apache::response::answer_part($tag,join(', ',@all_answer_info)); |
$result.= &Apache::response::answer_part($tag,join(', ',@all_answer_info)); |
} elsif ($target eq 'analyze') { |
|
my ($high,$low); |
|
if ($Apache::inputtags::params{'tol'}) { |
|
($high,$low)=&get_tolrange($ans,$Apache::inputtags::params{'tol'}); |
|
} |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.answer"} }, $ans); |
|
if ($high) { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.ans_high"} }, $high); |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.ans_low"} }, $low); |
|
} |
|
if ($fmt) { |
|
push (@{ $Apache::lonhomework::analyze{"$part_id.format"} }, $fmt); |
|
} |
|
} |
} |
} |
} |
|
|
Line 772 sub make_numerical_bubbles {
|
Line 793 sub make_numerical_bubbles {
|
&Apache::response::get_response_param($part.'_'.$id,'numbubbles',8); |
&Apache::response::get_response_param($part.'_'.$id,'numbubbles',8); |
|
|
my ($format)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval); |
my ($format)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval); |
my ($answer)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval); |
my $name = (exists($answer{$tag_internal_answer_name}) |
|
? $tag_internal_answer_name |
|
: (sort(keys(%answer)))[0]); |
|
|
|
if ( scalar(@{$answer{$name}{'answers'}}) > 1) { |
|
&Apache::lonxml::error("Only answers with 1 component are supported in exam mode"); |
|
} |
|
if (scalar(@{$answer{$name}{'answers'}[0]}) > 1) { |
|
&Apache::lonxml::error("Vector answers are unsupported in exam mode."); |
|
} |
|
|
|
my $answer = $answer{$name}{'answers'}[0][0]; |
my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack, |
my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack, |
$safeeval); |
$safeeval); |
if ($#incorrect eq 0) { @incorrect=(split(/,/,$incorrect[0])); } |
if ($#incorrect eq 0) { @incorrect=(split(/,/,$incorrect[0])); } |
Line 1005 sub end_stringresponse {
|
Line 1037 sub end_stringresponse {
|
} |
} |
} |
} |
} elsif ($target eq 'answer' || $target eq 'analyze') { |
} elsif ($target eq 'answer' || $target eq 'analyze') { |
|
&add_in_tag_answer($parstack,$safeeval); |
if ($target eq 'analyze') { |
if ($target eq 'analyze') { |
push (@{ $Apache::lonhomework::analyze{"parts"} },"$part.$id"); |
push (@{ $Apache::lonhomework::analyze{"parts"} },"$part.$id"); |
$Apache::lonhomework::analyze{"$part.$id.type"} = 'stringresponse'; |
$Apache::lonhomework::analyze{"$part.$id.type"} = 'stringresponse'; |
Line 1015 sub end_stringresponse {
|
Line 1048 sub end_stringresponse {
|
if ($target eq 'answer') { |
if ($target eq 'answer') { |
$result.=&Apache::response::answer_header('stringresponse'); |
$result.=&Apache::response::answer_header('stringresponse'); |
} |
} |
# foreach my $ans (@answers) { |
foreach my $name (keys(%answer)) { |
if ($target eq 'answer') { |
my @answers = @{ $answer{$name}{'answers'} }; |
$result.=&Apache::response::answer_part('stringresponse',$answer); |
for (my $i=0;$i<=$#answers;$i++) { |
if ($type eq 're') { |
my $answer_part = $answers[$i]; |
|
foreach my $element (@{$answer_part}) { |
|
if ($target eq 'answer') { |
|
$result.=&Apache::response::answer_part('stringresponse', |
|
$element); |
|
} elsif ($target eq 'analyze') { |
|
push (@{ $Apache::lonhomework::analyze{"$part.$id.answer"}{$name}[$i] }, |
|
$element); |
|
} |
|
} |
|
if ($target eq 'answer' && $type eq 're') { |
$result.=&Apache::response::answer_part('stringresponse', |
$result.=&Apache::response::answer_part('stringresponse', |
$answerdisplay); |
$answerdisplay); |
} |
} |
} elsif ($target eq 'analyze') { |
|
push (@{ $Apache::lonhomework::analyze{"$part.$id.answer"} }, |
|
$answer); |
|
} |
} |
# } |
} |
my $string='Case Insensitive'; |
my $string='Case Insensitive'; |
if ($type eq 'mc') { |
if ($type eq 'mc') { |
$string='Multiple Choice'; |
$string='Multiple Choice'; |