[LON-CAPA-cvs] cvs: loncom /interface/statistics lonsubmissiontimeanalysis.pm

matthew lon-capa-cvs@mail.lon-capa.org
Wed, 29 Oct 2003 18:59:47 -0000


matthew		Wed Oct 29 13:59:47 2003 EDT

  Modified files:              
    /loncom/interface/statistics	lonsubmissiontimeanalysis.pm 
  Log:
  1. Get the day of the week labels correct.
  2. Minor code cleanups.
  
  
Index: loncom/interface/statistics/lonsubmissiontimeanalysis.pm
diff -u loncom/interface/statistics/lonsubmissiontimeanalysis.pm:1.1 loncom/interface/statistics/lonsubmissiontimeanalysis.pm:1.2
--- loncom/interface/statistics/lonsubmissiontimeanalysis.pm:1.1	Wed Oct 29 10:22:04 2003
+++ loncom/interface/statistics/lonsubmissiontimeanalysis.pm	Wed Oct 29 13:59:46 2003
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonsubmissiontimeanalysis.pm,v 1.1 2003/10/29 15:22:04 matthew Exp $
+# $Id: lonsubmissiontimeanalysis.pm,v 1.2 2003/10/29 18:59:46 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -149,6 +149,13 @@
 
 sub analyze_times {
     my ($r,$resource,$students,$part) = @_;
+    #
+    # Convenience arrays
+    my @FullWeekDay = (qw/Sunday Monday Tuesday Wednesday Thursday Friday
+                       Saturday/);
+    my @WeekDay = (qw/SUN MON TUE WED THU FRI SAT SUN/);
+    my @Month = (qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/);
+    #
     my $html; # holds results of analysis
     # Get the data
     my $SubData = &Apache::loncoursedata::get_response_time_data
@@ -163,34 +170,24 @@
         return $html;
     }
     # Process the data
-    #   Get first and last times
-    my $span = &get_time_from_row($SubData->[-1]) - 
-               &get_time_from_row($SubData->[0]);
-    if ($span == 0) {
-        $html.= '<h2>There is no submission data for this resource</h2>';
-        return $html;
-    }
     #
     my (undef,undef,undef,$mday,$month,$year,$wday,$yday,$isdst) = 
         localtime(&get_time_from_row($SubData->[0]));
     my $day_start = &Time::Local::timelocal(0,0,0,$mday,$month,$year);
-    my $start_day_of_week = $wday;
-    #
-    my @WeekDay = (qw/SUN MON TUE WED THU FRI SAT SUN/);
-    my @Month = (qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/);
-    #
-    my $cumulative_answers = 0;
-    #
-    my @Ydata;
-    my @AnsData;
-    my @Xlabel;
     #
+    # Configure the bins used to store the data.
     my $binsize = 3600; # seconds
     my $bins_per_day = 86400/$binsize;
     my $bincount = 0;
     my $endtime = $day_start;
     #
+    # Initialize loop variables
     my $max;
+    my @Ydata=(0);
+    my @AnsData=(0);
+    my @Xlabel=($WeekDay[$wday]);
+    my $cumulative_answers = 0;
+    #
     foreach my $row (@$SubData) {
         my $subtime = &get_time_from_row($row);
         while ($subtime > $endtime && $endtime < time) {
@@ -200,8 +197,9 @@
             $AnsData[$bincount]=$AnsData[$bincount-1];
             $endtime += $binsize;
             if ($bincount % (86400/$binsize) == 0) {
-                $Xlabel[$bincount] = $WeekDay[$wday++];
+                $wday++;
                 $wday %= 7;
+                $Xlabel[$bincount] = $WeekDay[$wday];
             } else {
                 $Xlabel[$bincount] = '';
             }
@@ -226,6 +224,8 @@
         $AnsData[$bincount]=$AnsData[$bincount-1];
         $endtime += $binsize;
         if ($bincount % (86400/$binsize) == 0) {
+            $wday ++;
+            $wday %= 7;
             $Xlabel[$bincount] = $WeekDay[$wday];
         } else {
             $Xlabel[$bincount] = '';
@@ -234,13 +234,15 @@
 
     my $title = 'Number of Submissions and Number Correct';
     my $xlabel;
-    (undef,undef,undef,$mday,$month,$year) = localtime($day_start);
-    $xlabel .= 'Sunday '.join(' ',($Month[$month],$mday,1900+$year)).' - ';
-    (undef,undef,undef,$mday,$month,$year) = localtime($endtime);
-    $xlabel .= 'Sunday '.join(' ',($Month[$month],$mday,1900+$year));
+    (undef,undef,undef,$mday,$month,$year,$wday) = localtime($day_start);
+    $xlabel .= $FullWeekDay[$wday].' '.
+        join(' ',($Month[$month],$mday,1900+$year)).' - ';
+    (undef,undef,undef,$mday,$month,$year,$wday) = localtime($endtime);
+    $xlabel .= $FullWeekDay[$wday].' '.
+        join(' ',($Month[$month],$mday,1900+$year));
     $html .= &Apache::loncommon::DrawXYYGraph($title,
                                               $xlabel,
-                                              'Number of Submissions',
+                                              'Number of Submissions per hour',
                                               $plotcolors,
                                               \@Xlabel,
                                               \@Ydata,