[LON-CAPA-cvs] cvs: loncom /homework grades.pm
www
www@source.lon-capa.org
Mon, 07 Feb 2011 00:53:10 -0000
www Mon Feb 7 00:53:10 2011 EDT
Modified files:
/loncom/homework grades.pm
Log:
Adapt to also work with new i>clicker2 (numerical and alphanumerical)
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.643 loncom/homework/grades.pm:1.644
--- loncom/homework/grades.pm:1.643 Sun Jan 23 01:04:21 2011
+++ loncom/homework/grades.pm Mon Feb 7 00:53:10 2011
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.643 2011/01/23 01:04:21 www Exp $
+# $Id: grades.pm,v 1.644 2011/02/07 00:53:10 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -8841,7 +8841,7 @@
if ($env{'form.gradingmechanism'} eq 'given') {
$env{'form.givenanswer'}=~s/^\s*//gs;
$env{'form.givenanswer'}=~s/\s*$//gs;
- $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-]+/\,/g;
+ $env{'form.givenanswer'}=~s/[^a-zA-Z0-9\.\*\-\+]+/\,/g;
$env{'form.givenanswer'}=uc($env{'form.givenanswer'});
my @answers=split(/\,/,$env{'form.givenanswer'});
$foundgiven=$#answers+1;
@@ -9019,6 +9019,7 @@
$id=~s/^[\#0]+//;
for (my $i=0;$i<$number;$i++) {
my $idx=3+$i*6;
+ $entries[$idx]=~s/[^a-zA-Z0-9\.\*\-\+]+//g;
push(@idresponses,$entries[$idx]);
}
$$responses{$id}=join(',',@idresponses);
@@ -9090,20 +9091,20 @@
$result.='<br /><span class="LC_warning">'.
&mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
$env{'form.question:'.$i},$correct[$i],$input[$i]).'</span>';
- } elsif ($input[$i]) {
+ } elsif (($input[$i]) || ($input[$i] eq '0')) {
$correct[$i]=$input[$i];
}
}
}
}
for (my $i=0;$i<$number;$i++) {
- if (!$correct[$i]) {
+ if ((!$correct[$i]) && ($correct[$i] ne '0')) {
$result.='<br /><span class="LC_error">'.
&mt('No correct result given for question "[_1]"!',
$env{'form.question:'.$i}).'</span>';
}
}
- $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ($_?$_:'-') } @correct));
+ $result.='<br />'.&mt("Correct answer: [_1]",join(', ',map { ((($_) || ($_ eq '0'))?$_:'-') } @correct));
}
# Start grading
my $pcorrect=$env{'form.pcorrect'};
@@ -9136,17 +9137,29 @@
for (my $i=0;$i<$number;$i++) {
if ($correct[$i] eq '-') {
$realnumber--;
- } elsif ($answer[$i]) {
+ } elsif (($answer[$i]) || ($answer[$i]=~/^[0\.]+$/)) {
if ($gradingmechanism eq 'attendance') {
$sum+=$pcorrect;
} elsif ($correct[$i] eq '*') {
$sum+=$pcorrect;
} else {
- if ($answer[$i] eq $correct[$i]) {
- $sum+=$pcorrect;
- } else {
- $sum+=$pincorrect;
+# We actually grade if correct or not
+ my $increment=$pincorrect;
+# Special case: numerical answer "0"
+ if ($correct[$i] eq '0') {
+ if ($answer[$i]=~/^[0\.]+$/) {
+ $increment=$pcorrect;
+ }
+# General numerical answer, both evaluate to something non-zero
+ } elsif ((1.0*$correct[$i]!=0) && (1.0*$answer[$i]!=0)) {
+ if (1.0*$correct[$i]==1.0*$answer[$i]) {
+ $increment=$pcorrect;
+ }
+# Must be just alphanumeric
+ } elsif ($answer[$i] eq $correct[$i]) {
+ $increment=$pcorrect;
}
+ $sum+=$increment;
}
}
}