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

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 17 Oct 2002 14:35:34 -0000


matthew		Thu Oct 17 10:35:34 2002 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  Rewrite of collaborator code.  I have no means currently of testing this
  code so it may not have the functionality needed.  At least it compiles.
  Added regular expression to &keywords_highlight to clean up display
  of essay responses.
  Made showing the problem the default when grading.
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.56 loncom/homework/grades.pm:1.57
--- loncom/homework/grades.pm:1.56	Wed Oct 16 15:23:48 2002
+++ loncom/homework/grades.pm	Thu Oct 17 10:35:34 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.56 2002/10/16 19:23:48 matthew Exp $
+# $Id: grades.pm,v 1.57 2002/10/17 14:35:34 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -339,8 +339,8 @@
     my $checklastsub = $ENV{'form.handgrade'} eq 'yes' ? '' : 'checked';
 
     my $gradeTable='<form action="/adm/grades" method="post" name="gradesub">'."\n".
-	'&nbsp;<b>View Problem: </b><input type="radio" name="vProb" value="no" checked> no '."\n".
-	'<input type="radio" name="vProb" value="yes"> yes <br />'."\n".
+	'&nbsp;<b>View Problem: </b><input type="radio" name="vProb" value="no" > no '."\n".
+	'<input type="radio" name="vProb" value="yes" checked > yes <br />'."\n".
 	'&nbsp;<b>Submissions: </b>'."\n";
     if ($ENV{'form.handgrade'} eq 'yes') {
 	$gradeTable.='<input type="radio" name="lastSub" value="hdgrade" '.$checkhdgrade.' /> handgrade only'."\n";
@@ -916,44 +916,55 @@
 	($classlist,undef,$fullname) = &getclasslist('all','0');
 	for (keys (%$handgrade)) {
 	    my $ncol = &Apache::lonnet::EXT('resource.'.$_.
-					    '.maxcollaborators',$symb,$udom,$uname);
-	    if ($ncol > 0) {
-		s/\_/\./g;
-		if ($record{'resource.'.$_.'.collaborators'} ne '') {
-		    my (@collaborators) = split(/,?\s+/,
-						$record{'resource.'.$_.'.collaborators'});
-		    my (@badcollaborators);
-		    if (scalar(@collaborators) != 0) {
-			$result.='<b>Collaborators: </b>';
-			foreach my $collaborator (@collaborators) {
-			    $collaborator = $collaborator =~ /\@|:/ ? 
-				(split(/@|:/,$collaborator))[0] : $collaborator;
-			    next if ($collaborator eq $uname);
-			    if (!grep /^$collaborator:/i,keys %$classlist) {
-				push @badcollaborators,$collaborator;
-				next;
-			    }
-			    push @col_list, $collaborator;
-			    my ($lastname,$givenn) = split(/,/,$$fullname{$collaborator.':'.$udom});
-			    push @col_fullnames, $givenn.' '.$lastname;
-			    $result.=$$fullname{$collaborator.':'.$udom}.'&nbsp; &nbsp; &nbsp;';
-			}
-			$result.='<br />'."\n";
-			$result.='<table border="0"><tr bgcolor="#ffbbbb"><td>'.
-			    'This student has submitted '.
-			    (scalar (@badcollaborators) > 1 ? '' : 'an').
-			    ' invalid collaborator'.(scalar (@badcollaborators) > 1 ? 's. ' : '. ').
-			    (join ', ',@badcollaborators).'</td></tr></table>' 
-			    if (scalar(@badcollaborators) > 0);
-
-			$result.='<table border="0"><tr bgcolor="#ffbbbb"><td>'.
-			    'This student has submitted too many collaborators. Maximum is '.
-			    $ncol.'.</td></tr></table>' if (scalar(@collaborators) > $ncol);
-			$result.='<input type="hidden" name="collaborator'.$counter.
-			    '" value="'.(join ':',@col_list).'" />'."\n";
-		    }
-		}
-	    }
+					    '.maxcollaborators',
+                                            $symb,$udom,$uname);
+	    next if ($ncol <= 0);
+            s/\_/\./g;
+            next if ($record{'resource.'.$_.'.collaborators'} eq '');
+            my (@collaborators) = split(/,?\s+/,
+                                   $record{'resource.'.$_.'.collaborators'});
+            my (@badcollaborators);
+            if (scalar(@collaborators) != 0) {
+                $result.='<b>Collaborators: </b>';
+                foreach my $collaborator (@collaborators) {
+                    my ($co_name,$co_dom) = split /\@|:/,$collaborator;
+                    $co_dom = $udom if (! defined($co_dom));
+                    next if ($co_name eq $uname && $co_dom eq $udom);
+                    # Doing this grep allows 'fuzzy' specification
+                    my @Matches = grep /^$co_name:$co_dom/i,
+                    keys %$classlist;
+                    if (! scalar(@Matches)) {
+                        push @badcollaborators,$collaborator;
+                        next;
+                    }
+                    push @col_list, @Matches;
+                    foreach (@Matches) {
+                        my ($lastname,$givenn) = split(/,/,$$fullname{$_});
+                        push @col_fullnames, $givenn.' '.$lastname;
+                        $result.=$$fullname{$_}.'&nbsp; &nbsp; &nbsp;';
+                    }
+                }
+                $result.='<br />'."\n";
+                if (scalar(@badcollaborators) > 0) {
+                    $result.='<table border="0"><tr bgcolor="#ffbbbb"><td>';
+                    $result.='This student has submitted ';
+                    if (scalar(@badcollaborators) == 1) {
+                        $result .= 'an invalid collaborator';
+                    } else {
+                        $result .= 'invalid collaborators';
+                    }
+                    $result .= ': '.join(', ',@badcollaborators);
+                    
+                }
+                if (scalar(@collaborators > $ncol)) {
+                    $result .= '<table border="0"><tr bgcolor="#ffbbbb"><td>';
+                    $result .= 'This student has sumbitted too many '.
+                        'collaborators.  Maximum is '.$ncol;
+                    $result .= '</td></tr></table>';
+                }
+                $result.='<input type="hidden" name="collaborator'.$counter.
+                    '" value="'.(join ':',@col_list).'" />'."\n";
+            }
 	}
     }
     $request->print($result."\n");
@@ -1163,6 +1174,11 @@
     foreach (@keylist) {
 	$string =~ s/\b$_(\b|\.)/\<font color\=$ENV{'form.kwclr'} $size\>$styleon$_$styleoff\<\/font\>/gi;
     }
+    # This is not really the right place to do this, but I cannot find a
+    # better one at this time.  So here we go - the m in the s:::mg causes
+    # ^ to match the beginning of a new line.  So we replace(???) the beginning
+    # of the line with <br /> to make things formatted a little better.
+    $string =~ s:^:<br />:mg;
     return $string;
 }