version 1.71, 2002/11/08 20:36:27
|
version 1.86, 2003/03/26 18:44:13
|
Line 85 sub start_numericalresponse {
|
Line 85 sub start_numericalresponse {
|
$result.=&Apache::edit::tag_start($target,$token); |
$result.=&Apache::edit::tag_start($target,$token); |
$result.=&Apache::edit::text_arg('Answer:','answer',$token); |
$result.=&Apache::edit::text_arg('Answer:','answer',$token); |
if ($token->[1] eq 'numericalresponse') { |
if ($token->[1] eq 'numericalresponse') { |
$result.=&Apache::edit::text_arg('Unit:','unit',$token,5); |
$result.=&Apache::edit::text_arg('Unit:','unit',$token,5). |
$result.=&Apache::edit::text_arg('Format:','format',$token,4); |
&Apache::loncommon::help_open_topic('Physical_Units'); |
|
$result.=&Apache::edit::text_arg('Format:','format',$token,4). |
|
&Apache::loncommon::help_open_topic('Numerical_Response_Format'); |
} elsif ($token->[1] eq 'stringresponse') { |
} elsif ($token->[1] eq 'stringresponse') { |
$result.=&Apache::edit::select_arg('Type:','type', |
$result.=&Apache::edit::select_arg('Type:','type', |
[['cs','Case Sensitive'],['ci','Case Insensitive'], |
[['cs','Case Sensitive'],['ci','Case Insensitive'], |
['mc','Case Insensitive, Any Order']],$token); |
['mc','Case Insensitive, Any Order']],$token); |
} elsif ($token->[1] eq 'formularesponse') { |
} elsif ($token->[1] eq 'formularesponse') { |
$result.=&Apache::edit::text_arg('Sample Points:','samples',$token,40); |
$result.=&Apache::edit::text_arg('Sample Points:','samples',$token,40). |
|
&Apache::loncommon::help_open_topic('Formula_Response_Sampling'); |
} |
} |
$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); |
$result.=&Apache::edit::end_row().&Apache::edit::start_spanning_row(); |
} elsif ($target eq 'modified') { |
} elsif ($target eq 'modified') { |
Line 113 sub start_numericalresponse {
|
Line 116 sub start_numericalresponse {
|
} |
} |
} elsif ($target eq 'meta') { |
} elsif ($target eq 'meta') { |
$result=&Apache::response::meta_package_write('numericalresponse'); |
$result=&Apache::response::meta_package_write('numericalresponse'); |
|
} elsif ($target eq 'answer' || $target eq 'grade') { |
|
&Apache::response::reset_params(); |
} |
} |
return $result; |
return $result; |
} |
} |
Line 120 sub start_numericalresponse {
|
Line 125 sub start_numericalresponse {
|
sub end_numericalresponse { |
sub end_numericalresponse { |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_; |
my $result = ''; |
my $result = ''; |
|
if (!$Apache::lonxml::default_homework_loaded) { |
|
&Apache::lonxml::default_homework_load($safeeval); |
|
} |
if ( $target eq 'grade' ) { |
if ( $target eq 'grade' ) { |
if ( defined $ENV{'form.submitted'}) { |
if ( defined $ENV{'form.submitted'}) { |
&Apache::response::setup_params($$tagstack[-1]); |
&Apache::response::setup_params($$tagstack[-1]); |
Line 136 sub end_numericalresponse {
|
Line 144 sub end_numericalresponse {
|
$response =~ s/\'/\\\'/g; |
$response =~ s/\'/\\\'/g; |
&Apache::lonxml::debug("current $response"); |
&Apache::lonxml::debug("current $response"); |
my $expression="&caparesponse_check_list('".$response."','". |
my $expression="&caparesponse_check_list('".$response."','". |
$$parstack[$#$parstack]; |
$$parstack[-1]; |
foreach my $key (keys(%Apache::inputtags::params)) { |
foreach my $key (keys(%Apache::inputtags::params)) { |
$expression.= ';my $'. #' |
$expression.= ';my $'. #' |
$key.'="'.$Apache::inputtags::params{$key}.'"'; |
$key.'="'.$Apache::inputtags::params{$key}.'"'; |
Line 170 sub end_numericalresponse {
|
Line 178 sub end_numericalresponse {
|
if ($target eq 'web') { |
if ($target eq 'web') { |
$result="<br />The correct answer is "; |
$result="<br />The correct answer is "; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$result='\vskip 0 mm The correct answer is \\texttt{'; |
#$result='\vskip 0 mm The correct answer is \\texttt{'; |
} |
} |
for (my $i=0; $i <= $#answers; $i++) { |
for (my $i=0; $i <= $#answers; $i++) { |
my $answer=$answers[$i]; |
my $answer=$answers[$i]; |
Line 188 sub end_numericalresponse {
|
Line 196 sub end_numericalresponse {
|
&Apache::lonxml::debug("no format answer :$answer:"); |
&Apache::lonxml::debug("no format answer :$answer:"); |
$formatted="$answer,"; |
$formatted="$answer,"; |
} |
} |
if ($target eq 'tex') {$formatted=&Apache::lonxml::latex_special_symbols($formatted);} |
|
$result.=$formatted; |
if ($target eq 'tex') { |
} |
$formatted=''; |
|
#$formatted=&Apache::lonxml::latex_special_symbols($formatted); |
|
} |
|
$result.=$formatted; |
|
} |
chop $result; |
chop $result; |
if ($target eq 'web') { |
if ($target eq 'web') { |
$result.=" $unit.<br />"; |
$result.=" $unit.<br />"; |
} elsif ($target eq 'tex') { |
} elsif ($target eq 'tex') { |
$result.=&Apache::lonxml::latex_special_symbols($unit); |
#$result.=&Apache::lonxml::latex_special_symbols($unit); |
$result.="}. \\vskip 0 mm "; |
#$result.="}. \\vskip 0 mm "; |
} |
} |
} |
} |
if ($Apache::lonhomework::type eq 'exam') { |
if ($Apache::lonhomework::type eq 'exam') { |
Line 211 sub end_numericalresponse {
|
Line 223 sub end_numericalresponse {
|
my $powers_number = 8; #default values for number of powers |
my $powers_number = 8; #default values for number of powers |
my $symb; |
my $symb; |
if ($ENV{'form.symb'}=~/___\d+___/) {$symb=$ENV{'form.symb'};} else {$symb=$ENV{'request.symb'};} |
if ($ENV{'form.symb'}=~/___\d+___/) {$symb=$ENV{'form.symb'};} else {$symb=$ENV{'request.symb'};} |
my $randomseed = srand(&Apache::lonnet::rndseed($symb,$ENV{'request.course.id'}, |
|
$ENV{'user.domain'},$ENV{'user.name'})); |
&Apache::response::setrandomnumber(); |
my $ind=1+int(rand()*($factors_number-1)); |
my $ind=&Math::Random::random_uniform_integer(1,0,$#powers); |
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') { |
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 245 sub end_numericalresponse {
|
Line 258 sub end_numericalresponse {
|
$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') { |
|
$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') { |
my $max_val = 0; |
if (defined $unit and $Apache::lonhomework::type eq 'exam') { |
if ($formats[0]=~m/^(\d+)E([^\d]*)(\d*)$/) { |
$result.=' \textit{(in} \verb|'.$unit.'|\textit{)} '; |
$max_val=$1+$2+4; |
} |
} else { |
if ($$tagstack[-1] eq 'numericalresponse') { |
$max_val=4; |
my $max_val = 0; |
} |
if ($formats[0]=~m/^(\d+)E([^\d]*)(\d*)$/) { |
$max_val = int(0.9*$ENV{'form.textwidth'}/(($max_val+6)*2)); |
$max_val=$1+$2+4; |
my $celllength = 0.9*$ENV{'form.textwidth'}/$max_val-10; |
} else { |
my @table_range = (); |
$max_val=4; |
my $number_of_tables = int($number_of_bubbles/$max_val); |
} |
for (my $i=0;$i<$number_of_tables;$i++) {push @table_range,$max_val;} |
$max_val = int(0.9*$ENV{'form.textwidth'}/(($max_val+6)*2)); |
if ($number_of_bubbles % $max_val != 0) { |
my $celllength = 0.9*$ENV{'form.textwidth'}/$max_val-10; |
$number_of_tables++; |
my @table_range = (); |
push @table_range,($number_of_bubbles % $max_val); |
my $number_of_tables = int($number_of_bubbles/$max_val); |
} |
for (my $i=0;$i<$number_of_tables;$i++) {push @table_range,$max_val;} |
my $j=0; |
if ($number_of_bubbles % $max_val != 0) { |
my $cou=0; |
$number_of_tables++; |
$result.='\vskip -1 mm \noindent \begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]'; |
push @table_range,($number_of_bubbles % $max_val); |
for (my $i=0;$i<$number_of_tables;$i++) { |
|
$result.='\vskip -1 mm \noindent \begin{tabular}{'; |
|
for ($ind=0;$ind<$table_range[$j];$ind++) { |
|
$result.='lp{'.$celllength.' mm}'; |
|
} |
} |
$result.='}'; |
my $j=0; |
for ($ind=$cou;$ind<$cou+$table_range[$j];$ind++) { |
my $cou=0; |
my $ans; |
$result.='\vskip -1 mm \noindent \begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]'; |
if ($formats[0] ne '') { |
for (my $i=0;$i<$number_of_tables;$i++) { |
$ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]); |
$result.='\vskip -1 mm \noindent \begin{tabular}{'; |
if ($ans =~ m/([0-9\.\-\+]+)E([0-9\-\+]+)/ ) { |
for ($ind=0;$ind<$table_range[$j];$ind++) { |
my $number = $1; |
$result.='lp{'.$celllength.' mm}'; |
my $power = $2; |
} |
$power=~s/^\+//; |
$result.='}'; |
$power=~s/^(-?)0+(\d+)//; |
for ($ind=$cou;$ind<$cou+$table_range[$j];$ind++) { |
$ans=$number.'$\times 10^{'.$1.$2.'}$'; #'stupidemacs |
my $ans; |
} |
if ($formats[0] ne '') { |
} else { |
$ans = sprintf('%.'.$formats[0],$bubbles_values[$ind]); |
my $badans = $bubbles_values[$ind]; |
if ($ans =~ m/([0-9\.\-\+]+)E([0-9\-\+]+)/ ) { |
my $format = ''; |
my $number = $1; |
#What is the number? (integer,decimal,floating point) |
my $power = $2; |
if ($badans=~/^(\d*\.?\d*)(E|e)(\d*)$/) { |
$power=~s/^\+//; |
$format = 'e'.$2; |
$power=~s/^(-?)0+(\d+)//; |
} elsif ($badans=~/^(\d*)\.(\d*)$/) { |
$ans=$number.'$\times 10^{'.$1.$2.'}$'; #'stupidemacs |
$format = '4f'; |
} |
} elsif ($badans=~/^(\d*)$/) { |
} else { |
$format = 'd'; |
my $badans = $bubbles_values[$ind]; |
} |
my $format = ''; |
$ans = sprintf('%.'.$format,$bubbles_values[$ind]); |
#What is the number? (integer,decimal,floating point) |
if ($ans =~ m/([0-9\.\-\+]+)E([0-9\-\+]+)/ ) { |
if ($badans=~/^(\d*\.?\d*)(E|e)(\d*)$/) { |
my $number = $1; |
$format = 'e'.$2; |
my $power = $2; |
} elsif ($badans=~/^(\d*)\.(\d*)$/) { |
$power=~s/^\+//; |
$format = '4f'; |
$power=~s/^(-?)0+(\d+)//; |
} elsif ($badans=~/^(\d*)$/) { |
$ans=$number.'$\times 10^{'.$1.$2.'}$'; #'stupidemacs |
$format = 'd'; |
} |
} |
} |
$ans = sprintf('%.'.$format,$bubbles_values[$ind]); |
$result.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$ans.'} '; |
if ($ans =~ m/([0-9\.\-\+]+)E([0-9\-\+]+)/ ) { |
if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';} |
my $number = $1; |
} |
my $power = $2; |
$cou += $table_range[$j]; |
$power=~s/^\+//; |
$j++; |
$power=~s/^(-?)0+(\d+)//; |
$result.='\\\\\end{tabular}\vskip 0 mm '; |
$ans=$number.'$\times 10^{'.$1.$2.'}$'; #'stupidemacs |
|
} |
|
} |
|
$result.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$ans.'} '; |
|
if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';} |
|
} |
|
$cou += $table_range[$j]; |
|
$j++; |
|
$result.='\\\\\end{tabular}\vskip 0 mm '; |
|
} |
|
$result.='\end{enumerate}'; |
|
&Apache::lonxml::increment_counter(); |
|
} else { |
|
$result.='\fbox{\fbox{\parbox{\textwidth-5mm}{\strut\\\\\strut\\\\\strut\\\\\strut\\\\}}}'; |
|
my $id = $Apache::inputtags::part; |
|
my $weight = &Apache::lonnet::EXT("resource.$id.weight"); |
|
my $repetition = int $weight/9; |
|
if ($weight % 9 != 0) {$repetition++;} |
|
$result.='\begin{enumerate}'; |
|
for (my $i=0;$i<$repetition;$i++) { |
|
$result.='\item[\textbf{'.$Apache::lonxml::counter.'}.]\textit{Leave blank on scoring form}\vskip 0 mm'; |
|
&Apache::lonxml::increment_counter(); |
|
} |
|
$result.= '\end{enumerate}'; |
} |
} |
$result.='\end{enumerate}'; |
|
&Apache::lonxml::increment_counter(); |
|
} |
} |
} |
} |
} elsif ($target eq 'edit') { |
} elsif ($target eq 'edit') { |
Line 355 sub end_numericalresponse {
|
Line 388 sub end_numericalresponse {
|
} |
} |
} |
} |
if ($target eq 'answer') { |
if ($target eq 'answer') { |
if ($high) { $ans.=' ['.$low.','.$high.'] '; } |
if ($high) { $ans.=' ['.$low.','.$high.']'; } |
if ($sighigh) { $ans.= "Sig <i>$siglow - $sighigh</i>"; } |
if ($sighigh) { $ans.= " Sig <i>$siglow - $sighigh</i>"; } |
$result.=&Apache::response::answer_part($$tagstack[-1],$ans); |
$result.=&Apache::response::answer_part($$tagstack[-1],$ans); |
} elsif ($target eq 'analyze') { |
} elsif ($target eq 'analyze') { |
push (@{ $Apache::lonhomework::analyze{"$part_id.answer"} }, |
push (@{ $Apache::lonhomework::analyze{"$part_id.answer"} }, |