Diff for /loncom/interface/lonstatistics.pm between versions 1.27 and 1.29

version 1.27, 2002/07/17 12:53:00 version 1.29, 2002/07/22 20:35:05
Line 31 Line 31
 # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei  # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei
 # YEAR=2002  # YEAR=2002
 # 1/22,2/1,2/6,2/25,3/2,3/6,3/17,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei  # 1/22,2/1,2/6,2/25,3/2,3/6,3/17,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei
 # 5/12,5/14,5/15,5/19,5/26 Behrouz Minaei  # 5/12,5/14,5/15,5/19,5/26,7/16  Behrouz Minaei
 #  #
 ###  ###
   
Line 43  use Apache::lonnet(); Line 43  use Apache::lonnet();
 use Apache::lonhomework;  use Apache::lonhomework;
 use Apache::loncommon;  use Apache::loncommon;
 use Apache::loncoursedata;  use Apache::loncoursedata;
   use Apache::lonhtmlcommon;
   use Apache::lonchart;
 use HTML::TokeParser;  use HTML::TokeParser;
 use GDBM_File;  use GDBM_File;
   
Line 50  use GDBM_File; Line 52  use GDBM_File;
 my %hash;  my %hash;
 my %CachData;  my %CachData;
 my %GraphDat;  my %GraphDat;
 my %mapsort;  
 my $Pos;  
 my $r;  my $r;
 my $GData;  my $GData;
 my %color;  my %color;
 my %foil_to_concept;  my %foil_to_concept;
 my @Concepts;  my @Concepts;
 my %ConceptData;  my %ConceptData;
 my %Answer = ();  my %Answer=();
   my %mapsort;
   
   my %Activity=();
   my %Grade=();
   my %DoDiff=();
   my %Discuss=();
   my $TotalDiscuss=0;
   my $TotalDiscuss_=0;
   
   
   sub LoadDiscussion {
   #    my $symb=shift;
   #    $r->print('<br>$cid ... '.$symb);
   #    my %contrib=&Apache::lonnet::dump('msu_2964385f9033c63msul1','msu','2964385f9033c63msul1');
       my $cid=$ENV{'request.course.id'};
       my %contrib=&Apache::lonnet::dump(
                   $ENV{'request.course.id'},
                   $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
                   $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
                               
       foreach my $temp(keys %contrib) {
    if ($temp=~/^version/) {
       my $ver=$contrib{$temp};
       my ($dummy,$prb)=split(':',$temp);
       for (my $idx=1; $idx<=$ver; $idx++ ) {
    my $name=$contrib{"$idx:$prb:sendername"};
    $Discuss{"$name:$prb"}=$idx;
       }
    }
       }       
   #   $r->print('<br>cid='.$cid);
   #    my %contrib=&Apache::lonnet::restore($symb,$cid,
   # $ENV{$cid.'.domain'},
   # $ENV{'course.'.$cid.'.num'});
   
   #    $Apache::lonxml::debug=1;
   #    &Apache::lonhomework::showhash(%Discuss);
   #    $Apache::lonxml::debug=0;
   }
   
   sub LoadDoDiffFile {
       my $file="/home/minaeibi/183d.txt";
       open(FILEID, "<$file");
       my $line=<FILEID>;
       %DoDiff=();
       my @Act=split('&',$line);
       
   #    $r->print('<br>'.$#Act);
       for(my $n=0;$n<=$#Act;$n++){
          my ($res,$Degree)=split('@',$Act[$n]);
         $DoDiff{$res}=$Degree;
       }
   }
   
   
   sub LoadClassFile {
       my $file="/home/minaeibi/class.txt";
       open(FILEID, "<$file");
       my $line;
       %Grade=();
       while ($line=<FILEID>) {
           my ($id,$ex1,$ex2,$ex3,$ex4,$hw,$final,$grade)=split(' ',$line);
           $Grade{$id}=$grade;
       }
   }
   
   
   #------- Classification  
   sub Classify {
       my ($DiscFac, $students)=@_;
       &LoadClassFile();
       my $Count=0;
       my @List=();
       my @LS=();
       my @LF=();
       my @LM=();
       my $cf=0;
       my $cs=0;
       my $cm=0;
       foreach (keys(%$DiscFac)){  
    my @l=split(/\:/,$_);
    if (!($students->{$l[1]})) {next;}
    my $Grade=$Grade{$students->{$l[1]}};
    if( $Grade > 3 ) {
       $cs++;
       push(@LS,("$l[6],$l[5],$l[4],$l[7],$l[8],$l[9],Successful"));
    } elsif ( $Grade > 2 ) {
       $cm++;
       push(@LM,("$l[6],$l[5],$l[4],$l[7],$l[8],$l[9],Average"));
    } else {
       $cf++;
       push(@LF,("$l[6],$l[5],$l[4],$l[7],$l[8],$l[9],Failed"));
    }
       }    
       for(my $n=0;$n<$cs;$n++){$r->print('<br>'.$LS[$n]);}
       for(my $n=0;$n<$cm;$n++){$r->print('<br>'.$LM[$n]);}  
       for(my $n=0;$n<$cf;$n++){$r->print('<br>'.$LF[$n]);}
   } 
   
   
   sub ProcAct {
       # return;
       my ($Act,$Submit)=@_;
       my @Act=split(/\@/,$Act);
       @Act = sort(@Act);
   
       ##$r->print('<br>'.$#Act);
       ##for(my $n=0;$n<=$#Act;$n++){
   ## $r->print('<br>n='.$n.')'.$Act[$n]);
   ##    }
   
   #    my $Beg=$Act[0];
       my $Dif=$Submit-$Act[0];
       $Dif = ($Dif>0) ? ($Dif/3600) : 0; 
   
   #    $r->print('<br>Access Number = '.$#Act.'<br>Submit Time='.$Submit.'<br>First Access='.$Act[0].'<br>Last Access='.$Act[$#Act].'<br> Submit - First = <b>'.$Dif.'</b>');
   
   
   #time spent for solving the problem           
   #    $r->print('<br>Def'.($Act[$#Act-1]-$Act[0]));
   
       return $Dif;
   }
   
   
   
   sub LoadActivityLog {
   #    my $CacheDB = "/home/minaeibi/act183.log.cache";
       my $CacheDB = "/home/httpd/perl/tmp/act183.log.cache";
       
       if (-e "$CacheDB") {
    if (tie(%Activity,'GDBM_File',"$CacheDB",&GDBM_READER,0640)) {
       return;
           }
           else {
       $r->print("Unable to tie log Cache hash to db file");
           }
       }
       else {
    if (tie(%Activity,'GDBM_File',$CacheDB,&GDBM_WRCREAT,0640)) {
       foreach (keys %Activity) {delete $Activity{$_};}
       &Build_log(); 
    }
           else {
       $r->print("Unable to tie log Build hash to db file");
           }
       }
   }
   
   sub Build_log {
       my $file="/home/minaeibi/act183.log";
       open(FILEID, "<$file");
       my $line;
       my $count=0;
       while ($line=<FILEID>) {
    my ($time,$machine,$what)=split(':',$line);
    $what=&Apache::lonnet::unescape($what);
    my @accesses=split('&',$what);
              
    foreach my $access (@accesses) {
   
       $count++;
   
       my ($date,$resource,$who,$domain,$post,@posts)=split(':',$access);
       if (!$resource) { next; }
       my $res=&Apache::lonnet::unescape($resource);
       if (($res =~ /\.problem/)) {
    $Activity{$who.':'.$res}.=$date.'@';
                   #$r->print('<br>'.$time.':'.$who.'---'.$res);
    &Update_PrgInit($count);
   
       }
    }
       }
   
   # my $c=1;
   # foreach (sort keys %Activity) {
   #     $r->print('<br>'.$c.')'.$_.' ... '.$Activity{$_});
   #     $c++;
   # }
   
   }
   
 sub Activity {  sub Activity {
   #    $rid=~/(\d+)\.(\d+)/;
   #    my $MapId=$1;
   #    my $PrbId=$2;
   #    my $MapOrg = $hash{'map_id_'.$MapId};
   #    my $Map = &Apache::lonnet::declutter($MapOrg);
   #    my $URI = $hash{'src_'.$rid};
   #    my $Symb = $Map.'___'.$PrbId.'___'.&Apache::lonnet::declutter($URI);
     my $file="/home/minaeibi/activity.log";      my $file="/home/minaeibi/activity.log";
     my $userid='adamsde1';      my $userid='adamsde1';
     $r->print("<br>Using $file");      $r->print("<br>Using $file");
Line 75  sub Activity { Line 264  sub Activity {
  my @accesses=split('&',$what);   my @accesses=split('&',$what);
  foreach my $access (@accesses) {   foreach my $access (@accesses) {
     my ($date,$resource,$who,$domain,$post,@posts)=split(':',$access);      my ($date,$resource,$who,$domain,$post,@posts)=split(':',$access);
     if ($who ne $userid) { next; }      #if ($who ne $userid) { next; }
     if (!$resource) { next; }      if (!$resource) { next; }
     my $res=&Apache::lonnet::unescape($resource);      my $res=&Apache::lonnet::unescape($resource);
     if (($res =~ /\.(problem|htm|html)/)) {      if (($res =~ /\.(sequence|problem|htm|html|page)/)) {
  $Count++;       $Count++;
  $r->print("<br>$Count) ".localtime($date).": $who --> $res");   $r->print("<br>$Count) ".localtime($date).": $who --> $res");
 #        if ($post) {   #        if ($post) { 
 #    $Count++;  #    $Count++;
Line 88  sub Activity { Line 277  sub Activity {
 # }  # }
  $r->rflush();   $r->rflush();
     }      }
  ##    push (@allaccess,unescape($access));      #push (@allaccess,unescape($access));
     #print $machine;      #print $machine;
  }   }
     }      }
Line 105  sub Activity { Line 294  sub Activity {
 #    }  #    }
 }  }
   
 #---- Analyze Web Page ---------------------------------------------------  
   
 sub InitAnalysis {  sub InitAnalysis {
     my ($uri,$part,$problem,$student,$courseID)=@_;      my ($uri,$part,$problem,$student,$courseID)=@_;
     my ($username,$userdomain)=split(/\:/,$student);      my ($uname,$udom)=split(/\:/,$student);
   
   
     # Render the student's view of the problem.  $Answ is the problem       # Render the student's view of the problem.  $Answ is the problem 
     # Stringafied      # Stringafied
     my $Answ=&Apache::lonnet::ssi($uri,('grade_target'   => 'analyze',      my $Answ=&Apache::lonnet::ssi($uri,('grade_target' => 'analyze',
                                         'grade_username' => $username,                                    'grade_username' => $uname,
                                         'grade_domain'   => $userdomain,                                    'grade_domain' => $udom,
                                         'grade_courseid' => $courseID,                                    'grade_courseid' => $courseID,
                                         'grade_symb'     => $problem));                                    'grade_symb' => $problem));
 #    my $Answ=&Apache::lonnet::ssi($uri,('grade_target' => 'analyze'));  #    my $Answ=&Apache::lonnet::ssi($URI,('grade_target' => 'analyze'));
   
 #    (undef,$Answ)=split(/_HASH_REF__/,$Answ,2);  #    (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
     %Answer=();      %Answer=();
     %Answer=&Apache::lonnet::str2hash($Answ);      %Answer=&Apache::lonnet::str2hash($Answ);
   
 #    foreach (sort(keys(%Answer))) {  
 #        $r->print($_.'  '.$Answer{$_}.'<br>');  
 #    }  
   
     my $parts='';      my $parts='';
     foreach my $elm (@{$Answer{"parts"}}) {      foreach my $elm (@{$Answer{"parts"}}) {
  $parts.="$elm,";   $parts.="$elm,";
Line 150  sub InitAnalysis { Line 335  sub InitAnalysis {
     return;      return;
 }  }
   
   
 sub Interval {  sub Interval {
     my ($part,$symb)=@_;      my ($part,$symb)=@_;
     my $interval=$ConceptData{"Interval"};      my $Int=$ConceptData{"Interval"};
     my $due  = &Apache::lonnet::EXT('resource.'.$part.'.duedate',$symb)+1;      my $due = &Apache::lonnet::EXT('resource.$part.duedate',$symb)+1;
     my $open = &Apache::lonnet::EXT('resource.'.$part.'.opendate',$symb);      my $opn = &Apache::lonnet::EXT('resource.$part.opendate',$symb);
     my $add=int(($due-$open)/$interval);      my $add=int(($due-$opn)/$Int);
     $ConceptData{'Interval.0'}=$open;      $ConceptData{"Int.0"}=$opn;
     for (my $i=1;$i<$interval;$i++) {      for (my $i=1;$i<$Int;$i++) {
  $ConceptData{'Interval.'.$i}=$open+$i*$add;   $ConceptData{"Int.$i"}=$opn+$i*$add;
     }      }
     $ConceptData{'Interval.'.$interval}=$due;           $ConceptData{"Int.$Int"}=$due;     
     for (my $i=0;$i<$interval;$i++) {      for (my $i=0;$i<$Int;$i++) {
  for (my $n=0; $n<=$#Concepts; $n++ ) {   for (my $n=0; $n<=$#Concepts; $n++ ) {
     my $tmp=$Concepts[$n];      my $tmp=$Concepts[$n];
     $ConceptData{$tmp.'.'.$i.'.true'}=0;      $ConceptData{"$tmp.$i.true"}=0;
     $ConceptData{$tmp.'.'.$i.'.false'}=0;      $ConceptData{"$tmp.$i.false"}=0;
  }   }
     }      }
 }  }
   
   
 sub ShowOpGraph {  sub ShowOpGraph {
     my ($cache, $students, $courseID)=@_;      my ($cache, $students, $courseID)=@_;
     my $uri      = $cache->{'AnalyzeURI'};      my $uri      = $cache->{'AnalyzeURI'};
     my $part     = $cache->{'AnalyzePart'};      my $part     = $cache->{'AnalyzePart'};
     my $problem  = $cache->{'AnalyzeProblem'};      my $problem  = $cache->{'AnalyzeProblem'};
     my $title    = $cache->{'AnalyzeProblem'};      my $title    = $cache->{'AnalyzeTitle'};
     my $interval = $cache->{'Interval'};      my $interval = $cache->{'Interval'};
     $ConceptData{"Interval"} = $interval;      $ConceptData{"Interval"} = $interval;
   
Line 188  sub ShowOpGraph { Line 375  sub ShowOpGraph {
     $title =~ s/\ /"_"/eg;      $title =~ s/\ /"_"/eg;
     $r->print('<br><b>'.$uri.'</b>');      $r->print('<br><b>'.$uri.'</b>');
     $r->rflush();      $r->rflush();
                
     #Java script Progress window      #Java script Progress window
     &Create_PrgWin();      &Create_PrgWin();
     &Update_PrgWin("Starting to analyze problem",0,0,'');      &Update_PrgWin("Starting-to-analyze-problem");
     for(my $index=0; $index<(scalar @$students); $index++) {      for (my $index=0;$index<(scalar @$students);$index++) {
  &Update_PrgWin(scalar @$students, $index+1, $students->[$index]);   &Update_PrgWin($index);
  &OpStatus($problem, $students->[$index], $courseID);   &OpStatus($problem,$students->[$index],$courseID);
     }      }
     &Close_PrgWin();      &Close_PrgWin();
   
     $r->print('<br>');      $r->print('<br>');
     for(my $k=0; $k<$interval; $k++ ) {      for (my $k=0; $k<$interval; $k++ ) {
  &DrawGraph($k,$title);   &DrawGraph($k,$title);
     }      }
     for(my $k=0; $k<$interval; $k++ ) {      for (my $k=0; $k<$interval; $k++ ) {
  &DrawTable($k);   &DrawTable($k);
     }      }
 #$Apache::lonxml::debug=1;  #$Apache::lonxml::debug=1;
Line 212  sub ShowOpGraph { Line 399  sub ShowOpGraph {
     $r->print("<br><b>Here you can see the Problem:</b><br>$Answ");      $r->print("<br><b>Here you can see the Problem:</b><br>$Answ");
 }  }
   
   
 sub DrawTable {  sub DrawTable {
     my $k=shift;      my $k=shift;
     my $Max=0;      my $Max=0;
Line 266  sub DrawTable { Line 454  sub DrawTable {
   
   
 sub DrawGraph {  sub DrawGraph {
     my ($currentInterval,$title)=@_;      my ($k,$Src)=@_;
     my $Max=0;      my $Max=0;
     my @data1;      my @data1;
     my @data2;      my @data2;
   
     # Adjust Data and find the Max       # Adjust Data and find the Max 
     for(my $n=0; $n<=$#Concepts; $n++ ) {      for (my $n=0; $n<=$#Concepts; $n++ ) {
  my $tmp=$Concepts[$n];   my $tmp=$Concepts[$n];
  $data1[$n]=$ConceptData{$tmp.'.'.$currentInterval.'.true'};   $data1[$n]=$ConceptData{"$tmp.$k.true"};
  $data2[$n]=$ConceptData{$tmp.'.'.$currentInterval.'.false'};   $data2[$n]=$ConceptData{"$tmp.$k.false"};
  my $Sum=$data1[$n]+$data2[$n];   my $Sum=$data1[$n]+$data2[$n];
  if($Max < $Sum) { $Max = $Sum; }   if ( $Max<$Sum ) {$Max=$Sum;}
     }      }
     for(my $n=0; $n<=$#Concepts; $n++) {      for (my $n=0; $n<=$#Concepts; $n++ ) {
  if($data1[$n]+$data2[$n]<$Max) {   if ($data1[$n]+$data2[$n]<$Max) {
     $data2[$n]+=$Max-($data1[$n]+$data2[$n]);      $data2[$n]+=$Max-($data1[$n]+$data2[$n]);
  }   }
     }      }
     my $P_No = scalar @data1;      my $P_No = $#data1+1;
   
     if($Max > 1) {       if ( $Max > 1 ) { 
  $Max += (10 - $Max % 10);   $Max += (10 - $Max % 10);
  $Max = int($Max);   $Max = int($Max);
     } else {       } else { $Max = 1; }
         $Max = 1;  
     }  
   
     my $Titr=($ConceptData{'Interval'}>1) ?       my $Titr=($ConceptData{'Interval'}>1) ? $Src.'_interval_'.($k+1) : $Src;
         $title.'_interval_'.($currentInterval+1) : $title;  
 #    $GData=$Titr.'&Concepts'.'&'.'Answers'.'&'.$Max.'&'.$P_No.'&'.$data1.'&'.$data2;  #    $GData=$Titr.'&Concepts'.'&'.'Answers'.'&'.$Max.'&'.$P_No.'&'.$data1.'&'.$data2;
     $GData  = $Titr.'&Concepts&Answers&'.$Max.'&'.$P_No.'&';      $GData="$Titr&Concepts&Answers&$Max&$P_No&".
     $GData .= (join(',',@data1)).'&'.(join(',',@data2));             (join(',',@data1)).'&'.(join(',',@data2));
   
     $r->print('<IMG src="/cgi-bin/graph.gif?'.$GData.'" border=1/>');      $r->print('<IMG src="/cgi-bin/graph.gif?'.$GData.'" border=1/>');
 }  }
Line 312  sub Decide { Line 497  sub Decide {
     $ConceptData{"$foil_to_concept{$foil}.$k.$type"}++;      $ConceptData{"$foil_to_concept{$foil}.$k.$type"}++;
 }  }
   
   
 #restore the student submissions and finding the result  #restore the student submissions and finding the result
 sub OpStatus {  sub OpStatus {
     my ($problem, $student, $courseID)=@_;      my ($problem, $student, $courseID)=@_;
Line 356  sub OpStatus { Line 540  sub OpStatus {
     }      }
 }  }
   
   
 #---- END Analyze Web Page ----------------------------------------------  #---- END Analyze Web Page ----------------------------------------------
   
 #---- Problem Statistics Web Page ---------------------------------------  #---- Problem Statistics Web Page ---------------------------------------
Line 398  sub ProcessDiscriminant { Line 583  sub ProcessDiscriminant {
 }  }
   
   
   
 #------- Creating Discimination factor     #------- Creating Discimination factor   
 sub Discriminant {  sub Discriminant {
     my ($discriminantFactor)=@_;      my ($discriminantFactor)=@_;
Line 430  sub Discriminant { Line 616  sub Discriminant {
     return (\%DisUp, \%DisLow);      return (\%DisUp, \%DisLow);
 }  }
   
      
 sub NumericSort {            sub NumericSort {          
     $a <=> $b;      $a <=> $b;
 }  }
   
   
 sub CreateProblemStatisticsTableHeading {  sub CreateProblemStatisticsTableHeading {
     my ($displayFormat,$sequenceSource,$sequenceTitle,$headings)=@_;      my ($displayFormat,$sequenceSource,$sequenceTitle,$headings)=@_;
     if($displayFormat eq 'Display CSV Format') {      if($displayFormat eq 'Display CSV Format') {
Line 465  sub CloseTable { Line 653  sub CloseTable {
     $r->rflush();      $r->rflush();
 }  }
   
   
    
 # ------ Dump the Student's DB file and handling the data for statistics table   # ------ Dump the Student's DB file and handling the data for statistics table 
 sub ExtractStudentData {  sub ExtractStudentData {
     my ($cache,$name)=@_;      my ($cache,$name,$list)=@_;
     my %discriminantFactor;      my %discriminantFactor;
     my @list=();  
   
     my $totalTries = 0;      my $totalTries = 0;
     my $totalAwarded = 0;      my $totalAwarded = 0;
     my $tempProblemOrder=0;      my $tempProblemOrder=0;
       my $spent=0;
       my $spent_yes=0;
       my $TotDiscuss=0;
       my $TotalOpend = 0;
       my $ProbSolved = 0;
       my $ProbTot = 0;
       my $TotFirst = 0;
       my $TimeTot = 0;
       my $Discussed=0;
   
     foreach my $sequence (split(':', $cache->{'orderedSequences'})) {      foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
         if($cache->{'ProblemStatisticsMap'} ne 'All Maps'  &&          if($cache->{'ProblemStatisticsMap'} ne 'All Maps'  &&
            $cache->{'ProblemStatisticsMap'} ne $cache->{$sequence.':title'}) {             $cache->{'ProblemStatisticsMap'} ne $cache->{$sequence.':title'}) {
Line 525  sub ExtractStudentData { Line 724  sub ExtractStudentData {
                     my $tries=0;                      my $tries=0;
                     my $time=0;                      my $time=0;
                     my $awarded=0;                      my $awarded=0;
       $Discussed=0;
                     my $code='U';                      my $code='U';
   
                     $awarded = $cache->{$name.                      $awarded = $cache->{$name.
Line 571  sub ExtractStudentData { Line 771  sub ExtractStudentData {
                     $ptr .= "*(part $_)";                      $ptr .= "*(part $_)";
                     $Dis .= '&';                      $Dis .= '&';
                 }                  }
   
    my ($pr_no,$dod)=split('&',$ptr);
    my $DoDiff=$DoDiff{$dod};
   #               $r->print('<br>'.$name.'---'.$ptr.'==='.$DoDiff);
   
                 my $Fac = ($partData{$_.':Tries'}) ?                   my $Fac = ($partData{$_.':Tries'}) ? 
                     ($partData{$_.':awarded'}/$partData{$_.':tries'}) : 0;                      ($partData{$_.':awarded'}/$partData{$_.':tries'}) : 0;
                 my $DisF;                  my $DisF;
Line 579  sub ExtractStudentData { Line 784  sub ExtractStudentData {
                 } else {                  } else {
                     $DisF = $Fac;                      $DisF = $Fac;
                 }                  }
   
                   if ($Discuss{"$name:$problem"}) {
       $TotDiscuss++;
                       $Discussed=1;
                   }
                   my $time = $cache->{"$name:$LatestVersion:$problem:timestamp"};
                 $Dis .= $tempProblemOrder.'='.$DisF.'+'.$Yes;                  $Dis .= $tempProblemOrder.'='.$DisF.'+'.$Yes;
                 $ptr .= '&'.$partData{$_.'.Tries'}.                  $ptr .= '&'.$partData{$_.'.Tries'}.
                         '&'.$partData{$_.'.Wrongs'}.                          '&'.$partData{$_.'.Wrongs'}.
                         '&'.$partData{$_.'.Code'};                          '&'.$partData{$_.'.Code'};
                 push (@list, $ptr);                  push (@$list, $ptr."&$Discussed");
   
   #### if ($DoDiff>0.85) {
   
                   $TimeTot += $time;
   
                   if ($Yes==1 && $partData{$_.'.Tries'}==1) {
       $TotFirst++;
                   }
    my $Acts= $Activity{$name.':'.$problem};
    if ($Acts) {
       my $Pt=&ProcAct( $Acts, $time );
       #my ($spe,$beg) = split(/\+/,$Pt);
                       my $spe= $Pt;
       if ($Yes==1) {$spent_yes += $spe;}
       $spent += $spe;
       #$Beg += $beg;
   #                   $r->print('<br>'.$name.'---'.$problem.'---'.$spe);
    }
    $TotalOpend++;
    $ProbTot++;
   
                 $tempProblemOrder++;                  $tempProblemOrder++;
             }              }
         }          }
    my $pstr;
         if($totalTries) {          if($totalTries) {
     my $DisFac = ($totalAwarded/$totalTries);      my $DisFac = ($totalAwarded/$totalTries);
     my $DisFactor = sprintf( "%.4f", $DisFac );      my $DisFactor = sprintf( "%.4f", $DisFac );
     $discriminantFactor{$DisFactor}=$Dis;              my $TS = sprintf( "%.2f", $spent );
               my $TS_yes = sprintf( "%.2f", $spent_yes );
      # $DiscFac{$DisFactor}=$Dis;
       $pstr=$DisFactor.':'.$name.':'.$ProbTot.':'.$TotalOpend.':'.
                     $totalTries.':'.$ProbSolved.':'.$TotFirst.':'.
                     $TS_yes.':'.$TS.':'.$TotDiscuss;
       $discriminantFactor{$pstr}=$Dis;
  }   }
     }      }
   
     return (\%discriminantFactor, \@list);      return (\%discriminantFactor);
 }  }
   
   
   =pod
 sub MySort {            sub MySort {          
     if ( $Pos > 0 ) {      if ( $Pos > 0 ) {
  if ($ENV{'form.order'} eq 'Descending') {$b <=> $a;}   if ($ENV{'form.order'} eq 'Descending') {$b <=> $a;}
Line 607  sub MySort { Line 848  sub MySort {
  else { $a cmp $b; }   else { $a cmp $b; }
     }      }
 }  }
   =cut
   
 sub BuildStatisticsTable {  sub BuildStatisticsTable {
     my ($cache,$discriminantFactor,$list,$headings)=@_;      my ($cache,$discriminantFactor,$list,$headings,$students)=@_;
   
   #6666666
   #    my $file="/home/httpd/perl/tmp/183d.txt";
   #    open(OUT, ">$file");
   #6666666
       &Create_PrgWin();
   ##777777
   ##    &LoadActivityLog();
   ##    $r->print('<script>popwin.document.popremain.remaining.value="'.
   ##              'Loading Discussion...";</script>');
   ##    &LoadDoDiffFile();
       &LoadDiscussion();
   
     my $p_count = 0;      my $p_count = 0;
     my $nIndex = 0;      my $nIndex = 0;
Line 628  sub BuildStatisticsTable { Line 882  sub BuildStatisticsTable {
                                              $cache->{$sequence.':source'},                                                $cache->{$sequence.':source'}, 
                                              $cache->{$sequence.':title'},                                               $cache->{$sequence.':title'},
                                              $headings);                                               $headings);
   
   ##777777
   ##    &Classify($discriminantFactor, $students);
   
   
  my ($Hid,$pr)=split(/\:/,$mapsort{$_});   my ($Hid,$pr)=split(/\:/,$mapsort{$_});
  my @lpr=split(/\&/,$pr);   my @lpr=split(/\&/,$pr);
  for (my $i=1; $i<=$#lpr; $i++) {   for (my $i=1; $i<=$#lpr; $i++) {
     my %storestats=();      my %storestats=();
     my ($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\&/,$list->[$nIndex]);      my ($PrOrd,$Prob,$Tries,$Wrongs,$Code,$Disc)=split(/\&/,$list->[$nIndex]);
     my $Temp = $Prob;      my $Temp = $Prob;
     my $MxTries = 0;      my $MxTries = 0;
     my $TotalTries = 0;      my $TotalTries = 0;
Line 640  sub BuildStatisticsTable { Line 899  sub BuildStatisticsTable {
     my $Incorrect = 0;      my $Incorrect = 0;
     my $Override = 0;      my $Override = 0;
     my $StdNo = 0;      my $StdNo = 0;
       my $DiscNo=0;
     my @StdLst;      my @StdLst;
     while ( $PrOrd == $lpr[$i] )       while ( $PrOrd == $lpr[$i] ) 
     {      {
Line 652  sub BuildStatisticsTable { Line 912  sub BuildStatisticsTable {
  elsif( $Code eq 'I' ) { $Incorrect++; }   elsif( $Code eq 'I' ) { $Incorrect++; }
  elsif( $Code eq 'O' ) { $Override++; }   elsif( $Code eq 'O' ) { $Override++; }
  elsif( $Code eq 'U' ) { $StdNo--; }   elsif( $Code eq 'U' ) { $StdNo--; }
  ($PrOrd,$Prob,$Tries,$Wrongs,$Code)=split(/\&/,$list->[$nIndex]);   ($PrOrd,$Prob,$Tries,$Wrongs,$Code,$Disc)=split(/\&/,$list->[$nIndex]);
     }      }
   
     $p_count++;      $p_count++;
Line 732  sub BuildStatisticsTable { Line 992  sub BuildStatisticsTable {
                        $TotalTries.'&'.$MxTries.'&'.$Avg.'&'.                         $TotalTries.'&'.$MxTries.'&'.$Avg.'&'.
                        $YES.'&'.$Override.'&'.$Wrng.'&'.$DoD.'&'.                         $YES.'&'.$Override.'&'.$Wrng.'&'.$DoD.'&'.
        $SD.'&'.$Sk.'&'.$_D1.'&'.$_D2.'&'.         $SD.'&'.$Sk.'&'.$_D1.'&'.$_D2.'&'.
                        $Prob;                         $DiscNo.'&'.$Prob;
     $CachData{($p_count-1)}=$join;      $CachData{($p_count-1)}=$join;
   
   #6666666
   #    $r->print('<br>'.$out.'&'.$DoD);
   #            print (OUT $out.'@'.$DoD.'&');
   #6666666
   
     $urlres=~/^(\w+)\/(\w+)/;      $urlres=~/^(\w+)\/(\w+)/;
     if ($StdNo) {       if ($StdNo) { 
  &Apache::lonnet::put('resevaldata',\%storestats,$1,$2);    &Apache::lonnet::put('resevaldata',\%storestats,$1,$2); 
Line 745  sub BuildStatisticsTable { Line 1010  sub BuildStatisticsTable {
  &CloseTable($cache);   &CloseTable($cache);
     }      }
     &Close_PrgWin();      &Close_PrgWin();
   #666666
   #    close( OUT );
   #666666
 }  }
   
 =pod  =pod
Line 797  sub Cache_Statistics { Line 1065  sub Cache_Statistics {
  &CloseTable($cache);   &CloseTable($cache);
     }      }
 }  }
 =cut  =cut 
   
   
   
 sub TableRow {  sub TableRow {
     my ($cache,$Str,$Idx,$RealIdx)=@_;      my ($Str,$Idx,$RealIdx)=@_;
     my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,      my($PrOrd,$Temp,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
        $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$Prob)=split(/\&/,$Str);         $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$DiscNo,$Prob)=split(/\&/,$Str);
     if($cache->{'DisplayFormat'} eq 'Display CSV Format') {      if ($ENV{'form.showcsv'}) {
         my ($ResId,$Dummy)=split(/\*/,$Prob);          my ($ResId,$Dummy)=split(/\*/,$Prob);
         my $Ptr =  "\n".'<br>'.          my $Ptr =  "\n".'<br>'.
                "\n".'"'.($RealIdx+1).'",'.                 "\n".'"'.($RealIdx+1).'",'.
Line 819  sub TableRow { Line 1090  sub TableRow {
                "\n".'"'.$SD.'",'.                 "\n".'"'.$SD.'",'.
                "\n".'"'.$Sk.'",'.                 "\n".'"'.$Sk.'",'.
                "\n".'"'.$_D1.'",'.                 "\n".'"'.$_D1.'",'.
        "\n".'"'.$_D2.'"';         "\n".'"'.$_D2.'"'.
          "\n".'"'.$DiscNo.'"';
   
         $r->print("\n".$Ptr);          $r->print("\n".$Ptr);
     } else {      }
       else{
         my $Ptr =  "\n".'<tr>'.          my $Ptr =  "\n".'<tr>'.
                "\n".'<td>'.($RealIdx+1).'</td>'.                 "\n".'<td>'.($RealIdx+1).'</td>'.
           #     "\n".'<td>'.$PrOrd.$Temp.'</td>'.            #     "\n".'<td>'.$PrOrd.$Temp.'</td>'.
Line 837  sub TableRow { Line 1111  sub TableRow {
                "\n".'<td bgcolor='.$color{"green"}.'> '.$SD.'</td>'.                 "\n".'<td bgcolor='.$color{"green"}.'> '.$SD.'</td>'.
                "\n".'<td bgcolor='.$color{"green"}.'> '.$Sk.'</td>'.                 "\n".'<td bgcolor='.$color{"green"}.'> '.$Sk.'</td>'.
                "\n".'<td bgcolor='.$color{"purple"}.'> '.$_D1.'</td>'.                 "\n".'<td bgcolor='.$color{"purple"}.'> '.$_D1.'</td>'.
        "\n".'<td bgcolor='.$color{"purple"}.'> '.$_D2.'</td>';         "\n".'<td bgcolor='.$color{"purple"}.'> '.$_D2.'</td>'.
                  "\n".'<td bgcolor='.$color{"yellow"}.'> '.$DiscNo.'</td>';
         $r->print("\n".$Ptr.'</tr>' );          $r->print("\n".$Ptr.'</tr>' );
     }      }
     $GraphDat{$RealIdx}=$DoD.':'.$Wrng;      $GraphDat{$RealIdx}=$DoD.':'.$Wrng;
Line 965  sub ProblemStatisticsLegend { Line 1240  sub ProblemStatisticsLegend {
     $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';      $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
     $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';      $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
     $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';      $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
       $Ptr .= '</td></tr>';
       $Ptr .= '<tr><td><b>Disc.</b></td>';
       $Ptr .= '<td>Number of Students had at least one discussion.';
     $Ptr .= '</td></tr></table>';      $Ptr .= '</td></tr></table>';
   
     return $Ptr;      return $Ptr;
Line 974  sub ProblemStatisticsLegend { Line 1252  sub ProblemStatisticsLegend {
   
 #---- Problem Statistics Graph Web Page --------------------------------------  #---- Problem Statistics Graph Web Page --------------------------------------
   
   # ------------------------------------------- Prepare data for Graphical chart
   
 sub GetGraphData {  sub GetGraphData {
     my ($whichGraph, $courseID)=@_;      my $ylab = shift;
     my $Col=0;      my $Col;
     my $graphTitle='';  
     my $data='';      my $data='';
     my $count = 0;      my $count = 0;
     my $Max = 0;      my $Max = 0;
     my $graphData='Graph data does not exist.';      my $cid=$ENV{'request.course.id'};
     my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".      my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
                   "_$ENV{'user.domain'}_$courseID\_graph.db";                    "_$ENV{'user.domain'}_$cid\_graph.db";
     if(-e $GraphDB) {      foreach (keys %GraphDat) {delete $GraphDat{$_};}
  if(tie(%GraphDat,'GDBM_File',"$GraphDB",&GDBM_READER,0640)) {      if (-e "$GraphDB") {
     if($whichGraph eq 'DiffGraph') {   if (tie(%GraphDat,'GDBM_File',"$GraphDB",&GDBM_READER,0640)) {
  $graphTitle = 'Degree-of-Difficulty';      if ( $ylab eq 'DoDiff Graph' ) {
    $ylab = 'Degree-of-Difficulty';
  $Col = 0;   $Col = 0;
     } else {      }
  $graphTitle = 'Wrong-Percentage';      else {
    $ylab = 'Wrong-Percentage';
  $Col = 1;   $Col = 1;
     }      }
     foreach (sort NumericSort keys %GraphDat) {       foreach (sort NumericSort keys %GraphDat) { 
  my @Temp=split(/\:/,$GraphDat{$_});   my @Temp=split(/\:/,$GraphDat{$_});
                 my $inf = $Temp[$Col];                   my $inf = $Temp[$Col]; 
  if($Max < $inf) {   if ( $Max < $inf ) {$Max = $inf;}
                     $Max = $inf;  
                 }  
  $data .= $inf.',';   $data .= $inf.',';
  $count++;   $count++;
     }      }
     if($Max > 1) {       if ( $Max > 1 ) { 
  $Max += (10 - $Max % 10);   $Max += (10 - $Max % 10);
  $Max = int($Max);   $Max = int($Max);
     } else {       }
                 $Max = 1;      else { $Max = 1; }
             }  
             untie(%GraphDat);              untie(%GraphDat);
     my $Course = $ENV{'course.'.$courseID.'.description'};      my $Course = $ENV{'course.'.$cid.'.description'};
     $Course =~ s/\ /"_"/eg;      $Course =~ s/\ /"_"/eg;
     $graphData  = $Course.'&'.'Problems'.'&'.$graphTitle.'&'.$Max.'&';      $GData=$Course.'&'.'Problems'.'&'.$ylab.'&'.$Max.'&'.$count.'&'.$data;
             $graphData .= $count.'&'.$data;   }
  } else {   else {
     $graphData = "Unable to tie hash to db file";      $r->print("Unable to tie hash to db file");
  }   }
     }      }
   
     return $graphData;  
 }  }
   
 #---- END Problem Statistics Graph Web Page ----------------------------------  
   
 #---- Problem Analysis Web Page ----------------------------------------------  #---- Problem Analysis Web Page ----------------------------------------------
   
 sub IntervalOptions {  sub IntervalOptions {
Line 1079  sub OptionResponseTable { Line 1352  sub OptionResponseTable {
   
 #---- Student Assessment Web Page --------------------------------------------  #---- Student Assessment Web Page --------------------------------------------
   
 sub MapOptions {  
     my ($cache, $page)=@_;  
     my $Ptr = '<tr>';  
     $Ptr .= '<td align="right"><b>Select Map</b></td>'."\n";  
     $Ptr .= '<td align="left"><select name="Maps">'."\n";  
   
     my $selected = 0;  
     foreach my $sequence (split(':',$cache->{'orderedSequences'})) {  
  $Ptr .= '<option';  
         if($cache->{$page.'Map'} eq $cache->{$sequence.':title'}) {  
             $Ptr .= ' selected';  
             $selected = 1;  
         }  
  $Ptr .= '>'.$cache->{$sequence.':title'}.'</option>'."\n";       
     }  
     $Ptr .= '<option';  
     if(!$selected) {  
         $Ptr .= ' selected';  
     }  
     $Ptr .= '>All Maps</option>'."\n";  
   
     $Ptr .= '</select></td></tr>'."\n";  
   
     return $Ptr;  
 }  
   
 sub StudentOptions {  
     my ($students, $selectedName)=@_;  
   
     my $Ptr ='<tr>';  
     $Ptr .= '<td align="right"><b>Select Student</b></td>'."\n";  
     $Ptr .= '<td align="left"><select name="Students">'."\n";  
   
     my $selected=0;  
     foreach (@$students) {  
         my ($name) = split(':',$_);  
  $Ptr .= '<option';  
  if($selectedName eq $name) {  
             $Ptr .= ' selected';  
             $selected = 1;  
         }  
         $Ptr .= '>'.$name.'</option>'."\n";       
     }  
   
     $Ptr .= '<option';  
     if(!$selected) {  
         $Ptr .= ' selected';  
     }  
     $Ptr .= '>No Student Selected</option>'."\n";  
   
     $Ptr .= '</select></td></tr>'."\n";  
   
     return $Ptr;  
 }  
   
 # ------ Create different Student Report   # ------ Create different Student Report 
 sub StudentReport {  sub StudentReport {
     my ($cache, $name)=@_;      my ($cache, $name)=@_;
Line 1245  sub StudentReport { Line 1463  sub StudentReport {
   
 #---- Menu Web Page ----------------------------------------------------------  #---- Menu Web Page ----------------------------------------------------------
   
 sub Title {  
     my ($downloadTime)=@_;  
   
     my $Ptr = '';  
   
     $Ptr .= '<html><head><title>LON-CAPA Statistics</title></head>'."\n";  
     $Ptr .= '<body bgcolor="#FFFFFF">'."\n";  
     $Ptr .= '<script>window.focus(); window.width=500;window.height=500;';  
     $Ptr .= '</script>'."\n";  
     $Ptr .= '<img align=right src=/adm/lonIcons/lonlogos.gif>'."\n";  
     $Ptr .= '<h1> Course : "';  
     $Ptr .= $ENV{'course.'.$ENV{'request.course.id'}.'.description'};  
     $Ptr .= '"</h1>'."\n";  
     $Ptr .= '<h3>'.$downloadTime.'</h3>';  
   
     return $Ptr;  
 }  
   
 sub CreateMenuForm {  
     my ($cache)=@_;  
     my $Ptr = '<table border="0">';  
     $Ptr .= '<tr><td><input type="submit" name="ProblemStatistics" ';  
     $Ptr .= 'value="Problem Stats"/>';  
     $Ptr .= '</td></tr>'."\n";  
   
     if(defined($cache->{'OptionResponses'})) {  
         $Ptr .= '<tr><td><input type="submit" name="ProblemAnalysis" ';  
         $Ptr .= 'value="Problem Analysis"/>';  
         $Ptr .= '</td></tr>'."\n";  
     }  
   
     $Ptr .= '<tr><td><input type="submit" name="StudentAssessment" ';  
     $Ptr .= 'value="Student Assessment"/>';  
     $Ptr .= '</td></tr>'."\n";  
     #$Ptr .= '<input type="submit" name="ActivityLog" value="Activity Log"/>';  
   
     $Ptr .= '</table>'."\n";  
   
     return $Ptr;  
 }  
   
 #---- END Menu Web Page ------------------------------------------------------  #---- END Menu Web Page ------------------------------------------------------
   
 #---- HELPER FUNCTIONS -------------------------------------------------------  #---- HELPER FUNCTIONS -------------------------------------------------------
Line 1303  sub CheckFormElement { Line 1480  sub CheckFormElement {
 }  }
   
 sub ProcessFormData{  sub ProcessFormData{
     my ($cacheDB, $isCached)=@_;      my ($cache)=@_;
     my %cache;  
   
     if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {      $cache->{'reportKey'} = 'false';
         # Select page to display  
         if(defined($ENV{'form.ProblemStatistics'}) ||  
            defined($ENV{'form.ProblemStatisticsRecalculate'}) ||   
            defined($ENV{'form.DisplayCSVFormat'})) {  
             $cache{'GoToPage'} = 'ProblemStatistics';  
             &CheckFormElement(\%cache, 'DisplayCSVFormat',  
                               'DisplayFormat', 'Display Table Format');  
             &CheckFormElement(\%cache, 'Ascend','ProblemStatisticsAscend',  
                               'Ascending');  
             &CheckFormElement(\%cache, 'Maps', 'ProblemStatisticsMap',   
                               'All Maps');  
         } elsif(defined($ENV{'form.ProblemAnalysis'})) {  
             $cache{'GoToPage'} = 'ProblemAnalysis';  
             &CheckFormElement(\%cache, 'Interval', 'Interval', '1');  
         } elsif(defined($ENV{'form.StudentAssessment'}) ||  
                 defined($ENV{'form.CreateStudentAssessment'}) ||  
                 defined($ENV{'form.NextStudent'}) ||  
                 defined($ENV{'form.PreviousStudent'})) {  
             $cache{'GoToPage'} = 'StudentAssessment';  
             if(defined($ENV{'form.NextStudent'})) {  
                 $cache{'StudentAssessmentMove'} = 'next';  
             } elsif(defined($ENV{'form.PreviousStudent'})) {  
                 $cache{'StudentAssessmentMove'} = 'previous';  
             } else {  
                 $cache{'StudentAssessmentMove'} = 'selected';  
             }  
             &CheckFormElement(\%cache, 'Maps', 'StudentAssessmentMap',   
                               'All Maps');  
   
             &CheckFormElement(\%cache, 'Students', 'StudentAssessmentStudent',       &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
                               'No Student Selected');                                              ['sort','download']);
         } elsif(defined($ENV{'form.DoDiffGraph'})) {      &CheckFormElement($cache, 'Status', 'Status', 'Active');
             $cache{'GoToPage'} = 'DoDiffGraph';      &CheckFormElement($cache, 'postdata', 'reportSelected', 'Class list');
         } elsif(defined($ENV{'form.PercentWrongGraph'})) {      &CheckFormElement($cache, 'reportSelected', 'reportSelected', 
             $cache{'GoToPage'} = 'PercentWrongGraph';                        'Class list');
         } elsif(defined($ENV{'form.ActivityLog'})) {      &CheckFormElement($cache, 'DownloadAll', 'DownloadAll', 'false');
             $cache{'GoToPage'} = 'ActivityLog';      &CheckFormElement($cache, 'sort', 'sort', 'fullname');
         } else {      &CheckFormElement($cache, 'download', 'download', 'false');
             $cache{'GoToPage'} = 'Menu';  
       if(defined($ENV{'form.CreateStudentAssessment'}) ||
          defined($ENV{'form.NextStudent'}) ||
          defined($ENV{'form.PreviousStudent'})) {
           $cache->{'reportSelected'} = 'Student Assessment';
       }
       if(defined($ENV{'form.NextStudent'})) {
           $cache->{'StudentAssessmentMove'} = 'next';
       } elsif(defined($ENV{'form.PreviousStudent'})) {
           $cache->{'StudentAssessmentMove'} = 'previous';
       } else {
           $cache->{'StudentAssessmentMove'} = 'selected';
       }
       &CheckFormElement($cache, 'StudentAssessmentMap', 'StudentAssessmentMap', 
                         'All Maps');
       &CheckFormElement($cache, 'StudentAssessmentStudent', 
                         'StudentAssessmentStudent', 'No Student Selected');
   
       foreach (keys(%ENV)) {
           if(/form\.Analyze:::/) {
   #            $cache->{'reportSelected'} = 'Analyze';
   #            $cache->{'reportKey'} = 'Problem Analysis';
               my ($uri, $title, $part, $problem);
               (undef, $uri, $title, $part, $problem)=split(':::', $_);
               $cache->{'AnalyzeURI'}     = $uri;
               $cache->{'AnalyzeTitle'}   = $title;
               $cache->{'AnalyzePart'}    = $part;
               $cache->{'AnalyzeProblem'} = $problem;
               
               &CheckFormElement($cache, 'Interval', 'Interval', '1');
         }          }
       }
   
         &CheckFormElement(\%cache, 'Status', 'Status', 'Active');      return;
   
         foreach (keys(%ENV)) {  
             if(/form\.Analyze:::/) {  
                 $cache{'GoToPage'} = 'Analyze';  
                 my ($uri, $title, $part, $problem);  
                 (undef, $uri, $title, $part, $problem)=split(':::', $_);  
                 $cache{'AnalyzeURI'}     = $uri;  
                 $cache{'AnalyzeTitle'}   = $title;  
                 $cache{'AnalyzePart'}    = $part;  
                 $cache{'AnalyzeProblem'} = $problem;  
   
                 &CheckFormElement(\%cache, 'Interval', 'Interval', '1');      # Select page to display
             }      if(defined($ENV{'form.ProblemStatistics'}) ||
         }         defined($ENV{'form.ProblemStatisticsRecalculate'}) || 
          defined($ENV{'form.DisplayCSVFormat'})) {
           $cache->{'GoToPage'} = 'ProblemStatistics';
           &CheckFormElement($cache, 'DisplayCSVFormat',
                             'DisplayFormat', 'Display Table Format');
           &CheckFormElement($cache, 'Ascend','ProblemStatisticsAscend',
                             'Ascending');
           &CheckFormElement($cache, 'Maps', 'ProblemStatisticsMap', 
                             'All Maps');
       } elsif(defined($ENV{'form.ProblemAnalysis'})) {
           $cache->{'GoToPage'} = 'ProblemAnalysis';
           &CheckFormElement($cache, 'Interval', 'Interval', '1');
       } elsif(defined($ENV{'form.DoDiffGraph'})) {
           $cache->{'GoToPage'} = 'DoDiffGraph';
       } elsif(defined($ENV{'form.PercentWrongGraph'})) {
           $cache->{'GoToPage'} = 'PercentWrongGraph';
       } elsif(defined($ENV{'form.ActivityLog'})) {
           $cache->{'GoToPage'} = 'ActivityLog';
       } else {
           $cache->{'GoToPage'} = 'Menu';
     }      }
   
       &CheckFormElement($cache, 'Status', 'Status', 'Active');
   
     return;      return;
 }  }
   
Line 1394  Output: \@order Line 1583  Output: \@order
 =cut  =cut
   
 sub SortStudents {  sub SortStudents {
     my ($students,$cache)=@_;      my ($cache)=@_;
   
       my @students = split(':::',$cache->{'NamesOfStudents'});
     my @sorted1Students=();      my @sorted1Students=();
     foreach (@$students) {      foreach (@students) {
         push(@sorted1Students, $_);          if($cache->{'Status'} eq 'Any' || 
     }             $cache->{$_.':Status'} eq $cache->{'Status'}) {
 #        my ($end,$start)=split(/\:/,$cache->{$_.':date'});              push(@sorted1Students, $_);
 #        my $active=1;          }
 #        my $now=time;  
 #        my $Status=$cache->{'form.Status'};  
 #        $Status = ($Status) ? $Status : 'Active';  
 #        if((($end) && $now > $end) && (($Status eq 'Active'))) {   
 #            $active=0;   
 #        }  
 #        if(($Status eq 'Expired') && ($end == 0 || $now < $end)) {  
 #            $active=0;  
 #        }  
 #        if($active) {  
 #            push(@sorted1Students, $_);  
 #        }  
 #    }  
   
     my $Pos = $cache->{'form.ChartSort'};  
     my %sortData;  
     if($Pos eq 'Last Name') {  
  for(my $index=0; $index<scalar @sorted1Students; $index++) {  
     $sortData{$cache->{$sorted1Students[$index].':fullname'}}=  
  $sorted1Students[$index];  
  }  
     } elsif($Pos eq 'Section') {  
  for(my $index=0; $index<scalar @sorted1Students; $index++) {  
     $sortData{$cache->{$sorted1Students[$index].':section'}.  
       $sorted1Students[$index]}=$sorted1Students[$index];  
  }  
     } else {  
  # Sort by user name  
  for(my $index=0; $index<scalar @sorted1Students; $index++) {  
     $sortData{$sorted1Students[$index]}=$sorted1Students[$index];  
  }  
     }      }
   
     my @order = ();      my $sortBy = '';
     foreach my $key (sort(keys(%sortData))) {      if(defined($cache->{'sort'})) {
  push (@order,$sortData{$key});          $sortBy = ':'.$cache->{'sort'};
     }      }
       my @order = sort { $cache->{$a.$sortBy} cmp $cache->{$b.$sortBy} ||
                          $cache->{$a.':fullname'} cmp $cache->{$b.':fullname'} } 
                   @sorted1Students;
   
     return \@order;      return \@order;
 }  }
Line 1447  sub PrepareData { Line 1609  sub PrepareData {
     my ($c, $cacheDB)=@_;      my ($c, $cacheDB)=@_;
   
     # Test for access to the cache data      # Test for access to the cache data
     my $isCached=0;  
     my $courseID=$ENV{'request.course.id'};      my $courseID=$ENV{'request.course.id'};
     my $isRecalculate=0;      my $isRecalculate=0;
     if(defined($ENV{'form.ProblemStatisticsRecalculate'}) ||      if(defined($ENV{'form.Recalculate'})) {
        defined($ENV{'form.ChartRecalculate'})) {  
         $isRecalculate=1;          $isRecalculate=1;
     }      }
   
     $isRecalculate=1;      my $isCached = &Apache::loncoursedata::TestCacheData($cacheDB, 
                                                            $isRecalculate);
     $isCached=&Apache::loncoursedata::TestCacheData($cacheDB, $isRecalculate);  
     if($isCached < 0) {      if($isCached < 0) {
         return "Unable to tie hash to db file.";          return "Unable to tie hash to db file.";
     }      }
     &ProcessFormData($cacheDB, $isCached);  
   
     # Download class list information if not using cached data      # Download class list information if not using cached data
     my %cache;      my %cache;
     my @students=();      unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {
     if(!$isCached) {          return "Unable to tie hash to db file.";
         unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {      }
             return "Unable to tie hash to db file.";  
         }  
   
       if(!$isCached) {
         my $processTopResourceMapReturn=          my $processTopResourceMapReturn=
             &Apache::loncoursedata::ProcessTopResourceMap(\%cache, $c);              &Apache::loncoursedata::ProcessTopResourceMap(\%cache, $c);
         if($processTopResourceMapReturn ne 'OK') {          if($processTopResourceMapReturn ne 'OK') {
             untie(%cache);              untie(%cache);
             return $processTopResourceMapReturn;              return $processTopResourceMapReturn;
         }          }
       }
   
         if($c->aborted()) {      if($c->aborted()) {
             untie(%cache);          untie(%cache);
             return 'aborted';           return 'aborted'; 
         }      }
   
         my $classlist=&Apache::loncoursedata::DownloadStudentNamePIDSection(      my $classlist=&Apache::loncoursedata::DownloadClasslist($courseID,
                                                                    $courseID,                                                   $cache{'ClasslistTimestamp'},
                                                                    $c);                                                  $c);
         my ($checkForError)=keys(%$classlist);      foreach (keys(%$classlist)) {
         if($checkForError =~ /^(con_lost|error|no_such_host)/i ||          if(/^(con_lost|error|no_such_host)/i) {
            defined($classlist->{'error'})) {  
             untie(%cache);              untie(%cache);
             return "Error getting student data.";              return "Error getting student data.";
         }          }
       }
   
         if($c->aborted()) {      if($c->aborted()) {
             untie(%cache);          untie(%cache);
             return 'aborted';           return 'aborted'; 
         }      }
   
         # Active is a temporary solution, remember to change      # Active is a temporary solution, remember to change
         @students=&Apache::loncoursedata::ProcessClassList(\%cache,       Apache::loncoursedata::ProcessClasslist(\%cache,$classlist,$courseID,$c);
                                                            $classlist,       if($c->aborted()) {
                                                            $courseID,           untie(%cache);
                                                            'Active', $c);          return 'aborted'; 
       }
   
         if($c->aborted()) {      &ProcessFormData(\%cache);
             untie(%cache);      my $students = &SortStudents(\%cache);
             return 'aborted';   
         }  
   
         untie(%cache);      if($cache{'download'} ne 'false') {
     } else {          my $who = $cache{'download'};
         if(!$c->aborted() && tie(%cache,'GDBM_File',$cacheDB,          my $courseData = 
                                  &GDBM_READER,0640)) {              &Apache::loncoursedata::DownloadStudentCourseInformation(
             @students=split(/:::/,$cache{'NamesOfStudents'});                                               $who, $courseID, 
                                                $cache{$who.':lastDownloadTime'});
           &Apache::loncoursedata::ProcessStudentData(\%cache, $courseData, $who);
           $cache{'download'} = 'false';
       } elsif($cache{'DownloadAll'} ne 'false') {
           my @allStudents;
           if($cache{'DownloadAll'} eq 'sorted') {
               @allStudents = @$students;
         } else {          } else {
             return 'aborted';              @allStudents = split(':::', $cache{'NamesOfStudents'});
         }          }
           foreach (@allStudents) {
               my $courseData = 
                   &Apache::loncoursedata::DownloadStudentCourseInformation(
                                                $_, $courseID, 
                                                $cache{$_.':lastDownloadTime'});
               &Apache::loncoursedata::ProcessStudentData(\%cache, $courseData, 
                                                          $_);
               if($c->aborted()) {
                   untie(%cache);
                   return 'aborted'; 
               }
           }
           $cache{'DownloadAll'} = 'false';
       }
   
       if($c->aborted()) {
           untie(%cache);
           return 'aborted'; 
     }      }
   
     return ('OK', $isCached, \@students);      if($c->aborted()) {
           untie(%cache);
           return 'aborted'; 
       }
   
       untie(%cache);
   
       return ('OK', $students);
 }  }
   
 # Create progress  # Create progress
Line 1581  sub initial { Line 1770  sub initial {
     undef %CachData;      undef %CachData;
     undef %GraphDat;      undef %GraphDat;
     undef %ConceptData;      undef %ConceptData;
     undef $Pos;  
     undef $GData;      undef $GData;
 }  }
   
 #---- END HELPER FUNCTIONS ---------------------------------------------------  #---- END HELPER FUNCTIONS ---------------------------------------------------
   
 sub BuildProblemStatisticsPage {  sub BuildProblemStatisticsPage {
     my ($cacheDB, $students)=@_;      my ($cacheDB, $students, $courseID, $c)=@_;
   
     my %cache;      my %cache;
     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {      unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
Line 1597  sub BuildProblemStatisticsPage { Line 1785  sub BuildProblemStatisticsPage {
     }      }
   
     my $Ptr = '';      my $Ptr = '';
     $Ptr .= '<form name="ProblemStatisticsPage" method="post" ';  
     $Ptr .= 'action="/adm/statistics">'."\n";  
     $Ptr .= '<table border="0"><tbody>';      $Ptr .= '<table border="0"><tbody>';
     $Ptr .= '<tr><td></td><td align="left"><input type="submit" name="Menu" ';      $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
     $Ptr .= 'value="Return to Menu" /></td></tr>'."\n";      $Ptr .= '<td align="left">';
       $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics');
       $Ptr .= '</td></tr>'."\n";
     $r->print($Ptr);      $r->print($Ptr);
   
     $r->print(&MapOptions(\%cache, 'ProblemStatistics'));  
     $r->print(&StatusOptions());  
     $r->print(&AscendOrderOptions());      $r->print(&AscendOrderOptions());
     $r->print(&ProblemStatisticsButtons(\%cache));      $r->print(&ProblemStatisticsButtons(\%cache));
     $r->print('</table>');      $r->print('</table>');
   
     $r->print(&ProblemStatisticsLegend());      $r->print(&ProblemStatisticsLegend());
   
 #    my $discriminantFactor;      untie(%cache);
 #    my $list;      foreach (@$students) {
 #    foreach (@$students) {          my $courseData = 
 #        ($discriminantFactor, $list) = &ExtractStudentData($_);              &Apache::loncoursedata::DownloadStudentCourseInformation($_, 
 #    }                                                                      $courseID);
           last if ($c->aborted());
           if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {
               &Apache::loncoursedata::ProcessStudentData(\%cache, 
                                                          $courseData, $_);
               untie(%cache);
           }
       }
       if($c->aborted()) { return; }
   
 #    my ($upper, $lower) = &Discriminant($discriminantFactor);      unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
 #    my %Header = (0,"Homework Sets Order",1,"#Stdnts",2,"Tries",3,"Mod",          $r->print('<html><body>Unable to tie database.</body></html>');
 #                  4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"DoDiff",          return;
 #                  9,"S.D.",10,"Skew.",11,"D.F.1st",12,"D.F.2nd");      }
 #    &BuildStatisticsTable(\%cache, $discriminantFactor, $list, \%Header);      my $discriminantFactor;
       my @list=();
       foreach (@$students) {
           $discriminantFactor = &ExtractStudentData(\%cache, $_, \@list);
       }
   
     $r->print('</form>');      my ($upper, $lower) = &Discriminant($discriminantFactor);
       my %Header = (0,"Homework Sets Order",1,"#Stdnts",2,"Tries",3,"Mod",
                     4,"Mean",5,"#YES",6,"#yes",7,"%Wrng",8,"DoDiff",
                     9,"S.D.",10,"Skew.",11,"D.F.1st",12,"D.F.2nd", 13, "Disc.");
       &BuildStatisticsTable(\%cache, $discriminantFactor, \@list, \%Header, 
                              $students);
   
     untie(%cache);      untie(%cache);
   
Line 1674  sub BuildProblemAnalysisPage { Line 1876  sub BuildProblemAnalysisPage {
         return;          return;
     }      }
   
     $r->print('<form name="ProblemAnalysisPage" method="post" ');  
     $r->print('action="/adm/statistics">'."\n");  
     $r->print('<tr><td></td><td align="left"><input type="submit" ');  
     $r->print('name="Menu" value="Return to Menu" /></td></tr>'."\n");  
     $r->print(&IntervalOptions());      $r->print(&IntervalOptions());
     $r->print(&OptionResponseTable(\%cache));      $r->print(&OptionResponseTable(\%cache));
     $r->print('</form>'."\n");  
   
     untie(%cache);      untie(%cache);
   
Line 1688  sub BuildProblemAnalysisPage { Line 1885  sub BuildProblemAnalysisPage {
 }  }
   
 sub BuildStudentAssessmentPage {  sub BuildStudentAssessmentPage {
     my ($cacheDB, $students, $courseID)=@_;      my ($cacheDB, $students, $courseID, $c)=@_;
   
     my %cache;      my %cache;
   
     my $Ptr = '';      my $Ptr = '';
     $Ptr .= '<form name="StudentAssessmentPage" method="post" ';  
     $Ptr .= 'action="/adm/statistics">'."\n";  
     $Ptr .= '<table border="0"><tbody>';      $Ptr .= '<table border="0"><tbody>';
     $Ptr .= '<tr><td></td><td align="left"><input type="submit" name="Menu" ';  
     $Ptr .= 'value="Return to Menu" /></td></tr>'."\n";  
     $r->print($Ptr);      $r->print($Ptr);
   
     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {      unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
Line 1706  sub BuildStudentAssessmentPage { Line 1899  sub BuildStudentAssessmentPage {
     }      }
   
     my $selectedName = $cache{'StudentAssessmentStudent'};      my $selectedName = $cache{'StudentAssessmentStudent'};
     for(my $index=0; $index<(scalar @$students); $index++) {      for(my $index=0; 
         my ($username) = split(':', $students->[$index]);          ($selectedName ne 'All Students') && ($index<(scalar @$students)); 
         if($username eq $selectedName) {          $index++) {
           my $fullname = $cache{$students->[$index].':fullname'};
           if($fullname eq $selectedName) {
             if($cache{'StudentAssessmentMove'} eq 'next') {              if($cache{'StudentAssessmentMove'} eq 'next') {
                 if($index == ((scalar @$students) - 1)) {                  if($index == ((scalar @$students) - 1)) {
                     ($selectedName) = split(':',$students->[0]);                      $selectedName = $students->[0];
                 } else {                  } else {
                     ($selectedName) = split(':',$students->[$index+1]);                      $selectedName = $students->[$index+1];
                 }                  }
             } elsif($cache{'StudentAssessmentMove'} eq 'previous') {              } elsif($cache{'StudentAssessmentMove'} eq 'previous') {
                 if($index == 0) {                  if($index == 0) {
                     ($selectedName) = split(':',                      $selectedName = $students->[-1];
                                            $students->[(scalar @$students)-1]);  
                 } else {                  } else {
                     ($selectedName)=split(':',$students->[$index-1]);                      $selectedName = $students->[$index-1];
                 }                  }
               } else {
                   $selectedName = $students->[$index];
             }              }
             last;              last;
         }          }
     }      }
   
     $r->print(&MapOptions(\%cache, 'StudentAssessment'));      $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
     $r->print(&StudentOptions($students, $selectedName));      $Ptr .= '<td align="left">';
       $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'StudentAssessment');
       $Ptr .= '</td></tr>'."\n";
       $Ptr .= '<tr><td align="right"><b>Select Student</b></td>'."\n";
       $Ptr .= '<td align="left">'."\n";
       $Ptr .= &Apache::lonhtmlcommon::StudentOptions(\%cache, $students, 
                                                      $selectedName, 
                                                      'StudentAssessment');
       $Ptr .= '</td></tr>'."\n";
       untie(%cache);
   
     $Ptr  = '<tr><td></td><td align="left">';      $Ptr .= '<tr><td></td><td align="left">';
     $Ptr .= '<input type="submit" name="CreateStudentAssessment" ';      $Ptr .= '<input type="submit" name="CreateStudentAssessment" ';
     $Ptr .= 'value="Create Student Report" />';      $Ptr .= 'value="Create Student Report" />';
     $Ptr .= '&nbsp&nbsp&nbsp';      $Ptr .= '&nbsp&nbsp&nbsp';
Line 1740  sub BuildStudentAssessmentPage { Line 1945  sub BuildStudentAssessmentPage {
     $Ptr .= '<input type="submit" name="NextStudent" ';      $Ptr .= '<input type="submit" name="NextStudent" ';
     $Ptr .= 'value="Next Student" />';      $Ptr .= 'value="Next Student" />';
     $Ptr .= '&nbsp&nbsp&nbsp';      $Ptr .= '&nbsp&nbsp&nbsp';
     $Ptr .= '</td></tr></tbody></table></form>'."\n";      $Ptr .= '</td></tr></tbody></table>'."\n";
     $r->print($Ptr);      $r->print($Ptr);
   
     untie(%cache);  
   
     if($selectedName eq 'No Student Selected') {      if($selectedName eq 'No Student Selected') {
  $r->print('<h3><font color=blue>WARNING: ');   $r->print('<h3><font color=blue>WARNING: ');
         $r->print('Please select a student</font></h3>');          $r->print('Please select a student</font></h3>');
         return;          return;
     }      }
   
     my $name = '';      my $selected=0;
     foreach (@$students) {      foreach (@$students) {
         my ($currentName) = split(':',$_);          next if ($_ ne $selectedName && 
         if($currentName eq $selectedName) {                   $selectedName ne 'All Students');
             $name = $_;          $selected = 1;
             last;          my $courseData = 
               &Apache::loncoursedata::DownloadStudentCourseInformation($_, 
                                                                       $courseID);
           last if ($c->aborted());
           if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {
               &Apache::loncoursedata::ProcessStudentData(\%cache, 
                                                          $courseData, $_);
               if(!$c->aborted()) { $r->print(&StudentReport(\%cache, $_)); }
               untie(%cache);
         }          }
     }      }
     if($name eq '') {      if($selected == 0) {
         $r->print('<h3><font color=blue>ERROR: Unknown student selected.');   $r->print('<h3><font color=blue>WARNING: ');
         $r->print('</font></h3>');          $r->print('Please select a student</font></h3>');
         return;          return;
     }      }
   
     my $courseData =   
         &Apache::loncoursedata::DownloadStudentCourseInformation($name,   
                                                                  $courseID);  
     if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {  
         &Apache::loncoursedata::ProcessStudentData(\%cache,   
                                                    $courseData, $name);  
         untie(%cache);  
     }  
   
     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {  
         $Ptr .= 'Could not tie database.';  
         return $Ptr;  
     }  
     $r->print(&StudentReport(\%cache, $name));  
     untie(%cache);  
   
     return;      return;
 }  }
   
 sub BuildMenu {  sub BuildClasslist {
     my ($cacheDB)=@_;      my ($cacheDB,$students,$studentInformation,$headings,$spacePadding)=@_;
   
     my %cache;      my %cache;
     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {      unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
         $r->print('<html><body>Unable to tie database.</body></html>');          return '<html><body>Unable to tie database.</body></html>';
         return;  
     }      }
   
     $r->print('<form name="Menu" method="post" action="/adm/statistics" >');      my $Str='';
     $r->print(&CreateMenuForm(\%cache));      $Str .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
     $r->print('</form>'."\n");      $Str .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";
   
       my $displayString = '<td align="left"><a href="/adm/statistics?';
       $displayString .= 'sort=LINKDATA">DISPLAYDATA&nbsp</a></td>'."\n";
       $Str .= &Apache::lonhtmlcommon::CreateStudentInformationHeadings(\%cache,
                                                              $studentInformation,
                                                              $headings,
                                                              $displayString);
       $Str .= '<td align="left">';
       $Str .= '<a href="/adm/statistics?sort=lastDownloadTime">';
       $Str .= 'Last Updated&nbsp&nbsp</a></td>'."\n";
       $Str .= '</tr>'."\n";
       my $alternate=0;
       foreach (@$students) {
           my ($username, $domain) = split(':', $_);
           if($alternate) {
               $Str .= '<tr bgcolor="#ffffe6"><td>';
           } else {
               $Str .= '<tr bgcolor="#ffffc6"><td>';
           }
           $alternate = ($alternate + 1) % 2;
           foreach my $data (@$studentInformation) {
               if($data eq 'fullname') {
                   $Str .= '<a href="/adm/statistics?reportSelected=';
                   $Str .= &Apache::lonnet::escape('Student Assessment').'">';
               }
   
     untie(%cache);              $Str .= $cache{$_.':'.$data}.'&nbsp';
   
     return;              if($data eq 'fullname') {
 }                  $Str .= '</a>';
               }
   
 # ================================================================ Main Handler              $Str .= '</td><td>';
           }
   
 sub handler {          $Str .= '<a href="/adm/statistics?download='.$_.'">';
     $r=shift;          my $downloadTime = $cache{$_.':lastDownloadTime'};
     &initial();          if($downloadTime ne 'Not downloaded') {
               $downloadTime = localtime($downloadTime);
           }
           $Str .= $downloadTime;
   
     unless(&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {          $Str .= '&nbsp</a></td></tr>'."\n";
         $ENV{'user.error.msg'}=  
         $r->uri.":vgr:0:0:Cannot view grades for complete course";  
         return HTTP_NOT_ACCEPTABLE;   
     }      }
   
     # Set document type for header only      $Str .= '</table></td></tr></table>'."\n";
     if($r->header_only) {  
         if ($ENV{'browser.mathml'}) {  
             $r->content_type('text/xml');  
         } else {  
             $r->content_type('text/html');  
         }  
         &Apache::loncommon::no_cache($r);  
         $r->send_http_header;  
         return OK;  
     }  
   
     unless($ENV{'request.course.fn'}) {      untie(%cache);
  my $requrl=$r->uri;  
         $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";  
         return HTTP_NOT_ACCEPTABLE;   
     }  
   
     $r->content_type('text/html');      return $Str;
     $r->send_http_header;  }
   
   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 %reports = ('classlist'          => 'Class list',
                      'problem_statistics' => 'Problem Statistics',
                      'student_assessment' => 'Student Assessment',
                      'reportSelected'     => 'Class list');
   
     my %cache;      my %cache;
     my $courseID=$ENV{'request.course.id'};      my $courseID=$ENV{'request.course.id'};
     my $cacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".      my $cacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
                   "_$ENV{'user.domain'}_$courseID\_statistics.db";                    "_$ENV{'user.domain'}_$courseID\_statistics.db";
     my $c = $r->connection;  
   
     my ($returnValue, $isCached, $students) = &PrepareData($c, $cacheDB);      &setbgcolor(0);
       my ($returnValue, $students) = &PrepareData($c, $cacheDB);
     if($returnValue ne 'OK') {      if($returnValue ne 'OK') {
         $r->print('<html><body>'.$returnValue."\n".'</body></html>');          $r->print('<html><body>'.$returnValue."\n".'</body></html>');
         return OK;          return OK;
     }      }
   
     my $downloadTime=0;  
     my $GoToPage;      my $GoToPage;
     if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {      if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
         $students = &SortStudents($students, \%cache);          $GoToPage = $cache{'reportSelected'};
         if(defined($cache{'time'})) {          $reports{'reportSelected'} = $cache{'reportSelected'};
             $downloadTime=$cache{'time'};  #        if(defined($cache{'reportKey'}) && $cache{'reportKey'} ne 'false') {
         } else {  #            $reports{$cache{'reportKey'}} = $cache{'reportSelected'};
             $downloadTime=localtime();  #        }
         }  
         if(!defined($cache{'GoToPage'})) {          if(defined($cache{'OptionResponses'})) {
             $GoToPage = 'Menu';              $reports{'problem_analysis'} = 'Problem Analysis';
         } else {  
             $GoToPage = $cache{'GoToPage'};  
         }          }
   
           $r->print(&Apache::lonhtmlcommon::Title('LON-CAPA Statistics'));
           $r->print('<form name="Statistics" ');
           $r->print('method="post" action="/adm/statistics">');
           $r->print(&Apache::lonhtmlcommon::CreateStatisticsMainMenu(
                                                                $cache{'Status'}, 
                                                                \%reports));
         untie(%cache);          untie(%cache);
     } else {      } else {
         $r->print('<html><body>Unable to tie database.</body></html>');          $r->print('<html><body>Unable to tie database.</body></html>');
         return OK;          return OK;
     }      }
   
     &setbgcolor(0);      if($GoToPage eq 'Activity Log') {
     $r->print(&Title());  
   
     if($GoToPage eq 'ActivityLog') {  
         &Activity();          &Activity();
     } elsif($GoToPage eq 'ProblemStatistics') {      } elsif($GoToPage eq 'Problem Statistics') {
         &BuildProblemStatisticsPage($cacheDB, $students);          &BuildProblemStatisticsPage($cacheDB, $students, $courseID, $c);
     } elsif($GoToPage eq 'ProblemAnalysis') {      } elsif($GoToPage eq 'Problem Analysis') {
         &BuildProblemAnalysisPage($cacheDB);          &BuildProblemAnalysisPage($cacheDB);
     } elsif($GoToPage eq 'StudentAssessment') {      } elsif($GoToPage eq 'Student Assessment') {
         &BuildStudentAssessmentPage($cacheDB, $students, $courseID);          &BuildStudentAssessmentPage($cacheDB, $students, $courseID, $c);
     } elsif($GoToPage eq 'Analyze') {      } elsif($GoToPage eq 'Analyze') {
         &BuildAnalyzePage($cacheDB, $students, $courseID);          &BuildAnalyzePage($cacheDB, $students, $courseID);
     } elsif($GoToPage eq 'DoDiffGraph') {      } elsif($GoToPage eq 'DoDiffGraph') {
         &BuildDiffGraph($courseID);          &BuildDiffGraph($courseID);
     } elsif($GoToPage eq 'PercentWrongGraph') {      } elsif($GoToPage eq 'PercentWrongGraph') {
         &BuildWrongGraph($courseID);          &BuildWrongGraph($courseID);
     } else {      } elsif($GoToPage eq 'Class list') {
         &BuildMenu($cacheDB);          $r->print(&BuildClasslist($cacheDB, $students, \@studentInformation,
                                     \@headings, $spacePadding));
     }      }
   
       $r->print('</form>'."\n");
     $r->print("\n".'</body>'."\n".'</html>');      $r->print("\n".'</body>'."\n".'</html>');
     $r->rflush();      $r->rflush();
   
     return OK;      return OK;
 }  }
   
   # ================================================================ Main Handler
   
   sub handler {
       $r=shift;
       &initial();
   
       unless(&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
           $ENV{'user.error.msg'}=
           $r->uri.":vgr:0:0:Cannot view grades for complete course";
           return HTTP_NOT_ACCEPTABLE; 
       }
   
       # Set document type for header only
       if($r->header_only) {
           if ($ENV{'browser.mathml'}) {
               $r->content_type('text/xml');
           } else {
               $r->content_type('text/html');
           }
           &Apache::loncommon::no_cache($r);
           $r->send_http_header;
           return OK;
       }
   
       unless($ENV{'request.course.fn'}) {
    my $requrl=$r->uri;
           $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
           return HTTP_NOT_ACCEPTABLE; 
       }
   
       $r->content_type('text/html');
       $r->send_http_header;
   
       &BuildStatistics($r);
   
       return OK;
   }
 1;  1;
 __END__  __END__

Removed from v.1.27  
changed lines
  Added in v.1.29


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