File:  [LON-CAPA] / loncom / interface / statistics / loncorrectproblemplot.pm
Revision 1.18: download - view: text, annotated - select for diffs
Thu Apr 7 06:56:24 2005 UTC (19 years, 3 months ago) by albertel
Branches: MAIN
CVS tags: version_2_1_X, version_2_1_3, version_2_1_2, version_2_1_1, version_2_1_0, version_2_0_X, version_2_0_99_1, version_2_0_2, version_2_0_1, version_2_0_0, version_1_99_3, version_1_99_2, version_1_99_1_tmcc, version_1_99_1, version_1_99_0_tmcc, version_1_99_0, HEAD
- ENV -> env

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

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