version 1.29, 2002/09/03 02:22:40
|
version 1.45, 2003/02/13 14:49:16
|
Line 139 sub DownloadClasslist {
|
Line 139 sub DownloadClasslist {
|
%classlist=&Apache::lonnet::dump('classlist',$courseDomain, $courseNumber); |
%classlist=&Apache::lonnet::dump('classlist',$courseDomain, $courseNumber); |
foreach(keys (%classlist)) { |
foreach(keys (%classlist)) { |
if(/^(con_lost|error|no_such_host)/i) { |
if(/^(con_lost|error|no_such_host)/i) { |
return \%classlist; |
return; |
} |
} |
} |
} |
|
|
Line 218 sub DownloadCourseInformation {
|
Line 218 sub DownloadCourseInformation {
|
$courseID.'.db', |
$courseID.'.db', |
$Apache::lonnet::perlvar{'lonUsersDir'}); |
$Apache::lonnet::perlvar{'lonUsersDir'}); |
|
|
if($lastDownloadTime >= $modifiedTime && $modifiedTime >= 0) { |
if($lastDownloadTime ne 'Not downloaded' && |
|
$lastDownloadTime >= $modifiedTime && $modifiedTime >= 0) { |
# Data is not gathered so return UpToDate as true. This |
# Data is not gathered so return UpToDate as true. This |
# will be interpreted in ProcessClasslist |
# will be interpreted in ProcessClasslist |
$courseData{$namedata.':lastDownloadTime'}=time; |
$courseData{$namedata.':lastDownloadTime'}=time; |
Line 260 with stopping downloading then can not t
|
Line 261 with stopping downloading then can not t
|
|
|
# ----- PROCESSING FUNCTIONS --------------------------------------- |
# ----- PROCESSING FUNCTIONS --------------------------------------- |
|
|
|
|
|
|
|
=pod |
|
|
|
=item &get_sequence_assessment_data() |
|
|
|
AT THIS TIME THE USE OF THIS FUNCTION IS *NOT* RECOMMENDED |
|
|
|
Use lonnavmaps to build a data structure describing the order and |
|
assessment contents of each sequence in the current course. |
|
|
|
The returned structure is a hash reference. |
|
|
|
{ title => 'title', |
|
symb => 'symb', |
|
source => '/s/o/u/r/c/e', |
|
type => (container|assessment), |
|
contents => [ {},{},{},{} ], # only for container |
|
parts => [11,13,15], # only for assessment |
|
response_ids => [12,14,16] # only for assessment |
|
} |
|
|
|
$hash->{'contents'} is a reference to an array of hashes of the same structure. |
|
|
|
=cut |
|
|
|
sub get_sequence_assessment_data { |
|
return undef; |
|
my $fn=$ENV{'request.course.fn'}; |
|
&Apache::lonnet::logthis('filename = '.$fn); |
|
## |
|
## use navmaps |
|
my $navmap = Apache::lonnavmaps::navmap->new($fn.".bd",$fn."_parms.db",1,0); |
|
if (!defined($navmap)) { |
|
return 'Can not open Coursemap'; |
|
} |
|
my $iterator = $navmap->getIterator(undef, undef, undef, 1); |
|
## |
|
## Prime the pump |
|
## |
|
## We are going to loop until we run out of sequences/pages to explore for |
|
## resources. This means we have to start out with something to look |
|
## at. |
|
my $curRes = $iterator->next(); # BEGIN_MAP |
|
$curRes = $iterator->next(); # The sequence itself |
|
# |
|
my $title = $curRes->title(); |
|
my $symb = $curRes->symb(); |
|
my $src = $curRes->src(); |
|
# |
|
my @Nested_Sequences = (); # Stack of sequences, keeps track of depth |
|
my $top = { title => $title, |
|
symb => $symb, |
|
type => 'container', |
|
num_assess => 0, |
|
contents => [], }; |
|
push (@Nested_Sequences, $top); |
|
# |
|
# We need to keep track of which sequences contain homework problems |
|
# |
|
while (scalar(@Nested_Sequences)) { |
|
$curRes = $iterator->next(); |
|
my $currentmap = $Nested_Sequences[-1]; # Last one on the stack |
|
if ($curRes == $iterator->BEGIN_MAP()) { |
|
# get the map itself, instead of BEGIN_MAP |
|
$curRes = $iterator->next(); |
|
$title = $curRes->title(); |
|
$symb = $curRes->symb(); |
|
$src = $curRes->src(); |
|
my $newmap = { title => $title, |
|
src => $src, |
|
symb => $symb, |
|
type => 'container', |
|
num_assess => 0, |
|
contents => [], |
|
}; |
|
push (@{$currentmap->{'contents'}},$newmap); # this is permanent |
|
push (@Nested_Sequences, $newmap); # this is a stack |
|
next; |
|
} |
|
if ($curRes == $iterator->END_MAP()) { |
|
pop(@Nested_Sequences); |
|
next; |
|
} |
|
next if (! ref($curRes)); |
|
next if (! $curRes->is_problem() && !$curRes->randomout); |
|
# Okay, from here on out we only deal with assessments |
|
$title = $curRes->title(); |
|
$symb = $curRes->symb(); |
|
$src = $curRes->src(); |
|
my $parts = $curRes->parts(); |
|
my $assessment = { title => $title, |
|
src => $src, |
|
symb => $symb, |
|
type => 'assessment', |
|
}; |
|
push(@{$currentmap->{'contents'}},$assessment); |
|
$currentmap->{'num_assess'}++; |
|
} |
|
return $top; |
|
} |
|
|
=pod |
=pod |
|
|
=item &ProcessTopResourceMap() |
=item &ProcessTopResourceMap() |
Line 310 sub ProcessTopResourceMap {
|
Line 413 sub ProcessTopResourceMap {
|
} |
} |
|
|
my $oldkeys; |
my $oldkeys; |
|
delete $cache->{'OptionResponses'}; |
if(defined($cache->{'ResourceKeys'})) { |
if(defined($cache->{'ResourceKeys'})) { |
$oldkeys = $cache->{'ResourceKeys'}; |
$oldkeys = $cache->{'ResourceKeys'}; |
foreach (split(':::', $cache->{'ResourceKeys'})) { |
foreach (split(':::', $cache->{'ResourceKeys'})) { |
Line 322 sub ProcessTopResourceMap {
|
Line 426 sub ProcessTopResourceMap {
|
my (@sequences, @currentResource, @finishResource); |
my (@sequences, @currentResource, @finishResource); |
my ($currentSequence, $currentResourceID, $lastResourceID); |
my ($currentSequence, $currentResourceID, $lastResourceID); |
|
|
$currentResourceID=$hash{'ids_/res/'.$ENV{'request.course.uri'}}; |
$currentResourceID=$hash{'ids_'. |
|
&Apache::lonnet::clutter($ENV{'request.course.uri'})}; |
push(@currentResource, $currentResourceID); |
push(@currentResource, $currentResourceID); |
$lastResourceID=-1; |
$lastResourceID=-1; |
$currentSequence=-1; |
$currentSequence=-1; |
Line 486 sub ProcessTopResourceMap {
|
Line 591 sub ProcessTopResourceMap {
|
} |
} |
my @titleLength=split(//,$cache->{$currentSequence. |
my @titleLength=split(//,$cache->{$currentSequence. |
':title'}); |
':title'}); |
# $extra is 3 for problems correct and 3 for space |
# $extra is 5 for problems correct and 3 for space |
# between problems correct and problem output |
# between problems correct and problem output |
my $extra = 6; |
my $extra = 8; |
if(($totalProblems + $extra) > (scalar @titleLength)) { |
if(($totalProblems + $extra) > (scalar @titleLength)) { |
$cache->{$currentSequence.':columnWidth'}= |
$cache->{$currentSequence.':columnWidth'}= |
$totalProblems + $extra; |
$totalProblems + $extra; |
Line 517 sub ProcessTopResourceMap {
|
Line 622 sub ProcessTopResourceMap {
|
# big problem, need to handle. Next is probably wrong |
# big problem, need to handle. Next is probably wrong |
my $errorMessage = 'Big problem in '; |
my $errorMessage = 'Big problem in '; |
$errorMessage .= 'loncoursedata::ProcessTopLevelMap.'; |
$errorMessage .= 'loncoursedata::ProcessTopLevelMap.'; |
$errorMessage .= ' bighash to_$currentResourceID not defined!'; |
$errorMessage .= " bighash to_$currentResourceID not defined!"; |
&Apache::lonnet::logthis($errorMessage); |
&Apache::lonnet::logthis($errorMessage); |
last; |
if (!defined($currentResourceID)) {last;} |
} |
} |
my @nextResources=(); |
my @nextResources=(); |
foreach (split(/\,/,$hash{'to_'.$currentResourceID})) { |
foreach (split(/\,/,$hash{'to_'.$currentResourceID})) { |
Line 585 browser
|
Line 690 browser
|
Output: @names |
Output: @names |
|
|
@names: An array of students whose information has been processed, and are to |
@names: An array of students whose information has been processed, and are to |
be considered in an arbitrary order. |
be considered in an arbitrary order. The entries in @names are of the form |
|
username:domain. |
|
|
|
The values in $cache are as follows: |
|
|
|
*NOTE: for the following $name implies username:domain |
|
$name.':error' only defined if an error occured. Value |
|
contains the error message |
|
$name.':lastDownloadTime' unconverted time of the last update of a |
|
student\'s course data |
|
$name.'updateTime' coverted time of the last update of a |
|
student\'s course data |
|
$name.':username' username of a student |
|
$name.':domain' domain of a student |
|
$name.':fullname' full name of a student |
|
$name.':id' PID of a student |
|
$name.':Status' active/expired status of a student |
|
$name.':section' section of a student |
|
|
=back |
=back |
|
|
Line 608 sub ProcessClasslist {
|
Line 730 sub ProcessClasslist {
|
if($c->aborted()) { |
if($c->aborted()) { |
return (); |
return (); |
} |
} |
my $studentInformation = $classlist->{$name.':studentInformation'}, |
my $studentInformation = $classlist->{$name.':studentInformation'}; |
my $sectionData = $classlist->{$name.':sections'}, |
my $date = $classlist->{$name}; |
my $date = $classlist->{$name}, |
|
my ($studentName,$studentDomain) = split(/\:/,$name); |
my ($studentName,$studentDomain) = split(/\:/,$name); |
|
|
$cache->{$name.':username'}=$studentName; |
$cache->{$name.':username'}=$studentName; |
Line 645 sub ProcessClasslist {
|
Line 766 sub ProcessClasslist {
|
$courseID=~s/^(\w)/\/$1/; |
$courseID=~s/^(\w)/\/$1/; |
|
|
my $sec=''; |
my $sec=''; |
|
my $sectionData = $classlist->{$name.':sections'}; |
foreach my $key (keys (%$sectionData)) { |
foreach my $key (keys (%$sectionData)) { |
my $value = $sectionData->{$key}; |
my $value = $sectionData->{$key}; |
if ($key=~/^$courseID(?:\/)*(\w+)*\_st$/) { |
if ($key=~/^$courseID(?:\/)*(\w+)*\_st$/) { |
Line 652 sub ProcessClasslist {
|
Line 774 sub ProcessClasslist {
|
if($key eq $courseID.'_st') { |
if($key eq $courseID.'_st') { |
$tempsection=''; |
$tempsection=''; |
} |
} |
my ($dummy,$roleend,$rolestart)=split(/\_/,$value); |
my (undef,$roleend,$rolestart)=split(/\_/,$value); |
if($roleend eq $end && $rolestart eq $start) { |
if($roleend eq $end && $rolestart eq $start) { |
$sec = $tempsection; |
$sec = $tempsection; |
last; |
last; |
Line 1066 sub ProcessFullName {
|
Line 1188 sub ProcessFullName {
|
my ($lastname, $generation, $firstname, $middlename)=@_; |
my ($lastname, $generation, $firstname, $middlename)=@_; |
my $Str = ''; |
my $Str = ''; |
|
|
|
# Strip whitespace preceeding & following name components. |
|
$lastname =~ s/(\s+$|^\s+)//g; |
|
$generation =~ s/(\s+$|^\s+)//g; |
|
$firstname =~ s/(\s+$|^\s+)//g; |
|
$middlename =~ s/(\s+$|^\s+)//g; |
|
|
if($lastname ne '') { |
if($lastname ne '') { |
$Str .= $lastname.' '; |
$Str .= $lastname; |
if($generation ne '') { |
$Str .= ' '.$generation if ($generation ne ''); |
$Str .= $generation; |
$Str .= ','; |
} else { |
$Str .= ' '.$firstname if ($firstname ne ''); |
chop($Str); |
$Str .= ' '.$middlename if ($middlename ne ''); |
} |
|
$Str .= ', '; |
|
if($firstname ne '') { |
|
$Str .= $firstname.' '; |
|
} |
|
if($middlename ne '') { |
|
$Str .= $middlename; |
|
} else { |
|
chop($Str); |
|
if($firstname eq '') { |
|
chop($Str); |
|
} |
|
} |
|
} else { |
} else { |
if($firstname ne '') { |
$Str .= $firstname if ($firstname ne ''); |
$Str .= $firstname.' '; |
$Str .= ' '.$middlename if ($middlename ne ''); |
} |
$Str .= ' '.$generation if ($generation ne ''); |
if($middlename ne '') { |
|
$Str .= $middlename.' '; |
|
} |
|
if($generation ne '') { |
|
$Str .= $generation; |
|
} else { |
|
chop($Str); |
|
} |
|
} |
} |
|
|
return $Str; |
return $Str; |
Line 1176 sub DownloadStudentCourseData {
|
Line 1283 sub DownloadStudentCourseData {
|
my $WhatIWant; |
my $WhatIWant; |
$WhatIWant = '(^version:|'; |
$WhatIWant = '(^version:|'; |
$WhatIWant .= '^\d+:.+?:(resource\.\d+\.'; |
$WhatIWant .= '^\d+:.+?:(resource\.\d+\.'; |
$WhatIWant .= '(solved|tries|previous|awarded|(\d+\.submission))\s*$'; |
$WhatIWant .= '(solved|tries|previous|awarded|(\d+\.submission))\s*$';#' |
$WhatIWant .= '|timestamp)'; |
$WhatIWant .= '|timestamp)'; |
$WhatIWant .= ')'; |
$WhatIWant .= ')'; |
# $WhatIWant = '.'; |
# $WhatIWant = '.'; |
Line 1246 sub DownloadStudentCourseDataSeparate {
|
Line 1353 sub DownloadStudentCourseDataSeparate {
|
my $WhatIWant; |
my $WhatIWant; |
$WhatIWant = '(^version:|'; |
$WhatIWant = '(^version:|'; |
$WhatIWant .= '^\d+:.+?:(resource\.\d+\.'; |
$WhatIWant .= '^\d+:.+?:(resource\.\d+\.'; |
$WhatIWant .= '(solved|tries|previous|awarded|(\d+\.submission))\s*$'; |
$WhatIWant .= '(solved|tries|previous|awarded|(\d+\.submission))\s*$';#' |
$WhatIWant .= '|timestamp)'; |
$WhatIWant .= '|timestamp)'; |
$WhatIWant .= ')'; |
$WhatIWant .= ')'; |
|
|
&CheckForResidualDownload($courseID, $cacheDB, $students, $c); |
&CheckForResidualDownload($cacheDB, 'true', 'true', $courseID, $r, $c); |
|
|
my $studentCount = scalar(@$students); |
my $studentCount = scalar(@$students); |
if($status eq 'true') { |
if($status eq 'true') { |
Line 1384 sub CheckForResidualDownload {
|
Line 1491 sub CheckForResidualDownload {
|
return 'OK'; |
return 'OK'; |
} |
} |
|
|
|
################################################ |
|
################################################ |
|
|
|
=pod |
|
|
|
=item &get_classlist(); |
|
|
|
Retrieve the classist of a given class or of the current class. Student |
|
information is returned from the classlist.db file and, if needed, |
|
from the students environment. |
|
|
|
Optional arguments are $cid, $cdom, and $cnum (course id, course domain, |
|
and course number, respectively). Any omitted arguments will be taken |
|
from the current environment ($ENV{'request.course.id'}, |
|
$ENV{'course.'.$cid.'.domain'}, and $ENV{'course.'.$cid.'.num'}). |
|
|
|
Returns a reference to a hash which contains: |
|
keys '$sname:$sdom' |
|
values [$end,$start,$id,$section,$fullname] |
|
|
|
=cut |
|
|
|
################################################ |
|
################################################ |
|
|
|
sub get_classlist { |
|
my ($cid,$cdom,$cnum) = @_; |
|
$cid = $cid || $ENV{'request.course.id'}; |
|
$cdom = $cdom || $ENV{'course.'.$cid.'.domain'}; |
|
$cnum = $cnum || $ENV{'course.'.$cid.'.num'}; |
|
my $now = time; |
|
# |
|
my %classlist=&Apache::lonnet::dump('classlist',$cdom,$cnum); |
|
while (my ($student,$info) = each(%classlist)) { |
|
return undef if ($student =~ /^(con_lost|error|no_such_host)/i); |
|
my ($sname,$sdom) = split(/:/,$student); |
|
my @Values = split(/:/,$info); |
|
my ($end,$start,$id,$section,$fullname); |
|
if (@Values > 2) { |
|
($end,$start,$id,$section,$fullname) = @Values; |
|
} else { # We have to get the data ourselves |
|
($end,$start) = @Values; |
|
$section = &Apache::lonnet::getsection($sdom,$sname,$cid); |
|
my %info=&Apache::lonnet::get('environment', |
|
['firstname','middlename', |
|
'lastname','generation','id'], |
|
$sdom, $sname); |
|
my ($tmp) = keys(%info); |
|
if ($tmp =~/^(con_lost|error|no_such_host)/i) { |
|
$fullname = 'not available'; |
|
$id = 'not available'; |
|
&Apache::lonnet::logthis('unable to retrieve environment '. |
|
'for '.$sname.':'.$sdom); |
|
} else { |
|
$fullname = &ProcessFullName(@info{qw/lastname generation |
|
firstname middlename/}); |
|
$id = $info{'id'}; |
|
} |
|
# Update the classlist with this students information |
|
if ($fullname ne 'not available') { |
|
my $enrolldata = join(':',$end,$start,$id,$section,$fullname); |
|
my $reply=&Apache::lonnet::cput('classlist', |
|
{$student => $enrolldata}, |
|
$cdom,$cnum); |
|
if ($reply !~ /^(ok|delayed)/) { |
|
&Apache::lonnet::logthis('Unable to update classlist for '. |
|
'student '.$sname.':'.$sdom. |
|
' error:'.$reply); |
|
} |
|
} |
|
} |
|
my $status='Expired'; |
|
if(((!$end) || $now < $end) && ((!$start) || ($now > $start))) { |
|
$status='Active'; |
|
} |
|
$classlist{$student} = |
|
[$sdom,$sname,$end,$start,$id,$section,$fullname,$status]; |
|
} |
|
if (wantarray()) { |
|
return (\%classlist,['domain','username','end','start','id', |
|
'section','fullname','status']); |
|
} else { |
|
return \%classlist; |
|
} |
|
} |
|
|
# ----- END HELPER FUNCTIONS -------------------------------------------- |
# ----- END HELPER FUNCTIONS -------------------------------------------- |
|
|
1; |
1; |
__END__ |
__END__ |
|
|
|
|