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

sakharuk lon-capa-cvs@mail.lon-capa.org
Wed, 11 Feb 2004 21:10:45 -0000


sakharuk		Wed Feb 11 16:10:45 2004 EDT

  Modified files:              
    /loncom/homework/caparesponse	caparesponse.pm 
  Log:
  Algorithm for calculation the width of the cell for exam bubbles (tex output) is changed. I very want to have any responces from people used exams.
  
  
Index: loncom/homework/caparesponse/caparesponse.pm
diff -u loncom/homework/caparesponse/caparesponse.pm:1.127 loncom/homework/caparesponse/caparesponse.pm:1.128
--- loncom/homework/caparesponse/caparesponse.pm:1.127	Thu Feb  5 16:04:24 2004
+++ loncom/homework/caparesponse/caparesponse.pm	Wed Feb 11 16:10:45 2004
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # caparesponse definition
 #
-# $Id: caparesponse.pm,v 1.127 2004/02/05 21:04:24 albertel Exp $
+# $Id: caparesponse.pm,v 1.128 2004/02/11 21:10:45 sakharuk Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -254,18 +254,18 @@
 		}
 		if ($tag eq 'numericalresponse') {
 		    my ($celllength,$number_of_tables,@table_range)=
-			&get_table_sizes($formats[0],$number_of_bubbles);
+			&get_table_sizes($number_of_bubbles,\@bubble_values);
 		    my $j=0;
 		    my $cou=0;
 		    $result.='\vskip -1 mm \noindent \begin{enumerate}\item[\textbf{'.$Apache::lonxml::counter.'}.]';
 		    for (my $i=0;$i<$number_of_tables;$i++) {
 			$result.='\vskip -1 mm \noindent \begin{tabular}{';
 			for (my $ind=0;$ind<$table_range[$j];$ind++) {
-			    $result.='lp{'.$celllength.' mm}';
+			    $result.='p{3 mm}p{'.$celllength.' mm}';
 			}
 			$result.='}';
 			for (my $ind=$cou;$ind<$cou+$table_range[$j];$ind++) {
-			    $result.='\hskip -3 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$\hskip -2 mm & {\small '.$bubble_values[$ind].'} ';
+			    $result.='\hskip -4 mm {\small \textbf{'.$alphabet[$ind].'}}$\bigcirc$ & \hskip -3 mm {\small '.$bubble_values[$ind].'} ';
 			    if ($ind != $cou+$table_range[$j]-1) {$result.=' & ';}
 			}
 			$cou += $table_range[$j];
@@ -376,23 +376,33 @@
 }
 
 sub get_table_sizes {
-    my ($format,$number_of_bubbles)=@_;
-    my $max_val = 0;
-    if ($format=~m/^(\d+)E([^\d]*)(\d*)$/) {
-	$max_val=$1+$2+4;
-    } else {
-	$max_val=4;
+    my ($number_of_bubbles,$rbubble_values)=@_;
+    my $scale=2; #mm for one digit
+    my $cell_width=0;
+    foreach my $member (@$rbubble_values) {
+	my $cell_width_real=0;
+	if ($member=~/(\d*)\.?(\d*)(E|e)(\+|-)?(\d*)/) {
+	    $cell_width_real=(length($1)+length($2)+length($5)+9)*$scale;
+	} elsif ($member=~/(\d*)\.?(\d*)/) {
+	    $cell_width_real=(length($1)+length($2)+2)*$scale;
+	} else {
+	    $cell_width_real=(length($member)+1)*$scale;
+	}
+	if ($cell_width_real>$cell_width) {$cell_width=$cell_width_real;}
     }
-    $max_val = int(0.9*$ENV{'form.textwidth'}/(($max_val+6)*2));
-    my $celllength = 0.9*$ENV{'form.textwidth'}/$max_val-10;
+    $cell_width+=8;
+    $ENV{'form.textwidth'}=~/(\d+)/;
+    my $textwidth=$1;
+    my $bubbles_per_line=int($textwidth/$cell_width);
+    my $number_of_tables = int($number_of_bubbles/$bubbles_per_line);
     my @table_range = ();
-    my $number_of_tables = int($number_of_bubbles/$max_val);
-    for (my $i=0;$i<$number_of_tables;$i++) {push @table_range,$max_val;}
-    if ($number_of_bubbles % $max_val != 0) {
+    for (my $i=0;$i<$number_of_tables;$i++) {push @table_range,$bubbles_per_line;}
+    if ($number_of_bubbles % $bubbles_per_line) {
 	$number_of_tables++;
-	push @table_range,($number_of_bubbles % $max_val);
+	push @table_range,($number_of_bubbles % $bubbles_per_line);
     }
-    return ($celllength,$number_of_tables,@table_range);
+    $cell_width-=8;
+    return ($cell_width,$number_of_tables,@table_range);
 }
 
 sub format_number {