--- loncom/homework/response.pm 2003/04/30 21:19:13 1.73 +++ loncom/homework/response.pm 2003/05/16 20:16:18 1.78 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # various response type definitons response definition # -# $Id: response.pm,v 1.73 2003/04/30 21:19:13 albertel Exp $ +# $Id: response.pm,v 1.78 2003/05/16 20:16:18 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -83,18 +83,23 @@ sub setrandomnumber { $rndseed=$ENV{'form.rndseed'}; if (!$rndseed) { $rndseed=time; } } else { - my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); - $rndseed=&Apache::lonnet::rndseed($symb,$courseid,$domain,$name); + $rndseed=&Apache::lonnet::rndseed(); } &Apache::lonxml::debug("randseed $rndseed"); # $rndseed=unpack("%32i",$rndseed); - $rndseed=$rndseed - +(&Apache::lonnet::numval($Apache::inputtags::part) << 10); + my $rndmod=(&Apache::lonnet::numval($Apache::inputtags::part) << 10); if (defined($Apache::inputtags::response['-1'])) { - $rndseed=$rndseed - +&Apache::lonnet::numval($Apache::inputtags::response['-1']); + $rndmod+=&Apache::lonnet::numval($Apache::inputtags::response[-1]); } - &Math::Random::random_set_seed_from_phrase($rndseed); + if ($rndseed =~/,/) { + my ($num1,$num2)=split(/,/,$rndseed); + $num1+=$rndmod; + $num2+=$rndmod; + $rndseed="$num1,$num2"; + } else { + $rndseed+=$rndmod; + } + &Apache::lonnet::setup_random_from_rndseed($rndseed); &Apache::lonxml::debug("randseed $rndseed"); return ''; } @@ -358,12 +363,17 @@ sub setup_params { sub answer_header { my ($type) = @_; my $result; - if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse' ) { - $result = ''."\n"; + if ($ENV{'form.answer_output_mode'} eq 'tex') { + $result = ' \vskip 0 mm \begin{tabular}{|c|}\hline Answer for Part: '. + $Apache::inputtags::part.' \\\\ \hline '; } else { - $result = '
Answer for Part:'. - $Apache::inputtags::part. '
'."\n"; + if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse' ) { + $result = '
Answer for Part:'. - $Apache::inputtags::part. '
'."\n"; + } else { + $result = '
Answer for Part:'. + $Apache::inputtags::part. '
'."\n"; + } } return $result; } @@ -371,10 +381,14 @@ sub answer_header { sub answer_part { my ($type,$answer) = @_; my $result; - if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') { - $result = ''; + if ($ENV{'form.answer_output_mode'} eq 'tex') { + $result = ' '.$answer.'\\\\ \hline '; } else { - $result = ''; + if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') { + $result = ''; + } else { + $result = ''; + } } return $result; } @@ -382,10 +396,14 @@ sub answer_part { sub answer_footer { my ($type) = @_; my $result; - if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') { - $result = '
Answer for Part:'. + $Apache::inputtags::part. ''.$answer.''.$answer.''.$answer.''.$answer.'
'; + if ($ENV{'form.answer_output_mode'} eq 'tex') { + $result = ' \end{tabular} \vskip 0 mm '; } else { - $result = ''; + if ($type eq 'optionresponse' || $type eq 'radiobuttonresponse') { + $result = ''; + } else { + $result = ''; + } } return $result; } @@ -451,6 +469,58 @@ sub scored_response { return $repetition; } +sub whichorder { + my ($max,$randomize,$showall,$hash)=@_; + #&Apache::lonxml::debug("man $max randomize $randomize"); + if (!defined(@{ $$hash{'names'} })) { return; } + my @names = @{ $$hash{'names'} }; + my @whichopt =(); + my (%top,@toplist,%bottom,@bottomlist); + if (!($showall || ($randomize eq 'no'))) { + my $current=0; + foreach my $name (@names) { + $current++; + if ($$hash{"$name.location"} eq 'top') { + $top{$name}=$current; + } elsif ($$hash{"$name.location"} eq 'bottom') { + $bottom{$name}=$current; + } + } + } + my $topcount=0; + my $bottomcount=0; + while (((scalar(@whichopt)+$topcount+$bottomcount) < $max || $showall) + && ($#names > -1)) { + #&Apache::lonxml::debug("Have $#whichopt max is $max"); + my $aopt; + if ($showall || ($randomize eq 'no')) { + $aopt=0; + } else { + $aopt=int(&Math::Random::random_uniform() * ($#names+1)); + } + #&Apache::lonxml::debug("From $#whichopt $max $#names elms, picking $aopt"); + $aopt=splice(@names,$aopt,1); + #&Apache::lonxml::debug("Picked $aopt"); + if ($top{$aopt}) { + $toplist[$top{$aopt}]=$aopt; + $topcount++; + } elsif ($bottom{$aopt}) { + $bottomlist[$bottom{$aopt}]=$aopt; + $bottomcount++; + } else { + push (@whichopt,$aopt); + } + } + for (my $i=0;$i<=$#toplist;$i++) { + if ($toplist[$i]) { unshift(@whichopt,$toplist[$i]) } + } + for (my $i=0;$i<=$#bottomlist;$i++) { + if ($bottomlist[$i]) { push(@whichopt,$bottomlist[$i]) } + } + + return @whichopt; +} + 1; __END__