File:  [LON-CAPA] / loncom / interface / statistics / loncorrectproblemplot.pm
Revision 1.11: download - view: text, annotated - select for diffs
Fri Jun 4 21:42:18 2004 UTC (19 years, 11 months ago) by matthew
Branches: MAIN
CVS tags: version_1_2_X, version_1_2_1, version_1_2_0, version_1_1_99_5, version_1_1_99_4, version_1_1_99_3, version_1_1_99_2, version_1_1_99_1, version_1_1_99_0, HEAD
Unified cache handling among statistics routines.  All use inlined progress
dialog.
&lonstatistics:&Gather_Full_Student_data now takes $formname and $inputname
    for inlined progress dialog.
&lonstathelpers: All calls to lonstatistics::Sequences_with_Assess now pass
    parameter 'all' in for mode.  Added &manage_caches which takes care of
    updating student data at the right times.  "right times" may need some
    work.  &GetStudentAnswers now takes $formname, $inputname as parameters.
&lonproblemanalysis, &lonproblemstatistics, and &lonsubmissiontimeanalysis:
    Use lonstathelpers::manage_caches and inline progress dialog.
&lonstudentsubmissions: Uses lonstathelpers::manage_caches and inlines prgwin
    Uses inlined prgwin to display further status data.

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

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