--- loncom/interface/statistics/lonproblemstatistics.pm	2003/11/11 22:14:28	1.61
+++ loncom/interface/statistics/lonproblemstatistics.pm	2004/03/07 21:42:19	1.70
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonproblemstatistics.pm,v 1.61 2003/11/11 22:14:28 matthew Exp $
+# $Id: lonproblemstatistics.pm,v 1.70 2004/03/07 21:42:19 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -51,11 +51,13 @@ package Apache::lonproblemstatistics;
 
 use strict;
 use Apache::lonnet();
+use Apache::loncommon();
 use Apache::lonhtmlcommon;
 use Apache::loncoursedata;
 use Apache::lonstatistics;
 use Apache::lonlocal;
 use Spreadsheet::WriteExcel;
+use Apache::lonstathelpers();
 
 ##
 ## Localization notes:
@@ -146,7 +148,7 @@ my @Fields = (
              title  => '#YES',
              align  => 'right',
              color  => '#FFDDDD',
-             format => '%d',
+             format => '%4.1f',#             format => '%d',
              sortable  => 'yes',
              graphable => 'yes',
              long_title => 'Number of Students able to Solve' },
@@ -154,7 +156,7 @@ my @Fields = (
              title  => '#yes',
              align  => 'right',
              color  => '#FFDDDD',
-             format => '%d',
+             format => '%4.1f',#             format => '%d',
              sortable  => 'yes',
              graphable => 'yes',
              long_title => 'Number of Students given Override' },
@@ -184,19 +186,19 @@ select sections, maps, and output.
 ###############################################
 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',
@@ -207,12 +209,16 @@ my @OutputOptions =
 
 sub CreateInterface {
     my $Str = '';
+    $Str .= &Apache::lonhtmlcommon::breadcrumbs
+        (undef,'Overall Problem Statistics','Statistics_Overall_Key');
     $Str .= '<table cellspacing="5">'."\n";
     $Str .= '<tr>';
     $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
     $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";
@@ -294,7 +300,16 @@ sub BuildProblemStatisticsPage {
         $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);
@@ -500,6 +515,8 @@ sub output_excel {
         $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;
     #
@@ -529,7 +546,9 @@ sub output_excel {
     if (length($sheetname) > 31) {
         $sheetname = substr($sheetname,0,31);
     }
-    $excel_sheet = $excel_workbook->addworksheet($sheetname);
+    $excel_sheet = $excel_workbook->addworksheet(
+                       &Apache::loncommon::clean_excel_name($sheetname)
+                                                 );
     #
     # Put the course description in the header
     $excel_sheet->write($rows_output,$cols_output++,
@@ -556,6 +575,22 @@ sub output_excel {
     $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));
@@ -767,7 +802,8 @@ sub plot_statistics {
                                                      'Problem Number',
                                                      $yaxis,
                                                      $Max,
-                                                     undef,
+                                                     undef, # colors
+                                                     undef, # labels
                                                      \@Data)."</p>\n");
     #
     # Print out the data
@@ -776,18 +812,36 @@ sub plot_statistics {
     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 $students = \@Apache::lonstatistics::Students;
-    if ($Apache::lonstatistics::SelectedSections[0] eq 'all') {
-        $students = undef;
-    }
     my $data = &Apache::loncoursedata::get_problem_statistics
-                        ($students,$symb,$part,$courseid);
+                        (\@Apache::lonstatistics::SelectedSections,
+                         $Apache::lonstatistics::enrollment_status,
+                         $symb,$part,$courseid,$starttime,$endtime);
     $data->{'part'}        = $part;
     $data->{'problem_num'} = $problem_num;
     $data->{'container'}   = $sequence->{'title'};