Annotation of loncom/interface/statistics/lonsubmissiontimeanalysis.pm, revision 1.11

1.1       matthew     1: # The LearningOnline Network with CAPA
                      2: #
1.11    ! matthew     3: # $Id: lonsubmissiontimeanalysis.pm,v 1.10 2004/01/19 21:31:08 matthew 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::lonsubmissiontimeanalysis;
                     29: 
                     30: use strict;
                     31: use Apache::lonnet();
                     32: use Apache::loncommon();
                     33: use Apache::lonhtmlcommon();
                     34: use Apache::loncoursedata();
                     35: use Apache::lonstatistics;
1.10      matthew    36: use Apache::lonstathelpers;
1.1       matthew    37: use Apache::lonlocal;
                     38: use HTML::Entities();
                     39: use Time::Local();
                     40: use Spreadsheet::WriteExcel();
                     41: 
                     42: my $plotcolors = ['#33ff00', 
                     43:                   '#ff33cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                     44:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                     45:                   ]; 
                     46: 
                     47: my @SubmitButtons = (
1.11    ! matthew    48:                      { name => 'PrevProblemAnalysis',
        !            49:                        text => 'Previous Problem' },
        !            50:                      { name => 'ProblemAnalysis',
1.1       matthew    51:                        text => 'Analyze Problem Again' },
1.11    ! matthew    52:                      { name => 'NextProblemAnalysis',
        !            53:                        text => 'Next Problem' },
1.1       matthew    54:                      { name => 'SelectAnother',
1.11    ! matthew    55:                        text => 'Choose a different Problem' },
1.1       matthew    56:                      );
                     57: 
                     58: sub BuildSubmissionTimePage {
                     59:     my ($r,$c)=@_;
1.4       matthew    60:     #
                     61:     my %Saveable_Parameters = ('Status' => 'scalar',
                     62:                                'Section' => 'array');
                     63:     &Apache::loncommon::store_course_settings('submissiontime_analysis',
                     64:                                               \%Saveable_Parameters);
                     65:     &Apache::loncommon::restore_course_settings('submissiontime_analysis',
                     66:                                                 \%Saveable_Parameters);
                     67:     #
                     68:     &Apache::lonstatistics::PrepareClasslist();    
                     69:     #
1.1       matthew    70:     $r->print('<h2>'.&mt('Submission Time Plots').'</h2>');
                     71:     $r->print(&CreateInterface());
                     72:     #
                     73:     my @Students = @Apache::lonstatistics::Students;
                     74:     #
                     75:     if (@Students < 1) {
                     76:         $r->print('<h2>There are no students in the sections selected</h2>');
                     77:     }
                     78:     #
                     79:     &Apache::loncoursedata::clear_internal_caches();
                     80:     if (exists($ENV{'form.ClearCache'}) || 
                     81:         exists($ENV{'form.updatecaches'}) ||
                     82:         (exists($ENV{'form.firstanalysis'}) &&
                     83:          $ENV{'form.firstanalysis'} ne 'no')) {
                     84:         &Apache::lonstatistics::Gather_Full_Student_Data($r);
                     85:     }
                     86:     if (! exists($ENV{'form.firstanalysis'})) {
                     87:         $r->print('<input type="hidden" name="firstanalysis" value="yes" />');
                     88:     } else {
                     89:         $r->print('<input type="hidden" name="firstanalysis" value="no" />');
                     90:     }
                     91:     $r->rflush();
                     92:     #
                     93:     if (! exists($ENV{'form.problemchoice'}) ||
                     94:         exists($ENV{'form.SelectAnother'})) {
                     95:         $r->print('<input type="submit" name="" value="'.
                     96:                   &mt('Graph Problem Submission Times').'" />');
                     97:         $r->print('&nbsp;'x5);
                     98:         $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
1.11    ! matthew    99:         $r->print(&Apache::lonstathelpers::ProblemSelector('.'));
1.1       matthew   100:     } else {
                    101:         foreach my $button (@SubmitButtons) {
                    102:             $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
                    103:                       'value="'.&mt($button->{'text'}).'" />');
                    104:             $r->print('&nbsp;'x5);
                    105:         }
1.11    ! matthew   106:         #
        !           107:         # Determine which problem we are to analyze
        !           108:         my $current_problem = &Apache::lonstathelpers::get_target_from_id
        !           109:             ($ENV{'form.problemchoice'});
        !           110:         #
        !           111:         my ($prev,$curr,$next) = 
        !           112:             &Apache::lonstathelpers::get_prev_curr_next($current_problem,
        !           113:                                                         '.',
        !           114:                                                         'part');
        !           115:         if (exists($ENV{'form.PrevProblemAnalysis'}) && defined($prev)) {
        !           116:             $current_problem = $prev;
        !           117:         } elsif (exists($ENV{'form.NextProblemAnalysis'}) && defined($next)) {
        !           118:             $current_problem = $next;
        !           119:         } else {
        !           120:             $current_problem = $curr;
        !           121:         }
        !           122:         #
        !           123:         # Store the current problem choice and send it out in the form
        !           124:         $ENV{'form.problemchoice'} = 
        !           125:             &Apache::lonstathelpers::make_target_id($current_problem);
1.1       matthew   126:         $r->print('<input type="hidden" name="problemchoice" value="'.
                    127:                   $ENV{'form.problemchoice'}.'" />');
                    128:         #
                    129:         $r->print('<hr />');
                    130:         $r->rflush();
                    131:         #
1.11    ! matthew   132:         my $resource = $current_problem->{'resource'};
1.1       matthew   133:         if (! defined($resource)) {
                    134:             $r->print('resource is undefined');
                    135:         } else {
                    136:             $r->print('<h1>'.$resource->{'title'}.'</h1>');
                    137:             $r->print('<h3>'.$resource->{'src'}.'</h3>');
                    138:             $r->rflush();
1.10      matthew   139:             $r->print(&Apache::lonstathelpers::render_resource($resource));
1.1       matthew   140:             $r->rflush();
1.11    ! matthew   141:             $r->print(&analyze_times($r,$resource,\@Students,
        !           142:                                      $current_problem->{'part'}));
1.1       matthew   143:         }
                    144:         $r->print('<hr />');
                    145:     }
                    146: }
                    147: 
                    148: #########################################################
                    149: #########################################################
                    150: ##
                    151: ##                  Time Analysis
                    152: ##
                    153: #########################################################
                    154: #########################################################
                    155: sub get_week_start {
                    156:     my ($randomtime) = @_;
                    157:     my ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = 
                    158:         localtime($randomtime);
                    159:     $randomtime -= $wday * 86400;
                    160:     ($sec,$min,$hour,$mday,$month,$year,$wday,$yday,$isdst) = 
                    161:         localtime($randomtime);
                    162:     my $week_start = &Time::Local::timelocal(0,0,0,$mday,$month,$year);
                    163:     return $week_start;
                    164: }
                    165: 
                    166: sub analyze_times {
                    167:     my ($r,$resource,$students,$part) = @_;
1.2       matthew   168:     #
                    169:     # Convenience arrays
                    170:     my @FullWeekDay = (qw/Sunday Monday Tuesday Wednesday Thursday Friday
                    171:                        Saturday/);
                    172:     my @WeekDay = (qw/SUN MON TUE WED THU FRI SAT SUN/);
                    173:     my @Month = (qw/Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/);
                    174:     #
1.1       matthew   175:     my $html; # holds results of analysis
                    176:     # Get the data
                    177:     my $SubData = &Apache::loncoursedata::get_response_time_data
                    178:         ($students,$resource->{'symb'},$part);
                    179:     if (! defined($SubData) || ! ref($SubData)) {
1.9       matthew   180:         $html.= '<h2>There is no submission data for this problem</h2>';
1.1       matthew   181:         return $html;
                    182:     }
                    183:     my $NumSub = scalar(@{$SubData});
                    184:     if (! @{$SubData}) {
1.9       matthew   185:         $html.= '<h2>There is no submission data for this problem</h2>';
1.1       matthew   186:         return $html;
                    187:     }
                    188:     # Process the data
                    189:     #
                    190:     my (undef,undef,undef,$mday,$month,$year,$wday,$yday,$isdst) = 
                    191:         localtime(&get_time_from_row($SubData->[0]));
                    192:     my $day_start = &Time::Local::timelocal(0,0,0,$mday,$month,$year);
                    193:     #
1.2       matthew   194:     # Configure the bins used to store the data.
1.1       matthew   195:     my $binsize = 3600; # seconds
                    196:     my $bins_per_day = 86400/$binsize;
                    197:     my $bincount = 0;
                    198:     my $endtime = $day_start;
                    199:     #
1.2       matthew   200:     # Initialize loop variables
1.1       matthew   201:     my $max;
1.2       matthew   202:     my @Ydata=(0);
                    203:     my @AnsData=(0);
                    204:     my @Xlabel=($WeekDay[$wday]);
                    205:     my $cumulative_answers = 0;
                    206:     #
1.1       matthew   207:     foreach my $row (@$SubData) {
                    208:         my $subtime = &get_time_from_row($row);
                    209:         while ($subtime > $endtime && $endtime < time) {
                    210:             # Create a new bin
                    211:             $bincount++;
                    212:             $Ydata[$bincount]=0;
                    213:             $AnsData[$bincount]=$AnsData[$bincount-1];
                    214:             $endtime += $binsize;
                    215:             if ($bincount % (86400/$binsize) == 0) {
1.2       matthew   216:                 $wday++;
1.1       matthew   217:                 $wday %= 7;
1.2       matthew   218:                 $Xlabel[$bincount] = $WeekDay[$wday];
1.1       matthew   219:             } else {
                    220:                 $Xlabel[$bincount] = '';
                    221:             }
                    222:         }
                    223:         $Ydata[$bincount]++;
                    224:         $max = $Ydata[$bincount] if ($max < $Ydata[$bincount]);
                    225:         $AnsData[$bincount] += &successful_submission($row);
                    226:         $cumulative_answers += &successful_submission($row);
                    227:     }
                    228:     foreach my $maximum (10,15,20,25,30,40,50,60,70,80,90,100,
                    229:                           120,150,200,250,300,350,400,450,500,
                    230:                           600,700,800,900,1000,1100,1200,1500,2000,
                    231:                           2500,3000,4000,5000) {
                    232:         if ($max < $maximum) {
                    233:             $max = $maximum;
                    234:             last;
                    235:         }
                    236:     }
                    237:     while ($bincount % $bins_per_day != 0) {
                    238:         $bincount++;
                    239:         $Ydata[$bincount]=0;
                    240:         $AnsData[$bincount]=$AnsData[$bincount-1];
                    241:         $endtime += $binsize;
                    242:         if ($bincount % (86400/$binsize) == 0) {
1.2       matthew   243:             $wday ++;
                    244:             $wday %= 7;
1.1       matthew   245:             $Xlabel[$bincount] = $WeekDay[$wday];
                    246:         } else {
                    247:             $Xlabel[$bincount] = '';
                    248:         }
                    249:     }
1.6       matthew   250:     my $numstudents = scalar(@$students);
                    251:     for (my $i=0;$i<=$#AnsData;$i++) {
                    252:         $AnsData[$i] = int(100*($AnsData[$i]/$numstudents));
                    253:     }
1.1       matthew   254:     my $title = 'Number of Submissions and Number Correct';
                    255:     my $xlabel;
1.2       matthew   256:     (undef,undef,undef,$mday,$month,$year,$wday) = localtime($day_start);
                    257:     $xlabel .= $FullWeekDay[$wday].' '.
                    258:         join(' ',($Month[$month],$mday,1900+$year)).' - ';
                    259:     (undef,undef,undef,$mday,$month,$year,$wday) = localtime($endtime);
                    260:     $xlabel .= $FullWeekDay[$wday].' '.
                    261:         join(' ',($Month[$month],$mday,1900+$year));
1.8       matthew   262:     my $width = 50+2*$bincount;
                    263:     if ($width < 250) {
                    264:         $width = 250;
                    265:     }
1.1       matthew   266:     $html .= &Apache::loncommon::DrawXYYGraph($title,
                    267:                                               $xlabel,
1.6       matthew   268:                                               'Submissions vs Time',
1.1       matthew   269:                                               $plotcolors,
                    270:                                               \@Xlabel,
                    271:                                               \@Ydata,
                    272:                                               0,$max,
                    273:                                               \@AnsData,
1.6       matthew   274:                                               0,100,
1.1       matthew   275:                                               (xskip => $bins_per_day,
                    276:                                                x_ticks => $bins_per_day,
                    277:                                                x_tick_offset => $bins_per_day,
1.8       matthew   278:                                                width => $width,
1.7       matthew   279:                       y1_label=>'Number of Submissions per hour',
                    280:                       y2_label=>'Percent of Students answering Correctly',
                    281:                      'data.1.label'=>'Submissions per hour',
                    282:                      'data.2.label'=>'Percent correct',
                    283:                                                )
1.1       matthew   284:                                               );
                    285:     $html .= '<br />';
                    286:     return $html;
                    287: }
                    288: 
                    289: sub successful_submission {
                    290:     my ($row) = @_;
                    291:     if (ref($row) eq 'ARRAY') {
1.3       matthew   292:         return $row->[&Apache::loncoursedata::RT_awarded()];
1.1       matthew   293:     }
                    294:     return undef;
                    295:     return 0;
                    296: }
                    297: 
                    298: sub get_time_from_row {
                    299:     my ($row) = @_;
                    300:     if (ref($row) eq 'ARRAY') {
1.3       matthew   301:         return $row->[&Apache::loncoursedata::RT_timestamp()];
1.1       matthew   302:     } 
                    303:     return undef;
                    304: }
                    305: 
                    306: sub get_tries_from_row {
                    307:     my ($row) = @_;
                    308:     if (ref($row) eq 'ARRAY') {
1.3       matthew   309:         return $row->[&Apache::loncoursedata::RT_tries()];
1.1       matthew   310:     }
                    311:     return undef;
                    312: }
                    313: 
                    314: sub Process_Row {
                    315:     my ($row) = @_;
                    316:     my %RowData;
                    317:     my ($student_id,$award,$tries,$time) = @$row;
                    318:     return %RowData;
                    319: }
                    320: 
                    321: #########################################################
                    322: #########################################################
                    323: ##
                    324: ##   Generic Interface Routines
                    325: ##
                    326: #########################################################
                    327: #########################################################
                    328: sub CreateInterface {
                    329:     ##
                    330:     ## Environment variable initialization
                    331:     if (! exists$ENV{'form.AnalyzeOver'}) {
                    332:         $ENV{'form.AnalyzeOver'} = 'Tries';
                    333:     }
                    334:     ##
                    335:     ## Build the menu
                    336:     my $Str = '';
                    337:     $Str .= '<table cellspacing="5">'."\n";
                    338:     $Str .= '<tr>';
                    339:     $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
                    340:     $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
                    341:     $Str .= '<td align="center">&nbsp;</td>';
                    342:     $Str .= '</tr>'."\n";
                    343:     ##
                    344:     ## 
                    345:     $Str .= '<tr><td align="center">'."\n";
                    346:     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
                    347:     $Str .= '</td>';
                    348:     #
                    349:     $Str .= '<td align="center">';
                    350:     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
                    351:     $Str .= '</td>';
                    352:     #
                    353:     my $only_seq_with_assessments = sub { 
                    354:         my $s=shift;
                    355:         if ($s->{'num_assess'} < 1) { 
                    356:             return 0;
                    357:         } else { 
                    358:             return 1;
                    359:         }
                    360:     };
                    361:     &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
                    362:                                               $only_seq_with_assessments);
                    363:     ##
                    364:     ##
                    365:     $Str .= '</tr>'."\n";
                    366:     $Str .= '</table>'."\n";
                    367:     return $Str;
                    368: }
                    369: 
                    370: 1;
                    371: 
                    372: __END__

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