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

raeburn raeburn at source.lon-capa.org
Mon Dec 10 00:47:21 EST 2012


raeburn		Mon Dec 10 05:47:21 2012 EDT

  Modified files:              
    /loncom/homework	grades.pm 
  Log:
  - Bubblesheet grading and verification of "CODEd" and "NAMEd" exams 
    available for exams where randomorder parameter set for exam folder.
  - Routine used to create array of resources in the order used in the exam
    -- either CODE-based, or NAME-based -- moved to routine: &users_order()
    to facilitate reuse.   
  
  
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.677 loncom/homework/grades.pm:1.678
--- loncom/homework/grades.pm:1.677	Mon Dec 10 01:13:08 2012
+++ loncom/homework/grades.pm	Mon Dec 10 05:47:21 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.677 2012/12/10 01:13:08 raeburn Exp $
+# $Id: grades.pm,v 1.678 2012/12/10 05:47:21 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -8025,22 +8025,10 @@
         }
 
         my @mapresources = @resources;
-        if ($randomorder && $scancode) {
-            unless (ref($ordered{$scancode}) eq 'ARRAY') {
-                $env{'form.CODE'} = $scancode;
-                my $actual_seq =
-                    &Apache::lonprintout::master_seq_to_person_seq($sequence,
-                                                                   \@master_seq,
-                                                                   $user,$scancode);
-                if (ref($actual_seq) eq 'ARRAY') {
-                    @{$ordered{$scancode}} = 
-                        map { $symb_to_resource{$_}; } @{$actual_seq};
-                }
-                delete($env{'form.CODE'});
-            }
-            if (ref($ordered{$scancode}) eq 'ARRAY') {
-                @mapresources = @{$ordered{$scancode}};
-            }
+        if ($randomorder) {
+            @mapresources = 
+                &users_order($user,$scancode,$sequence,\@master_seq,\%ordered,
+                             \%symb_to_resource);
         }
         my (%partids_by_symb,$res_error);
         foreach my $resource (@mapresources) {
@@ -8190,6 +8178,53 @@
     return;
 }
 
+=pod
+
+=item users_order
+
+  Returns array of resources in current map, ordered based on either CODE,
+  if this is a CODEd exam, or based on student's identity if this is a 
+  "NAMEd" exam.
+
+  Should be used when randomorder applied when the corresponding exam was
+  printed, prior to students completing bubblesheets for the version of the
+  exam the student received. 
+
+=cut
+
+sub users_order  {
+    my ($user,$scancode,$mapurl,$master_seq,$ordered,$symb_to_resource) = @_;
+    my @mapresources;
+    unless ((ref($ordered) eq 'HASH') && (ref($symb_to_resource) eq 'HASH')) {
+        return @mapresources;
+    }  
+    if (($scancode) && (ref($ordered->{$scancode}) eq 'ARRAY')) {
+        @mapresources = @{$ordered->{$scancode}};
+    } elsif ($scancode) {
+        $env{'form.CODE'} = $scancode;
+        my $actual_seq =
+            &Apache::lonprintout::master_seq_to_person_seq($mapurl,
+                                                           $master_seq,
+                                                           $user,$scancode);
+        if (ref($actual_seq) eq 'ARRAY') {
+            @{$ordered->{$scancode}} =
+                map { $symb_to_resource->{$_}; } @{$actual_seq};
+            @mapresources = @{$ordered->{$scancode}};
+        }
+        delete($env{'form.CODE'});
+    } else {
+        my $actual_seq =
+            &Apache::lonprintout::master_seq_to_person_seq($mapurl,
+                                                           $master_seq,
+                                                           $user);
+        if (ref($actual_seq) eq 'ARRAY') {
+            @mapresources = 
+                map { $symb_to_resource->{$_}; } @{$actual_seq};
+        }
+     }
+     return @mapresources;
+}
+
 sub grade_student_bubbles {
     my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row) = @_; 
     if (ref($resources) eq 'ARRAY') {
@@ -8495,11 +8530,18 @@
         return '';
     }
     my $map=$navmap->getResourceByUrl($sequence);
-    my $randomorder;
+    my ($randomorder, at master_seq,%symb_to_resource);
     if (ref($map)) { 
         $randomorder=$map->randomorder();
     }
     my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0);
+    foreach my $resource (@resources) {
+        if (ref($resource)) {
+            my $ressymb = $resource->symb();
+            push(@master_seq,$ressymb);
+            $symb_to_resource{$ressymb} = $resource;
+        }
+    }
     my (%grader_partids_by_symb,%grader_randomlists_by_symb);
     &graders_resources_pass(\@resources,\%grader_partids_by_symb,
                             \%grader_randomlists_by_symb,$bubbles_per_row);
@@ -8513,7 +8555,7 @@
 
     my $count=&Apache::grades::get_todo_count($scanlines,$scan_data);
     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count);
-    my ($username,$domain,$started);
+    my ($username,$domain,$started,%ordered);
     my $nav_error;
     &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse.
     if ($nav_error) {
@@ -8555,9 +8597,11 @@
         $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos);
         chomp($scandata{$pid});
         $scandata{$pid} =~ s/\r$//;
+        my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION];
+        my $user = $uname.':'.$usec;
         ($username,$domain)=split(/:/,$uname);
 
-        my ($scancode,%ordered);
+        my $scancode;
         if ((exists($scan_record->{'scantron.CODE'})) &&
             (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) {
             $scancode = $scan_record->{'scantron.CODE'};
@@ -8566,18 +8610,10 @@
         }
 
         my @mapresources = @resources;
-        if ($randomorder && $scancode) {
-            unless (ref($ordered{$scancode}) eq 'ARRAY') {
-                $env{'form.CODE'} = $scancode;
-                $ordered{$scancode} = 
-                    &Apache::lonprintout::master_seq_to_person_seq($sequence,
-                                                                   \@resources,
-                                                                   $uname,$scancode);
-                delete($env{'form.CODE'});
-            }
-            if (ref($ordered{$scancode}) eq 'ARRAY') {
-                @mapresources = @{$ordered{$scancode}};
-            }
+        if ($randomorder) {
+            @mapresources =
+                &users_order($user,$scancode,$sequence,\@master_seq,\%ordered,
+                             \%symb_to_resource);
         }
         my $counter = -1;
         foreach my $resource (@mapresources) {




More information about the LON-CAPA-cvs mailing list