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

matthew lon-capa-cvs@mail.lon-capa.org
Sun, 07 Mar 2004 21:42:19 -0000


matthew		Sun Mar  7 16:42:19 2004 EDT

  Modified files:              
    /loncom/interface	loncoursedata.pm 
    /loncom/interface/statistics	lonproblemstatistics.pm 
  Log:
  loncoursedata: &get_problem_statistics now supports limiting statistics
      by time.
  lonproblemstatistics: Now supports limiting statistics by time.  
      Made text of output options more concise to save real estate.
  
  
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.121 loncom/interface/loncoursedata.pm:1.122
--- loncom/interface/loncoursedata.pm:1.121	Sun Mar  7 15:53:40 2004
+++ loncom/interface/loncoursedata.pm	Sun Mar  7 16:42:19 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: loncoursedata.pm,v 1.121 2004/03/07 20:53:40 matthew Exp $
+# $Id: loncoursedata.pm,v 1.122 2004/03/07 21:42:19 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1867,7 +1867,7 @@
 properly.  This means you need to call &ensure_current_data for
 the students you are concerned with prior to calling this routine.
 
-Inputs: $students, $symb, $part, $courseid
+Inputs: $students, $symb, $part, $courseid, $starttime, $endtime
 
 =over 4
 
@@ -1880,6 +1880,9 @@
 
 =item $courseid is the course id, of course!
 
+=item $starttime and $endtime are unix times which to use to limit
+the statistical data.
+
 =back
 
 Outputs: See the code for up to date information.  A hash reference is
@@ -1915,7 +1918,7 @@
 ################################################
 ################################################
 sub get_problem_statistics {
-    my ($Sections,$status,$symb,$part,$courseid) = @_;
+    my ($Sections,$status,$symb,$part,$courseid,$starttime,$endtime) = @_;
     return if (! defined($symb) || ! defined($part));
     $courseid = $ENV{'request.course.id'} if (! defined($courseid));
     #
@@ -1944,6 +1947,20 @@
     }
     if (defined($status) && lc($status) ne 'any') {
         $request .= " AND b.status='".$status."'";
+    }
+    #
+    &Apache::lonnet::logthis('starttime = '.$starttime);
+    my $time_requirements = undef;
+    if (defined($starttime)) {
+        $time_requirements .= 'a.timestamp>='.$starttime;
+        if (defined($endtime)) {
+            $time_requirements .= ' AND a.timestamp<='.$endtime;
+        }
+    } elsif (defined($endtime)) {
+        $time_requirements .= 'a.timestamp<='.$endtime;
+    }
+    if (defined($time_requirements)) {
+        $request .= ' AND '.$time_requirements;
     }
     $dbh->do($request);
 #    &Apache::lonnet::logthis('request = '.$/.$request);
Index: loncom/interface/statistics/lonproblemstatistics.pm
diff -u loncom/interface/statistics/lonproblemstatistics.pm:1.69 loncom/interface/statistics/lonproblemstatistics.pm:1.70
--- loncom/interface/statistics/lonproblemstatistics.pm:1.69	Mon Mar  1 11:39:19 2004
+++ loncom/interface/statistics/lonproblemstatistics.pm	Sun Mar  7 16:42:19 2004
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonproblemstatistics.pm,v 1.69 2004/03/01 16:39:19 matthew Exp $
+# $Id: lonproblemstatistics.pm,v 1.70 2004/03/07 21:42:19 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -57,6 +57,7 @@
 use Apache::lonstatistics;
 use Apache::lonlocal;
 use Spreadsheet::WriteExcel;
+use Apache::lonstathelpers();
 
 ##
 ## Localization notes:
@@ -185,19 +186,19 @@
 ###############################################
 my @OutputOptions = 
     (
-     { name  => 'problem statistics grouped by sequence',
+     { name  => 'grouped by sequence',
        value => 'HTML problem statistics grouped',
        description => 'Output statistics for the problem parts.',
        mode => 'html',
        show => 'grouped',
      },
-     { name  => 'problem statistics ungrouped',
+     { name  => 'ungrouped',
        value => 'HTML problem statistics ungrouped',
        description => 'Output statistics for the problem parts.',
        mode => 'html',
        show => 'ungrouped',
      },
-     { name  => 'problem statistics, Excel',
+     { name  => 'Excel',
        value => 'Excel problem statistics',
        description => 'Output statistics for the problem parts '.
            'in an Excel workbook',
@@ -216,6 +217,8 @@
     $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
     $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
     $Str .= '<td align="center"><b>'.&mt('Output').'</b></td>';
+    $Str .= '<td rowspan="2">'.
+        &Apache::lonstathelpers::limit_by_time_form().'</td>';
     $Str .= '</tr>'."\n";
     #
     $Str .= '<tr><td align="center">'."\n";
@@ -297,7 +300,16 @@
         $r->print("<h2>".
                   $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.
                   "</h2>\n");
-        $r->print("<h3>".localtime(time)."</h3>");
+        my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
+        if (defined($starttime) || defined($endtime)) {
+            # Inform the user what the time limits on the data are.
+            $r->print('<h3>'.&mt('Statistics on submissions from [_1] to [_2]',
+                                 &Apache::lonlocal::locallocaltime($starttime),
+                                 &Apache::lonlocal::locallocaltime($endtime)).
+                      '</h3>');
+        }
+        $r->print("<h3>".&mt('Compiled on [_1]',
+                             &Apache::lonlocal::locallocaltime(time))."</h3>");
         $r->rflush();
         if ($show eq 'grouped') {
             &output_html_grouped_by_sequence($r);
@@ -503,6 +515,8 @@
         $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
             time.'_'.rand(1000000000).'.xls';
     #
+    my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
+    #
     my $excel_workbook = undef;
     my $excel_sheet = undef;
     #
@@ -561,6 +575,22 @@
     $excel_sheet->write($rows_output,$cols_output++,$sectionstring);
     $cols_output += scalar(@Sections);
     #
+    # Time restrictions
+    my $time_string;
+    if (defined($starttime)) {
+        # call localtime but not lonlocal:locallocaltime because excel probably
+        # cannot handle localized text.  Probably.
+        $time_string .= 'Data collected from '.localtime($time_string);
+        if (defined($endtime)) {
+            $time_string .= ' to '.localtime($endtime);
+        }
+        $time_string .= '.';
+    } elsif (defined($endtime)) {
+        # See note above about lonlocal:locallocaltime
+        $time_string .= 'Data collected before '.localtime($endtime).'.';
+    }
+    
+    #
     # Put the date in there too
     $excel_sheet->write($rows_output,$cols_output++,
                         'Compiled on '.localtime(time));
@@ -782,16 +812,36 @@
     return;
 }
 
+########################################################
+########################################################
+
+=pod
+
+=item &get_statistics()
+
+Wrapper routine from the call to loncoursedata::get_problem_statistics.  
+Calls lonstathelpers::get_time_limits() to limit the data set by time.
+
+Inputs: $sequence, $resource, $part, $problem_num
+
+Returns: Hash reference with statistics data from 
+loncoursedata::get_problem_statistics.
+
+=cut
+
+########################################################
+########################################################
 sub get_statistics {
     my ($sequence,$resource,$part,$problem_num) = @_;
     #
+    my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
     my $symb = $resource->{'symb'};
     my $courseid = $ENV{'request.course.id'};
     #
     my $data = &Apache::loncoursedata::get_problem_statistics
                         (\@Apache::lonstatistics::SelectedSections,
                          $Apache::lonstatistics::enrollment_status,
-                         $symb,$part,$courseid);
+                         $symb,$part,$courseid,$starttime,$endtime);
     $data->{'part'}        = $part;
     $data->{'problem_num'} = $problem_num;
     $data->{'container'}   = $sequence->{'title'};