File:  [LON-CAPA] / loncom / interface / statistics / loncorrectproblemplot.pm
Revision 1.21: download - view: text, annotated - select for diffs
Fri Aug 18 15:15:38 2006 UTC (17 years, 10 months ago) by raeburn
Branches: MAIN
CVS tags: version_2_2_X, version_2_2_99_1, version_2_2_99_0, version_2_2_2, version_2_2_1, version_2_2_0, HEAD
Bug 4954.  Filter title changed from "Enrollment Status" to "Access Status".  Access Status selections in lonhtmlcommon set to:
Currently Has Access
Will Have Future Access
Previously Had Access
Any Access Status
See comment appended to bug 4954 for more information.
Documentation updated to include ability to selectively display students with future access.

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: loncorrectproblemplot.pm,v 1.21 2006/08/18 15:15:38 raeburn 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:                      );
   43: 
   44: #########################################################
   45: #########################################################
   46: 
   47: =pod
   48: 
   49: =item &BuildCorrectProblemsPage
   50: 
   51: Entry point from lonstatistics to the correct problems plot page.
   52: 
   53: =cut
   54: 
   55: #########################################################
   56: #########################################################
   57: 
   58: sub BuildCorrectProblemsPage {
   59:     my ($r,$c)=@_;
   60:     #
   61:     my %Saveable_Parameters = ('Status' => 'scalar',
   62:                                'Section' => 'array',
   63:                                'Groups' => 'array');
   64:     &Apache::loncommon::store_course_settings('correct_problems_plot',
   65:                                               \%Saveable_Parameters);
   66:     &Apache::loncommon::restore_course_settings('correct_problems_plot',
   67:                                                 \%Saveable_Parameters);
   68:     #
   69:     &Apache::lonstatistics::PrepareClasslist();    
   70:     #
   71:     $r->print(&CreateInterface());
   72:     #
   73:     my @Students = @Apache::lonstatistics::Students;
   74:     #
   75:     if (@Students < 1) {
   76:         $r->print('<h2>'.
   77:                   &mt('There are no students in the sections/groups selected').
   78:                   '</h2>');
   79:     }
   80:     #
   81:     my @CacheButtonHTML = 
   82:         &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
   83:     foreach my $button (@SubmitButtons) {
   84:         $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
   85:                   'value="'.&mt($button->{'text'}).'" />');
   86:         $r->print('&nbsp;'x5);
   87:     }
   88:     foreach my $html (@CacheButtonHTML) {
   89:         $r->print($html.('&nbsp;'x5));
   90:     }
   91:     $r->rflush();
   92:     #
   93:     # Determine which problem symbs we are to sum over
   94:     if (exists($env{'form.CreatePlot'})) {
   95:         my @ProblemSymbs;
   96:         my $total_weights = 0;
   97:         my $title = '';
   98:         my @maps = &Apache::lonstatistics::get_selected_maps('Maps');
   99:         my ($navmap,@sequences) =
  100:             &Apache::lonstatistics::selected_sequences_with_assessments();
  101:         if ($maps[0] ne 'all') {
  102:             foreach my $seq (@sequences) {
  103:                 if ($title eq '') {
  104:                     $title = $seq->compTitle;
  105:                 } else {
  106:                     $title = 'Multiple Sequences';
  107:                 }
  108:             }
  109:         } else {
  110:             $title = 'All Problems';
  111:         }
  112:         foreach my $seq (@sequences) {
  113:             my @resources = 
  114:                 &Apache::lonstathelpers::get_resources($navmap,$seq);
  115:             foreach my $res (@resources) {
  116:                 foreach my $partid (@{$res->parts}) {
  117:                     push(@ProblemSymbs,{symb=>$res->symb,
  118:                                         part=>$partid});
  119:                     $total_weights += 
  120:                         &Apache::lonnet::EXT('resource.'.$partid.'.weight',
  121:                                              $res->symb,
  122:                                              undef,undef,undef);
  123:                 }
  124:             }
  125:         }
  126:         $r->print('<h4>'.
  127:                   &Apache::lonstatistics::section_and_enrollment_description().
  128:                   '</h4>');
  129:         my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
  130:         if (defined($starttime) || defined($endtime)) {
  131:             # Inform the user what the time limits on the data are.
  132:             $r->print(&mt('Statistics on submissions from [_1] to [_2]',
  133:                           &Apache::lonlocal::locallocaltime($starttime),
  134:                           &Apache::lonlocal::locallocaltime($endtime)));
  135:         }
  136:         &Apache::loncoursedata::populate_weight_table();
  137:         my $score_data = &Apache::loncoursedata::get_student_scores
  138:             ([&Apache::lonstatistics::get_selected_sections()],
  139:              [&Apache::lonstatistics::get_selected_groups()],
  140:              \@ProblemSymbs,
  141:              $Apache::lonstatistics::enrollment_status,undef,
  142:              $starttime,$endtime);
  143:         $r->print(&AnalyzeScoreData($score_data,$title,$total_weights));
  144:     } else {
  145:         $r->print('<h3>'.&mt('Make a sequence selection from the "Sequences and Folders" menu and hit "Create Plot" to begin').'</h3>');
  146:     }
  147:     return;
  148: }
  149: 
  150: #########################################################
  151: #########################################################
  152: 
  153: =pod
  154: 
  155: =item & AnalyzeScoreData($score_data)
  156: 
  157: Analyze the result of &Apache::loncoursedata::get_student_scores() and
  158: return html with a plot of the data and a table of the values and bins.
  159: 
  160: =cut
  161: 
  162: #########################################################
  163: #########################################################
  164: sub AnalyzeScoreData {
  165:     my ($score_data,$title,$maximum) = @_;
  166:     #
  167:     # Basic check first
  168:     if (ref($score_data) ne 'ARRAY' || @$score_data < 1) {
  169:         return '<h2>'.&mt('There is no data to plot').'</h2>';
  170:     }
  171:     #
  172:     # Determine which bins to use
  173:     my $lowest  = $score_data->[0]->[0];
  174:     $lowest = 0;
  175:     my $highest = $score_data->[-1]->[0];
  176:     my $binsize = 1;
  177:     if ($highest > 50) { $binsize = 2; }
  178:     if ($highest > 100) { $binsize = 5; }
  179:     if ($highest > 200) { $binsize = 10; }
  180:     if ($highest > 500) { $binsize = 20; }
  181:     if ($highest > 1000) { $binsize = 50; }
  182:     if ($highest > 2000) { $binsize = 100; }
  183:     #
  184:     # Get the data into the bins (destroying $score_data in the process)
  185:     my @Bins = &bin_data($score_data,$binsize,$lowest,$highest);
  186:     my @Xdata; my @Ydata; my $max;
  187:     my $Str = 
  188:         '<p>'.
  189:         &mt('Problem weights do not reflect individual student settings.')
  190:         .'</p>'.
  191:         '<table border="1">'."\n".'<tr><th>Range</th><th>Count</th></tr>'."\n";
  192:     my $sum = 0;
  193:     while (my $bin = shift(@Bins)) {
  194:         push (@Xdata,$bin->{'start'});
  195:         push (@Ydata,$bin->{'count'});
  196:         $sum += $bin->{'count'};
  197:         if ($bin->{'count'} > $max) {
  198:             $max = $bin->{'count'};
  199:         }
  200:         $Str.= '<tr><td>'.$bin->{'start'}.' - '.$bin->{'end'}.'</td>'.
  201:             '<td>'.$bin->{'count'}.'</td></tr>'."\n";
  202:     }
  203:     # scale max to an integer.
  204:     $max = 5*(int($max/5)+1);
  205:     $Str .= "</table><br />\n";
  206:     $title = &HTML::Entities::decode($title);
  207:     $Str = "\n<p>".
  208:         &Apache::loncommon::DrawBarGraph($title.' ('.$sum.' students)',
  209:                               'Correct Problems (max possible = '.$maximum.')',
  210:                                          'Number of students',
  211:                                          $max,undef, # colors
  212:                                          \@Xdata,\@Ydata).
  213:                                          "\n<br />\n".$Str;
  214:     $Str .= '</p>'."\n";
  215:     return $Str;                                               
  216: }
  217: 
  218: 
  219: #########################################################
  220: #########################################################
  221: 
  222: =pod
  223: 
  224: =item &bin_data($data,$binsize,$startbin,$endbin)
  225: 
  226: Note: This routine destroys the array of data passed to it.
  227: 
  228: Inputs: $data: array reference - the contents of @$data must
  229:         be arrays with x and y data.  $data = [ [x1,y1],[x2,y2],...];
  230:         $binsize: Width of bins to put data in
  231:         $startbin: the starting bin.
  232:         $endbin: the ending bin.
  233: Returns: Array of Bins.  Each bin is a hash reference with the following
  234:          keys: 'start', 'count', and 'end'.
  235: 
  236: =cut
  237: 
  238: #########################################################
  239: #########################################################
  240: sub bin_data {
  241:     my ($data,$binsize,$startbin,$endbin)=@_;
  242:     return () if (! defined($data) || ref($data) ne 'ARRAY');
  243:     #
  244:     # Determine bin geometry
  245:     my $binstart = $startbin;
  246:     my $binend = $startbin+$binsize;
  247:     # put the data into bins
  248:     my @Bins;
  249:     my $count=0;
  250:     my $idx=0;
  251:     while ($idx < scalar(@$data) && ($endbin-$binend + $binsize)>0) {
  252:         my $dataset = $data->[$idx++];
  253:         my ($x,$y) = @{$dataset};
  254:         while ($x > ($binend-.001)) {
  255:             # store the old data
  256:             push (@Bins,{ start => $binstart,
  257:                           count => $count,
  258:                           end   => $binend });
  259:             # start counting again
  260:             $binstart += $binsize;
  261:             $binend += $binsize;
  262:             $count = 0;
  263:         }
  264:         $count+=$y;
  265:     }
  266:     if ($count > 0) {
  267:         push (@Bins,{ start => $binstart,
  268:                       count => $count,
  269:                       end   => $binend });
  270:     }
  271:     return @Bins;
  272: }
  273: 
  274: #########################################################
  275: #########################################################
  276: 
  277: =pod
  278: 
  279: =item &CreateInterface
  280: 
  281: Inputs: none.
  282: 
  283: Returns: HTML for the correct problems plot interface.
  284: 
  285: =cut
  286: 
  287: #########################################################
  288: #########################################################
  289: sub CreateInterface {
  290:     ##
  291:     ## Environment variable initialization
  292:     my $Str;
  293:     $Str .= &Apache::lonhtmlcommon::breadcrumbs('Correct Problems Plot');
  294:     $Str .= '<p>';
  295:     #
  296:     $Str .= '<table cellspacing="5">'."\n";
  297:     $Str .= '<tr>';
  298:     $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
  299:     $Str .= '<td align="center"><b>'.&mt('Groups').'</b></td>';
  300:     $Str .= '<td align="center"><b>'.&mt('Access Status').'</b></td>';
  301:     $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
  302:     $Str .= '<td rowspan="2">'.
  303:         &Apache::lonstathelpers::limit_by_time_form().'</td>';
  304:     $Str .= '</tr>'."\n";
  305:     #
  306:     $Str .= '<tr><td align="center">'."\n";
  307:     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
  308:     $Str .= '</td>';
  309:     #
  310:     $Str .= '<td align="center">'."\n";
  311:     $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
  312:     $Str .= '</td>';
  313:     $Str .= '<td align="center">';
  314:     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
  315:     $Str .= '</td><td>'."\n";
  316:     #
  317:     $Str .= &Apache::lonstatistics::map_select('Maps','multiple,all',5);
  318:     $Str .= '</td>';
  319:     #
  320:     $Str .= '</tr>'."\n";
  321:     $Str .= '</table>'."\n";
  322:     #
  323:     $Str .= '<nobr>'.&mt('Status: [_1]',
  324:                          '<input type="text" '.
  325:                          'name="stats_status" size="60" value="" />').
  326:             '</nobr>'.'</p>';
  327:     ##
  328:     return $Str;
  329: }
  330: 
  331: 1;
  332: 
  333: __END__

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