--- loncom/metadata_database/LONCAPA/lonmetadata.pm 2007/01/12 21:30:58 1.17 +++ loncom/metadata_database/LONCAPA/lonmetadata.pm 2007/06/15 23:02:09 1.22 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonmetadata.pm,v 1.17 2007/01/12 21:30:58 albertel Exp $ +# $Id: lonmetadata.pm,v 1.22 2007/06/15 23:02:09 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -184,8 +184,6 @@ $Portfolio_metadata_table_description = { name => 'domain', type=>'TEXT'}, { name => 'groupname', type=>'TEXT'}, { name => 'courserestricted', type=>'TEXT'}, - { name => 'addedfieldnames', type=>'TEXT'}, - { name => 'addedfieldvalues', type=>'TEXT'}, #-------------------------------------------------- { name => 'dependencies', type=>'TEXT'}, { name => 'modifyinguser', type=>'TEXT'}, @@ -797,23 +795,17 @@ sub process_dynamic_metadata { # Get the statistical data - Use a weighted average foreach my $type (qw/avetries difficulty disc/) { my $studentcount; + my %course_counted; my $sum; my @Values; my @Students; # - # Old data - foreach my $coursedata (values(%{$resdata->{'statistics'}}), - values(%{$resdata->{'stats'}})) { - if (ref($coursedata) eq 'HASH' && exists($coursedata->{$type})) { - $studentcount += $coursedata->{'stdno'}; - $sum += ($coursedata->{$type}*$coursedata->{'stdno'}); - push(@Values,$coursedata->{$type}); - push(@Students,$coursedata->{'stdno'}); - } - } + # New data if (exists($resdata->{'stats'})) { foreach my $identifier (sort(keys(%{$resdata->{'stats'}}))) { my $coursedata = $resdata->{'stats'}->{$identifier}; + next if (lc($coursedata->{$type}) eq 'nan'); + $course_counted{$coursedata->{'course'}}++; $studentcount += $coursedata->{'stdno'}; $sum += $coursedata->{$type}*$coursedata->{'stdno'}; push(@Values,$coursedata->{$type}); @@ -821,7 +813,18 @@ sub process_dynamic_metadata { } } # - # New data + # Old data + foreach my $course (keys(%{$resdata->{'statistics'}})) { + next if (exists($course_counted{$course})); + my $coursedata = $resdata->{'statistics'}{$course}; + if (ref($coursedata) eq 'HASH' && exists($coursedata->{$type})) { + next if (lc($coursedata->{$type}) eq 'nan'); + $studentcount += $coursedata->{'stdno'}; + $sum += ($coursedata->{$type}*$coursedata->{'stdno'}); + push(@Values,$coursedata->{$type}); + push(@Students,$coursedata->{'stdno'}); + } + } if (defined($studentcount) && $studentcount>0) { $data{$type} = $sum/$studentcount; $data{$type.'_list'} = join(',',@Values); @@ -830,12 +833,7 @@ sub process_dynamic_metadata { # # Find out the number of students who have completed the resource... my $stdno; - foreach my $coursedata (values(%{$resdata->{'statistics'}}), - values(%{$resdata->{'stats'}})) { - if (ref($coursedata) eq 'HASH' && exists($coursedata->{'stdno'})) { - $stdno += $coursedata->{'stdno'}; - } - } + my %course_counted; if (exists($resdata->{'stats'})) { # # For the number of students, take the maximum found for the class @@ -848,6 +846,7 @@ sub process_dynamic_metadata { } if ($current_course ne $coursedata->{'course'}) { $stdno += $coursemax; + $course_counted{$coursedata->{'course'}}++; $coursemax = 0; $current_course = $coursedata->{'course'}; } @@ -857,6 +856,14 @@ sub process_dynamic_metadata { } $stdno += $coursemax; # pick up the final course in the list } + # check for old data that has not been run since the format was changed + foreach my $course (keys(%{$resdata->{'statistics'}})) { + next if (exists($course_counted{$course})); + my $coursedata = $resdata->{'statistics'}{$course}; + if (ref($coursedata) eq 'HASH' && exists($coursedata->{'stdno'})) { + $stdno += $coursedata->{'stdno'}; + } + } $data{'stdno'}=$stdno; # # Get the context data @@ -993,20 +1000,10 @@ sub portfolio_metadata { } } } # End of ($token->[0] eq 'S') - } - if (keys(%addedfields) > 0) { - foreach my $key (sort keys(%addedfields)) { - $metacache{'addedfieldnames'} .= $key.','; - $metacache{'addedfieldvalues'} .= $addedfields{$key}.'&&&'; - } - $metacache{'addedfieldnames'} =~ s/,$//; - $metacache{'addedfieldvalues'} =~ s/\&\&\&$//; - if ($metacache{'keys'}) { - $metacache{'keys'}.=',addedfieldnames'; - } else { - $metacache{'keys'}='addedfieldnames'; - } - $metacache{'keys'}.=',addedfieldvalues'; + + if (!exists($metacache{'domain'})) { + $metacache{'domain'} = $dom; + } } return (\%metacache,$metacache{'courserestricted'},\%addedfields); } @@ -1127,8 +1124,6 @@ sub process_portfolio_metadata { ###################################################################### ###################################################################### -## Utilities originally in searchcat.pl. Moved to be more widely available. - sub getfile { my $file = shift(); if (! -e $file ) {