[LON-CAPA-cvs] cvs: loncom /interface/spreadsheet Spreadsheet.pm assesscalc.pm classcalc.pm lonspreadsheet.pm studentcalc.pm

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 29 May 2003 13:39:39 -0000


matthew		Thu May 29 09:39:39 2003 EDT

  Modified files:              
    /loncom/interface/spreadsheet	Spreadsheet.pm assesscalc.pm 
                                 	classcalc.pm lonspreadsheet.pm 
                                 	studentcalc.pm 
  Log:
  Added $spreadsheet->initialize() subroutine to take care of specific
  initialization needed for each sheet.  assesscalc now has a list of
  mandatory parameters (Bug 1514) but is running in to problems with
  bug 1513.
  
  
Index: loncom/interface/spreadsheet/Spreadsheet.pm
diff -u loncom/interface/spreadsheet/Spreadsheet.pm:1.10 loncom/interface/spreadsheet/Spreadsheet.pm:1.11
--- loncom/interface/spreadsheet/Spreadsheet.pm:1.10	Wed May 28 13:38:57 2003
+++ loncom/interface/spreadsheet/Spreadsheet.pm	Thu May 29 09:39:38 2003
@@ -1,5 +1,5 @@
 #
-# $Id: Spreadsheet.pm,v 1.10 2003/05/28 17:38:57 matthew Exp $
+# $Id: Spreadsheet.pm,v 1.11 2003/05/29 13:39:38 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -220,6 +220,11 @@
     }
     return 1 if ($self->filename() eq $default_filename);
     return 0;
+}
+
+sub initialize {
+    # This method is here to remind you that it will be overridden by
+    # the descendents of the spreadsheet class.
 }
 
 sub initialize_spreadsheet_package {
Index: loncom/interface/spreadsheet/assesscalc.pm
diff -u loncom/interface/spreadsheet/assesscalc.pm:1.10 loncom/interface/spreadsheet/assesscalc.pm:1.11
--- loncom/interface/spreadsheet/assesscalc.pm:1.10	Tue May 27 16:20:25 2003
+++ loncom/interface/spreadsheet/assesscalc.pm	Thu May 29 09:39:38 2003
@@ -1,5 +1,5 @@
 #
-# $Id: assesscalc.pm,v 1.10 2003/05/27 20:20:25 matthew Exp $
+# $Id: assesscalc.pm,v 1.11 2003/05/29 13:39:38 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -123,6 +123,10 @@
     undef(%courseopt);
 }
 
+sub initialize {
+    &clear_package();
+}
+
 ########################################################
 ########################################################
 
@@ -507,6 +511,19 @@
     my $self = shift;
     $self->logthis('computing');
     $self->initialize_safe_space();
+    #########################################
+    #########################################
+    ###                                   ###
+    ###  Retrieve the problem parameters  ###
+    ###                                   ###
+    #########################################
+    #########################################
+    my @Mandatory_parameters = ("stores_0_solved",
+                                "stores_0_awarddetail",
+                                "stores_0_awarded",
+                                "timestamp",
+                                "stores_0_tries",
+                                "stores_0_award");
     #
     # Definitions
     undef(%nice_parameter_name);
@@ -515,7 +532,7 @@
     # Get the metadata fields and determine their proper names
     my ($symap,$syid,$srcf)=split(/___/,$self->{'symb'});
     my @Metadata = split(/\,/,&Apache::lonnet::metadata($srcf,'keys'));
-    foreach my $parm (@Metadata) {
+    foreach my $parm (@Mandatory_parameters,@Metadata) {
         next if ($parm !~ /^(resource\.|stores|parameter)_/);
         my $cleaned_name = $parm;
         $cleaned_name =~ s/^resource\./stores_/;
Index: loncom/interface/spreadsheet/classcalc.pm
diff -u loncom/interface/spreadsheet/classcalc.pm:1.5 loncom/interface/spreadsheet/classcalc.pm:1.6
--- loncom/interface/spreadsheet/classcalc.pm:1.5	Tue May 27 10:52:45 2003
+++ loncom/interface/spreadsheet/classcalc.pm	Thu May 29 09:39:38 2003
@@ -1,5 +1,5 @@
 #
-# $Id: classcalc.pm,v 1.5 2003/05/27 14:52:45 matthew Exp $
+# $Id: classcalc.pm,v 1.6 2003/05/29 13:39:38 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -59,6 +59,18 @@
 
 @Apache::classcalc::ISA = ('Apache::Spreadsheet');
 
+##
+## Package variable
+##
+
+my @Students;
+
+sub initialize {
+    &Apache::lonstatistics::clear_classlist_variables();
+    @Students = &Apache::lonstatistics::get_students();
+    return;
+}
+
 sub html_header {
     my $self = shift;
     my ($toprow,$bottomrow);
@@ -76,12 +88,6 @@
         "</table>\n</p>";
 }
 
-sub get_classlist {
-    my $self = shift;
-    # Retrieve the classlist and return it 
-    return &Apache::lonstatistics::get_students();
-}
-
 sub get_title {
     my $self = shift;
     # Section info should be included
@@ -159,7 +165,7 @@
     }
     #
     my $num_output = 0;
-    foreach my $student ($self->get_classlist()) {
+    foreach my $student (@Students) {
 	if ($num_output++ % 50 == 0) {
 	    $r->print("</table>\n".$tableheader);
 	}
@@ -194,7 +200,7 @@
     $rows_output++;    
     #
     # Write each students row
-    foreach my $student ($self->get_classlist()) {
+    foreach my $student (@Students) {
         $cols_output = 0;
 	my $rownum = $self->get_row_number_from_key
 	    ($student->{'username'}.':'.$student->{'domain'});
@@ -222,7 +228,7 @@
                           ('fullname','username','domain','section','status'));
     #
     # Write each students row
-    foreach my $student ($self->get_classlist()) {
+    foreach my $student (@Students) {
 	my $rownum = $self->get_row_number_from_key
 	    ($student->{'username'}.':'.$student->{'domain'});
         $student->{'section'} = 'none' if ($student->{'section'} eq '-1');
@@ -247,12 +253,11 @@
     $self->initialize_safe_space();
     my %c = $self->constants();
     my %f = $self->formulas();
-    my @Students = $self->get_classlist();
     my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
         ($r,'Spreadsheet Computation Status',
          'Spreadsheet Computation', scalar(@Students));
     &Apache::studentcalc::initialize_package();
-    foreach my $student ($self->get_classlist()) {
+    foreach my $student (@Students) {
         my $sname = $student->{'username'}.':'.$student->{'domain'};
 	my $studentsheet = Apache::studentcalc->new
 	    ($student->{'username'},$student->{'domain'},undef);
Index: loncom/interface/spreadsheet/lonspreadsheet.pm
diff -u loncom/interface/spreadsheet/lonspreadsheet.pm:1.7 loncom/interface/spreadsheet/lonspreadsheet.pm:1.8
--- loncom/interface/spreadsheet/lonspreadsheet.pm:1.7	Wed May 28 11:19:34 2003
+++ loncom/interface/spreadsheet/lonspreadsheet.pm	Thu May 29 09:39:38 2003
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.7 2003/05/28 15:19:34 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.8 2003/05/29 13:39:38 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -351,6 +351,7 @@
         # error error - run in circles, scream and shout
         return;
     }
+    $spreadsheet->initialize();
     #
     # Output selector
     $r->print('<input type="submit" value="Update Display" /><br />');
Index: loncom/interface/spreadsheet/studentcalc.pm
diff -u loncom/interface/spreadsheet/studentcalc.pm:1.7 loncom/interface/spreadsheet/studentcalc.pm:1.8
--- loncom/interface/spreadsheet/studentcalc.pm:1.7	Fri May 23 17:03:29 2003
+++ loncom/interface/spreadsheet/studentcalc.pm	Thu May 29 09:39:38 2003
@@ -1,5 +1,5 @@
 #
-# $Id: studentcalc.pm,v 1.7 2003/05/23 21:03:29 matthew Exp $
+# $Id: studentcalc.pm,v 1.8 2003/05/29 13:39:38 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -64,10 +64,22 @@
 
 my $current_course;
 
+sub initialize {
+    &initialize_sequence_cache();
+}
+
 sub initialize_package {
     $current_course = $ENV{'request.course.id'};
     &initialize_sequence_cache();
     &load_cached_export_rows();
+}
+
+sub ensure_correct_sequence_data {
+    if ($current_course ne $ENV{'request.course.id'}) {
+        &initialize_sequence_cache();
+        $current_course = $ENV{'request.course.id'};
+    }
+    return;
 }
 
 sub initialize_sequence_cache {