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

matthew lon-capa-cvs@mail.lon-capa.org
Thu, 13 Feb 2003 22:52:48 -0000


matthew		Thu Feb 13 17:52:48 2003 EDT

  Modified files:              
    /loncom/interface	lonspreadsheet.pm loncoursedata.pm 
  Log:
  Added loncoursedata::get_current_state, which is currently a simple
  wrapper for currentdump.  Changed loncoursedata to use $Apache::lonnet::tmpdir
  and changed lonspreadsheet to use loncoursedata::get_current_state.
  
  
Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.170 loncom/interface/lonspreadsheet.pm:1.171
--- loncom/interface/lonspreadsheet.pm:1.170	Thu Feb 13 17:22:01 2003
+++ loncom/interface/lonspreadsheet.pm	Thu Feb 13 17:52:48 2003
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.170 2003/02/13 22:22:01 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.171 2003/02/13 22:52:48 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1886,6 +1886,22 @@
     }
     $self->logthis("--------------------------------------------------------");}
 
+##
+## Yet another debugging function
+##
+sub dump_hash_to_log {
+    my $self= shift();
+    my %tmp = @_;
+    if (@_<2) {
+        %tmp = %{$_[0]};
+    }
+    $self->logthis('---------------------------- (entries end with ":"');
+    while (my ($key,$val) = each (%tmp)) {
+        $self->logthis($key.' = '.$val.':');
+    }
+    $self->logthis('---------------------------- (entries end with ":"');
+}
+
 ################################
 ##      Helper functions      ##
 ################################
@@ -3126,14 +3142,17 @@
     my %formulas  = $self->formulas();
     $cachedassess = $self->{'uname'}.':'.$self->{'udom'};
     # Get ALL the student preformance data
-    my @tmp = &Apache::lonnet::currentdump($self->{'cid'},
-                                           $self->{'udom'},
-                                           $self->{'uname'});
+    my @tmp = &Apache::loncoursedata::get_current_state($self->{'uname'},
+                                                        $self->{'udom'},
+                                                        undef,
+                                                        $self->{'cid'});
     if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
         %cachedstores = @tmp;
     }
     undef @tmp;
-    # 
+    # debugging code
+    # $self->dump_hash_to_log(\%cachedstores);
+    #
     my @assessdata=();
     foreach my $row ($self->rows()) {
         my $cell = 'A'.$row;
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.45 loncom/interface/loncoursedata.pm:1.46
--- loncom/interface/loncoursedata.pm:1.45	Thu Feb 13 09:49:16 2003
+++ loncom/interface/loncoursedata.pm	Thu Feb 13 17:52:48 2003
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: loncoursedata.pm,v 1.45 2003/02/13 14:49:16 matthew Exp $
+# $Id: loncoursedata.pm,v 1.46 2003/02/13 22:52:48 matthew Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -293,7 +293,8 @@
     &Apache::lonnet::logthis('filename = '.$fn);
     ##
     ## use navmaps
-    my $navmap = Apache::lonnavmaps::navmap->new($fn.".bd",$fn."_parms.db",1,0);
+    my $navmap = Apache::lonnavmaps::navmap->new($fn.".db",$fn."_parms.db",
+                                                 1,0);
     if (!defined($navmap)) {
         return 'Can not open Coursemap';
     }
@@ -1346,7 +1347,7 @@
 
 sub DownloadStudentCourseDataSeparate {
     my ($students,$checkDate,$cacheDB,$extract,$status,$courseID,$r,$c)=@_;
-    my $residualFile = '/home/httpd/perl/tmp/'.$courseID.'DownloadFile.db';
+    my $residualFile = $Apache::lonnet::tmpdir.$courseID.'DownloadFile.db';
     my $title = 'LON-CAPA Statistics';
     my $heading = 'Download Course Data';
 
@@ -1427,7 +1428,7 @@
 sub CheckForResidualDownload {
     my ($cacheDB,$extract,$status,$courseID,$r,$c)=@_;
 
-    my $residualFile = '/home/httpd/perl/tmp/'.$courseID.'DownloadFile.db';
+    my $residualFile = $Apache::lonnet::tmpdir.$courseID.'DownloadFile.db';
     if(!-e $residualFile) {
         return 'OK';
     }
@@ -1489,6 +1490,66 @@
     }
 
     return 'OK';
+}
+
+
+################################################
+################################################
+
+=pod
+
+=item &get_current_state($sname,$sdom,$symb,$courseid);
+
+Retrive the current status of a students performance.  $sname and
+$sdom are the only required parameters.  If $symb is undef the results
+of a &Apache::lonnet::currentdump() will be returned.  
+If $courseid is undef it will be retrieved from the environment.
+
+The return structure is based on &Apache::lonnet::currentdump.  If
+$symb is unspecified, all the students data is returned in a hash of
+the form:
+( 
+  symb1 => { param1 => value1, param2 => value2 ... },
+  symb2 => { param1 => value1, param2 => value2 ... },
+)
+
+If $symb is specified, a hash of 
+(
+  param1 => value1, 
+  param2 => value2,
+)
+is returned.
+
+Eventually this routine will cache the results locally.
+
+If no data is found for $symb, or if the student has not performance data,
+an empty list is returned.
+
+=cut
+
+################################################
+################################################
+
+sub get_current_state {
+    my ($sname,$sdom,$symb,$courseid)=@_;
+    return undef if (! defined($sname) || ! defined($sdom));
+    $courseid = $ENV{'request.course.id'} if (! defined($courseid));
+    # For a first pass, just get a currentdump and return the requested
+    # results
+    my @tmp = &Apache::lonnet::currentdump($courseid,$sdom,$sname);
+    if (! ((scalar(@tmp) > 0) && ($tmp[0] !~ /^error:/)) ) {
+        &Apache::lonnet::logthis('error getting data for '.$sname.':'.$sdom.
+                                 'in course '.$courseid);
+        return ();
+    }
+    my %student_data = @tmp;
+    if (! defined($symb)) {
+        return %student_data;
+    } elsif (exists($student_data{$symb})) {
+        return %{$student_data{$symb}};
+    } else {
+        return ();
+    }
 }
 
 ################################################