Diff for /loncom/interface/statistics/lonproblemstatistics.pm between versions 1.27 and 1.30

version 1.27, 2002/08/14 20:42:49 version 1.30, 2002/08/15 14:15:20
Line 52  sub InitializeProblemStatistics { Line 52  sub InitializeProblemStatistics {
     $jr = $r;      $jr = $r;
   
     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {      unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
         $r->print('Unable to tie database.');          $r->print('Unable to tie database1.');
         return ('ERROR', undef);          return ('ERROR', undef);
     }      }
   
Line 80  sub InitializeProblemStatistics { Line 80  sub InitializeProblemStatistics {
         }          }
     }      }
   
       my $isNotCached = 0;
     my $lastStatus = (defined($cache{'StatisticsLastStatus'})) ?      my $lastStatus = (defined($cache{'StatisticsLastStatus'})) ?
                      $cache{'StatisticsLastStatus'} : 'Nothing';                       $cache{'StatisticsLastStatus'} : 'Nothing';
     my $whichStudents = join(':::',sort(@$students));      my $whichStudents = join(':::',sort(@$students));
     if(!defined($cache{'StatisticsCached'}) ||       if(!defined($cache{'StatisticsCached'}) || 
        $lastStatus ne $cache{'Status'} ||         $lastStatus ne $cache{'Status'} ||
        $whichStudents ne $cache{'StatisticsWhichStudents'}) {         $whichStudents ne $cache{'StatisticsWhichStudents'}) {
         if(defined($cache{'StatisticsCached'})) {          $isNotCached = 1;
             untie(%cache);      }
             unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {  
                 $r->print('Unable to tie database.');      untie(%cache);
                 return ('ERROR', undef);      unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
             }          $r->print('Unable to tie database.2');
             my @statkeys = split(':::', $cache{'StatisticsKeys'});          return ('ERROR', undef);
             delete $cache{'StatisticsKeys'};      }
             delete $cache{'StatisticsCached'};      if($isNotCached && defined($cache{'StatisticsCached'})) {
             foreach(@statkeys) {          my @statkeys = split(':::', $cache{'StatisticsKeys'});
                 delete $cache{$_};          delete $cache{'StatisticsKeys'};
             }          delete $cache{'StatisticsCached'};
           foreach(@statkeys) {
               delete $cache{$_};
         }          }
         untie(%cache);      }
   
       untie(%cache);
       if($isNotCached) {
         &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,          &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
                                                                   'true',                                                                    'true',
                                                                   $cacheDB,                                                                    $cacheDB,
Line 107  sub InitializeProblemStatistics { Line 113  sub InitializeProblemStatistics {
                                                                   'true',                                                                    'true',
                                                                   $courseID,                                                                    $courseID,
                                                                   $r, $c);                                                                    $r, $c);
         if($c->aborted()) { return ('ERROR', undef); }      }
       if($c->aborted()) { return ('ERROR', undef); }
   
         unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {      unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
             $r->print('Unable to tie database.');          $r->print('Unable to tie database.3');
             return ('ERROR', undef);          return ('ERROR', undef);
         }      }
         my ($problemData) = &ExtractStudentData(\%cache, $students);      my $problemData;
         &CalculateStatistics($problemData, \%cache);      if($isNotCached) {
         untie(%cache);          ($problemData) = &ExtractStudentData(\%cache, $students);
           &CalculateStatistics($problemData, \%cache, $courseID);
         unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {      }
             $r->print('Unable to tie database.');      untie(%cache);
             return ('ERROR', undef);  
         }      unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
           $r->print('Unable to tie database.4');
           return ('ERROR', undef);
       }
       if($isNotCached) {
         foreach(keys(%$problemData)) {          foreach(keys(%$problemData)) {
             $cache{$_} = $problemData->{$_};              $cache{$_} = $problemData->{$_};
         }          }
Line 128  sub InitializeProblemStatistics { Line 139  sub InitializeProblemStatistics {
         $cache{'StatisticsCached'} = 'true';          $cache{'StatisticsCached'} = 'true';
         $cache{'StatisticsLastStatus'} = $cache{'Status'};          $cache{'StatisticsLastStatus'} = $cache{'Status'};
         $cache{'StatisticsWhichStudents'} = $whichStudents;          $cache{'StatisticsWhichStudents'} = $whichStudents;
         untie(%cache);      }
       untie(%cache);
   
         unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {      unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
             $r->print('Unable to tie database.');          $r->print('Unable to tie database.5');
             return ('ERROR', undef);          return ('ERROR', undef);
         }  
     }      }
   
     my $orderedProblems = &SortProblems(\%cache,       my $orderedProblems = &SortProblems(\%cache, 
                                         $cache{'ProblemStatisticsSort'},                                          $cache{'ProblemStatisticsSort'},
                                         $cache{'SortProblems'},                                          $cache{'SortProblems'},
                                         $cache{'ProblemStatisticsAscend'});                                          $cache{'ProblemStatisticsAscend'});
       untie(%cache);
   
     return ('OK', $orderedProblems);      return ('OK', $orderedProblems);
 }  }
   
Line 153  sub BuildProblemStatisticsPage { Line 166  sub BuildProblemStatisticsPage {
     my %cache;      my %cache;
   
     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {      unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
         $r->print('Unable to tie database.');          $r->print('Unable to tie database.6');
         return;          return;
     }      }
     my $Ptr = '';      my $Ptr = '';
Line 197  sub BuildProblemStatisticsPage { Line 210  sub BuildProblemStatisticsPage {
     }      }
   
     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {      unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
         $r->print('Unable to tie database.');          $r->print('Unable to tie database.6');
         return;          return;
     }      }
     &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'},       &BuildStatisticsTable(\%cache, $cache{'DisplayFormat'}, 
Line 220  sub BuildGraphicChart { Line 233  sub BuildGraphicChart {
     }      }
   
     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {      unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
         return 'Unable to tie database.';          return 'Unable to tie database.7';
     }      }
         
     my @problems = split(':::', $cache{'problemList'});      my @problems = split(':::', $cache{'problemList'});
Line 686  sub SortProblems { Line 699  sub SortProblems {
 }  }
   
 sub CalculateStatistics {  sub CalculateStatistics {
     my ($data, $cache)=@_;      my ($data, $cache, $courseID)=@_;
   
     my @problems = split(':::', $data->{'problemList'});      my @problems = split(':::', $data->{'problemList'});
     foreach(@problems) {      foreach(@problems) {
Line 784  sub CalculateStatistics { Line 797  sub CalculateStatistics {
   
         my $df2 = $upper2Sum - $lower2Sum;          my $df2 = $upper2Sum - $lower2Sum;
         $data->{$_.':discriminationFactor2'} = sprintf("%.2f", $df2);          $data->{$_.':discriminationFactor2'} = sprintf("%.2f", $df2);
   
           my %storestats;
           my $Average = ($data->{$_.':studentCount'}) ? 
               $data->{$_.':totalTries'}/$data->{$_.':studentCount'} : 0;
           $storestats{$courseID.'___'.$cache->{$sequence.':source'}.
                           '___timestamp'}=time;
           $storestats{$courseID.'___'.$cache->{$sequence.':source'}.
                           '___stdno'}=$data->{$_.':studentCount'};
           $storestats{$courseID.'___'.$cache->{$sequence.':source'}.
                           '___avetries'}=$Average;
           $storestats{$courseID.'___'.$cache->{$sequence.':source'}.
                           '___difficulty'}=$data->{$_.':degreeOfDifficulty'};
           $cache->{$sequence.':source'} =~ /^(\w+)\/(\w+)/;
           if($data->{$_.':studentCount'}) { 
               &Apache::lonnet::put('resevaldata',\%storestats,$1,$2);
           }
     }      }
   
     return;      return;

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


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