--- loncom/homework/caparesponse/caparesponse.pm 2007/03/15 02:51:29 1.210
+++ loncom/homework/caparesponse/caparesponse.pm 2010/02/28 23:45:43 1.237
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.210 2007/03/15 02:51:29 albertel Exp $
+# $Id: caparesponse.pm,v 1.237 2010/02/28 23:45:43 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -392,9 +392,6 @@ sub setup_capa_args {
sub setup_capa_response {
my ($args_ref,$response) = @_;
- use Data::Dumper;
- &Apache::lonxml::debug("response dump is ".&Dumper($response));
-
if (ref($response)) {
$$args_ref{'response'}=dclone($response);
} else {
@@ -430,10 +427,18 @@ sub check_submission {
}
} elsif ($tag eq 'numericalresponse') {
$$args_ref{'type'}='float';
+ } elsif ($tag eq 'stringresponse') {
+ if ($$args_ref{'type'} eq '') {
+ $$args_ref{'type'} = 'ci';
+ }
}
-
+
&add_in_tag_answer($parstack,$safeeval);
+ if (!%answer) {
+ &Apache::lonxml::error("No answers are defined");
+ }
+
my (@final_awards,@final_msgs,@names);
foreach my $name (keys(%answer)) {
&Apache::lonxml::debug(" doing $name with ".join(':',@{ $answer{$name}{'answers'} }));
@@ -465,7 +470,7 @@ sub add_in_tag_answer {
my @answer=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval,
$response_level);
&Apache::lonxml::debug('answer is'.join(':',@answer));
- if (@answer && defined($answer[0])) {
+ if (@answer && $answer[0] =~ /\S/) {
$answer{$tag_internal_answer_name}= {'type' => 'ordered',
'answers' => [\@answer] };
}
@@ -509,12 +514,12 @@ sub end_numericalresponse {
&Apache::lonxml::debug($$parstack[-1] . "\n
");
if ( &Apache::response::submitted('scantron')) {
- &add_in_tag_answer($parstack,$safeeval);
- my ($values,$display)=&make_numerical_bubbles($partid,$id,
- $target,$parstack,$safeeval);
- $response=$values->[$response];
- }
- $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
+ &add_in_tag_answer($parstack,$safeeval);
+ my ($values,$display)=&make_numerical_bubbles($partid,$id,
+ $target,$parstack,$safeeval);
+ $response=$values->[$response];
+ }
+ $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
my ($ad,$msg,$name)=&check_submission($response,$partid,$id,
$tag,$parstack,
$safeeval);
@@ -528,11 +533,18 @@ sub end_numericalresponse {
$Apache::inputtags::params{'sig'});
}
&Apache::lonxml::debug("\n
result:$result:$Apache::lonxml::curdepth
\n");
- if ($Apache::lonhomework::type eq 'survey' &&
- ($ad eq 'INCORRECT' || $ad eq 'APPROX_ANS' ||
- $ad eq 'EXACT_ANS')) {
- $ad='SUBMITTED';
- }
+ if (($ad eq 'INCORRECT' || $ad eq 'APPROX_ANS' ||
+ $ad eq 'EXACT_ANS')) {
+ if ($Apache::lonhomework::type eq 'survey') {
+ $ad='SUBMITTED';
+ } elsif ($Apache::lonhomework::type eq 'surveycred') {
+ $ad='SUBMITTED_CREDIT';
+ } elsif ($Apache::lonhomework::type eq 'anonsurvey') {
+ $ad='ANONYMOUS';
+ } elsif ($Apache::lonhomework::type eq 'anonsurveycred') {
+ $ad='ANONYMOUS_CREDIT';
+ }
+ }
&Apache::response::handle_previous(\%previous,$ad);
$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
$Apache::lonhomework::results{"resource.$partid.$id.awardmsg"}=$msg;
@@ -601,7 +613,13 @@ sub end_numericalresponse {
}
}
}
- &setup_prior_tries_hash();
+ if (($target eq 'web') && ($tag eq 'formularesponse')
+ && ($Apache::lonhomework::type ne 'exam') && ($Apache::inputtags::status['-1'] eq 'CAN_ANSWER')
+ && (&Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.turnoffeditor') ne 'yes')) {
+ $result.=&Apache::response::edit_mathresponse_button($id,"HWVAL_$id");
+ }
+
+ &Apache::response::setup_prior_tries_hash(\&format_prior_response_numerical);
} elsif ($target eq 'edit') {
$result.=''.&Apache::edit::end_table;
} elsif ($target eq 'answer' || $target eq 'analyze') {
@@ -677,12 +695,12 @@ sub end_numericalresponse {
#}
}
if ($high && $tag eq 'numericalresponse') {
- $element.=' ['.$low.','.$high.']';
+ $element.='; ['.$low.'; '.$high.']';
$tolline .= "[$low, $high]";
}
if (defined($sighigh) && $tag eq 'numericalresponse') {
if ($env{'form.answer_output_mode'} eq 'tex') {
- $element.= " Sig $siglow - $sighigh";
+ $element.= "; Sig $siglow - $sighigh";
} else {
$element.= " Sig $siglow - $sighigh";
$sigline .= "[$siglow, $sighigh]";
@@ -702,7 +720,7 @@ sub end_numericalresponse {
}
}
if ($target eq 'answer') {
- $result.= &Apache::response::answer_part($tag,join(', ',@all_answer_info));
+ $result.= &Apache::response::answer_part($tag,join('; ',@all_answer_info));
}
}
@@ -741,16 +759,17 @@ sub end_numericalresponse {
if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
my $error;
if ($tag eq 'formularesponse') {
- $error=&mt('Computer\'s answer is incorrect ("[_1]").',join(', ',@$response));
+ $error=&mt("Computer's answer is incorrect ([_1]).",'"'.join(', ',@$response).'"');
} else {
# answer failed check if it is sig figs that is failing
my ($ad,$msg)=&check_submission($response,$partid,$id,
$tag,$parstack,
$safeeval,1);
+ $error=&mt("Computer's answer is incorrect ([_1]).",'"'.join(', ',@$response).'"').' ';
if ($sigline ne '') {
- $error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] or significant figures [_3] need to be adjusted.',join(', ',@$response),$tolline,$sigline);
+ $error.=&mt('It is likely that the tolerance range [_1] or significant figures [_2] need to be adjusted.',$tolline,$sigline);
} else {
- $error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] needs to be adjusted.',join(', ',@$response),$tolline);
+ $error.=&mt('It is likely that the tolerance range [_1] needs to be adjusted.',$tolline);
}
}
if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
@@ -786,24 +805,35 @@ sub end_numericalresponse {
}
if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' ||
$target eq 'tex' || $target eq 'analyze') {
- &Apache::lonxml::increment_counter($increment);
+ if (($tag eq 'formularesponse') && ($target eq 'analyze')) {
+ my $type = &Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.type');
+ if ($type eq 'exam') {
+ $increment = &Apache::response::repetition();
+ }
+ }
+ &Apache::lonxml::increment_counter($increment,"$partid.$id");
+ if ($target eq 'analyze') {
+ &Apache::lonhomework::set_bubble_lines();
+ }
}
&Apache::response::end_response();
return $result;
}
-sub setup_prior_tries_hash {
- #FIXME support multi answer numericals/formula
- my $part=$Apache::inputtags::part;
- my $id=$Apache::inputtags::response[-1];
- foreach my $i (1..$Apache::lonhomework::history{'version'}) {
- my $key = "$i:resource.$part.$id.submission";
- next if (!exists($Apache::lonhomework::history{"$key"}));
- $Apache::inputtags::submission_display{$key} =
- ''.
- &HTML::Entities::encode($Apache::lonhomework::history{$key},
- '"<>&').'';
+sub format_prior_response_numerical {
+ my ($mode,$answer) = @_;
+ if (ref($answer)) {
+ my $result = '
'. + &HTML::Entities::encode($element,'"<>&').' | '; + } + $result.='