[LON-CAPA-cvs] cvs: loncom /metadata_database/LONCAPA lonmetadata.pm

albertel lon-capa-cvs-allow@mail.lon-capa.org
Sat, 12 May 2007 23:03:31 -0000


albertel		Sat May 12 19:03:31 2007 EDT

  Modified files:              
    /loncom/metadata_database/LONCAPA	lonmetadata.pm 
  Log:
  - BUG#5248, stop double counting course accesses
  
  
Index: loncom/metadata_database/LONCAPA/lonmetadata.pm
diff -u loncom/metadata_database/LONCAPA/lonmetadata.pm:1.19 loncom/metadata_database/LONCAPA/lonmetadata.pm:1.20
--- loncom/metadata_database/LONCAPA/lonmetadata.pm:1.19	Fri Jan 19 09:23:46 2007
+++ loncom/metadata_database/LONCAPA/lonmetadata.pm	Sat May 12 19:03:30 2007
@@ -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 @@
     #
     # 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 @@
             }
             if ($current_course ne $coursedata->{'course'}) {
                 $stdno += $coursemax;
+		$course_counted{$coursedata->{'course'}}++;
                 $coursemax = 0;
                 $current_course = $coursedata->{'course'};                
             }
@@ -855,6 +851,14 @@
         }
         $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