--- loncom/homework/grades.pm 2007/07/25 00:11:05 1.425
+++ loncom/homework/grades.pm 2007/09/05 00:22:20 1.428.2.2
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.425 2007/07/25 00:11:05 albertel Exp $
+# $Id: grades.pm,v 1.428.2.2 2007/09/05 00:22:20 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -45,8 +45,7 @@ use LONCAPA;
use POSIX qw(floor);
-my %oldessays=();
-my %perm=();
+my %perm;
# ----- These first few routines are general use routines.----
#
@@ -195,22 +194,54 @@ sub showResourceInfo {
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.
@@ -259,11 +290,11 @@ sub cleanRecord {
} 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.='
true
';
} else {
$toprow.='
true
';
@@ -538,7 +569,7 @@ sub compute_points {
#
sub most_similar {
- my ($uname,$udom,$uessay)=@_;
+ my ($uname,$udom,$uessay,$old_essays)=@_;
# ignore spaces and punctuation
@@ -555,23 +586,22 @@ sub most_similar {
my $scrsid='';
my $sessay='';
# go through all essays ...
- foreach my $tkey (keys %oldessays) {
- my ($tname,$tdom,$tcrsid)=split(/\./,$tkey);
+ foreach my $tkey (keys(%$old_essays)) {
+ my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey));
# ... except the same student
- if (($tname ne $uname) || ($tdom ne $udom)) {
- my $tessay=$oldessays{$tkey};
- $tessay=~s/\W+/ /gs;
+ next if (($tname eq $uname) && ($tdom eq $udom));
+ my $tessay=$old_essays->{$tkey};
+ $tessay=~s/\W+/ /gs;
# String similarity gives up if not even limit
- my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
+ my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
# Found one
- if ($tsimilar>$limit) {
- $limit=$tsimilar;
- $sname=$tname;
- $sdom=$tdom;
- $scrsid=$tcrsid;
- $sessay=$oldessays{$tkey};
- }
- }
+ if ($tsimilar>$limit) {
+ $limit=$tsimilar;
+ $sname=$tname;
+ $sdom=$tdom;
+ $scrsid=$tcrsid;
+ $sessay=$old_essays->{$tkey};
+ }
}
if ($limit>0.6) {
return ($sname,$sdom,$scrsid,$sessay,$limit);
@@ -1691,6 +1721,7 @@ sub submission {
'" src="'.$request->dir_config('lonIconsURL').
'/check.gif" height="16" border="0" />';
+ my %old_essays;
# header info
if ($counter == 0) {
&sub_page_js($request);
@@ -1805,7 +1836,7 @@ KEYWORDS
my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
$apath=&escape($apath);
$apath=~s/\W/\_/gs;
- %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
+ %old_essays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
}
}
@@ -1943,12 +1974,21 @@ KEYWORDS
my $similar='';
if($env{'form.checkPlag'}){
my ($oname,$odom,$ocrsid,$oessay,$osim)=
- &most_similar($uname,$udom,$subval);
+ &most_similar($uname,$udom,$subval,\%old_essays);
if ($osim) {
$osim=int($osim*100.0);
- $similar="
Essay".
- " is $osim% similar to an essay by ".
- &Apache::loncommon::plainname($oname,$odom).
+ my %old_course_desc =
+ &Apache::lonnet::coursedescription($ocrsid,
+ {'one_time' => 1});
+
+ $similar="
".
+ &mt('Essay is [_1]% similar to an essay by [_2] ([_3]:[_4]) in course [_5] (course id [_6]:[_7])',
+ $osim,
+ &Apache::loncommon::plainname($oname,$odom),
+ $oname,$odom,
+ $old_course_desc{'description'},
+ $old_course_desc{'num'},
+ $old_course_desc{'domain'}).
'
'.
&keywords_highlight($oessay).
'
';
@@ -7032,9 +7072,10 @@ sub gather_clicker_ids {
# Set up a couple variables.
my $username_idx = &Apache::loncoursedata::CL_SNAME();
my $domain_idx = &Apache::loncoursedata::CL_SDOM();
+ my $status_idx = &Apache::loncoursedata::CL_STATUS();
foreach my $student (keys(%$classlist)) {
-
+ if ($classlist->{$student}->[$status_idx] ne 'Active') { next; }
my $username = $classlist->{$student}->[$username_idx];
my $domain = $classlist->{$student}->[$domain_idx];
my $clickers =
@@ -7295,8 +7336,21 @@ ENDHEADER
$result.="\n".'';
$correct_count++;
} elsif ($clicker_ids{$id}) {
- $result.="\n".'';
- $student_count++;
+ if ($clicker_ids{$id}=~/\,/) {
+# More than one user with the same clicker!
+ $result.="\n".&mt('Clicker registered more than once').": ".$id." ";
+ $result.="\n".''.
+ "';
+ $unknown_count++;
+ } else {
+# Good: found one and only one user with the right clicker
+ $result.="\n".'';
+ $student_count++;
+ }
} else {
$result.="\n".&mt('Unregistered Clicker')." ".$id." ";
$result.="\n".''.
@@ -7316,6 +7370,9 @@ ENDHEADER
$result.=' '.&mt("Found [_1] entries for grading!",$correct_count).'';
}
}
+ if ($number<1) {
+ $errormsg.="Found no questions.";
+ }
if ($errormsg) {
$result.=' '.&mt($errormsg).'';
} else {
@@ -7444,6 +7501,8 @@ ENDHEADER
my $id=$1;
if (($env{'form.uname'.$id}) && ($env{'form.udom'.$id})) {
$user=$env{'form.uname'.$id}.':'.$env{'form.udom'.$id};
+ } elsif ($env{'form.multi'.$id}) {
+ $user=$env{'form.multi'.$id};
}
}
if ($user) {
@@ -7489,7 +7548,7 @@ ENDHEADER
sub handler {
my $request=$_[0];
- &reset_perm();
+ &reset_caches();
if ($env{'browser.mathml'}) {
&Apache::loncommon::content_type($request,'text/xml');
} else {
@@ -7602,6 +7661,7 @@ sub handler {
}
}
$request->print(&Apache::loncommon::end_page());
+ &reset_caches();
return '';
}