[LON-CAPA-cvs] cvs: loncom /homework matchresponse.pm optionresponse.pm rankresponse.pm response.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Fri, 16 May 2003 20:16:18 -0000
This is a MIME encoded message
--albertel1053116178
Content-Type: text/plain
albertel Fri May 16 16:16:18 2003 EDT
Modified files:
/loncom/homework rankresponse.pm optionresponse.pm matchresponse.pm
response.pm
Log:
- consolidates the whichfoil functions and fixes BUG#1439
--albertel1053116178
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20030516161618.txt"
Index: loncom/homework/rankresponse.pm
diff -u loncom/homework/rankresponse.pm:1.12 loncom/homework/rankresponse.pm:1.13
--- loncom/homework/rankresponse.pm:1.12 Wed Apr 2 15:23:52 2003
+++ loncom/homework/rankresponse.pm Fri May 16 16:16:18 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# rank style response
#
-# $Id: rankresponse.pm,v 1.12 2003/04/02 20:23:52 sakharuk Exp $
+# $Id: rankresponse.pm,v 1.13 2003/05/16 20:16:18 albertel Exp $
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
@@ -308,52 +308,9 @@
sub whichfoils {
my ($max,$randomize)=@_;
- $max = &getfoilcounts($max);
- # &Apache::lonxml::debug("man $max randomize $randomize");
- if (!defined(@{ $Apache::response::foilgroup{'names'} })) { return; }
- my @names = @{ $Apache::response::foilgroup{'names'} };
- my @whichopt =();
- my (%top,@toplist,%bottom,@bottomlist);
- if (!(&Apache::response::showallfoils() || ($randomize eq 'no'))) {
- my $current=0;
- foreach my $name (@names) {
- $current++;
- if ($Apache::response::foilgroup{"$name.location"} eq 'top') {
- $top{$name}=$current;
- } elsif ($Apache::response::foilgroup{"$name.location"} eq
- 'bottom') {
- $bottom{$name}=$current;
- }
- }
- }
- while ((($#whichopt+1) < $max) && ($#names > -1)) {
-# &Apache::lonxml::debug("Have $#whichopt max is $max");
- my $aopt;
- if (&Apache::response::showallfoils() || ($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;
- } elsif ($bottom{$aopt}) {
- $bottomlist[$bottom{$aopt}]=$aopt;
- } else {
- push (@whichopt,$aopt);
- }
- }
-# &Apache::lonxml::debug("Grr, ".$#whichopt.":".$#toplist.':'.$#bottomlist);
- 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]) }
- }
- &Apache::lonxml::debug("Grr, ".$#whichopt.":".$#toplist.':'.$#bottomlist);
- return @whichopt;
+ return &Apache::response::whichorder($max,$randomize,
+ &Apache::response::showallfoils(),
+ \%Apache::response::foilgroup);
}
sub start_conceptgroup {
Index: loncom/homework/optionresponse.pm
diff -u loncom/homework/optionresponse.pm:1.76 loncom/homework/optionresponse.pm:1.77
--- loncom/homework/optionresponse.pm:1.76 Thu Apr 24 11:49:46 2003
+++ loncom/homework/optionresponse.pm Fri May 16 16:16:18 2003
@@ -1,7 +1,7 @@
# LearningOnline Network with CAPA
# option list style responses
#
-# $Id: optionresponse.pm,v 1.76 2003/04/24 15:49:46 albertel Exp $
+# $Id: optionresponse.pm,v 1.77 2003/05/16 20:16:18 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -265,52 +265,10 @@
}
sub whichfoils {
- my ($max,$randomize)=@_;
- $max = &getfoilcounts($max);
- &Apache::lonxml::debug("randomize $randomize");
- if (!defined(@{ $Apache::response::foilgroup{'names'} })) {return;}
- my @names = @{ $Apache::response::foilgroup{'names'} };
- my @whichopt =();
- my (%top,@toplist,%bottom,@bottomlist);
- if (!(&Apache::response::showallfoils() || ($randomize eq 'no'))) {
- my $current=0;
- foreach my $name (@names) {
- $current++;
- if ($Apache::response::foilgroup{$name.'.location'} eq 'top') {
- $top{$name}=$current;
- } elsif ($Apache::response::foilgroup{$name.'.location'} eq
- 'bottom') {
- $bottom{$name}=$current;
- }
- }
- }
- while ((($#whichopt+1) < $max) && ($#names > -1)) {
- &Apache::lonxml::debug("Have $#whichopt max is $max");
- my $aopt;
- if (&Apache::response::showallfoils() || ($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;
- } elsif ($bottom{$aopt}) {
- $bottomlist[$bottom{$aopt}]=$aopt;
- } 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;
+ my ($max,$randomize)=@_;
+ return &Apache::response::whichorder($max,$randomize,
+ &Apache::response::showallfoils(),
+ \%Apache::response::foilgroup);
}
sub displayanswers {
Index: loncom/homework/matchresponse.pm
diff -u loncom/homework/matchresponse.pm:1.17 loncom/homework/matchresponse.pm:1.18
--- loncom/homework/matchresponse.pm:1.17 Tue May 6 18:08:28 2003
+++ loncom/homework/matchresponse.pm Fri May 16 16:16:18 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Full matching style response
#
-# $Id: matchresponse.pm,v 1.17 2003/05/06 22:08:28 albertel Exp $
+# $Id: matchresponse.pm,v 1.18 2003/05/16 20:16:18 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -118,8 +118,8 @@
my @names=@{ $Apache::response::itemgroup{'names'} };
my $randomize =&Apache::lonxml::get_param('randomize',$parstack,$safeeval);
if ($randomize ne 'no' ) {
- @names=&whichorder($#names+1,$randomize,0,
- \%Apache::response::itemgroup)
+ @names=&Apache::response::whichorder($#names+1,$randomize,0,
+ \%Apache::response::itemgroup);
}
my %letter_name_map;
my %name_letter_map;
@@ -258,9 +258,10 @@
my ($max,$randomize,@opt)=@_;
if (!defined(@{ $Apache::response::foilgroup{'names'} })) { return; }
my @names = @{ $Apache::response::foilgroup{'names'} };
- my @whichfoils = &whichorder(&getfoilcounts($max),$randomize,
- &Apache::response::showallfoils(),
- \%Apache::response::foilgroup);
+ my @whichfoils = &Apache::response::whichorder(&getfoilcounts($max),
+ $randomize,
+ &Apache::response::showallfoils(),
+ \%Apache::response::foilgroup);
my $result=&Apache::response::answer_header('matchresponse');
my %name_letter_map;
if (defined(%{ $Apache::response::itemgroup{'name_letter_map'} })) {
@@ -279,9 +280,10 @@
sub grade_response {
my ($max,$randomize)=@_;
- my (@whichfoils)=&whichorder(&getfoilcounts($max),$randomize,
- &Apache::response::showallfoils(),
- \%Apache::response::foilgroup);
+ my (@whichfoils)=&Apache::response::whichorder(&getfoilcounts($max),
+ $randomize,
+ &Apache::response::showallfoils(),
+ \%Apache::response::foilgroup);
if (!defined($ENV{'form.submitted'})) { return; }
my %responsehash;
my %grade;
@@ -350,9 +352,10 @@
my ($target,$max,$randomize)=@_;
my $result;
my $question;
- my (@whichfoils)=&whichorder(&getfoilcounts($max),$randomize,
- &Apache::response::showallfoils(),
- \%Apache::response::foilgroup);
+ my (@whichfoils)=&Apache::response::whichorder(&getfoilcounts($max),
+ $randomize,
+ &Apache::response::showallfoils(),
+ \%Apache::response::foilgroup);
my $part=$Apache::inputtags::part;
my $solved=$Apache::lonhomework::history{"resource.$part.solved"};
my $status=$Apache::inputtags::status[-1];
@@ -454,52 +457,6 @@
return $count;
}
-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;
- }
- }
- }
- while ((($#whichopt+1) < $max) && ($#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;
- } elsif ($bottom{$aopt}) {
- $bottomlist[$bottom{$aopt}]=$aopt;
- } 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;
-}
sub start_conceptgroup {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval,$style)=@_;
Index: loncom/homework/response.pm
diff -u loncom/homework/response.pm:1.77 loncom/homework/response.pm:1.78
--- loncom/homework/response.pm:1.77 Wed May 14 09:33:00 2003
+++ loncom/homework/response.pm Fri May 16 16:16:18 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# various response type definitons response definition
#
-# $Id: response.pm,v 1.77 2003/05/14 13:33:00 albertel Exp $
+# $Id: response.pm,v 1.78 2003/05/16 20:16:18 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -467,6 +467,58 @@
$Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=
'ASSIGNED_SCORE';
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;
--albertel1053116178--