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

raeburn raeburn@source.lon-capa.org
Sat, 18 Dec 2010 23:09:58 -0000


This is a MIME encoded message

--raeburn1292713798
Content-Type: text/plain

raeburn		Sat Dec 18 23:09:58 2010 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - New Question Type - randomizetry
  - New Variation displayed after N tries (default N=1).
     - Additional args (type,trial,rndseed) for the following:
       &get_analyze(), &get_order(), &get_radiobutton_correct_foil(), &cleanRecord() 
     - 'New variation this try' displayed in grading screen submissions view 
       if try used different rndseed.
     - rndseed used shown in submission record.
  
  
--raeburn1292713798
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20101218230958.txt"

Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.639 loncom/homework/grades.pm:1.640
--- loncom/homework/grades.pm:1.639	Sat Dec  4 15:02:26 2010
+++ loncom/homework/grades.pm	Sat Dec 18 23:09:57 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.639 2010/12/04 15:02:26 www Exp $
+# $Id: grades.pm,v 1.640 2010/12/18 23:09:57 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -213,8 +213,13 @@
     }
 
     sub get_analyze {
-	my ($symb,$uname,$udom,$no_increment,$add_to_hash)=@_;
+	my ($symb,$uname,$udom,$no_increment,$add_to_hash,$type,$trial,$rndseed)=@_;
 	my $key = "$symb\0$uname\0$udom";
+        if ($type eq 'randomizetry') {
+            if ($trial ne '') {
+                $key .= "\0".$trial;
+            }
+        }
 	if (exists($analyze_cache{$key})) {
             my $getupdate = 0;
             if (ref($add_to_hash) eq 'HASH') {
@@ -242,9 +247,15 @@
                     'grade_courseid'    =>  $env{'request.course.id'},
                     'grade_username'    => $uname,
                     'grade_noincrement' => $no_increment);
+        if ($type eq 'randomizetry') {
+            $form{'grade_questiontype'} = $type;
+            if ($rndseed ne '') {
+                $form{'grade_rndseed'} = $rndseed;
+            }
+        }
         if (ref($add_to_hash)) {
             %form = (%form,%{$add_to_hash});
-        } 
+        }
 	my $subresult=&ssi_with_retries($url, $ssi_retries,%form);
 	(undef,$subresult)=split(/_HASH_REF__/,$subresult,2);
 	my %analyze=&Apache::lonnet::str2hash($subresult);
@@ -257,15 +268,15 @@
     }
 
     sub get_order {
-	my ($partid,$respid,$symb,$uname,$udom,$no_increment)=@_;
-	my $analyze = &get_analyze($symb,$uname,$udom,$no_increment);
+	my ($partid,$respid,$symb,$uname,$udom,$no_increment,$type,$trial,$rndseed)=@_;
+	my $analyze = &get_analyze($symb,$uname,$udom,$no_increment,undef,$type,$trial,$rndseed);
 	return $analyze->{"$partid.$respid.shown"};
     }
 
     sub get_radiobutton_correct_foil {
-	my ($partid,$respid,$symb,$uname,$udom)=@_;
-	my $analyze = &get_analyze($symb,$uname,$udom);
-        my $foils = &get_order($partid,$respid,$symb,$uname,$udom);
+	my ($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed)=@_;
+	my $analyze = &get_analyze($symb,$uname,$udom,undef,undef,$type,$trial,$rndseed);
+        my $foils = &get_order($partid,$respid,$symb,$uname,$udom,undef,$type,$trial,$rndseed);
         if (ref($foils) eq 'ARRAY') {
 	    foreach my $foil (@{$foils}) {
 	        if ($analyze->{"$partid.$respid.foil.value.$foil"} eq 'true') {
@@ -307,7 +318,7 @@
 #        response types only.
 sub cleanRecord {
     my ($answer,$response,$symb,$partid,$respid,$record,$order,$version,
-	$uname,$udom) = @_;
+	$uname,$udom,$type,$trial,$rndseed) = @_;
     my $grayFont = '<span class="LC_internal_info">';
     if ($response =~ /^(option|rank)$/) {
 	my %answer=&Apache::lonnet::str2hash($answer);
@@ -351,7 +362,7 @@
 	my %answer=&Apache::lonnet::str2hash($answer);
 	my ($toprow,$bottomrow);
 	my $correct = 
-	    &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom);
+	    &get_radiobutton_correct_foil($partid,$respid,$symb,$uname,$udom,$type,$trial,$rndseed);
 	foreach my $foil (@$order) {
 	    if (exists($answer{$foil})) {
 		if ($foil eq $correct) {
@@ -2133,6 +2144,12 @@
 		    my ($ressub,$hide,$subval) = split(/:/,$submission,3);
 		    # Similarity check
 		    my $similar='';
+                    my ($type,$trial,$rndseed);
+                    if ($hide eq 'rand') {
+                        $type = 'randomizetry';
+                        $trial = $record{"resource.$partid.tries"};
+                        $rndseed = $record{"resource.$partid.rndseed"};
+                    }
 		    if($env{'form.checkPlag'}){
 			my ($oname,$odom,$ocrsid,$oessay,$osim)=
 			    &most_similar($uname,$udom,$subval,\%old_essays);
@@ -2142,7 +2159,7 @@
 				&Apache::lonnet::coursedescription($ocrsid,
 								   {'one_time' => 1});
 
-                            if ($hide) {
+                            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 {
@@ -2159,7 +2176,8 @@
                             }
 			}
 		    }
-		    my $order=&get_order($partid,$respid,$symb,$uname,$udom);
+		    my $order=&get_order($partid,$respid,$symb,$uname,$udom,
+                                         undef,$type,$trial,$rndseed);
 		    if ($env{'form.lastSub'} eq 'lastonly' || 
 			($env{'form.lastSub'} eq 'hdgrade' && 
 			 $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) {
@@ -2171,7 +2189,7 @@
                             '</span>&nbsp; &nbsp;';
 			my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record);
 			if (@$files) {
-                            if ($hide) {
+                            if ($hide eq 'anon') {
                                 $lastsubonly.='<br />'.&mt('[quant,_1,file] uploaded to this anonymous survey',scalar(@{$files}));
                             } else {
                                 $lastsubonly.='<br /><span class="LC_warning">'.&mt('Like all files provided by users, this file may contain viruses').'</span><br />';
@@ -2182,12 +2200,12 @@
                             }
 			    $lastsubonly.='<br />';
 			}
-                        if ($hide) {
+                        if ($hide eq 'anon') {
                             $lastsubonly.='<b>'.&mt('Anonymous Survey').'</b>'; 
                         } else {
 			    $lastsubonly.='<b>'.&mt('Submitted Answer:').' </b>'.
 			        &cleanRecord($subval,$responsetype,$symb,$partid,
-					     $respid,\%record,$order,undef,$uname,$udom);
+					     $respid,\%record,$order,undef,$uname,$udom,$type,$trial,$rndseed);
                         }
 			if ($similar) {$lastsubonly.="<br /><br />$similar\n";}
 			$lastsubonly.='</div>';
@@ -2386,35 +2404,52 @@
 		    &Apache::lonlocal::locallocaltime($$returnhash{$version.':timestamp'});
 	    }
 	}
-        my %typeparts;
+        my (%typeparts,%randombytry);
         my $showsurv = 
             &Apache::lonnet::allowed('vas',$env{'request.course.id'});
         foreach my $key (sort(keys(%lasthash))) {
             if ($key =~ /\.type$/) {
                 if (($lasthash{$key} eq 'anonsurvey') || 
-                    ($lasthash{$key} eq 'anonsurveycred')) {
+                    ($lasthash{$key} eq 'anonsurveycred') ||
+                    ($lasthash{$key} eq 'randomizetry')) {
                     my ($ign,@parts) = split(/\./,$key);
                     pop(@parts);
-                    unless ($showsurv) {
+                    if ($lasthash{$key} eq 'randomizetry') {
                         my $id = join(',',@parts);
-                        $typeparts{$ign.'.'.$id} = $lasthash{$key};
+                        $randombytry{$ign.'.'.$id} = $lasthash{$key};
+                    } else {
+                        unless ($showsurv) {
+                            my $id = join(',',@parts);
+                            $typeparts{$ign.'.'.$id} = $lasthash{$key};
+                        }
                     }
                     delete($lasthash{$key});
                 }
             }
         }
         my @hidden = keys(%typeparts);
+        my @randomize = keys(%randombytry);
 	foreach my $key (keys(%lasthash)) {
 	    next if ($key !~ /\.submission$/);
             my $hide;
             if (@hidden) {
                 foreach my $id (@hidden) {
                     if ($key =~ /^\Q$id\E/) {
-                        $hide = 1;
+                        $hide = 'anon';
                         last;
                     }
                 }
             }
+            unless ($hide) {
+                if (@randomize) {
+                    foreach my $id (@hidden) {
+                        if ($key =~ /^\Q$id\E/) {
+                            $hide = 'rand';
+                            last;
+                        }
+                    }
+                }
+            }
 	    my ($partid,$foo) = split(/submission$/,$key);
 	    my $draft  = $lasthash{$partid.'awarddetail'} eq 'DRAFT' ?
 		'<span class="LC_warning">Draft Copy</span> ' : '';
@@ -4366,8 +4401,8 @@
 		&Apache::loncommon::start_data_table_row().
 		'<td align="center" valign="top" >'.$prob.
 		(scalar(@{$parts}) == 1 ? '' 
-		                        : '<br />('.&mt('[_1]&nbsp;parts)',
-							scalar(@{$parts}))
+		                        : '<br />('.&mt('[_1]parts)',
+							scalar(@{$parts}).'&nbsp;')
 		 ).
 		 '</td>';
 	    $studentTable.='<td valign="top">';
@@ -4461,6 +4496,7 @@
 
     my $interaction;
     my $no_increment = 1;
+    my %lastrndseed;
     for ($version=1;$version<=$$record{'version'};$version++) {
 	my $timestamp = 
 	    &Apache::lonlocal::locallocaltime($$record{$version.':timestamp'});
@@ -4478,9 +4514,9 @@
 	my @versionKeys = split(/\:/,$$record{$version.':keys'});
 	my @displaySub = ();
 	foreach my $partid (@{$parts}) {
-            my $hidden;
-            if (($$record{$version.':resource.'.$partid.'.type'} eq 'anonsurvey') ||
-                ($$record{$version.':resource.'.$partid.'.type'} eq 'anonsurveycred')) {
+            my ($hidden,$type);
+            $type = $$record{$version.':resource.'.$partid.'.type'};
+            if (($type eq 'anonsurvey') || ($type eq 'anonsurveycred')) {
                 $hidden = 1;
             }
 	    my @matchKey = ($isTask ? sort(grep /^resource\.\d+\.\Q$partid\E\.award$/,@versionKeys)
@@ -4503,23 +4539,34 @@
                     if ($hidden) {
                         $displaySub[0].= &mt('Anonymous Survey').'</b>';
                     } else {
+                        my ($trial,$rndseed,$newvariation);
+                        if ($type eq 'randomizetry') {
+                            $trial = $$record{"$where.$partid.tries"};
+                            $rndseed = $$record{"$where.$partid.rndseed"};
+                        }
 		        if ($$record{"$where.$partid.tries"} eq '') {
 			    $displaySub[0].=&mt('Trial not counted');
 		        } else {
 			    $displaySub[0].=&mt('Trial: [_1]',
 					    $$record{"$where.$partid.tries"});
+                            if ($rndseed || $lastrndseed{$partid}) {
+                                if ($rndseed ne $lastrndseed{$partid}) {
+                                    $newvariation = '&nbsp;('.&mt('New variation this try').')';
+                                }
+                            }
+                            $lastrndseed{$partid} = $rndseed;
 		        }
 		        my $responseType=($isTask ? 'Task'
                                               : $responseType->{$partid}->{$responseId});
 		        if (!exists($orders{$partid})) { $orders{$partid}={}; }
-		        if (!exists($orders{$partid}->{$responseId})) {
+		        if ((!exists($orders{$partid}->{$responseId})) || ($trial)) {
 			    $orders{$partid}->{$responseId}=
 			        &get_order($partid,$responseId,$symb,$uname,$udom,
-                                           $no_increment);
+                                           $no_increment,$type,$trial,$rndseed);
 		        }
-		        $displaySub[0].='</b></span>'; # /nobreak
+		        $displaySub[0].='</b>'.$newvariation.'</span>'; # /nobreak
 		        $displaySub[0].='&nbsp; '.
-			    &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom).'<br />';
+			    &cleanRecord($$record{$version.':'.$matchKey},$responseType,$symb,$partid,$responseId,$record,$orders{$partid}->{$responseId},"$version:",$uname,$udom,$type,$trial,$rndseed).'<br />';
                     }
 		}
 	    }
@@ -4618,7 +4665,7 @@
 		&Apache::loncommon::start_data_table_row().
 		'<td align="center" valign="top" >'.$prob.
 		(scalar(@{$parts}) == 1 ? '' 
-                                        : '<br />('.&mt('[quant,_1,&nbsp;part]',scalar(@{$parts}))
+                                        : '<br />('.&mt('[quant,_1,part]',scalar(@{$parts}))
 		.')').'</td>';
 	    $studentTable.='<td valign="top">&nbsp;<b>'.$title.'</b>&nbsp;</td>';
 

--raeburn1292713798--