[LON-CAPA-cvs] cvs: loncom /homework/caparesponse caparesponse.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Thu, 23 Oct 2003 07:31:52 -0000
albertel Thu Oct 23 03:31:52 2003 EDT
Modified files:
/loncom/homework/caparesponse caparesponse.pm
Log:
- implements the ability to specify incorrect answers fr bubble mode,
supports overspecifying and exactly specifying the correct number of answers
(in the underspecified mode it currently punts and ignores the incorrect, ideas on what to do are apprec
iated)
- supports a number of bubbles option
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.116 loncom/homework/caparesponse/caparesponse.pm:1.117
--- loncom/homework/caparesponse/caparesponse.pm:1.116 Wed Oct 15 15:40:43 2003
+++ loncom/homework/caparesponse/caparesponse.pm Thu Oct 23 03:31:52 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.116 2003/10/15 19:40:43 albertel Exp $
+# $Id: caparesponse.pm,v 1.117 2003/10/23 07:31:52 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -41,6 +41,8 @@
if ($target eq 'edit') {
$result.=&Apache::edit::tag_start($target,$token);
$result.=&Apache::edit::text_arg('Answer:','answer',$token);
+ $result.=&Apache::edit::text_arg('Incorrect Answers:','incorrect',
+ $token);
if ($token->[1] eq 'numericalresponse') {
$result.=&Apache::edit::text_arg('Unit:','unit',$token,5).
&Apache::loncommon::help_open_topic('Physical_Units');
@@ -61,7 +63,8 @@
if ($token->[1] eq 'numericalresponse') {
$constructtag=&Apache::edit::get_new_args($token,$parstack,
$safeeval,'answer',
- 'unit','format');
+ 'incorrect','unit',
+ 'format');
} elsif ($token->[1] eq 'stringresponse') {
$constructtag=&Apache::edit::get_new_args($token,$parstack,
$safeeval,'answer',
@@ -118,13 +121,12 @@
&Apache::lonxml::debug($$parstack[-1] . "\n<br>");
if ($ENV{'form.submitted'} eq 'scantron') {
- my $number_of_bubbles = 8;#default values for number of bubbles
- my (@formats)=&Apache::lonxml::get_param_var('format',
- $parstack,$safeeval);
- my (@answers)=&Apache::lonxml::get_param_var('answer',
- $parstack,$safeeval);
- my @values=&make_numerical_bubbles($number_of_bubbles,$target,
- $answers[0],$formats[0]);
+ my $number_of_bubbles = &Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.numbubbles');
+ if (!$number_of_bubbles) { $number_of_bubbles=8; }
+ my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,$safeeval);
+ my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
+ my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,$safeeval);
+ my @values=&make_numerical_bubbles($number_of_bubbles,$target,$answers[0],$formats[0],\@incorrect);
$response=$values[$response];
} else {
$response =~ s/\\/\\\\/g;
@@ -206,14 +208,16 @@
}
}
if ($Apache::lonhomework::type eq 'exam') {
- my $number_of_bubbles = 8; #default values for number of bubbles
+ my $number_of_bubbles = &Apache::lonnet::EXT('resource.'.$partid.'_'.$id.'.numbubbles');
+ if (!$number_of_bubbles) { $number_of_bubbles=8; }
my (@formats)=&Apache::lonxml::get_param_var('format',$parstack,
$safeeval);
my $unit=&Apache::lonxml::get_param_var('unit',$parstack,
$safeeval);
+ my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,$safeeval);
my @bubble_values=&make_numerical_bubbles($number_of_bubbles,
$target,$answers[0],
- $formats[0]);
+ $formats[0],\@incorrect);
my @alphabet=('A'..'Z');
my $id=$Apache::inputtags::response[-1];
if ($target eq 'web') {
@@ -282,6 +286,8 @@
if ($target eq 'analyze') {
push (@{ $Apache::lonhomework::analyze{"parts"} },$part_id);
$Apache::lonhomework::analyze{"$part_id.type"} = $$tagstack[-1];
+ my (@incorrect)=&Apache::lonxml::get_param_var('incorrect',$parstack,$safeeval);
+ push (@{ $Apache::lonhomework::analyze{"$part_id.incorrect"} }, @incorrect);
}
&Apache::response::setup_params($$tagstack[-1]);
my (@answers)=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
@@ -435,8 +441,22 @@
}
sub make_numerical_bubbles {
- my ($number_of_bubbles,$target,$answer,$format) =@_;
+ my ($number_of_bubbles,$target,$answer,$format,$incorrect) =@_;
my @bubble_values = ();
+ &Apache::lonxml::debug("incorrect is $incorrect");
+ if (defined($incorrect) && ref($incorrect)) {
+ &Apache::lonxml::debug("inside ".(scalar(@$incorrect)+1 gt $number_of_bubbles));
+ if (scalar(@$incorrect)+1 >= $number_of_bubbles) {
+ &Apache::lonxml::debug("inside ".(scalar(@$incorrect)+1).":$number_of_bubbles");
+ &Apache::response::setrandomnumber();
+ my @rand_inc=&Math::Random::random_permutation(@$incorrect);
+ @bubble_values=@rand_inc[0..($number_of_bubbles-2)];
+ @bubble_values=sort {$a <=> $b} (@bubble_values,$answer);
+ &Apache::lonxml::debug("Answer was :$answer: returning :".$#bubble_values.": whih are :".join(':',@bubble_values));
+ return @bubble_values;
+ }
+ #FIXME what to do when not enough incorrects specified?
+ }
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
&Apache::response::setrandomnumber();