File:  [LON-CAPA] / loncom / interface / statistics / loncorrectproblemplot.pm
Revision 1.6: download - view: text, annotated - select for diffs
Fri Feb 20 16:24:20 2004 UTC (20 years, 4 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Modified to use &Apache::htmlcommon breadcrumb routines.

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: loncorrectproblemplot.pm,v 1.6 2004/02/20 16:24:20 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(&CreateInterface());
   75:     #
   76:     my @Students = @Apache::lonstatistics::Students;
   77:     #
   78:     if (@Students < 1) {
   79:         $r->print('<h2>'.
   80:                   &mt('There are no students in the sections selected').
   81:                   '</h2>');
   82:     }
   83:     #
   84:     &Apache::loncoursedata::clear_internal_caches();
   85:     if (exists($ENV{'form.ClearCache'}) || 
   86:         exists($ENV{'form.updatecaches'}) ||
   87:         (exists($ENV{'form.firstanalysis'}) &&
   88:          $ENV{'form.firstanalysis'} ne 'no')) {
   89:         &Apache::lonstatistics::Gather_Full_Student_Data($r);
   90:     }
   91:     if (! exists($ENV{'form.firstanalysis'})) {
   92:         $r->print('<input type="hidden" name="firstanalysis" value="yes" />');
   93:     } else {
   94:         $r->print('<input type="hidden" name="firstanalysis" value="no" />');
   95:     }
   96:     foreach my $button (@SubmitButtons) {
   97:         $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
   98:                   'value="'.&mt($button->{'text'}).'" />');
   99:         $r->print('&nbsp;'x5);
  100:     }
  101:     $r->rflush();
  102:     #
  103:     # Determine which problem symbs we are to sum over
  104:     if (exists($ENV{'form.CreatePlot'})) {
  105:         my @ProblemSymbs;
  106:         if ($Apache::lonstatistics::SelectedMaps[0] ne 'all') {
  107:             foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()){
  108:                 foreach my $res (@{$seq->{'contents'}}) {
  109:                     next if ($res->{'type'} ne 'assessment');
  110:                     foreach my $part (@{$res->{'parts'}}) {
  111:                         push(@ProblemSymbs,{symb=>$res->{'symb'},
  112:                                             part=>$part});
  113:                     }
  114:                 }
  115:             }
  116:         }
  117:         my $score_data = &Apache::loncoursedata::get_student_scores
  118:             (\@Apache::lonstatistics::SelectedSections,
  119:              \@ProblemSymbs,
  120:              $Apache::lonstatistics::enrollment_status);
  121:         $r->print(&AnalyzeScoreData($score_data));
  122:     }
  123:     return;
  124: }
  125: 
  126: #########################################################
  127: #########################################################
  128: 
  129: =pod
  130: 
  131: =item & AnalyzeScoreData($score_data)
  132: 
  133: Analyze the result of &Apache::loncoursedata::get_student_scores() and
  134: return html with a plot of the data and a table of the values and bins.
  135: 
  136: =cut
  137: 
  138: #########################################################
  139: #########################################################
  140: sub AnalyzeScoreData {
  141:     my ($score_data) = @_;
  142:     #
  143:     # Basic check first
  144:     if (@$score_data < 1) {
  145:         return '<h2>There is no data to plot</h2>';
  146:     }
  147:     #
  148:     # Determine which bins to use
  149:     my $lowest  = $score_data->[0]->[0];
  150:     $lowest = 0;
  151:     my $highest = $score_data->[-1]->[0];
  152:     my $binsize = 1;
  153:     if ($highest > 50) { $binsize = 2; }
  154:     if ($highest > 100) { $binsize = 5; }
  155:     if ($highest > 200) { $binsize = 10; }
  156:     if ($highest > 500) { $binsize = 20; }
  157:     if ($highest > 1000) { $binsize = 50; }
  158:     if ($highest > 2000) { $binsize = 100; }
  159:     #
  160:     # Get the data into the bins (destroying $score_data in the process)
  161:     my @Bins = &bin_data($score_data,$binsize,$lowest,$highest);
  162:     my @Xdata; my @Ydata; my $max;
  163:     my $Str = '<table border="1">'."\n".'<tr><th>Range</th><th>Count</th></tr>'."\n";
  164:     while (my $bin = shift(@Bins)) {
  165:         push (@Xdata,$bin->{'start'});
  166:         push (@Ydata,$bin->{'count'});
  167:         if ($bin->{'count'} > $max) {
  168:             $max = $bin->{'count'};
  169:         }
  170:         $Str.= '<tr><td>'.$bin->{'start'}.' - '.$bin->{'end'}.'</td>'.
  171:             '<td>'.$bin->{'count'}.'</td></tr>'."\n";
  172:     }
  173:     # scale max to an integer.
  174:     $max = 5*(int($max/5)+1);
  175:     my $title = 'Correct Problems Plot';
  176:     $Str .= "</table><br />\n";
  177:     $Str = "<br />\n".&Apache::loncommon::DrawBarGraph($title,
  178:                                                        'Num Correct Problems',
  179:                                                        'Number of students',
  180:                                                        $max,
  181:                                                        undef, # colors
  182:                                                        \@Xdata,
  183:                                                        \@Ydata).
  184:                                                            "\n<br />\n".$Str;
  185:     return $Str;                                               
  186: }
  187: 
  188: 
  189: #########################################################
  190: #########################################################
  191: 
  192: =pod
  193: 
  194: =item &bin_data($data,$binsize,$startbin,$endbin)
  195: 
  196: Note: This routine destroys the array of data passed to it.
  197: 
  198: Inputs: $data: array reference - the contents of @$data must
  199:         be arrays with x and y data.  $data = [ [x1,y1],[x2,y2],...];
  200:         $binsize: Width of bins to put data in
  201:         $startbin: the starting bin.
  202:         $endbin: the ending bin.
  203: Returns: Array of Bins.  Each bin is a hash reference with the following
  204:          keys: 'start', 'count', and 'end'.
  205: 
  206: =cut
  207: 
  208: #########################################################
  209: #########################################################
  210: sub bin_data {
  211:     my ($data,$binsize,$startbin,$endbin)=@_;
  212:     return () if (! defined($data) || ref($data) ne 'ARRAY');
  213:     #
  214:     # Determine bin geometry
  215:     my $binstart = $startbin;
  216:     my $binend = $startbin+$binsize;
  217:     # put the data into bins
  218:     my @Bins;
  219:     my $count=0;
  220:     my $idx=0;
  221:     while ($idx < scalar(@$data) && ($binend-$endbin)<$binsize) {
  222:         my $dataset = $data->[$idx++];
  223:         my ($x,$y) = @{$dataset};
  224:         while ($x > $binend) {
  225:             # store the old data
  226:             push (@Bins,{ start => $binstart,
  227:                           count => $count,
  228:                           end   => $binend });
  229:             # start counting again
  230:             $binstart += $binsize;
  231:             $binend += $binsize;
  232:             $count = 0;
  233:         }
  234:         $count+=$y;
  235:     }
  236:     return @Bins;
  237: }
  238: 
  239: #########################################################
  240: #########################################################
  241: 
  242: =pod
  243: 
  244: =item &CreateInterface
  245: 
  246: Inputs: none.
  247: 
  248: Returns: HTML for the correct problems plot interface.
  249: 
  250: =cut
  251: 
  252: #########################################################
  253: #########################################################
  254: sub CreateInterface {
  255:     ##
  256:     ## Environment variable initialization
  257:     my $Str;
  258:     $Str .= &Apache::lonhtmlcommon::breadcrumbs(undef,'Correct Problems Plot');
  259:     $Str .= '<table cellspacing="5">'."\n";
  260:     $Str .= '<tr>';
  261:     $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
  262:     $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
  263:     $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
  264:     $Str .= '</tr>'."\n";
  265:     ##
  266:     ## 
  267:     $Str .= '<tr><td align="center">'."\n";
  268:     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
  269:     $Str .= '</td>';
  270:     #
  271:     $Str .= '<td align="center">';
  272:     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
  273:     $Str .= '</td><td>'."\n";
  274:     #
  275:     my $only_seq_with_assessments = sub { 
  276:         my $s=shift;
  277:         if ($s->{'num_assess'} < 1) { 
  278:             return 0;
  279:         } else { 
  280:             return 1;
  281:         }
  282:     };
  283:     $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
  284:                                               $only_seq_with_assessments);
  285:     $Str .= '</td><td>'."\n";
  286:     ##
  287:     $Str .= '</tr>'."\n";
  288:     $Str .= '</table>'."\n";
  289:     return $Str;
  290: }
  291: 
  292: 1;
  293: 
  294: __END__

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