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

albertel lon-capa-cvs@mail.lon-capa.org
Fri, 04 Oct 2002 06:22:12 -0000


This is a MIME encoded message

--albertel1033712532
Content-Type: text/plain

albertel		Fri Oct  4 02:22:12 2002 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  -supports partids which aren't purely numeric
  -supports setting all store possibilities
  -renamed all internal form elments to prevent any conflicts
  -supports changing numer of tries BUG#700
  -some foo removal (replaced with undef)
  
  
  
--albertel1033712532
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20021004022212.txt"

Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.53 loncom/homework/grades.pm:1.54
--- loncom/homework/grades.pm:1.53	Wed Oct  2 17:24:35 2002
+++ loncom/homework/grades.pm	Fri Oct  4 02:22:12 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.53 2002/10/02 21:24:35 albertel Exp $
+# $Id: grades.pm,v 1.54 2002/10/04 06:22:12 albertel Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -51,7 +51,7 @@
     my @parts =();
     my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
     foreach my $key (@metakeys) {
-	if ( $key =~ m/stores_([0-9]+)_.*/) {
+	if ( $key =~ m/stores_(\w+)_.*/) {
 	    push(@parts,$key);
 	}
     }
@@ -91,7 +91,7 @@
     my %seen = ();
     my (@partlist,%handgrade);
     foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
-	if (/^\w+response_\d+.*/) {
+	if (/^\w+response_\w+.*/) {
 	    my ($responsetype,$part) = split(/_/,$_,2);
 	    my ($partid,$respid) = split(/_/,$part);
 	    $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no');
@@ -1441,10 +1441,10 @@
 	for (i=0;i<document.classgrade.total.value;i++) {
 	    var user = eval("document.classgrade.ctr"+i+".value");
 	    var scorename = eval("document.classgrade.GD_"+user+
-				 "_"+partid+"_aw");
+				 "_"+partid+"_awarded");
 	    var saveval   = eval("document.classgrade.GD_"+user+
-				 "_"+partid+"_sv_s.value");
-	    var selname   = eval("document.classgrade.GD_"+user+"_"+partid+"_sv");
+				 "_"+partid+"_solved_s.value");
+	    var selname   = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
 	    if (saveval != "correct") {
 		scorename.value = point;
 		if (selname[0].selected != true) {
@@ -1470,11 +1470,11 @@
 	    for (i=0;i<document.classgrade.total.value;i++) {
 		var user = eval("document.classgrade.ctr"+i+".value");
 		var scorename = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_aw");
+				     "_"+partid+"_awarded");
 		var saveval   = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_sv_s.value");
+				     "_"+partid+"_solved_s.value");
 		var selname   = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_sv");
+				     "_"+partid+"_solved");
 		if (saveval != "correct") {
 		    scorename.value = "";
 		    selname[1].selected = true;
@@ -1484,14 +1484,14 @@
 	    for (i=0;i<document.classgrade.total.value;i++) {
 		var user = eval("document.classgrade.ctr"+i+".value");
 		var scorename = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_aw");
+				     "_"+partid+"_awarded");
 		var saveval   = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_sv_s.value");
+				     "_"+partid+"_solved_s.value");
 		var selname   = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_sv");
+				     "_"+partid+"_solved");
 		if (saveval != "correct") {
 		    scorename.value = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_aw_s.value");;
+				     "_"+partid+"_awarded_s.value");;
 		    selname[0].selected = true;
 		}
 	    }
@@ -1499,8 +1499,8 @@
     }
 
     function changeSelect(partid,user) {
-	var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_sv");
-	var textbox = eval("document.classgrade.GD_"+user+'_'+partid+"_aw");
+	var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
+	var textbox = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
 	var point  = textbox.value;
 	var weight = eval("document.classgrade.weight_"+partid+".value");
 
@@ -1521,9 +1521,9 @@
     }
 
     function changeOneScore(partid,user) {
-	var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_sv");
+	var selval = eval("document.classgrade.GD_"+user+'_'+partid+"_solved");
 	if (selval[1].selected) {
-	    var boxval = eval("document.classgrade.GD_"+user+'_'+partid+"_aw");
+	    var boxval = eval("document.classgrade.GD_"+user+'_'+partid+"_awarded");
 	    boxval.value = "";
 	}
     }
@@ -1544,14 +1544,14 @@
 	    for (i=0;i<document.classgrade.total.value;i++) {
 		var user = eval("document.classgrade.ctr"+i+".value");
 		var resetscore = eval("document.classgrade.GD_"+user+
-				      "_"+partid+"_aw");
+				      "_"+partid+"_awarded");
 		resetscore.value = eval("document.classgrade.GD_"+user+
-					"_"+partid+"_aw_s.value");
+					"_"+partid+"_awarded_s.value");
 
 		var saveselval   = eval("document.classgrade.GD_"+user+
-				     "_"+partid+"_sv_s.value");
+				     "_"+partid+"_solved_s.value");
 
-		var selname   = eval("document.classgrade.GD_"+user+"_"+partid+"_sv");
+		var selname   = eval("document.classgrade.GD_"+user+"_"+partid+"_solved");
 		if (saveselval == "excused") {
 		    if (selname[1].selected == false) { selname[1].selected = true;}
 		} else {
@@ -1608,7 +1608,7 @@
     $result.='<table border="0">';
     my %seen = ();
     for (sort keys(%$handgrade)) {
-	my ($partid,$respid) = split (/_/);
+	my ($partid,$respid) = split (/_/,$_,2);
 	next if $seen{$partid};
 	$seen{$partid}++;
 	my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
@@ -1624,19 +1624,19 @@
 	my $ctr = 0;
 	while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
 	    $result.= '<td><input type="radio" name="RADVAL_'.$partid.'" '.
-		'onclick="javascript:writePoint('.$partid.','.$weight{$partid}.
+		'onclick="javascript:writePoint(\''.$partid.'\','.$weight{$partid}.
 		','.$ctr.')" />'.$ctr."</td>\n";
 	    $result.=(($ctr+1)%10 == 0 ? '</tr><tr>' : '');
 	    $ctr++;
 	}
 	$result.='</tr></table>';
 	$result.= '</td><td><b> or </b><input type="text" name="TEXTVAL_'.
-	    $partid.'" size="4" '.
-	    'onChange="javascript:writePoint('.$partid.','.$weight{$partid}.
-	    ',\'textval\')" /> /'.
+	    $partid.'" size="4" '.'onChange="javascript:writePoint(\''.
+		$partid.'\','.$weight{$partid}.',\'textval\')" /> /'.
 	    $weight{$partid}.' (problem weight)</td>'."\n";
 	$result.= '</td><td><select name="SELVAL_'.$partid.'"'.
-	    'onChange="javascript:writeRadText('.$partid.','.$weight{$partid}.')" /> '.
+	    'onChange="javascript:writeRadText(\''.$partid.'\','.
+		$weight{$partid}.')" /> '.
 	    '<option selected="on"> </option>'.
 	    '<option>excused</option></select></td></tr>'."\n";
 	$ctsparts++;
@@ -1664,11 +1664,9 @@
     my (@parts) = sort(&getpartlist($url));
     foreach my $part (@parts) {
 	my $display=&Apache::lonnet::metadata($url,$part.'.display');
-	next if ($display =~ /^Number of Attempts/);
 	if  (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
 	if ($display =~ /^Partial Credit Factor/) {
-	    $_ = $display;
-	    my ($partid) = /.*?(\d+).*/;
+	    my ($partid) = &split_part_type($part);
 	    $result.='<td><b>Score Part '.$partid.'<br />(weight = '.
 		$weight{$partid}.')</b></td>'."\n";
 	    next;
@@ -1707,30 +1705,36 @@
 	'\')"; TARGET=_self>'.$fullname.'</a>'.
 	'</td><td>'.$uname.'</td><td align="middle">'.$udom.'</td>'."\n";
     foreach my $part (@$parts) {
-	my ($temp,$part,$type)=split(/_/,$part);
+	my ($part,$type) = &split_part_type($part);
 	my $score=$record{"resource.$part.$type"};
-	next if $type eq 'tries';
 	if ($type eq 'awarded') {
 	    my $pts = $score eq '' ? '' : $score*$$weight{$part};
 	    $result.='<input type="hidden" name="'.
-		'GD_'.$uname.'_'.$part.'_aw_s" value="'.$pts.'" />'."\n";
+		'GD_'.$uname.'_'.$part.'_awarded_s" value="'.$pts.'" />'."\n";
 	    $result.='<td align="middle"><input type="text" name="'.
-		'GD_'.$uname.'_'.$part.'_aw" '.
-		'onChange="javascript:changeSelect('.$part.',\''.$uname.
+		'GD_'.$uname.'_'.$part.'_awarded" '.
+		'onChange="javascript:changeSelect(\''.$part.'\',\''.$uname.
 		'\')" value="'.$pts.'" size="4" /></td>'."\n";
 	} elsif ($type eq 'solved') {
 	    my ($status,$foo)=split(/_/,$score,2);
 	    $status = 'nothing' if ($status eq '');
-	    $result.='<input type="hidden" name="'.
-		'GD_'.$uname.'_'.$part.'_sv_s" value="'.$status.'" />'."\n";
+	    $result.='<input type="hidden" name="'.'GD_'.$uname.'_'.
+		$part.'_solved_s" value="'.$status.'" />'."\n";
 	    $result.='<td align="middle"><select name="'.
-		'GD_'.$uname.'_'.$part.'_sv" '.
-		'onChange="javascript:changeOneScore('.$part.',\''.$uname.'\')" >'."\n";
+		'GD_'.$uname.'_'.$part.'_solved" '.
+		'onChange="javascript:changeOneScore(\''.$part.'\',\''.$uname.'\')" >'."\n";
 	    my $optsel = '<option selected="on"> </option><option>excused</option>'."\n";
 	    $optsel = '<option> </option><option selected="on">excused</option>'."\n"
 		if ($status eq 'excused');
 	    $result.=$optsel;
 	    $result.="</select></td>\n";
+	} else {
+	    $result.='<input type="hidden" name="'.
+		'GD_'.$uname.'_'.$part.'_'.$type.'_s" value="'.$score.'" />'.
+		    "\n";
+	    $result.='<td align="middle"><input type="text" name="'.
+		'GD_'.$uname.'_'.$part.'_'.$type.'" '.
+		'value="'.$score.'" size="4" /></td>'."\n";
 	}
     }
     $result.='</tr>';
@@ -1763,20 +1767,40 @@
 
     my (@partid);
     my %weight = ();
+    my %columns = ();
     my ($i,$ctr,$count,$rec_update) = (0,0,0,0);
+
+    my (@parts) = sort(&getpartlist($url));
+    my $header;
     while ($ctr < $ENV{'form.totalparts'}) {
 	my $partid = $ENV{'form.partid_'.$ctr};
 	push @partid,$partid;
 	$weight{$partid} = $ENV{'form.weight_'.$partid};
 	$ctr++;
-	$result .= '<td colspan = 2 align="center"><b>Part '.$partid.
-	    '</b> (Weight = '.$weight{$partid}.')</td>';
     }
-    $result .= '</tr><tr bgcolor="#deffff">';
-    foreach (@partid) {
-	$result .= '<td align="center">&nbsp;<b>Old Score</b>&nbsp;</td>'.
+    foreach my $partid (@partid) {
+	$header .= '<td align="center">&nbsp;<b>Old Score</b>&nbsp;</td>'.
 	    '<td align="center">&nbsp;<b>New Score</b>&nbsp;</td>';
+	$columns{$partid}=2;
+	foreach my $stores (@parts) {
+	    my ($part,$type) = &split_part_type($stores);
+	    if ($part !~ m/^\Q$partid\E/) { next;}
+	    if ($type eq 'awarded' || $type eq 'solved') { next; }
+	    my $display=&Apache::lonnet::metadata($url,$stores.'.display');
+	    $display =~ s/\[Part: (\w)+\]//;
+	    $header .= '<td align="center">&nbsp;<b>Old</b> '.$display.'&nbsp;</td>'.
+		'<td align="center">&nbsp;<b>New</b> '.$display.'&nbsp;</td>';
+	    $columns{$partid}+=2;
+	}
     }
+    foreach my $partid (@partid) {
+	$result .= '<td colspan="'.$columns{$partid}.
+	    '" align="center"><b>Part '.$partid.
+	    '</b> (Weight = '.$weight{$partid}.')</td>';
+
+    }
+    $result .= '</tr><tr bgcolor="#deffff">';
+    $result .= $header;
     $result .= '</tr>'."\n";
 
     for ($i=0; $i<$ENV{'form.total'}; $i++) {
@@ -1784,38 +1808,54 @@
 	my %newrecord;
 	my $updateflag = 0;
 	my @userdom = grep /^$user:/,keys %$classlist;
-	my ($foo,$udom) = split(/:/,$userdom[0]);
+	my (undef,$udom) = split(/:/,$userdom[0]);
 
 	$result .= '<tr bgcolor="#ffffde"><td>'.$user.'&nbsp;</td><td>'.
 	    $$fullname{$userdom[0]}.'&nbsp;</td>';
-
 	foreach (@partid) {
-	    my $old_aw    = $ENV{'form.GD_'.$user.'_'.$_.'_aw_s'};
-	    my $old_part  = $old_aw eq '' ? '' : $old_aw/$weight{$_};
-	    my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_sv_s'}};
-
-	    my $awarded   = $ENV{'form.GD_'.$user.'_'.$_.'_aw'};
-	    my $partial   = $awarded eq '' ? '' : $awarded/$weight{$_};
+	    my $old_aw    = $ENV{'form.GD_'.$user.'_'.$_.'_awarded_s'};
+	    my $old_part_pcr = $old_aw/($weight{$_} ne '0' ? $weight{$_}:1);
+	    my $old_part  = $old_aw eq '' ? '' : $old_part_pcr;
+	    my $old_score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
+
+	    my $awarded   = $ENV{'form.GD_'.$user.'_'.$_.'_awarded'};
+	    my $pcr       = $awarded/($weight{$_} ne '0' ? $weight{$_} : 1);
+	    my $partial   = $awarded eq '' ? '' : $pcr;
 	    my $score;
 	    if ($partial eq '') {
-		$score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_sv_s'}};
+		$score = $scoreptr{$ENV{'form.GD_'.$user.'_'.$_.'_solved_s'}};
 	    } elsif ($partial > 0) {
 		$score = 'correct_by_override';
 	    } elsif ($partial == 0) {
 		$score = 'incorrect_by_override';
 	    }
-	    $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_sv'} eq 'excused') &&
+	    $score = 'excused' if (($ENV{'form.GD_'.$user.'_'.$_.'_solved'} eq 'excused') &&
 				   ($score ne 'excused'));
 	    $result .= '<td align="center">'.$old_aw.'&nbsp;</td>'.
 		'<td align="center">'.$awarded.
 		($score eq 'excused' ? $score : '').'&nbsp;</td>';
 
-	    next if ($old_part eq $partial && $old_score eq $score);
-
-	    $updateflag = 1;
-	    $newrecord{'resource.'.$_.'.awarded'}  = $partial if $partial ne '';
-	    $newrecord{'resource.'.$_.'.solved'}   = $score;
-	    $rec_update++;
+	    if (!($old_part eq $partial && $old_score eq $score)) {
+		$updateflag = 1;
+		$newrecord{'resource.'.$_.'.awarded'}  = $partial if $partial ne '';
+		$newrecord{'resource.'.$_.'.solved'}   = $score;
+		$rec_update++;
+	    }
+
+	    my $partid=$_;
+	    foreach my $stores (@parts) {
+		my ($part,$type) = &split_part_type($stores);
+		if ($part !~ m/^\Q$partid\E/) { next;}
+		if ($type eq 'awarded' || $type eq 'solved') { next; }
+		my $old_aw    = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type.'_s'};
+		my $awarded   = $ENV{'form.GD_'.$user.'_'.$part.'_'.$type};
+		if ($awarded ne '' && $awarded ne $old_aw) {
+		    $newrecord{'resource.'.$part.'.'.$type}= $awarded;
+		    $updateflag=1;
+		}
+		$result .= '<td align="center">'.$old_aw.'&nbsp;</td>'.
+		    '<td align="center">'.$awarded.'&nbsp;</td>';
+	    }
 	}
 	$result .= '</tr>'."\n";
 	if ($updateflag) {
@@ -1831,6 +1871,15 @@
 	'<b>Total number of students = '.$ENV{'form.total'}.'</b><br />';
     return $title.$msg.$result;
 }
+
+sub split_part_type {
+    my ($partstr) = @_;
+    my ($temp,@allparts)=split(/_/,$partstr);
+    my $type=pop(@allparts);
+    my $part=join('.',@allparts);
+    return ($part,$type);
+}
+
 #------------- end of section for handling grading by section/class ---------
 #
 #----------------------------------------------------------------------------

--albertel1033712532--