Diff for /loncom/interface/lonstatistics.pm between versions 1.4 and 1.108

version 1.4, 2002/02/06 16:59:01 version 1.108, 2004/07/15 21:08:45
Line 1 Line 1
 # The LearningOnline Network with CAPA  # The LearningOnline Network with CAPA
 # (Publication Handler  
 #  #
 # $Id$  # $Id$
 #  #
Line 26 Line 25
 # http://www.lon-capa.org/  # http://www.lon-capa.org/
 #  #
 # (Navigate problems for statistical reports  # (Navigate problems for statistical reports
 # YEAR=2001  #
 # 5/05/01, 7/09/01, 7/25/01, 8/11/01,9/13/01, 9/26/01 Behrouz Minaei  
 # 10/5/01, 10/9/01, 10/22/01, 10/26/01 Behrouz Minaei  
 # 11/1/01, 11/4/01, 11/16/01 Behrouz Minaei  
 # 12/14/01, 12/16/01, 12/18/01,12/20/01,12/31/01 Behrouz Minaei  
 # YEAR=2002  
 # 1/22/02,2/1/02 Behrouz Minaei  
 ###  ###
   
 package Apache::lonstatistics;   =pod
   
   =head1 NAME
   
   lonstatistics
   
   =head1 SYNOPSIS
   
   Main handler for statistics and chart.
   
   =over 4
   
   =cut
   
   package Apache::lonstatistics;
   
 use strict;  use strict;
 use Apache::Constants qw(:common :http);  use Apache::Constants qw(:common :http);
   use vars qw(
       @FullClasslist 
       @Students
       @Sections 
       @SelectedSections
       %StudentData
       @StudentDataOrder
       @SelectedStudentData
       $top_map 
       @Sequences 
       @SelectedMaps
       @Assessments
       $enrollment_status);
   
 use Apache::lonnet();  use Apache::lonnet();
 use Apache::lonhomework;  use Apache::lonhomework;
 use HTML::TokeParser;  use Apache::loncommon;
 use GDBM_File;  use Apache::loncoursedata;
 #use Benchmark;  use Apache::lonhtmlcommon;
   use Apache::lonmysql;
 # -------------------------------------------------------------- Module Globals  use Apache::lonlocal;
 my %hash;  use Time::HiRes;
 my %CachData;  #
 my %GraphDat;  # Statistics Packages
 my %maps;  use Apache::lonproblemanalysis();
 my @mapsort;  use Apache::lonsubmissiontimeanalysis();
 my %section;  use Apache::loncorrectproblemplot();
 my %StuBox;  use Apache::lonproblemstatistics();
 my %DiscFac;  use Apache::lonstudentassessment();
 my $CurMap;  use Apache::lonpercentage;
 my $CurSec;  use Apache::lonstudentsubmissions();
 my $CurStu;  use Apache::lonsurveyreports();
 my @cols;  
 my @list;  #######################################################
 my @students;  #######################################################
 my $p_count;  
 my $Pos;  =pod
 my $r;  
 my $OpSel1;  =item Package Variables
 my $OpSel2;  
 my $OpSelDis1;  =item @FullClasslist The full classlist
 my $OpSelDis2;  
 my $CurDis=0;  =item @Students The students we are concerned with for this invocation
 my $OpSel3;  
 my $OpSel4;  =item @Sections The sections available in this class
 my $GData;  
 my $cid;  =item $curr_student The student currently being examined
 my $firstres;  
 my $lastres;  =item $prev_student The student previous in the classlist
 my $DiscFlag=0;  
 my $HWN=0;  =item $next_student The student next in the classlist
   
 my %Header = (0,"Problem Title",1,"#Stdnts",2,"Tries",3,"Mod",  =over
               4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"S.D.",  
               9,"Skew.",10,"DoDiff",11,"Map");  =cut 
 #             9,"Skew.",10,"DoDiff",11,"Dis.F.",12,"Resourse URL");  
   #######################################################
 sub NumericSort {            #######################################################
     $a <=> $b;  #
 }  # Classlist variables
   #
 # ------ Create different Student Report   my $curr_student;
 sub StudentReport {  my $prev_student;
     my ($sname,$sdom)=@_;  my $next_student;
     if ( $sname eq 'All Students' ) {  
  $r->print( '<h3><font color=blue>WARNING:   #######################################################
                     Please select a student</font></h3>' );  #######################################################
  return;  
     }  =pod
     my $shome=&Apache::lonnet::homeserver( $sname,$sdom );            
     my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$cid,$shome );  =item &clear_classlist_variables()
     my %result = ();  
     my $ResId;  undef the following package variables:
     my $Code;  
     my $Tries;  =over
     my $TotalTries = 0;  
     my $ParCr = 0;  =item @FullClasslist
     my $Wrongs;  
     my %TempHash;  =item @Students
     my $Version;  
     my $LatestVersion;  =item @Sections
     my $PtrTry='';  
     my $PtrCod='';  =item @SelectedSections
     my $SetNo=0;  
     my $Str = "\n".'<table border=2>'.  =item %StudentData
               "\n".'<tr>'.  
               "\n".'<th> # </th>'.  =item @StudentDataOrder
       "\n".'<th> Set Title </th>'.  
       "\n".'<th> Results </th>'.  =item @SelectedStudentData
       "\n".'<th> Tries </th>'.  
       "\n".'</tr>';  =item $curr_student
     unless ($reply=~/^error\:/) {  
         map {  =item $prev_student
             my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));  
             $result{$name}=$value;  =item $next_student
         } split(/\&/,$reply);;  
         foreach $ResId (@cols) {  =back
     if ( !$ResId ) {  
  my $Set=&Apache::lonnet::declutter($hash{'map_id_'.$1});  =cut
  if ( $Set ) {  
     $SetNo++;  #######################################################
     $Str .= "\n"."<tr>".  #######################################################
     "\n"."<td> $SetNo </td>".  sub clear_classlist_variables {
                             "\n"."<td> $Set </td>".      undef(@FullClasslist);
                             "\n"."<td> $PtrCod </td>".      undef(@Students);
                             "\n"."<td> $PtrTry</td>".      undef(@Sections);
                             "\n"."</tr>";      undef(@SelectedSections);
  }      undef(%StudentData);
  $PtrTry='';      undef(@SelectedStudentData);
  $PtrCod='';      undef($curr_student);
  next;       undef($prev_student);
     }      undef($next_student);
             $ResId=~/(\d+)\.(\d+)/;  }
             my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );  
             if ( $CurMap ne 'All Maps' ) {  #######################################################
  my ( $ResMap, $NameMap ) = split(/\=/,$CurMap);  #######################################################
  if ( $Map ne $ResMap ) { next; }  
     }  =pod
     my $meta=$hash{'src_'.$ResId};  
     my $PartNo = 0;  =item &PrepareClasslist()
     undef %TempHash;  
     map {  Build up the classlist information.  The classlist information is kept in
  if ($_=~/^stores\_(\d+)\_tries$/) {  the following package variables:
                     my $Part=&Apache::lonnet::metadata($meta,$_.'.part');  
     if ( $TempHash{"$Part"} eq '' ) {   =over
  $TempHash{"$Part"} = $Part;  
  $TempHash{$PartNo}=$Part;  =item @FullClasslist
  $TempHash{"$Part.Code"} = '-';    
  $PartNo++;  =item @Students
     }  
  }  =item @Sections
             } split(/\,/,&Apache::lonnet::metadata($meta,'keys'));  
   =item @SelectedSections
             my $Prob = $Map.'___'.$2.'___'.  
                        &Apache::lonnet::declutter( $hash{'src_'.$ResId} );  =item %StudentData
             $Code='U';  
             $Tries = 0;  =item @SelectedStudentData
             $Wrongs = 0;  
      $LatestVersion = $result{"version:$Prob"};         =item $curr_student
   
     if ( $LatestVersion ) {  =item $prev_student
  for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {  
     my $vkeys = $result{"$Version:keys:$Prob"};  =item $next_student
     my @keys = split(/\:/,$vkeys);  
     =back
     foreach my $Key (@keys) {    
  if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {  $curr_student, $prev_student, and $next_student may not be defined, depending
     my $Part = $1;  upon the calling context.
     $Tries = $result{"$Version:$Prob:resource.$Part.tries"};  
     $TempHash{"$Part.Tries"} = ($Tries) ? $Tries : 0;   =cut
     $TotalTries += $Tries;  
     my $Val = $result{"$Version:$Prob:resource.$Part.solved"};  #######################################################
     if ( $Val eq 'correct_by_student' )  #######################################################
                                 { $Wrongs = $Tries - 1; $Code = 'Y'; }   sub PrepareClasslist {
     elsif ( $Val eq 'correct_by_override' )      my %Sections;
                                 { $Wrongs = $Tries - 1; $Code = 'y'; }                              &clear_classlist_variables();
     elsif ( $Val eq 'incorrect_attempted' ||       #
                                 $Val eq 'incorrect_by_override' )      # Retrieve the classlist
                 { $Wrongs = $Tries; $Code = 'N'; }      my $cid  = $ENV{'request.course.id'};
     $TempHash{"$Part.Code"} = $Code;      my $cdom = $ENV{'course.'.$cid.'.domain'};
     $TempHash{"$Part.Wrongs"} = $Wrongs;      my $cnum = $ENV{'course.'.$cid.'.num'};
  }      my ($classlist,$field_names) = &Apache::loncoursedata::get_classlist($cid,
          }                                                                    $cdom,$cnum);
                 }       if (exists($ENV{'form.Section'})) {
  for ( my $n = 0; $n < $PartNo; $n++ ) {            if (ref($ENV{'form.Section'})) {
     my $part = $TempHash{$n};              @SelectedSections = @{$ENV{'form.Section'}};
     if ($PtrTry ne '') {$PtrTry .= ',';}          } elsif ($ENV{'form.Section'} !~ /^\s*$/) {
     $PtrTry .= "$TempHash{$part.'.Tries'}";              @SelectedSections = ($ENV{'form.Section'});
                     $PtrCod .= "$TempHash{$part.'.Code'}";              }
  }      }
       @SelectedSections = ('all') if (! @SelectedSections);
       foreach (@SelectedSections) {
           if ($_ eq 'all') {
               @SelectedSections = ('all');
           }
       }
       #
       # Deal with instructors with restricted section access
       if ($ENV{'request.course.sec'} !~ /^\s*$/) {
           @SelectedSections = ($ENV{'request.course.sec'});
       }
       #
       # Set up %StudentData
       @StudentDataOrder = qw/fullname username domain id section status comments/;
       foreach my $field (@StudentDataOrder) {
           $StudentData{$field}->{'title'} = &mt($field);
           $StudentData{$field}->{'base_width'} = length(&mt($field));
           $StudentData{$field}->{'width'} = 
                                  $StudentData{$field}->{'base_width'};
       }
       #
       # get the status requested
       $enrollment_status = 'Active';
       $enrollment_status = $ENV{'form.Status'} if (exists($ENV{'form.Status'}));
       #
       # Process the classlist
       while (my ($student,$student_data) = each (%$classlist)) {
           my $studenthash = ();
           for (my $i=0; $i< scalar(@$field_names);$i++) {
               my $field = $field_names->[$i];
               # Store the data
               $studenthash->{$field}=$student_data->[$i];
               # Keep track of the width of the fields
               next if (! exists($StudentData{$field}));
               my $length = length($student_data->[$i]);
               if ($StudentData{$field}->{'width'} < $length) {
                   $StudentData{$field}->{'width'} = $length; 
               }
           }
           push (@FullClasslist,$studenthash);
           #
           # Build up a list of sections
           my $section = $studenthash->{'section'};
           if (! defined($section) || $section =~/^\s*$/ || $section == -1) {
               $studenthash->{'section'} = 'none';
               $section = $studenthash->{'section'};
           }
           $Sections{$section}++;
           #
           # Only put in the list those students we are interested in
           foreach my $sect (@SelectedSections) {
               if ( (($sect eq 'all') || 
                     ($section eq $sect)) &&
                    (($studenthash->{'status'} eq $enrollment_status) || 
                     ($enrollment_status eq 'Any')) 
                    ){
                   push (@Students,$studenthash);
                   last;
             }              }
     else {   
  for(my $n=0; $n<$PartNo; $n++) {   
     if ($PtrTry ne '') {$PtrTry .= ',';}  
     $PtrTry .= "0";  
                     $PtrCod .= "-";   
  }  
     }  
         }          }
     }      }
     $Str .= "\n".'</table>';      #
     $r->print($Str);      # Put the consolidated section data in the right place
     $r->rflush();      if ($ENV{'request.course.sec'} !~ /^\s*$/) {
           @Sections = ($ENV{'request.course.sec'});
       } else {
           @Sections = sort {$a cmp $b} keys(%Sections);
           unshift(@Sections,'all'); # Put 'all' at the front of the list
       }
       #
       # Sort the Students
       my $sortby = 'fullname';
       $sortby = $ENV{'form.sort'} if (exists($ENV{'form.sort'}));
       my @TmpStudents = sort { $a->{$sortby} cmp $b->{$sortby} ||
                                $a->{'fullname'} cmp $b->{'fullname'} } @Students;
       @Students = @TmpStudents;
       # 
       # Now deal with that current student thing....
       $curr_student = undef;
       if (exists($ENV{'form.SelectedStudent'})) {
           my ($current_uname,$current_dom) = 
               split(':',$ENV{'form.SelectedStudent'});
           my $i;
           for ($i = 0; $i<=$#Students; $i++) {
               next if (($Students[$i]->{'username'} ne $current_uname) || 
                        ($Students[$i]->{'domain'}   ne $current_dom));
               $curr_student = $Students[$i];
               last; # If we get here, we have our student.
           }
           if (defined($curr_student)) {
               if ($i == 0) {
                   $prev_student = undef;
               } else {
                   $prev_student = $Students[$i-1];
               }
               if ($i == $#Students) {
                   $next_student = undef;
               } else {
                   $next_student = $Students[$i+1];
               }
           }
       }
       #
       if (exists($ENV{'form.StudentData'})) {
           if (ref($ENV{'form.StudentData'}) eq 'ARRAY') {
               @SelectedStudentData = @{$ENV{'form.StudentData'}};
           } else {
               @SelectedStudentData = ($ENV{'form.StudentData'});
           }
       } else {
           @SelectedStudentData = ('username');
       }
       foreach (@SelectedStudentData) {
           if ($_ eq 'all') {
               @SelectedStudentData = ('all');
               last;
           }
       }
       #
       return;
 }  }
   
   
 # ------------------------------------------- Prepare Statistics Table  #######################################################
 sub PreStatTable {  #######################################################
     my $CacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".  
                   "_$ENV{'user.domain'}_$cid\_statistics.db";  =pod
     my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".  
                   "_$ENV{'user.domain'}_$cid\_graph.db";  =item get_students
     my $CachDisFac = "/home/httpd/perl/tmp/$ENV{'user.name'}".  
      "_$ENV{'user.domain'}_$cid\_DiscFactor.db";  Returns a list of the selected students
     $r->print('<br><input type="submit" name="sort" value="Recalculate Statistics" />');  
   =cut
     my $Ptr = '';  
   #######################################################
     $Ptr .= '<br><b> Sorting Type: &nbsp; </b>'."\n".  #######################################################
             '<select name="order"> <option '.$OpSel1.' >Ascending</option>'."\n".  sub get_students {
     '<option '.$OpSel2.'>Descending</option> </select> '."\n";      if (! @Students) {
     $Ptr .= '&nbsp;&nbsp;&nbsp;';          &PrepareClasslist()
     $Ptr .= '<input type="submit" name="sort" value="DoDiff Graph" />'."\n";  
     $Ptr .= '&nbsp;&nbsp;&nbsp;';  
     $Ptr .= '<input type="submit" name="sort" value="%Wrong Graph" />'."\n";  
   
     $Ptr .= '<pre>'.  
     '  #Stdnts: Total Number of Students opened the problem.<br>'.   
     '  Tries  : Total Number of Tries for solving the problem.<br>'.   
     '  Mod    : Maximunm Number of Tries for solving the problem.<br>'.   
     '  Mean   : Average Number of the tries. [ Tries / #Stdns ]<br>'.  
     '  #YES   : Number of students solved the problem correctly.<br>'.   
     '  #yes   : Number of students solved the problem by override.<br>'.  
     '  %Wrng  : Percentage of students tried to solve the problem but'.  
     ' still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]<br>'.  
     '  S.D.   : Standard Deviation of the tries.'.  
     '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1)'.  
     ' where Xi is every student\'s tries ]<br>'.  
     '  Skew.  : Skewness of the students tries.'.  
     ' [ (sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3) ]<br>'.  
 #    '  DoDiff : Degree of Difficulty of the problem. [ Tries/(#YES+#yes+0.1) ]<br>'.  
     '  DoDiff : Degree of Difficulty of the problem. [ 1 - ((#YES+#yes) / Tries) ]<br>'.  
 #    '  Dis.F. : Discrimination Factor. [ Sum of Partial Credits Awarded / Total Number of Tries in %27 upper and lower students]</b>'.  
             '</pre>';  
   
     $r->print($Ptr);  
     $r->rflush();  
         
     my $Result = "\n".'<table border=2>';  
     $Result .= '<tr><th>P#</th>'."\n";  
     for ( my $nIdx=0; $nIdx < 12; $nIdx++ ) {   
  $Result .= '<th>'.'<input type="submit" name="sort" value="'.  
                    $Header{$nIdx}.'" />'.'</th>'."\n";  
     }      }
     $Result .= "\n".'</tr>'."\n";          return @Students;
     $r->print( $Result );  }
     $r->rflush();  
   #######################################################
   #######################################################
   
   =pod
   
   =item &current_student()
   
   Returns a pointer to a hash containing data about the currently
   selected student.
   
   =cut
   
     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);  sub current_student { 
     &Cache_Statistics();      return $curr_student;
         }  }
         else {  
     $r->print("Unable to tie hash to db file");  #######################################################
         }  #######################################################
     }  
     else {  =pod
  if (tie(%CachData,'GDBM_File',$CacheDB,&GDBM_WRCREAT,0640)) {  
     tie(%DiscFac,'GDBM_File',$CachDisFac,&GDBM_WRCREAT,0640);  =item &previous_student()
     tie(%GraphDat,'GDBM_File',$GraphDB,&GDBM_WRCREAT,0640);  
     foreach (keys %DiscFac) {delete $CachData{$_};}  Returns a pointer to a hash containing data about the student prior
     foreach (keys %CachData) {delete $CachData{$_};}  in the list of students.  Or something.  
     $DiscFlag=0;  
     &Build_Statistics();  =cut
  }  
         else {  #######################################################
     $r->print("Unable to tie hash to db file");  #######################################################
         }  sub previous_student { 
     }      return $prev_student;
     #$r->print('Total instances of the problems : '.($p_count*($#students+1)));  }
   
     untie(%CachData);  #######################################################
     untie(%GraphDat);  #######################################################
     untie(%DiscFac);  
   =pod
     $r->print("\n".'</table>'."\n");  
     $r->rflush();          =item &next_student()
 }  
   Returns a pointer to a hash containing data about the next student
   to be viewed.
 # ------------------------------------- Find the section of student in a course  
   =cut
 sub usection {  
     my ($udom,$unam,$courseid)=@_;  #######################################################
     $courseid=~s/\_/\//g;  #######################################################
     $courseid=~s/^(\w)/\/$1/;  sub next_student { 
     map {      return $next_student;
         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));  =pod
             $section=($section) ? $section : '(none)';  
 #            $section=(int($section)) ? int($section) : $section;  =item &clear_sequence_variables()
 #            $r->print($unam.'...'.$section.'<br>');  
     return $section;  =cut
         }  
     } split(/\&/,&Apache::lonnet::reply('dump:'.$udom.':'.$unam.':roles',  #######################################################
                         &Apache::lonnet::homeserver($unam,$udom)));  #######################################################
     return '';  sub clear_sequence_variables {
 }      undef($top_map);
       undef(@Sequences);
       undef(@Assessments);
 # ------ Dump the Student's DB file and handling the data for statistics table   }
   
 sub ExtractStudentData {  #######################################################
     my ($student,$coid)=@_;  #######################################################
     my ($sname,$sdom) = split( /\:/, $student );  
     my $shome=&Apache::lonnet::homeserver( $sname,$sdom );            =pod
     my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$coid,$shome );  
     my %result = ();  =item &SetSelectedMaps($elementname)
     my $ResId;  
     my $Dis = '';  Sets the @SelectedMaps array from $ENV{'form.'.$elementname};
     my $Code;  
     my $Tries;  =cut
     my $ParCr;  
     my $TotalTries = 0;  #######################################################
     my $TotalOpend = 0;  #######################################################
     my $ProbSolved = 0;  sub SetSelectedMaps {
     my $ProbTot = 0;      my $elementname = shift;
     my $TimeTot = 0;      if (exists($ENV{'form.'.$elementname})) {
     my $TotParCr = 0;          if (ref($ENV{'form.'.$elementname})) {
     my $Wrongs;              @SelectedMaps = @{$ENV{'form.'.$elementname}};
     my %TempHash;          } else {
     my $Version;              @SelectedMaps = ($ENV{'form.'.$elementname});
     my $LatestVersion;          }
     my $SecLimit;      } else {
     my $MapLimit;          @SelectedMaps = ('all');
     unless ($reply=~/^error\:/) {      }
         map {  }
             my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));  
             $result{$name}=$value;  
 #$r->print($name.'='.$value.'<br>');  #######################################################
         } split(/\&/,$reply);  #######################################################
         foreach $ResId (@cols) {  
     if ( !$ResId ) { next; }  =pod
             $ResId=~/(\d+)\.(\d+)/;  
             my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );  =item &Sequences_with_Assess()
             if ( $CurMap ne 'All Maps' ) {  
  my ( $ResMap, $NameMap ) = split(/\=/,$CurMap);  Returns an array containing the subset of @Sequences which contain
  if ( $Map ne $ResMap ) { next; }  assessments.
     }  
     my $meta=$hash{'src_'.$ResId};  =cut
     my $PartNo = 0;  
     $Dis .= ':';  #######################################################
     undef %TempHash;  #######################################################
     map {  sub Sequences_with_Assess {
  if ($_=~/^stores\_(\d+)\_tries$/) {      my ($mode) = @_;
                     my $Part=&Apache::lonnet::metadata($meta,$_.'.part');      $mode = 'selected' if (! defined($mode));
     if ( $TempHash{"$Part"} eq '' ) {       my @Sequences_to_Show;
  $TempHash{"$Part"} = $Part;      foreach my $sequence (@Sequences) {
  $TempHash{$PartNo}=$Part;          next if ($sequence->{'num_assess'} < 1);
  $TempHash{"$Part.Code"} = 'U';            if ($mode eq 'all') {
  $PartNo++;              push (@Sequences_to_Show,$sequence);
     }          } elsif ($mode eq 'selected') {
  }              foreach my $map_symb (@SelectedMaps) {
             } split(/\,/,&Apache::lonnet::metadata($meta,'keys'));                  if ($sequence->{'symb'} eq $map_symb || $map_symb eq 'all'){
                       push (@Sequences_to_Show,$sequence);
             my $Prob = $Map.'___'.$2.'___'.                      last; # Only put it in once
                        &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.'<br>');  
     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}";  
     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 .= "*$ResId:$TempHash{$part.'.Tries'}".  
             ":$TempHash{$part.'.Wrongs'}".  
                             ":$TempHash{$part.'.Code'}";      
 #$r->print($sname.' -- '.$ptr.'--- timestamp='.$TempHash{"$part.Time"}.'<br>');  
     push (@list, $ptr);  
     $TotalOpend++;  
     $ProbTot++;  
  }  
             }              }
     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.'<br> --- Dis= '.$Dis.'<br>');  
  }  
     }  
     #$r->print($sname.' PrCr= '.$TotParCr.' Slvd= '.$ProbSolved.' Tries='.$TotalTries.'<br>');  
 }  
   
   
 # ------------------------------------------------------------ Build page table  
 sub tracetable {  
     my ($rid,$beenhere)=@_;  
     $rid=~/(\d+)\.(\d+)/;  
     $maps{&Apache::lonnet::declutter($hash{'map_id_'.$1})}='';#$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;  
        $HWN++;  
                $mapsort[$HWN]=$rid.$hash{'title_'.$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.'&');  
   
               if ($hash{'src_'.$frid}) {  
                  if ($hash{'src_'.$frid}=~  
                                  /\.(problem|exam|quiz|assess|survey|form)$/) {  
      $cols[$#cols+1]=$frid;  
      $mapsort[$HWN] .= '&'.$frid;  
                  }  
       }  
    }  
        } else {  
           if ($hash{'src_'.$rid}) {  
              if ($hash{'src_'.$rid}=~  
                                  /\.(problem|exam|quiz|assess|survey|form)$/) {  
          $cols[$#cols+1]=$rid;  
  $mapsort[$HWN] .= '&'.$rid;  
              }  
           }  
        }  
        if (defined($hash{'to_'.$rid})) {  
           map {  
               &tracetable($hash{'goesto_'.$_},$beenhere);  
           } split(/\,/,$hash{'to_'.$rid});  
        }  
     }  
 }  
   
 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; }  
     }  
 }  
   
 sub Build_Statistics {  
     $r->print(<<ENDPOP);  
 <script>  
     popwin=open('','popwin','width=400,height=100');  
     popwin.document.writeln('<html><body bgcolor="#8cee8c">'+  
       '<title>LON-CAPA Statistics</title>'+  
       '<h4>Computation Progress</h4>'+  
       '<form name=popremain>'+  
       '<input type=text size=35 name=remaining value=Starting></form>'+  
       '</body></html>');  
     popwin.document.close();  
 </script>  
 ENDPOP  
   
     $r->rflush();      }
 # ---------------------------- Gathering the Data of students' tries      return @Sequences_to_Show;
     my $index;  }
     for ($index=0;$index<=$#students;$index++) {  
 #----------- update progress  #######################################################
         $r->print('<script>popwin.document.popremain.remaining.value="'.  #######################################################
                   'Computing '.($index+1).'/'.($#students+1).': '.  
                   $students[$index].'";</script>');  
         $r->rflush();  
   
         &ExtractStudentData($students[$index],$cid);  =pod
   
   =item &PrepareCourseData($r)
   
   =cut
   
   #######################################################
   #######################################################
   sub PrepareCourseData {
       my ($r) = @_;
       &clear_sequence_variables();
       my ($top,$sequences,$assessments) = 
           &Apache::loncoursedata::get_sequence_assessment_data();
       if (! defined($top) || ! ref($top)) {
           # There has been an error, better report it
           &Apache::lonnet::logthis('top is undefined');
           return;
       }
       $top_map = $top if (ref($top));
       @Sequences = @{$sequences} if (ref($sequences) eq 'ARRAY');
       @Assessments = @{$assessments} if (ref($assessments) eq 'ARRAY');
       return;
   }
   
   #######################################################
   #######################################################
   
   =pod
   
   =item &log_sequence($sequence,$recursive,$padding)
   
   Write data about the sequence to a logfile.  If $recursive is not
   undef the data is written recursively.  $padding is used for recursive
   calls.
   
   =cut
   
   #######################################################
   #######################################################
   sub log_sequence {
       my ($seq,$recursive,$padding) = @_;
       $padding = '' if (! defined($padding));
       if (ref($seq) ne 'HASH') {
           &Apache::lonnet::logthis('log_sequence passed bad sequnce');
           return;
       }
       &Apache::lonnet::logthis($padding.'sequence '.$seq->{'title'});
       while (my($key,$value) = each(%$seq)) {
           next if ($key eq 'contents');
           if (ref($value) eq 'ARRAY') {
               for (my $i=0;$i< scalar(@$value);$i++) {
                   &Apache::lonnet::logthis($padding.$key.'['.$i.']='.
                                            $value->[$i]);
               }
           } else {
               &Apache::lonnet::logthis($padding.$key.'='.$value);
           }
       }
       if (defined($recursive)) {
           &Apache::lonnet::logthis($padding.'-'x20);
           &Apache::lonnet::logthis($padding.'contains:');
           foreach my $item (@{$seq->{'contents'}}) {
               if ($item->{'type'} eq 'container') {
                   &log_sequence($item,$recursive,$padding.'    ');
               } else {
                   &Apache::lonnet::logthis($padding.'title = '.$item->{'title'});
                   while (my($key,$value) = each(%$item)) {
                       next if ($key eq 'title');
                       if (ref($value) eq 'ARRAY') {
                           for (my $i=0;$i< scalar(@$value);$i++) {
                               &Apache::lonnet::logthis($padding.$key.'['.$i.']='.
                                                        $value->[$i]);
                           }
                       } else {
                           &Apache::lonnet::logthis($padding.$key.'='.$value);
                       }
                   }
               }
           }
           &Apache::lonnet::logthis($padding.'end contents of '.$seq->{'title'});
           &Apache::lonnet::logthis($padding.'-'x20);
     }      }
 #--------------------- close Progress Line      return;
     $r->print('<script>popwin.close()</script>');  }
     $r->rflush();   
 # -------------------- sorting the Data  
     @list = sort(@list);  
     $OpSel2='';  
     $OpSel1='selected';  
       
     $p_count = 0;   
     my $nIdx = 0;  
     my $dummy;   
     my $p_val;  
     my $ResId;  
     my $NoElements = $#list + 1;  
 #-------------------------------- loop for data representation  
     while ( $nIdx < $NoElements ) {  
         my %storestats=();  
  my ($Prob,$Tries,$Wrongs,$Code)=split(/\:/,$list[$nIdx]);  
  my $Temp = $Prob;  
  my $MxTries = 0;  
  my $TotalTries = 0;  
  my $YES = 0;  
  my $Incorrect = 0;  
  my $Override = 0;  
  my $StdNo = 0;  
  my @StdLst;   
  do {  
     $nIdx++;  
     $StdNo++;  
     $StdLst[ $StdNo ] = $Tries;  
     $TotalTries += $Tries;  
     if ( $MxTries < $Tries ) { $MxTries = $Tries; }   
     if ( $Code eq 'C' ){ $YES++; }  
     elsif( $Code eq 'I' ) { $Incorrect++; }  
     elsif( $Code eq 'O' ) { $Override++; }  
     elsif( $Code eq 'U' ) { $StdNo--; }  
     ($Prob,$Tries,$Wrongs,$Code)=split(/\:/,$list[$nIdx]);  
  } while ( $Prob eq $Temp && $nIdx < $NoElements );  
   
  $p_count++;  ##############################################
   ##############################################
   
  ($Temp,$ResId)=split(/\*/,$Temp);  =pod 
   
         $Temp = '<a href="'.$hash{'src_'.$ResId}.'" target="_blank">'.$Temp.'</a>';  =item &StudentDataSelect($elementname,$status,$numvisible,$selected)
       
  my $res = &Apache::lonnet::declutter($hash{'src_'.$ResId});  
         my $urlres=$res;  
   
         $ResId=~/(\d+)\.(\d+)/;  Returns html for a selection box allowing the user to choose one (or more) 
         my $Map = &Apache::lonnet::declutter( $hash{'map_id_'.$1} );  of the fields of student data available (fullname, username, id, section, etc)
         $urlres=$Map;  
    =over 4
   
         $res = '<a href="'.$hash{'src_'.$ResId}.'">'.$res.'</a>';  =item $elementname The name of the HTML form element
   
         #$Map = '<a href="'.$Map.'">'.$res.'</a>';  =item $status 'multiple' or 'single' selection box
   
 #------------------------ Compute the Average of Tries about one problem  =item $numvisible The number of options to be visible
  my $Average = ($StdNo) ? $TotalTries/$StdNo : 0;  
   =back
         $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___timestamp'}=time;         
         $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___stdno'}=$StdNo;  =cut
         $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___avetries'}=$Average;  
      ##############################################
 #-------------------------------- Compute percentage of Wrong tries  ##############################################
  my $Wrong = ( $StdNo ) ? 100 * ( $Incorrect / $StdNo ) : 0;  sub StudentDataSelect {
       my ($elementname,$status,$numvisible)=@_;
 #-------------------------------- Compute Standard Deviation      if ($numvisible < 1) {
  my $StdDev = 0;           return;
  if ( $StdNo > 1 ) {      }
     for ( my $n = 0; $n < $StdNo; $n++ ) {      #
                 my $Dif = $StdLst[ $n ]-$Average;      # Build the form element
  $StdDev += $Dif*$Dif;      my $Str = "\n";
     }       $Str .= '<select name="'.$elementname.'" ';
     $StdDev /= ( $StdNo - 1 );      if ($status ne 'single') {
     $StdDev = sqrt( $StdDev );          $Str .= 'multiple="true" ';
  }      }
       $Str .= 'size="'.$numvisible.'" >'."\n";
 #-------------------------------- Compute Degree of Difficulty      #
  my $DoDiff = 0;      # Deal with 'all'
  if( $TotalTries > 0 ) {      $Str .= '    <option value="all" ';
     $DoDiff = 1 - ( ( $YES + $Override ) / $TotalTries );      foreach (@SelectedStudentData) {
 #    $DoDiff =  ($TotalTries)/($YES + $Override+ 0.1);              if ($_ eq 'all') {
  }              $Str .= 'selected ';
                      last;
         $storestats{$ENV{'request.course.id'}.'___'.$urlres.'___difficulty'}=$DoDiff;          }
       }
 #-------------------------------- Compute the Skewness      $Str .= ">all</option>\n";
  my $Skewness = 0;      #
         my $Sum = 0;       # Loop through the student data fields
  if ( $StdNo > 0 && $StdDev > 0 ) {      foreach my $item (@StudentDataOrder) {
     for ( my $n = 0; $n < $StdNo; $n++ ) {          $Str .= '    <option value="'.$item.'" ';
                 my $Dif = $StdLst[ $n ]-$Average;          foreach (@SelectedStudentData) {
  $Skewness += $Dif*$Dif*$Dif;              if ($item eq $_ ) {
     }                   $Str .= 'selected ';
     $Skewness /= $StdNo;                  last;
     $Skewness /= $StdDev*$StdDev*$StdDev;              }
  }          }
 #-----------------  Some restition in presenting the float numbers          $Str .= '>'.$item."</option>\n";
  my $Avg = sprintf( "%.2f", $Average );      }
  my $Wrng = sprintf( "%.1f", $Wrong );      $Str .= "</select>\n";
  my $SD = sprintf( "%.1f", $StdDev );      return $Str;
  my $DoD = sprintf( "%.2f", $DoDiff );  }
  my $Sk = sprintf( "%.1f", $Skewness );  
       ##############################################
  $CachData{($p_count-1)}=$Temp.':'.$StdNo.':'.$TotalTries.':'.  ##############################################
                                 $MxTries.':'.$Avg.':'.$YES.':'.  
                                 $Override.':'.$Wrng.':'.$SD.':'.  =pod 
                                 $Sk.':'.$DoD.':'.$Map.':'.$Prob;  
   =item &MapSelect($elementname,$status,$numvisible,$restriction) 
         $urlres=~/^(\w+)\/(\w+)/;  
         if ($StdNo) {   Returns html for a selection box allowing the user to choose one (or more) 
            &Apache::lonnet::put('resevaldata',\%storestats,$1,$2);   of the sequences in the course.  The values of the sequences are the symbs.
         }  If the top sequence is selected, the value 'top' will result.
   
 #-------------------------------- Row of statistical table  =over 4
         if ( $DiscFlag == 0 ) {  
     $r->print( "\n".'<tr>'.  =item $elementname The name of the HTML form element
                "\n".'<td>'.$p_count.'</td>'.  
                "\n".'<td>'.$Temp.'</td>'.  =item $status 'multiple' or 'single' selection box
                "\n".'<td>'.$StdNo.'</td>'.  
                "\n".'<td>'.$TotalTries.'</td>'.  =item $numvisible The number of options to be visible
                "\n".'<td>'.$MxTries.'</td>'.  
                "\n".'<td>'.$Avg.'</td>'.  =item $restriction Code reference to subroutine which returns true or 
                "\n".'<td>'.$YES.'</td>'.  false.  The code must expect a reference to a sequence data structure.
                "\n".'<td>'.$Override.'</td>'.  
                "\n".'<td>'.$Wrng.'</td>'.  =back
                "\n".'<td>'.$SD.'</td>'.  
                "\n".'<td>'.$Sk.'</td>'.  =cut
                "\n".'<td>'.$DoD.'</td>'.  
                "\n".'<td>'.$Map.'</td>'.  ##############################################
                        "\n".'</tr>' );  ##############################################
     $GraphDat{$nIdx}=$DoD.':'.$Wrng;  sub MapSelect {
  }       my ($elementname,$status,$numvisible,$restriction)=@_;
     }      if ($numvisible < 1) {
 }          return;
       }
       #
 sub Cache_Statistics {      # Set up array of selected items
     my @list = ();      &SetSelectedMaps($elementname);
     my $Useful;      #
     my $UnUseful;      # Set up the restriction call
     my %myHeader = reverse( %Header );      if (! defined($restriction)) {
     $Pos = $myHeader{$ENV{'form.sort'}};          $restriction = sub { 1; };
     $p_count = 0;      }
       #
     foreach my $key( keys %CachData) {       # Build the form element
  my @Temp=split(/\:/,$CachData{$key});      my $Str = "\n";
  if ( $Pos == 0 || $Pos == 11 ) {      $Str .= '<select name="'.$elementname.'" ';
     ($UnUseful,$Useful)=split(/\>/,$Temp[$Pos]);      if ($status ne 'single') {
  }          $Str .= 'multiple="true" ';
  else {      }
     $Useful = $Temp[$Pos];      $Str .= 'size="'.$numvisible.'" >'."\n";
  }         #
  $list[$p_count]=$Useful.'&'.$CachData{$key};      # Deal with 'all'
         $p_count++;      foreach (@SelectedMaps) {
     }          if ($_ eq 'all') {
               @SelectedMaps = ('all');
     @list = sort MySort (@list);              last;
           }
     for ( my $nIdx = 0; $nIdx < $p_count; $nIdx++ ) {      }
  my( $Pre, $Post ) = split(/\&/,$list[$nIdx]);       #
  my ($Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,      # Put in option for 'all'
             $Override,$Wrng,$SD,$Sk,$DoD,$res,$Prob)=split(/\:/,$Post);      $Str .= '    <option value="all" ';
  $r->print( "\n".'<tr>'.      foreach (@SelectedMaps) {
                "\n".'<td>'.($nIdx+1).'</td>'.          if ($_ eq 'all') {
                "\n".'<td  bgcolor="#FFFFFF">'.$Temp.'</td>'.              $Str .= 'selected ';
                "\n".'<td>'.$StdNo.'</td>'.              last;
                "\n".'<td>'.$TotalTries.'</td>'.          }
                "\n".'<td>'.$MxTries.'</td>'.      }
                "\n".'<td>'.$Avg.'</td>'.      $Str .= ">all</option>\n";
                "\n".'<td>'.$YES.'</td>'.      #
                "\n".'<td>'.$Override.'</td>'.      # Loop through the sequences
                "\n".'<td>'.$Wrng.'</td>'.      foreach my $seq (@Sequences) {
                "\n".'<td>'.$SD.'</td>'.          next if (! $restriction->($seq));
                "\n".'<td>'.$Sk.'</td>'.          $Str .= '    <option value="'.$seq->{'symb'}.'" ';
                "\n".'<td>'.$DoD.'</td>'.          foreach (@SelectedMaps) {
                "\n".'<td>'.$res.'</td>'.              if ($seq->{'symb'} eq $_) {
                "\n".'</tr>' );                  $Str .= 'selected ';
  $GraphDat{$nIdx}=$DoD.':'.$Wrng;                  last;
     }               }
 }          }
           $Str .= '>'.$seq->{'title'}."</option>\n";
 # ------------------------------------------- Prepare data for Graphical chart      }
       $Str .= "</select>\n";
 sub GetGraphData {      return $Str;
     my $Tag = shift;  }
     my $Col;  
     my $data='';  ##############################################
     my $count = 0;  ##############################################
     my $Max = 0;  
     my $cid=$ENV{'request.course.id'};  =pod 
     my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".  
                   "_$ENV{'user.domain'}_$cid\_graph.db";  =item &SectionSelect($elementname,$status,$numvisible) 
     foreach (keys %GraphDat) {delete $GraphDat{$_};}  
     if (-e "$GraphDB") {  Returns html for a selection box allowing the user to choose one (or more) 
  if (tie(%GraphDat,'GDBM_File',"$GraphDB",&GDBM_READER,0640)) {  of the sections in the course.  
     if ( $Tag eq 'DoDiff Graph' ) {  
  $Tag = 'Degree-of-Difficulty';  Uses the package variables @Sections and @SelectedSections
  $Col = 0;  =over 4
     }  
     else {  =item $elementname The name of the HTML form element
  $Tag = 'Wrong-Percentage';  
  $Col = 1;  =item $status 'multiple' or 'single' selection box
     }  
     foreach (sort NumericSort keys %GraphDat) {   =item $numvisible The number of options to be visible
  my @Temp=split(/\:/,$GraphDat{$_});  
                 my $inf = $Temp[$Col];   =back
  if ( $Max < $inf ) {$Max = $inf;}  
  $data .= $inf.',';  =cut
  $count++;  
     }  
             untie(%GraphDat);  
     my $Course = $ENV{'course.'.$cid.'.description'};  
     $Course =~ s/\ /"_"/eg;  
     $GData=$Course.'&'.$Tag.'&'.$Max.'&'.$count.'&'.$data;  
   
  }  
  else {  
     $r->print("Unable to tie hash to db file");  
  }  
     }  
 }  
   
   
 sub initial {  
 # --------------------------------- Initialize the global varaibles  
   undef @students;  
   undef @cols;  
   undef %maps;  
   undef %section;  
   undef %StuBox;  
   undef @list;  
   undef %CachData;  
   undef %GraphDat;  
   undef %DiscFac;  
   undef $CurMap;  
   undef $CurSec;  
   undef $CurStu;  
   undef $p_count;  
   undef $Pos;  
   undef $GData;  
 }  
   
   
 sub ClassList {  
   
     &GetStatus();  
   
     $cid=$ENV{'request.course.id'};  
     my $chome=$ENV{'course.'.$cid.'.home'};  
     my ($cdom,$cnum)=split(/\_/,$cid);  
 # ----------------------- Get first and last resource, see if there is anything  
     $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};  
     $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};  
     if (($firstres) && ($lastres)) {  
 # ----------------------------------------------------------------- Render page  
  my $classlst=&Apache::lonnet::reply  
                  ('dump:'.$cdom.':'.$cnum.':classlist',$chome);  
  my $StudNo = 0;  
  unless ($classlst=~/^error\:/) {  
     foreach (sort split(/\&/,$classlst)) {  
  my ($name,$value)=split(/\=/,$_);  
  my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value));  
  $name=&Apache::lonnet::unescape($name);  
  my ($sname,$sdom)=split(/\:/,$name);  
  my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);  
                 if ($ssec==-1) {next;}  
  $ssec=($ssec) ? $ssec : '(none)';  
  #$ssec=(int($ssec)) ? int($ssec) : $ssec;  
  #$r->print($sname.'...'.$ssec.'<br>');  
  $section{$ssec}=$ssec;  
  if ($CurSec eq 'All Sections' || $ssec eq $CurSec) {  
     $students[$StudNo]=$name;  
     $StuBox{$sname}=$ssec;  
  }  
  $StudNo++;  
     }  
  }  
  else {  
     $r->print('<h1>Could not access course data</h1>');  
  }   
         $r->print("Total number of students : ".($#students+1));  
         $r->rflush();  
 # --------------- Find all assessments and put them into some linear-like order  
  &tracetable($firstres,'&'.$lastres.'&');  
   
 #my $c=0;  ##############################################
 #foreach(@mapsort) {  ##############################################
 #    $c++;  sub SectionSelect {
 #    $r->print('<br>'.$mapsort[$c]);      my ($elementname,$status,$numvisible)=@_;
 #}      if ($numvisible < 1) {
 #$r->print('<br> Count = '.$c);          return;
   
     }  
   
 # ------------------------------------------------------------- End render page   
     else {  
  $r->print('<h3>Undefined course sequence</h3>');  
     }  
     &MapSecOptions();  
 }  
   
   
 sub Menu {  
     my $InpStr = $ENV{'form.sort'};  
     if ( $InpStr eq 'DoDiff Graph' || $InpStr eq '%Wrong Graph' ) {        
  &GetGraphData($InpStr);  
     $r->print('<IMG src="/cgi-bin/graph.gif?'.$GData.'" />');  
     }  
     else {  
  $r->print('<html><head><title>LON-CAPA Statistics</title></head>');  
   
   
         $r->print('<body bgcolor="#FFFFFF">'.  
                   '<script>window.focus(); window.width=500;window.height=500; </script>'.  
                   '<img align=right src=/adm/lonIcons/lonlogos.gif>');  
 # ---------------------------------------------------------------- Course title  
         $r->print('<h1> Course : "'.  
                   $ENV{'course.'.$ENV{'request.course.id'}.  
                   '.description'}.'"</h1><h2>'.localtime().'</h2>');  
 # ------------------------------- This is going to take a while, produce output  
         $r->rflush();  
   
  $r->print("\n".'<form name=stat method=post action="/adm/statistics" >');  
   
  my $content = $ENV{'form.sort'};  
  if ($content eq '' || $content eq 'Return to Menu') {  
     my $Ptr = '<h3>';  
     $Ptr .= '<input type=submit name=sort value="Problem Evaluation"/>';#General Statistics"/>';  
     $Ptr .= '<br><br>';  
     $Ptr .= '<input type=submit name=sort value="Student Assessment"/>';  
     $Ptr .= '<br><br>';  
 #    $Ptr .= '<input type=submit name=sort value=Discrimination>';#"Problem Evaluation"/>';  
     $Ptr .= '</h3>';  
     $r->print( $Ptr );  
       }  
  else {  
     &initial();  
     &ClassList();  
     if ( $content eq 'Discrimination' || #'Problem Evaluation' ||  
                  $content eq 'Recalculate Discrimintion Factor' ) {  
  &CreateDiscFac();  
     }  
     elsif ( $content eq 'Student Assessment' ||   
                     $content eq 'Create Student Report' ) {  
  &StudentOptions();  
  &StudentReport($CurStu,$StuBox{"$CurStu"});  
     }  
     else {  
  &PreStatTable();  
     }  
  }  
  $r->print("\n".'</form>'.  
                   "\n".'</body>'.  
                   "\n".'</html>');  
  $r->rflush();  
     }  
 }  
   
 sub StudentOptions {  
     my $OpSel5='';  
     $CurStu = $ENV{'form.student'};  
     if ( $CurStu eq '' ) {   
         $CurStu = 'All Students';  
         $OpSel5 = 'selected';  
     }  
     my $Ptr ='';  
 # ----------------------------------- Loading the Students Combobox  
     $Ptr .= '<br><b>Select Student</b>'."\n".  
            '<select name="student">'."\n".   
     '<option '.$OpSel5.'>All Students</option>';                               
     foreach my $key ( sort keys %StuBox ) {            
  $Ptr .= '<option';  
  if ($CurStu eq $key) {$Ptr .= ' selected';}       
         $Ptr .= '>'.$key."</option>\n";       
     }  
     $Ptr .= '</select>';  
     $Ptr .= '<br><input type="submit" name="sort" value="Create Student Report" />';  
     $r->print( $Ptr );  
     $r->rflush();  
 }  
   
 sub GetStatus {  
   
     $OpSelDis1='';  
     $OpSelDis2='';  
     $OpSel1='';  
     $OpSel2='';  
     $OpSel3='';  
     $OpSel4='';  
   
 #    if ( $ENV{'form.DisType'} eq 'Total Number of Correct Answers' ) {   
 # $OpSelDis1='selected';   
 # $CurDis=0;  
 #    }  
 #    else { $OpSel2 = 'selected'; $CurDis = 1;}  
   
     if ( $ENV{'form.order'} eq 'Descending' ) { $OpSel2='selected'; }  
     else { $OpSel1 = 'selected'; }  
     $CurMap = $ENV{'form.maps'};  
     if ( $CurMap eq '' ) {   
  $CurMap = 'All Maps';  
  $OpSel3 = 'selected';  
     }  
     $CurSec = $ENV{'form.section'};  
     if ( $CurSec eq '' ) {   
  $CurSec = 'All Sections';  
         $OpSel4 = 'selected';  
     }  
 }  
   
   
 sub MapSecOptions {  
 # ----------------------------------- Loading the Maps Combobox  
     my $Ptr = '<br>';  
     $Ptr .= '<br><input type="submit" name="sort" value="Return to Menu" />';  
     $Ptr .= '<br><b> Select &nbsp; Map &nbsp; &nbsp; </b>'."\n".  
            '<select name="maps">'."\n".   
     '<option '.$OpSel3.'>All Maps</option>';                               
     foreach my $key ( sort keys %maps ) {            
  $Ptr .= '<option';  
         if ($CurMap eq $key) {$Ptr .= ' selected';}       
  $Ptr .= '>'.$key."</option>\n";       
     }  
     $Ptr .= '</select>';  
     $Ptr .= '&nbsp;&nbsp;&nbsp;';  
   
 # ----------------------------------- Loading the Sections Combobox  
     $Ptr .= '<br><b>Select Section</b>'."\n".  
            '<select name="section">'."\n".   
     '<option '.$OpSel4.'>All Sections</option>';                               
     foreach my $key ( sort keys %section ) {            
  $Ptr .= '<option';  
         if ($CurSec eq $key) {$Ptr .= ' selected';}       
  $Ptr .= '>'.$key."</option>"."\n";       
     }      }
     $Ptr .= '</select>'."\n";      #
       # Make sure we have the data we need to continue
       if (! @Sections) {
           &PrepareClasslist()
       }
       #
       # Build the form element
       my $Str = "\n";
       $Str .= '<select name="'.$elementname.'" ';
       if ($status ne 'single') {
           $Str .= 'multiple="true" ';
       }
       $Str .= 'size="'.$numvisible.'" >'."\n";
       #
       # Loop through the sequences
       foreach my $s (@Sections) {
           $Str .= '    <option value="'.$s.'" ';
           foreach (@SelectedSections) {
               if ($s eq $_) {
                   $Str .= 'selected ';
                   last;
               }
           }
           $Str .= '>'.$s."</option>\n";
       }
       $Str .= "</select>\n";
       return $Str;
   }
   
   #######################################################
   #######################################################
   
   =pod
   
   =item &CreateAndParseOutputSelector()
   
     $r->print( $Ptr );  Construct a selection list of options for output and parse output selections.
   
   =cut
   
   #######################################################
   #######################################################
   sub OutputDescriptions {
       my (@OutputOptions) = @_;
       my $Str = '';
       $Str .= "<h2>Output Modes</h2>\n";
       $Str .= "<dl>\n";
       foreach my $outputmode (@OutputOptions) {
    $Str .="    <dt>".$outputmode->{'name'}."</dt>\n";
    $Str .="        <dd>".$outputmode->{'description'}."</dd>\n";
       }
       $Str .= "</dl>\n";
       return $Str;
   }
   
   sub CreateAndParseOutputSelector {
       my ($elementname,$default,@OutputOptions) = @_;
       my $output_mode;
       my $show;
       my $Str = '';
       #
       # Format for output options is 'mode, restrictions';
       my $selected = $default;
       if (exists($ENV{'form.'.$elementname})) {
           if (ref($ENV{'form.'.$elementname} eq 'ARRAY')) {
               $selected = $ENV{'form.'.$elementname}->[0];
           } else {
               $selected = $ENV{'form.'.$elementname};
           }
       }
       #
       # Set package variables describing output mode
       $output_mode = 'html';
       $show        = 'all';
       foreach my $option (@OutputOptions) {
           next if ($option->{'value'} ne $selected);
           $output_mode = $option->{'mode'};
           $show        = $option->{'show'};
       }
       #
       # Build the form element
       $Str = qq/<select size="5" name="$elementname">/;
       foreach my $option (@OutputOptions) {
           if (exists($option->{'special'}) && 
               $option->{'special'} =~ /do not show/) {
               next;
           }
           $Str .= "\n".'    <option value="'.$option->{'value'}.'"';
           $Str .= " selected " if ($option->{'value'} eq $selected);
           $Str .= ">".&mt($option->{'name'})."<\/option>";
       }
       $Str .= "\n</select>";
       return ($Str,$output_mode,$show);
   }
   
   ###############################################
   ###############################################
   
   =pod 
   
   =item &Gather_Student_Data()
   
   Ensures all student data is up to date.
   
   =cut
   
   ###############################################
   ###############################################
   sub Gather_Student_Data {
       my ($r) = @_;
       my $c = $r->connection();
       #
       &Apache::loncoursedata::clear_internal_caches();
       #
       my @Sequences = &Apache::lonstatistics::Sequences_with_Assess();
       #
       my @Students = @Apache::lonstatistics::Students;
       #
       # Open the progress window
       my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
           ($r,'Statistics Compilation Status',
            'Statistics Compilation Progress', scalar(@Students));
       #
       while (my $student = shift @Students) {
           return if ($c->aborted());
           my ($status,undef) = &Apache::loncoursedata::ensure_current_data
               ($student->{'username'},$student->{'domain'},
                $ENV{'request.course.id'});
           &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
                                                    &mt('last student'));
       }
       &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
     $r->rflush();      $r->rflush();
 }  }
   
   ###############################################
   ###############################################
   
 # ================================================================ Main Handler  =pod 
   
 sub handler {  =item &Gather_Full_Student_Data()
     $r=shift;  
   
     if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {  Ensures all student data is up to date.
 # ------------------------------------------- Set document type for header only  
  if ($r->header_only) {  =cut
     if ($ENV{'browser.mathml'}) {  
  $r->content_type('text/xml');  ###############################################
     }   ###############################################
     else {  sub Gather_Full_Student_Data {
  $r->content_type('text/html');      my ($r,$formname,$inputname) = @_;
     }      my $status_type;
     $r->send_http_header;      if (defined($formname)) {
     return OK;          $status_type = 'inline';
  }          } else {
  my $requrl=$r->uri;          $status_type = 'popup';
 # ----------------------------------------------------------------- Tie db file      }
       my $c = $r->connection();
  undef %hash;      #
       &Apache::loncoursedata::clear_internal_caches();
  if ($ENV{'request.course.fn'}) {      #
     my $fn=$ENV{'request.course.fn'};      my @Students = @Apache::lonstatistics::Students;
     if (-e "$fn.db") {      #
  if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {      # Open the progress window
 # ------------------------------------------------------------------- Hash tied      my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
     $r->content_type('text/html');          ($r,&mt('Student Data Compilation Status'),
     $r->send_http_header;           &mt('Student Data Compilation Progress'), scalar(@Students),
     &Menu();           $status_type,undef,$formname,$inputname);
  }      #
  else {      while (my $student = shift @Students) {
     $r->content_type('text/html');          return if ($c->aborted());
     $r->send_http_header;          my ($status,undef) = &Apache::loncoursedata::ensure_current_full_data
     $r->print('<html><body>Coursemap undefined.</body></html>');              ($student->{'username'},$student->{'domain'},
  }               $ENV{'request.course.id'});
 # ------------------------------------------------------------------ Untie hash          &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
  unless (untie(%hash)) {                                                   &mt('last student'));
     &Apache::lonnet::logthis("<font color=blue>WARNING: ".  
                             "Could not untie coursemap $fn (browse).</font>");   
  }  
   
 # -------------------------------------------------------------------- All done  
  return OK;  
 # ----------------------------------------------- Errors, hash could no be tied  
     }  
  }   
  else {  
     $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";  
     return HTTP_NOT_ACCEPTABLE;   
  }  
     }      }
     else {      &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
         $ENV{'user.error.msg'}=      $r->rflush();
         $r->uri.":vgr:0:0:Cannot view grades for complete course";  }
   
         return HTTP_NOT_ACCEPTABLE;   ##################################################
   ##################################################
   sub DisplayClasslist {
       my ($r)=@_;
       &Apache::lonhtmlcommon::add_breadcrumb
           ({text=>'Select One Student'});
       #
       # Output some of the standard interface components
       my $Str;
       $Str .= &Apache::lonhtmlcommon::breadcrumbs(undef,'Select One Student');
       $Str .= '<p><table cellspacing="5">'."\n";
       $Str .= '<tr>';
       $Str .= '<th align="center"><b>'.&mt('Sections').'</b></th>';
       $Str .= '<th align="center"><b>'.&mt('Enrollment Status').'</b></th>';
       $Str .= '</tr>'.$/;
       $Str .= '<tr>';
       $Str .= '<td>'.
           &Apache::lonstatistics::SectionSelect('Section','multiple',5).
           '</td>';
       $Str .= '<td>'.
           &Apache::lonhtmlcommon::StatusOptions(undef,undef,5).
           '</td>';
       
       $Str .= '</tr>'.$/;
       $Str .= '</table></p>';
       $Str .= '<input type="submit" name="selectstudent" value="'.
           &mt('Update Display').'" />';
       $r->print($Str);
       $r->rflush();
       #
       my @Fields = ('fullname','username','domain','id','section','status');
       #
       $Str = '';
       if (! @Students) {
           if ($SelectedSections[0] eq 'all') { 
               if (lc($ENV{'form.Status'}) eq 'any') {
                   $Str .= '<h2>'.
                       &mt('There are no students in the course.').
                       '</h2>';
               } elsif (lc($ENV{'form.Status'}) eq 'active') {
                   $Str .= '<h2>'.
                   &mt('There are no currently enrolled students in the course.').
                       '</h2>';
               } elsif (lc($ENV{'form.Status'}) eq 'expired') {
                   $Str .= '<h2>'.
                       &mt('There are no previously enrolled students in the course.').
                           '</h2>';
               }
           } else { 
               my $sections;
               if (lc($ENV{'form.Status'}) eq 'any') {
                   $Str .= '<h2>'.
                       &mt('There are no students in the selected sections.').
                       '</h2>';
               } elsif (lc($ENV{'form.Status'}) eq 'active') {
                   $Str .= '<h2>'.
                       &mt('There are no currently enrolled students in the selected sections.').
                       '</h2>';
               } elsif (lc($ENV{'form.Status'}) eq 'expired') {
                   $Str .= '<h2>'.
                       &mt('There are no previously enrolled students in the selected sections.').
                       '</h2>';
               }
           }
           $Str.= '<a href="/adm/statistics?reportSelected=student_assessment">'.
               &mt('Click here to return to the chart').'</a>';
           $r->print($Str);
           $r->rflush();
           return;
       }
   
       # "Click" is asinine but it is probably not my place to change the world.
       $Str .= '<h2>Click on a students name or username to view their chart</h2>';
       $Str .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
       $Str .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";
       foreach my $field (@Fields) {
           $Str .= '<th><a href="/adm/statistics?'.
               'reportSelected=student_assessment&'.
               'selectstudent=1&'.
               'sort='.$field.'">'.&mt($field).
               '</a></th>';
       }
       $Str .= '</tr>'."\n";
       #
       my $alternate = 0;
       foreach my $student (@Students) { # @Students is a package variable
           my $sname = $student->{'username'}.':'.$student->{'domain'};
           if($alternate) {
               $Str .= '<tr bgcolor="#ffffe6">';
           } else {
               $Str .= '<tr bgcolor="#ffffc6">';
           }
           $alternate = ($alternate + 1) % 2;
           #
           foreach my $field (@Fields) {
               $Str .= '<td>';
               if ($field eq 'fullname' || $field eq 'username') {
                   $Str .= '<a href="/adm/statistics?reportSelected=';
                   $Str .= &Apache::lonnet::escape('student_assessment');
                   $Str .= '&sort='.&Apache::lonnet::escape($ENV{'form.sort'});
                   $Str .= '&SelectedStudent=';
                   $Str .= &Apache::lonnet::escape($sname).'">';
                   $Str .= $student->{$field}.'&nbsp';
                   $Str .= '</a>';
               } elsif ($field eq 'status') {
                   $Str .= &mt($student->{$field});
               } else {
                   $Str .= $student->{$field};
               }
               $Str .= '</td>';
           }
           $Str .= "</tr>\n";
       }
       $Str .= '</table></td></tr></table>'."\n";
       #
       $r->print($Str);
       $r->rflush();
       #
       return;
   }
   
   ##############################################
   ##############################################
   sub CreateMainMenu {
       #
       # Define menu data
       my @reports = ({ internal_name => 'problem_statistics',
                        name => &mt('Overall Problem Statistics'),
                        short_description => 
       &mt('Student performance statistics on all problems.'),
                    },
                      { internal_name => 'problem_analysis',
                        name => &mt('Detailed Problem Analysis'),
                        short_description => 
       &mt('Detailed statistics and graphs of student performance on problems.'),
                    },
                      { internal_name => 'submissiontime_analysis',
                        name => &mt('Submission Time Plots'),
                        short_description => 
       &mt('Display and analysis of submission times on assessments.'),
                    },
                      { internal_name => 'student_submission_reports',
                        name => &mt('Student Submission Reports'),
                        short_description => 
       &mt('Prepare Excel spreadsheets of student submissions.'),
                    },
                      { internal_name => 'survey_reports',
                        name => &mt('Survey Reports'),
                        short_description => 
       &mt('Prepare reports on survey results.'),
                    },
                      { internal_name => 'correct_problems_plot',
                        name => &mt('Correct Problems Plot'),
                        short_description => 
       &mt('Display a histogram of student performance in the course.'),
                    },
   #                   { internal_name => 'student_assessment',
   #                     name => &mt('Problem Status Chart'),
   #                     short_description => 
   #    &mt('Brief view of each students performance in course.'),
   #                 },
                      # 'percentage'  => 'Correct-problems Plot',
                      # 'activitylog' => 'Activity Log',
                      );
       #
       # Create the menu
       my $Str;
       $Str .= '<h2>'.&mt('Please select a report to generate').'</h2>';
       foreach my $reportdata (@reports) {
           $Str .='    <h3><a href="/adm/statistics?reportSelected='.
               $reportdata->{'internal_name'}.'" >'.
               $reportdata->{'name'}."</a></h3>\n";
           $Str .= '    '.('&nbsp;'x8).$reportdata->{'short_description'}.
               "\n";
       }
       $Str .="</dl>\n";
       #
       return $Str;
   }
   
   ##############################################
   ##############################################
   sub handler {
       my $r=shift;
       my $c = $r->connection();
       #
       # Check for overloading
       my $loaderror=&Apache::lonnet::overloaderror($r);
       if ($loaderror) { return $loaderror; }
       $loaderror=
          &Apache::lonnet::overloaderror($r,
            $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
       if ($loaderror) { return $loaderror; }
       #
       # Check for access
       if (! &Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
           $ENV{'user.error.msg'}=
               $r->uri.":vgr:0:0:Cannot view grades for complete course";
           if (! &Apache::lonnet::allowed('vgr',
                         $ENV{'request.course.id'}.'/'.$ENV{'request.course.sec'})) {
               $ENV{'user.error.msg'}=
                   $r->uri.":vgr:0:0:Cannot view grades with given role";
               return HTTP_NOT_ACCEPTABLE;
           }
       }
       #
       # Send the header
       &Apache::loncommon::no_cache($r);
       &Apache::loncommon::content_type($r,'text/html');
       $r->send_http_header;
       if ($r->header_only) { return OK; }
       #
       # Extract form elements from query string
       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                                               ['sort','reportSelected',
                                                'SelectedStudent']);
       #
       # Give the LON-CAPA page header
       $r->print('<html><head><title>'.
                 &mt('Course Statistics and Charts').
                 "</title></head>\n".
                 &Apache::loncommon::bodytag('Course Statistics and Charts'));
       $r->rflush();
       # 
       # Either print out a menu for them or send them to a report
       &Apache::lonhtmlcommon::clear_breadcrumbs();
       &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/statistics',
                                               title=>'Statistics',
                                               text =>'Statistics',
                                               faq=>139,
                                               bug=>'Statistics and Charts'});
       if (! exists($ENV{'form.reportSelected'}) || 
           $ENV{'form.reportSelected'} eq '') {
           $r->print(&Apache::lonhtmlcommon::breadcrumbs
                     (undef,&mt('Statistics Main Page')).
                     &CreateMainMenu());
       } else {
       #
           if (! &Apache::lonmysql::verify_sql_connection()) {
               my $serveradmin = $r->dir_config('lonAdmEMail');
               $r->print('<h2><font color="Red">'.
                         &mt('Unable to connect to database!').
                         '</font></h2>');
               $r->print('<p>'.
                         &mt('Please notify the server administrator ').
                         '<b>'.$serveradmin.'</b></p>');
               $r->print('<p>'.
                         &mt('Course Statistics and Charts cannot be '.
                             'retrieved until the database is restarted.  '.
                             'Your data is intact but cannot be displayed '.
                             'at this time.').'</p>');
               $r->print('</body></html>');
               return;
           }
           #
           # Clean out the caches
           if (exists($ENV{'form.ClearCache'})) {
               &Apache::loncoursedata::delete_caches($ENV{'requres.course.id'});
           }
           #
           # Begin form output
           $r->print('<form name="Statistics" ');
           $r->print('method="post" action="/adm/statistics">');
           $r->rflush();
           #
           my $GoToPage = $ENV{'form.reportSelected'};
           #
           # Set up the statistics and chart environment
           &PrepareCourseData($r);
           #
           $r->print('<input type="hidden" name="reportSelected" value="'.
                     $GoToPage.'">');
           if($GoToPage eq 'activitylog') {
   #        &Apache::lonproblemstatistics::Activity();
           } elsif($GoToPage eq 'problem_statistics') {
               &Apache::lonhtmlcommon::add_breadcrumb
                   ({href=>'/adm/statistics?reportselected=problem_statistics',
                     text=>'Overall Problem Statistics'});
               &Apache::lonproblemstatistics::BuildProblemStatisticsPage($r,$c);
           } elsif($GoToPage eq 'problem_analysis') {
               &Apache::lonhtmlcommon::add_breadcrumb
                   ({href=>'/adm/statistics?reportselected=problem_analysis',
                     text=>'Detailed Problem Analysis'});
               &Apache::lonproblemanalysis::BuildProblemAnalysisPage($r,$c);
           } elsif($GoToPage eq 'submissiontime_analysis') {
               &Apache::lonhtmlcommon::add_breadcrumb
                   ({href=>
                         '/adm/statistics?reportselected=submissiontime_analysis',
                         text=>'Submission Time Plots'});
               &Apache::lonsubmissiontimeanalysis::BuildSubmissionTimePage($r,$c);
           } elsif($GoToPage eq 'student_submission_reports') {
               &Apache::lonhtmlcommon::add_breadcrumb
                   ({href=>
                     '/adm/statistics?reportselected=student_submission_reports',
                     text=>'Student Submission Reports'});
               &Apache::lonstudentsubmissions::BuildStudentSubmissionsPage($r,$c);
           } elsif($GoToPage eq 'survey_reports') {
               &Apache::lonhtmlcommon::add_breadcrumb
                   ({href=>
                     '/adm/statistics?reportselected=survey_reports',
                     text=>'Survey Reports'});
               &Apache::lonsurveyreports::BuildSurveyReportsPage($r,$c);
           } elsif($GoToPage eq 'correct_problems_plot') {
               &Apache::lonhtmlcommon::add_breadcrumb
                   ({href=>'/adm/statistics?reportselected=correct_problems_plot',
                     text=>'Correct Problems Plot'});
               &Apache::loncorrectproblemplot::BuildCorrectProblemsPage($r,$c);
           } elsif($GoToPage eq 'student_assessment') {
               &Apache::lonhtmlcommon::clear_breadcrumbs();
               &Apache::lonhtmlcommon::add_breadcrumb
                   ({href=>'/adm/statistics?reportselected=student_assessment',
                     text=>'Chart'});
               &Apache::lonstudentassessment::BuildStudentAssessmentPage($r,$c);
           }
           #
           $r->print("</form>\n");
     }      }
       $r->print("</body>\n</html>\n");
       $r->rflush();
       #
       return OK;
 }  }
   
 1;  1;
 __END__  
   
   #######################################################
   #######################################################
   
   =pod
   
   =back
   
   =cut
   
   #######################################################
   #######################################################
   
   __END__
   

Removed from v.1.4  
changed lines
  Added in v.1.108


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