Annotation of loncom/interface/statistics/loncorrectproblemplot.pm, revision 1.22

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

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