[LON-CAPA-cvs] cvs: modules /gerd/texas THconvert.pl texas.library
www
lon-capa-cvs@mail.lon-capa.org
Thu, 16 Nov 2006 16:27:40 -0000
www Thu Nov 16 11:27:40 2006 EDT
Modified files:
/modules/gerd/texas THconvert.pl texas.library
Log:
Now does the Hello World multiple choices
Index: modules/gerd/texas/THconvert.pl
diff -u modules/gerd/texas/THconvert.pl:1.2 modules/gerd/texas/THconvert.pl:1.3
--- modules/gerd/texas/THconvert.pl:1.2 Thu Nov 16 09:46:29 2006
+++ modules/gerd/texas/THconvert.pl Thu Nov 16 11:27:36 2006
@@ -17,6 +17,7 @@
my $keywords='';
my $currentquestion;
my %multiplechoice=();
+my $multiflag=0;
foreach my $line (split(/\n/,$filecontent)) {
chomp($line);
if ($line=~/^[\%\s]*quest\s+(\d+)/) {
@@ -39,6 +40,7 @@
$readsofar='';
$content{'choice_'.$currentquestion.'_'.$2}=$3;
$multiplechoice{$currentquestion}=1;
+ $multiflag=1;
} elsif ($line=~/^keywords\:(.*)$/) {
$keywords=$1;
$keywords=~s/\s*\%.*$//;
@@ -54,7 +56,7 @@
# Start problem output
print("<problem>\n<import>texas.library</import>\n");
print("<meta name='keywords' content='".$keywords."' />\n");
-my %globals=&generate_script($content{'script'});
+my %globals=&generate_script($content{'script'},$multiflag);
if ($multipart) {
} else {
if ($content{'question_1'}=~/\\choice\{/s) {
@@ -63,7 +65,7 @@
# single part numerical
&question($content{'question_1'});
if ($multiplechoice{1}) {
- &multiresponse(1,%globals);
+ &multiresponse(1,%content);
} else {
&numericalresponse(1,%globals);
}
@@ -74,7 +76,7 @@
sub generate_script {
- my ($script)=@_;
+ my ($script,$multiplechoice)=@_;
my %globals=();
print "\n".'<script type="loncapa/perl">'."\n";
$script=~s/\}\s*$//s;
@@ -96,6 +98,7 @@
}
print $line.";\n";
}
+ if ($multiplechoice) { print '&generate_truth_values();' }
print"</script>\n";
return (%globals);
}
@@ -122,9 +125,16 @@
}
sub multiresponse {
- my ($number,%globals)=@_;
- print '<radiobuttonresponse>';
- print '</radiobuttonresponse>';
+ my ($number,%content)=@_;
+ print '<radiobuttonresponse><foilgroup>';
+ for (my $n=1; $n<=99; $n++) {
+ if ($content{'choice_'.$number.'_'.$n}) {
+ print "\n".'<foil value="$truth_value{'.$number.'0'.$n.'}" name="foil'.$number.'0'.$n.'">';
+ &print_text($content{'choice_'.$number.'_'.$n});
+ print "</foil>";
+ }
+ }
+ print '</foilgroup></radiobuttonresponse>';
}
sub answer {
Index: modules/gerd/texas/texas.library
diff -u modules/gerd/texas/texas.library:1.1 modules/gerd/texas/texas.library:1.2
--- modules/gerd/texas/texas.library:1.1 Wed Nov 15 17:09:54 2006
+++ modules/gerd/texas/texas.library Thu Nov 16 11:27:36 2006
@@ -9,5 +9,15 @@
sub random_default {
return &random(@_);
}
+
+sub generate_truth_values {
+ for (my $question=0; $question<=99; $question++) {
+ my $value;
+ eval('$value=$ans'.$question.';');
+ for (my $foil=0; $foil<=99; $foil++) {
+ if ($value==$foil) { $truth_value{$question.'0'.$foil}='true'; } else {$truth_value{$question.'0'.$foil}='false'; }
+ }
+ }
+}
</script>
</library>