File:  [LON-CAPA] / loncom / interface / statistics / lonproblemanalysis.pm
Revision 1.107: download - view: text, annotated - select for diffs
Fri Dec 3 21:53:59 2004 UTC (19 years, 7 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Restrict analysis to implemented types.
OR_tries_analysis: No longer ISE when there are no concepts.

    1: # The LearningOnline Network with CAPA
    2: #
    3: # $Id: lonproblemanalysis.pm,v 1.107 2004/12/03 21:53:59 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: package Apache::lonproblemanalysis;
   28: 
   29: use strict;
   30: use Apache::lonnet();
   31: use Apache::loncommon();
   32: use Apache::lonhtmlcommon();
   33: use Apache::loncoursedata();
   34: use Apache::lonstatistics;
   35: use Apache::lonlocal;
   36: use Apache::lonstathelpers();
   37: use Apache::lonstudentsubmissions();
   38: use HTML::Entities();
   39: use Time::Local();
   40: use Spreadsheet::WriteExcel();
   41: use capa;
   42: 
   43: my $plotcolors = ['#33ff00', 
   44:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
   45:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
   46:                   ]; 
   47: 
   48: my @SubmitButtons = ({ name => 'PrevProblemAnalysis',
   49:                        text => 'Previous Problem' },
   50:                      { name => 'ProblemAnalysis',
   51:                        text => 'Analyze Problem Again' },
   52:                      { name => 'NextProblemAnalysis',
   53:                        text => 'Next Problem' },
   54:                      { name => 'break'},
   55:                      { name => 'SelectAnother',
   56:                        text => 'Choose a different Problem' },
   57:                      { name => 'ExcelOutput',
   58:                        text => 'Produce Excel Output' });
   59: 
   60: sub BuildProblemAnalysisPage {
   61:     my ($r,$c)=@_;
   62:     #
   63:     my %Saveable_Parameters = ('Status' => 'scalar',
   64:                                'Section' => 'array',
   65:                                'NumPlots' => 'scalar',
   66:                                'AnalyzeOver' => 'scalar',
   67:                                );
   68:     &Apache::loncommon::store_course_settings('problem_analysis',
   69:                                               \%Saveable_Parameters);
   70:     &Apache::loncommon::restore_course_settings('problem_analysis',
   71:                                                 \%Saveable_Parameters);
   72:     #
   73:     &Apache::lonstatistics::PrepareClasslist();
   74:     #
   75:     $r->print(&CreateInterface());
   76:     #
   77:     my @Students = @Apache::lonstatistics::Students;
   78:     #
   79:     if (@Students < 1 && exists($ENV{'form.firstrun'})) {
   80:         $r->print('<h2>There are no students in the sections selected</h2>');
   81:     }
   82:     #
   83:     my @CacheButtonHTML = 
   84:         &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
   85:     $r->rflush();
   86:     #
   87:     # Support for numerical and radio response isn't complete enough to
   88:     # include in 1.2 release.
   89:     my $problem_types = '(option|radiobutton|numerical)';
   90:     # my $problem_types = '.';#(option)';
   91:     if (exists($ENV{'form.problemchoice'}) && 
   92:         ! exists($ENV{'form.SelectAnother'})) {
   93:         foreach my $button (@SubmitButtons) {
   94:             if ($button->{'name'} eq 'break') {
   95:                 $r->print("<br />\n");
   96:             } else {
   97:                 $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
   98:                           'value="'.&mt($button->{'text'}).'" />');
   99:                 $r->print('&nbsp;'x5);
  100:             }
  101:         }
  102:         foreach my $html (@CacheButtonHTML) {
  103:             $r->print($html.('&nbsp;'x5));
  104:         }
  105:         #
  106:         $r->print('<hr />');
  107:         $r->rflush();
  108:         #
  109:         # Determine which problem we are to analyze
  110:         my $current_problem = &Apache::lonstathelpers::get_target_from_id
  111:             ($ENV{'form.problemchoice'});
  112:         #
  113:         my ($prev,$curr,$next) = 
  114:             &Apache::lonstathelpers::get_prev_curr_next($current_problem,
  115:                                                         $problem_types,
  116:                                                         'response',
  117:                                                         );
  118:         if (exists($ENV{'form.PrevProblemAnalysis'}) && defined($prev)) {
  119:             $current_problem = $prev;
  120:         } elsif (exists($ENV{'form.NextProblemAnalysis'}) && defined($next)) {
  121:             $current_problem = $next;
  122:         } else {
  123:             $current_problem = $curr;
  124:         }
  125:         #
  126:         # Store the current problem choice and send it out in the form
  127:         $ENV{'form.problemchoice'} = 
  128:             &Apache::lonstathelpers::make_target_id($current_problem);
  129:         $r->print('<input type="hidden" name="problemchoice" value="'.
  130:                   $ENV{'form.problemchoice'}.'" />');
  131:         #
  132:         if (! defined($current_problem->{'resource'})) {
  133:             $r->print('resource is undefined');
  134:         } else {
  135:             my $resource = $current_problem->{'resource'};
  136:             $r->print('<h1>'.$resource->{'title'}.'</h1>');
  137:             $r->print('<h3>'.$resource->{'src'}.'</h3>');
  138:             if ($ENV{'form.show_prob'} eq 'true') {
  139:                 $r->print(&Apache::lonstathelpers::render_resource($resource));
  140:             }
  141:             $r->rflush();
  142:             my %Data = &Apache::lonstathelpers::get_problem_data
  143:                 ($resource->{'src'});
  144:             my $problem_data = $Data{$current_problem->{'part'}.
  145:                                     '.'.
  146:                                     $current_problem->{'respid'}};
  147:             if ($current_problem->{'resptype'} eq 'option') {
  148:                 &OptionResponseAnalysis($r,$current_problem,
  149:                                         $problem_data,
  150:                                         \@Students);
  151:             } elsif ($current_problem->{'resptype'} eq 'radiobutton') {
  152:                 &radio_response_analysis($r,$current_problem,
  153:                                          $problem_data,
  154:                                          \@Students);
  155:             } elsif ($current_problem->{'resptype'} eq 'numerical') {
  156:                 &numerical_response_analysis($r,$current_problem,
  157:                                              $problem_data,\@Students);
  158:             } else {
  159:                 $r->print('<h2>Analysis of '.$current_problem->{'resptype'}.' is not supported</h2>');
  160:             }
  161:         }
  162:         $r->print('<hr />');
  163:     } else {
  164:         $r->print('<input type="submit" name="ProblemAnalysis" value="'.
  165:                   &mt('Analyze Problem').'" />');
  166:         $r->print('&nbsp;'x5);
  167:         $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
  168:         $r->print(&Apache::lonstathelpers::ProblemSelector
  169:                   ($problem_types));
  170:     }
  171: }
  172: 
  173: #########################################################
  174: #########################################################
  175: ##
  176: ##      Numerical Response Routines
  177: ##
  178: #########################################################
  179: #########################################################
  180: sub numerical_response_analysis {
  181:     my ($r,$problem,$problem_analysis,$students) = @_;
  182:     my $c = $r->connection();
  183:     #
  184:     if ($ENV{'form.AnalyzeOver'} !~ /^(tries|time)$/) {
  185:         $r->print('Bad request');
  186:     }
  187:     #
  188:     my ($resource,$partid,$respid) = ($problem->{'resource'},
  189:                                       $problem->{'part'},
  190:                                       $problem->{'respid'});
  191:     # Gather student data
  192:     my $response_data = &Apache::loncoursedata::get_response_data
  193:         (\@Apache::lonstatistics::SelectedSections,
  194:          $Apache::lonstatistics::enrollment_status,
  195:          $resource->{'symb'},$respid);
  196:     #
  197:     $problem_analysis->{'answercomputed'} = 1;
  198:     if ($problem_analysis->{'answercomputed'}) {
  199:         my $answers = 
  200:             &Apache::lonstathelpers::GetStudentAnswers($r,$problem,$students,
  201:                                                        'Statistics',
  202:                                                        'stats_status');
  203:         $r->print(&numerical_one_dimensional_plot($r,600,150,$answers));
  204:     }
  205:     #
  206:     if (ref($response_data) ne 'ARRAY') {
  207:         $r->print('<h2>'.
  208:                   &mt('There is no submission data for this resource').
  209:                   '</h2>');
  210:         return;
  211:     }
  212:     my $analysis_html = '<table>';
  213:     for (my $plot_num = 1;$plot_num<=$ENV{'form.NumPlots'};$plot_num++) {
  214:         my $restriction_function;
  215:         my $header_message;
  216:         my $stats_message;
  217:         my $post_message; # passed through &mt sooner rather than later
  218:         my $no_data_message;
  219:         my @extra_data;
  220:         if ($ENV{'form.AnalyzeOver'} eq 'tries') {
  221:             $restriction_function = sub {($_[0]->{'tries'} == $plot_num?1:0)};
  222:             $header_message = 'Attempt [_1]';
  223:             $stats_message = 
  224:                 '[_1] submissions, [_2] correct, [_3] incorrect';
  225:             $post_message = '';
  226:             $no_data_message = 'No data exists for attempt [_1]';
  227:         } else {
  228:             my $starttime = &Apache::lonhtmlcommon::get_date_from_form
  229:                 ('startdate_'.$plot_num);
  230:             my $endtime = &Apache::lonhtmlcommon::get_date_from_form
  231:                 ('enddate_'.$plot_num);
  232:             ($starttime,$endtime) = &ensure_start_end_times
  233:                 ($starttime,$endtime,
  234:                  &get_time_from_row($response_data->[0]),
  235:                  &get_time_from_row($response_data->[-1]),
  236:                  $plot_num);
  237:             $header_message = 'Data from [_2] to [_3]';
  238:             $extra_data[0] = &Apache::lonlocal::locallocaltime($starttime);
  239:             $extra_data[1] = &Apache::lonlocal::locallocaltime($endtime);
  240:             #
  241:             $stats_message = 
  242:                 '[_1] submissions from [_4] students, [_2] correct, [_3] incorrect';
  243:             #
  244:             $post_message = 
  245:                 &mt('Start time: [_1]',
  246:                     &Apache::lonhtmlcommon::date_setter
  247:                     ('Statistics','startdate_'.$plot_num,$starttime)).
  248:                 '<br />'.
  249:                 &mt('End time: [_1]',
  250:                     &Apache::lonhtmlcommon::date_setter
  251:                     ('Statistics','enddate_'.$plot_num,$endtime));
  252:             $restriction_function = 
  253:                 sub { 
  254:                     my $t = $_[0]->{'timestamp'};
  255:                     if ($t >= $starttime && $t < $endtime) {
  256:                         return 1;
  257:                     } else { 
  258:                         return 0;
  259:                     }
  260:                 };
  261:             $no_data_message = 'No data for [_2] to [_3]';
  262:         }
  263:         #
  264:         my ($correct,$answers) = 
  265:             &numerical_determine_answers($r,$resource,$partid,
  266:                                          $respid,$students);
  267:         if ($c->aborted()) { return; };
  268:         #
  269:         my $responses = &numerical_classify_responses($response_data,$correct,
  270:                                                       $restriction_function);
  271:         if ($responses->{'_count'} == 0) {
  272:             $analysis_html.= 
  273:                 '<tr><td colspan="2"><font size="+1"><b>'.
  274:                 &mt($no_data_message,$plot_num,@extra_data).
  275:                 '</b></font></td></tr>';
  276:         } else {
  277:             $analysis_html.= 
  278:                 '<tr><td colspan="2" align="center"><font size="+1"><b>'.
  279:                 &mt($header_message,$plot_num,@extra_data).
  280:                 '</b></font></td></tr>'.
  281:                 '<tr><td colspan="2" align="center">'.
  282:                 &mt($stats_message,
  283:                     $responses->{'_count'},
  284:                     $responses->{'_correct'},
  285:                     $responses->{'_count'}-$responses->{'_correct'},
  286:                     $responses->{'_students'},
  287:                     @extra_data).
  288:                     '</td></tr>'.
  289:                     '<tr>'.'<td valign="top" align="center">'.
  290:                     &numerical_plot_percent($r,$responses).'</td>'.
  291:                     '<td align="center" valign="top">'.
  292:                     &numerical_plot_differences($r,$responses).'</td>'.
  293:                     '</tr>';
  294:         }
  295:         if ($post_message ne '') {
  296:             $analysis_html .=
  297:                 '<tr><td colspan="2">'.$post_message.'</td></tr>';
  298:         }
  299:     }
  300:     $analysis_html.='</table>';
  301:     $r->print($analysis_html);
  302:     #
  303:     return;
  304: }
  305: 
  306: sub numerical_plot_percent {
  307:     my ($r,$responses) = @_;
  308:     #
  309:     my $total = $responses->{'_count'};
  310:     return '' if ($total == 0);
  311:     my $minbin = 5;
  312:     while (my ($interval,$submissions) = each(%$responses)) {
  313:         next if ($interval =~ /^_/);
  314:         my ($ans,$ans_low,$ans_high) = split(" ",$interval);
  315:         my $low_percent  = abs(100*($ans-$ans_low)/$ans);
  316:         my $high_percent = abs(100*($ans_high-$ans)/$ans);
  317:         if ($minbin > $high_percent) { $minbin = $high_percent; }
  318:         if ($minbin > $low_percent) { $minbin = $low_percent; }
  319:     }
  320:     #
  321:     my @bins;
  322:     if ($minbin < 1) {
  323:         @bins = ('0.1','0.5','1.0','1.5','2.0','2.5','3.0','4.0','5.0',10,20,50,100);        
  324:     } elsif ($minbin < 2) {
  325:         @bins = ('0.5','1.0','1.5','2.0','2.5','3.0','4.0','5.0',10,20,50,100);
  326:     } elsif ($minbin < 5) {
  327:         @bins = (1,2,3,4,5,10,25,50,75,100,200);
  328:     } elsif ($minbin < 10) {
  329:         @bins = (2,4,6,8,10,12,15,20,25,30,50,75,100,200);
  330:     } else {
  331:         @bins = (5,10,15,20,25,30,50,75,100,200);
  332:     }
  333:     my @labels = (1..scalar(@bins));
  334:     #
  335:     my @correct;
  336:     my @incorrect;
  337:     my @count;
  338:     while (my ($interval,$submissions) = each(%$responses)) {
  339:         next if ($interval =~ /^_/);
  340:         my ($ans,$ans_low,$ans_high) = split(" ",$interval);
  341:         while (my ($submission,$counts) = each(%$submissions)) {
  342:             my ($correct_count,$incorrect_count) = @$counts;
  343:             my $scaled_value = abs(($submission-$ans)/$ans);
  344:             my $bin=0;
  345:             for ($bin=0;$bin<$#bins;$bin++) { # not <= for a reason
  346:                 last if ($bins[$bin]>$scaled_value);
  347:             }
  348:             $correct[$bin]+=$correct_count;
  349:             $incorrect[$bin]+=$incorrect_count;
  350:             $count[$bin]+=$correct_count+$incorrect_count;
  351:         }
  352:     }
  353:     #
  354:     my @plot_correct;
  355:     my @plot_incorrect;
  356:     for (my $i=0;$i<=$#bins;$i++) {
  357:         $plot_correct[$i] = $correct[$i]*100/$total;
  358:         $plot_incorrect[$i] = $incorrect[$i]*100/$total;
  359:     }
  360:     my $title = &mt('Distribution by Percent');
  361:     my $graph = &Apache::loncommon::DrawBarGraph
  362:         ($title,'Percent difference from correct','Number of answers',
  363:          100,['#33FF00','#FF3300'],\@labels,\@plot_correct,\@plot_incorrect,
  364:          {xskip=>1});
  365:     #
  366:     my $table = $graph.$/.
  367:         &numerical_bin_table(\@bins,\@labels,\@incorrect,\@correct,\@count).$/;
  368:     return $table;
  369: }
  370: 
  371: sub numerical_plot_differences {
  372:     my ($r,$responses) = @_;
  373:     #
  374:     my $total = $responses->{'_count'};
  375:     return '' if ($total == 0);
  376:     my $minbin = undef;
  377:     my $maxbin = undef;
  378:     while (my ($interval,$submissions) = each(%$responses)) {
  379:         next if ($interval =~ /^_/);
  380:         my ($ans,$ans_low,$ans_high) = split(" ",$interval);
  381:         my $low_diff  = abs($ans-$ans_low);
  382:         my $high_diff = abs($ans_high-$ans);
  383:         if (! defined($maxbin)) { $maxbin = $low_diff;}
  384:         if (! defined($minbin)) { $minbin = $low_diff;}
  385:         #
  386:         if ($minbin > $high_diff) { $minbin = $high_diff; }
  387:         if ($minbin > $low_diff ) { $minbin = $low_diff; }
  388:         #
  389:         if ($maxbin < $high_diff) { $maxbin = $high_diff; }
  390:         if ($maxbin < $low_diff ) { $maxbin = $low_diff; }
  391:     }    
  392:     #
  393:     my @bins;
  394:     my @labels;
  395:     # Hmmmm, should switch to absolute difference
  396:     for (my $i=1;$i<=20;$i++) {
  397:         push(@bins,$i*$minbin/2);
  398:         push(@labels,$i);
  399:     }
  400:     #
  401:     my @correct;
  402:     my @incorrect;
  403:     my @count;
  404:     while (my ($interval,$submissions) = each(%$responses)) {
  405:         next if ($interval =~ /^_/);
  406:         my ($ans,$ans_low,$ans_high) = split(" ",$interval);
  407:         while (my ($submission,$counts) = each(%$submissions)) {
  408:             my ($correct_count,$incorrect_count) = @$counts;
  409:             my $value = abs($submission-$ans);
  410:             my $bin=0;
  411:             for ($bin=0;$bin<$#bins;$bin++) { # not <= for a reason
  412:                 last if ($bins[$bin]>$value);
  413:             }
  414:             $correct[$bin]+=$correct_count;
  415:             $incorrect[$bin]+=$incorrect_count;
  416:             $count[$bin]+=$correct_count+$incorrect_count;
  417:         }
  418:     }
  419:     #
  420:     my @plot_correct;
  421:     my @plot_incorrect;
  422:     for (my $i=0;$i<=$#bins;$i++) {
  423:         $plot_correct[$i]   =   $correct[$i]*100/$total;
  424:         $plot_incorrect[$i] = $incorrect[$i]*100/$total;
  425:     }
  426:     my $title = &mt('Distribution by Magnitude');
  427:     my $graph = &Apache::loncommon::DrawBarGraph
  428:         ($title,'magnitude difference from correct','Number of answers',
  429:          100,['#33FF00','#FF3300'],\@labels,\@plot_correct,\@plot_incorrect,
  430:          {xskip=>1});
  431:     #
  432:     my $table = $graph.$/.
  433:         &numerical_bin_table(\@bins,\@labels,\@incorrect,\@correct,\@count).$/;
  434:     return $table;
  435: }
  436: 
  437: sub numerical_classify_responses {
  438:     &Apache::lonnet::logthis('--------------');
  439:     my ($full_row_data,$correct,$function) = @_;
  440:     my %submission_data;
  441:     my %students;
  442:     my $max=0;
  443:     foreach my $row (@$full_row_data) {
  444: #        &Apache::lonnet::logthis(' row = '.join(',',@$row));
  445:         my %subm = &hashify_attempt($row);
  446:         if (ref($correct) eq 'HASH') {
  447:             $subm{'correct'} = $correct->{$subm{'student'}}->{'answer'};
  448:             $subm{'unit'} = $correct->{$subm{'student'}}->{'unit'};
  449:         } else { # This probably never happens....
  450:             $subm{'correct'} = $correct->{'answer'};
  451:             $subm{'unit'} = $correct->{'unit'};
  452:         }
  453:         $subm{'submission'} =~ s/=\d+\s*$//;
  454:         if (&$function(\%subm)) {
  455:             my $scaled = '1';
  456:             my ($sname,$sdom) = split(':',$subm{'student'});
  457:             # Note that $subm{'unit'} is modified by the following call
  458:             # We do not use it again but you should be aware just in case.
  459: #            my ($myunit,$mysub) = ($subm{'unit'},$subm{'submission'});
  460: #            $myunit = 'm';
  461: #            # &Apache::lonnet::logthis($myunit);
  462: #            my $result = 
  463: #                &capa::caparesponse_get_real_response($myunit,
  464: #                                                      $mysub,
  465: #                                                      \$scaled);
  466: #            # &Apache::lonnet::logthis('  '.$myunit.':'.$subm{'unit'}.
  467: #            #  ' '.$mysub.':'.$subm{'submission'}.'; '.$result);
  468: #            next if (! defined($scaled));
  469: #            next if ($result ne '6');
  470: #            my $submission = $scaled;
  471:             my $submission = $subm{'submission'};
  472:             $students{$subm{'student'}}++;
  473:             if (&numerical_submission_is_correct($subm{'award'})) { 
  474:                 &Apache::lonnet::logthis('correct:'.$submission.':'.$subm{'correct'});
  475:                 $submission_data{'_correct'}++;
  476:                 $submission_data{'_count'}++;
  477:                 $submission_data{$subm{'correct'}}->{$submission}->[0]++;
  478:             } elsif (&numerical_submission_is_incorrect($subm{'award'})) { 
  479:                 &Apache::lonnet::logthis('incorrect:'.$submission.':'.$subm{'correct'});
  480:                 $submission_data{'_count'}++;
  481:                 $submission_data{$subm{'correct'}}->{$submission}->[1]++;
  482:             }
  483:             my $value = 
  484:                 $submission_data{$subm{'correct'}}->{$submission}->[0]+ 
  485:                 $submission_data{$subm{'correct'}}->{$submission}->[1];
  486:             if ($max < $value) { $max = $value; }
  487:         }
  488:     }
  489:     $submission_data{'_max'} = $max;
  490:     $submission_data{'_students'}=scalar(keys(%students));
  491:     return \%submission_data;
  492: }
  493: 
  494: sub numerical_submission_is_correct {
  495:     my ($award) = @_;
  496:     &Apache::lonnet::logthis('award = "'.$award.'"');
  497:     if ($award =~ /^(APPROX_ANS|EXACT_ANS)$/) {
  498:         return 1;
  499:     } else {
  500:         return 0;
  501:     }
  502: }
  503: 
  504: sub numerical_submission_is_incorrect {
  505:     my ($award) = @_;
  506:     if ($award =~ /^(INCORRECT)$/) {
  507:         return 1;
  508:     } else {
  509:         return 0;
  510:     }
  511: }
  512: 
  513: sub numerical_bin_table {
  514:     my ($bins,$labels,$incorrect,$correct,$count)=@_;
  515:     my $table = 
  516:         '<table><tr><th>'.&mt('Bar').'</th>'.
  517:         '<th colspan="3">'.&mt('Range').'</th>'.
  518:         '<th>'.&mt('Incorrect').'</th>'.
  519:         '<th>'.&mt('Correct').'</th>'.
  520:         '<th>'.&mt('Count').'</th>'.
  521:         '</tr>'.$/;
  522:     for (my $i=0;$i<scalar(@{$bins});$i++) {
  523:         my $lownum;
  524:         if ($i == 0) {
  525:             $lownum = 0;
  526:         } else {
  527:             $lownum = $bins->[$i-1];
  528:         }
  529:         my $highnum = $bins->[$i];
  530:         $table .= 
  531:             '<tr>'.
  532:             '<td>'.$labels->[$i].'</td>'.
  533:             '<td align="right">'.$lownum.'</td>'.
  534:             '<td>&nbsp;-&nbsp;</td>'.
  535:             '<td align="right">'.$highnum.'</td>'.
  536:             '<td align="right">'.$incorrect->[$i].'</td>'.
  537:             '<td align="right">'.$correct->[$i].'</td>'.
  538:             '<td align="right">'.$count->[$i].'</td>'.
  539:             '</tr>'.$/;
  540:     }
  541:     $table.= '</table>';
  542:     return $table;
  543: }
  544: 
  545: sub numerical_determine_answers {
  546:     my ($r,$resource,$partid,$respid,$students)=@_;
  547:     my $c = $r->connection();
  548:     #
  549:     # FIX ME: May need progress dialog updates
  550:     #
  551:     # Read in the cache (if it exists) before we start timing things.
  552:     &Apache::lonstathelpers::ensure_proper_cache($resource->{'symb'});
  553:     #
  554:     my $correct;
  555:     my %answers;
  556:     foreach my $student (@$students) {
  557:         last if ($c->aborted());
  558:         my $sname = $student->{'username'};
  559:         my $sdom = $student->{'domain'};
  560:         # analyze problem
  561:         my $analysis = 
  562:             &Apache::lonstathelpers::analyze_problem_as_student($resource,
  563:                                                                 $sname,
  564:                                                                 $sdom);
  565:         # make the key
  566:         my $key = $partid.'.'.$respid;
  567:         $correct->{$sname.':'.$sdom}->{'answer'} = 
  568:             $analysis->{$key.'.answer'}->[0];
  569:         $correct->{$sname.':'.$sdom}->{'unit'} = 
  570:             $analysis->{$key.'.unit'}->[0];
  571:         $answers{$analysis->{$key.'.answer'}->[0]}++;
  572:     }
  573:     &Apache::lonstathelpers::write_analysis_cache();
  574:     return ($correct,\%answers);
  575: }
  576: 
  577: #
  578: # Inputs: $r, $width, $height, $data
  579: #         $n = number of students
  580: #         $data = hashref of $answer => $frequency pairs
  581: sub numerical_one_dimensional_plot {
  582:     my ($r,$width,$height,$data)=@_;
  583:     #
  584:     # Compute data -> image scaling factors
  585:     my $max_y = 0;
  586:     my $min_x = undef;
  587:     my $max_x = undef;
  588:     my $n = 0;
  589:     while (my ($answer,$count) = each(%$data)) {
  590:         $n+=$count;
  591:         $max_y = $count if ($max_y < $count);
  592:         if (! defined($min_x) || $answer < $min_x) {
  593:             $min_x = $answer;
  594:         }
  595:         if (! defined($max_x) || $answer > $max_x) {
  596:             $max_x = $answer;
  597:         }
  598:     }
  599:     #
  600:     my $min_max_difference = $max_x - $min_x;
  601:     if (! defined($min_max_difference) || $min_max_difference == 0) {
  602:         $min_max_difference = 1;
  603:     }
  604:     my $h_scale = ($width-10)/$min_max_difference;
  605:     #
  606:     my $ticscale = 5;
  607:     if ($max_y * $ticscale > $height/2) {
  608:         $ticscale = int($height/2/$max_y);
  609:         $ticscale = 1 if ($ticscale < 1);
  610:     }
  611:     #
  612:     # Create the plot
  613:     my $plot = 
  614:         qq{<drawimage width="$width" height="$height" bgcolor="transparent" >};
  615:     while (my ($answer,$count) = each(%$data)) {
  616:         my $xloc = 5+$h_scale*($answer - $min_x);
  617:         my $top    = $height/2-$count*$ticscale;
  618:         my $bottom = $height/2+$count*$ticscale;
  619:         $plot .= &line($xloc,$top,$xloc,$bottom,'888888',1);
  620:     }
  621:     #
  622:     # Put the scale on last to ensure it is on top of the data.
  623:     if ($min_x < 0 && $max_x > 0) {
  624:         my $circle_x = 5+$h_scale*abs($min_x);  # '0' in data coordinates
  625:         my $r = 4;
  626:         $plot .= &line(5,$height/2,$circle_x-$r,$height/2,'000000',1);
  627:         $plot .= &circle($circle_x,$height/2,$r+1,'000000');
  628:         $plot .= &line($circle_x+$r,$height/2,$width-5,$height/2,'000000',1);
  629:     } else {
  630:         $plot .= &line(5,$height/2,$width-5,$height/2,'000000',1);
  631:     }
  632:     $plot .= '</drawimage>';
  633:     my $plotresult =  &Apache::lonxml::xmlparse($r,'web',$plot);
  634:     my $result = '<table>'.
  635:         '<tr><td colspan="3" align="center">'.
  636:         '<font size="+2">'.&mt('Distribution of correct answers').'</font>'.
  637:         '<br />'.&mt('[_1] students, [_2] distinct correct answers',
  638:                      $n,scalar(keys(%$data))).
  639:         '<br />'.&mt('Maximum number of coinciding values: [_1]',$max_y).
  640:         '</td></tr>'.
  641:         '<tr>'.
  642:         '<td valign="center">'.$min_x.'</td>'.
  643:         '<td>'.$plotresult.'</td>'.
  644:         '<td valign="center">'.$max_x.'</td>'.
  645:         '</tr>'.
  646:         '</table>';
  647:     return $result;
  648: }
  649: 
  650: ##
  651: ## Helper subroutines for <drawimage>.  
  652: ## These should probably go somewhere more suitable soon.
  653: sub line {
  654:     my ($x1,$y1,$x2,$y2,$color,$thickness) = @_;
  655:     return qq{<line x1="$x1" y1="$y1" x2="$x2" y2="$y2" color="$color" thickness="$thickness" />};
  656: }
  657: 
  658: sub text {
  659:     my ($x,$y,$color,$text,$font,$direction) = @_;
  660:     if (! defined($font) || $font !~ /^(tiny|small|medium|large|giant)$/) {
  661:         $font = 'medium';
  662:     }
  663:     if (! defined($direction) || $direction ne 'vertical') {
  664:         $direction = '';
  665:     }
  666:     return qq{<text x="$x" y="$y" color="$color" font="$font" direction="$direction" >$text</text>};
  667: }
  668: 
  669: sub rectangle {
  670:     my ($x1,$y1,$x2,$y2,$color,$thickness,$filled) = @_;
  671:     return qq{<rectangle x1="$x1" y1="$y1" x2="$x2" y2="$y2" color="$color" thickness="$thickness" filled="$filled" />};
  672: }
  673: 
  674: sub arc {
  675:     my ($x,$y,$width,$height,$start,$end,$color,$thickness,$filled)=@_;
  676:     return qq{<arc x="$x" y="$y" width="$width" height="$height" start="$start" end="$end" color="$color" thickness="$thickness" filled="$filled" />};
  677: }
  678: 
  679: sub circle {
  680:     my ($x,$y,$radius,$color,$thickness,$filled)=@_;
  681:     return &arc($x,$y,$radius,$radius,0,360,$color,$thickness,$filled);
  682: }
  683: 
  684: #########################################################
  685: #########################################################
  686: ##
  687: ##      Radio Response Routines
  688: ##
  689: #########################################################
  690: #########################################################
  691: sub radio_response_analysis {
  692:     my ($r,$problem,$problem_analysis,$students) = @_;
  693:     #
  694:     if ($ENV{'form.AnalyzeOver'} !~ /^(tries|time)$/) {
  695:         $r->print('Bad request');
  696:     }
  697:     #
  698:     my ($resource,$partid,$respid) = ($problem->{'resource'},
  699:                                       $problem->{'part'},
  700:                                       $problem->{'respid'});
  701:     #
  702:     my $analysis_html;
  703:     my $foildata = $problem_analysis->{'_Foils'};
  704:     my ($table,$foils,$concepts) = &build_foil_index($problem_analysis);
  705:     if (! defined($concepts)) {
  706:         $concepts = [];
  707:     }
  708:     #
  709:     my %true_foils;
  710:     my $num_true = 0;
  711:     if (! $problem_analysis->{'answercomputed'}) {
  712:         foreach my $foil (@$foils) {
  713:             if ($foildata->{$foil}->{'value'} eq 'true') {
  714:                 $true_foils{$foil}++; 
  715:             }
  716:         }
  717:         $num_true = scalar(keys(%true_foils));
  718:     }
  719:     #
  720:     $analysis_html .= $table;
  721:     # Gather student data
  722:     my $response_data = &Apache::loncoursedata::get_response_data
  723:         (\@Apache::lonstatistics::SelectedSections,
  724:          $Apache::lonstatistics::enrollment_status,
  725:          $resource->{'symb'},$respid);
  726:     my $correct;   # either a hash reference or a scalar
  727:     if ($problem_analysis->{'answercomputed'} || scalar(@$concepts) > 1) {
  728:         # This takes a while for large classes...
  729:         &Apache::lonstathelpers::GetStudentAnswers($r,$problem,$students,
  730:                                                    'Statistics',
  731:                                                    'stats_status');
  732:         foreach my $student (@$students) {
  733:             my ($idx,@remainder) = split('&',$student->{'answer'});
  734:             my ($answer) = ($remainder[$idx]=~/^(.*)=([^=]*)$/);
  735:             $correct->{$student->{'username'}.':'.$student->{'domain'}}=
  736:                 &Apache::lonnet::unescape($answer);
  737:         }
  738:     } else {
  739:         foreach my $foil (keys(%$foildata)) {
  740:             if ($foildata->{$foil}->{'value'} eq 'true') {
  741:                 $correct = $foildata->{$foil}->{'name'};
  742:             }
  743:         }
  744:     }
  745:     #
  746:     if (! defined($response_data) || ref($response_data) ne 'ARRAY' ) {
  747:         $analysis_html = '<h2>'.
  748:             &mt('There is no submission data for this resource').
  749:             '</h2>';
  750:         $r->print($analysis_html);
  751:         return;
  752:     }
  753:     #
  754:     $analysis_html.='<table>';
  755:     for (my $plot_num = 1;$plot_num<=$ENV{'form.NumPlots'};$plot_num++) {
  756:         # classify data ->correct foil -> selected foil
  757:         my ($restriction_function,
  758:             $correct_foil_title,$incorrect_foil_title,
  759:             $pre_graph_text,$post_graph_text,
  760:             $no_data_text,@extra_data);
  761:         if ($ENV{'form.AnalyzeOver'} eq 'tries') {
  762:             $restriction_function = sub {($_[0]->{'tries'} == $plot_num?1:0)};
  763:             $correct_foil_title = 'Attempt '.$plot_num;
  764:             $incorrect_foil_title = 'Attempt '.$plot_num;
  765:             $pre_graph_text = 
  766:                 'Attempt [_1], [_2] submissions, [_3] correct, [_4] incorrect';
  767:             $post_graph_text = '';
  768:             $no_data_text = 'No data exists for attempt [_1]';
  769:         } elsif ($ENV{'form.AnalyzeOver'} eq 'time') {
  770:             my $starttime = &Apache::lonhtmlcommon::get_date_from_form
  771:                 ('startdate_'.$plot_num);
  772:             my $endtime = &Apache::lonhtmlcommon::get_date_from_form
  773:                 ('enddate_'.$plot_num);
  774:             ($starttime,$endtime) = &ensure_start_end_times
  775:                 ($starttime,$endtime,
  776:                  &get_time_from_row($response_data->[0]),
  777:                  &get_time_from_row($response_data->[-1]),
  778:                  $plot_num);
  779:             $pre_graph_text = 
  780:                 'Data from [_6] to [_7]<br /> [_2] submissions from [_5] students, [_3] correct, [_4] incorrect';
  781:             $extra_data[0] = &Apache::lonlocal::locallocaltime($starttime);
  782:             $extra_data[1] = &Apache::lonlocal::locallocaltime($endtime);
  783:             #
  784:             $post_graph_text = 
  785:                 &mt('Start time: [_1]',
  786:                     &Apache::lonhtmlcommon::date_setter
  787:                     ('Statistics','startdate_'.$plot_num,$starttime)).
  788:                 '<br />'.
  789:                 &mt('End time: [_1]',
  790:                     &Apache::lonhtmlcommon::date_setter
  791:                     ('Statistics','enddate_'.$plot_num,$endtime));
  792:             $restriction_function = 
  793:                 sub { 
  794:                     my $t = $_[0]->{'timestamp'};
  795:                     if ($t >= $starttime && $t < $endtime) {
  796:                         return 1;
  797:                     } else { 
  798:                         return 0;
  799:                     }
  800:                 };
  801:             $no_data_text = 'No data for [_5] to [_6]';
  802:         }
  803:         my $foil_choice_data =
  804:             &classify_response_data($response_data,$correct,
  805:                                     $restriction_function);
  806:         # &Apache::lonstathelpers::log_hash_ref($foil_choice_data);
  807:         my $answers;
  808:         if (ref($correct)) {
  809:             my %tmp;
  810:             foreach my $foil (values(%$correct)) {
  811:                 $tmp{$foil}++;
  812:             }
  813:             $answers = [keys(%tmp)];
  814:         } else {
  815:             $answers = [$correct];
  816:         }
  817:         # Concept Plot
  818:         my $concept_plot = '';
  819:         if (scalar(@$concepts) > 1) {
  820:             $concept_plot = &RR_concept_plot($concepts,$foil_choice_data,
  821:                                              'Correct Concepts');
  822:         }
  823:         # % Choosing plot
  824:         my $choice_plot = &RR_create_percent_selected_plot
  825:             ($concepts,$foils,$foil_choice_data,$correct_foil_title);
  826:         # for each correct foil, how did they mark it? (stacked bar graph)
  827:         my ($stacked_plot,$count_by_foil);
  828:         if ($problem_analysis->{'answercomputed'} || $num_true > 1) {
  829:             ($stacked_plot,$count_by_foil) =
  830:                 &RR_create_stacked_selection_plot($foils,$foil_choice_data,
  831:                                                   $incorrect_foil_title,
  832:                                                   \%true_foils);
  833:         }
  834:         #
  835:         if ($concept_plot ne '' ||
  836:             $choice_plot  ne '' ||
  837:             $stacked_plot ne '') {
  838:             my $correct = $foil_choice_data->{'_correct'};
  839:             if (! defined($correct) || $correct eq '') {
  840:                 $correct = 0;
  841:             }
  842:             my $incorrect = 
  843:             $analysis_html.= '<tr><td colspan="4" align="center">'.
  844:                 '<font size="+1">'.
  845:                 &mt($pre_graph_text,
  846:                     $plot_num,$foil_choice_data->{'_count'},
  847:                     $correct,
  848:                     $foil_choice_data->{'_count'}-$correct,
  849:                     $foil_choice_data->{'_students'},
  850:                     @extra_data).
  851:                     '</td></tr>'.$/;
  852:             $analysis_html.=
  853:                 '<tr>'.
  854:                 '<td>'.$concept_plot.'</td>'.
  855:                 '<td>'.$choice_plot.'</td>';
  856:             if ($stacked_plot ne '') {
  857:                 $analysis_html .= 
  858:                     '<td>'.$stacked_plot.'</td>'.
  859:                     '<td>'.&build_foil_key($foils,$count_by_foil).'</td>';
  860:             } else {
  861:                 $analysis_html .= ('<td></td>'x2);
  862:             }
  863:             $analysis_html.='</tr>'.$/;
  864:             if (defined($post_graph_text)) {
  865:                 $analysis_html.= '<tr><td colspan="4" align="center">'.
  866:                     $post_graph_text.'</td></tr>'.$/;
  867:             }
  868:         } elsif ($no_data_text ne '') {
  869:             $analysis_html.='<tr><td colspan="4" align="center">'.
  870:                 &mt($no_data_text,
  871:                     $plot_num,$foil_choice_data->{'_count'},
  872:                     $correct,                    
  873:                     $foil_choice_data->{'_count'}-$correct,
  874:                     @extra_data);
  875:             if (defined($post_graph_text)) {
  876:                 $analysis_html.='<br />'.$post_graph_text;
  877:             }
  878:             $analysis_html.='</td></tr>'.$/;
  879:         }
  880:     } # end of loop for plots
  881:     $analysis_html.='</table>';
  882:     $r->print($analysis_html);
  883: }
  884: 
  885: sub ensure_start_end_times {
  886:     my ($start,$end,$first,$last,$plot_num) = @_;
  887:     if (! defined($start) || ! defined($end)) {
  888:         my $sec_in_day = 86400;
  889:         my ($sday,$smon,$syear) = 
  890:             (localtime($last - $sec_in_day*($plot_num-1)))[3..5];
  891:         $start = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear);
  892:         $end   = $start + $sec_in_day;
  893:         if ($plot_num == $ENV{'form.NumPlots'}) {
  894:             $start = $first;
  895:         }
  896:     }
  897:     return ($start,$end);
  898: }
  899: 
  900: sub RR_concept_plot {
  901:     my ($concepts,$foil_data,$title) = @_;
  902:     #
  903:     my %correct_by_concept;
  904:     my %incorrect_by_concept;
  905:     my %true;
  906:     foreach my $concept (@$concepts) {
  907:         foreach my $foil (@{$concept->{'foils'}}) {
  908:             next if (! exists($foil_data->{$foil}));
  909:             foreach my $choice (keys(%{$foil_data->{$foil}})) {
  910:                 if ($choice eq $foil) {
  911:                     $correct_by_concept{$concept->{'name'}} +=
  912:                         $foil_data->{$foil}->{$choice};
  913:                 } else {
  914:                     $incorrect_by_concept{$concept->{'name'}} +=
  915:                         $foil_data->{$foil}->{$choice};
  916:                     
  917:                 }
  918:             }
  919:         }
  920:     }
  921:     # 
  922:     # need arrays for incorrect and correct because we want to use different
  923:     # colors for them
  924:     my @correct;
  925:     #
  926:     my $total =0;
  927:     for (my $i=0;$i<scalar(@$concepts);$i++) {
  928:         my $concept = $concepts->[$i];
  929:         $correct[$i]   =   $correct_by_concept{$concept->{'name'}};
  930:         $total += $correct_by_concept{$concept->{'name'}}+
  931:             $incorrect_by_concept{$concept->{'name'}};
  932:     }
  933:     if ($total == 0) { return ''; };
  934:     for (my $i=0;$i<=$#correct;$i++) { 
  935:         $correct[$i] = sprintf('%0f',$correct[$i]/$total*100);
  936:     }
  937:     my $xlabel = 'concept';
  938:     my $plot=  &Apache::loncommon::DrawBarGraph($title,
  939:                                                 $xlabel,
  940:                                                 'Percent Choosing',
  941:                                                 100,
  942:                                                 ['#33ff00','#ff3300'],
  943:                                                 undef,
  944:                                                 \@correct);
  945:     return $plot;
  946: }
  947: 
  948: sub RR_create_percent_selected_plot {
  949:     my ($concepts,$foils,$foil_data,$title) = @_;
  950:     #
  951:     if ($foil_data->{'_count'} == 0) { return ''; };
  952:     my %correct_selections;
  953:     my %incorrect_selections;
  954:     foreach my $foil (@$foils) {
  955:         # foil_data has format $foil_data->{true_foil}->{selected foil}=count
  956:         next if (! exists($foil_data->{$foil}));
  957:         while (my ($f,$count)= each(%{$foil_data->{$foil}})) {
  958:             if ($f eq $foil) {
  959:                 $correct_selections{$foil} += $count;
  960:             } else {
  961:                 $incorrect_selections{$f} += $count;
  962:             }
  963:         }
  964:     }
  965:     # 
  966:     # need arrays for incorrect and correct because we want to use different
  967:     # colors for them
  968:     my @correct;
  969:     my @incorrect;
  970:     #
  971:     my $total = $foil_data->{'_count'};
  972:     for (my $i=0;$i<scalar(@$foils);$i++) {
  973:         my $foil = $foils->[$i];
  974:         $correct[$i]   = $correct_selections{$foil};
  975:         $incorrect[$i] = $incorrect_selections{$foil};
  976:     }
  977:     for (my $i=0;$i<=$#correct;$i++) { 
  978:         $correct[$i] = sprintf('%2f',$correct[$i]/$total*100);
  979:     }
  980:     for (my $i=0;$i<=$#incorrect;$i++) {
  981:         $incorrect[$i] = sprintf('%2f',$incorrect[$i]/$total*100);
  982:     }
  983:     #
  984:     # Put a blank in the data sets between concepts, if there are concepts
  985:     my @labels;
  986:     if (defined($concepts) && scalar(@$concepts) > 1) {
  987:         my @new_correct;
  988:         my @new_incorrect;
  989:         my $foil_count = 0;
  990:         foreach my $concept (@$concepts) {
  991:             foreach (@{$concept->{'foils'}}) {
  992:                 push(@new_correct,  $correct[$foil_count]);
  993:                 push(@new_incorrect,$incorrect[$foil_count]);
  994:                 push(@labels,++$foil_count);
  995:             }
  996:             push(@new_correct,'');
  997:             push(@new_incorrect,'');
  998:             push(@labels,'');
  999:         }
 1000:         @correct = @new_correct;
 1001:         @incorrect = @new_incorrect;
 1002:     } else {
 1003:         @labels = (1 .. scalar(@correct));
 1004:     }
 1005:     #
 1006:     my $xlabel = 'foil chosen';
 1007:     my $plot=  &Apache::loncommon::DrawBarGraph($title,
 1008:                                                 $xlabel,
 1009:                                                 'Percent Choosing',
 1010:                                                 100,
 1011:                                                 ['#33ff00','#ff3300'],
 1012:                                                 \@labels,
 1013:                                                 \@correct,
 1014:                                                 \@incorrect);
 1015:     return $plot;
 1016: }
 1017: 
 1018: sub RR_create_stacked_selection_plot {
 1019:     my ($foils,$foil_data,$title,$true_foils)=@_;
 1020:     #
 1021:     my @dataset; # array of array refs - multicolor rows $datasets[row]->[col]
 1022:     my @labels;
 1023:     my $count;
 1024:     my %column; # maps foil name to column in @datasets
 1025:     for (my $i=0;$i<scalar(@$foils);$i++) {
 1026:         my $foil = $foils->[$i];
 1027:         if (defined($true_foils) && scalar(keys(%$true_foils)) > 0 ) {
 1028:             next if (! $true_foils->{$foil} );
 1029:             push(@labels,$i+1);
 1030:         } else {
 1031:             next if (! exists($foil_data->{$foil}));
 1032:             push(@labels,$i+1);
 1033:         }
 1034:         next if (! exists($foil_data->{$foils->[$i]}));
 1035:         $column{$foil}= $count++;
 1036:         for (my $j=0;$j<scalar(@$foils);$j++) {
 1037:             my $value = 0;
 1038:             if ($i != $j ) {
 1039:                 $value += $foil_data->{$foil}->{$foils->[$j]};
 1040:             }
 1041:             $dataset[$j]->[$column{$foil}]=$value;
 1042:         }
 1043:     }
 1044:     #
 1045:     return '' if (! scalar(keys(%column)));
 1046:     #
 1047:     my $grand_total = 0;
 1048:     my %count_per_foil;
 1049:     while (my ($foil,$bar) = each (%column)) {
 1050:         my $bar_total = 0;
 1051:         for (my $j=0;$j<scalar(@dataset);$j++) {
 1052:             $bar_total += $dataset[$j]->[$bar];
 1053:         }
 1054:         next if ($bar_total == 0);
 1055:         for (my $j=0;$j<scalar(@dataset);$j++) {
 1056:             $dataset[$j]->[$bar] = 
 1057:                 sprintf('%2f',$dataset[$j]->[$bar]/$bar_total * 100);
 1058:         }
 1059:         $count_per_foil{$foil}=' ( '.$bar_total.' )';
 1060:         $grand_total += $bar_total;
 1061:     }
 1062:     if ($grand_total == 0) {
 1063:         return ('',undef);
 1064:     }
 1065:     my @empty_row = ();
 1066:     foreach (@{$dataset[0]}) {
 1067:         push(@empty_row,0);
 1068:     }
 1069:     #
 1070:     my $graph = &Apache::loncommon::DrawBarGraph
 1071:         ($title,'Correct Foil','foils chosen Incorrectly',
 1072:          100,$plotcolors,\@labels,\@empty_row,@dataset);
 1073:     return ($graph,\%count_per_foil);
 1074: }
 1075: 
 1076: 
 1077: #########################################################
 1078: #########################################################
 1079: ##
 1080: ##       Misc routines
 1081: ##
 1082: #########################################################
 1083: #########################################################
 1084: 
 1085: # if $correct is a hash ref, it is assumed to be indexed by student names.
 1086: #    the values are assumed to be hash refs with a key of 'answer'.
 1087: sub classify_response_data {
 1088:     my ($full_row_data,$correct,$function) = @_;
 1089:     my %submission_data;
 1090:     my %students;
 1091:     my $max=0;
 1092:     foreach my $row (@$full_row_data) {
 1093:         my %subm = &hashify_attempt($row);
 1094:         if (ref($correct) eq 'HASH') {
 1095:             $subm{'correct'} = $correct->{$subm{'student'}};
 1096:         } else {
 1097:             $subm{'correct'} = $correct;
 1098:         }
 1099:         $subm{'submission'} =~ s/=\d+\s*$//;
 1100:         if (&$function(\%subm)) {
 1101:             $students{$subm{'student'}}++;
 1102:             $submission_data{'_count'}++;
 1103:             if (&submission_is_correct($subm{'award'})) { 
 1104:                 $submission_data{'_correct'}++;
 1105:             }
 1106:             
 1107:             if($max<++$submission_data{$subm{'correct'}}->{$subm{'submission'}}) {
 1108:                 $max=$submission_data{$subm{'correct'}}->{$subm{'submission'}};
 1109:             }
 1110:         }
 1111:     }
 1112:     $submission_data{'_max'} = $max;
 1113:     $submission_data{'_students'}=scalar(keys(%students));
 1114:     return \%submission_data;
 1115: }
 1116: 
 1117: 
 1118: #########################################################
 1119: #########################################################
 1120: ##
 1121: ##      Option Response Routines
 1122: ##
 1123: #########################################################
 1124: #########################################################
 1125: sub OptionResponseAnalysis {
 1126:     my ($r,$problem,$problem_data,$Students) = @_;
 1127:     my ($resource,$respid) = ($problem->{'resource'},
 1128:                               $problem->{'respid'});
 1129:     # Note: part data is not needed.
 1130:     my $PerformanceData = &Apache::loncoursedata::get_response_data
 1131:         (\@Apache::lonstatistics::SelectedSections,
 1132:          $Apache::lonstatistics::enrollment_status,
 1133:          $resource->{'symb'},$respid);
 1134:     if (! defined($PerformanceData) || 
 1135:         ref($PerformanceData) ne 'ARRAY' ) {
 1136:         $r->print('<h2>'.
 1137:                   &mt('There is no student data for this problem.').
 1138:                   '</h2>');
 1139:     }  else {
 1140:         $r->rflush();
 1141:         if (exists($ENV{'form.ExcelOutput'})) {
 1142:             my $result = &OR_excel_sheet($r,$resource,
 1143:                                          $PerformanceData,
 1144:                                          $problem_data);
 1145:             $r->print($result);
 1146:             $r->rflush();
 1147:         } else {
 1148:             if ($ENV{'form.AnalyzeOver'} eq 'tries') {
 1149:                 my $analysis_html = &OR_tries_analysis($r,
 1150:                                                     $PerformanceData,
 1151:                                                     $problem_data);
 1152:                 $r->print($analysis_html);
 1153:                 $r->rflush();
 1154:             } elsif ($ENV{'form.AnalyzeOver'} eq 'time') {
 1155:                 my $analysis_html = &OR_time_analysis($PerformanceData,
 1156:                                                    $problem_data);
 1157:                 $r->print($analysis_html);
 1158:                 $r->rflush();
 1159:             } else {
 1160:                 $r->print('<h2>'.
 1161:                           &mt('The analysis you have selected is '.
 1162:                               'not supported at this time').
 1163:                           '</h2>');
 1164:             }
 1165:         }
 1166:     }
 1167: }
 1168: 
 1169: #########################################################
 1170: #
 1171: #       Option Response:  tries Analysis
 1172: #
 1173: #########################################################
 1174: sub OR_tries_analysis {
 1175:     my ($r,$PerformanceData,$ORdata) = @_;
 1176:     my $mintries = 1;
 1177:     my $maxtries = $ENV{'form.NumPlots'};
 1178:     my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
 1179:     if (! defined($Concepts)) {
 1180:         $Concepts = [];
 1181:     }
 1182:     my %response_data = &OR_analyze_by_tries($r,$PerformanceData,
 1183:                                                      $mintries,$maxtries);
 1184:     my $analysis = '';
 1185:     #
 1186:     # Compute the data necessary to make the plots
 1187:     my @foil_plot; 
 1188:     my @concept_data;
 1189:     for (my $j=0;$j<=scalar(@$Concepts);$j++) {
 1190:         my $concept = $Concepts->[$j];
 1191:         foreach my $foilid (@{$concept->{'foils'}}) {
 1192:             for (my $try=$mintries;$try<=$maxtries;$try++) {
 1193:                 # concept analysis data
 1194:                 $concept_data[$j]->[$try]->{'_correct'} +=
 1195:                     $response_data{$foilid}->[$try]->{'_correct'};
 1196:                 $concept_data[$j]->[$try]->{'_total'} +=
 1197:                     $response_data{$foilid}->[$try]->{'_total'};
 1198:                 #
 1199:                 # foil analysis data
 1200:                 if ($response_data{$foilid}->[$try]->{'_total'} == 0) {
 1201:                     push(@{$foil_plot[$try]->{'_correct'}},0);
 1202:                 } else {
 1203:                     push(@{$foil_plot[$try]->{'_correct'}},
 1204:                          100*$response_data{$foilid}->[$try]->{'_correct'}/
 1205:                          $response_data{$foilid}->[$try]->{'_total'});
 1206:                 }
 1207:                 foreach my $option (@{$ORdata->{'_Options'}}) {
 1208:                     push(@{$foil_plot[$try]->{'_total'}},
 1209:                          $response_data{$foilid}->[$try]->{'_total'});
 1210:                     if ($response_data{$foilid}->[$try]->{'_total'} == 0) {
 1211:                         push (@{$foil_plot[$try]->{$option}},0);
 1212:                     } else {
 1213:                         if ($response_data{$foilid}->[$try]->{'_total'} ==
 1214:                             $response_data{$foilid}->[$try]->{'_correct'}) {
 1215:                             push(@{$foil_plot[$try]->{$option}},0);
 1216:                         } else {
 1217:                             push (@{$foil_plot[$try]->{$option}},
 1218:                                   100 * 
 1219:                                   $response_data{$foilid}->[$try]->{$option} / 
 1220:                                   ($response_data{$foilid}->[$try]->{'_total'} 
 1221:                                    - 
 1222:                                    $response_data{$foilid}->[$try]->{'_correct'}
 1223:                                    ));
 1224:                         }
 1225:                     }
 1226:                 } # End of foreach my $option
 1227:             }
 1228:         } # End of foreach my $foilid
 1229:     } # End of concept loops
 1230:     # 
 1231:     # Build a table for the plots
 1232:     my $analysis_html = "<br /><table>\n";
 1233:     my $optionkey = &build_option_index($ORdata);
 1234:     my $num_concepts = 1;
 1235:     if (defined($Concepts)) { $num_concepts = scalar(@$Concepts); }
 1236:     #
 1237:     for (my $try=$mintries;$try<=$maxtries;$try++) {
 1238:         if (! defined($response_data{'_total'}->[$try]) ||
 1239:             $response_data{'_total'}->[$try] == 0) { 
 1240:             if ($try > 1) {
 1241:                 $analysis_html.= '<tr><td align="center" colspan="4"><b>'.
 1242:                     &mt('None of the selected students attempted the problem more than [_1] times.',$try-1).
 1243:                     '</b></td></tr>';
 1244:             } else {
 1245:                 $analysis_html.= '<tr><td colspan="4" align="center"><b>'.
 1246:                     &mt('None of the selected students have attempted the problem').'</b></td></tr>';
 1247:             }
 1248:             last;
 1249:         }
 1250:         my $concept_graph='';
 1251:         if ($num_concepts > 1) {
 1252:             #
 1253:             # Create concept plot
 1254:             my @concept_plot_data;
 1255:             for (my $j=0;$j<=$#concept_data;$j++) {
 1256:                 my $total = $concept_data[$j]->[$try]->{'_total'};
 1257:                 if ($total == 0) {
 1258:                     $concept_plot_data[$j] = 0;
 1259:                 } else {
 1260:                     $concept_plot_data[$j] = 100 * 
 1261:                         sprintf('%0.3f',
 1262:                                 $concept_data[$j]->[$try]->{'_correct'} / 
 1263:                                 $total);
 1264:                 }
 1265:             }
 1266:             #
 1267:             $concept_graph = &Apache::loncommon::DrawBarGraph
 1268:                 ('Correct Concepts','Concept Number','Percent Correct',
 1269:                  100,$plotcolors,undef,\@concept_plot_data,{xskip=>1});
 1270:         }
 1271:         #
 1272:         # Create Foil Plots
 1273:         my $data_count = $response_data{'_total'}->[$try];
 1274:         my $correct = $response_data{'_correct'}->[$try];
 1275:         my @Datasets;
 1276:         foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {
 1277:             next if (! exists($foil_plot[$try]->{$option}));
 1278:             push(@Datasets,$foil_plot[$try]->{$option});
 1279:         }
 1280:         #
 1281:         # Put a blank in the data set between concepts
 1282:         for (my $set =0;$set<=$#Datasets;$set++) {
 1283:             my @Data = @{$Datasets[$set]};
 1284:             my $idx = 0;
 1285:             foreach my $concept (@{$Concepts}) {
 1286:                 foreach my $foilid (@{$concept->{'foils'}}) {
 1287:                     $Datasets[$set]->[$idx++]=shift(@Data);
 1288:                 }
 1289:                 if ($concept->{'name'} ne $Concepts->[-1]->{'name'}) {
 1290:                     $Datasets[$set]->[$idx++] = 0;
 1291:                 }
 1292:             }
 1293:         }
 1294:         #
 1295:         # Set up the labels needed for the bar graph
 1296:         my @Labels;
 1297:         my $idx = 1;
 1298:         foreach my $concept (@{$Concepts}) {
 1299:             foreach my $foilid (@{$concept->{'foils'}}) {
 1300:                 push(@Labels,$idx++);
 1301:             }
 1302:             push(@Labels,'');
 1303:         }
 1304:         #
 1305:         my $correct_graph = &Apache::loncommon::DrawBarGraph
 1306:             ('Correct Statements','Statement','% Answered Correct',
 1307:              100,$plotcolors,\@Labels,$Datasets[0],{xskip=>1});
 1308:         
 1309:         #
 1310:         #
 1311:         next if (! defined($Datasets[0]));
 1312:         for (my $i=0; $i< scalar(@{$Datasets[0]});$i++) {
 1313:             $Datasets[0]->[$i]=0;
 1314:         }
 1315:         my $count = $response_data{'_total'}->[$try] - 
 1316:                                            $response_data{'_correct'}->[$try];
 1317:         my $incorrect_graph = &Apache::loncommon::DrawBarGraph
 1318:             ('Incorrect Statements','Statement','% Chosen Incorrectly',
 1319:              100,$plotcolors,\@Labels,@Datasets,{xskip=>1});
 1320:         $analysis_html.= 
 1321:             '<tr><td colspan="4" align="center">'.
 1322:             '<font size="+1">'.
 1323:             &mt('Attempt [_1], [_2] submissions, [_3] correct, [_4] incorrect',
 1324:                 $try,$data_count,$correct,$data_count-$correct).
 1325:             '</font>'.'</td></tr>'.$/.                
 1326:             '<tr>'.
 1327:             '<td>'.$concept_graph.'</td>'.
 1328:             '<td>'.$correct_graph.'</td>'.
 1329:             '<td>'.$incorrect_graph.'</td>'.
 1330:             '<td>'.$optionkey.'<td>'.
 1331:             '</tr>'.$/;
 1332:     }
 1333:     $analysis_html .= "</table>\n";
 1334:     $table .= $analysis_html;
 1335:     return $table;
 1336: }
 1337: 
 1338: sub OR_analyze_by_tries {
 1339:     my ($r,$PerformanceData,$mintries,$maxtries) = @_;
 1340:     my %Trydata;
 1341:     $mintries = 1         if (! defined($mintries) || $mintries < 1);
 1342:     $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
 1343:     my @students;
 1344:     foreach my $row (@$PerformanceData) {
 1345:         next if (! defined($row));
 1346:         my $tries = &get_tries_from_row($row);
 1347:         my %Row   = &Process_OR_Row($row);
 1348:         next if (! %Row);
 1349:         my $student_id = $row->[&Apache::loncoursedata::RD_student_id()];
 1350:         $students[$tries]->{$student_id}++;
 1351:         while (my ($foilid,$href) = each(%Row)) {
 1352:             if (! ref($href)) { 
 1353:                 $Trydata{$foilid}->[$tries] += $href;
 1354:                 next;
 1355:             }
 1356:             while (my ($option,$value) = each(%$href)) {
 1357:                 $Trydata{$foilid}->[$tries]->{$option}+=$value;
 1358:             }
 1359:         }
 1360:     }
 1361:     for (my $try=$mintries;$try<=$maxtries;$try++) {
 1362:         $Trydata{'_studentcount'}->[$try] = scalar(keys(%{$students[$try]}));
 1363:     }
 1364:     return %Trydata;
 1365: }
 1366: 
 1367: #########################################################
 1368: #
 1369: #     Option Response: Time Analysis
 1370: #
 1371: #########################################################
 1372: sub OR_time_analysis {
 1373:     my ($performance_data,$ORdata) = @_;
 1374:     my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
 1375:     my $foilkey = &build_option_index($ORdata);
 1376:     my $num_concepts = 1;
 1377:     if (defined($Concepts)) { $num_concepts = scalar(@$Concepts); }
 1378:     #
 1379:     if ($num_concepts < 2) {
 1380:         $table = '<h3>'.
 1381:             &mt('Not enough data for concept analysis.  '.
 1382:                 'Performing Foil Analysis').
 1383:                 '</h3>'.$table;
 1384:     }
 1385:     #
 1386:     my $num_plots = $ENV{'form.NumPlots'};
 1387:     my $num_data = scalar(@$performance_data)-1;
 1388:     #
 1389:     my $current_index;
 1390:     $table .= "<table>\n";
 1391:     for (my $i=0;$i<$num_plots;$i++) {
 1392:         ##
 1393:         my $starttime = &Apache::lonhtmlcommon::get_date_from_form
 1394:             ('startdate_'.$i);
 1395:         my $endtime = &Apache::lonhtmlcommon::get_date_from_form
 1396:             ('enddate_'.$i);
 1397:         if (! defined($starttime) || ! defined($endtime)) {
 1398:             my $sec_in_day = 86400;
 1399:             my $last_sub_time = &get_time_from_row($performance_data->[-1]);
 1400:             my ($sday,$smon,$syear) = 
 1401:                 (localtime($last_sub_time - $sec_in_day*$i))[3..5];
 1402:             $starttime = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear);
 1403:             $endtime = $starttime + $sec_in_day;
 1404:             if ($i == ($num_plots -1 )) {
 1405:                 $starttime = &get_time_from_row($performance_data->[0]);
 1406:             }
 1407:         }
 1408:         $table .= '<tr><td colspan="4" align="center"><font size="+1">'.
 1409:             &mt('Data from [_1] to [_2]',
 1410:                 &Apache::lonlocal::locallocaltime($starttime),
 1411:                 &Apache::lonlocal::locallocaltime($endtime)).
 1412:                 '</font></td></tr>'.$/;
 1413:         my $startdateform = &Apache::lonhtmlcommon::date_setter
 1414:             ('Statistics','startdate_'.$i,$starttime);
 1415:         my $enddateform = &Apache::lonhtmlcommon::date_setter
 1416:             ('Statistics','enddate_'.$i,$endtime);
 1417:         #
 1418:         my $begin_index;
 1419:         my $end_index;
 1420:         my $j;
 1421:         while (++$j < scalar(@$performance_data)) {
 1422:             last if (&get_time_from_row($performance_data->[$j]) 
 1423:                                                               > $starttime);
 1424:         }
 1425:         $begin_index = $j;
 1426:         while ($j < scalar(@$performance_data)) {
 1427:             if (&get_time_from_row($performance_data->[$j]) > $endtime) {
 1428:                 last;
 1429:             } else {
 1430:                 $j++;
 1431:             }
 1432:         }
 1433:         $end_index = $j;
 1434:         ##
 1435:         my ($processed_time_data,$correct,$data_count,$student_count) =
 1436:             &OR_time_process_data($performance_data,$begin_index,$end_index);
 1437:         ##
 1438:         $table .= '<tr><td colspan="4" align="center"><font size="+1">'.
 1439:             &mt('[_1] submissions from [_2] students, [_3] correct, [_4] incorrect',
 1440:                 $data_count,$student_count,$correct,$data_count-$correct).
 1441:                 '</font></td></tr>'.$/;
 1442:         my $concept_correct_plot = '';
 1443:         if ($num_concepts > 1) {
 1444:             $concept_correct_plot = 
 1445:                 &OR_Concept_Time_Analysis($processed_time_data,
 1446:                                           $correct,$data_count,$student_count,
 1447:                                           $ORdata,$Concepts);
 1448:         }
 1449:         my ($foil_correct_plot,$foil_incorrect_plot) = 
 1450:             &OR_Foil_Time_Analysis($processed_time_data,
 1451:                                    $correct,$data_count,$student_count,
 1452:                                    $ORdata,$Foils,$Concepts);
 1453:         $table .= '<tr>'.
 1454:             '<td>'.$concept_correct_plot.'</td>'.
 1455:             '<td>'.$foil_correct_plot.'</td>'.
 1456:             '<td>'.$foil_incorrect_plot.'</td>'.
 1457:             '<td align="left" valign="top">'.$foilkey.'</td></tr>'.$/;
 1458:         $table .= '<tr><td colspan="4" align="center">'.
 1459:             &mt('Start time: [_1]',$startdateform).'<br />'.
 1460:             &mt('End time: [_1]',$enddateform).'</td></tr>'.$/;
 1461:         $table.= '<tr><td colspan="4">&nbsp</td></tr>'.$/;
 1462:     }
 1463:     $table .= '</table>';
 1464:     #
 1465:     return $table;
 1466: }
 1467: 
 1468: sub OR_Foil_Time_Analysis {
 1469:     my ($processed_time_data,$correct,$data_count,$student_count,
 1470:         $ORdata,$Foils,$Concepts) = @_;
 1471:     if ($data_count <= 0) {
 1472:         return ('<h2>'.&mt('There is no data to plot').'</h2>','');
 1473:     }
 1474:     my $analysis_html;
 1475:     my @plotdata;
 1476:     my @labels;
 1477:     foreach my $concept (@{$Concepts}) {
 1478:         foreach my $foil (@{$concept->{'foils'}}) {
 1479:             push(@labels,scalar(@labels)+1);
 1480:             my $total = $processed_time_data->{$foil}->{'_total'};
 1481:             if ($total == 0) {
 1482:                 push(@{$plotdata[0]},0);
 1483:             } else {
 1484:                 push(@{$plotdata[0]},
 1485:                      100 * $processed_time_data->{$foil}->{'_correct'} / $total);
 1486:             }
 1487:             my $total_incorrect = $total - $processed_time_data->{$foil}->{'_correct'};
 1488:             for (my $i=0;$i<scalar(@{$ORdata->{'_Options'}});$i++) {
 1489:                 my $option = $ORdata->{'_Options'}->[$i];
 1490:                 if ($total_incorrect == 0) {
 1491:                     push(@{$plotdata[$i+1]},0);
 1492:                 } else {
 1493:                     push(@{$plotdata[$i+1]},
 1494:                          100 * $processed_time_data->{$foil}->{$option} / $total_incorrect);
 1495:                 }
 1496:             }
 1497:         }
 1498:         # Put in a blank one
 1499:         push(@labels,'');
 1500:         push(@{$plotdata[0]},0);
 1501:         for (my $i=0;$i<scalar(@{$ORdata->{'_Options'}});$i++) {
 1502:             push(@{$plotdata[$i+1]},0);
 1503:         }
 1504:     }
 1505:     #
 1506:     # Create the plot
 1507:     my $correct_plot = &Apache::loncommon::DrawBarGraph('Correct Statements',
 1508:                                                         'Statement Number',
 1509:                                                         'Percent Correct',
 1510:                                                         100,
 1511:                                                         $plotcolors,
 1512:                                                         undef,
 1513:                                                         $plotdata[0],
 1514:                                                         {xskip=>1});
 1515:     for (my $j=0; $j< scalar(@{$plotdata[0]});$j++) {
 1516:         $plotdata[0]->[$j]=0;
 1517:     }
 1518:     my $incorrect_plot = 
 1519:         &Apache::loncommon::DrawBarGraph('Incorrect Statements',
 1520:                                          'Statement Number',
 1521:                                          'Incorrect Option Choice',
 1522:                                          100,
 1523:                                          $plotcolors,
 1524:                                          undef,
 1525:                                          @plotdata,{xskip=>1});
 1526:     return ($correct_plot,$incorrect_plot);
 1527: }
 1528: 
 1529: sub OR_Concept_Time_Analysis {
 1530:     my ($processed_time_data,$correct,$data_count,$student_count,
 1531:         $ORdata,$Concepts) = @_;
 1532:     return '' if ($data_count == 0);
 1533:     #
 1534:     # Put the data in plottable form
 1535:     my @plotdata;
 1536:     foreach my $concept (@$Concepts) {
 1537:         my ($total,$correct);
 1538:         foreach my $foil (@{$concept->{'foils'}}) {
 1539:             $total += $processed_time_data->{$foil}->{'_total'};
 1540:             $correct += $processed_time_data->{$foil}->{'_correct'};
 1541:         }
 1542:         if ($total == 0) {
 1543:             push(@plotdata,0);
 1544:         } else {
 1545:             push(@plotdata,100 * $correct / $total);
 1546:         }
 1547:     }
 1548:     #
 1549:     # Create the plot
 1550:     return &Apache::loncommon::DrawBarGraph('Correct Concepts',
 1551:                                             'Concept Number',
 1552:                                             'Percent Correct',
 1553:                                             100,
 1554:                                             $plotcolors,
 1555:                                             undef,
 1556:                                             \@plotdata,{xskip=>1});
 1557: }
 1558: 
 1559: sub OR_time_process_data {
 1560:     my ($performance_data,$begin_index,$end_index)=@_;
 1561:     my %processed_time_data;
 1562:     my %distinct_students;
 1563:     my ($correct,$data_count);
 1564:     if (($begin_index == $end_index) && 
 1565:         ($end_index != scalar(@$performance_data)-1)) { 
 1566:         return undef;
 1567:     }
 1568:     # Be sure we include the last one if we are asked for it.
 1569:     # That we have to correct here (and not when $end_index is 
 1570:     # given a value) should probably be considered a bug.
 1571:     if ($end_index == scalar(@$performance_data)-1) {
 1572:         $end_index++;
 1573:     }
 1574:     my $count;
 1575:     for (my $i=$begin_index;$i<$end_index;$i++) {
 1576:         my $attempt = $performance_data->[$i];
 1577:         $count++;
 1578:         next if (! defined($attempt));
 1579:         my %attempt = &Process_OR_Row($attempt);
 1580:         $data_count++;
 1581:         $correct += $attempt{'_correct'};
 1582:         $distinct_students{$attempt->[&Apache::loncoursedata::RD_student_id()]}++;
 1583:         while (my ($foilid,$href) = each(%attempt)) {
 1584:             if (! ref($href)) {
 1585:                 $processed_time_data{$foilid} += $href;
 1586:                 next;
 1587:             }
 1588:             while (my ($option,$value) = each(%$href)) {
 1589:                 $processed_time_data{$foilid}->{$option}+=$value;
 1590:             }
 1591:         }
 1592:     }
 1593:     return (\%processed_time_data,$correct,$data_count,
 1594:             scalar(keys(%distinct_students)));
 1595: }
 1596: 
 1597: #########################################################
 1598: #########################################################
 1599: ##
 1600: ##             Excel output 
 1601: ##
 1602: #########################################################
 1603: #########################################################
 1604: sub build_student_data_worksheet {
 1605:     my ($workbook,$format) = @_;
 1606:     my $rows_output = 3;
 1607:     my $cols_output = 0;
 1608:     my $worksheet  = $workbook->addworksheet('Student Data');
 1609:     $worksheet->write($rows_output++,0,'Student Data',$format->{'h3'});
 1610:     my @Headers = ('full name','username','domain','section',
 1611:                    "student\nnumber",'identifier');
 1612:     $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
 1613:     my @Students = @Apache::lonstatistics::Students;
 1614:     my $studentrows = &Apache::loncoursedata::get_student_data(\@Students);
 1615:     my %ids;
 1616:     foreach my $row (@$studentrows) {
 1617:         my ($mysqlid,$student) = @$row;
 1618:         $ids{$student}=$mysqlid;
 1619:     }
 1620:     foreach my $student (@Students) {
 1621:         my $name_domain = $student->{'username'}.':'.$student->{'domain'};
 1622:         $worksheet->write_row($rows_output++,0,
 1623:                           [$student->{'fullname'},
 1624:                            $student->{'username'},$student->{'domain'},
 1625:                            $student->{'section'},$student->{'id'},
 1626:                            $ids{$name_domain}]);
 1627:     }
 1628:     return $worksheet;
 1629: }
 1630: 
 1631: sub OR_excel_sheet {
 1632:     my ($r,$resource,$performance_data,$ORdata) = @_;
 1633:     my $response = '';
 1634:     my (undef,$Foils,$Concepts) = &build_foil_index($ORdata);
 1635:     #
 1636:     # Create excel worksheet
 1637:     my $filename = '/prtspool/'.
 1638:         $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
 1639:         time.'_'.rand(1000000000).'.xls';
 1640:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
 1641:     if (! defined($workbook)) {
 1642:         $r->log_error("Error creating excel spreadsheet $filename: $!");
 1643:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
 1644:                             "This error has been logged.  ".
 1645:                             "Please alert your LON-CAPA administrator").
 1646:                   '</p>');
 1647:         return undef;
 1648:     }
 1649:     #
 1650:     $workbook->set_tempdir('/home/httpd/perl/tmp');
 1651:     my $format = &Apache::loncommon::define_excel_formats($workbook);
 1652:     #
 1653:     # Create and populate main worksheets
 1654:     my $problem_data_sheet  = $workbook->addworksheet('Problem Data');
 1655:     my $student_data_sheet = &build_student_data_worksheet($workbook,$format);
 1656:     my $response_data_sheet = $workbook->addworksheet('Response Data');
 1657:     foreach my $sheet ($problem_data_sheet,$student_data_sheet,
 1658:                        $response_data_sheet) {
 1659:         $sheet->write(0,0,$resource->{'title'},$format->{'h2'});
 1660:         $sheet->write(1,0,$resource->{'src'},$format->{'h3'});
 1661:     }
 1662:     #
 1663:     my $result;
 1664:     $result = &OR_build_problem_data_worksheet($problem_data_sheet,$format,
 1665:                                             $Concepts,$ORdata);
 1666:     if ($result ne 'okay') {
 1667:         # Do something useful
 1668:     }
 1669:     $result = &OR_build_response_data_worksheet($response_data_sheet,$format,
 1670:                                              $performance_data,$Foils,
 1671:                                              $ORdata);
 1672:     if ($result ne 'okay') {
 1673:         # Do something useful
 1674:     }
 1675:     $response_data_sheet->activate();
 1676:     #
 1677:     # Close the excel file
 1678:     $workbook->close();
 1679:     #
 1680:     # Write a link to allow them to download it
 1681:     $result .= '<h2>'.&mt('Excel Raw Data Output').'</h2>'.
 1682:               '<p><a href="'.$filename.'">'.
 1683:               &mt('Your Excel spreadsheet.').
 1684:               '</a></p>'."\n";
 1685:     return $result;
 1686: }
 1687: 
 1688: sub OR_build_problem_data_worksheet {
 1689:     my ($worksheet,$format,$Concepts,$ORdata) = @_;
 1690:     my $rows_output = 3;
 1691:     my $cols_output = 0;
 1692:     $worksheet->write($rows_output++,0,'Problem Structure',$format->{'h3'});
 1693:     ##
 1694:     ##
 1695:     my @Headers;
 1696:     if (@$Concepts > 1) {
 1697:         @Headers = ("Concept\nNumber",'Concept',"Foil\nNumber",
 1698:                     'Foil Name','Foil Text','Correct value');
 1699:     } else {
 1700:         @Headers = ('Foil Number','FoilName','Foil Text','Correct value');
 1701:     }
 1702:     $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
 1703:     my %Foildata = %{$ORdata->{'_Foils'}};
 1704:     my $conceptindex = 1;
 1705:     my $foilindex = 1;
 1706:     foreach my $concept (@$Concepts) {
 1707:         my @FoilsInConcept = @{$concept->{'foils'}};
 1708:         my $firstfoil = shift(@FoilsInConcept);
 1709:         if (@$Concepts > 1) {
 1710:             $worksheet->write_row($rows_output++,0,
 1711:                                   [$conceptindex,
 1712:                                    $concept->{'name'},
 1713:                                    $foilindex++,
 1714:                                    $Foildata{$firstfoil}->{'name'},
 1715:                                    $Foildata{$firstfoil}->{'text'},
 1716:                                    $Foildata{$firstfoil}->{'value'},]);
 1717:         } else {
 1718:             $worksheet->write_row($rows_output++,0,
 1719:                                   [ $foilindex++,
 1720:                                     $Foildata{$firstfoil}->{'name'},
 1721:                                     $Foildata{$firstfoil}->{'text'},
 1722:                                     $Foildata{$firstfoil}->{'value'},]);
 1723:         }
 1724:         foreach my $foilid (@FoilsInConcept) {
 1725:             if (@$Concepts > 1) {
 1726:                 $worksheet->write_row($rows_output++,0,
 1727:                                       ['',
 1728:                                        '',
 1729:                                        $foilindex,
 1730:                                        $Foildata{$foilid}->{'name'},
 1731:                                        $Foildata{$foilid}->{'text'},
 1732:                                        $Foildata{$foilid}->{'value'},]);
 1733:             } else {
 1734:                 $worksheet->write_row($rows_output++,0,                
 1735:                                       [$foilindex,
 1736:                                        $Foildata{$foilid}->{'name'},
 1737:                                        $Foildata{$foilid}->{'text'},
 1738:                                        $Foildata{$foilid}->{'value'},]);
 1739:             }                
 1740:         } continue {
 1741:             $foilindex++;
 1742:         }
 1743:     } continue {
 1744:         $conceptindex++;
 1745:     }
 1746:     $rows_output++;
 1747:     $rows_output++;
 1748:     ##
 1749:     ## Option data output
 1750:     $worksheet->write($rows_output++,0,'Options',$format->{'header'});
 1751:     foreach my $string (@{$ORdata->{'_Options'}}) {
 1752:         $worksheet->write($rows_output++,0,$string);
 1753:     }
 1754:     return 'okay';
 1755: }
 1756: 
 1757: sub OR_build_response_data_worksheet {
 1758:     my ($worksheet,$format,$performance_data,$Foils,$ORdata)=@_;
 1759:     my $rows_output = 3;
 1760:     my $cols_output = 0;
 1761:     $worksheet->write($rows_output++,0,'Response Data',$format->{'h3'});
 1762:     $worksheet->set_column(1,1,20);
 1763:     $worksheet->set_column(2,2,13);
 1764:     my @Headers = ('identifier','time','award detail','attempt');
 1765:     foreach my $foil (@$Foils) {
 1766:         push (@Headers,$foil.' submission');
 1767:         push (@Headers,$foil.' grading');
 1768:     }
 1769:     $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
 1770:     #
 1771:     foreach my $row (@$performance_data) {
 1772:         next if (! defined($row));
 1773:         my ($student,$award,$grading,$submission,$time,$tries) = @$row;
 1774:         my @Foilgrades = split('&',$grading);
 1775:         my @Foilsubs   = split('&',$submission);
 1776:         my %response_data;
 1777:         for (my $j=0;$j<=$#Foilgrades;$j++) {
 1778:             my ($foilid,$correct)  = split('=',$Foilgrades[$j]);
 1779:             my (undef,$submission) = split('=',$Foilsubs[$j]);
 1780:             $submission = &Apache::lonnet::unescape($submission);
 1781:             $response_data{$foilid.' submission'}=$submission;
 1782:             $response_data{$foilid.' award'}=$correct;
 1783:         }
 1784:         $worksheet->write($rows_output,$cols_output++,$student);
 1785:         $worksheet->write($rows_output,$cols_output++,
 1786:              &Apache::lonstathelpers::calc_serial($time),$format->{'date'});
 1787:         $worksheet->write($rows_output,$cols_output++,$award);
 1788:         $worksheet->write($rows_output,$cols_output++,$tries);
 1789:         foreach my $foilid (@$Foils) {
 1790:             $worksheet->write($rows_output,$cols_output++,
 1791:                               $response_data{$foilid.' submission'});
 1792:             $worksheet->write($rows_output,$cols_output++,
 1793:                               $response_data{$foilid.' award'});
 1794:         }
 1795:         $rows_output++;
 1796:         $cols_output = 0;
 1797:     }
 1798:     return;
 1799: }
 1800: 
 1801: sub build_foil_index {
 1802:     my ($ORdata) = @_;
 1803:     return if (! exists($ORdata->{'_Foils'}));
 1804:     my %Foildata = %{$ORdata->{'_Foils'}};
 1805:     my @Foils = sort(keys(%Foildata));
 1806:     my %Concepts;
 1807:     foreach my $foilid (@Foils) {
 1808:         push(@{$Concepts{$Foildata{$foilid}->{'_Concept'}}},
 1809:              $foilid);
 1810:     }
 1811:     undef(@Foils);
 1812:     # Having gathered the concept information in a hash, we now translate it
 1813:     # into an array because we need to be consistent about order.
 1814:     # Also put the foils in order, too.
 1815:     my $sortfunction = sub {
 1816:         my %Numbers = (one   => 1,
 1817:                        two   => 2,
 1818:                        three => 3,
 1819:                        four  => 4,
 1820:                        five  => 5,
 1821:                        six   => 6,
 1822:                        seven => 7,
 1823:                        eight => 8,
 1824:                        nine  => 9,
 1825:                        ten   => 10,);
 1826:         my $a1 = lc($a); 
 1827:         my $b1 = lc($b);
 1828:         if (exists($Numbers{$a1})) {
 1829:             $a1 = $Numbers{$a1};
 1830:         }
 1831:         if (exists($Numbers{$b1})) {
 1832:             $b1 = $Numbers{$b1};
 1833:         }
 1834:         if (($a1 =~/^\d+$/) && ($b1 =~/^\d+$/)) {
 1835:             return $a1 <=> $b1;
 1836:         } else {
 1837:             return $a1 cmp $b1;
 1838:         }
 1839:     };
 1840:     my @Concepts;
 1841:     foreach my $concept (sort $sortfunction (keys(%Concepts))) {
 1842:         if (! defined($Concepts{$concept})) {
 1843:             $Concepts{$concept}=[];
 1844: #            next;
 1845:         }
 1846:         push(@Concepts,{ name => $concept,
 1847:                         foils => [@{$Concepts{$concept}}]});
 1848:         push(@Foils,(@{$Concepts{$concept}}));
 1849:     }
 1850:     #
 1851:     # Build up the table of row labels.
 1852:     my $table = '<table border="1" >'."\n";
 1853:     if (@Concepts > 1) {
 1854:         $table .= '<tr>'.
 1855:             '<th>'.&mt('Concept Number').'</th>'.
 1856:             '<th>'.&mt('Concept').'</th>'.
 1857:             '<th>'.&mt('Foil Number').'</th>'.
 1858:             '<th>'.&mt('Foil Name').'</th>'.
 1859:             '<th>'.&mt('Foil Text').'</th>'.
 1860:             '<th>'.&mt('Correct Value').'</th>'.
 1861:             "</tr>\n";
 1862:     } else {
 1863:         $table .= '<tr>'.
 1864:             '<th>'.&mt('Foil Number').'</th>'.
 1865:             '<th>'.&mt('Foil Name').'</th>'.
 1866:             '<th>'.&mt('Foil Text').'</th>'.
 1867:             '<th>'.&mt('Correct Value').'</th>'.
 1868:             "</tr>\n";
 1869:     }        
 1870:     my $conceptindex = 1;
 1871:     my $foilindex = 1;
 1872:     foreach my $concept (@Concepts) {
 1873:         my @FoilsInConcept = @{$concept->{'foils'}};
 1874:         my $firstfoil = shift(@FoilsInConcept);
 1875:         if (@Concepts > 1) {
 1876:             $table .= '<tr>'.
 1877:                 '<td>'.$conceptindex.'</td>'.
 1878:                 '<td>'.&HTML::Entities::encode($concept->{'name'},'<>&"').'</td>'.
 1879:                 '<td>'.$foilindex++.'</td>'.
 1880:                 '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').'</td>'.
 1881:                 '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
 1882:                 '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').'</td>'.
 1883:                 "</tr>\n";
 1884:         } else {
 1885:             $table .= '<tr>'.
 1886:                 '<td>'.$foilindex++.'</td>'.
 1887:                 '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').'</td>'.
 1888:                 '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
 1889:                 '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').'</td>'.
 1890:                 "</tr>\n";
 1891:         }
 1892:         foreach my $foilid (@FoilsInConcept) {
 1893:             if (@Concepts > 1) {
 1894:                 $table .= '<tr>'.
 1895:                     '<td></td>'.
 1896:                     '<td></td>'.
 1897:                     '<td>'.$foilindex.'</td>'.
 1898:                     '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').'</td>'.
 1899:                     '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
 1900:                     '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').'</td>'.
 1901:                     "</tr>\n";
 1902:             } else {
 1903:                 $table .= '<tr>'.
 1904:                     '<td>'.$foilindex.'</td>'.
 1905:                     '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').'</td>'.
 1906:                     '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
 1907:                     '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').'</td>'.
 1908:                     "</tr>\n";
 1909:             }                
 1910:         } continue {
 1911:             $foilindex++;
 1912:         }
 1913:     } continue {
 1914:         $conceptindex++;
 1915:     }
 1916:     $table .= "</table>\n";
 1917:     #
 1918:     # Build option index with color stuff
 1919:     return ($table,\@Foils,\@Concepts);
 1920: }
 1921: 
 1922: sub build_option_index {
 1923:     my ($ORdata)= @_;
 1924:     my $table = "<table>\n";
 1925:     my $optionindex = 0;
 1926:     my @Rows;
 1927:     foreach my $option (&mt('correct option chosen'),@{$ORdata->{'_Options'}}) {
 1928:         my $color = $plotcolors->[$optionindex++];
 1929:         push (@Rows,
 1930:               '<tr>'.
 1931:               '<td bgcolor="'.$color.'">'.
 1932:               '<font color="'.$color.'">'.('*'x3).'</font>'.'</td>'.
 1933:               '<td>'.&HTML::Entities::encode($option,'<>&"').'</td>'.
 1934:               "</tr>\n");
 1935:     }
 1936:     shift(@Rows); # Throw away 'correct option chosen' color
 1937:     $table .= join('',reverse(@Rows));
 1938:     $table .= "</table>\n";
 1939: }
 1940: 
 1941: sub build_foil_key {
 1942:     my ($foils,$extra_data)= @_;
 1943:     if (! defined($extra_data)) { $extra_data = {}; }
 1944:     my $table = "<table>\n";
 1945:     my $foil_index = 0;
 1946:     my @rows;
 1947:     foreach my $foil (&mt('correct foil chosen'),@{$foils}) {
 1948:         my $color = $plotcolors->[$foil_index++];
 1949:         push (@rows,
 1950:               '<tr>'.
 1951:               '<td bgcolor="'.$color.'" class="key">'.
 1952:               '<font color="'.$color.'">'.('*'x4).'</font></td>'.
 1953:               '<td>'.&HTML::Entities::encode($foil,'<>&"').
 1954:               ('&nbsp;'x2).$extra_data->{$foil}.'</td>'.
 1955:               "</tr>\n");
 1956:     }
 1957:     shift(@rows); # Throw away 'correct foil chosen' color
 1958:     $table .= join('',reverse(@rows));
 1959:     $table .= "</table>\n";
 1960: }
 1961: 
 1962: #########################################################
 1963: #########################################################
 1964: ##
 1965: ##   Generic Interface Routines
 1966: ##
 1967: #########################################################
 1968: #########################################################
 1969: sub CreateInterface {
 1970:     ##
 1971:     ## Environment variable initialization
 1972:     if (! exists$ENV{'form.AnalyzeOver'}) {
 1973:         $ENV{'form.AnalyzeOver'} = 'tries';
 1974:     }
 1975:     ##
 1976:     ## Build the menu
 1977:     my $Str = '';
 1978:     $Str .= &Apache::lonhtmlcommon::breadcrumbs
 1979:         (undef,'Detailed Problem Analysis');
 1980:     $Str .= '<table cellspacing="5">'."\n";
 1981:     $Str .= '<tr>';
 1982:     $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
 1983:     $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
 1984: #    $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
 1985:     $Str .= '<td align="center">&nbsp;</td>';
 1986:     $Str .= '</tr>'."\n";
 1987:     ##
 1988:     ## 
 1989:     $Str .= '<tr><td align="center">'."\n";
 1990:     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
 1991:     $Str .= '</td>';
 1992:     #
 1993:     $Str .= '<td align="center">';
 1994:     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
 1995:     $Str .= '</td>';
 1996:     #
 1997: #    $Str .= '<td align="center">';
 1998:     my $only_seq_with_assessments = sub { 
 1999:         my $s=shift;
 2000:         if ($s->{'num_assess'} < 1) { 
 2001:             return 0;
 2002:         } else { 
 2003:             return 1;
 2004:         }
 2005:     };
 2006:     &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
 2007:                                               $only_seq_with_assessments);
 2008:     ##
 2009:     ##
 2010:     $Str .= '<td>';
 2011:     ##
 2012:     my $showprob_checkbox = 
 2013:         '<input type="checkbox" name="show_prob" value="true" ';
 2014:     if ($ENV{'form.show_prob'} eq 'true') {
 2015:         $showprob_checkbox .= 'checked ';
 2016:     }
 2017:     $showprob_checkbox.= ' />';
 2018:     $Str.= '<nobr><label>'.
 2019:         &mt('Show problem [_1]',$showprob_checkbox).
 2020:         '</label></nobr><br />';
 2021:     ##
 2022:     my $analyze_selector = '<select name="AnalyzeOver" >';
 2023:     $analyze_selector .= '<option value="tries" ';
 2024:     if (! exists($ENV{'form.AnalyzeOver'}) || 
 2025:         $ENV{'form.AnalyzeOver'} eq 'tries'){
 2026:         # Default to tries
 2027:         $analyze_selector .= ' selected ';
 2028:     }
 2029:     $analyze_selector .= '>'.&mt('Tries').'</option>';
 2030:     $analyze_selector .= '<option value="time" ';
 2031:     $analyze_selector .= ' selected ' if ($ENV{'form.AnalyzeOver'} eq 'time');
 2032:     $analyze_selector .= '>'.&mt('Time').'</option>';
 2033:     $analyze_selector .= '</select>';
 2034:     $Str .= '<nobr><label>'.
 2035:         &mt('Analyze Over [_1] [_2]',
 2036:             $analyze_selector,
 2037:             &Apache::loncommon::help_open_topic('Analysis_Analyze_Over')).
 2038:             '</label></nobr><br />'.$/;
 2039:     ##
 2040:     my $numplots_selector = '<select name="NumPlots">';
 2041:     if (! exists($ENV{'form.NumPlots'}) 
 2042:         || $ENV{'form.NumPlots'} < 1 
 2043:         || $ENV{'form.NumPlots'} > 20) {
 2044:         $ENV{'form.NumPlots'} = 5;
 2045:     }
 2046:     foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
 2047:         $numplots_selector .= '<option value="'.$i.'" ';
 2048:         if ($ENV{'form.NumPlots'} == $i) { $numplots_selector.=' selected '; }
 2049:         $numplots_selector .= '>'.$i.'</option>';
 2050:     }
 2051:     $numplots_selector .= '</select></nobr><br />';
 2052:     $Str .= '<nobr><label>'.&mt('Number of Plots [_1]',$numplots_selector).
 2053:         '</label></nobr>';
 2054:     ##
 2055:     $Str .= '<nobr><label>'.&mt('Status: [_1]',
 2056:                                  '<input type="text" '.
 2057:                                  'name="stats_status" size="60" value="" />'
 2058:                                  ).
 2059:                     '</label></nobr>';
 2060:     $Str .= '</td>';
 2061:     ##
 2062:     ##
 2063:     $Str .= '</tr>'."\n";
 2064:     $Str .= '</table>'."\n";
 2065:     return $Str;
 2066: }
 2067: 
 2068: #########################################################
 2069: #########################################################
 2070: ##
 2071: ##              Misc Option Response functions
 2072: ##
 2073: #########################################################
 2074: #########################################################
 2075: sub get_time_from_row {
 2076:     my ($row) = @_;
 2077:     if (ref($row)) {
 2078:         return $row->[&Apache::loncoursedata::RD_timestamp()];
 2079:     } 
 2080:     return undef;
 2081: }
 2082: 
 2083: sub get_tries_from_row {
 2084:     my ($row) = @_;
 2085:     if (ref($row)) {
 2086:         return $row->[&Apache::loncoursedata::RD_tries()];
 2087:     }
 2088:     return undef;
 2089: }
 2090: 
 2091: sub hashify_attempt {
 2092:     my ($row) = @_;
 2093:     my %attempt;
 2094:     $attempt{'student'}    = $row->[&Apache::loncoursedata::RD_sname()];
 2095:     $attempt{'tries'}      = $row->[&Apache::loncoursedata::RD_tries()];
 2096:     $attempt{'submission'} = &Apache::lonnet::unescape($row->[&Apache::loncoursedata::RD_submission()]);
 2097:     $attempt{'award'}      = $row->[&Apache::loncoursedata::RD_awarddetail()];
 2098:     $attempt{'timestamp'}  = $row->[&Apache::loncoursedata::RD_timestamp()];
 2099:     return %attempt;
 2100: }
 2101: 
 2102: sub Process_OR_Row {
 2103:     my ($row) = @_;
 2104:     my %RowData;
 2105: #    my $student_id = $row->[&Apache::loncoursedata::RD_student_id()];
 2106:     my $award      = $row->[&Apache::loncoursedata::RD_awarddetail()];
 2107:     my $grading    = $row->[&Apache::loncoursedata::RD_response_eval()];
 2108:     my $submission = $row->[&Apache::loncoursedata::RD_submission()];
 2109:     my $time       = $row->[&Apache::loncoursedata::RD_timestamp()];
 2110: #    my $tries      = $row->[&Apache::loncoursedata::RD_tries()];
 2111:     return undef if ($award eq 'MISSING_ANSWER');
 2112:     if (&submission_is_correct($award)) {
 2113:         $RowData{'_correct'} = 1;
 2114:     }
 2115:     $RowData{'_total'} = 1;
 2116:     my @Foilgrades = split('&',$grading);
 2117:     my @Foilsubs   = split('&',$submission);
 2118:     for (my $j=0;$j<=$#Foilgrades;$j++) {
 2119:         my ($foilid,$correct)  = split('=',$Foilgrades[$j]);
 2120:         $foilid = &Apache::lonnet::unescape($foilid);
 2121:         my (undef,$submission) = split('=',$Foilsubs[$j]);
 2122:         if ($correct) {
 2123:             $RowData{$foilid}->{'_correct'}++;
 2124:         } else {
 2125:             $submission = &Apache::lonnet::unescape($submission);
 2126:             $RowData{$foilid}->{$submission}++;
 2127:         }
 2128:         $RowData{$foilid}->{'_total'}++;
 2129:     }
 2130:     return %RowData;
 2131: }
 2132: 
 2133: sub submission_is_correct {
 2134:     my ($award) = @_;
 2135:     if ($award =~ /(APPROX_ANS|EXACT_ANS)/) {
 2136:         return 1;
 2137:     } else {
 2138:         return 0;
 2139:     }
 2140: }
 2141: 
 2142: 1;
 2143: 
 2144: __END__

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