--- loncom/homework/caparesponse/caparesponse.pm 2003/03/03 14:39:41 1.81
+++ loncom/homework/caparesponse/caparesponse.pm 2003/04/07 23:14:52 1.88
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.81 2003/03/03 14:39:41 sakharuk Exp $
+# $Id: caparesponse.pm,v 1.88 2003/04/07 23:14:52 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -46,7 +46,7 @@ sub end_caparesponse {
if ( $target eq 'grade' ) {
if ( defined $ENV{'form.submitted'}) {
$safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
- my $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']};
+ my $response = $ENV{'form.HWVAL_'.$Apache::inputtags::response['-1']};
if ( $response =~ /[^\s]/) {
my $id = $Apache::inputtags::response['-1'];
my $previous= &Apache::response::check_for_previous($response,$id,$response);
@@ -134,34 +134,43 @@ sub end_numericalresponse {
$safeeval->share_from('capa',['&caparesponse_capa_check_answer']);
my $partid = $Apache::inputtags::part;
my $id = $Apache::inputtags::response['-1'];
- my $response = $ENV{'form.HWVAL'.$id};
+ my $response = &Apache::response::getresponse();
if ( $response =~ /[^\s]/) {
+ my $ad;
my %previous = &Apache::response::check_for_previous($response,$partid,$id);
$Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
&Apache::lonxml::debug("submitted a $response
\n");
&Apache::lonxml::debug($$parstack[$#$parstack] . "\n
");
- $response =~ s/\\/\\\\/g;
- $response =~ s/\'/\\\'/g;
- &Apache::lonxml::debug("current $response");
- my $expression="&caparesponse_check_list('".$response."','".
- $$parstack[-1];
- foreach my $key (keys(%Apache::inputtags::params)) {
- $expression.= ';my $'. #'
- $key.'="'.$Apache::inputtags::params{$key}.'"';
- }
- if ($$tagstack[-1] eq 'formularesponse') {
- $expression.=';my $type="fml";';
- } elsif ($$tagstack[-1] eq 'numericalresponse') {
- $expression.=';my $type="float";';
+ if ($Apache::lonhomework::type eq 'exam' &&
+ ($$tagstack[-1] eq 'numericalresponse')) {
+ &Apache::response::setrandomnumber();
+ #FIXME the 8 here is based off of number of powers need a parameter
+ my $ind=&Math::Random::random_uniform_integer(1,0,8);
+ if ($ind eq $response) { $ad='CORRECT'; } else { $ad='INCORRECT'; }
+ } else {
+ $response =~ s/\\/\\\\/g;
+ $response =~ s/\'/\\\'/g;
+ &Apache::lonxml::debug("current $response");
+ my $expression="&caparesponse_check_list('".$response."','".
+ $$parstack[-1];
+ foreach my $key (keys(%Apache::inputtags::params)) {
+ $expression.= ';my $'. #'
+ $key.'="'.$Apache::inputtags::params{$key}.'"';
+ }
+ if ($$tagstack[-1] eq 'formularesponse') {
+ $expression.=';my $type="fml";';
+ } elsif ($$tagstack[-1] eq 'numericalresponse') {
+ $expression.=';my $type="float";';
+ }
+ $expression.="');";
+ $result = &Apache::run::run($expression,$safeeval);
+ my ($awards) = split /:/ , $result;
+ ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
+ &Apache::lonxml::debug("$expression");
+ &Apache::lonxml::debug("\n
result:$result:$Apache::lonxml::curdepth
\n");
}
- $expression.="');";
- $result = &Apache::run::run($expression,$safeeval);
- my ($awards) = split /:/ , $result;
- my ($ad) = &Apache::inputtags::finalizeawards(split /,/ , $awards);
&Apache::response::handle_previous(\%previous,$ad);
$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad;
- &Apache::lonxml::debug("$expression");
- &Apache::lonxml::debug("\n
result:$result:$Apache::lonxml::curdepth
\n");
$result='';
}
}
@@ -178,9 +187,6 @@ sub end_numericalresponse {
if ($target eq 'web') {
$result="
The correct answer is ";
} elsif ($target eq 'tex') {
- if (defined $unit and $Apache::lonhomework::type eq 'exam') {
- $result.=' \textit{(in} \verb|'.$unit.'|\textit{)} ';
- }
#$result='\vskip 0 mm The correct answer is \\texttt{';
}
for (my $i=0; $i <= $#answers; $i++) {
@@ -222,11 +228,6 @@ sub end_numericalresponse {
my @bubbles_values = ();
my @factors = (1.13,1.17,1.25,1.33,1.45); #default values of factors
my @powers = (1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0); #default values for powers
- my $factors_number = 5; #default values for number of factors
- my $powers_number = 8; #default values for number of powers
- my $symb;
- if ($ENV{'form.symb'}=~/___\d+___/) {$symb=$ENV{'form.symb'};} else {$symb=$ENV{'request.symb'};}
-
&Apache::response::setrandomnumber();
my $ind=&Math::Random::random_uniform_integer(1,0,$#powers);
my $power = $powers[$ind];
@@ -235,11 +236,11 @@ sub end_numericalresponse {
for ($ind=0;$ind<$number_of_bubbles;$ind++) {
$bubbles_values[$ind] = $answers[0]*($factor**($power-$powers[$#powers-$ind]));
}
- my @alphabet = ('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P',
- 'Q','R','S','T','U','V','W','X','Y','Z');
+ my @alphabet=('A'..'Z');
if ($target eq 'web') {
if ($$tagstack[-1] eq 'numericalresponse') {
my $id=$Apache::inputtags::response[-1];
+ if ($unit=~/\S/) {$result.=' (in '.$unit.')
';}
$result.= '
'.$alphabet[$ind].': '.$ans.' | '; + $result.=''.$alphabet[$ind].': '.$ans.' | '; } $result.='