--- loncom/interface/statistics/lonproblemstatistics.pm	2004/04/16 21:43:56	1.84
+++ loncom/interface/statistics/lonproblemstatistics.pm	2004/06/16 14:21:16	1.88
@@ -1,6 +1,6 @@
 # The LearningOnline Network with CAPA
 #
-# $Id: lonproblemstatistics.pm,v 1.84 2004/04/16 21:43:56 matthew Exp $
+# $Id: lonproblemstatistics.pm,v 1.88 2004/06/16 14:21:16 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -96,6 +96,10 @@ my %SeqStat;    # keys are symbs, values
 ##                                      statistics display?
 ## selected        yes     (yes|no)     Is the column selected by default?
 ##
+## format          no      sprintf format string
+##
+## excel_format    no      excel format type 
+##                               (see &Apache::loncommon::define_excel_formats
 my @Fields = (
            { name => 'problem_num',
              title => 'P#',
@@ -261,6 +265,50 @@ my @Fields = (
              selectable => 'yes',
              defaultselected => 'no',
            },
+##   duedate included for research purposes.  Commented out most of the time.
+#           { name => 'duedate',
+#             title => 'Due Date',
+#             align => 'left',
+#             color => '#FFFFFF',
+#             sortable => 'yes',
+#             graphable => 'no',
+#             long_title => 'Due date of resource for instructor',
+#             selectable => 'no',
+#             defaultselected => 'yes',
+#            },
+##   opendate included for research purposes.  Commented out most of the time.
+#           { name => 'opendate',
+#             title => 'Open Date',
+#             align => 'left',
+#             color => '#FFFFFF',
+#             sortable => 'yes',
+#             graphable => 'no',
+#             long_title => 'date resource became answerable',
+#             selectable => 'no',
+#             defaultselected => 'yes',
+#            },
+##   symb included for research purposes.  Commented out most of the time.
+#           { name => 'symb',
+#             title => 'Symb',
+#             align => 'left',
+#             color => '#FFFFFF',
+#             sortable => 'yes',
+#             graphable => 'no',
+#             long_title => 'Unique LON-CAPA identifier for problem',
+#             selectable => 'no',
+#             defaultselected => 'yes',
+#            },
+##   resptypes included for research purposes.  Commented out most of the time.
+#           { name => 'resptypes',
+#             title => 'Response Types',
+#             align => 'left',
+#             color => '#FFFFFF',
+#             sortable => 'no',
+#             graphable => 'no',
+#             long_title => 'Response Types used in this problem',
+#             selectable => 'no',
+#             defaultselected => 'yes',
+#            },
 );
 
 my @SeqFields = (
@@ -499,6 +547,7 @@ select sections, maps, and output.
 ###############################################
 ###############################################
 sub CreateInterface {
+    my ($r) = @_;
     #
     &parse_field_selection();
     #
@@ -534,19 +583,18 @@ sub CreateInterface {
     $Str .= '</td><td>'.&field_selection_input();
     $Str .= '</td></tr>'."\n";
     $Str .= '</table>'."\n";
+    #
+    $Str .= '<p>'.&mt('Status: [_1]',
+                         '<input type="text" '.
+                         'name="stats_status" size="60" value="" />'
+                         ).
+                         '</nobr></p>';
+    #
     $Str .= '<input type="submit" name="GenerateStatistics" value="'.
         &mt('Generate Statistics').'" />';
     $Str .= '&nbsp;'x5;
     $Str .= 'Plot '.&plot_dropdown().('&nbsp;'x10);
-    $Str .= '<input type="submit" name="ClearCache" value="'.
-        &mt('Clear Caches').'" />';
-    $Str .= '&nbsp;'x5;
-    $Str .= '<input type="submit" name="UpdateCache" value="'.
-        &mt('Update Student Data').'" />';
-    $Str .= '&nbsp;'x5;
-    $Str .= '<input type="submit" name="Excel" value="'.
-        &mt('Produce Excel Output').'" />';
-    $Str .= '&nbsp;'x5;
+    #
     return $Str;
 }
 
@@ -584,13 +632,20 @@ sub BuildProblemStatisticsPage {
     undef(%SeqStat);
     #
     # Finally let the user know we are here
-    my $interface = &CreateInterface();
+    my $interface = &CreateInterface($r);
     $r->print($interface);
     $r->print('<input type="hidden" name="sortby" value="'.$ENV{'form.sortby'}.
               '" />');
     #
-    if (! exists($ENV{'form.statsfirstcall'})) {
-        $r->print('<input type="hidden" name="statsfirstcall" value="yes" />');
+    my @CacheButtonHTML = 
+        &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
+    my $Str;
+    foreach my $html (@CacheButtonHTML) {
+        $Str.=$html.('&nbsp;'x5);
+    }
+    #
+    $r->print($Str);
+    if (! exists($ENV{'form.firstrun'})) {
         $r->print('<h3>'.
                   &mt('Press "Generate Statistics" when you are ready.').
                   '</h3><p>'.
@@ -599,13 +654,6 @@ sub BuildProblemStatisticsPage {
                       ' will not have this delay.').
                   '</p>');
         return;
-    } elsif ($ENV{'form.statsfirstcall'} eq 'yes' || 
-             exists($ENV{'form.UpdateCache'}) ||
-             exists($ENV{'form.ClearCache'}) ) {
-        $r->print('<input type="hidden" name="statsfirstcall" value="no" />');
-        &Apache::lonstatistics::Gather_Student_Data($r);
-    } else {
-        $r->print('<input type="hidden" name="statsfirstcall" value="no" />');
     }
     $r->rflush();
     #
@@ -615,7 +663,10 @@ sub BuildProblemStatisticsPage {
     #
     if (exists($ENV{'form.Excel'})) {
         &Excel_output($r);
-    } else {
+    } else { 
+        $r->print('<input type="submit" name="Excel" value="'.
+                  &mt('Produce Excel Output').'" />'.'&nbsp;'x5);
+        $r->rflush();
         my $count = 0;
         foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
             $count += $seq->{'num_assess_parts'};
@@ -1241,8 +1292,12 @@ sub Excel_output {
         $cols_output=0;
         foreach my $field (@SeqFields) {
             next if ($field->{'selected'} ne 'yes');
+            my $fieldformat = undef;
+            if (exists($field->{'excel_format'})) {
+                $fieldformat = $format->{$field->{'excel_format'}};
+            }
             $excel_sheet->write($rows_output,$cols_output++,
-                                $data->{$field->{'name'}});
+                                $data->{$field->{'name'}},$fieldformat);
         }
         $rows_output++;
         $cols_output=0;
@@ -1260,8 +1315,12 @@ sub Excel_output {
         foreach my $field (@Fields) {
             next if ($field->{'selected'} ne 'yes');
             next if ($field->{'name'} eq 'problem_num');
+            my $fieldformat = undef;
+            if (exists($field->{'excel_format'})) {
+                $fieldformat = $format->{$field->{'excel_format'}};
+            }
             $excel_sheet->write($rows_output,$cols_output++,
-                                $data->{$field->{'name'}});
+                                $data->{$field->{'name'}},$fieldformat);
         }
         $rows_output++;
         $cols_output=0;
@@ -1328,6 +1387,7 @@ sub compute_statistics_on_sequence {
     foreach my $res (@{$seq->{'contents'}}) {
         next if ($res->{'type'} ne 'assessment');
         foreach my $part (@{$res->{'parts'}}) {
+            next if ($res->{'partdata'}->{$part}->{'Survey'});
             #
             # This is where all the work happens
             my $data = &get_statistics($seq,$res,$part,scalar(@StatsArray)+1);
@@ -1441,6 +1501,7 @@ sub get_statistics {
                         (\@Apache::lonstatistics::SelectedSections,
                          $Apache::lonstatistics::enrollment_status,
                          $symb,$part,$courseid,$starttime,$endtime);
+    $data->{'symb'}        = $symb;
     $data->{'part'}        = $part;
     $data->{'problem_num'} = $problem_num;
     $data->{'container'}   = $sequence->{'title'};
@@ -1467,6 +1528,13 @@ sub get_statistics {
         my ($dom,$user) = $urlres=~/^(\w+)\/(\w+)/; 
         &Apache::lonnet::put('nohist_resevaldata',\%storestats,$dom,$user);
     }
+    #
+    # Get the due date for research purposes (commented out most of the time)
+#    $data->{'duedate'} = 
+#        &Apache::lonnet::EXT('resource.'.$part.'.duedate',$symb);
+#    $data->{'opendate'} = 
+#        &Apache::lonnet::EXT('resource.'.$part.'.opendate',$symb);
+#    $data->{'resptypes'} = join(',',@{$resource->{'partdata'}->{$part}->{'ResponseTypes'}});
     return $data;
 }