Collection Of Foils | Delete:"
@@ -238,12 +262,16 @@ sub start_foilgroup {
sub end_foilgroup {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
my $result;
+ my $part = $Apache::inputtags::part;
+ my $response_id = $Apache::inputtags::response[-1];
+
if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || $target eq 'tex' || $target eq 'analyze') {
my $max = &Apache::lonxml::get_param('max',$parstack,$safeeval,'-2');
my $randomize = &Apache::lonxml::get_param('randomize',$parstack,
$safeeval,'-2');
if ($target eq 'web' || $target eq 'tex') {
$result=&displayfoils($target,$max,$randomize);
+ $Apache::lonxml::post_evaluate=0;
} elsif ($target eq 'answer' ) {
$result=&displayanswers($max,$randomize);
} elsif ( $target eq 'grade') {
@@ -251,16 +279,30 @@ sub end_foilgroup {
} elsif ( $target eq 'analyze') {
my @shown=&whichfoils($max,$randomize);
&Apache::response::analyze_store_foilgroup(\@shown,
- ['text','value']);
+ ['text','value','location']);
#FIXME need to store options in some way
}
- &Apache::lonxml::increment_counter(&getfoilcounts($max));
+ &Apache::lonxml::increment_counter(&getfoilcounts($max),
+ "$part.$response_id");
+ if ($target eq 'analyze') {
+ &Apache::lonhomework::set_bubble_lines();
+ }
+
} elsif ($target eq 'edit') {
$result=&Apache::edit::end_table();
}
+ &Apache::response::poprandomnumber();
return $result;
}
+sub whichfoils {
+ my ($max,$randomize)=@_;
+ return &Apache::response::whichorder(&getfoilcounts($max),
+ $randomize,
+ &Apache::response::showallfoils(),
+ \%Apache::response::foilgroup);
+}
+
sub displayanswers {
my ($max,$randomize,@opt)=@_;
if (!defined(@{ $Apache::response::foilgroup{'names'} })) { return; }
@@ -269,18 +311,30 @@ sub displayanswers {
$randomize,
&Apache::response::showallfoils(),
\%Apache::response::foilgroup);
- my $result=&Apache::response::answer_header('matchresponse');
my %name_letter_map;
if (defined(%{ $Apache::response::itemgroup{'name_letter_map'} })) {
%name_letter_map=
%{ $Apache::response::itemgroup{'name_letter_map'} };
}
- foreach my $name (@whichfoils) {
- my $value_name=$Apache::response::foilgroup{$name.'.value'};
- my $letter=$name_letter_map{$value_name};
- $result.=&Apache::response::answer_part('matchresponse',$letter);
+ my $result;
+ if ($Apache::lonhomework::type eq 'exam') {
+ my $i=0;
+ foreach my $name (@whichfoils) {
+ $result.=&Apache::response::answer_header('matchresponse',$i++);
+ my $value_name=$Apache::response::foilgroup{$name.'.value'};
+ my $letter=$name_letter_map{$value_name};
+ $result.=&Apache::response::answer_part('matchresponse',$letter);
+ $result.=&Apache::response::answer_footer('matchresponse');
+ }
+ } else {
+ $result=&Apache::response::answer_header('matchresponse');
+ foreach my $name (@whichfoils) {
+ my $value_name=$Apache::response::foilgroup{$name.'.value'};
+ my $letter=$name_letter_map{$value_name};
+ $result.=&Apache::response::answer_part('matchresponse',$letter);
+ }
+ $result.=&Apache::response::answer_footer('matchresponse');
}
- $result.=&Apache::response::answer_footer('matchresponse');
return $result;
}
@@ -291,22 +345,24 @@ sub grade_response {
$randomize,
&Apache::response::showallfoils(),
\%Apache::response::foilgroup);
- if (!defined($ENV{'form.submitted'})) { return; }
+ if (!&Apache::response::submitted()) { return; }
my %responsehash;
my %grade;
- my ($temp,$right,$wrong,$ignored)=(0,0,0,0);
+ my ($temp,$right,$wrong,$ignored)=(1,0,0,0);
my %letter_name_map;
if (defined(%{ $Apache::response::itemgroup{'letter_name_map'} })) {
%letter_name_map=
%{ $Apache::response::itemgroup{'letter_name_map'} };
}
+ my @items;
foreach my $name (@whichfoils) {
- my $response = &Apache::response::getresponse($temp);
+ my $response = &Apache::response::getresponse($temp,'letter');
+ push(@items,$response);
my $responsename = $letter_name_map{$response};
- $responsehash{$name}=$responsename;
my $value=$Apache::response::foilgroup{$name.'.value'};
if ( $response =~ /[^\s]/) {
- &Apache::lonxml::debug("submitted a $response for $value \n");
+ $responsehash{$name}=$responsename;
+ &Apache::lonxml::debug("submitted a $response($responsename) for $value \n");
if ($value eq $responsename) {
$grade{$name}='1'; $right++;
} else {
@@ -320,28 +376,72 @@ sub grade_response {
my $part=$Apache::inputtags::part;
my $id = $Apache::inputtags::response['-1'];
my $responsestr=&Apache::lonnet::hash2str(%responsehash);
+ my $itemstr =&Apache::lonnet::array2str(@items);
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 ");
- 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"}=
$responsestr;
+ $Apache::lonhomework::results{"resource.$part.$id.submissionitems"}=
+ $itemstr;
$Apache::lonhomework::results{"resource.$part.$id.submissiongrading"}=
$gradestr;
- $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=$ad;
- &Apache::response::handle_previous(\%previous,$ad);
+ if ($Apache::lonhomework::type eq 'survey') {
+ if ($ignored == 0) {
+ my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='SUBMITTED';
+ &Apache::response::handle_previous(\%previous,$ad);
+ } elsif ($wrong==0 && $right==0) {
+ } else {
+ my $ad=$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}='MISSING_ANSWER';
+ &Apache::response::handle_previous(\%previous,$ad);
+ }
+ } elsif (!$Apache::lonhomework::scantronmode) {
+ 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 format_prior_answer {
+ my ($mode,$answer,$other_data) = @_;
+ my %answer =&Apache::lonnet::str2hash($answer);
+ my $foil_order =$other_data->[0];
+ my %grading =&Apache::lonnet::str2hash($other_data->[1]);
+ my @items =&Apache::lonnet::str2array($other_data->[2]);
+ my $output;
+
+ foreach my $name (@{ $foil_order }) {
+ my $item=shift(@items);
+ $output .= ' |