File:  [LON-CAPA] / loncom / interface / statistics / loncorrectproblemplot.pm
Revision 1.25: download - view: text, annotated - select for diffs
Mon Jan 17 00:19:41 2011 UTC (13 years, 4 months ago) by www
Branches: MAIN
CVS tags: language_hyphenation_merge, language_hyphenation, HEAD
Add statistics and reports under "grading"

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

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