--- loncom/homework/grades.pm 2003/04/30 15:52:28 1.87
+++ loncom/homework/grades.pm 2003/06/20 20:13:18 1.103
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.87 2003/04/30 15:52:28 www Exp $
+# $Id: grades.pm,v 1.103 2003/06/20 20:13:18 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -49,6 +49,7 @@ use Apache::Constants qw(:common);
use String::Similarity;
my %oldessays=();
+my %perm=();
# ----- These first few routines are general use routines.----
#
@@ -130,58 +131,66 @@ sub getclasslist {
# filter students according to status selected
if ($filterlist && $ENV{'form.status'} ne 'Any') {
if ($ENV{'form.status'} ne $status) {
+Apache->request->print("
removed
");
delete ($classlist->{$_});
next;
}
}
$section = ($section ne '' ? $section : 'no');
- if ($getsec eq 'all' || $getsec eq $section) {
- $sections{$section}++;
- $fullnames{$_}=$fullname;
- } else {
- delete($classlist->{$_});
- }
+ if (&canview($section)) {
+ if ($getsec eq 'all' || $getsec eq $section) {
+ $sections{$section}++;
+ $fullnames{$_}=$fullname;
+ } else {
+ delete($classlist->{$_});
+ }
+ } else {
+ delete($classlist->{$_});
+ }
}
my %seen = ();
my @sections = sort(keys(%sections));
return ($classlist,\@sections,\%fullnames);
}
-#find user domain
-sub finduser {
- my ($name) = @_;
- my $domain = '';
- if ( $Apache::grades::viewgrades eq 'F' ) {
- my %classlist=&Apache::lonnet::dump('classlist',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
- my (@fields) = grep /^$name:/, keys %classlist;
- ($name, $domain) = split(/:/,$fields[0]);
- return ($name,$domain);
- } else {
- return ($ENV{'user.name'},$ENV{'user.domain'});
+sub canmodify {
+ my ($sec)=@_;
+ if ($perm{'mgr'}) {
+ if (!defined($perm{'mgr_section'})) {
+ # can modify whole class
+ return 1;
+ } else {
+ if ($sec eq $perm{'mgr_section'}) {
+ #can modify the requested section
+ return 1;
+ } else {
+ # can't modify the request section
+ return 0;
+ }
+ }
}
+ #can't modify
+ return 0;
}
-#--- Prompts a user to enter a username.
-sub moreinfo {
- my ($request,$reason) = @_;
- $request->print("Unable to process request: $reason");
- if ( $Apache::grades::viewgrades eq 'F' ) {
- $request->print('');
+sub canview {
+ my ($sec)=@_;
+ if ($perm{'vgr'}) {
+ if (!defined($perm{'vgr_section'})) {
+ # can modify whole class
+ return 1;
+ } else {
+ if ($sec eq $perm{'vgr_section'}) {
+ #can modify the requested section
+ return 1;
+ } else {
+ # can't modify the request section
+ return 0;
+ }
+ }
}
- return '';
+ #can't modify
+ return 0;
}
#--- Retrieve the grade status of a student for all the parts
@@ -237,7 +246,7 @@ sub most_similar {
$uessay=~s/\W+/ /gs;
# these will be returned. Do not care if not at least 50 percent similar
- my $limit=0.5;
+ my $limit=0.6;
my $sname='';
my $sdom='';
my $scrsid='';
@@ -246,22 +255,22 @@ sub most_similar {
foreach my $tkey (keys %oldessays) {
my ($tname,$tdom,$tcrsid)=split(/\./,$tkey);
# ... except the same student
- if (($tname ne $uname) && ($tdom ne $udom)) {
+ if (($tname ne $uname) || ($tdom ne $udom)) {
my $tessay=$oldessays{$tkey};
$tessay=~s/\W+/ /gs;
# String similarity gives up if not even limit
- my $tsimilar=&String::Similarity::similar($uessay,$tessay,$limit);
+ my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit);
# Found one
if ($tsimilar>$limit) {
$limit=$tsimilar;
$sname=$tname;
- $sdom=$sdom;
+ $sdom=$tdom;
$scrsid=$tcrsid;
$sessay=$oldessays{$tkey};
}
}
}
- if ($limit>0.5) {
+ if ($limit>0.6) {
return ($sname,$sdom,$scrsid,$sessay,$limit);
} else {
return ('','','','',0);
@@ -466,8 +475,13 @@ LISTJAVASCRIPT
'onClick="javascript:checkSelect(this.form.stuinfo);" '.
'value="'.$viewgrade.'" />'."\n";
if ($ctr == 0) {
- $gradeTable=' '.
- 'No submission found for this resource. ';
+ my $num_students=(scalar(keys(%$fullname)));
+ if ($num_students eq 0) {
+ $gradeTable=' There are no students currently enrolled.';
+ } else {
+ $gradeTable=' '.
+ 'No submissions found for this resource for any students. ('.$num_students.' checked for submissions ';
+ }
} elsif ($ctr == 1) {
$gradeTable =~ s/type=checkbox/type=checkbox checked/;
}
@@ -1045,7 +1059,7 @@ sub submission {
(my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
my ($uname,$udom) = ($ENV{'form.student'},$ENV{'form.userdom'});
- ($uname,$udom) = &finduser($uname) if $udom eq '';
+
$ENV{'form.fullname'} = &get_fullname ($uname,$udom) if $ENV{'form.fullname'} eq '';
my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
@@ -1122,6 +1136,9 @@ sub submission {
$request->print($prnmsg);
if ($ENV{'form.handgrade'} eq 'yes' && $ENV{'form.showgrading'} eq 'yes') {
+#
+# Print out the keyword options line
+#
$request->print(<Keyword Options:
List
@@ -1129,6 +1146,14 @@ sub submission {
CLASS="page">Paste Selection to List
Highlight Attribute
KEYWORDS
+#
+# Load the other essays for similarity check
+#
+ my $essayurl=&Apache::lonnet::declutter($url);
+ my ($adom,$aname,$apath)=($essayurl=~/^(\w+)\/(\w+)\/(.*)$/);
+ $apath=&Apache::lonnet::escape($apath);
+ $apath=~s/\W/\_/gs;
+ %oldessays=&Apache::lonnet::dump('nohist_essay_'.$apath,$adom,$aname);
}
}
@@ -1236,6 +1261,15 @@ KEYWORDS
my ($partid,$respid) = /^resource\.(\d+)\.(\d+)\.submission/;
if ($part eq ($partid.'_'.$respid)) {
my ($ressub,$subval) = split(/:/,$_,2);
+# Similarity check
+ my $similar='';
+ my ($oname,$odom,$ocrsid,$oessay,$osim)=&most_similar($uname,$udom,$subval);
+ if ($osim) {
+ $osim=int($osim*100.0);
+ $similar='
Essay is '.$osim.'% similar to an essay by '.&Apache::loncommon::plainname($oname,$odom).
+ '
'.
+ &keywords_highlight($oessay).'
';
+ }
$lastsubonly.='
Part '.
$partid.' ( ID '.$respid.
' ) '.
@@ -1243,8 +1277,8 @@ KEYWORDS
' File uploaded by student Like all files provided by users, this file may contain virusses ':'').
- 'Answer: '.
- &keywords_highlight($subval).'
'."\n";
}
}
@@ -1965,7 +2005,7 @@ sub editgrades {
$title.='Section: '.$ENV{'form.section'}.''."\n";
my $result= '
'."\n";
$result.= '
'.
- '
Username
Fullname
'."\n";
+ '
Username
Domain
Fullname
'."\n";
my %scoreptr = (
'correct' =>'correct_by_override',
@@ -2013,16 +2053,19 @@ sub editgrades {
$result .= '
';
$result .= $header;
$result .= '
'."\n";
-
+ my $noupdate;
for ($i=0; $i<$ENV{'form.total'}; $i++) {
+ my $line;
my $user = $ENV{'form.ctr'.$i};
+ my $usercolon = $user;
+ $usercolon =~s/_/:/;
+ my ($uname,$udom)=split(/_/,$user);
my %newrecord;
my $updateflag = 0;
- my @userdom = grep /^$user:/,keys %$classlist;
- my (undef,$udom) = split(/:/,$userdom[0]);
- $result .= '
'.$user.'
'.
- $$fullname{$userdom[0]}.'
';
+ $line .= '
'.$uname.'
'.
+ $udom.'
'.
+ $$fullname{$usercolon}.'
';
foreach (@partid) {
my $old_aw = $ENV{'form.GD_'.$user.'_'.$_.'_awarded_s'};
my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
@@ -2042,7 +2085,7 @@ sub editgrades {
}
$score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_solved'} eq 'excused') &&
($score ne 'excused'));
- $result .= '
';
- my ($depth,$ctr,$question) = (1,0,1);
+ my ($depth,$question) = (1,1);
$iterator->next(); # skip the first BEGIN_MAP
my $curRes = $iterator->next(); # for "current resource"
- while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop
+ while ($depth > 0) {
if($curRes == $iterator->BEGIN_MAP) { $depth++; }
- if($curRes == $iterator->END_MAP) { $depth++; }
+ if($curRes == $iterator->END_MAP) { $depth--; }
if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
my $parts = $curRes->parts();
- $parts = &temp_parts_fix($parts); # remove line when lonnavmap is fixed
my $title = $curRes->compTitle();
my $symbx = $curRes->symb();
$studentTable.='
'."\n";
@@ -2776,14 +2823,13 @@ sub updateGradeByPage {
$iterator->next(); # skip the first BEGIN_MAP
my $curRes = $iterator->next(); # for "current resource"
- my ($depth,$ctr,$question,$changeflag)= (1,0,1,0);
- while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop
+ my ($depth,$question,$changeflag)= (1,1,0);
+ while ($depth > 0) {
if($curRes == $iterator->BEGIN_MAP) { $depth++; }
- if($curRes == $iterator->END_MAP) { $depth++; }
+ if($curRes == $iterator->END_MAP) { $depth--; }
if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
my $parts = $curRes->parts();
- $parts = &temp_parts_fix($parts); # remove line when lonnavmap is fixed
my $title = $curRes->compTitle();
my $symbx = $curRes->symb();
$studentTable.='