Diff for /loncom/interface/statistics/lonproblemstatistics.pm between versions 1.26 and 1.33

version 1.26, 2002/08/14 17:45:19 version 1.33, 2002/09/22 17:08:32
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 %Discuss=&Apache::loncoursedata::LoadDiscussion($courseID);      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 108  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 129  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 149  sub BuildProblemStatisticsPage { Line 161  sub BuildProblemStatisticsPage {
   
     my @Header = ("Homework Sets Order","#Stdnts","Tries","Mod",      my @Header = ("Homework Sets Order","#Stdnts","Tries","Mod",
                   "Mean","#YES","#yes","%Wrng","DoDiff",                    "Mean","#YES","#yes","%Wrng","DoDiff",
                   "S.D.","Skew.","D.F.1st","D.F.2nd","Disc.");                    "S.D.","Skew.","D.F.1st","D.F.2nd");
     my $color=&setbgcolor(0);      my $color=&setbgcolor(0);
     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 = '';
     $Ptr .= '<table border="0"><tbody>';      $Ptr .= '<table border="0" cellspacing="5"><tbody>';
     $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";      $Ptr .= '<tr><td align="right"><b>Select Map</b></td>'."\n";
     $Ptr .= '<td align="left">';      $Ptr .= '<td align="left">';
     $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'ProblemStatistics',      $Ptr .= &Apache::lonhtmlcommon::MapOptions(\%cache, 'Statistics',
                                                'Statistics');                                                 'Statistics');
     $Ptr .= '</td></tr>'."\n";      $Ptr .= '</td></tr>'."\n";
     $Ptr .= '<tr><td align="right"><b>Sorting Type:</b></td>'."\n";      $Ptr .= '<tr><td align="right"><b>Sorting Type:</b></td>'."\n";
     $Ptr .= '<td align="left">'."\n";      $Ptr .= '<td align="left">'."\n";
     $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions(      $Ptr .= &Apache::lonhtmlcommon::AscendOrderOptions(
                                             $cache{'ProblemStatisticsAscend'},                                              $cache{'ProblemStatisticsAscend'}, 
                                             'ProblemStatistics',                                             'ProblemStatistics',
                                             'Statistics');                                             'Statistics');
     $Ptr .= '</td></tr>'."\n";      $Ptr .= '</td></tr>'."\n";
     $Ptr .= '<tr><td align="right"><b>Select Sections</b>';      $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
     $Ptr .= '</td>'."\n";      $Ptr .= '</td>'."\n";
Line 198  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 221  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 269  sub CreateProblemStatisticsTableHeading Line 281  sub CreateProblemStatisticsTableHeading
     $Str .= '<tr>'."\n";      $Str .= '<tr>'."\n";
     $Str .= '<th bgcolor="#ffffe6">P#</th>'."\n";      $Str .= '<th bgcolor="#ffffe6">P#</th>'."\n";
     foreach(@$headings) {      foreach(@$headings) {
  $Str .= '<th bgcolor="#ffffe6">'.'<a href="/adm/statistics?reportSelected=';   $Str .= '<th bgcolor="#ffffe6">';
           $Str .= '<a href="/adm/statistics?reportSelected=';
         $Str .= &Apache::lonnet::escape('Problem Statistics');          $Str .= &Apache::lonnet::escape('Problem Statistics');
         $Str .= '&ProblemStatisticsSort=';          $Str .= '&ProblemStatisticsSort=';
         $Str .= &Apache::lonnet::escape($_).'">'.$_.'</a>&nbsp</th>'."\n";          $Str .= &Apache::lonnet::escape($_).'">'.$_.'</a>&nbsp</th>'."\n";
Line 283  sub BuildStatisticsTable { Line 296  sub BuildStatisticsTable {
     my ($cache,$displayFormat,$sortProblems,$orderedProblems,$headings,      my ($cache,$displayFormat,$sortProblems,$orderedProblems,$headings,
         $r,$color)=@_;          $r,$color)=@_;
   
 #6666666  
 #    my $file="/home/httpd/perl/tmp/183d.txt";  
 #    open(OUT, ">$file");  
 #6666666  
 ##     &Apache::lonstatistics::Create_PrgWin($r);  
 ##777777  
 ##    my (%Activity) = &LoadActivityLog();  
 ##    $r->print('<script>popwin.document.popremain.remaining.value="'.  
 ##              'Loading Discussion...";</script>');  
 ##    my ($doDiffFile) = &LoadDoDiffFile();  
   
 ##777777  
 ##    $Str .= &Classify($discriminantFactor, $students);  
   
     my $count = 1;      my $count = 1;
     my $currentSequence = -1;      my $currentSequence = -1;
     foreach(@$orderedProblems) {      foreach(@$orderedProblems) {
Line 332  sub BuildStatisticsTable { Line 331  sub BuildStatisticsTable {
         my $ref = '<a href="'.$cache->{$problem.':source'}.          my $ref = '<a href="'.$cache->{$problem.':source'}.
                   '" target="_blank">'.$cache->{$problem.':title'}.'</a>';                    '" target="_blank">'.$cache->{$problem.':title'}.'</a>';
         my $title = $cache->{$problem.':title'};          my $title = $cache->{$problem.':title'};
           if($part != 0) {
               $title .= ' Part '.$part;
           }
         my $source = $cache->{$problem.':source'};          my $source = $cache->{$problem.':source'};
         my $tableData = join('&', $ref, $title, $source,          my $tableData = join('&', $ref, $title, $source,
                        $cache->{$_.':studentCount'},                         $cache->{$_.':studentCount'},
                        $cache->{$_.':totalTries'},                         $cache->{$_.':totalTries'},
                        $cache->{$_.':maxTries'},                         $cache->{$_.':maxTries'},
                        sprintf("%.2f", $cache->{$_.':mean'}),                         $cache->{$_.':mean'},
                        $cache->{$_.':correct'},                         $cache->{$_.':correct'},
                        $cache->{$_.':correctByOverride'},                         $cache->{$_.':correctByOverride'},
                        sprintf("%.1f", $cache->{$_.':percentWrong'}),                         $cache->{$_.':percentWrong'},
                        sprintf("%.2f", $cache->{$_.':degreeOfDifficulty'}),                         $cache->{$_.':degreeOfDifficulty'},
                        sprintf("%.1f", $cache->{$_.':standardDeviation'}),                         $cache->{$_.':standardDeviation'},
                        sprintf("%.1f", $cache->{$_.':skewness'}),                         $cache->{$_.':skewness'},
                        sprintf("%.2f", $cache->{$_.':discriminationFactor1'}),                         $cache->{$_.':discriminationFactor1'},
                        sprintf("%.2f", $cache->{$_.':discriminationFactor2'}),                         $cache->{$_.':discriminationFactor2'});
                        0); # 0 is for discussion, need to figure out  
   
         &TableRow($displayFormat,$tableData,$count,$r,$color);          &TableRow($displayFormat,$tableData,$count,$r,$color);
   
Line 358  sub BuildStatisticsTable { Line 359  sub BuildStatisticsTable {
     } else {      } else {
         $r->print('<br>');          $r->print('<br>');
     }      }
 #6666666  
 #    $r->print('<br>'.$out.'&'.$DoD);  
 #            print (OUT $out.'@'.$DoD.'&');  
 #6666666  
   
 #6666666  
 #    close( OUT );  
 #666666  
     return;      return;
 }  }
   
 sub TableRow {  sub TableRow {
     my ($displayFormat,$Str,$RealIdx,$r,$color)=@_;      my ($displayFormat,$Str,$RealIdx,$r,$color)=@_;
     my($ref,$title,$source,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,      my($ref,$title,$source,$StdNo,$TotalTries,$MxTries,$Avg,$YES,$Override,
        $Wrng,$DoD,$SD,$Sk,$_D1,$_D2,$DiscNo,$Prob)=split(/\&/,$Str);         $Wrng,$DoD,$SD,$Sk,$_D1,$_D2)=split(/\&/,$Str);
     my $Ptr;      my $Ptr;
     if($displayFormat eq 'Display CSV Format') {      if($displayFormat eq 'Display CSV Format') {
         $Ptr='"'.$RealIdx.'",'."\n".          $Ptr='"'.$RealIdx.'",'."\n".
Line 390  sub TableRow { Line 384  sub TableRow {
              '"'.$Sk.'",'."\n".               '"'.$Sk.'",'."\n".
              '"'.$_D1.'",'."\n".               '"'.$_D1.'",'."\n".
              '"'.$_D2.'"'."\n".               '"'.$_D2.'"'."\n".
              '"'.$DiscNo.'"'."\n".  
              "<br>\n";               "<br>\n";
   
         $r->print("\n".$Ptr);          $r->print("\n".$Ptr);
Line 409  sub TableRow { Line 402  sub TableRow {
              '<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>'."\n";  
         $r->print($Ptr.'</tr>'."\n");          $r->print($Ptr.'</tr>'."\n");
     }      }
   
Line 443  sub ProblemStatisticsButtons { Line 435  sub ProblemStatisticsButtons {
   
     my $Ptr = '<tr><td></td><td align="left">';      my $Ptr = '<tr><td></td><td align="left">';
     $Ptr .= '<input type="submit" name="DoDiffGraph" ';      $Ptr .= '<input type="submit" name="DoDiffGraph" ';
     $Ptr .= 'value="DoDiff Graph" />'."\n";      $Ptr .= 'value="Plot Degree of Difficulty" />'."\n";
     $Ptr .= '&nbsp;&nbsp;&nbsp;';      $Ptr .= '</td><td align="left">';
     $Ptr .= '<input type="submit" name="PercentWrongGraph" ';      $Ptr .= '<input type="submit" name="PercentWrongGraph" ';
     $Ptr .= 'value="%Wrong Graph" />'."\n";      $Ptr .= 'value="Plot Percent Wrong" />'."\n";
     $Ptr .= '</td></tr><tr><td></td><td>'."\n";      $Ptr .= '</td></tr><tr><td></td><td>'."\n";
     $Ptr .= '<input type="submit" name="SortProblems" ';      $Ptr .= '<input type="submit" name="SortProblems" ';
     if($sortProblems eq 'Sort All Problems') {      if($sortProblems eq 'Sort All Problems') {
Line 454  sub ProblemStatisticsButtons { Line 446  sub ProblemStatisticsButtons {
     } else {      } else {
         $Ptr .= 'value="Sort All Problems" />'."\n";          $Ptr .= 'value="Sort All Problems" />'."\n";
     }      }
     $Ptr .= '&nbsp;&nbsp;&nbsp;';      $Ptr .= '</td><td align="left">';
     $Ptr .= '<input type="submit" name="DisplayLegend" ';      $Ptr .= '<input type="submit" name="DisplayLegend" ';
     if($displayLegend eq 'Show Legend') {      if($displayLegend eq 'Show Legend') {
         $Ptr .= 'value="Hide Legend" />'."\n";          $Ptr .= 'value="Hide Legend" />'."\n";
     } else {      } else {
         $Ptr .= 'value="Show Legend" />'."\n";          $Ptr .= 'value="Show Legend" />'."\n";
     }      }
     $Ptr .= '&nbsp;&nbsp;&nbsp;';      $Ptr .= '</td><td align="left">';
     $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';      $Ptr .= '<input type="submit" name="DisplayCSVFormat" ';
     if($displayFormat eq 'Display CSV Format') {      if($displayFormat eq 'Display CSV Format') {
         $Ptr .= 'value="Display Table Format" />'."\n";          $Ptr .= 'value="Display Table Format" />'."\n";
Line 515  sub ProblemStatisticsLegend { Line 507  sub ProblemStatisticsLegend {
     $Ptr .= '<b>Dis.F.</b></td>';      $Ptr .= '<b>Dis.F.</b></td>';
     $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';      $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
     $Ptr .= 'problem according to a Criterion<br>';      $Ptr .= 'problem according to a Criterion<br>';
     $Ptr .= '<b>[Applied Criterion in %27 Upper Students - ';      $Ptr .= '<b>[Criterion to group students into %27 Upper Students - ';
     $Ptr .= 'Applied the same Criterion in %27 Lower Students]</b><br>';      $Ptr .= 'and %27 Lower Students]</b><br>';
     $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';      $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
     $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: ';
Line 529  sub ProblemStatisticsLegend { Line 521  sub ProblemStatisticsLegend {
     return $Ptr;      return $Ptr;
 }  }
   
 #------- Processing upperlist and lowerlist according to each problem  
   
 sub ExtractStudentData {  sub ExtractStudentData {
     my ($cache, $students)=@_;      my ($cache, $students)=@_;
   
 #$Apache::lonxml::debug=1;  
 #&Apache::lonhomework::showhash(%$cache);  
 #$Apache::lonxml::debug=0;  
   
     my @problemList=();      my @problemList=();
     my %problemData;      my %problemData;
     foreach my $sequence (split(':', $cache->{'orderedSequences'})) {      foreach my $sequence (split(':', $cache->{'orderedSequences'})) {
Line 584  sub ExtractStudentData { Line 570  sub ExtractStudentData {
                     }                      }
                 }                  }
   
                   my $studentTriesJoined = join(':::', @studentTries);
                 $problemData{$id.':sequenceTitle'} =                   $problemData{$id.':sequenceTitle'} = 
                     $cache->{$sequence.':title'};                      $cache->{$sequence.':title'};
                 $problemData{$id.':studentCount'} = $studentCount;                  $problemData{$id.':studentCount'} = $studentCount;
                 $problemData{$id.':totalTries'} = $totalTries;                  $problemData{$id.':totalTries'} = $totalTries;
                 $problemData{$id.':studentTries'} = \@studentTries;                  $problemData{$id.':studentTries'} = $studentTriesJoined;
                 $problemData{$id.':totalAwarded'} = $totalAwarded;                  $problemData{$id.':totalAwarded'} = $totalAwarded;
                 $problemData{$id.':correct'} = $correct;                  $problemData{$id.':correct'} = $correct;
                 $problemData{$id.':correctByOverride'} = $correctByOverride;                  $problemData{$id.':correctByOverride'} = $correctByOverride;
Line 627  sub ExtractStudentData { Line 614  sub ExtractStudentData {
     $problemData{'studentsLowerListCriterion2'}=join(':::', @lowerStudents2);      $problemData{'studentsLowerListCriterion2'}=join(':::', @lowerStudents2);
   
     $problemData{'problemList'} = join(':::', @problemList);      $problemData{'problemList'} = join(':::', @problemList);
 #                $Discussed=0;  
 #                if($Discuss->{"$name:$problem"}) {  
 #    $TotDiscuss++;  
 #                    $Discussed=1;  
 #                }  
   
     return \%problemData;      return \%problemData;
 }  }
Line 668  sub SortProblems { Line 650  sub SortProblems {
     elsif($sortBy eq "DoDiff")  { $data = ':degreeOfDifficulty'; }      elsif($sortBy eq "DoDiff")  { $data = ':degreeOfDifficulty'; }
     elsif($sortBy eq "S.D.")    { $data = ':standardDeviation'; }      elsif($sortBy eq "S.D.")    { $data = ':standardDeviation'; }
     elsif($sortBy eq "Skew.")   { $data = ':skewness'; }      elsif($sortBy eq "Skew.")   { $data = ':skewness'; }
     elsif($sortBy eq "D.F.1st") { $data = ':discriminantFactor1'; }      elsif($sortBy eq "D.F.1st") { $data = ':discriminationFactor1'; }
     elsif($sortBy eq "D.F.2nd") { $data = ':discriminantFactor2'; }      elsif($sortBy eq "D.F.2nd") { $data = ':discriminationFactor2'; }
     elsif($sortBy eq "Disc.")   { $data = ''; }  
     else                        { return \@problems; }      else                        { return \@problems; }
   
     my %temp;      my %temp;
       my @sequenceList=();
     foreach(@problems) {      foreach(@problems) {
         my ($sequence) = split(':', $_);          my ($sequence) = split(':', $_);
         $temp{$_} = $sequence;  
           my @array=();
           my $tempArray;
           if(defined($temp{$sequence})) {
               $tempArray = $temp{$sequence};
           } else {
               push(@sequenceList, $sequence);
               $tempArray = \@array;
               $temp{$sequence} = $tempArray;
           }
   
           push(@$tempArray, $_);
     }      }
   
     my @orderedProblems;      my @orderedProblems;
     if($sortProblems eq "Sort Within Sequence") {      if($sortProblems eq "Sort Within Sequence") {
         @orderedProblems =           foreach(keys(%temp)) {
             sort { $temp{$a} cmp $temp{$b} ||              my $tempArray = $temp{$_};
                    $problemData->{$a.$data} <=> $problemData->{$b.$data} }              my @tempOrder =
         @problems;                  sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }
               @$tempArray;
               $temp{$_} = \@tempOrder;
           }
           foreach(@sequenceList) {
               my $tempArray = $temp{$_};
               @orderedProblems = (@orderedProblems, @$tempArray);
           }
     } else {      } else {
         @orderedProblems =           @orderedProblems = 
             sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }              sort { $problemData->{$a.$data} <=> $problemData->{$b.$data} }
Line 699  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) {
         # Mean          # Mean
         $data->{$_.':mean'} = ($data->{$_.':studentCount'}) ?           my $mean = ($data->{$_.':studentCount'}) ? 
             ($data->{$_.':totalTries'} / $data->{$_.':studentCount'}) : 0;              ($data->{$_.':totalTries'} / $data->{$_.':studentCount'}) : 0;
           $data->{$_.':mean'} = sprintf("%.2f", $mean);
   
         # %Wrong          # %Wrong
         $data->{$_.':percentWrong'} = ($data->{$_.':studentCount'}) ?          my $pw = ($data->{$_.':studentCount'}) ?
             (($data->{$_.':wrong'} / $data->{$_.':studentCount'}) * 100.0) :               (($data->{$_.':wrong'} / $data->{$_.':studentCount'}) * 100.0) : 
             100.0;              100.0;
           $data->{$_.':percentWrong'} = sprintf("%.1f", $pw);
   
         # Degree of Difficulty          # Degree of Difficulty
         $data->{$_.':degreeOfDifficulty'} = ($data->{$_.':totalTries'}) ?          my $dod = ($data->{$_.':totalTries'}) ?
             (1 - (($data->{$_.':correct'} + $data->{$_.':correctByOverride'}) /              (1 - (($data->{$_.':correct'} + $data->{$_.':correctByOverride'}) /
                   $data->{$_.':totalTries'})) : 0;                    $data->{$_.':totalTries'})) : 0;
   
           $data->{$_.':degreeOfDifficulty'} = sprintf("%.2f", $dod);
   
         # Factor in mean          # Factor in mean
         my $studentTries = $data->{$_.':studentTries'};          my @studentTries = split(':::', $data->{$_.':studentTries'});
         foreach(my $index=0; $index < scalar(@$studentTries); $index++) {          foreach(my $index=0; $index < scalar(@studentTries); $index++) {
             $studentTries->[$index] -= $data->{$_.':mean'};              $studentTries[$index] -= $mean;
         }          }
         my $sumSquared = 0;          my $sumSquared = 0;
         my $sumCubed = 0;          my $sumCubed = 0;
         foreach(@$studentTries) {          foreach(@studentTries) {
             my $squared = ($_ * $_);              my $squared = ($_ * $_);
             my $cubed = ($squared * $_);              my $cubed = ($squared * $_);
             $sumSquared += $squared;              $sumSquared += $squared;
Line 732  sub CalculateStatistics { Line 736  sub CalculateStatistics {
         }          }
   
         # Standard deviation          # Standard deviation
         $data->{$_.':standardDeviation'} = ($data->{$_.':studentCount'} - 1) ?          my $standardDeviation;
             ((sqrt($sumSquared)) / ($data->{$_.':studentCount'} - 1)) : 0;          if($data->{$_.':studentCount'} - 1 > 0) {
               $standardDeviation = (sqrt($sumSquared)) / 
                                    ($data->{$_.':studentCount'} - 1);
           } else {
               $standardDeviation =  0.0;
           }
           $data->{$_.':standardDeviation'} = sprintf("%.1f", $standardDeviation);
   
         # Skewness          # Skewness
         my $standardDeviation = $data->{$_.':standardDeviation'};          my $skew;
         $data->{$_.':skewness'} = ($data->{$_.':standardDeviation'}) ?          if($standardDeviation > 0.0999 && $data->{$_.':studentCount'} > 0) {
             (((sqrt($sumSquared)) / $data->{$_.':studentCount'}) /               $skew = (((sqrt($sumSquared)) / $data->{$_.':studentCount'}) / 
              ($standardDeviation * $standardDeviation * $standardDeviation)) :                       ($standardDeviation * 
              0;                        $standardDeviation * 
                         $standardDeviation));
           } else {
               $skew = 0.0;
           }
   
           $data->{$_.':skewness'} = sprintf("%.1f", $skew);
   
         # Discrimination Factor 1          # Discrimination Factor 1
         my ($sequence, $problem, $part) = split(':', $_);          my ($sequence, $problem, $part) = split(':', $_);
Line 760  sub CalculateStatistics { Line 776  sub CalculateStatistics {
         }          }
         $lower1Sum = (scalar(@lower1)) ? ($lower1Sum/(scalar(@lower1))) : 0;          $lower1Sum = (scalar(@lower1)) ? ($lower1Sum/(scalar(@lower1))) : 0;
   
         $data->{$_.':discriminationFactor1'} = $upper1Sum - $lower1Sum;          my $df1 = $upper1Sum - $lower1Sum;
           $data->{$_.':discriminationFactor1'} = sprintf("%.2f", $df1);
   
         # Discrimination Factor 2          # Discrimination Factor 2
         my @upper2 = split(':::', $data->{'studentsUpperListCriterion2'});          my @upper2 = split(':::', $data->{'studentsUpperListCriterion2'});
Line 778  sub CalculateStatistics { Line 795  sub CalculateStatistics {
         }          }
         $lower2Sum = (scalar(@lower2)) ? ($lower2Sum/(scalar(@lower2))) : 0;          $lower2Sum = (scalar(@lower2)) ? ($lower2Sum/(scalar(@lower2))) : 0;
   
         $data->{$_.':discriminationFactor2'} = $upper2Sum - $lower2Sum;          my $df2 = $upper2Sum - $lower2Sum;
           $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('nohist_resevaldata',\%storestats,$1,$2);
           }
     }      }
   
     return;      return;

Removed from v.1.26  
changed lines
  Added in v.1.33


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