File:  [LON-CAPA] / loncom / interface / statistics / loncorrectproblemplot.pm
Revision 1.10: download - view: text, annotated - select for diffs
Mon Mar 8 18:42:58 2004 UTC (20 years, 4 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Added text describing starttime and endtime in html output.

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

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