version 1.5, 2001/01/12 01:07:13
|
version 1.9, 2001/01/19 20:05:40
|
Line 1
|
Line 1
|
# The LearningOnline Network with CAPA |
# The LearningOnline Network with CAPA |
# mutliple choice style responses |
# mutliple choice style responses |
|
|
# 11/23,11/24,11/28 Gerd Kortemeyer |
|
|
|
package Apache::radiobuttonresponse; |
package Apache::radiobuttonresponse; |
use strict; |
use strict; |
|
|
Line 26 sub end_radiobuttonresponse {
|
Line 24 sub end_radiobuttonresponse {
|
%Apache::response::foilgroup={}; |
%Apache::response::foilgroup={}; |
sub start_foilgroup { |
sub start_foilgroup { |
%Apache::response::foilgroup={}; |
%Apache::response::foilgroup={}; |
|
return ''; |
} |
} |
|
|
sub setrandomnumber { |
sub setrandomnumber { |
Line 38 sub setrandomnumber {
|
Line 37 sub setrandomnumber {
|
return ''; |
return ''; |
} |
} |
|
|
#FIXME needs to stablely do random picks |
|
sub end_foilgroup { |
sub end_foilgroup { |
my ($target,$token,$parstack,$parser,$safeeval,$style)=@_; |
my ($target,$token,$parstack,$parser,$safeeval,$style)=@_; |
my $name; |
|
my $result; |
my $result; |
&setrandomnumber(); |
if ($target ne 'meta') { |
my $rrargs =''; |
my $name; |
if ( $#$parstack > 0 ) { $rrargs=$$parstack['-2']; } |
&setrandomnumber(); |
my $max = &Apache::run::run("{$rrargs;".'return $max}',$safeeval); |
my ($truecnt,$falsecnt,$max) = &getfoilcounts($parstack,$safeeval); |
my $answer = int(rand $max); |
my $count=0; |
if ($target eq 'web') { |
# we will add in 1 of the true statements |
$result=&displayfoils($max,$answer); |
if (($falsecnt+1)>$max) { $count=$max } else { $count=$falsecnt+1; } |
} elsif ( $target eq 'grade') { |
my $answer = int(rand ($count)); |
if ( defined $ENV{'form.submit'}) { |
&Apache::lonxml::debug("Answer is $answer, $count from $max, $falsecnt"); |
my $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']}; |
if ($target eq 'web') { |
if ( $response =~ /[^\s]/) { |
$result=&displayfoils($max,$answer); |
my $id = $Apache::inputtags::response['-1']; |
} elsif ( $target eq 'grade') { |
$Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}=$response; |
if ( defined $ENV{'form.submitted'}) { |
&Apache::lonxml::debug("submitted a $response<br>\n"); |
my $response = $ENV{'form.HWVAL'.$Apache::inputtags::response['-1']}; |
if ($response == $answer) { |
if ( $response =~ /[^\s]/) { |
$Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='EXACT_ANS'; |
my $id = $Apache::inputtags::response['-1']; |
} else { |
$Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.submission"}=$response; |
$Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='INCORRECT'; |
&Apache::lonxml::debug("submitted a $response<br>\n"); |
|
if ($response == $answer) { |
|
$Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='EXACT_ANS'; |
|
} else { |
|
$Apache::lonhomework::results{"resource.$Apache::inputtags::part.$id.awarddetail"}='INCORRECT'; |
|
} |
} |
} |
} |
} |
} |
} |
Line 68 sub end_foilgroup {
|
Line 71 sub end_foilgroup {
|
return $result; |
return $result; |
} |
} |
|
|
|
sub getfoilcounts { |
|
my ($parstack,$safeeval)=@_; |
|
my $rrargs =''; |
|
if ( $#$parstack > 0 ) { $rrargs=$$parstack['-2']; } |
|
my $max = &Apache::run::run("{$rrargs;".'return $max}',$safeeval); |
|
my @names = @{ $Apache::response::foilgroup{'names'} }; |
|
my $truecnt=0; |
|
my $falsecnt=0; |
|
my $name; |
|
|
|
foreach $name (@names) { |
|
if ($Apache::response::foilgroup{$name.'.value'} eq 'true') { |
|
$truecnt++; |
|
} elsif ($Apache::response::foilgroup{$name.'.value'} eq 'false') { |
|
$falsecnt++; |
|
} |
|
} |
|
return ($truecnt,$falsecnt,$max); |
|
} |
|
|
sub displayfoils { |
sub displayfoils { |
my ($max,$answer)=@_; |
my ($max,$answer)=@_; |
my @names = @{ $Apache::response::foilgroup{'names'} }; |
my @names = @{ $Apache::response::foilgroup{'names'} }; |