--- loncom/homework/structuretags.pm 2005/04/18 21:10:41 1.285 +++ loncom/homework/structuretags.pm 2005/04/22 17:15:33 1.289 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: structuretags.pm,v 1.285 2005/04/18 21:10:41 raeburn Exp $ +# $Id: structuretags.pm,v 1.289 2005/04/22 17:15:33 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -321,8 +321,7 @@ sub initialize_storage { # if running user has student role. sub finalize_storage { my $result; - my ($temp) = keys %Apache::lonhomework::results; - if ( $temp ne '' ) { + if (%Apache::lonhomework::results) { my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser(); if ($env{'request.state'} eq 'construct' || $symb eq '') { $Apache::lonhomework::results{'rndseed'}=$env{'form.rndseed'}; @@ -340,6 +339,7 @@ sub finalize_storage { } return $result; } +use Data::Dumper; # -------------------------------------------------------------store_aggregates # Sends hash of values to be incremented in nohist_resourcetracker.db @@ -347,24 +347,32 @@ sub finalize_storage { # and corrects for each part for an instance of a problem, as appropriate. sub store_aggregates { my ($symb,$courseid) = @_; - my %aggregate = (); - my @parts = (); - my ($cdomain,$cname) = split/_/,$courseid; - foreach my $key (keys %Apache::lonhomework::results) { - if ($key =~ /resource\.(\d+)\.tries/) { - push @parts, $1; + my %aggregate; + my @parts; + my $cdomain = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $cname = $env{'course.'.$env{'request.course.id'}.'.num'}; + foreach my $key (keys(%Apache::lonhomework::results)) { + if ($key =~ /resource\.([^\.]+)\.tries/) { + push(@parts, $1); } } - foreach (@parts) { - if ($Apache::lonhomework::results{'resource.'.$_.'.award'} eq 'APPROX_ANS' || $Apache::lonhomework::results{'resource.'.$_.'.award'} eq 'EXACT_ANS') { - $aggregate{$symb.'_'.$_.'_correct'} = 1; + foreach my $part (@parts) { + if ($Apache::lonhomework::results{'resource.'.$part.'.award'} + eq 'APPROX_ANS' || + $Apache::lonhomework::results{'resource.'.$part.'.award'} + eq 'EXACT_ANS') { + $aggregate{$symb."\0".$part."\0correct"} = 1; } - if ($Apache::lonhomework::results{'resource.'.$_.'.tries'} == 1) { - $aggregate{$symb.'_'.$_.'_users'} = 1; + if ($Apache::lonhomework::results{'resource.'.$part.'.tries'} == 1) { + $aggregate{$symb."\0".$part."\0users"} = 1; } - $aggregate{$symb.'_'.$_.'_attempts'} = 1; + $aggregate{$symb."\0".$part."\0attempts"} = 1; + } + if (%aggregate) { + &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate, + $cdomain,$cname); + } - &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,$cdomain,$cname); } sub checkout_msg {