' );
- return;
- }
- my $shome=&Apache::lonnet::homeserver( $sname,$sdom );
- my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$cid,$shome );
- my %result = ();
- my $ResId;
- my $PrOrd;
- my $Code;
- my $Tries;
- my $TotalTries = 0;
- my $ParCr = 0;
- my $Wrongs;
- my %TempHash;
- my $Version;
- my $LatestVersion;
- my $PtrTry='';
- my $PtrCod='';
- my $SetNo=0;
- my $Str = "\n".'
'.
- "\n".'
'.
- "\n".'
#
'.
- "\n".'
Set Title
'.
- "\n".'
Results
'.
- "\n".'
Tries
'.
- "\n".'
';
- unless ($reply=~/^error\:/) {
- foreach (split(/\&/,$reply)){
- my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));
- $result{$name}=$value;
- }
- foreach my $CurCol (@cols) {
- if (!$CurCol){
- my $Set=&Apache::lonnet::declutter($hash{'map_id_'.$1});
- if ( $Set ) {
- $SetNo++;
- $Str .= "\n"."
'.
- ' #Stdnts: Total Number of Students opened the problem. '.
- ' Tries : Total Number of Tries for solving the problem. '.
- ' Mod : Maximunm Number of Tries for solving the problem. '.
- ' Mean : Average Number of the tries. [ Tries / #Stdnts ] '.
- ' #YES : Number of students solved the problem correctly. '.
- ' #yes : Number of students solved the problem by override. '.
- ' %Wrng : Percentage of students tried to solve the problem but'.
- ' still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ] '.
-# ' DoDiff : Degree of Difficulty of the problem. [ Tries/(#YES+#yes+0.1) ] '.
- ' DoDiff : Degree of Difficulty of the problem. [ 1 - ((#YES+#yes) / Tries) ] '.
- ' S.D. : Standard Deviation of the tries.'.
- '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1)'.
- ' where Xi denotes every student\'s tries ] '.
- ' Skew. : Skewness of the students tries.'.
- ' [ (sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3) ] '.
-
-# ' Dis.F. : Discrimination Factor. [ Sum of Partial Credits Awarded / Total Number of Tries in %27 upper and lower students]'.
- '
';
-
- $r->print($Ptr);
- $r->rflush();
-
- if ((-e "$CacheDB")&&($ENV{'form.sort'} ne 'Recalculate Statistics')) {
- if (tie(%CachData,'GDBM_File',"$CacheDB",&GDBM_READER,0640)) {
- tie(%GraphDat,'GDBM_File',$GraphDB,&GDBM_WRCREAT,0640);
- &Cache_Statistics();
- }
- else {
- $r->print("Unable to tie hash to db file");
+
+=pod
+
+=item &SortStudents()
+
+Determines which students to display and in which order. Which are
+displayed are determined by their status(active/expired). The order
+is determined by the sort button pressed (default to username). The
+type of sorting is username, lastname, or section.
+
+=over 4
+
+Input: $students, $CacheData
+
+$students: A array pointer to a list of students (username:domain)
+
+$CacheData: A pointer to the hash tied to the cached data
+
+Output: \@order
+
+@order: An ordered list of students (username:domain)
+
+=back
+
+=cut
+
+sub SortStudents {
+ my ($cache)=@_;
+
+ my @students = split(':::',$cache->{'NamesOfStudents'});
+ my @sorted1Students=();
+ foreach (@students) {
+ if($cache->{'Status'} eq 'Any' ||
+ $cache->{$_.':Status'} eq $cache->{'Status'}) {
+ push(@sorted1Students, $_);
}
}
- else {
- if (tie(%CachData,'GDBM_File',$CacheDB,&GDBM_WRCREAT,0640)) {
- tie(%DiscFac,'GDBM_File',$CachDisFac,&GDBM_WRCREAT,0640);
- tie(%GraphDat,'GDBM_File',$GraphDB,&GDBM_WRCREAT,0640);
- foreach (keys %DiscFac) {delete $CachData{$_};}
- foreach (keys %CachData) {delete $CachData{$_};}
- $DiscFlag=0;
- &Build_Statistics();
- }
- else {
- $r->print("Unable to tie hash to db file");
- }
+
+ my $sortBy = '';
+ if(defined($cache->{'sort'})) {
+ $sortBy = ':'.$cache->{'sort'};
}
- #$r->print('Total instances of the problems : '.($p_count*($#students+1)));
+ my @order = sort { $cache->{$a.$sortBy} cmp $cache->{$b.$sortBy} ||
+ $cache->{$a.':fullname'} cmp $cache->{$b.':fullname'} }
+ @sorted1Students;
- untie(%CachData);
- untie(%GraphDat);
- untie(%DiscFac);
+ return \@order;
}
+=pod
-# ------------------------------------- Find the section of student in a course
+=item &SpaceColumns()
-sub usection {
- my ($udom,$unam,$courseid)=@_;
- $courseid=~s/\_/\//g;
- $courseid=~s/^(\w)/\/$1/;
- map {
- my ($key,$value)=split(/\=/,$_);
- $key=&Apache::lonnet::unescape($key);
- if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) {
- my $section=$1;
- if ($key eq $courseid.'_st') { $section=''; }
- my ($dummy,$end,$start)=split(/\_/,&Apache::lonnet::unescape($value));
- $section=($section) ? $section : '(none)';
-# $section=(int($section)) ? int($section) : $section;
-# $r->print($unam.'...'.$section.' ');
- return $section;
- }
- } split(/\&/,&Apache::lonnet::reply('dump:'.$udom.':'.$unam.':roles',
- &Apache::lonnet::homeserver($unam,$udom)));
- return '';
-}
+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
-# ------ Dump the Student's DB file and handling the data for statistics table
+Input: $students, $studentInformation, $headings, $ChartDB
-sub ExtractStudentData {
- my ($student,$coid)=@_;
- my ($sname,$sdom) = split( /\:/, $student );
- my $shome=&Apache::lonnet::homeserver( $sname,$sdom );
- my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$coid,$shome );
- my %result = ();
- my $ResId;
- my $PrOrd;
- my $Dis = '';
- my $Code;
- my $Tries;
- my $ParCr;
- my $TotalTries = 0;
- my $TotalOpend = 0;
- my $ProbSolved = 0;
- my $ProbTot = 0;
- my $TimeTot = 0;
- my $TotParCr = 0;
- my $Wrongs;
- my %TempHash;
- my $Version;
- my $LatestVersion;
- my $SecLimit;
- my $MapLimit;
- unless ($reply=~/^error\:/) {
- foreach (split(/\&/,$reply)) {
- my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));
- $result{$name}=$value;
- }
- foreach my $CurCol(@cols) {
- ($PrOrd,$ResId)=split(/\:/,$CurCol);
- if ( !$CurCol ) { next; }
- $ResId=~/(\d+)\.(\d+)/;
- my $MapId=$1;
- my $PrbId=$2;
- my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$MapId} );
- if ( $CurMap ne 'All Maps' ) {
- my ( $ResMap, $NameMap ) = split(/\=/,$CurMap);
- if ( $Map ne $ResMap ) { next; }
- }
- my $meta=$hash{'src_'.$ResId};
- my $PartNo = 0;
- $Dis .= ':';
- undef %TempHash;
- foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
- if ($_=~/^stores\_(\d+)\_tries$/) {
- my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
- if ( $TempHash{"$Part"} eq '' ) {
- $TempHash{"$Part"} = $Part;
- $TempHash{$PartNo}=$Part;
- $TempHash{"$Part.Code"} = 'U';
- $TempHash{"$Part.PrOrd"} = $PrOrd+$PartNo;
- $PartNo++;
- }
- }
- }
+$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.
- my $Prob = $Map.'___'.$PrbId.'___'.
- &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
- $Code='U';
- $Tries = 0;
- $ParCr = 0;
- $Wrongs = 0;
- $LatestVersion = $result{"version:$Prob"};
-
- if ( $LatestVersion ) {
- for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
- my $vkeys = $result{"$Version:keys:$Prob"};
- my @keys = split(/\:/,$vkeys);
-
- foreach my $Key (@keys) {
- if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
- my $Part = $1;
- $Tries = $result{"$Version:$Prob:resource.$Part.tries"};
- $ParCr = $result{"$Version:$Prob:resource.$Part.awarded"};
- my $Time = $result{"$Version:$Prob:timestamp"};
- $TempHash{"$Part.Time"} = ($Time) ? $Time : 0;
- $TempHash{"$Part.Tries"} = ($Tries) ? $Tries : 0;
- $TempHash{"$Part.ParCr"} = ($ParCr) ? $ParCr : 0;
- $TotalTries += $TempHash{"$Part.Tries"};
- $TotParCr += $TempHash{"$Part.ParCr"};
-#$r->print($Version.'---'.$Prob.'==='.$Time.' ');
- my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
- if ( $Val eq 'correct_by_student' )
- { $Wrongs = $Tries - 1; $Code = 'C'; }
- elsif ( $Val eq 'correct_by_override' )
- { $Wrongs = $Tries - 1; $Code = 'O'; }
- elsif ( $Val eq 'incorrect_attempted' ||
- $Val eq 'incorrect_by_override' )
- { $Wrongs = $Tries; $Code = 'I'; }
- $TempHash{"$Part.Code"} = $Code;
- $TempHash{"$Part.Wrongs"} = $Wrongs;
- }
- }
- }
- for ( my $n = 0; $n < $PartNo; $n++ ) {
- my $part = $TempHash{$n};
- my $Yes = 0;
- if ( $TempHash{$part.'.Code'} eq 'C' ||
- $TempHash{$part.'.Code'} eq 'O' )
- {$ProbSolved++;$Yes=1;}
-# my $ptr = "$hash{'title_'.$ResId}";
- my $ptr = $TempHash{$part.'.PrOrd'}.':'.$ResId;
- if ( $PartNo > 1 ) {
- $ptr .= "*(part $part)";
- $Dis .= ':';
- }
- my $Fac = ($TempHash{"$part.Tries"}) ?
- ($TempHash{"$part.ParCr"}/$TempHash{"$part.Tries"}) : 0;
- my $DisF;
- if ( $Fac > 0 && $Fac < 1 ) {
- $DisF = sprintf( "%.4f", $Fac );
- }
- else {$DisF = $Fac;}
-# $DisF .= '+'.$TempHash{"$part.Time"};
- $TimeTot += $TempHash{"$part.Time"};
- $Dis .= $ptr.'*'.$ResId.'='.$DisF.'+'.$Yes;
- $ptr .= ":$TempHash{$part.'.Tries'}".
- ":$TempHash{$part.'.Wrongs'}".
- ":$TempHash{$part.'.Code'}";
- push (@list, $ptr);
- $TotalOpend++;
- $ProbTot++;
- }
+=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;
}
- #else {
- #for(my $n=0; $n<$PartNo; $n++) {
- # push (@list, "$hash{'title_'.$ResId}*$ResId:0:0:U");
- # $ProbTot++;
- #}
- #}
}
- if ( $TotalTries ) {
- my $DisFac = ( $TotalTries ) ? ($TotParCr/$TotalTries) : 0;
-# my $DisFactor = int(sprintf( "%.4f", $DisFac ) * 100);
- my $DisFactor = sprintf( "%.4f", $DisFac );
- my $time;
- if ($ProbSolved){
- $time = int(($TimeTot/$ProbSolved)-10000000);
- }
- $DiscFac{($DisFactor.':'.$sname.':'.$ProbTot.':'.$TotalOpend.':'.
- $TotalTries.':'.$ProbSolved.':'.$time)}=$Dis;
-#$r->print($DisFactor.$sname.' --- Dis= '.$Dis.' ');
- }
}
- #$r->print($sname.' PrCr= '.$TotParCr.' Slvd= '.$ProbSolved.' Tries='.$TotalTries.' ');
+
+ return;
}
+sub PrepareData {
+ my ($c, $cacheDB, $studentInformation, $headings,$r)=@_;
-# ------------------------------------------------------------ Build page table
-sub tracetable {
- my ($rid,$beenhere)=@_;
- $rid=~/(\d+)\.(\d+)/;
- $maps{&Apache::lonnet::declutter($hash{'map_id_'.$1})}='';#$hash{'title_'.$rid};
- #$maps{$HWN}=$hash{'title_'.$rid};
- unless ($beenhere=~/\&$rid\&/) {
- $beenhere.=$rid.'&';
- if (defined($hash{'is_map_'.$rid})) {
- my $cmap=$hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}};
- if ( $cmap eq 'sequence' || $cmap eq 'page' ) {
- $cols[$#cols+1]=0;
- $P_Order++;
- $HWN=$P_Order;
- $mapsort{$HWN} = $rid.':';
- #$maps{&Apache::lonnet::declutter($hash{'src_'.$rid})}=
- # $hash{'title_'.$rid};
- }
- if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
- (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
- my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
-
- &tracetable($hash{'map_start_'.$hash{'src_'.$rid}},
- '&'.$frid.'&');
-
- $cols[$#cols+1]=($P_Order+1).':'.$frid;
-
- my $meta=$hash{'src_'.$frid};
- my $PartNo = 0;
- if ($meta) {
- if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
- foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
- if ($_=~/^stores\_(\d+)\_tries$/) {
- &Apache::lonnet::metadata($meta,$_.'.part');
- $P_Order++;
- $mapsort{$HWN} .= '&'.$P_Order;
- $PartNo++;
- $r->print(' '.$PartNo.'---'.$P_Order);
- }
- }
- }
- }
- }
- } else {
- $cols[$#cols+1]=($P_Order+1).':'.$rid;
- my $meta=$hash{'src_'.$rid};
- my $PartNo = 0;
- if ($meta) {
- if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) {
- foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
- if ($_=~/^stores\_(\d+)\_tries$/) {
- &Apache::lonnet::metadata($meta,$_.'.part');
- $P_Order++;
- $mapsort{$HWN} .= '&'.$P_Order;
- $PartNo++;
- }
- }
- }
- }
- }
- if (defined($hash{'to_'.$rid})) {
- foreach (split(/\,/,$hash{'to_'.$rid})){
- &tracetable($hash{'goesto_'.$_},$beenhere);
- }
- }
+ # Test for access to the cache data
+ my $courseID=$ENV{'request.course.id'};
+ my $isRecalculate=0;
+ if(defined($ENV{'form.Recalculate'})) {
+ $isRecalculate=1;
+ }
+
+ my $isCached = &Apache::loncoursedata::TestCacheData($cacheDB,
+ $isRecalculate);
+ if($isCached < 0) {
+ return "Unable to tie hash to db file.";
+ }
+
+ # Download class list information if not using cached data
+ my %cache;
+ unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
+ return "Unable to tie hash to db file.";
+ }
+
+ if(!$isCached) {
+ my $processTopResourceMapReturn=
+ &Apache::loncoursedata::ProcessTopResourceMap(\%cache, $c, $r);
+ if($processTopResourceMapReturn ne 'OK') {
+ untie(%cache);
+ return $processTopResourceMapReturn;
+ }
+ }
+
+ if($c->aborted()) {
+ untie(%cache);
+ return 'aborted';
+ }
+
+ my $classlist=&Apache::loncoursedata::DownloadClasslist($courseID,
+ $cache{'ClasslistTimestamp'},
+ $c);
+ foreach (keys(%$classlist)) {
+ if(/^(con_lost|error|no_such_host)/i) {
+ untie(%cache);
+ return "Error getting student data.";
+ }
+ }
+
+ if($c->aborted()) {
+ untie(%cache);
+ return 'aborted';
+ }
+
+ # Active is a temporary solution, remember to change
+ Apache::loncoursedata::ProcessClasslist(\%cache,$classlist,$courseID,$c);
+ if($c->aborted()) {
+ untie(%cache);
+ return 'aborted';
+ }
+
+ &ProcessFormData(\%cache);
+ my $students = &SortStudents(\%cache);
+ &SpaceColumns($students, $studentInformation, $headings, \%cache);
+ $cache{'updateTime:columnWidth'}=24;
+
+ if($cache{'download'} ne 'false') {
+ my $who = $cache{'download'};
+ my $courseData =
+ &Apache::loncoursedata::DownloadCourseInformation(
+ $who, $courseID,
+ $cache{$who.':lastDownloadTime'});
+ &Apache::loncoursedata::ProcessStudentData(\%cache, $courseData, $who);
+ $cache{'download'} = 'false';
+ } elsif($cache{'DownloadAll'} ne 'false') {
+ $cache{'DownloadAll'} = 'false';
+ my @allStudents;
+ if($cache{'DownloadAll'} eq 'sorted') {
+ @allStudents = @$students;
+ } else {
+ @allStudents = split(':::', $cache{'NamesOfStudents'});
+ }
+ &Create_PrgWin($r);
+ my $count=1;
+ foreach (@allStudents) {
+ &Update_PrgWin(scalar(@allStudents),$count,$_,$r);
+ my $courseData =
+ &Apache::loncoursedata::DownloadCourseInformation(
+ $_, $courseID,
+ $cache{$_.':lastDownloadTime'});
+ &Apache::loncoursedata::ProcessStudentData(\%cache, $courseData,
+ $_);
+ if($c->aborted()) {
+ untie(%cache);
+ return 'aborted';
+ }
+ $count++;
+ }
+ &Close_PrgWin($r);
}
-}
-sub MySort {
- if ( $Pos > 0 && $Pos < 11 ) {
- if ($ENV{'form.order'} eq 'Descending') {$b <=> $a;}
- else { $a <=> $b; }
- }
- else {
- if ($ENV{'form.order'} eq 'Descending') {$b cmp $a;}
- else { $a cmp $b; }
+ if($c->aborted()) {
+ untie(%cache);
+ return 'aborted';
}
+
+ untie(%cache);
+
+ return ('OK', $students);
}
-sub Build_Statistics {
+
+# Create progress
+sub Create_PrgWin {
+ my ($r)=@_;
$r->print(<
popwin=open('','popwin','width=400,height=100');
- popwin.document.writeln(''+
+ popwin.document.writeln(''+
'LON-CAPA Statistics'+
'