File:  [LON-CAPA] / loncom / interface / statistics / loncorrectproblemplot.pm
Revision 1.4: download - view: text, annotated - select for diffs
Mon Feb 2 21:54:13 2004 UTC (20 years, 5 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
More POD just so I can bump the version number and improve my odds at
winning this week.

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: loncorrectproblemplot.pm,v 1.4 2004/02/02 21:54:13 matthew Exp $
    4: #
    5: # Copyright Michigan State University Board of Trustees
    6: #
    7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    8: #
    9: # LON-CAPA is free software; you can redistribute it and/or modify
   10: # it under the terms of the GNU General Public License as published by
   11: # the Free Software Foundation; either version 2 of the License, or
   12: # (at your option) any later version.
   13: #
   14: # LON-CAPA is distributed in the hope that it will be useful,
   15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   17: # GNU General Public License for more details.
   18: #
   19: # You should have received a copy of the GNU General Public License
   20: # along with LON-CAPA; if not, write to the Free Software
   21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   22: #
   23: # /home/httpd/html/adm/gpl.txt
   24: #
   25: # http://www.lon-capa.org/
   26: #
   27: 
   28: package Apache::loncorrectproblemplot;
   29: 
   30: use strict;
   31: use Apache::lonnet();
   32: use Apache::loncommon();
   33: use Apache::lonhtmlcommon();
   34: use Apache::loncoursedata();
   35: use Apache::lonstatistics;
   36: use Apache::lonstathelpers;
   37: use Apache::lonlocal;
   38: 
   39: my @SubmitButtons = (
   40:                      { name => 'CreatePlot',
   41:                        text => 'Create Plot' },
   42:                      { name => 'ClearCache',
   43:                        text => 'Clear Caches' },
   44:                      { name => 'updatecaches',
   45:                        text => 'Update Student Data' },
   46:                      );
   47: 
   48: #########################################################
   49: #########################################################
   50: 
   51: =pod
   52: 
   53: =item &BuildCorrectProblemsPage
   54: 
   55: Entry point from lonstatistics to the correct problems plot page.
   56: 
   57: =cut
   58: 
   59: #########################################################
   60: #########################################################
   61: 
   62: sub BuildCorrectProblemsPage {
   63:     my ($r,$c)=@_;
   64:     #
   65:     my %Saveable_Parameters = ('Status' => 'scalar',
   66:                                'Section' => 'array');
   67:     &Apache::loncommon::store_course_settings('correct_problems_plot',
   68:                                               \%Saveable_Parameters);
   69:     &Apache::loncommon::restore_course_settings('correct_problems_plot',
   70:                                                 \%Saveable_Parameters);
   71:     #
   72:     &Apache::lonstatistics::PrepareClasslist();    
   73:     #
   74:     $r->print('<h2>'.&mt('Number of Correct Problems Plot').'</h2>');
   75:     $r->print(&CreateInterface());
   76:     #
   77:     my @Students = @Apache::lonstatistics::Students;
   78:     #
   79:     if (@Students < 1) {
   80:         $r->print('<h2>'.
   81:                   &mt('There are no students in the sections selected').
   82:                   '</h2>');
   83:     }
   84:     #
   85:     &Apache::loncoursedata::clear_internal_caches();
   86:     if (exists($ENV{'form.ClearCache'}) || 
   87:         exists($ENV{'form.updatecaches'}) ||
   88:         (exists($ENV{'form.firstanalysis'}) &&
   89:          $ENV{'form.firstanalysis'} ne 'no')) {
   90:         &Apache::lonstatistics::Gather_Full_Student_Data($r);
   91:     }
   92:     if (! exists($ENV{'form.firstanalysis'})) {
   93:         $r->print('<input type="hidden" name="firstanalysis" value="yes" />');
   94:     } else {
   95:         $r->print('<input type="hidden" name="firstanalysis" value="no" />');
   96:     }
   97:     foreach my $button (@SubmitButtons) {
   98:         $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
   99:                   'value="'.&mt($button->{'text'}).'" />');
  100:         $r->print('&nbsp;'x5);
  101:     }
  102:     $r->rflush();
  103:     #
  104:     # Determine which problem symbs we are to sum over
  105:     if (exists($ENV{'form.CreatePlot'})) {
  106:         my @ProblemSymbs;
  107:         if ($Apache::lonstatistics::SelectedMaps[0] ne 'all') {
  108:             foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()){
  109:                 foreach my $res (@{$seq->{'contents'}}) {
  110:                     next if ($res->{'type'} ne 'assessment');
  111:                     foreach my $part (@{$res->{'parts'}}) {
  112:                         push(@ProblemSymbs,{symb=>$res->{'symb'},
  113:                                             part=>$part});
  114:                     }
  115:                 }
  116:             }
  117:         }
  118:         my $score_data = &Apache::loncoursedata::get_student_scores
  119:             (\@Apache::lonstatistics::SelectedSections,
  120:              \@ProblemSymbs,
  121:              $Apache::lonstatistics::enrollment_status);
  122:         $r->print(&AnalyzeScoreData($score_data));
  123:     }
  124:     return;
  125: }
  126: 
  127: #########################################################
  128: #########################################################
  129: 
  130: =pod
  131: 
  132: =item & AnalyzeScoreData($score_data)
  133: 
  134: Analyze the result of &Apache::loncoursedata::get_student_scores() and
  135: return html with a plot of the data and a table of the values and bins.
  136: 
  137: =cut
  138: 
  139: #########################################################
  140: #########################################################
  141: sub AnalyzeScoreData {
  142:     my ($score_data) = @_;
  143:     #
  144:     # Basic check first
  145:     if (@$score_data < 1) {
  146:         return '<h2>There is no data to plot</h2>';
  147:     }
  148:     #
  149:     # Determine which bins to use
  150:     my $lowest  = $score_data->[0]->[0];
  151:     $lowest = 0;
  152:     my $highest = $score_data->[-1]->[0];
  153:     my $binsize = 1;
  154:     if ($highest > 50) { $binsize = 2; }
  155:     if ($highest > 100) { $binsize = 5; }
  156:     if ($highest > 200) { $binsize = 10; }
  157:     if ($highest > 500) { $binsize = 20; }
  158:     if ($highest > 1000) { $binsize = 50; }
  159:     if ($highest > 2000) { $binsize = 100; }
  160:     #
  161:     # Get the data into the bins (destroying $score_data in the process)
  162:     my @Bins = &bin_data($score_data,$binsize,$lowest,$highest);
  163:     my @Xdata; my @Ydata; my $max;
  164:     my $Str = '<table border="1">'."\n".'<tr><th>Range</th><th>Count</th></tr>'."\n";
  165:     while (my $bin = shift(@Bins)) {
  166:         push (@Xdata,$bin->{'start'});
  167:         push (@Ydata,$bin->{'count'});
  168:         if ($bin->{'count'} > $max) {
  169:             $max = $bin->{'count'};
  170:         }
  171:         $Str.= '<tr><td>'.$bin->{'start'}.' - '.$bin->{'end'}.'</td>'.
  172:             '<td>'.$bin->{'count'}.'</td></tr>'."\n";
  173:     }
  174:     my $title = '';
  175:     $Str .= "</table><br />\n";
  176:     $Str = "<br />\n".&Apache::loncommon::DrawBarGraph($title,
  177:                                                        'Num Correct Problems',
  178:                                                        'Number of students',
  179:                                                        $max,
  180:                                                        undef, # colors
  181:                                                        \@Xdata,
  182:                                                        \@Ydata).
  183:                                                            "\n<br />\n".$Str;
  184:     return $Str;                                               
  185: }
  186: 
  187: 
  188: #########################################################
  189: #########################################################
  190: 
  191: =pod
  192: 
  193: =item &bin_data($data,$binsize,$startbin,$endbin)
  194: 
  195: Note: This routine destroys the array of data passed to it.
  196: 
  197: Inputs: $data: array reference - the contents of @$data must
  198:         be arrays with x and y data.  $data = [ [x1,y1],[x2,y2],...];
  199:         $binsize: Width of bins to put data in
  200:         $startbin: the starting bin.
  201:         $endbin: the ending bin.
  202: Returns: Array of Bins.  Each bin is a hash reference with the following
  203:          keys: 'start', 'count', and 'end'.
  204: 
  205: =cut
  206: 
  207: #########################################################
  208: #########################################################
  209: sub bin_data {
  210:     my ($data,$binsize,$startbin,$endbin)=@_;
  211:     return () if (! defined($data) || ref($data) ne 'ARRAY');
  212:     #
  213:     # Determine bin geometry
  214:     my $binstart = $startbin;
  215:     my $binend = $startbin+$binsize;
  216:     # put the data into bins
  217:     my @Bins;
  218:     my $count=0;
  219:     my $idx=0;
  220:     while ($idx < scalar(@$data) && ($binend-$endbin)<$binsize) {
  221:         my $dataset = $data->[$idx++];
  222:         my ($x,$y) = @{$dataset};
  223:         while ($x > $binend) {
  224:             # store the old data
  225:             push (@Bins,{ start => $binstart,
  226:                           count => $count,
  227:                           end   => $binend });
  228:             # start counting again
  229:             $binstart += $binsize;
  230:             $binend += $binsize;
  231:             $count = 0;
  232:         }
  233:         $count+=$y;
  234:     }
  235:     return @Bins;
  236: }
  237: 
  238: #########################################################
  239: #########################################################
  240: 
  241: =pod
  242: 
  243: =item &CreateInterface
  244: 
  245: Inputs: none.
  246: 
  247: Returns: HTML for the correct problems plot interface.
  248: 
  249: =cut
  250: 
  251: #########################################################
  252: #########################################################
  253: sub CreateInterface {
  254:     ##
  255:     ## Environment variable initialization
  256:     my $Str;
  257:     $Str .= '<table cellspacing="5">'."\n";
  258:     $Str .= '<tr>';
  259:     $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
  260:     $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
  261:     $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
  262:     $Str .= '</tr>'."\n";
  263:     ##
  264:     ## 
  265:     $Str .= '<tr><td align="center">'."\n";
  266:     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
  267:     $Str .= '</td>';
  268:     #
  269:     $Str .= '<td align="center">';
  270:     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
  271:     $Str .= '</td><td>'."\n";
  272:     #
  273:     my $only_seq_with_assessments = sub { 
  274:         my $s=shift;
  275:         if ($s->{'num_assess'} < 1) { 
  276:             return 0;
  277:         } else { 
  278:             return 1;
  279:         }
  280:     };
  281:     $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
  282:                                               $only_seq_with_assessments);
  283:     $Str .= '</td><td>'."\n";
  284:     ##
  285:     $Str .= '</tr>'."\n";
  286:     $Str .= '</table>'."\n";
  287:     return $Str;
  288: }
  289: 
  290: 1;
  291: 
  292: __END__

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