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

raeburn raeburn at source.lon-capa.org
Tue Nov 20 14:14:15 EST 2018


raeburn		Tue Nov 20 19:14:15 2018 EDT

  Modified files:              
    /loncom/homework	essayresponse.pm grades.pm 
  Log:
  - "Check For Plagiarism" now supported for submissions to Simple Problem
  (Essay-open ended). Similarity checking only for submissions in same course
  
  
-------------- next part --------------
Index: loncom/homework/essayresponse.pm
diff -u loncom/homework/essayresponse.pm:1.124 loncom/homework/essayresponse.pm:1.125
--- loncom/homework/essayresponse.pm:1.124	Tue Mar 10 17:32:53 2015
+++ loncom/homework/essayresponse.pm	Tue Nov 20 19:14:14 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # essay (ungraded) style responses
 #
-# $Id: essayresponse.pm,v 1.124 2015/03/10 17:32:53 raeburn Exp $
+# $Id: essayresponse.pm,v 1.125 2018/11/20 19:14:14 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -226,16 +226,30 @@
 				      &escape($crsid));
 			my $essayurl=
 			    &Apache::lonnet::declutter($ENV{'REQUEST_URI'});
-			my ($adom,$aname,$apath)=
-			    ($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
-                        $apath=&escape($apath);
-			$apath=~s/\W/\_/gs;
-			&Apache::lonnet::put('nohist_essay_'.$apath,
-					 { $akey => $response },$adom,$aname);
+                        if ($essayurl eq 'lib/templates/simpleproblem.problem') {
+                            my %crsinfo = &Apache::lonnet::coursedescription($crsid);
+                            my $cdom = $crsinfo{'domain'};
+                            my $cnum = $crsinfo{'num'};
+                            my ($map,$id,$res) = &Apache::lonnet::decode_symb($symb);
+                            if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(default(?:|_\d+)\.(?:sequence|page))$}) {
+                                my $apath = $1.'_'.$id;
+                                $apath=~s/\W/\_/gs;
+                                my $akey = join('.',&escape($name),&escape($domain));
+                                &Apache::lonnet::put('nohist_essay_'.$apath,
+                                                     { $akey => $response },$cdom,$cnum);
+                            }
+                        } else {
+			    my ($adom,$aname,$apath)=
+			        ($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
+                            $apath=&escape($apath);
+			    $apath=~s/\W/\_/gs;
+			    &Apache::lonnet::put('nohist_essay_'.$apath,
+                                                 { $akey => $response },$adom,$aname);
+                        }
 		    }
                 }
             }
-	} 
+	}
     } elsif ($target eq 'edit') {
 	$result.=&Apache::edit::end_table();
 
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.752 loncom/homework/grades.pm:1.753
--- loncom/homework/grades.pm:1.752	Mon Oct  8 19:11:01 2018
+++ loncom/homework/grades.pm	Tue Nov 20 19:14:14 2018
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.752 2018/10/08 19:11:01 raeburn Exp $
+# $Id: grades.pm,v 1.753 2018/11/20 19:14:14 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2121,6 +2121,7 @@
     my $probtitle=&Apache::lonnet::gettitle($symb); 
     if ($symb eq '') { $request->print("Unable to handle ambiguous references:."); return ''; }
     my $is_tool = ($symb =~ /ext\.tool$/);
+    my ($essayurl,%coursedesc_by_cid);
 
     if (!&canview($usec)) {
         $request->print(
@@ -2251,11 +2252,24 @@
 #
 # Load the other essays for similarity check
 #
-            my (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
-	    my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
-	    $apath=&escape($apath);
-	    $apath=~s/\W/\_/gs;
-            &init_old_essays($symb,$apath,$adom,$aname);
+            (undef,undef,$essayurl) = &Apache::lonnet::decode_symb($symb);
+            if ($essayurl eq 'lib/templates/simpleproblem.problem') {
+                my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
+                my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
+                if ($cdom ne '' && $cnum ne '') {
+                    my ($map,$id,$res) = &Apache::lonnet::decode_symb($symb);
+                    if ($map =~ m{^\Quploaded/$cdom/$cnum/\E(default(?:|_\d+)\.(?:sequence|page))$}) {
+                        my $apath = $1.'_'.$id;
+                        $apath=~s/\W/\_/gs;
+                        &init_old_essays($symb,$apath,$cdom,$cnum);
+                    }
+                }
+            } else {
+	        my ($adom,$aname,$apath)=($essayurl=~/^($LONCAPA::domain_re)\/($LONCAPA::username_re)\/(.*)$/);
+	        $apath=&escape($apath);
+	        $apath=~s/\W/\_/gs;
+                &init_old_essays($symb,$apath,$adom,$aname);
+            }
         }
     }
 
@@ -2406,24 +2420,52 @@
 		        &most_similar($uname,$udom,$symb,$subval);
 		    if ($osim) {
 			$osim=int($osim*100.0);
-			my %old_course_desc = 
-			    &Apache::lonnet::coursedescription($ocrsid,
-							{'one_time' => 1});
-
                         if ($hide eq 'anon') {
                             $similar='<hr /><span class="LC_warning">'.&mt("Essay was found to be similar to another essay submitted for this assignment.").'<br />'.
                                      &mt('As the current submission is for an anonymous survey, no other details are available.').'</span><hr />';
                         } else {
-			    $similar="<hr /><h3><span class=\"LC_warning\">".
-				&mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
-				    $osim,
-				    &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
-				        $old_course_desc{'description'},
-				        $old_course_desc{'num'},
-				        $old_course_desc{'domain'}).
-				    '</span></h3><blockquote><i>'.
-				    &keywords_highlight($oessay).
-				    '</i></blockquote><hr />';
+			    $similar='<hr />';
+                            if ($essayurl eq 'lib/templates/simpleproblem.problem') {
+                                $similar .= '<h3><span class="LC_warning">'.
+                                            &mt('Essay is [_1]% similar to an essay by [_2]',
+                                                $osim,
+                                                &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')').
+                                            '</span></h3>';
+                            } else {
+                                my %old_course_desc;
+                                if ($ocrsid ne '') {
+                                    if (ref($coursedesc_by_cid{$ocrsid}) eq 'HASH') {
+                                        %old_course_desc = %{$coursedesc_by_cid{$ocrsid}};
+                                    } else {
+                                        my $args;
+                                        if ($ocrsid ne $env{'request.course.id'}) {
+                                            $args = {'one_time' => 1};
+                                        }
+                                        %old_course_desc =
+                                            &Apache::lonnet::coursedescription($ocrsid,$args);
+                                        $coursedesc_by_cid{$ocrsid} = \%old_course_desc;
+                                    }
+                                    $similar .=
+                                        '<h3><span class="LC_warning">'.
+                                        &mt('Essay is [_1]% similar to an essay by [_2] in course [_3] (course id [_4]:[_5])',
+                                            $osim,
+                                            &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')',
+                                            $old_course_desc{'description'},
+                                            $old_course_desc{'num'},
+                                            $old_course_desc{'domain'}).
+                                        '</span></h3>';
+                                } else {
+                                    $similar .=
+                                        '<h3><span class="LC_warning">'.
+                                        &mt('Essay is [_1]% similar to an essay by [_2] in an unknown course',
+                                            $osim,
+                                            &Apache::loncommon::plainname($oname,$odom).' ('.$oname.':'.$odom.')').
+                                        '</span></h3>';
+                                }
+                            }
+                            $similar .= '<blockquote><i>'.
+                                        &keywords_highlight($oessay).
+                                        '</i></blockquote><hr />';
                         }
 	            }
 		}


More information about the LON-CAPA-cvs mailing list