[LON-CAPA-cvs] cvs: loncom /interface loncoursedata.pm /lonnet/perl lonnet.pm
stredwic
lon-capa-cvs@mail.lon-capa.org
Wed, 28 Aug 2002 21:50:27 -0000
This is a MIME encoded message
--stredwic1030571427
Content-Type: text/plain
stredwic Wed Aug 28 17:50:27 2002 EDT
Modified files:
/loncom/interface loncoursedata.pm
/loncom/lonnet/perl lonnet.pm
Log:
First, I think there was a typo in the last submit for loncoursedata. One
too many paranthesis. Fixed that. Moved GetDatestamp function to lonnet,
like Guy wanted a while ago. Added documentation to loncoursedata.
--stredwic1030571427
Content-Type: text/plain
Content-Disposition: attachment; filename="stredwic-20020828175027.txt"
Index: loncom/interface/loncoursedata.pm
diff -u loncom/interface/loncoursedata.pm:1.21 loncom/interface/loncoursedata.pm:1.22
--- loncom/interface/loncoursedata.pm:1.21 Wed Aug 28 14:29:22 2002
+++ loncom/interface/loncoursedata.pm Wed Aug 28 17:50:27 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# (Publication Handler
#
-# $Id: loncoursedata.pm,v 1.21 2002/08/28 18:29:22 matthew Exp $
+# $Id: loncoursedata.pm,v 1.22 2002/08/28 21:50:27 stredwic Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -35,12 +35,13 @@
=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
Apache::Constants qw(:common :http)
Apache::lonnet()
+ Apache::lonhtmlcommon
HTML::TokeParser
GDBM_File
@@ -59,11 +60,8 @@
=head1 DOWNLOAD INFORMATION
-This section contains all the files that get data from other servers
-and/or itself. There is one function that has a call to get remote
-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.
+This section contains all the functions that get data from other servers
+and/or itself.
=cut
@@ -74,8 +72,15 @@
=item &DownloadClasslist()
Collects lastname, generation, middlename, firstname, PID, and section for each
-student from their environment database. The list of students is built from
-collecting a classlist for the course that is to be displayed.
+student from their environment database. The section data is also download, though
+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
@@ -83,7 +88,9 @@
$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
is used to short circuit this function so that it does not continue to
@@ -100,6 +107,10 @@
-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
=cut
@@ -109,12 +120,17 @@
my ($courseDomain,$courseNumber)=split(/\_/,$courseID);
my %classlist;
- my $modifiedTime = &GetFileTimestamp($courseDomain, $courseNumber,
- 'classlist.db',
- $Apache::lonnet::perlvar{'lonUsersDir'});
-
+ my $modifiedTime = &Apache::lonnet::GetFileTimestamp($courseDomain, $courseNumber,
+ 'classlist.db',
+ $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' &&
$lastDownloadTime >= $modifiedTime && $modifiedTime >= 0) {
+ # Data is not gathered so return UpToDate as true. This
+ # will be interpreted in ProcessClasslist
$classlist{'lastDownloadTime'}=time;
$classlist{'UpToDate'} = 'true';
return \%classlist;
@@ -128,7 +144,7 @@
}
foreach my $name (keys(%classlist)) {
- if((defined($c) && ($c->aborted())) {
+ if(defined($c) && ($c->aborted())) {
$classlist{'error'}='aborted';
return \%classlist;
}
@@ -163,19 +179,27 @@
=item &DownloadCourseInformation()
-Dump of all the course information for a single student. There is no
-pruning of data, it is all stored in a hash and returned. It also
+Dump of all the course information for a single student. The data can be
+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
if it has been modified since the last download.
=over 4
-Input: $name, $courseID
+Input: $namedata, $courseID, $lastDownloadTime, $WhatIWant
-$name: student name:domain
+$namedata: student name:domain
$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
\%courseData: A hash pointer to the raw data from the student's course
@@ -190,11 +214,13 @@
my %courseData;
my ($name,$domain) = split(/\:/,$namedata);
- my $modifiedTime = &GetFileTimestamp($domain, $name,
+ my $modifiedTime = &Apache::lonnet::GetFileTimestamp($domain, $name,
$courseID.'.db',
$Apache::lonnet::perlvar{'lonUsersDir'});
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.':UpToDate'} = 'true';
return \%courseData;
@@ -202,6 +228,7 @@
# Download course data
if(!defined($WhatIWant)) {
+ # set the regular expression to everything by setting it to period
$WhatIWant = '.';
}
%courseData=&Apache::lonnet::dump($courseID, $domain, $name, $WhatIWant);
@@ -210,6 +237,8 @@
my %newData;
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{$_};
}
@@ -223,10 +252,9 @@
=head1 PROCESSING FUNCTIONS
These functions process all the data for all the students. Also, they
-are the only functions that access the cache database for writing. Thus
-they are the only functions that cache data. The downloading and caching
-were separated to reduce problems with stopping downloading then can't
-tie hash to database later.
+are the functions that access the cache database for writing the majority of
+the time. The downloading and caching were separated to reduce problems
+with stopping downloading then can't tie hash to database later.
=cut
@@ -504,7 +532,6 @@
stored in cache data. The username, domain, class related date, PID,
full name, and section are all processed here.
-
=over 4
Input: $cache, $classlist, $courseID, $ChartDB, $c
@@ -666,6 +693,7 @@
return;
}
+ # user name:domain was prepended earlier in DownloadCourseInformation
foreach (keys %$courseData) {
$cache->{$_}=$courseData->{$_};
}
@@ -673,6 +701,51 @@
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 {
my ($input, $output, $data, $name)=@_;
@@ -861,7 +934,12 @@
=head1 HELPER FUNCTIONS
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
@@ -1221,25 +1299,6 @@
}
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 --------------------------------------------
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.274 loncom/lonnet/perl/lonnet.pm:1.275
--- loncom/lonnet/perl/lonnet.pm:1.274 Wed Aug 28 15:48:57 2002
+++ loncom/lonnet/perl/lonnet.pm Wed Aug 28 17:50:27 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network
# TCP networking package
#
-# $Id: lonnet.pm,v 1.274 2002/08/28 19:48:57 albertel Exp $
+# $Id: lonnet.pm,v 1.275 2002/08/28 21:50:27 stredwic Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -2455,6 +2455,30 @@
my @emptyResults = ();
push(@emptyResults, 'missing domain');
return split(':',@emptyResults);
+ }
+}
+
+# --------------------------------------------- GetFileTimestamp
+# This function utilizes dirlist and returns the date stamp for
+# when it was last modified. It will also return an error of -1
+# if an error occurs
+
+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;
}
}
--stredwic1030571427--