File:  [LON-CAPA] / loncom / interface / statistics / loncorrectproblemplot.pm
Revision 1.13: download - view: text, annotated - select for diffs
Fri Dec 10 20:14:16 2004 UTC (19 years, 6 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Show the maximum possible when computing for 'all' sequences.

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

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