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

raeburn raeburn at source.lon-capa.org
Sun Jan 27 18:16:36 EST 2019


raeburn		Sun Jan 27 23:16:36 2019 EDT

  Modified files:              
    /loncom/homework	grades.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  - Uploaded bubblesheet data can consist of comma separated values.
    - Set each value in each question field to correct length, and appropriate
      value, either letter A-J, or number 1-9 then 0, or '    1      ', as 
      determined by selected data format. 
  
  
-------------- next part --------------
Index: loncom/homework/grades.pm
diff -u loncom/homework/grades.pm:1.754 loncom/homework/grades.pm:1.755
--- loncom/homework/grades.pm:1.754	Sun Jan 27 14:39:55 2019
+++ loncom/homework/grades.pm	Sun Jan 27 23:16:25 2019
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # The LON-CAPA Grading handler
 #
-# $Id: grades.pm,v 1.754 2019/01/27 14:39:55 raeburn Exp $
+# $Id: grades.pm,v 1.755 2019/01/27 23:16:25 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -8684,7 +8684,7 @@
 	return '';		# Dunno why the other returns return '' rather than just returning.
     }
 
-    my %lettdig = &letter_to_digits();
+    my %lettdig = &Apache::lonnet::letter_to_digits();
     my $numletts = scalar(keys(%lettdig));
     my %orderedforcode;
 
@@ -9396,7 +9396,7 @@
     my ($r,$symb) = @_;
     if (!$symb) {return '';}
     my $cid = $env{'request.course.id'};
-    my %lettdig = &letter_to_digits();
+    my %lettdig = &Apache::lonnet::letter_to_digits();
     my $numletts = scalar(keys(%lettdig));
     my $cnum = $env{'course.'.$cid.'.num'};
     my $cdom = $env{'course.'.$cid.'.domain'};
@@ -9727,22 +9727,6 @@
     return ($counter,$record);
 }
 
-sub letter_to_digits {
-    my %lettdig = (
-                    A => 1,
-                    B => 2,
-                    C => 3,
-                    D => 4,
-                    E => 5,
-                    F => 6,
-                    G => 7,
-                    H => 8,
-                    I => 9,
-                    J => 0,
-                  );
-    return %lettdig;
-}
-
 
 #-------- end of section for handling grading scantron forms -------
 #
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1402 loncom/lonnet/perl/lonnet.pm:1.1403
--- loncom/lonnet/perl/lonnet.pm:1.1402	Sun Jan 27 16:02:58 2019
+++ loncom/lonnet/perl/lonnet.pm	Sun Jan 27 23:16:36 2019
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1402 2019/01/27 16:02:58 raeburn Exp $
+# $Id: lonnet.pm,v 1.1403 2019/01/27 23:16:36 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -4359,7 +4359,7 @@
 sub bubblesheet_converter {
     my ($cdom,$fullpath,$config,$format) = @_;
     if ((&domain($cdom) ne '') &&
-        ($fullpath =~ m{^\Q$perlvar{'lonDocRoot'}/userfiles/$cdom/$match_courseid/scantron_orig}) &&
+        ($fullpath =~ m{^\Q$perlvar{'lonDocRoot'}/userfiles/$cdom/\E$match_courseid/scantron_orig}) &&
         (-e $fullpath) && (ref($config) eq 'HASH') && ($format ne '')) {
         my %csvcols = %{$config};
         my %csvbynum = reverse(%csvcols);
@@ -4375,7 +4375,7 @@
                         );
             my @ordered;
             foreach my $item (sort { $a <=> $b } keys(%bynum)) {
-                push (@ordered,$bynum{$item}));
+                push(@ordered,$bynum{$item});
             }
             my %mapstart = (
                               CODEstart => 'CODE',
@@ -4394,23 +4394,70 @@
             );
             if (open(my $fh,'<',$fullpath)) {
                 my $output;
+                my %lettdig = &letter_to_digits();
+                my %diglett = reverse(%lettdig);
+                my $numletts = scalar(keys(%lettdig));
                 while (my $line=<$fh>) {
                     $line =~ s{[\r\n]+$}{};
                     my %found;
                     my @values = split(/,/,$line);
                     my ($qstart,$record);
                     for (my $i=0; $i<@values; $i++) {
-                        if (($qstart ne '') && ($i > $qstart)) {
-                            $found{'FirstQuestion'} .= $values[$i];
-                        } elsif (exists($csvbynum{$i})) {
+                        if ((($qstart ne '') && ($i > $qstart)) ||
+                            ($csvbynum{$i} eq 'FirstQuestion')) {
+                            if ($values[$i] eq '') {
+                                $values[$i] = $scantronconf{'Qoff'};
+                            } elsif ($scantronconf{'Qon'} eq 'number') {
+                                if ($values[$i] =~ /^[A-Ja-j]$/) {
+                                    $values[$i] = $lettdig{uc($values[$i])};
+                                }
+                            } elsif ($scantronconf{'Qon'} eq 'letter') {
+                                if ($values[$i] =~ /^[0-9]$/) {
+                                    $values[$i] = $diglett{$values[$i]};
+                                }
+                            } else {
+                                if ($values[$i] =~ /^[0-9A-Ja-j]$/) {
+                                    my $digit;
+                                    if ($values[$i] =~ /^[A-Ja-j]$/) {
+                                        $digit = $lettdig{uc($values[$i])}-1;
+                                        if ($values[$i] eq 'J') {
+                                            $digit += $numletts;
+                                        }
+                                    } elsif ($values[$i] =~ /^[0-9]$/) {
+                                        $digit = $values[$i]-1;
+                                        if ($values[$i] eq '0') {
+                                            $digit += $numletts;
+                                        }
+                                    }
+                                    my $qval='';
+                                    for (my $j=0; $j<$scantronconf{'Qlength'}; $j++) {
+                                        if ($j == $digit) {
+                                            $qval .= $scantronconf{'Qon'};
+                                        } else {
+                                            $qval .= $scantronconf{'Qoff'};
+                                        }
+                                    }
+                                    $values[$i] = $qval;
+                                }
+                            }
+                            if (length($values[$i]) > $scantronconf{'Qlength'}) {
+                                $values[$i] = substr($values[$i],0,$scantronconf{'Qlength'});
+                            }
+                            my $numblank = $scantronconf{'Qlength'} - length($values[$i]);
+                            if ($numblank > 0) {
+                                 $values[$i] .= ($scantronconf{'Qoff'} x $numblank);
+                            }
                             if ($csvbynum{$i} eq 'FirstQuestion') {
                                 $qstart = $i;
+                                $found{$csvbynum{$i}} = $values[$i];
                             } else {
-                                $values[$i] =~ s/^\s+//;
-                                if ($csvbynum{$i} eq 'PaperID') {
-                                    while (length($values[$i]) < $scantronconf{$maplength{$csvbynum{$i}}}) {
-                                        $values[$i] = '0'.$values[$i];
-                                    }
+                                $found{'FirstQuestion'} .= $values[$i];
+                            }
+                        } elsif (exists($csvbynum{$i})) {
+                            $values[$i] =~ s/^\s+//;
+                            if ($csvbynum{$i} eq 'PaperID') {
+                                while (length($values[$i]) < $scantronconf{$maplength{$csvbynum{$i}}}) {
+                                    $values[$i] = '0'.$values[$i];
                                 }
                             }
                             $found{$csvbynum{$i}} = $values[$i];
@@ -4446,6 +4493,22 @@
     }
 }
 
+sub letter_to_digits {
+    my %lettdig = (
+                    A => 1,
+                    B => 2,
+                    C => 3,
+                    D => 4,
+                    E => 5,
+                    F => 6,
+                    G => 7,
+                    H => 8,
+                    I => 9,
+                    J => 0,
+                  );
+    return %lettdig;
+}
+
 sub get_scantron_config {
     my ($which,$cdom) = @_;
     my @lines = &get_scantronformat_file($cdom);
@@ -4511,7 +4574,7 @@
             if (open(my $fh,'<',$perlvar{'lonTabDir'}.'/scantronformat.tab')) {
                 @lines = <$fh>;
                 close($fh);
-            }  
+            }
         } else {
             if (open(my $fh,'<',$perlvar{'lonTabDir'}.'/default_scantronformat.tab')) {
                 @lines = <$fh>;


More information about the LON-CAPA-cvs mailing list