[LON-CAPA-cvs] cvs: loncom /homework grades.pm
albertel
lon-capa-cvs-allow@mail.lon-capa.org
Fri, 24 Aug 2007 00:32:01 -0000
albertel Thu Aug 23 20:32:01 2007 EDT
Modified files:
/loncom/homework grades.pm
Log:
- was incorrectly displaying the grading information for radiobutton problems
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.433 loncom/homework/grades.pm:1.434
--- loncom/homework/grades.pm:1.433 Wed Aug 22 14:27:03 2007
+++ loncom/homework/grades.pm Thu Aug 23 20:32:00 2007
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.433 2007/08/22 18:27:03 banghart Exp $
+# $Id: grades.pm,v 1.434 2007/08/24 00:32:00 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -45,7 +45,7 @@
use POSIX qw(floor);
-my %perm=();
+my %perm;
# ----- These first few routines are general use routines.----
#
@@ -194,22 +194,54 @@
return $result,$responseType,$hdgrade,$partlist,$handgrade;
}
+sub reset_caches {
+ &reset_analyze_cache();
+ &reset_perm();
+}
-sub get_order {
- my ($partid,$respid,$symb,$uname,$udom)=@_;
- my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
- $url=&Apache::lonnet::clutter($url);
- my $subresult=&Apache::lonnet::ssi($url,
- ('grade_target' => 'analyze'),
- ('grade_domain' => $udom),
- ('grade_symb' => $symb),
- ('grade_courseid' =>
- $env{'request.course.id'}),
- ('grade_username' => $uname));
- (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
- my %analyze=&Apache::lonnet::str2hash($subresult);
- return ($analyze{"$partid.$respid.shown"});
+{
+ my %analyze_cache;
+
+ sub reset_analyze_cache {
+ undef(%analyze_cache);
+ }
+
+ sub get_analyze {
+ my ($symb,$uname,$udom)=@_;
+ my $key = "$symb\0$uname\0$udom";
+ return $analyze_cache{$key} if (exists($analyze_cache{$key}));
+
+ my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
+ $url=&Apache::lonnet::clutter($url);
+ my $subresult=&Apache::lonnet::ssi($url,
+ ('grade_target' => 'analyze'),
+ ('grade_domain' => $udom),
+ ('grade_symb' => $symb),
+ ('grade_courseid' =>
+ $env{'request.course.id'}),
+ ('grade_username' => $uname));
+ (undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
+ my %analyze=&Apache::lonnet::str2hash($subresult);
+ return $analyze_cache{$key} = \%analyze;
+ }
+
+ sub get_order {
+ my ($partid,$respid,$symb,$uname,$udom)=@_;
+ my $analyze = &get_analyze($symb,$uname,$udom);
+ return $analyze->{"$partid.$respid.shown"};
+ }
+
+ sub get_radiobutton_correct_foil {
+ my ($partid,$respid,$symb,$uname,$udom)=@_;
+ my $analyze = &get_analyze($symb,$uname,$udom);
+ foreach my $foil (@{&get_order($partid,$respid,$symb,$uname,$udom)}) {
+ if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
+ return $foil;
+ }
+ }
+ }
}
+
#--- Clean response type for display
#--- Currently filters option/rank/radiobutton/match/essay/Task
# response types only.
@@ -258,11 +290,11 @@
} elsif ($response eq 'radiobutton') {
my %answer=&Apache::lonnet::str2hash($answer);
my ($toprow,$bottomrow);
- my $correct=($order->[0])+1;
- for (my $i=1;$i<=$#$order;$i++) {
- my $foil=$order->[$i];
+ my $correct =
+ &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom);
+ foreach my $foil (@$order) {
if (exists($answer{$foil})) {
- if ($i == $correct) {
+ if ($foil eq $correct) {
$toprow.='<td><b>true</b></td>';
} else {
$toprow.='<td><i>true</i></td>';
@@ -1665,7 +1697,7 @@
$section_inputs .= '<input type="hidden" name="section" value="all" />'."\n";
} else {
my @sections = &Apache::loncommon::get_env_multiple('form.section');
- foreach my $section(@sections) {
+ foreach my $section (@sections) {
$section_inputs .= '<input type="hidden" name="section" value="'.$section.'" />'."\n";
}
}
@@ -7515,7 +7547,7 @@
sub handler {
my $request=$_[0];
- &reset_perm();
+ &reset_caches();
if ($env{'browser.mathml'}) {
&Apache::loncommon::content_type($request,'text/xml');
} else {
@@ -7628,6 +7660,7 @@
}
}
$request->print(&Apache::loncommon::end_page());
+ &reset_caches();
return '';
}