[LON-CAPA-cvs] cvs: loncom /homework essayresponse.pm grades.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Fri, 10 Aug 2007 20:09:30 -0000


albertel		Fri Aug 10 16:09:30 2007 EDT

  Modified files:              
    /loncom/homework	grades.pm essayresponse.pm 
  Log:
  - eliminate unneeded global
  - list the course the similar response came from (BUG#5363)
  - handle usernames/domains properl by escaping them (as they can now have . in them)
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.425 loncom/homework/grades.pm:1.426
--- loncom/homework/grades.pm:1.425	Tue Jul 24 20:11:05 2007
+++ loncom/homework/grades.pm	Fri Aug 10 16:09:30 2007
@@ -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.426 2007/08/10 20:09:30 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -45,7 +45,6 @@
 
 use POSIX qw(floor);
 
-my %oldessays=();
 my %perm=();
 
 # ----- These first few routines are general use routines.----
@@ -538,7 +537,7 @@
 #
 
 sub most_similar {
-    my ($uname,$udom,$uessay)=@_;
+    my ($uname,$udom,$uessay,$old_essays)=@_;
 
 # ignore spaces and punctuation
 
@@ -555,23 +554,22 @@
     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 +1689,7 @@
 	'" 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 +1804,7 @@
 	    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 +1942,19 @@
 		    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="<hr /><h3><span class=\"LC_warning\">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="<hr /><h3><span class=\"LC_warning\">".
+				&mt('Essay is [_1]% similar to an essay by [_2] in course [_3]:[_4]',
+				    $osim,
+				    &Apache::loncommon::plainname($oname,$odom),
+				    $old_course_desc{'description'},
+				    $old_course_desc{'domain'}).
 				'</span></h3><blockquote><i>'.
 				&keywords_highlight($oessay).
 				'</i></blockquote><hr />';
Index: loncom/homework/essayresponse.pm
diff -u loncom/homework/essayresponse.pm:1.82 loncom/homework/essayresponse.pm:1.83
--- loncom/homework/essayresponse.pm:1.82	Tue Apr 17 19:25:09 2007
+++ loncom/homework/essayresponse.pm	Fri Aug 10 16:09:30 2007
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # essay (ungraded) style responses
 #
-# $Id: essayresponse.pm,v 1.82 2007/04/17 23:25:09 albertel Exp $
+# $Id: essayresponse.pm,v 1.83 2007/08/10 20:09:30 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -148,7 +148,8 @@
 		    my ($symb,$crsid,$domain,$name)=
 			&Apache::lonnet::whichuser();
 		    if ($crsid) {
-			my $akey=$name.'.'.$domain.'.'.$crsid;
+			my $akey=join('.',&escape($name),&escape($domain),
+				      &escape($crsid));
 			my $essayurl=
 			    &Apache::lonnet::declutter($ENV{'REQUEST_URI'});
 			my ($adom,$aname,$apath)=