--- loncom/interface/lonstatistics.pm 2002/07/25 19:30:24 1.31 +++ loncom/interface/lonstatistics.pm 2002/07/25 21:23:51 1.32 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonstatistics.pm,v 1.31 2002/07/25 19:30:24 minaeibi Exp $ +# $Id: lonstatistics.pm,v 1.32 2002/07/25 21:23:51 stredwic Exp $ # # Copyright Michigan State University Board of Trustees # @@ -94,8 +94,6 @@ sub ProcessFormData{ } else { $cache->{'StudentAssessmentMove'} = 'selected'; } - &CheckFormElement($cache, 'StudentAssessmentMap', 'StudentAssessmentMap', - 'All Maps'); &CheckFormElement($cache, 'StudentAssessmentStudent', 'StudentAssessmentStudent', 'All Students'); $cache->{'StudentAssessmentStudent'} = @@ -195,8 +193,57 @@ sub SortStudents { return \@order; } +=pod + +=item &SpaceColumns() + +Determines the width of all the columns in the chart. It is based on +the max of the data for that column and its header. + +=over 4 + +Input: $students, $studentInformation, $headings, $ChartDB + +$students: An array pointer to a list of students (username:domain) + +$studentInformatin: The type of data for the student information. It is +used as part of the key in $CacheData. + +$headings: The name of the student information columns. + +$ChartDB: The name of the cache database which is opened for read/write. + +Output: None - All data stored in cache. + +=back + +=cut + +sub SpaceColumns { + my ($students,$studentInformation,$headings,$cache)=@_; + + # Initialize Lengths + for(my $index=0; $index<(scalar @$headings); $index++) { + my @titleLength=split(//,$headings->[$index]); + $cache->{$studentInformation->[$index].':columnWidth'}= + scalar @titleLength; + } + + foreach my $name (@$students) { + foreach (@$studentInformation) { + my @dataLength=split(//,$cache->{$name.':'.$_}); + my $length=(scalar @dataLength); + if($length > $cache->{$_.':columnWidth'}) { + $cache->{$_.':columnWidth'}=$length; + } + } + } + + return; +} + sub PrepareData { - my ($c, $cacheDB)=@_; + my ($c, $cacheDB, $studentInformation, $headings)=@_; # Test for access to the cache data my $courseID=$ENV{'request.course.id'}; @@ -255,6 +302,8 @@ sub PrepareData { &ProcessFormData(\%cache); my $students = &SortStudents(\%cache); + &SpaceColumns($students, $studentInformation, $headings, \%cache); + $cache{'updateTime:columnWidth'}=24; if($cache{'download'} ne 'false') { my $who = $cache{'download'}; @@ -291,11 +340,6 @@ sub PrepareData { return 'aborted'; } - if($c->aborted()) { - untie(%cache); - return 'aborted'; - } - untie(%cache); return ('OK', $students); @@ -359,7 +403,7 @@ sub setbgcolor { } sub BuildClasslist { - my ($cacheDB,$students,$studentInformation,$headings,$spacePadding)=@_; + my ($cacheDB,$students,$studentInformation,$headings)=@_; my %cache; unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) { @@ -372,51 +416,42 @@ sub BuildClasslist { my $displayString = 'DISPLAYDATA '."\n"; - $Str .= &Apache::lonhtmlcommon::CreateStudentInformationHeadings(\%cache, - $studentInformation, - $headings, - $displayString); - $Str .= ''; - $Str .= ''; - $Str .= 'Last Updated '."\n"; + $Str .= &Apache::lonhtmlcommon::CreateHeadings(\%cache, $studentInformation, + $headings, $displayString); $Str .= ''."\n"; my $alternate=0; foreach (@$students) { my ($username, $domain) = split(':', $_); if($alternate) { - $Str .= ''; + $Str .= ''; } else { - $Str .= ''; + $Str .= ''; } $alternate = ($alternate + 1) % 2; foreach my $data (@$studentInformation) { + $Str .= ''; if($data eq 'fullname') { $Str .= ''; - #$Str .= 'Student Assessment'.'">'; - } - - $Str .= $cache{$_.':'.$data}.' '; - - if($data eq 'fullname') { + $Str .= $cache{$_.':'.$data}.' '; $Str .= ''; + } elsif($data eq 'updateTime') { + $Str .= ''; + $Str .= $cache{$_.':'.$data}.' '; + $Str .= ' '; + } else { + $Str .= $cache{$_.':'.$data}.' '; } - $Str .= ''; + $Str .= ''."\n"; } - - $Str .= ''; - my $downloadTime = $cache{$_.':lastDownloadTime'}; - if($downloadTime ne 'Not downloaded') { - $downloadTime = localtime($downloadTime); - } - $Str .= $downloadTime; - - $Str .= ' '."\n"; } + $Str .= ''."\n"; $Str .= ''."\n"; untie(%cache); @@ -428,9 +463,11 @@ sub BuildStatistics { my ($r)=@_; my $c = $r->connection; - my @studentInformation=('fullname','section','id','domain','username'); - my @headings=('Full Name', 'Section', 'PID', 'Domain', 'User Name'); - my $spacePadding = ' '; + my @studentInformation=('fullname','section','id','domain','username', + 'updateTime'); + my @headings=('Full Name', 'Section', 'PID', 'Domain', 'User Name', + 'Last Updated'); + my $spacing = ' '; my %reports = ('classlist' => 'Class list', 'problem_statistics' => 'Problem Statistics', 'student_assessment' => 'Student Assessment', @@ -442,7 +479,9 @@ sub BuildStatistics { "_$ENV{'user.domain'}_$courseID\_statistics.db"; my %color=&setbgcolor(0); - my ($returnValue, $students) = &PrepareData($c, $cacheDB); + my ($returnValue, $students) = &PrepareData($c, $cacheDB, + \@studentInformation, + \@headings); if($returnValue ne 'OK') { $r->print(''.$returnValue."\n".''); return OK; @@ -487,9 +526,13 @@ sub BuildStatistics { } elsif($GoToPage eq 'Student Assessment') { $r->print( &Apache::lonstudentassessment::BuildStudentAssessmentPage($cacheDB, - $students, - $courseID, - $c)); + $students, + $courseID, + 'Statistics', + \@headings, + $spacing, + \@studentInformation, + $r, $c)); } elsif($GoToPage eq 'Analyze') { $r->print(&Apache::lonproblemanalysis::BuildAnalyzePage($cacheDB, $students, @@ -500,7 +543,7 @@ sub BuildStatistics { &Apache::lonproblemstatistics::BuildWrongGraph($r); } elsif($GoToPage eq 'Class list') { $r->print(&BuildClasslist($cacheDB, $students, \@studentInformation, - \@headings, $spacePadding)); + \@headings)); } $r->print(''."\n");