version 1.31, 2003/11/15 06:28:02
|
version 1.37, 2004/03/08 23:23:04
|
Line 30 package Apache::matchresponse;
|
Line 30 package Apache::matchresponse;
|
use strict; |
use strict; |
use HTML::Entities(); |
use HTML::Entities(); |
use Math::Random(); |
use Math::Random(); |
use Apache::optionresponse; |
use Apache::optionresponse(); |
|
use Apache::lonlocal; |
|
|
BEGIN { |
BEGIN { |
&Apache::lonxml::register('Apache::matchresponse',('matchresponse')); |
&Apache::lonxml::register('Apache::matchresponse',('matchresponse')); |
Line 46 sub start_matchresponse {
|
Line 47 sub start_matchresponse {
|
push (@Apache::lonxml::namespace,'matchresponse'); |
push (@Apache::lonxml::namespace,'matchresponse'); |
my $id = &Apache::response::start_response($parstack,$safeeval); |
my $id = &Apache::response::start_response($parstack,$safeeval); |
%Apache::hint::match=(); |
%Apache::hint::match=(); |
|
undef(%Apache::response::foilnames); |
if ($target eq 'meta') { |
if ($target eq 'meta') { |
$result=&Apache::response::meta_package_write('matchresponse'); |
$result=&Apache::response::meta_package_write('matchresponse'); |
} elsif ($target eq 'edit' ) { |
} elsif ($target eq 'edit' ) { |
Line 80 sub end_matchresponse {
|
Line 82 sub end_matchresponse {
|
pop @Apache::lonxml::namespace; |
pop @Apache::lonxml::namespace; |
&Apache::lonxml::deregister('Apache::matchresponse', |
&Apache::lonxml::deregister('Apache::matchresponse', |
('foilgroup','foil','conceptgroup')); |
('foilgroup','foil','conceptgroup')); |
|
undef(%Apache::response::foilnames); |
return $result; |
return $result; |
} |
} |
|
|
Line 306 sub grade_response {
|
Line 309 sub grade_response {
|
if (!defined($ENV{'form.submitted'})) { return; } |
if (!defined($ENV{'form.submitted'})) { return; } |
my %responsehash; |
my %responsehash; |
my %grade; |
my %grade; |
my ($temp,$right,$wrong,$ignored)=(0,0,0,0); |
my ($temp,$right,$wrong,$ignored)=(1,0,0,0); |
my %letter_name_map; |
my %letter_name_map; |
if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) { |
if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) { |
%letter_name_map= |
%letter_name_map= |
Line 314 sub grade_response {
|
Line 317 sub grade_response {
|
} |
} |
my @items; |
my @items; |
foreach my $name (@whichfoils) { |
foreach my $name (@whichfoils) { |
my $response = &Apache::response::getresponse($temp); |
my $response = &Apache::response::getresponse($temp,'letter'); |
push(@items,$response); |
push(@items,$response); |
my $responsename = $letter_name_map{$response}; |
my $responsename = $letter_name_map{$response}; |
my $value=$Apache::response::foilgroup{$name.'.value'}; |
my $value=$Apache::response::foilgroup{$name.'.value'}; |
if ( $response =~ /[^\s]/) { |
if ( $response =~ /[^\s]/) { |
$responsehash{$name}=$responsename; |
$responsehash{$name}=$responsename; |
&Apache::lonxml::debug("submitted a $response for $value<br />\n"); |
&Apache::lonxml::debug("submitted a $response($responsename) for $value<br />\n"); |
if ($value eq $responsename) { |
if ($value eq $responsename) { |
$grade{$name}='1'; $right++; |
$grade{$name}='1'; $right++; |
} else { |
} else { |
Line 338 sub grade_response {
|
Line 341 sub grade_response {
|
my $gradestr =&Apache::lonnet::hash2str(%grade); |
my $gradestr =&Apache::lonnet::hash2str(%grade); |
my %previous=&Apache::response::check_for_previous($responsestr,$part,$id); |
my %previous=&Apache::response::check_for_previous($responsestr,$part,$id); |
&Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored "); |
&Apache::lonxml::debug("Got $right right and $wrong wrong, and $ignored were ignored "); |
my $ad; |
|
if ($wrong==0 && $ignored==0) { |
|
$ad='EXACT_ANS'; |
|
} elsif ($wrong==0 && $right==0) { |
|
#nothing submitted |
|
} else { |
|
if ($ignored==0) { |
|
$ad='INCORRECT'; |
|
} else { |
|
$ad='MISSING_ANSWER'; |
|
} |
|
} |
|
$Apache::lonhomework::results{"resource.$part.$id.submission"}= |
$Apache::lonhomework::results{"resource.$part.$id.submission"}= |
$responsestr; |
$responsestr; |
$Apache::lonhomework::results{"resource.$part.$id.submissionitems"}= |
$Apache::lonhomework::results{"resource.$part.$id.submissionitems"}= |
$itemstr; |
$itemstr; |
$Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}= |
$Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}= |
$gradestr; |
$gradestr; |
$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad; |
if (!$Apache::lonhomework::scantronmode) { |
&Apache::response::handle_previous(\%previous,$ad); |
my $ad; |
|
if ($wrong==0 && $ignored==0) { |
|
$ad='EXACT_ANS'; |
|
} elsif ($wrong==0 && $right==0) { |
|
#nothing submitted |
|
} else { |
|
if ($ignored==0) { |
|
$ad='INCORRECT'; |
|
} else { |
|
$ad='MISSING_ANSWER'; |
|
} |
|
} |
|
$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad; |
|
&Apache::response::handle_previous(\%previous,$ad); |
|
} else { |
|
my $ad; |
|
if ($wrong==0 && $right==0) { |
|
#nothing submitted |
|
} else { |
|
$ad='ASSIGNED_SCORE'; |
|
$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}= |
|
$ad; |
|
$Apache::lonhomework::results{"resource.$part.$id.awarded"}= |
|
$right/(scalar(@whichfoils)); |
|
$Apache::lonhomework::results{"resource.$part.$id.numfoils"}= |
|
scalar(@whichfoils); |
|
} |
|
} |
} |
} |
|
|
sub itemdisplay { |
sub itemdisplay { |
Line 404 sub displayfoils {
|
Line 422 sub displayfoils {
|
} |
} |
} else { |
} else { |
my $i = 0; |
my $i = 0; |
my $temp=0; |
my $temp=1; |
my $id=$Apache::inputtags::response[-1]; |
my $id=$Apache::inputtags::response[-1]; |
my $part=$Apache::inputtags::part; |
my $part=$Apache::inputtags::part; |
my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"}; |
my $lastresponse=$Apache::lonhomework::history{"resource.$part.$id.submission"}; |
Line 465 sub displayfoils {
|
Line 483 sub displayfoils {
|
} elsif ($result=&itemdisplay('bottom')) { |
} elsif ($result=&itemdisplay('bottom')) { |
$result=$question.$result; |
$result=$question.$result; |
} elsif ($result=&itemdisplay('right')) { |
} elsif ($result=&itemdisplay('right')) { |
$result='<table><tr><td>'.$question.'</td><td>'.$result. |
if ($target ne 'tex') { |
'</td></tr></table>'; |
$result='<table><tr><td>'.$question.'</td><td>'.$result. |
|
'</td></tr></table>'; |
|
} else { |
|
$result='\begin{tabular}{p{\textwidth/2}p{\textwidth/2}}\begin{minipage}{\textwidth/2}'.$question.'\end{minipage}&\begin{minipage}{\textwidth/2}'.$result.'\end{minipage}\end{tabular}'; |
|
} |
} elsif ($result=&itemdisplay('left')) { |
} elsif ($result=&itemdisplay('left')) { |
$result='<table><tr><td>'.$result.'</td><td>'.$question. |
if ($target ne 'tex') { |
'</td></tr></table>'; |
$result='<table><tr><td>'.$result.'</td><td>'.$question. |
|
'</td></tr></table>'; |
|
} else { |
|
$result='\begin{tabular}{p{\textwidth/2}p{\textwidth/2}}\begin{minipage}{\textwidth/2}'.$result.'\end{minipage}&\begin{minipage}{\textwidth/2}'.$question.'\end{minipage}\end{tabular}'; |
|
} |
} |
} |
if ($target ne 'tex') {$result.="<br />";} else {$result.=' \\\\ ';} |
if ($target ne 'tex') {$result.="<br />";} else {$result.=' \\\\ ';} |
return $result; |
return $result; |
Line 569 sub end_foil {
|
Line 595 sub end_foil {
|
my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval); |
my $value = &Apache::lonxml::get_param('value',$parstack,$safeeval); |
if ($value ne 'unused') { |
if ($value ne 'unused') { |
my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval); |
my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval); |
my $location =&Apache::lonxml::get_param('location',$parstack,$safeeval); |
|
&Apache::lonxml::debug("Got a name of :$name:"); |
&Apache::lonxml::debug("Got a name of :$name:"); |
if (!$name) { $name=$Apache::lonxml::curdepth; } |
if (!$name) { $name=$Apache::lonxml::curdepth; } |
&Apache::lonxml::debug("Using a name of :$name:"); |
&Apache::lonxml::debug("Using a name of :$name:"); |
|
if (defined($Apache::response::foilnames{$name})) { |
|
&Apache::lonxml::error(&mt("Foil name <b><tt>[_1]</tt></b> appears more than once. Foil names need to be unique.",$name)); |
|
} |
|
my $location =&Apache::lonxml::get_param('location',$parstack, |
|
$safeeval); |
if ( $Apache::matchresponse::conceptgroup |
if ( $Apache::matchresponse::conceptgroup |
&& !&Apache::response::showallfoils() ) { |
&& !&Apache::response::showallfoils() ) { |
push @{ $Apache::response::conceptgroup{'names'} }, $name; |
push @{ $Apache::response::conceptgroup{'names'} }, $name; |