--- loncom/metadata_database/LONCAPA/lonmetadata.pm 2007/01/19 14:23:46 1.19 +++ loncom/metadata_database/LONCAPA/lonmetadata.pm 2007/05/12 23:03:30 1.20 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonmetadata.pm,v 1.19 2007/01/19 14:23:46 raeburn Exp $ +# $Id: lonmetadata.pm,v 1.20 2007/05/12 23:03:30 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -828,12 +828,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 @@ -846,6 +841,7 @@ sub process_dynamic_metadata { } if ($current_course ne $coursedata->{'course'}) { $stdno += $coursemax; + $course_counted{$coursedata->{'course'}}++; $coursemax = 0; $current_course = $coursedata->{'course'}; } @@ -855,6 +851,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