[LON-CAPA-cvs] cvs: loncom /homework inputtags.pm /homework/caparesponse caparesponse.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Wed, 16 Nov 2005 22:52:32 -0000
This is a MIME encoded message
--albertel1132181552
Content-Type: text/plain
albertel Wed Nov 16 17:52:32 2005 EDT
Modified files:
/loncom/homework inputtags.pm
/loncom/homework/caparesponse caparesponse.pm
Log:
- barest beginning of <n/fr> or support
--albertel1132181552
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20051116175232.txt"
Index: loncom/homework/inputtags.pm
diff -u loncom/homework/inputtags.pm:1.180 loncom/homework/inputtags.pm:1.181
--- loncom/homework/inputtags.pm:1.180 Tue Nov 15 17:28:30 2005
+++ loncom/homework/inputtags.pm Wed Nov 16 17:52:22 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# input definitons
#
-# $Id: inputtags.pm,v 1.180 2005/11/15 22:28:30 albertel Exp $
+# $Id: inputtags.pm,v 1.181 2005/11/16 22:52:22 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -403,7 +403,7 @@
}
sub finalizeawards {
- my ($awardref,$msgref)=@_;
+ my ($awardref,$msgref,$nameref,$reverse)=@_;
my $result=undef;
my $award;
my $msg;
@@ -419,15 +419,18 @@
if ($blankcount == ($#$awardref + 1)) { $result = 'NO_RESPONSE'; }
}
if (defined($result)) { return ($result,$msg); }
- foreach my $possibleaward ('MISSING_ANSWER', 'ERROR', 'NO_RESPONSE',
- 'TOO_LONG', 'UNIT_INVALID_INSTRUCTOR',
- 'UNIT_INVALID_STUDENT', 'UNIT_IRRECONCIBLE',
- 'UNIT_FAIL', 'NO_UNIT',
- 'UNIT_NOTNEEDED', 'WANTED_NUMERIC',
- 'BAD_FORMULA', 'SIG_FAIL', 'INCORRECT',
- 'MISORDERED_RANK', 'INVALID_FILETYPE',
- 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
- 'APPROX_ANS', 'EXACT_ANS','COMMA_FAIL') {
+
+ # these awards are ordered from most important error through best correct
+
+ my @awards = ('MISSING_ANSWER', 'ERROR', 'NO_RESPONSE', 'TOO_LONG',
+ 'UNIT_INVALID_INSTRUCTOR', 'UNIT_INVALID_STUDENT',
+ 'UNIT_IRRECONCIBLE', 'UNIT_FAIL', 'NO_UNIT',
+ 'UNIT_NOTNEEDED', 'WANTED_NUMERIC', 'BAD_FORMULA',
+ 'COMMA_FAIL', 'SIG_FAIL', 'INCORRECT', 'MISORDERED_RANK',
+ 'INVALID_FILETYPE', 'DRAFT', 'SUBMITTED', 'ASSIGNED_SCORE',
+ 'APPROX_ANS', 'EXACT_ANS');
+ if ($reverse) { @awards=reverse(@awards); }
+ foreach my $possibleaward (@awards) {
($result,$msg)=&checkstatus($possibleaward,$awardref,$msgref);
if (defined($result)) { return ($result,$msg); }
}
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.180 loncom/homework/caparesponse/caparesponse.pm:1.181
--- loncom/homework/caparesponse/caparesponse.pm:1.180 Thu Sep 8 13:49:22 2005
+++ loncom/homework/caparesponse/caparesponse.pm Wed Nov 16 17:52:31 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# caparesponse definition
#
-# $Id: caparesponse.pm,v 1.180 2005/09/08 17:49:22 albertel Exp $
+# $Id: caparesponse.pm,v 1.181 2005/11/16 22:52:31 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,11 +36,104 @@
&Apache::lonxml::register('Apache::caparesponse',('caparesponse','numericalresponse','stringresponse','formularesponse'));
}
+my %answer;
+my $cur_name;
+sub start_answer {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my $result;
+ $cur_name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
+ if ($cur_name =~ /^\s*$/) { $cur_name = $Apache::lonxml::curdepth; }
+ my $type = &Apache::lonxml::get_param('type',$parstack,$safeeval);
+ if (!defined($type) && $tagstack->[-2] eq 'answergroup') {
+ $type = &Apache::lonxml::get_param('type',$parstack,$safeeval,-2);
+ }
+ if (!defined($type)) { $type = 'ordered' };
+ $answer{$cur_name}= { 'type' => $type,
+ 'answers' => [] };
+ return $result;
+}
+
+sub end_answer {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my $result;
+ undef($cur_name);
+ return $result;
+}
+
+sub start_answergroup {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my $result;
+ my $id = $Apache::inputtags::response[-1];
+ my $dis = &Apache::lonxml::get_param('answerdisplay',$parstack,$safeeval);
+ if (defined($dis)) { $Apache::inputtags::answertxt{$id}=$dis; }
+ return $result;
+}
+
+sub end_answergroup {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my $result;
+ return $result;
+}
+
+sub start_value {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my $result;
+ if ( $target eq 'web' || $target eq 'tex' ||
+ $target eq 'grade' || $target eq 'webgrade' ||
+ $target eq 'answer' || $target eq 'analyze' ) {
+ my $bodytext = &Apache::lonxml::get_all_text("/value",$parser);
+ $bodytext = &Apache::run::evaluate($bodytext,$safeeval,
+ $$parstack[-1]);
+ push(@{ $answer{$cur_name}{'answers'} },$bodytext);
+ }
+ return $result;
+}
+
+sub end_value {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my $result;
+ return $result;
+}
+
+sub start_array {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my $result;
+ if ( $target eq 'web' || $target eq 'tex' ||
+ $target eq 'grade' || $target eq 'webgrade' ||
+ $target eq 'answer' || $target eq 'analyze' ) {
+ my $bodytext = &Apache::lonxml::get_all_text("/value",$parser);
+ my @values = &Apache::run::evaluate($bodytext,$safeeval,
+ $$parstack[-1]);
+ push(@{ $answer{$cur_name}{'answers'} },@values);
+ }
+ return $result;
+}
+
+sub end_array {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my $result;
+ return $result;
+}
+
+sub start_unit {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my $result;
+ return $result;
+}
+
+sub end_unit {
+ my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ my $result;
+ return $result;
+}
+
sub start_numericalresponse {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
+ &Apache::lonxml::register('Apache::caparesponse',('answer','answergroup','value','array','unit'));
my $id = &Apache::response::start_response($parstack,$safeeval);
my $result;
- undef %{$safeeval->varglob('LONCAPA::CAPAresponse_args')};
+ undef(%answer);
+ undef(%{$safeeval->varglob('LONCAPA::CAPAresponse_args')});
if ($target eq 'edit') {
$result.=&Apache::edit::tag_start($target,$token);
$result.=&Apache::edit::text_arg('Answer:','answer',$token);
@@ -155,14 +248,31 @@
}
my @answer=&Apache::lonxml::get_param_var('answer',$parstack,$safeeval);
&Apache::lonxml::debug('answer is'.join(':',@answer));
- @{$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=@answer;
-
- my ($result,@msgs) =
- &Apache::run::run("&caparesponse_check_list()",$safeeval);
- &Apache::lonxml::debug('msgs are'.join(':',@msgs));
- my ($awards)=split(/:/,$result);
- my @awards= split(/,/,$awards);
- return(\@awards,\@msgs);
+ if (@answer && defined($answer[0])) {
+ $answer{'INTERNAL'}= {'type' => 'ordered',
+ 'answers' => \@answer };
+ }
+ #FIXME would be nice if we could save name so we know who graded him
+ #correct
+ my (%results,@final_awards,@final_msgs,@names);
+ foreach my $name (keys(%answer)) {
+ &Apache::lonxml::debug(" doing $name with ".join(':',@{ $answer{$name}{'answers'} }));
+ @{$safeeval->varglob('LONCAPA::CAPAresponse_answer')}=@{ $answer{$name}{'answers'} };
+ my ($result,@msgs) =
+ &Apache::run::run("&caparesponse_check_list()",$safeeval);
+ &Apache::lonxml::debug('msgs are '.join(':',@msgs));
+ my ($awards)=split(/:/,$result);
+ my @awards= split(/,/,$awards);
+ my ($ad, $msg) = &Apache::inputtags::finalizeawards(\@awards,\@msgs);
+ $results{$name}= [$ad,$msg];
+ push(@final_awards,$ad);
+ push(@final_msgs,$msg);
+ push(@names,$name);
+ }
+ my ($ad, $msg, $name) = &Apache::inputtags::finalizeawards(\@final_awards,
+ \@final_msgs,
+ \@names,1);
+ return($ad,$msg);
}
sub end_numericalresponse {
@@ -185,7 +295,6 @@
} else {
my $response = &Apache::response::getresponse();
if ( $response =~ /[^\s]/) {
- my $ad;
my %previous = &Apache::response::check_for_previous($response,$partid,$id);
&Apache::lonxml::debug("submitted a $response<br>\n");
&Apache::lonxml::debug($$parstack[-1] . "\n<br>");
@@ -201,10 +310,9 @@
$response=$values->[$response];
}
$Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
- my ($awards,$msgs)=&check_submission($response,$partid,$id,
- $tag,$parstack,$safeeval);
+ my ($ad,$msg)=&check_submission($response,$partid,$id,
+ $tag,$parstack,$safeeval);
- ($ad,my $msg) = &Apache::inputtags::finalizeawards($awards,$msgs);
&Apache::lonxml::debug('ad is'.$ad);
if ($ad eq 'SIG_FAIL') {
my ($sig_u,$sig_l)=
@@ -404,21 +512,17 @@
$response.=" $cleanunit";
}
- my ($awards,$msgs)=&check_submission($response,$partid,$id,$tag,
- $parstack,$safeeval);
- my ($ad,$msg) =&Apache::inputtags::finalizeawards($awards,$msgs);
+ my ($ad,$msg)=&check_submission($response,$partid,$id,$tag,
+ $parstack,$safeeval);
if ($ad ne 'EXACT_ANS' && $ad ne 'APPROX_ANS') {
my $error;
if ($tag eq 'formularesponse') {
$error=&mt('Computer\'s answer is incorrect ("[_1]").');
} else {
# answer failed check if it is sig figs that is failing
- my ($awards,$msgs)=&check_submission($response,$partid,$id,
- $tag,$parstack,
- $safeeval,1);
- ($ad,$msg)=&Apache::inputtags::finalizeawards($awards,
- $msgs);
-
+ my ($ad,$msg)=&check_submission($response,$partid,$id,
+ $tag,$parstack,
+ $safeeval,1);
if ($sigline ne '') {
$error=&mt('Computer\'s answer is incorrect ("[_1]"). It is likely that the tolerance range [_2] or significant figures [_3] need to be adjusted.',$response,$tolline,$sigline);
} else {
--albertel1132181552--