version 1.79, 2003/02/27 21:20:33
|
version 1.88, 2003/04/07 23:14:52
|
Line 46 sub end_caparesponse {
|
Line 46 sub end_caparesponse {
|
if ( $target eq 'grade' ) { |
if ( $target eq 'grade' ) { |
if ( defined $ENV{'form.submitted'}) { |
if ( defined $ENV{'form.submitted'}) { |
$safeeval->share_from('capa',['&caparesponse_capa_check_answer']); |
$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]/) { |
if ( $response =~ /[^\s]/) { |
my $id = $Apache::inputtags::response['-1']; |
my $id = $Apache::inputtags::response['-1']; |
my $previous= &Apache::response::check_for_previous($response,$id,$response); |
my $previous= &Apache::response::check_for_previous($response,$id,$response); |
Line 134 sub end_numericalresponse {
|
Line 134 sub end_numericalresponse {
|
$safeeval->share_from('capa',['&caparesponse_capa_check_answer']); |
$safeeval->share_from('capa',['&caparesponse_capa_check_answer']); |
my $partid = $Apache::inputtags::part; |
my $partid = $Apache::inputtags::part; |
my $id = $Apache::inputtags::response['-1']; |
my $id = $Apache::inputtags::response['-1']; |
my $response = $ENV{'form.HWVAL'.$id}; |
my $response = &Apache::response::getresponse(); |
if ( $response =~ /[^\s]/) { |
if ( $response =~ /[^\s]/) { |
|
my $ad; |
my %previous = &Apache::response::check_for_previous($response,$partid,$id); |
my %previous = &Apache::response::check_for_previous($response,$partid,$id); |
$Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response; |
$Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response; |
&Apache::lonxml::debug("submitted a $response<br>\n"); |
&Apache::lonxml::debug("submitted a $response<br>\n"); |
&Apache::lonxml::debug($$parstack[$#$parstack] . "\n<br>"); |
&Apache::lonxml::debug($$parstack[$#$parstack] . "\n<br>"); |
$response =~ s/\\/\\\\/g; |
if ($Apache::lonhomework::type eq 'exam' && |
$response =~ s/\'/\\\'/g; |
($$tagstack[-1] eq 'numericalresponse')) { |
&Apache::lonxml::debug("current $response"); |
&Apache::response::setrandomnumber(); |
my $expression="&caparesponse_check_list('".$response."','". |
#FIXME the 8 here is based off of number of powers need a parameter |
$$parstack[$#$parstack]; |
my $ind=&Math::Random::random_uniform_integer(1,0,8); |
foreach my $key (keys(%Apache::inputtags::params)) { |
if ($ind eq $response) { $ad='CORRECT'; } else { $ad='INCORRECT'; } |
$expression.= ';my $'. #' |
} else { |
$key.'="'.$Apache::inputtags::params{$key}.'"'; |
$response =~ s/\\/\\\\/g; |
} |
$response =~ s/\'/\\\'/g; |
if ($$tagstack[-1] eq 'formularesponse') { |
&Apache::lonxml::debug("current $response"); |
$expression.=';my $type="fml";'; |
my $expression="&caparesponse_check_list('".$response."','". |
} elsif ($$tagstack[-1] eq 'numericalresponse') { |
$$parstack[-1]; |
$expression.=';my $type="float";'; |
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<br>result:$result:$Apache::lonxml::curdepth<br>\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::response::handle_previous(\%previous,$ad); |
$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad; |
$Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}=$ad; |
&Apache::lonxml::debug("$expression"); |
|
&Apache::lonxml::debug("\n<br>result:$result:$Apache::lonxml::curdepth<br>\n"); |
|
$result=''; |
$result=''; |
} |
} |
} |
} |
Line 219 sub end_numericalresponse {
|
Line 228 sub end_numericalresponse {
|
my @bubbles_values = (); |
my @bubbles_values = (); |
my @factors = (1.13,1.17,1.25,1.33,1.45); #default values of factors |
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 @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 |
&Apache::response::setrandomnumber(); |
my $powers_number = 8; #default values for number of powers |
my $ind=&Math::Random::random_uniform_integer(1,0,$#powers); |
my $symb; |
|
if ($ENV{'form.symb'}=~/___\d+___/) {$symb=$ENV{'form.symb'};} else {$symb=$ENV{'request.symb'};} |
|
srand(&Apache::lonnet::rndseed($symb,$ENV{'request.course.id'}, |
|
$ENV{'user.domain'},$ENV{'user.name'})); |
|
my $ind=1+int(rand()*($factors_number-1)); |
|
my $factor = $factors[$ind]; |
|
$ind=1+int(rand()*($powers_number-1)); |
|
my $power = $powers[$ind]; |
my $power = $powers[$ind]; |
|
$ind=&Math::Random::random_uniform_integer(1,0,$#factors); |
|
my $factor = $factors[$ind]; |
for ($ind=0;$ind<$number_of_bubbles;$ind++) { |
for ($ind=0;$ind<$number_of_bubbles;$ind++) { |
$bubbles_values[$ind] = $answers[0]*$factor**($power-$powers[$powers_number-$ind-1]); |
$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', |
my @alphabet=('A'..'Z'); |
'Q','R','S','T','U','V','W','X','Y','Z'); |
|
if ($target eq 'web') { |
if ($target eq 'web') { |
if ($$tagstack[-1] eq 'numericalresponse') { |
if ($$tagstack[-1] eq 'numericalresponse') { |
my $id=$Apache::inputtags::response[-1]; |
my $id=$Apache::inputtags::response[-1]; |
|
if ($unit=~/\S/) {$result.=' (in '.$unit.')<br /><br />';} |
$result.= '<table border="1"><tr>'; |
$result.= '<table border="1"><tr>'; |
for ($ind=0;$ind<$number_of_bubbles;$ind++) { |
for ($ind=0;$ind<$number_of_bubbles;$ind++) { |
my $ans; |
my $ans; |
Line 255 sub end_numericalresponse {
|
Line 259 sub end_numericalresponse {
|
} |
} |
$ans = sprintf('%.'.$format,$bubbles_values[$ind]); |
$ans = sprintf('%.'.$format,$bubbles_values[$ind]); |
} |
} |
$result.='<td><input type="radio" name="HWVAL'.$id.'" value="'.$ans.'"><b>'.$alphabet[$ind].'</b>: '.$ans.'</td>'; |
$result.='<td><input type="radio" name="HWVAL_'.$id.'" value="'.$ans.'"><b>'.$alphabet[$ind].'</b>: '.$ans.'</td>'; |
} |
} |
$result.='</tr></table>'; |
$result.='</tr></table>'; |
} elsif ($$tagstack[-1] eq 'formularesponse') { |
} elsif ($$tagstack[-1] eq 'formularesponse') { |
$result.= '<br /><br /><font color="red"> Formula have to be entered here! </font><br /><br />'; |
$result.= '<br /><br /><font color="red"><textarea name="formulainput" rows="4" cols="50"> </textarea></font> <br /><br />'; |
} |
} |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
|
if (defined $unit and $Apache::lonhomework::type eq 'exam') { |
|
$result.=' \textit{(in} \verb|'.$unit.'|\textit{)} '; |
|
} |
if ($$tagstack[-1] eq 'numericalresponse') { |
if ($$tagstack[-1] eq 'numericalresponse') { |
my $max_val = 0; |
my $max_val = 0; |
if ($formats[0]=~m/^(\d+)E([^\d]*)(\d*)$/) { |
if ($formats[0]=~m/^(\d+)E([^\d]*)(\d*)$/) { |
Line 328 sub end_numericalresponse {
|
Line 335 sub end_numericalresponse {
|
$result.='\end{enumerate}'; |
$result.='\end{enumerate}'; |
&Apache::lonxml::increment_counter(); |
&Apache::lonxml::increment_counter(); |
} else { |
} else { |
$result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}'; |
$result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}'; |
my $id = $Apache::inputtags::part; |
my $id = $Apache::inputtags::part; |
my $weight = &Apache::lonnet::EXT("resource.$id.weight"); |
my $weight = &Apache::lonnet::EXT("resource.$id.weight"); |
my $repetition = int $weight/9; |
my $repetition = int $weight/9; |