--- loncom/homework/inputtags.pm 2007/03/13 00:21:28 1.218 +++ loncom/homework/inputtags.pm 2007/03/15 02:52:16 1.219 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # input definitons # -# $Id: inputtags.pm,v 1.218 2007/03/13 00:21:28 albertel Exp $ +# $Id: inputtags.pm,v 1.219 2007/03/15 02:52:16 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -957,6 +957,42 @@ sub setgradedata { } } +sub find_which_previous { + my ($version) = @_; + my $part = $Apache::inputtags::part; + my (@previous_version); + foreach my $resp (@Apache::inputtags::response) { + my $key = "$version:resource.$part.$resp.submission"; + my $submission = $Apache::lonhomework::history{$key}; + my %previous = &Apache::response::check_for_previous($submission, + $part,$resp, + $version); + push(@previous_version,$previous{'version'}); + } + return &previous_match(\@previous_version, + scalar(@Apache::inputtags::response)); +} + +sub previous_match { + my ($previous_array,$count) = @_; + my $match = 0; + my @matches; + foreach my $versionar (@$previous_array) { + foreach my $version (@$versionar) { + $matches[$version]++; + } + } + my $which=0; + foreach my $elem (@matches) { + if ($elem eq $count) { + $match=1; + last; + } + $which++; + } + return ($match,$which); +} + sub grade { my ($target) = @_; my $id = $Apache::inputtags::part; @@ -975,14 +1011,10 @@ sub grade { my ($finalaward,$msg) = &finalizeawards(\@awards,\@msgs); my $previously_used; if ( $#Apache::inputtags::previous eq $#awards ) { - my $match=0; - my @matches; - foreach my $versionar (@Apache::inputtags::previous_version) { - foreach my $version (@$versionar) { - $matches[$version]++; - } - } - foreach my $elem (@matches) {if ($elem eq ($#awards+1)) {$match=1;}} + my ($match) = + &previous_match(\@Apache::inputtags::previous_version, + scalar(@Apache::inputtags::response)); + if ($match) { $previously_used = 'PREVIOUSLY_LAST'; foreach my $value (@Apache::inputtags::previous) { @@ -1121,11 +1153,17 @@ sub previous_tries { my ($id,$target) = @_; my $output; my $status = $Apache::inputtags::status['-1']; - + + my $count; + my %count_lookup; + foreach my $i (1..$Apache::lonhomework::history{'version'}) { my $prefix = $i.":resource.$id"; next if (!exists($Apache::lonhomework::history{"$prefix.award"})); + $count++; + $count_lookup{$i} = $count; + my ($previousmsg,$latemessage,$message,$trystr); ($previousmsg,$latemessage,$message,$trystr) = @@ -1134,11 +1172,21 @@ sub previous_tries { undef($trystr); } - if ($previousmsg eq '') { $previousmsg='
'.join("\n",@Apache::inputtags::previous_version).''; #return $output; $output=~s/\\/\\\\/g; $output=~s/\'/\\\'/g;