[LON-CAPA-cvs] cvs: modules /gerd/texas THconvert.pl
www
lon-capa-cvs@mail.lon-capa.org
Thu, 16 Nov 2006 14:46:30 -0000
www Thu Nov 16 09:46:30 2006 EDT
Modified files:
/modules/gerd/texas THconvert.pl
Log:
Dealing with tolerances (done) and with multiple choice (not finished)
Index: modules/gerd/texas/THconvert.pl
diff -u modules/gerd/texas/THconvert.pl:1.1 modules/gerd/texas/THconvert.pl:1.2
--- modules/gerd/texas/THconvert.pl:1.1 Wed Nov 15 17:09:54 2006
+++ modules/gerd/texas/THconvert.pl Thu Nov 16 09:46:29 2006
@@ -15,14 +15,17 @@
my %content=();
my $multipart=0;
my $keywords='';
+my $currentquestion;
+my %multiplechoice=();
foreach my $line (split(/\n/,$filecontent)) {
chomp($line);
- if ($line=~/^\s*quest\s+(\d+)/) {
+ if ($line=~/^[\%\s]*quest\s+(\d+)/) {
if ($current) { $content{$current}=$readsofar; }
$readsofar='';
$current='question_'.$1;
+ $currentquestion=$1;
if ($1>1) { $multipart=1; }
- } elsif ($line=~/^\s*expl\s+(\d+)/) {
+ } elsif ($line=~/^[\%\s]*expl\s+(\d+)/) {
if ($current) { $content{$current}=$readsofar; }
$readsofar='';
$current='explanation_'.$1;
@@ -30,10 +33,17 @@
if ($current) { $content{$current}=$readsofar; }
$readsofar='';
$current='script';
+ } elsif ($line=~/^\s*\\choice\s*\{([^\}]*)\}\{([^\}]*)\}\{([^\}]*)\}/) {
+ if ($current) { $content{$current}=$readsofar;
+ $current='';}
+ $readsofar='';
+ $content{'choice_'.$currentquestion.'_'.$2}=$3;
+ $multiplechoice{$currentquestion}=1;
} elsif ($line=~/^keywords\:(.*)$/) {
$keywords=$1;
$keywords=~s/\s*\%.*$//;
$keywords=~s/^\s*//;
+ $keywords=~s/\,\s+/\,/g;
$readsofar.=$line."\n";
} elsif ($line!~/^\s*\*/) {
$readsofar.=$line."\n";
@@ -52,7 +62,11 @@
} else {
# single part numerical
&question($content{'question_1'});
- &numericalresponse(1,%globals);
+ if ($multiplechoice{1}) {
+ &multiresponse(1,%globals);
+ } else {
+ &numericalresponse(1,%globals);
+ }
}
&answer($content{'explanation_1'});
}
@@ -66,9 +80,13 @@
$script=~s/\}\s*$//s;
foreach my $line (split(/[\n\;]/,$script)) {
unless ($line) { next; }
- if ($line=~/\s*\/\*\s*global\s* (?:double)*\s*(\w+)\s*u=\{*[^\}]*\}*\s/) {
+ if ($line=~/\s*\/\*\s*global\s* (?:double)*\s*(\w+)\s*u=\{*[^\}]*\}*\s+(tol=.+)*/) {
$line="&global('$1','$2')";
$globals{$1}=$2;
+ my $tol=$3;
+ if ($tol=~/\s*tol\s*=\s*(.*)$/) {
+ $globals{$1.'_tol'}=$1;
+ }
} else {
$line=~s/\=\((\w+)\)(.+)$/\=\&$1($2)/;
$line=~s/random\(/\&random_default\(/;
@@ -94,11 +112,21 @@
print ' unit="'.$unit.'"';
}
print ">\n";
- print '<responseparam type="tolerance" default="5%" name="tol" description="Numerical Tolerance" />'."\n";
+ my $tol='1%';
+ if ($globals{'ans'.$number.'_tol'}) {
+ $tol=$globals{'ans'.$number.'_tol'};
+ }
+ print '<responseparam type="tolerance" default="'.$tol.'" name="tol" description="Numerical Tolerance" />'."\n";
print '<responseparam name="sig" type="int_range,0-16" default="0,15" description="Significant Figures" />'."\n";
print "<textline />\n</numericalresponse>\n";
}
+sub multiresponse {
+ my ($number,%globals)=@_;
+ print '<radiobuttonresponse>';
+ print '</radiobuttonresponse>';
+}
+
sub answer {
print "\n<postanswerdate>\n";
&print_text(@_);