[LON-CAPA-cvs] cvs: loncom /publisher testbankimport.pm

raeburn lon-capa-cvs-allow@mail.lon-capa.org
Thu, 05 Jun 2008 01:25:00 -0000


This is a MIME encoded message

--raeburn1212629100
Content-Type: text/plain

raeburn		Wed Jun  4 21:25:00 2008 EDT

  Modified files:              
    /loncom/publisher	testbankimport.pm 
  Log:
  - Stop processing of testbanks containing ranking/ordering question types causing an ISE.
  - Also, ranking/ordering testbank questions may now contain multiple foils with the same rank (identified in the answers with an equals sign - e.g., (b),(e)=(a),(d),(c) ).
  
  
--raeburn1212629100
Content-Type: text/plain
Content-Disposition: attachment; filename="raeburn-20080604212500.txt"

Index: loncom/publisher/testbankimport.pm
diff -u loncom/publisher/testbankimport.pm:1.13 loncom/publisher/testbankimport.pm:1.14
--- loncom/publisher/testbankimport.pm:1.13	Thu Apr 17 11:58:45 2008
+++ loncom/publisher/testbankimport.pm	Wed Jun  4 21:24:59 2008
@@ -1,5 +1,5 @@
 # Handler for parsing text upload problem descriptions into .problems
-# $Id: testbankimport.pm,v 1.13 2008/04/17 15:58:45 raeburn Exp $
+# $Id: testbankimport.pm,v 1.14 2008/06/05 01:24:59 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -456,8 +456,8 @@
          <li>All questions (including question text and all foils) must occur before any of the answers.  Each question should begin on a new line, and should start with the question number. Questions should be numbered sequentially using a number followed immediately by a space, a period, or enclosed in parentheses, i.e., 1 , 1., (1), 1), or (1 .</li>
          <li><i>Multiple choice</i> and <i>multiple answer correct</i> questions should consist of: (i) the question number followed by (ii) the question text beginning on the same line and (iii) two or more foils, with each foil beginning on a new line and prefixed by a unique letter, or Roman numeral, listed in alphabetic or numeric order, beginning at a (alphabetic) or i (Roman numeral), followed by a period, or enclosed in parentheses, i.e., a., (a), i., or (i).</li>
          <li>One or more correct answers should be provided for all questions (although blank answers may be provided for <i>essay</i> questions).  Answers should be numbered sequentially, using the same scheme as used for the questions, and must occur after <b>all</b> the questions.        
-         <li>If <i>fill-in-the-blank</i> or <i>multiple answer</i> questions have more than one correct answer, each answer should appear in a comma-, tab-, space-, or new line-delimited list. For a <i>ranking/ordering</i> question, the "answer" should contain the foil identifiers correctly ordered in a similarly delimited list.</li> 
-        </ol>      
+         <li>If <i>fill-in-the-blank</i> or <i>multiple answer</i> questions have more than one correct answer, each answer should appear in a comma-, tab-, space-, or new line-delimited list. For a <i>ranking/ordering</i> question, the "answer" should contain the foil identifiers correctly ordered in a similarly delimited list. If two or more foils have the same ranking, they should occur together, with an equals sign separating equally ranked foils [e.g., (b),(e)=(a),(d),(c)].</li> 
+        </ol>
 Five steps are involved in the import process.
         <ol>
          <li>Upload your text file to the server.|);
@@ -1188,19 +1188,58 @@
                         $items[$k] =~ tr/A-Z/a-z/;
                         my @corrects = split/$patterns{$ansrtypes[$i]}/,$items[$k];
                         foreach my $correct (@corrects) {
-                            $correct =~s/\W//g;
+                            my @tied;
+                            if ($qtype[$i] eq "Ord") {
+                                if ($correct =~ /=/) {
+                                    @tied = split(/=/,$correct);
+                                    for (my $j=0; $j<@tied; $j++) {
+                                        $tied[$j] =~ s/\W//g;
+                                    }
+                                } else {
+                                    $correct =~s/\W//g;
+                                }
+                            } else {
+                                $correct =~s/\W//g;
+                            }
                             if ($foilformats[$i] eq "lcperiod" || $foilformats[$i] eq "lcparen" || $foilformats[$i] eq "ucparen" || $foilformats[$i] eq "ucperiod") {
-                                for (my $j=0; $j<@alphabet; $j++) {
-                                    if ($alphabet[$j] eq $correct) {
-                                        push @{$answers{$k}}, $j;
-                                        last;
+                                if (($qtype[$i] eq "Ord") && (@tied > 0)) { 
+                                    my @ties;
+                                    foreach my $tie (@tied) {
+                                        for (my $j=0; $j<@alphabet; $j++) {
+                                            if ($alphabet[$j] eq $tie) {
+                                                push(@ties,$j);
+                                                last;
+                                            }
+                                        }
+                                    }
+                                    my $ans = join('=',@ties);
+                                    push(@{$answers{$k}},$ans);
+                                } else {
+                                    for (my $j=0; $j<@alphabet; $j++) {
+                                        if ($alphabet[$j] eq $correct) {
+                                            push @{$answers{$k}}, $j;
+                                            last;
+                                        }
                                     }
                                 }
                             } elsif (($foilformats[$i] eq "romparen") || ($foilformats[$i] eq "romperiod") || ($foilformats[$i] eq "romoneparen") || ($foilformats[$i] eq "romdotparen")) {
-                                for (my $j=0; $j<@romans; $j++) {
-                                    if ($romans[$j] eq $correct) {
-                                        push @{$answers{$k}}, $j;
-                                        last;
+                                if (($qtype[$i] eq "Ord") && (@tied > 0)) {
+                                    my @ties;
+                                    foreach my $tie (@tied) {
+                                        for (my $j=0; $j<@romans; $j++) {
+                                            if ($romans[$j] eq $tie) {
+                                                push(@ties,$j);
+                                                last;
+                                            }
+                                        }
+                                    }
+                                    push(@{$answers{$k}},join('=',@ties));
+                                } else {
+                                    for (my $j=0; $j<@romans; $j++) {
+                                        if ($romans[$j] eq $correct) {
+                                            push @{$answers{$k}}, $j;
+                                            last;
+                                        }
                                     }
                                 }
                             }
@@ -1451,7 +1490,7 @@
     my %multparts = ();
     for (my $i=0; $i<$blocks; $i++) {
         if (${$numsref}[$i] > 0) {
-            if ((${$qtyperef}[$i] eq "MC") || (${$qtyperef}[$i] eq "MA")) {
+            if ((${$qtyperef}[$i] eq "MC") || (${$qtyperef}[$i] eq "MA") || (${$qtyperef}[$i] eq "Ord")) {
                 my $splitstr = '';
                 if (${$foilsref}[$i] eq "lcperiod") {
                     $splitstr = '[a-z]\.';
@@ -1568,7 +1607,26 @@
     <foilgroup>
         |;
         for (my $k=0; $k<@{$qstnref}-1; $k++) {
-            $output .= "   <foil location=\"random\" name=\"foil".$k."\" value=\"".$$answerref[$k]."\><startouttext />".${$qstnref}[$k+1]."<endouttext /></foil>\n";
+            my $ansval;
+            my $num = 0;
+            for (my $i=0; $i<@{$answerref}; $i++) {
+                if ($$answerref[$i] =~ /=/) {
+                    my @tied = split(/=/,$$answerref[$i]);
+                    foreach my $tie (@tied) {
+                        if ($k == $tie) {
+                            $ansval = $num + 1;
+                            last;
+                        }
+                    }
+                    $num += scalar(@tied);
+                } elsif ($k == $$answerref[$i]) {
+                    $ansval = $num + 1;
+                    last;
+                } else {
+                    $num ++;
+                }
+            }
+            $output .= "   <foil location=\"random\" name=\"foil".$k."\" value=\"".$ansval."\"><startouttext />".${$qstnref}[$k+1]."<endouttext /></foil>\n";
         }
         chomp($output);
         $output .= qq|

--raeburn1212629100--