Diff for /loncom/interface/loncoursedata.pm between versions 1.21 and 1.22

version 1.21, 2002/08/28 18:29:22 version 1.22, 2002/08/28 21:50:27
Line 35  loncoursedata Line 35  loncoursedata
   
 =head1 SYNOPSIS  =head1 SYNOPSIS
   
 Set of functions that download and process student information.  Set of functions that download and process student and course information.
   
 =head1 PACKAGES USED  =head1 PACKAGES USED
   
  Apache::Constants qw(:common :http)   Apache::Constants qw(:common :http)
  Apache::lonnet()   Apache::lonnet()
    Apache::lonhtmlcommon
  HTML::TokeParser   HTML::TokeParser
  GDBM_File   GDBM_File
   
Line 59  use GDBM_File; Line 60  use GDBM_File;
   
 =head1 DOWNLOAD INFORMATION  =head1 DOWNLOAD INFORMATION
   
 This section contains all the files that get data from other servers   This section contains all the functions that get data from other servers 
 and/or itself.  There is one function that has a call to get remote  and/or itself.
 information but is not included here which is ProcessTopLevelMap.  The  
 usage was small enough to be ignored, but that portion may be moved  
 here in the future.  
   
 =cut  =cut
   
Line 74  here in the future. Line 72  here in the future.
 =item &DownloadClasslist()  =item &DownloadClasslist()
   
 Collects lastname, generation, middlename, firstname, PID, and section for each  Collects lastname, generation, middlename, firstname, PID, and section for each
 student from their environment database.  The list of students is built from  student from their environment database.  The section data is also download, though
 collecting a classlist for the course that is to be displayed.  it is in a rough format, and is processed later.  The list of students is built from
   collecting a classlist for the course that is to be displayed.  Once the classlist
   has been downloaded, its date stamp is recorded.  Unless the datestamp for the
   class database is reset or is modified, this data will not be downloaded again.  
   Also, there was talk about putting the fullname and section
   and perhaps other pieces of data into the classlist file.  This would
   reduce the number of different file accesses and reduce the amount of 
   processing on this side.
   
 =over 4  =over 4
   
Line 83  Input: $courseID, $lastDownloadTime, $c Line 88  Input: $courseID, $lastDownloadTime, $c
   
 $courseID:  The id of the course  $courseID:  The id of the course
   
 $lastDownloadTime: I am not sure.  $lastDownloadTime:  This is the date stamp for when this information was
   last gathered.  If it is set to 'Not downloaded', it will gather the data
   again, though it currently does not remove the old data.
   
 $c: The connection class that can determine if the browser has aborted.  It  $c: The connection class that can determine if the browser has aborted.  It
 is used to short circuit this function so that it does not continue to   is used to short circuit this function so that it does not continue to 
Line 100  middlename, and PID : Key is $name.'stud Line 107  middlename, and PID : Key is $name.'stud
   
 -A hash pointer to each students section data : Key is $name.section  -A hash pointer to each students section data : Key is $name.section
   
   -If there was an error in dump, it will be returned in the hash.  See
   the error codes for dump in lonnet.  Also, an error key will be 
   generated if an abort occurs.
   
 =back  =back
   
 =cut  =cut
Line 109  sub DownloadClasslist { Line 120  sub DownloadClasslist {
     my ($courseDomain,$courseNumber)=split(/\_/,$courseID);      my ($courseDomain,$courseNumber)=split(/\_/,$courseID);
     my %classlist;      my %classlist;
   
     my $modifiedTime = &GetFileTimestamp($courseDomain, $courseNumber,      my $modifiedTime = &Apache::lonnet::GetFileTimestamp($courseDomain, $courseNumber,
                                      'classlist.db',                                                            'classlist.db', 
                                      $Apache::lonnet::perlvar{'lonUsersDir'});                                                           $Apache::lonnet::perlvar{'lonUsersDir'});
   
       # Always download the information if lastDownloadTime is set to
       # 'Not downloaded', otherwise it is only downloaded if the file
       # has been updated and has a more recent date stamp
     if($lastDownloadTime ne 'Not downloaded' &&      if($lastDownloadTime ne 'Not downloaded' &&
        $lastDownloadTime >= $modifiedTime && $modifiedTime >= 0) {         $lastDownloadTime >= $modifiedTime && $modifiedTime >= 0) {
           # Data is not gathered so return UpToDate as true.  This
           # will be interpreted in ProcessClasslist
         $classlist{'lastDownloadTime'}=time;          $classlist{'lastDownloadTime'}=time;
         $classlist{'UpToDate'} = 'true';          $classlist{'UpToDate'} = 'true';
         return \%classlist;          return \%classlist;
Line 128  sub DownloadClasslist { Line 144  sub DownloadClasslist {
     }      }
   
     foreach my $name (keys(%classlist)) {      foreach my $name (keys(%classlist)) {
         if((defined($c) && ($c->aborted())) {          if(defined($c) && ($c->aborted())) {
             $classlist{'error'}='aborted';              $classlist{'error'}='aborted';
             return \%classlist;              return \%classlist;
         }          }
Line 163  sub DownloadClasslist { Line 179  sub DownloadClasslist {
   
 =item &DownloadCourseInformation()  =item &DownloadCourseInformation()
   
 Dump of all the course information for a single student.  There is no  Dump of all the course information for a single student.  The data can be
 pruning of data, it is all stored in a hash and returned.  It also  pruned by making use of dumps regular expression arguement.  This function
   also takes a regular expression which it passes straight through to dump.  
   The data is no escaped, because it is done elsewhere.  It also
 checks the timestamp of the students course database file and only downloads  checks the timestamp of the students course database file and only downloads
 if it has been modified since the last download.  if it has been modified since the last download.
   
 =over 4  =over 4
   
 Input: $name, $courseID  Input: $namedata, $courseID, $lastDownloadTime, $WhatIWant
   
 $name: student name:domain  $namedata: student name:domain
   
 $courseID:  The id of the course  $courseID:  The id of the course
   
   $lastDownloadTime:  This is the date stamp for when this information was
   last gathered.  If it is set to 'Not downloaded', it will gather the data
   again, though it currently does not remove the old data.
   
   $WhatIWant:  Regular expression used to get selected data with dump
   
 Output: \%courseData  Output: \%courseData
   
 \%courseData:  A hash pointer to the raw data from the student's course  \%courseData:  A hash pointer to the raw data from the student's course
Line 190  sub DownloadCourseInformation { Line 214  sub DownloadCourseInformation {
     my %courseData;      my %courseData;
     my ($name,$domain) = split(/\:/,$namedata);      my ($name,$domain) = split(/\:/,$namedata);
   
     my $modifiedTime = &GetFileTimestamp($domain, $name,      my $modifiedTime = &Apache::lonnet::GetFileTimestamp($domain, $name,
                                       $courseID.'.db',                                         $courseID.'.db', 
                                       $Apache::lonnet::perlvar{'lonUsersDir'});                                        $Apache::lonnet::perlvar{'lonUsersDir'});
   
     if($lastDownloadTime >= $modifiedTime && $modifiedTime >= 0) {      if($lastDownloadTime >= $modifiedTime && $modifiedTime >= 0) {
           # Data is not gathered so return UpToDate as true.  This
           # will be interpreted in ProcessClasslist
         $courseData{$namedata.':lastDownloadTime'}=time;          $courseData{$namedata.':lastDownloadTime'}=time;
         $courseData{$namedata.':UpToDate'} = 'true';          $courseData{$namedata.':UpToDate'} = 'true';
         return \%courseData;          return \%courseData;
Line 202  sub DownloadCourseInformation { Line 228  sub DownloadCourseInformation {
   
     # Download course data      # Download course data
     if(!defined($WhatIWant)) {      if(!defined($WhatIWant)) {
           # set the regular expression to everything by setting it to period
         $WhatIWant = '.';          $WhatIWant = '.';
     }      }
     %courseData=&Apache::lonnet::dump($courseID, $domain, $name, $WhatIWant);      %courseData=&Apache::lonnet::dump($courseID, $domain, $name, $WhatIWant);
Line 210  sub DownloadCourseInformation { Line 237  sub DownloadCourseInformation {
   
     my %newData;      my %newData;
     foreach (keys(%courseData)) {      foreach (keys(%courseData)) {
           # need to have the keys to be prepended with the name:domain of the
           # student to reduce data collision later.
         $newData{$namedata.':'.$_} = $courseData{$_};          $newData{$namedata.':'.$_} = $courseData{$_};
     }      }
   
Line 223  sub DownloadCourseInformation { Line 252  sub DownloadCourseInformation {
 =head1 PROCESSING FUNCTIONS  =head1 PROCESSING FUNCTIONS
   
 These functions process all the data for all the students.  Also, they  These functions process all the data for all the students.  Also, they
 are the only functions that access the cache database for writing.  Thus  are the functions that access the cache database for writing the majority of
 they are the only functions that cache data.  The downloading and caching  the time.  The downloading and caching were separated to reduce problems 
 were separated to reduce problems with stopping downloading then can't  with stopping downloading then can't tie hash to database later.
 tie hash to database later.  
   
 =cut  =cut
   
Line 504  Takes data downloaded for a student and Line 532  Takes data downloaded for a student and
 stored in cache data.  The username, domain, class related date, PID,   stored in cache data.  The username, domain, class related date, PID, 
 full name, and section are all processed here.  full name, and section are all processed here.
   
   
 =over 4  =over 4
   
 Input: $cache, $classlist, $courseID, $ChartDB, $c  Input: $cache, $classlist, $courseID, $ChartDB, $c
Line 666  sub ProcessStudentData { Line 693  sub ProcessStudentData {
         return;          return;
     }      }
   
       # user name:domain was prepended earlier in DownloadCourseInformation
     foreach (keys %$courseData) {      foreach (keys %$courseData) {
         $cache->{$_}=$courseData->{$_};          $cache->{$_}=$courseData->{$_};
     }      }
Line 673  sub ProcessStudentData { Line 701  sub ProcessStudentData {
     return;      return;
 }  }
   
   =pod
   
   =item &ExtractStudentData()
   
   HISTORY: This function originally existed in every statistics module,
   and performed different tasks, the had some overlap.  Due to the need
   for the data from the different modules, they were combined into
   a single function.
   
   This function now extracts all the necessary course data for a student
   from what was downloaded from their homeserver.  There is some extra
   time overhead compared to the ProcessStudentInformation function, but
   it would have had to occurred at some point anyways.  This is now
   typically called while downloading the data it will process.  It is
   the brother function to ProcessStudentInformation.
   
   =over 4
   
   Input: $input, $output, $data, $name
   
   $input: A hash that contains the input data to be processed
   
   $output: A hash to contain the processed data
   
   $data: A hash containing the information on what is to be
   processed and how (basically).
   
   $name:  username:domain
   
   The input is slightly different here, but is quite simple.
   It is currently used where the $input, $output, and $data
   can and are often the same hashes, but they do not need
   to be.
   
   Output: None
   
   *NOTE:  There is no output, but an error message is stored away in the cache 
   data.  This is checked in &FormatStudentData().  The key username:domain:error 
   will only exist if an error occured.  The error is an error from 
   &DownloadCourseInformation().
   
   =back
   
   =cut
   
 sub ExtractStudentData {  sub ExtractStudentData {
     my ($input, $output, $data, $name)=@_;      my ($input, $output, $data, $name)=@_;
   
Line 861  sub LoadDiscussion { Line 934  sub LoadDiscussion {
 =head1 HELPER FUNCTIONS  =head1 HELPER FUNCTIONS
   
 These are just a couple of functions do various odd and end   These are just a couple of functions do various odd and end 
 jobs.  jobs.  There was also a couple of bulk functions added.  These are
   &DownloadStudentCourseData(), &DownloadStudentCourseDataSeparate(), and
   &CheckForResidualDownload().  These functions now act as the interface
   for downloading student course data.  The statistical modules should
   no longer make the calls to dump and download and process etc.  They
   make calls to these bulk functions to get their data.
   
 =cut  =cut
   
Line 1223  sub CheckForResidualDownload { Line 1301  sub CheckForResidualDownload {
     return 'OK';      return 'OK';
 }  }
   
 sub GetFileTimestamp {  
     my ($studentDomain,$studentName,$filename,$root)=@_;  
     $studentDomain=~s/\W//g;  
     $studentName=~s/\W//g;  
     my $subdir=$studentName.'__';  
     $subdir =~ s/(.)(.)(.).*/$1\/$2\/$3/;  
     my $proname="$studentDomain/$subdir/$studentName";  
     $proname .= '/'.$filename;  
     my @dir = &Apache::lonnet::dirlist($proname, $studentDomain, $studentName,  
                                        $root);  
     my $fileStat = $dir[0];  
     my @stats = split('&', $fileStat);  
     if($stats[0] ne 'empty' && $stats[0] ne 'no_such_dir') {  
         return $stats[9];  
     } else {  
         return -1;  
     }  
 }  
   
 # ----- END HELPER FUNCTIONS --------------------------------------------  # ----- END HELPER FUNCTIONS --------------------------------------------
   
 1;  1;

Removed from v.1.21  
changed lines
  Added in v.1.22


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>