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

1.1       matthew     1: # The LearningOnline Network with CAPA
                      2: #
1.28    ! golterma    3: # $Id: loncorrectproblemplot.pm,v 1.27 2012/05/03 11:21:33 goltermann 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();
1.25      www        34: use Apache::lonquickgrades();
1.1       matthew    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:                      );
1.4       matthew    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: #########################################################
1.1       matthew    58: 
                     59: sub BuildCorrectProblemsPage {
                     60:     my ($r,$c)=@_;
                     61:     #
                     62:     my %Saveable_Parameters = ('Status' => 'scalar',
1.20      raeburn    63:                                'Section' => 'array',
                     64:                                'Groups' => 'array');
1.1       matthew    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();    
1.25      www        71:     
                     72:     $r->print(&Apache::lonhtmlcommon::breadcrumbs('Correct Problems Plot'));
                     73:     &Apache::lonquickgrades::startGradeScreen($r,'statistics');
1.1       matthew    74:     #
                     75:     $r->print(&CreateInterface());
                     76:     #
                     77:     my @Students = @Apache::lonstatistics::Students;
                     78:     #
                     79:     if (@Students < 1) {
                     80:         $r->print('<h2>'.
1.20      raeburn    81:                   &mt('There are no students in the sections/groups selected').
1.1       matthew    82:                   '</h2>');
                     83:     }
                     84:     #
1.11      matthew    85:     my @CacheButtonHTML = 
                     86:         &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
1.1       matthew    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:     }
1.11      matthew    92:     foreach my $html (@CacheButtonHTML) {
                     93:         $r->print($html.('&nbsp;'x5));
                     94:     }
1.1       matthew    95:     $r->rflush();
                     96:     #
                     97:     # Determine which problem symbs we are to sum over
1.18      albertel   98:     if (exists($env{'form.CreatePlot'})) {
1.1       matthew    99:         my @ProblemSymbs;
1.16      matthew   100:         my $total_weights = 0;
1.9       matthew   101:         my $title = '';
1.15      matthew   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) {
1.9       matthew   107:                 if ($title eq '') {
1.15      matthew   108:                     $title = $seq->compTitle;
1.9       matthew   109:                 } else {
                    110:                     $title = 'Multiple Sequences';
                    111:                 }
1.1       matthew   112:             }
1.13      matthew   113:         } else {
1.16      matthew   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);
1.13      matthew   127:                 }
                    128:             }
1.1       matthew   129:         }
1.27      golterma  130:         $r->print('<p>'.
1.17      matthew   131:                   &Apache::lonstatistics::section_and_enrollment_description().
1.27      golterma  132:                   '</p>');
1.9       matthew   133:         my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
1.10      matthew   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:         }
1.16      matthew   140:         &Apache::loncoursedata::populate_weight_table();
1.1       matthew   141:         my $score_data = &Apache::loncoursedata::get_student_scores
1.17      matthew   142:             ([&Apache::lonstatistics::get_selected_sections()],
1.20      raeburn   143:              [&Apache::lonstatistics::get_selected_groups()],
1.1       matthew   144:              \@ProblemSymbs,
1.9       matthew   145:              $Apache::lonstatistics::enrollment_status,undef,
                    146:              $starttime,$endtime);
1.16      matthew   147:         $r->print(&AnalyzeScoreData($score_data,$title,$total_weights));
1.11      matthew   148:     } else {
1.27      golterma  149:         $r->print('<p>'.&mt('Make a sequence selection from the "Sequences and Folders" menu and hit "Create Plot" to begin').'</p>');
1.1       matthew   150:     }
                    151:     return;
                    152: }
                    153: 
                    154: #########################################################
                    155: #########################################################
                    156: 
                    157: =pod
                    158: 
1.2       matthew   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.
1.1       matthew   163: 
                    164: =cut
                    165: 
                    166: #########################################################
                    167: #########################################################
                    168: sub AnalyzeScoreData {
1.16      matthew   169:     my ($score_data,$title,$maximum) = @_;
1.1       matthew   170:     #
                    171:     # Basic check first
1.12      matthew   172:     if (ref($score_data) ne 'ARRAY' || @$score_data < 1) {
1.27      golterma  173:         return '<p class="LC_warning">'.&mt('There is no data to plot').'</p>';
1.1       matthew   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;
1.11      matthew   191:     my $Str = 
1.16      matthew   192:         '<p>'.
                    193:         &mt('Problem weights do not reflect individual student settings.')
                    194:         .'</p>'.
1.27      golterma  195:         &Apache::loncommon::start_data_table().
                    196:         &Apache::loncommon::start_data_table_header_row().
1.28    ! golterma  197:         '<th>'.&mt('Range').'</th><th>'.&mt('Count').'</th>'.
1.27      golterma  198:         &Apache::loncommon::end_data_table_header_row();
1.9       matthew   199:     my $sum = 0;
1.1       matthew   200:     while (my $bin = shift(@Bins)) {
                    201:         push (@Xdata,$bin->{'start'});
                    202:         push (@Ydata,$bin->{'count'});
1.9       matthew   203:         $sum += $bin->{'count'};
1.1       matthew   204:         if ($bin->{'count'} > $max) {
                    205:             $max = $bin->{'count'};
                    206:         }
1.27      golterma  207:         $Str.= &Apache::loncommon::start_data_table_row().
                    208:             '<td>'.$bin->{'start'}.' - '.$bin->{'end'}.'</td>'.
                    209:             '<td>'.$bin->{'count'}.'</td>'.
                    210:             &Apache::loncommon::end_data_table_row().'<br>';
1.1       matthew   211:     }
1.5       matthew   212:     # scale max to an integer.
                    213:     $max = 5*(int($max/5)+1);
1.27      golterma  214:     $Str .= &Apache::loncommon::end_data_table()."<br />\n";
1.9       matthew   215:     $title = &HTML::Entities::decode($title);
1.16      matthew   216:     $Str = "\n<p>".
                    217:         &Apache::loncommon::DrawBarGraph($title.' ('.$sum.' students)',
                    218:                               'Correct Problems (max possible = '.$maximum.')',
                    219:                                          'Number of students',
                    220:                                          $max,undef, # colors
                    221:                                          \@Xdata,\@Ydata).
                    222:                                          "\n<br />\n".$Str;
1.11      matthew   223:     $Str .= '</p>'."\n";
1.1       matthew   224:     return $Str;                                               
                    225: }
                    226: 
                    227: 
                    228: #########################################################
                    229: #########################################################
                    230: 
                    231: =pod
                    232: 
                    233: =item &bin_data($data,$binsize,$startbin,$endbin)
                    234: 
                    235: Note: This routine destroys the array of data passed to it.
                    236: 
                    237: Inputs: $data: array reference - the contents of @$data must
                    238:         be arrays with x and y data.  $data = [ [x1,y1],[x2,y2],...];
                    239:         $binsize: Width of bins to put data in
                    240:         $startbin: the starting bin.
                    241:         $endbin: the ending bin.
                    242: Returns: Array of Bins.  Each bin is a hash reference with the following
                    243:          keys: 'start', 'count', and 'end'.
                    244: 
                    245: =cut
                    246: 
                    247: #########################################################
                    248: #########################################################
                    249: sub bin_data {
                    250:     my ($data,$binsize,$startbin,$endbin)=@_;
                    251:     return () if (! defined($data) || ref($data) ne 'ARRAY');
                    252:     #
                    253:     # Determine bin geometry
                    254:     my $binstart = $startbin;
                    255:     my $binend = $startbin+$binsize;
                    256:     # put the data into bins
                    257:     my @Bins;
                    258:     my $count=0;
                    259:     my $idx=0;
1.22      albertel  260:     while ($idx < scalar(@$data) && ($endbin-$binend + $binsize)>=0) {
1.1       matthew   261:         my $dataset = $data->[$idx++];
                    262:         my ($x,$y) = @{$dataset};
1.9       matthew   263:         while ($x > ($binend-.001)) {
1.1       matthew   264:             # store the old data
                    265:             push (@Bins,{ start => $binstart,
                    266:                           count => $count,
                    267:                           end   => $binend });
                    268:             # start counting again
                    269:             $binstart += $binsize;
                    270:             $binend += $binsize;
                    271:             $count = 0;
                    272:         }
                    273:         $count+=$y;
                    274:     }
1.9       matthew   275:     if ($count > 0) {
                    276:         push (@Bins,{ start => $binstart,
                    277:                       count => $count,
                    278:                       end   => $binend });
                    279:     }
1.1       matthew   280:     return @Bins;
                    281: }
                    282: 
                    283: #########################################################
                    284: #########################################################
                    285: 
                    286: =pod
                    287: 
1.2       matthew   288: =item &CreateInterface
                    289: 
                    290: Inputs: none.
                    291: 
                    292: Returns: HTML for the correct problems plot interface.
1.1       matthew   293: 
                    294: =cut
                    295: 
                    296: #########################################################
                    297: #########################################################
                    298: sub CreateInterface {
                    299:     ##
                    300:     ## Environment variable initialization
                    301:     my $Str;
1.11      matthew   302:     $Str .= '<p>';
                    303:     #
1.24      bisitz    304:     $Str .= &Apache::loncommon::start_data_table();
                    305:     $Str .= &Apache::loncommon::start_data_table_header_row();
                    306:     $Str .= '<th>'.&mt('Sections').'</th>';
                    307:     $Str .= '<th>'.&mt('Groups').'</th>';
                    308:     $Str .= '<th>'.&mt('Access Status').'</th>';
                    309:     $Str .= '<th>'.&mt('Sequences and Folders').'</th>';
                    310:     $Str .= '<th>'.&mt('Time Period').'</th>';
                    311:     $Str .= &Apache::loncommon::end_data_table_header_row();
1.11      matthew   312:     #
1.24      bisitz    313:     $Str .= &Apache::loncommon::start_data_table_row();
                    314:     $Str .= '<td align="center" valign="top">'."\n";
1.1       matthew   315:     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
                    316:     $Str .= '</td>';
                    317:     #
1.24      bisitz    318:     $Str .= '<td align="center" valign="top">'."\n";
1.20      raeburn   319:     $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5);
                    320:     $Str .= '</td>';
1.24      bisitz    321:     $Str .= '<td align="center" valign="top">';
1.1       matthew   322:     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1.24      bisitz    323:     $Str .= '</td>'."\n";
1.1       matthew   324:     #
1.24      bisitz    325:     $Str .= '<td align="center" valign="top">'."\n";
1.15      matthew   326:     $Str .= &Apache::lonstatistics::map_select('Maps','multiple,all',5);
1.9       matthew   327:     $Str .= '</td>';
                    328:     #
1.24      bisitz    329:     $Str .= '<td align="center" valign="top">'."\n";
                    330:     $Str .= &Apache::lonstathelpers::limit_by_time_form();
                    331:     $Str .= '</td>';
                    332:     #
                    333:     $Str .= &Apache::loncommon::end_data_table_row();
                    334:     $Str .= &Apache::loncommon::end_data_table();
1.11      matthew   335:     ##
1.1       matthew   336:     return $Str;
                    337: }
                    338: 
                    339: 1;
                    340: 
                    341: __END__

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