Annotation of loncom/interface/statistics/lonproblemanalysis.pm, revision 1.81

1.1       stredwic    1: # The LearningOnline Network with CAPA
                      2: #
1.81    ! matthew     3: # $Id: lonproblemanalysis.pm,v 1.80 2004/03/16 16:30:31 matthew Exp $
1.1       stredwic    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: #
1.11      minaeibi   27: package Apache::lonproblemanalysis;
1.1       stredwic   28: 
                     29: use strict;
                     30: use Apache::lonnet();
1.25      matthew    31: use Apache::loncommon();
1.7       stredwic   32: use Apache::lonhtmlcommon();
1.23      matthew    33: use Apache::loncoursedata();
                     34: use Apache::lonstatistics;
                     35: use Apache::lonlocal;
1.71      matthew    36: use Apache::lonstathelpers();
                     37: use Apache::lonstudentsubmissions();
1.37      matthew    38: use HTML::Entities();
1.42      matthew    39: use Time::Local();
1.43      matthew    40: use Spreadsheet::WriteExcel();
1.2       stredwic   41: 
1.40      matthew    42: my $plotcolors = ['#33ff00', 
                     43:                   '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
                     44:                   '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
                     45:                   ]; 
1.39      matthew    46: 
1.54      matthew    47: my @SubmitButtons = ({ name => 'PrevProblemAnalysis',
                     48:                        text => 'Previous Problem' },
                     49:                      { name => 'ProblemAnalysis',
1.46      matthew    50:                        text => 'Analyze Problem Again' },
1.54      matthew    51:                      { name => 'NextProblemAnalysis',
                     52:                        text => 'Next Problem' },
                     53:                      { name => 'break'},
1.46      matthew    54:                      { name => 'ClearCache',
                     55:                        text => 'Clear Caches' },
                     56:                      { name => 'updatecaches',
                     57:                        text => 'Update Student Data' },
                     58:                      { name => 'SelectAnother',
1.53      matthew    59:                        text => 'Choose a different Problem' },
1.46      matthew    60:                      { name => 'ExcelOutput',
                     61:                        text => 'Produce Excel Output' });
                     62: 
                     63: 
1.1       stredwic   64: sub BuildProblemAnalysisPage {
1.23      matthew    65:     my ($r,$c)=@_;
1.49      matthew    66:     #
                     67:     my %Saveable_Parameters = ('Status' => 'scalar',
                     68:                                'Section' => 'array',
                     69:                                'NumPlots' => 'scalar',
                     70:                                'AnalyzeAs' => 'scalar',
                     71:                                'AnalyzeOver' => 'scalar',
                     72:                                );
                     73:     &Apache::loncommon::store_course_settings('problem_analysis',
                     74:                                               \%Saveable_Parameters);
                     75:     &Apache::loncommon::restore_course_settings('problem_analysis',
                     76:                                                 \%Saveable_Parameters);
                     77:     #
                     78:     &Apache::lonstatistics::PrepareClasslist();
1.48      matthew    79:     #
1.25      matthew    80:     $r->print(&CreateInterface());
1.28      matthew    81:     #
                     82:     my @Students = @Apache::lonstatistics::Students;
                     83:     #
1.46      matthew    84:     if (@Students < 1) {
                     85:         $r->print('<h2>There are no students in the sections selected</h2>');
                     86:     }
                     87:     #
                     88:     &Apache::loncoursedata::clear_internal_caches();
1.41      matthew    89:     if (exists($ENV{'form.ClearCache'}) || 
                     90:         exists($ENV{'form.updatecaches'}) ||
1.33      matthew    91:         (exists($ENV{'form.firstanalysis'}) &&
                     92:          $ENV{'form.firstanalysis'} ne 'no')) {
                     93:         &Apache::lonstatistics::Gather_Full_Student_Data($r);
                     94:     }
                     95:     if (! exists($ENV{'form.firstanalysis'})) {
                     96:         $r->print('<input type="hidden" name="firstanalysis" value="yes" />');
                     97:     } else {
                     98:         $r->print('<input type="hidden" name="firstanalysis" value="no" />');
                     99:     }
1.39      matthew   100:     $r->rflush();
1.46      matthew   101:     #
1.78      matthew   102:     my $problem_types = '(option|radiobutton|numerical)';
1.33      matthew   103:     if (exists($ENV{'form.problemchoice'}) && 
                    104:         ! exists($ENV{'form.SelectAnother'})) {
1.46      matthew   105:         foreach my $button (@SubmitButtons) {
1.54      matthew   106:             if ($button->{'name'} eq 'break') {
                    107:                 $r->print("<br />\n");
                    108:             } else {
                    109:                 $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
                    110:                           'value="'.&mt($button->{'text'}).'" />');
                    111:                 $r->print('&nbsp;'x5);
                    112:             }
1.46      matthew   113:         }
1.31      matthew   114:         #
1.25      matthew   115:         $r->print('<hr />');
1.54      matthew   116:         $r->rflush();
                    117:         #
                    118:         # Determine which problem we are to analyze
1.61      matthew   119:         my $current_problem = &Apache::lonstathelpers::get_target_from_id
                    120:             ($ENV{'form.problemchoice'});
1.54      matthew   121:         #
1.61      matthew   122:         my ($prev,$curr,$next) = 
                    123:             &Apache::lonstathelpers::get_prev_curr_next($current_problem,
1.66      matthew   124:                                                         $problem_types,
                    125:                                                         'response',
1.61      matthew   126:                                                         );
1.54      matthew   127:         if (exists($ENV{'form.PrevProblemAnalysis'}) && defined($prev)) {
                    128:             $current_problem = $prev;
                    129:         } elsif (exists($ENV{'form.NextProblemAnalysis'}) && defined($next)) {
                    130:             $current_problem = $next;
                    131:         } else {
                    132:             $current_problem = $curr;
                    133:         }
1.23      matthew   134:         #
1.54      matthew   135:         # Store the current problem choice and send it out in the form
1.61      matthew   136:         $ENV{'form.problemchoice'} = 
                    137:             &Apache::lonstathelpers::make_target_id($current_problem);
1.54      matthew   138:         $r->print('<input type="hidden" name="problemchoice" value="'.
                    139:                   $ENV{'form.problemchoice'}.'" />');
1.28      matthew   140:         #
1.54      matthew   141:         if (! defined($current_problem->{'resource'})) {
1.46      matthew   142:             $r->print('resource is undefined');
                    143:         } else {
1.54      matthew   144:             my $resource = $current_problem->{'resource'};
1.44      matthew   145:             $r->print('<h1>'.$resource->{'title'}.'</h1>');
1.41      matthew   146:             $r->print('<h3>'.$resource->{'src'}.'</h3>');
1.60      matthew   147:             $r->print(&Apache::lonstathelpers::render_resource($resource));
1.44      matthew   148:             $r->rflush();
1.71      matthew   149:             my %Data = &Apache::lonstathelpers::get_problem_data
                    150:                 ($resource->{'src'});
1.54      matthew   151:             my $ProblemData = $Data{$current_problem->{'part'}.
                    152:                                     '.'.
                    153:                                     $current_problem->{'respid'}};
                    154:             if ($current_problem->{'resptype'} eq 'option') {
1.56      matthew   155:                 &OptionResponseAnalysis($r,$current_problem,
1.54      matthew   156:                                         $ProblemData,
1.47      matthew   157:                                         \@Students);
1.54      matthew   158:             } elsif ($current_problem->{'resptype'} eq 'radiobutton') {
1.56      matthew   159:                 &RadioResponseAnalysis($r,$current_problem,
1.54      matthew   160:                                        $ProblemData,
1.47      matthew   161:                                        \@Students);
1.66      matthew   162:             } elsif ($current_problem->{'resptype'} eq 'numerical') {
1.78      matthew   163:                     &NumericalResponseAnalysis($r,$current_problem,
                    164:                                                $ProblemData,\@Students);
1.47      matthew   165:             } else {
                    166:                 $r->print('<h2>This analysis is not supported</h2>');
                    167:             }
1.7       stredwic  168:         }
1.23      matthew   169:         $r->print('<hr />');
1.25      matthew   170:     } else {
1.31      matthew   171:         $r->print('<input type="submit" name="ProblemAnalysis" value="'.
                    172:                   &mt('Analyze Problem').'" />');
                    173:         $r->print('&nbsp;'x5);
1.27      matthew   174:         $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
1.61      matthew   175:         $r->print(&Apache::lonstathelpers::ProblemSelector
1.66      matthew   176:                   ($problem_types));
1.1       stredwic  177:     }
                    178: }
                    179: 
1.69      matthew   180: 
                    181: #########################################################
                    182: #########################################################
                    183: ##
1.66      matthew   184: ##      Numerical Response Routines
                    185: ##
                    186: #########################################################
                    187: #########################################################
                    188: sub NumericalResponseAnalysis {
                    189:     my ($r,$problem,$ProblemData,$Students) = @_;
1.79      matthew   190:     my $c = $r->connection();
1.66      matthew   191:     my ($resource,$respid) = ($problem->{'resource'},
                    192:                               $problem->{'respid'});
1.80      matthew   193:     $r->print('Response '.$respid.'</br />');
1.66      matthew   194:     my $analysis_html;
                    195:     my $PerformanceData = 
                    196:         &Apache::loncoursedata::get_response_data
                    197:         ($Students,$resource->{'symb'},$respid);
                    198:     if (! defined($PerformanceData) || 
                    199:         ref($PerformanceData) ne 'ARRAY' ) {
                    200:         $analysis_html = '<h2>'.
                    201:             &mt('There is no submission data for this resource').
                    202:             '</h2>';
                    203:         $r->print($analysis_html);
                    204:         return;
                    205:     }
1.78      matthew   206:     #
                    207:     # This next call causes all the waiting around that people complain about
1.81    ! matthew   208:     my ($max,$min) = &Apache::lonstathelpers::GetStudentAnswers($r,$problem,
        !           209:                                                                 $Students);
1.79      matthew   210:     return if ($c->aborted());
1.78      matthew   211:     #
                    212:     # Collate the data
1.68      matthew   213:     my %Data;
                    214:     foreach my $student (@$Students) {
                    215:         my $answer = $student->{'answer'};
                    216:         $Data{$answer}++;
                    217:     }
                    218:     my @Labels = sort {$a <=> $b } keys(%Data);
                    219:     my @PlotData = @Data{@Labels};
1.78      matthew   220:     #
                    221:     my $width  = 500; 
                    222:     my $height = 100;
                    223:     my $plot = &one_dimensional_plot($r,500,100,scalar(@$Students),
                    224:                                      \@Labels,\@PlotData);
                    225:     $r->print($plot);
1.68      matthew   226:     return;
1.66      matthew   227: }
                    228: 
1.78      matthew   229: sub one_dimensional_plot {
                    230:     my ($r,$width,$height,$N,$Labels,$Data)=@_;
                    231:     #
                    232:     # Compute data -> image scaling factors
                    233:     my $min = $Labels->[0];
                    234:     my $max = $Labels->[-1];
                    235:     my $h_scale = ($width-10)/($max-$min);
                    236:     #
                    237:     my $max_y = 0;
                    238:     foreach (@$Data) {
                    239:         $max_y = $_ if ($max_y < $_);
                    240:     }
                    241:     my $ticscale = 5;
                    242:     if ($max_y * $ticscale > $height/2) {
                    243:         $ticscale = int($height/2/$max_y);
                    244:         $ticscale = 1 if ($ticscale < 1);
                    245:     }
                    246:     #
                    247:     # Create the plot
                    248:     my $plot = 
                    249:         qq{<drawimage width="$width" height="$height" bgcolor="transparent" >};
                    250:     for (my $idx=0;$idx<scalar(@$Labels);$idx++) {
                    251:         my $xloc = 5+$h_scale*($Labels->[$idx] - $min);
                    252:         my $top    = $height/2-$Data->[$idx]*$ticscale;
                    253:         my $bottom = $height/2+$Data->[$idx]*$ticscale;
                    254:         $plot .= 
                    255:             &line($xloc,$top,$xloc,$bottom,'888888',1);
                    256:     }
                    257:     #
                    258:     # Put the scale on last to ensure it is on top of the data.
                    259:     if ($min < 0 && $max > 0) {
                    260:         my $circle_x = 5+$h_scale*abs($min);  # '0' in data coordinates
                    261:         my $r = 4;
                    262:         $plot .= &line(5,$height/2,$circle_x-$r,$height/2,'000000',1);
                    263:         $plot .= &circle($circle_x,$height/2,$r+1,'000000');
                    264:         $plot .= &line($circle_x+$r,$height/2,$width-5,$height/2,'000000',1);
                    265:     } else {
                    266:         $plot .= &line(5,$height/2,$width-5,$height/2,'000000',1);
                    267:     }
                    268:     $plot .= '</drawimage>';
                    269:     my $plotresult =  &Apache::lonxml::xmlparse($r,'web',$plot);
                    270:     
                    271:     my $title = 'Distribution of correct answers';
                    272:     my $result = '<table>'.
                    273:         '<tr><td colspan="3" align="center">'.
                    274:         '<font size="+2">'.$title.' (N='.$N.')'.
                    275:         '</font>'.
                    276:         '</td></tr>'.
                    277:         '<tr>'.
                    278:         '<td valign="center">'.$min.'</td>'.
                    279:         '<td>'.$plotresult.'</td>'.
                    280:         '<td valign="center">'.$max.'</td>'.
                    281:         '</tr>'.
                    282:         '<tr><td colspan="3" align="center">'.
                    283:         'Maximum Number of Coinciding Values: '.$max_y.
                    284:         '</td></tr>'.
                    285:         '</table>';
                    286:     return $result;
                    287: }
                    288: 
                    289: ##
                    290: ## Helper subroutines for <drawimage>.  
                    291: ## These should probably go somewhere more suitable soon.
                    292: sub line {
                    293:     my ($x1,$y1,$x2,$y2,$color,$thickness) = @_;
                    294:     return qq{<line x1="$x1" y1="$y1" x2="$x2" y2="$y2" color="$color" thickness="$thickness" />$/};
                    295: }
                    296: 
                    297: sub rectangle {
                    298:     my ($x1,$y1,$x2,$y2,$color,$thickness,$filled) = @_;
                    299:     return qq{<rectangle x1="$x1" y1="$y1" x2="$x2" y2="$y2" color="$color" thickness="$thickness" filled="$filled" />};
                    300: }
                    301: 
                    302: sub arc {
                    303:     my ($x,$y,$width,$height,$start,$end,$color,$thickness,$filled)=@_;
                    304:     return qq{<arc x="$x" y="$y" width="$width" height="$height" start="$start" end="$end" color="$color" thickness="$thickness" filled="$filled" />};
                    305: }
                    306: 
                    307: sub circle {
                    308:     my ($x,$y,$radius,$color,$thickness,$filled)=@_;
                    309:     return &arc($x,$y,$radius,$radius,0,360,$color,$thickness,$filled);
1.68      matthew   310: }
                    311: 
                    312: sub build_student_data_worksheet {
                    313:     my ($workbook,$format) = @_;
                    314:     my $rows_output = 3;
                    315:     my $cols_output = 0;
                    316:     my $worksheet  = $workbook->addworksheet('Student Data');
                    317:     $worksheet->write($rows_output++,0,'Student Data',$format->{'h3'});
                    318:     my @Headers = ('full name','username','domain','section',
                    319:                    "student\nnumber",'identifier');
                    320:     $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
                    321:     my @Students = @Apache::lonstatistics::Students;
                    322:     my $studentrows = &Apache::loncoursedata::get_student_data(\@Students);
                    323:     my %ids;
                    324:     foreach my $row (@$studentrows) {
                    325:         my ($mysqlid,$student) = @$row;
                    326:         $ids{$student}=$mysqlid;
                    327:     }
                    328:     foreach my $student (@Students) {
                    329:         my $name_domain = $student->{'username'}.':'.$student->{'domain'};
                    330:         $worksheet->write_row($rows_output++,0,
                    331:                           [$student->{'fullname'},
                    332:                            $student->{'username'},$student->{'domain'},
                    333:                            $student->{'section'},$student->{'id'},
                    334:                            $ids{$name_domain}]);
                    335:     }
                    336:     return $worksheet;
1.66      matthew   337: }
1.47      matthew   338: 
                    339: #########################################################
                    340: #########################################################
                    341: ##
                    342: ##      Radio Response Routines
                    343: ##
                    344: #########################################################
                    345: #########################################################
                    346: sub RadioResponseAnalysis {
1.56      matthew   347:     my ($r,$problem,$ProblemData,$Students) = @_;
                    348:     my ($resource,$respid) = ($problem->{'resource'},
1.66      matthew   349:                               $problem->{'respid'});
1.48      matthew   350:     my $analysis_html;
1.47      matthew   351:     my $PerformanceData = 
                    352:         &Apache::loncoursedata::get_response_data
1.48      matthew   353:         ($Students,$resource->{'symb'},$respid);
                    354:     if (! defined($PerformanceData) || 
                    355:         ref($PerformanceData) ne 'ARRAY' ) {
                    356:         $analysis_html = '<h2>'.
                    357:             &mt('There is no submission data for this resource').
                    358:             '</h2>';
                    359:         $r->print($analysis_html);
1.47      matthew   360:         return;
                    361:     }
1.48      matthew   362:     if (exists($ENV{'form.ExcelOutput'})) {
1.56      matthew   363:         $analysis_html .= &RR_Excel_output($r,$problem->{'resource'},
                    364:                                            $PerformanceData,$ProblemData);
1.48      matthew   365:     } elsif ($ENV{'form.AnalyzeOver'} eq 'Tries') {
1.56      matthew   366:         $analysis_html .= &RR_Tries_Analysis($r,$problem->{'resource'},
                    367:                                              $PerformanceData,$ProblemData);
1.48      matthew   368:     } elsif ($ENV{'form.AnalyzeOver'} eq 'Time') {
1.56      matthew   369:         $analysis_html .= &RR_Time_Analysis($r,$problem->{'resource'},
                    370:                                             $PerformanceData,$ProblemData);
1.48      matthew   371:     } else {
                    372:         $analysis_html .= '<h2>'.
                    373:            &mt('The analysis you have selected is not supported at this time').
                    374:            '</h2>';
                    375:     }
                    376:     $r->print($analysis_html);
                    377: }
                    378: 
                    379: sub RR_Excel_output   { 
                    380:     my ($r,$PerformanceData,$ProblemData) = @_;
                    381:     return '<h1>No!</h1>';
                    382: }
                    383: 
                    384: sub RR_Tries_Analysis { 
                    385:     my ($r,$resource,$PerformanceData,$ProblemData) = @_;
                    386:     my $analysis_html;
                    387:     my $mintries = 1;
                    388:     my $maxtries = $ENV{'form.NumPlots'};
                    389:     my ($table,$Foils,$Concepts) = &build_foil_index($ProblemData);
1.57      matthew   390:     if ((! defined($Concepts)) || ((@$Concepts < 2) && 
                    391:                                    ($ENV{'form.AnalyzeAs'} ne 'Foils'))) {
1.48      matthew   392:         $table = '<h3>'.
                    393:             &mt('Not enough data for concept analysis.  '.
                    394:                 'Performing Foil Analysis').
                    395:             '</h3>'.$table;
                    396:         $ENV{'form.AnalyzeAs'} = 'Foils';
                    397:     }
                    398:     $analysis_html .= $table;
                    399:     my @TryData = &RR_tries_data_analysis($r,$PerformanceData);
1.56      matthew   400: #    if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
                    401:         $analysis_html .= &RR_Tries_Foil_Analysis($mintries,$maxtries,$Foils,
1.48      matthew   402:                                                  \@TryData,$ProblemData);
1.56      matthew   403: #    } else {
                    404: #        $analysis_html = &RR_Tries_Concept_Analysis($mintries,$maxtries,
                    405: #                                                    $Concepts,
                    406: #                                                    \@TryData,
                    407: #                                                    $ProblemData);
                    408: #    }
1.48      matthew   409:     return $analysis_html;
                    410: }
                    411: 
                    412: sub RR_tries_data_analysis {
                    413:     my ($r,$Attempt_data) = @_;
                    414:     my @TryData;
                    415:     foreach my $attempt (@$Attempt_data) {
                    416:         my %Attempt = &hashify_attempt($attempt);
                    417:         my ($answer,undef) = split('=',$Attempt{'submission'});
                    418:         $TryData[$Attempt{'tries'}]->{$answer}++;
                    419:     }
                    420:     return @TryData;
                    421: }
                    422: 
                    423: sub RR_Time_Analysis  { 
                    424:     my ($r,$PerformanceData,$ProblemData) = @_;
                    425:     my $html;
                    426:     return $html;
                    427: }
                    428: 
                    429: sub RR_Tries_Foil_Analysis {
                    430:     my ($min,$max,$Foils,$TryData,$ProblemData) = @_;
                    431:     my $html;
                    432:     #
                    433:     # Compute the data neccessary to make the plots
                    434:     for (my $try=$min;$try<=$max;$try++) {
                    435:         my @PlotData_Correct; 
                    436:         my @PlotData_Incorrect;
                    437:         next if ($try > scalar(@{$TryData}));
1.56      matthew   438:         next if (! defined($TryData->[$try]));
                    439:         my %DataSet = %{$TryData->[$try]};
1.48      matthew   440:         my $total = 0;
                    441:         foreach my $foilid (@$Foils) {
                    442:             $total += $DataSet{$foilid};
                    443:         }
                    444:         foreach my $foilid (@$Foils) {
                    445:             if ($total == 0) {
                    446:                 push (@PlotData_Correct,0);
                    447:                 push (@PlotData_Incorrect,0);
                    448:             } else {
                    449:                 if ($ProblemData->{'_Foils'}->{$foilid}->{'value'} eq 'true') {
                    450:                     push (@PlotData_Correct,
                    451:                           int(100*$DataSet{$foilid}/$total));
                    452:                     push (@PlotData_Incorrect,0);
                    453:                 } else {
                    454:                     push (@PlotData_Correct,0);
                    455:                     push (@PlotData_Incorrect,
                    456:                           int(100*$DataSet{$foilid}/$total));
                    457:                 }
                    458:             }
                    459:         }
                    460:         my $title='Attempt '.$try;
                    461:         my $xlabel = $total.' Submissions';
                    462:         $html.=  &Apache::loncommon::DrawBarGraph($title,
                    463:                                                   $xlabel,
                    464:                                                   'Percent Choosing',
                    465:                                                   100,
                    466:                                                   ['#33ff00','#ff3300'],
1.64      matthew   467:                                                   undef,
1.48      matthew   468:                                                   \@PlotData_Correct,
                    469:                                                   \@PlotData_Incorrect);
                    470:     }
                    471:     return $html;
                    472: }
                    473: 
                    474: sub RR_Tries_Concept_Analysis {
                    475:     my ($min,$max,$Concepts,$ResponseData,$ProblemData) = @_;
                    476:     my $html;
                    477:     return $html;
                    478: }
                    479: 
                    480: sub RR_Time_Foil_Analysis {
                    481:     my ($min,$max,$Foils,$ResponseData,$ProblemData) = @_;
                    482:     my $html;
                    483:     return $html;
                    484: }
                    485: 
                    486: sub RR_Time_Concept_Analysis {
                    487:     my ($min,$max,$Concepts,$ResponseData,$ProblemData) = @_;
                    488:     my $html;
                    489:     return $html;
                    490: }
                    491: 
                    492: 
                    493: sub get_Radio_problem_data {
                    494:     my ($url) = @_;
                    495:     my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze'));
                    496:     (my $garbage,$Answ)=split('_HASH_REF__',$Answ,2);
                    497:     my %Answer = &Apache::lonnet::str2hash($Answ);
                    498:     my %Partdata;
                    499:     foreach my $part (@{$Answer{'parts'}}) {
                    500:         while (my($key,$value) = each(%Answer)) {
                    501: #            if (ref($value) eq 'ARRAY') {
                    502: #                &Apache::lonnet::logthis('is ref part:'.$part.' '.$key.'='.join(',',@$value));
                    503: #            } else {
                    504: #                &Apache::lonnet::logthis('notref part:'.$part.' '.$key.'='.$value);
                    505: #            }                
                    506:             next if ($key !~ /^$part/);
                    507:             $key =~ s/^$part\.//;
                    508:             if ($key eq 'foils') {
                    509:                 $Partdata{$part}->{'_Foils'}=$value;
                    510:             } elsif ($key eq 'options') {
                    511:                 $Partdata{$part}->{'_Options'}=$value;
                    512:             } elsif ($key eq 'shown') {
                    513:                 $Partdata{$part}->{'_Shown'}=$value;
                    514:             } elsif ($key =~ /^foil.value.(.*)$/) {
                    515:                 $Partdata{$part}->{$1}->{'value'}=$value;
                    516:             } elsif ($key =~ /^foil.text.(.*)$/) {
                    517:                 $Partdata{$part}->{$1}->{'text'}=$value;
                    518:             }
                    519:         }
                    520:     }
                    521:     return %Partdata;
1.47      matthew   522: }
1.48      matthew   523: 
1.33      matthew   524: #########################################################
                    525: #########################################################
                    526: ##
1.46      matthew   527: ##      Option Response Routines
1.33      matthew   528: ##
                    529: #########################################################
                    530: #########################################################
1.46      matthew   531: sub OptionResponseAnalysis {
1.56      matthew   532:     my ($r,$problem,$ProblemData,$Students) = @_;
                    533:     my ($resource,$respid) = ($problem->{'resource'},
                    534:                               $problem->{'respid'});
                    535:     # Note: part data is not needed.
1.46      matthew   536:     my $PerformanceData = 
1.47      matthew   537:         &Apache::loncoursedata::get_response_data
1.54      matthew   538:         ($Students,$resource->{'symb'},$respid);
1.46      matthew   539:     if (! defined($PerformanceData) || 
                    540:         ref($PerformanceData) ne 'ARRAY' ) {
                    541:         $r->print('<h2>'.
                    542:                   &mt('There is no student data for this problem.').
                    543:                   '</h2>');
                    544:     }  else {
                    545:         $r->rflush();
                    546:         if (exists($ENV{'form.ExcelOutput'})) {
1.57      matthew   547:             my $result = &OR_excel_sheet($r,$resource,
                    548:                                          $PerformanceData,
                    549:                                          $ProblemData);
1.46      matthew   550:             $r->print($result);
                    551:             $r->rflush();
1.39      matthew   552:         } else {
1.46      matthew   553:             if ($ENV{'form.AnalyzeOver'} eq 'Tries') {
1.57      matthew   554:                 my $analysis_html = &OR_tries_analysis($r,
1.46      matthew   555:                                                     $PerformanceData,
                    556:                                                     $ProblemData);
                    557:                 $r->print($analysis_html);
                    558:                 $r->rflush();
                    559:             } elsif ($ENV{'form.AnalyzeOver'} eq 'Time') {
1.57      matthew   560:                 my $analysis_html = &OR_time_analysis($PerformanceData,
1.46      matthew   561:                                                    $ProblemData);
                    562:                 $r->print($analysis_html);
                    563:                 $r->rflush();
1.39      matthew   564:             } else {
1.46      matthew   565:                 $r->print('<h2>'.
                    566:                           &mt('The analysis you have selected is '.
                    567:                               'not supported at this time').
                    568:                           '</h2>');
                    569:             }
1.36      matthew   570:         }
1.39      matthew   571:     }
                    572: }
                    573: 
1.33      matthew   574: #########################################################
1.46      matthew   575: #
                    576: #       Option Response:  Tries Analysis
                    577: #
1.33      matthew   578: #########################################################
1.57      matthew   579: sub OR_tries_analysis {
1.43      matthew   580:     my ($r,$PerformanceData,$ORdata) = @_;
1.33      matthew   581:     my $mintries = 1;
                    582:     my $maxtries = $ENV{'form.NumPlots'};
1.39      matthew   583:     my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
1.78      matthew   584:     if (! defined($Concepts) || 
                    585:         ((@$Concepts < 2) && ($ENV{'form.AnalyzeAs'} ne 'Foils'))) {
1.39      matthew   586:         $table = '<h3>'.
                    587:             &mt('Not enough data for concept analysis.  '.
                    588:                 'Performing Foil Analysis').
                    589:             '</h3>'.$table;
                    590:         $ENV{'form.AnalyzeAs'} = 'Foils';
                    591:     }
1.57      matthew   592:     my %ResponseData = &OR_analyze_by_tries($r,$PerformanceData,
1.36      matthew   593:                                                      $mintries,$maxtries);
1.42      matthew   594:     my $analysis = '';
                    595:     if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
1.75      matthew   596:         $analysis = &OR_Tries_Foil_Analysis($mintries,$maxtries,$Concepts,
1.42      matthew   597:                                          \%ResponseData,$ORdata);
                    598:     } else {
1.57      matthew   599:         $analysis = &OR_Tries_Concept_Analysis($mintries,$maxtries,
1.42      matthew   600:                                             $Concepts,\%ResponseData,$ORdata);
                    601:     }
                    602:     $table .= $analysis;
                    603:     return $table;
                    604: }
                    605: 
1.57      matthew   606: sub OR_Tries_Foil_Analysis {
1.75      matthew   607:     my ($mintries,$maxtries,$Concepts,$respdat,$ORdata) = @_;
1.42      matthew   608:     my %ResponseData = %$respdat;
1.31      matthew   609:     #
                    610:     # Compute the data neccessary to make the plots
1.42      matthew   611:     my @PlotData; 
1.75      matthew   612:     foreach my $concept (@$Concepts) {
                    613:         foreach my $foilid (@{$concept->{'foils'}}) {
1.76      matthew   614:             for (my $try=$mintries;$try<=$maxtries;$try++) {
                    615:                 if ($ResponseData{$foilid}->[$try]->{'_total'} == 0) {
                    616:                     push(@{$PlotData[$try]->{'_correct'}},0);
1.42      matthew   617:                 } else {
1.76      matthew   618:                     push(@{$PlotData[$try]->{'_correct'}},
                    619:                          100*$ResponseData{$foilid}->[$try]->{'_correct'}/
                    620:                          $ResponseData{$foilid}->[$try]->{'_total'});
1.75      matthew   621:                 }
                    622:                 foreach my $option (@{$ORdata->{'_Options'}}) {
1.76      matthew   623:                     push(@{$PlotData[$try]->{'_total'}},
                    624:                          $ResponseData{$foilid}->[$try]->{'_total'});
                    625:                     if ($ResponseData{$foilid}->[$try]->{'_total'} == 0) {
                    626:                         push (@{$PlotData[$try]->{$option}},0);
1.39      matthew   627:                     } else {
1.76      matthew   628:                         if ($ResponseData{$foilid}->[$try]->{'_total'} ==
                    629:                             $ResponseData{$foilid}->[$try]->{'_correct'}) {
                    630:                             push(@{$PlotData[$try]->{$option}},0);
1.75      matthew   631:                         } else {
1.76      matthew   632:                             push (@{$PlotData[$try]->{$option}},
                    633:                                   100 * 
                    634:                                   $ResponseData{$foilid}->[$try]->{$option} / 
                    635:                                   ($ResponseData{$foilid}->[$try]->{'_total'} 
                    636:                                    - 
                    637:                                    $ResponseData{$foilid}->[$try]->{'_correct'}
                    638:                                    ));
1.75      matthew   639:                         }
1.39      matthew   640:                     }
1.76      matthew   641:                 } # End of foreach my $option
1.36      matthew   642:             }
1.76      matthew   643:         } # End of foreach my $foilid
                    644:     } # End of foreach my $concept
1.42      matthew   645:     # 
                    646:     # Build a table for the plots
                    647:     my $analysis_html = "<table>\n";
1.75      matthew   648:     my $optionkey = &build_option_index($ORdata);
                    649:     for (my $try=$mintries;$try<=$maxtries;$try++) {
                    650:         my $count = $ResponseData{'_total'}->[$try];
1.77      matthew   651:         my $title = 'Submission '.$try.' (N='.$count.')';
1.42      matthew   652:         my @Datasets;
1.48      matthew   653:         foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {
1.75      matthew   654:             next if (! exists($PlotData[$try]->{$option}));
                    655:             push(@Datasets,$PlotData[$try]->{$option});
1.42      matthew   656:         }
1.76      matthew   657:         #
                    658:         # Put a blank in the data set between concepts
                    659:         for (my $set =0;$set<=$#Datasets;$set++) {
                    660:             my @Data = @{$Datasets[$set]};
                    661:             my $idx = 0;
                    662:             foreach my $concept (@{$Concepts}) {
                    663:                 foreach my $foilid (@{$concept->{'foils'}}) {
                    664:                     $Datasets[$set]->[$idx++]=shift(@Data);
                    665:                 }
                    666:                 if ($concept->{'name'} ne $Concepts->[-1]->{'name'}) {
                    667:                     $Datasets[$set]->[$idx++] = 0;
                    668:                 }
                    669:             }
                    670:         }
                    671:         #
                    672:         # Set up the labels needed for the bar graph
                    673:         my @Labels;
                    674:         my $idx = 1;
                    675:         foreach my $concept (@{$Concepts}) {
                    676:             foreach my $foilid (@{$concept->{'foils'}}) {
                    677:                 push(@Labels,$idx++);
                    678:             }
                    679:             push(@Labels,'');
                    680:         }
                    681:         #
1.46      matthew   682:         my $correctgraph = &Apache::loncommon::DrawBarGraph
1.42      matthew   683:             ($title,'Foil Number','Percent Correct',
1.76      matthew   684:              100,$plotcolors,\@Labels,$Datasets[0]);
1.42      matthew   685:         $analysis_html.= '<tr><td>'.$correctgraph.'</td>';
1.75      matthew   686:         
                    687:         #
                    688:         #
1.57      matthew   689:         next if (! defined($Datasets[0]));
1.42      matthew   690:         for (my $i=0; $i< scalar(@{$Datasets[0]});$i++) {
                    691:             $Datasets[0]->[$i]=0;
                    692:         }
1.75      matthew   693:         $count = $ResponseData{'_total'}->[$try] - 
                    694:                                            $ResponseData{'_correct'}->[$try];
1.77      matthew   695:         $title = 'Submission '.$try.' (N='.$count.')';
1.46      matthew   696:         my $incorrectgraph = &Apache::loncommon::DrawBarGraph
1.42      matthew   697:             ($title,'Foil Number','% Option Chosen Incorrectly',
1.76      matthew   698:              100,$plotcolors,\@Labels,@Datasets);
1.42      matthew   699:         $analysis_html.= '<td>'.$incorrectgraph.'</td>';
1.75      matthew   700:         $analysis_html.= '<td>'.$optionkey."<td></tr>\n";
1.42      matthew   701:     }
                    702:     $analysis_html .= "</table>\n";
                    703:     return $analysis_html;
                    704: }
                    705: 
1.57      matthew   706: sub OR_Tries_Concept_Analysis {
1.42      matthew   707:     my ($mintries,$maxtries,$Concepts,$respdat,$ORdata) = @_;
                    708:     my %ResponseData = %$respdat;
                    709:     my $analysis_html = "<table>\n";
                    710:     #
                    711:     # Compute the data neccessary to make the plots
                    712:     my @PlotData;
                    713:     # Concept analysis
                    714:     #
                    715:     # Note: we do not bother with characterizing the students incorrect
                    716:     # answers at the concept level because an incorrect answer for one foil
                    717:     # may be a correct answer for another foil.
                    718:     my %ConceptData;
                    719:     foreach my $concept (@{$Concepts}) {
                    720:         for (my $i=$mintries;$i<=$maxtries;$i++) {
                    721:             #
                    722:             # Gather the per-attempt data
                    723:             my $cdata = $ConceptData{$concept}->[$i];
                    724:             foreach my $foilid (@{$concept->{'foils'}}) {
                    725:                 $cdata->{'_correct'} += 
                    726:                     $ResponseData{$foilid}->[$i]->{'_correct'};
                    727:                 $cdata->{'_total'}   += 
                    728:                     $ResponseData{$foilid}->[$i]->{'_total'};
                    729:             }
                    730:             push (@{$PlotData[$i]->{'_total'}},$cdata->{'_total'});
                    731:             if ($cdata->{'_total'} == 0) {
                    732:                 push (@{$PlotData[$i]->{'_correct'}},0);
                    733:             } else {
                    734:                 push (@{$PlotData[$i]->{'_correct'}},
                    735:                       100*$cdata->{'_correct'}/$cdata->{'_total'});
1.36      matthew   736:                 }
1.25      matthew   737:         }
1.42      matthew   738:     }
1.31      matthew   739:     # Build a table for the plots
1.25      matthew   740:     for (my $i=$mintries;$i<=$maxtries;$i++) {
1.39      matthew   741:         my $minstu = $PlotData[$i]->{'_total'}->[0];
                    742:         my $maxstu = $PlotData[$i]->{'_total'}->[0];
                    743:         foreach my $count (@{$PlotData[$i]->{'_total'}}) {
1.36      matthew   744:             if ($minstu > $count) {
                    745:                 $minstu = $count;
1.27      matthew   746:             }
1.36      matthew   747:             if ($maxstu < $count) {
                    748:                 $maxstu = $count;
1.27      matthew   749:             }
                    750:         }
1.39      matthew   751:         $maxstu = 0 if (! defined($maxstu));
                    752:         $minstu = 0 if (! defined($minstu));
1.35      matthew   753:         my $title;
1.42      matthew   754:         my $count = $ResponseData{'_total'}->[$i];
                    755:         if ($count == 0) {
                    756:             $count = 'no submissions';
                    757:         } elsif ($count == 1) {
                    758:             $count = '1 submission';
1.27      matthew   759:         } else {
1.42      matthew   760:             $count = $count.' submissions';
1.39      matthew   761:         }
1.42      matthew   762:         $title = 'Attempt '.$i.', '.$count;
1.46      matthew   763:         my $graphlink = &Apache::loncommon::DrawBarGraph
1.42      matthew   764:             ($title,'Concept Number','Percent Correct',
1.64      matthew   765:              100,$plotcolors,undef,$PlotData[$i]->{'_correct'});
1.42      matthew   766:         $analysis_html.= '<tr><td>'.$graphlink."</td></tr>\n";
1.25      matthew   767:     }
1.42      matthew   768:     $analysis_html .= "</table>\n";
                    769:     return $analysis_html;
1.25      matthew   770: }
                    771: 
1.57      matthew   772: sub OR_analyze_by_tries {
1.43      matthew   773:     my ($r,$PerformanceData,$mintries,$maxtries) = @_;
1.25      matthew   774:     my %Trydata;
                    775:     $mintries = 1         if (! defined($mintries) || $mintries < 1);
                    776:     $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
1.26      matthew   777:     foreach my $row (@$PerformanceData) {
                    778:         next if (! defined($row));
1.47      matthew   779:         my $tries = &get_tries_from_row($row);
1.46      matthew   780:         my %Row   = &Process_OR_Row($row);
1.43      matthew   781:         next if (! %Row);
1.42      matthew   782:         while (my ($foilid,$href) = each(%Row)) {
                    783:             if (! ref($href)) { 
                    784:                 $Trydata{$foilid}->[$tries] += $href;
                    785:                 next;
                    786:             }
                    787:             while (my ($option,$value) = each(%$href)) {
                    788:                 $Trydata{$foilid}->[$tries]->{$option}+=$value;
1.25      matthew   789:             }
                    790:         }
                    791:     }
                    792:     return %Trydata;
                    793: }
                    794: 
1.33      matthew   795: #########################################################
1.46      matthew   796: #
                    797: #     Option Response: Time Analysis
                    798: #
1.33      matthew   799: #########################################################
1.57      matthew   800: sub OR_time_analysis {
1.33      matthew   801:     my ($PerformanceData,$ORdata) = @_;
1.42      matthew   802:     my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
                    803:     if ((@$Concepts < 2) && ($ENV{'form.AnalyzeAs'} ne 'Foils')) {
                    804:         $table = '<h3>'.
                    805:             &mt('Not enough data for concept analysis.  '.
                    806:                 'Performing Foil Analysis').
                    807:             '</h3>'.$table;
                    808:         $ENV{'form.AnalyzeAs'} = 'Foils';
                    809:     }
1.33      matthew   810:     my $num_plots = $ENV{'form.NumPlots'};
                    811:     my $num_data = scalar(@$PerformanceData)-1;
                    812:     my $percent = sprintf('%2f',100/$num_plots);
1.42      matthew   813:     #
1.37      matthew   814:     $table .= "<table>\n";
1.33      matthew   815:     for (my $i=0;$i<$num_plots;$i++) {
1.42      matthew   816:         ##
1.34      matthew   817:         my $starttime = &Apache::lonhtmlcommon::get_date_from_form
                    818:             ('startdate_'.$i);
                    819:         my $endtime = &Apache::lonhtmlcommon::get_date_from_form
                    820:             ('enddate_'.$i);
                    821:         if (! defined($starttime) || ! defined($endtime)) {
1.42      matthew   822:             my $sec_in_day = 86400;
1.47      matthew   823:             my $last_sub_time = &get_time_from_row($PerformanceData->[-1]);
1.42      matthew   824:             my ($sday,$smon,$syear);
                    825:             (undef,undef,undef,$sday,$smon,$syear) = 
                    826:                 localtime($last_sub_time - $sec_in_day*$i);
                    827:             $starttime = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear);
                    828:             $endtime = $starttime + $sec_in_day;
                    829:             if ($i == ($num_plots -1 )) {
1.47      matthew   830:                 $starttime = &get_time_from_row($PerformanceData->[0]);
1.42      matthew   831:             }
                    832:         }
1.34      matthew   833:         my $startdateform = &Apache::lonhtmlcommon::date_setter
                    834:             ('Statistics','startdate_'.$i,$starttime);
                    835:         my $enddateform = &Apache::lonhtmlcommon::date_setter
                    836:             ('Statistics','enddate_'.$i,$endtime);
1.42      matthew   837:         #
                    838:         my $begin_index;
                    839:         my $end_index;
                    840:         my $j;
                    841:         while (++$j < scalar(@$PerformanceData)) {
1.47      matthew   842:             last if (&get_time_from_row($PerformanceData->[$j]) 
1.46      matthew   843:                                                               > $starttime);
1.42      matthew   844:         }
                    845:         $begin_index = $j;
                    846:         while (++$j < scalar(@$PerformanceData)) {
1.47      matthew   847:             last if (&get_time_from_row($PerformanceData->[$j]) > $endtime);
1.42      matthew   848:         }
                    849:         $end_index = $j;
                    850:         ##
                    851:         my $interval = {
                    852:             begin_index => $begin_index,
                    853:             end_index   => $end_index,
                    854:             startdateform => $startdateform,
                    855:             enddateform   => $enddateform,
                    856:         };
                    857:         if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
1.57      matthew   858:             $table .= &OR_Foil_Time_Analysis($PerformanceData,$ORdata,$Foils,
1.42      matthew   859:                                           $interval);
                    860:         } else {
1.57      matthew   861:             $table .= &OR_Concept_Time_Analysis($PerformanceData,$ORdata,
1.42      matthew   862:                                              $Concepts,$interval);
                    863:         }
1.33      matthew   864:     }
1.42      matthew   865:     #
1.33      matthew   866:     return $table;
                    867: }
                    868: 
1.57      matthew   869: sub OR_Foil_Time_Analysis {
1.42      matthew   870:     my ($PerformanceData,$ORdata,$Foils,$interval) = @_;
                    871:     my $analysis_html;
                    872:     my $foilkey = &build_option_index($ORdata);
                    873:     my ($begin_index,$end_index) = ($interval->{'begin_index'},
                    874:                                     $interval->{'end_index'});
1.33      matthew   875:     my %TimeData;
                    876:     #
                    877:     # Compute the number getting the foils correct or incorrects
1.42      matthew   878:     for (my $j=$begin_index;$j<=$end_index;$j++) {
                    879:         my $row = $PerformanceData->[$j];
1.33      matthew   880:         next if (! defined($row));
1.46      matthew   881:         my %Row = &Process_OR_Row($row);
1.42      matthew   882:         while (my ($foilid,$href) = each(%Row)) {
                    883:             if (! ref($href)) {
                    884:                 $TimeData{$foilid} += $href;
                    885:                 next;
                    886:             }
                    887:             while (my ($option,$value) = each(%$href)) {
                    888:                 $TimeData{$foilid}->{$option}+=$value;
1.33      matthew   889:             }
                    890:         }
                    891:     }
1.39      matthew   892:     my @Plotdata;
1.42      matthew   893:     foreach my $foil (@$Foils) {
                    894:         my $total = $TimeData{$foil}->{'_total'};
                    895:         if ($total == 0) {
                    896:             push(@{$Plotdata[0]},0);
                    897:         } else {
                    898:             push(@{$Plotdata[0]},
                    899:                  100 * $TimeData{$foil}->{'_correct'} / $total);
                    900:         }
                    901:         my $total_incorrect = $total - $TimeData{$foil}->{'_correct'};
                    902:         my $optionidx = 1;
1.48      matthew   903:         foreach my $option (@{$ORdata->{'_Options'}}) {
1.42      matthew   904:             if ($total_incorrect == 0) {
                    905:                 push(@{$Plotdata[$optionidx]},0);
                    906:             } else {
                    907:                 push(@{$Plotdata[$optionidx]},
                    908:                      100 * $TimeData{$foil}->{$option} / $total_incorrect);
1.37      matthew   909:             }
1.42      matthew   910:         } continue {
                    911:             $optionidx++;
1.39      matthew   912:         }
1.42      matthew   913:     }
                    914:     #
                    915:     # Create the plot
                    916:     my $count = $end_index-$begin_index;
                    917:     my $title;
                    918:     if ($count == 0) {
                    919:         $title = 'no submissions';
                    920:     } elsif ($count == 1) {
                    921:         $title = 'one submission';
1.39      matthew   922:     } else {
1.42      matthew   923:         $title = $count.' submissions';
                    924:     }
1.46      matthew   925:     my $correctplot = &Apache::loncommon::DrawBarGraph($title,
                    926:                                                        'Foil Number',
                    927:                                                        'Percent Correct',
                    928:                                                        100,
                    929:                                                        $plotcolors,
1.64      matthew   930:                                                        undef,
1.46      matthew   931:                                                        $Plotdata[0]);
1.42      matthew   932:     for (my $j=0; $j< scalar(@{$Plotdata[0]});$j++) {
                    933:         $Plotdata[0]->[$j]=0;
                    934:     }
                    935:     $count = $end_index-$begin_index-$TimeData{'_correct'};
                    936:     if ($count == 0) {
                    937:         $title = 'no submissions';
                    938:     } elsif ($count == 1) {
                    939:         $title = 'one submission';
                    940:     } else {
                    941:         $title = $count.' submissions';
                    942:     }
1.46      matthew   943:     my $incorrectplot = &Apache::loncommon::DrawBarGraph($title,
1.42      matthew   944:                                                  'Foil Number',
                    945:                                                  'Incorrect Option Choice',
                    946:                                                  100,
                    947:                                                  $plotcolors,
1.64      matthew   948:                                                  undef,
1.42      matthew   949:                                                  @Plotdata);        
                    950:     $analysis_html.='<tr>'.
                    951:         '<td>'.$correctplot.'</td>'.
                    952:         '<td>'.$incorrectplot.'</td>'.
                    953:         '<td align="left" valign="top">'.$foilkey.'</td>'."</tr>\n";
                    954:     $analysis_html.= '<tr>'.'<td colspan="3">'.
                    955:         '<b>Start Time</b>:'.
                    956:         ' &nbsp;'.$interval->{'startdateform'}.'<br />'.
                    957:         '<b>End Time</b>&nbsp;&nbsp;: '.
                    958:         '&nbsp;'.$interval->{'enddateform'}.'<br />'.
                    959: #        '<b>Plot Title</b>&nbsp;&nbsp;:'.
                    960: #        ("&nbsp;"x3).$interval->{'titleform'}.
                    961:         '</td>'.
                    962:         "</tr>\n";
                    963:     return $analysis_html;
                    964: }
                    965: 
1.57      matthew   966: sub OR_Concept_Time_Analysis {
1.42      matthew   967:     my ($PerformanceData,$ORdata,$Concepts,$interval) = @_;
                    968:     my $analysis_html;
                    969:     ##
                    970:     ## Determine starttime, endtime, startindex, endindex
                    971:     my ($begin_index,$end_index) = ($interval->{'begin_index'},
                    972:                                     $interval->{'end_index'});
                    973:     my %TimeData;
                    974:     #
                    975:     # Compute the number getting the foils correct or incorrects
                    976:     for (my $j=$begin_index;$j<=$end_index;$j++) {
                    977:         my $row = $PerformanceData->[$j];
                    978:         next if (! defined($row));
1.46      matthew   979:         my %Row = &Process_OR_Row($row);
1.42      matthew   980:         while (my ($foilid,$href) = each(%Row)) {
                    981:             if (! ref($href)) {
                    982:                 $TimeData{$foilid} += $href;
                    983:                 next;
1.37      matthew   984:             }
1.42      matthew   985:             while (my ($option,$value) = each(%$href)) {
                    986:                 $TimeData{$foilid}->{$option}+=$value;
1.37      matthew   987:             }
1.33      matthew   988:         }
                    989:     }
                    990:     #
1.42      matthew   991:     # Put the data in plottable form
                    992:     my @Plotdata;
                    993:     foreach my $concept (@$Concepts) {
                    994:         my ($total,$correct);
                    995:         foreach my $foil (@{$concept->{'foils'}}) {
                    996:             $total += $TimeData{$foil}->{'_total'};
                    997:             $correct += $TimeData{$foil}->{'_correct'};
                    998:         }
                    999:         if ($total == 0) {
                   1000:             push(@Plotdata,0);
                   1001:         } else {
                   1002:             push(@Plotdata,100 * $correct / $total);
                   1003:         }
                   1004:     }
                   1005:     #
1.33      matthew  1006:     # Create the plot
1.42      matthew  1007:     my $title = ($end_index - $begin_index).' submissions';
1.46      matthew  1008:     my $correctplot = &Apache::loncommon::DrawBarGraph($title,
1.42      matthew  1009:                                                     'Concept Number',
                   1010:                                                     'Percent Correct',
                   1011:                                                     100,
                   1012:                                                     $plotcolors,
1.64      matthew  1013:                                                     undef,
1.42      matthew  1014:                                                     \@Plotdata);
                   1015:     $analysis_html.='<tr>'.
                   1016:         '<td>'.$correctplot.'</td>'.
                   1017:         '<td align="left" valign="top">'.
                   1018:         '<b>Start Time</b>: &nbsp;'.$interval->{'startdateform'}.'<br />'.
                   1019:         '<b>End Time</b>&nbsp;&nbsp;: '.
                   1020:            '&nbsp;'.$interval->{'enddateform'}.'<br />'.
                   1021: #        '<b>Plot Title</b>&nbsp;&nbsp;:'.("&nbsp;"x3).
                   1022: #            $interval->{'titleform'}.
                   1023:         '</td>'.
                   1024:         "</tr>\n";
                   1025:     return $analysis_html;
                   1026: }
                   1027: 
                   1028: #########################################################
                   1029: #########################################################
                   1030: ##
                   1031: ##             Excel output 
                   1032: ##
                   1033: #########################################################
                   1034: #########################################################
1.57      matthew  1035: sub OR_excel_sheet {
1.43      matthew  1036:     my ($r,$resource,$PerformanceData,$ORdata) = @_;
1.44      matthew  1037:     my $response = '';
1.42      matthew  1038:     my (undef,$Foils,$Concepts) = &build_foil_index($ORdata);
1.43      matthew  1039:     #
                   1040:     # Create excel worksheet
                   1041:     my $filename = '/prtspool/'.
                   1042:         $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
                   1043:         time.'_'.rand(1000000000).'.xls';
                   1044:     my $workbook  = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
                   1045:     if (! defined($workbook)) {
                   1046:         $r->log_error("Error creating excel spreadsheet $filename: $!");
                   1047:         $r->print('<p>'.&mt("Unable to create new Excel file.  ".
                   1048:                             "This error has been logged.  ".
                   1049:                             "Please alert your LON-CAPA administrator").
                   1050:                   '</p>');
                   1051:         return undef;
                   1052:     }
                   1053:     #
                   1054:     $workbook->set_tempdir('/home/httpd/perl/tmp');
1.69      matthew  1055:     my $format = &Apache::loncommon::define_excel_formats($workbook);
1.43      matthew  1056:     #
                   1057:     # Create and populate main worksheets
                   1058:     my $problem_data_sheet  = $workbook->addworksheet('Problem Data');
1.69      matthew  1059:     my $student_data_sheet = &build_student_data_worksheet($workbook,$format);
1.43      matthew  1060:     my $response_data_sheet = $workbook->addworksheet('Response Data');
                   1061:     foreach my $sheet ($problem_data_sheet,$student_data_sheet,
                   1062:                        $response_data_sheet) {
                   1063:         $sheet->write(0,0,$resource->{'title'},$format->{'h2'});
                   1064:         $sheet->write(1,0,$resource->{'src'},$format->{'h3'});
                   1065:     }
                   1066:     #
                   1067:     my $result;
1.59      matthew  1068:     $result = &OR_build_problem_data_worksheet($problem_data_sheet,$format,
1.43      matthew  1069:                                             $Concepts,$ORdata);
                   1070:     if ($result ne 'okay') {
                   1071:         # Do something useful
                   1072:     }
1.59      matthew  1073:     $result = &OR_build_response_data_worksheet($response_data_sheet,$format,
1.43      matthew  1074:                                              $PerformanceData,$Foils,
                   1075:                                              $ORdata);
                   1076:     if ($result ne 'okay') {
                   1077:         # Do something useful
                   1078:     }
1.44      matthew  1079:     $response_data_sheet->activate();
1.43      matthew  1080:     #
                   1081:     # Close the excel file
                   1082:     $workbook->close();
                   1083:     #
                   1084:     # Write a link to allow them to download it
1.44      matthew  1085:     $result .= '<h2>'.&mt('Excel Raw Data Output').'</h2>'.
                   1086:               '<p><a href="'.$filename.'">'.
                   1087:               &mt('Your Excel spreadsheet.').
                   1088:               '</a></p>'."\n";
1.43      matthew  1089:     return $result;
                   1090: }
                   1091: 
1.57      matthew  1092: sub OR_build_problem_data_worksheet {
1.43      matthew  1093:     my ($worksheet,$format,$Concepts,$ORdata) = @_;
                   1094:     my $rows_output = 3;
                   1095:     my $cols_output = 0;
                   1096:     $worksheet->write($rows_output++,0,'Problem Structure',$format->{'h3'});
                   1097:     ##
                   1098:     ##
                   1099:     my @Headers;
                   1100:     if (@$Concepts > 1) {
                   1101:         @Headers = ("Concept\nNumber",'Concept',"Foil\nNumber",
                   1102:                     'Foil Name','Foil Text','Correct value');
                   1103:     } else {
                   1104:         @Headers = ('Foil Number','FoilName','Foil Text','Correct value');
                   1105:     }
                   1106:     $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
1.48      matthew  1107:     my %Foildata = %{$ORdata->{'_Foils'}};
1.43      matthew  1108:     my $conceptindex = 1;
                   1109:     my $foilindex = 1;
                   1110:     foreach my $concept (@$Concepts) {
                   1111:         my @FoilsInConcept = @{$concept->{'foils'}};
                   1112:         my $firstfoil = shift(@FoilsInConcept);
                   1113:         if (@$Concepts > 1) {
                   1114:             $worksheet->write_row($rows_output++,0,
                   1115:                                   [$conceptindex,
                   1116:                                    $concept->{'name'},
                   1117:                                    $foilindex++,
                   1118:                                    $Foildata{$firstfoil}->{'name'},
                   1119:                                    $Foildata{$firstfoil}->{'text'},
                   1120:                                    $Foildata{$firstfoil}->{'value'},]);
                   1121:         } else {
                   1122:             $worksheet->write_row($rows_output++,0,
                   1123:                                   [ $foilindex++,
                   1124:                                     $Foildata{$firstfoil}->{'name'},
                   1125:                                     $Foildata{$firstfoil}->{'text'},
                   1126:                                     $Foildata{$firstfoil}->{'value'},]);
                   1127:         }
                   1128:         foreach my $foilid (@FoilsInConcept) {
                   1129:             if (@$Concepts > 1) {
                   1130:                 $worksheet->write_row($rows_output++,0,
                   1131:                                       ['',
                   1132:                                        '',
                   1133:                                        $foilindex,
                   1134:                                        $Foildata{$foilid}->{'name'},
                   1135:                                        $Foildata{$foilid}->{'text'},
                   1136:                                        $Foildata{$foilid}->{'value'},]);
                   1137:             } else {
                   1138:                 $worksheet->write_row($rows_output++,0,                
                   1139:                                       [$foilindex,
                   1140:                                        $Foildata{$foilid}->{'name'},
                   1141:                                        $Foildata{$foilid}->{'text'},
                   1142:                                        $Foildata{$foilid}->{'value'},]);
                   1143:             }                
                   1144:         } continue {
                   1145:             $foilindex++;
                   1146:         }
                   1147:     } continue {
                   1148:         $conceptindex++;
                   1149:     }
                   1150:     $rows_output++;
                   1151:     $rows_output++;
                   1152:     ##
                   1153:     ## Option data output
                   1154:     $worksheet->write($rows_output++,0,'Options',$format->{'header'});
1.48      matthew  1155:     foreach my $string (@{$ORdata->{'_Options'}}) {
1.43      matthew  1156:         $worksheet->write($rows_output++,0,$string);
                   1157:     }
                   1158:     return 'okay';
                   1159: }
                   1160: 
1.57      matthew  1161: sub OR_build_response_data_worksheet {
1.43      matthew  1162:     my ($worksheet,$format,$PerformanceData,$Foils,$ORdata)=@_;
                   1163:     my $rows_output = 3;
                   1164:     my $cols_output = 0;
                   1165:     $worksheet->write($rows_output++,0,'Response Data',$format->{'h3'});
                   1166:     $worksheet->set_column(1,1,20);
                   1167:     $worksheet->set_column(2,2,13);
                   1168:     my @Headers = ('identifier','time','award detail','attempt');
                   1169:     foreach my $foil (@$Foils) {
                   1170:         push (@Headers,$foil.' submission');
                   1171:         push (@Headers,$foil.' grading');
                   1172:     }
                   1173:     $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
                   1174:     #
                   1175:     foreach my $row (@$PerformanceData) {
                   1176:         next if (! defined($row));
                   1177:         my ($student,$award,$grading,$submission,$time,$tries) = @$row;
                   1178:         my @Foilgrades = split('&',$grading);
                   1179:         my @Foilsubs   = split('&',$submission);
                   1180:         my %ResponseData;
                   1181:         for (my $j=0;$j<=$#Foilgrades;$j++) {
                   1182:             my ($foilid,$correct)  = split('=',$Foilgrades[$j]);
                   1183:             my (undef,$submission) = split('=',$Foilsubs[$j]);
                   1184:             $submission = &Apache::lonnet::unescape($submission);
                   1185:             $ResponseData{$foilid.' submission'}=$submission;
                   1186:             $ResponseData{$foilid.' award'}=$correct;
                   1187:         }
                   1188:         $worksheet->write($rows_output,$cols_output++,$student);
                   1189:         $worksheet->write($rows_output,$cols_output++,
1.71      matthew  1190:              &Apache::lonstathelpers::calc_serial($time),$format->{'date'});
1.43      matthew  1191:         $worksheet->write($rows_output,$cols_output++,$award);
                   1192:         $worksheet->write($rows_output,$cols_output++,$tries);
                   1193:         foreach my $foilid (@$Foils) {
                   1194:             $worksheet->write($rows_output,$cols_output++,
                   1195:                               $ResponseData{$foilid.' submission'});
                   1196:             $worksheet->write($rows_output,$cols_output++,
                   1197:                               $ResponseData{$foilid.' award'});
                   1198:         }
                   1199:         $rows_output++;
                   1200:         $cols_output = 0;
                   1201:     }
                   1202:     return;
1.42      matthew  1203: }
                   1204: 
1.46      matthew  1205: sub build_foil_index {
                   1206:     my ($ORdata) = @_;
1.48      matthew  1207:     return if (! exists($ORdata->{'_Foils'}));
                   1208:     my %Foildata = %{$ORdata->{'_Foils'}};
1.46      matthew  1209:     my @Foils = sort(keys(%Foildata));
                   1210:     my %Concepts;
                   1211:     foreach my $foilid (@Foils) {
1.48      matthew  1212:         push(@{$Concepts{$Foildata{$foilid}->{'_Concept'}}},
1.46      matthew  1213:              $foilid);
                   1214:     }
                   1215:     undef(@Foils);
                   1216:     # Having gathered the concept information in a hash, we now translate it
                   1217:     # into an array because we need to be consistent about order.
                   1218:     # Also put the foils in order, too.
                   1219:     my $sortfunction = sub {
                   1220:         my %Numbers = (one   => 1,
                   1221:                        two   => 2,
                   1222:                        three => 3,
                   1223:                        four  => 4,
                   1224:                        five  => 5,
                   1225:                        six   => 6,
                   1226:                        seven => 7,
                   1227:                        eight => 8,
                   1228:                        nine  => 9,
                   1229:                        ten   => 10,);
                   1230:         my $a1 = lc($a); 
                   1231:         my $b1 = lc($b);
1.57      matthew  1232:         if (exists($Numbers{$a1})) {
1.67      matthew  1233:             $a1 = $Numbers{$a1};
1.57      matthew  1234:         }
                   1235:         if (exists($Numbers{$b1})) {
1.67      matthew  1236:             $b1 = $Numbers{$b1};
1.46      matthew  1237:         }
1.67      matthew  1238:         if (($a1 =~/^\d+$/) && ($b1 =~/^\d+$/)) {
                   1239:             return $a1 <=> $b1;
1.57      matthew  1240:         } else {
1.67      matthew  1241:             return $a1 cmp $b1;
1.46      matthew  1242:         }
                   1243:     };
                   1244:     my @Concepts;
                   1245:     foreach my $concept (sort $sortfunction (keys(%Concepts))) {
1.57      matthew  1246:         if (! defined($Concepts{$concept})) {
                   1247:             $Concepts{$concept}=[];
                   1248: #            next;
                   1249:         }
1.46      matthew  1250:         push(@Concepts,{ name => $concept,
                   1251:                         foils => [@{$Concepts{$concept}}]});
                   1252:         push(@Foils,(@{$Concepts{$concept}}));
                   1253:     }
                   1254:     #
                   1255:     # Build up the table of row labels.
                   1256:     my $table = '<table border="1" >'."\n";
                   1257:     if (@Concepts > 1) {
                   1258:         $table .= '<tr>'.
                   1259:             '<th>'.&mt('Concept Number').'</th>'.
                   1260:             '<th>'.&mt('Concept').'</th>'.
                   1261:             '<th>'.&mt('Foil Number').'</th>'.
                   1262:             '<th>'.&mt('Foil Name').'</th>'.
                   1263:             '<th>'.&mt('Foil Text').'</th>'.
                   1264:             '<th>'.&mt('Correct Value').'</th>'.
                   1265:             "</tr>\n";
                   1266:     } else {
                   1267:         $table .= '<tr>'.
                   1268:             '<th>'.&mt('Foil Number').'</th>'.
                   1269:             '<th>'.&mt('Foil Name').'</th>'.
                   1270:             '<th>'.&mt('Foil Text').'</th>'.
                   1271:             '<th>'.&mt('Correct Value').'</th>'.
                   1272:             "</tr>\n";
                   1273:     }        
                   1274:     my $conceptindex = 1;
                   1275:     my $foilindex = 1;
                   1276:     foreach my $concept (@Concepts) {
                   1277:         my @FoilsInConcept = @{$concept->{'foils'}};
                   1278:         my $firstfoil = shift(@FoilsInConcept);
                   1279:         if (@Concepts > 1) {
                   1280:             $table .= '<tr>'.
                   1281:                 '<td>'.$conceptindex.'</td>'.
1.63      matthew  1282:                 '<td>'.&HTML::Entities::encode($concept->{'name'}).'</td>'.
1.46      matthew  1283:                 '<td>'.$foilindex++.'</td>'.
1.63      matthew  1284:                 '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'}).'</td>'.
1.65      matthew  1285:                 '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
1.63      matthew  1286:                 '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'}).'</td>'.
1.46      matthew  1287:                 "</tr>\n";
                   1288:         } else {
                   1289:             $table .= '<tr>'.
                   1290:                 '<td>'.$foilindex++.'</td>'.
1.63      matthew  1291:                 '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'}).'</td>'.
1.65      matthew  1292:                 '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
1.63      matthew  1293:                 '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'}).'</td>'.
1.46      matthew  1294:                 "</tr>\n";
                   1295:         }
                   1296:         foreach my $foilid (@FoilsInConcept) {
                   1297:             if (@Concepts > 1) {
                   1298:                 $table .= '<tr>'.
                   1299:                     '<td></td>'.
                   1300:                     '<td></td>'.
                   1301:                     '<td>'.$foilindex.'</td>'.
1.63      matthew  1302:                     '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'name'}).'</td>'.
1.65      matthew  1303:                     '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
1.63      matthew  1304:                     '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'value'}).'</td>'.
1.46      matthew  1305:                     "</tr>\n";
                   1306:             } else {
                   1307:                 $table .= '<tr>'.
                   1308:                     '<td>'.$foilindex.'</td>'.
1.63      matthew  1309:                     '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'name'}).'</td>'.
1.65      matthew  1310:                     '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
1.63      matthew  1311:                     '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'value'}).'</td>'.
1.46      matthew  1312:                     "</tr>\n";
                   1313:             }                
                   1314:         } continue {
                   1315:             $foilindex++;
                   1316:         }
                   1317:     } continue {
                   1318:         $conceptindex++;
                   1319:     }
                   1320:     $table .= "</table>\n";
                   1321:     #
                   1322:     # Build option index with color stuff
                   1323:     return ($table,\@Foils,\@Concepts);
                   1324: }
                   1325: 
                   1326: sub build_option_index {
                   1327:     my ($ORdata)= @_;
                   1328:     my $table = "<table>\n";
                   1329:     my $optionindex = 0;
                   1330:     my @Rows;
1.48      matthew  1331:     foreach my $option (&mt('correct option chosen'),@{$ORdata->{'_Options'}}) {
1.46      matthew  1332:         push (@Rows,
                   1333:               '<tr>'.
                   1334:               '<td bgcolor="'.$plotcolors->[$optionindex++].'">'.
                   1335:               ('&nbsp;'x4).'</td>'.
1.63      matthew  1336:               '<td>'.&HTML::Entities::encode($option).'</td>'.
1.46      matthew  1337:               "</tr>\n");
                   1338:     }
                   1339:     shift(@Rows); # Throw away 'correct option chosen' color
                   1340:     $table .= join('',reverse(@Rows));
                   1341:     $table .= "</table>\n";
                   1342: }
                   1343: 
1.33      matthew  1344: #########################################################
                   1345: #########################################################
                   1346: ##
1.46      matthew  1347: ##   Generic Interface Routines
1.33      matthew  1348: ##
                   1349: #########################################################
                   1350: #########################################################
1.23      matthew  1351: sub CreateInterface {
1.28      matthew  1352:     ##
                   1353:     ## Environment variable initialization
1.36      matthew  1354:     if (! exists$ENV{'form.AnalyzeOver'}) {
                   1355:         $ENV{'form.AnalyzeOver'} = 'Tries';
1.28      matthew  1356:     }
                   1357:     ##
                   1358:     ## Build the menu
1.7       stredwic 1359:     my $Str = '';
1.72      matthew  1360:     $Str .= &Apache::lonhtmlcommon::breadcrumbs
1.74      matthew  1361:         (undef,'Detailed Problem Analysis');
1.23      matthew  1362:     $Str .= '<table cellspacing="5">'."\n";
                   1363:     $Str .= '<tr>';
                   1364:     $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
                   1365:     $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
1.31      matthew  1366: #    $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
                   1367:     $Str .= '<td align="center">&nbsp;</td>';
1.23      matthew  1368:     $Str .= '</tr>'."\n";
1.31      matthew  1369:     ##
                   1370:     ## 
1.23      matthew  1371:     $Str .= '<tr><td align="center">'."\n";
                   1372:     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1.28      matthew  1373:     $Str .= '</td>';
                   1374:     #
                   1375:     $Str .= '<td align="center">';
1.23      matthew  1376:     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1.28      matthew  1377:     $Str .= '</td>';
                   1378:     #
1.31      matthew  1379: #    $Str .= '<td align="center">';
1.23      matthew  1380:     my $only_seq_with_assessments = sub { 
                   1381:         my $s=shift;
                   1382:         if ($s->{'num_assess'} < 1) { 
                   1383:             return 0;
                   1384:         } else { 
                   1385:             return 1;
                   1386:         }
                   1387:     };
1.31      matthew  1388:     &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
1.23      matthew  1389:                                               $only_seq_with_assessments);
1.36      matthew  1390:     ##
                   1391:     ##
1.28      matthew  1392:     $Str .= '<td>';
1.36      matthew  1393:     { # These braces are here to organize the code, not scope it.
                   1394:         {
                   1395:             $Str .= '<nobr>'.&mt('Analyze Over ');
1.51      matthew  1396:             $Str .= &Apache::loncommon::help_open_topic
                   1397:                                                   ('Analysis_Analyze_Over');
1.36      matthew  1398:             $Str .='<select name="AnalyzeOver" >';
                   1399:             $Str .= '<option value="Tries" ';
                   1400:             if (! exists($ENV{'form.AnalyzeOver'}) || 
                   1401:                 $ENV{'form.AnalyzeOver'} eq 'Tries'){
                   1402:                 # Default to Tries
                   1403:                 $Str .= ' selected ';
                   1404:             }
                   1405:             $Str .= '>'.&mt('Tries').'</option>';
                   1406:             $Str .= '<option value="Time" ';
                   1407:             $Str .= ' selected ' if ($ENV{'form.AnalyzeOver'} eq 'Time');
                   1408:             $Str .= '>'.&mt('Time').'</option>';
1.51      matthew  1409:             $Str .= '</select>';
                   1410:             $Str .= '</nobr><br />';
1.36      matthew  1411:         }
                   1412:         {
                   1413:             $Str .= '<nobr>'.&mt('Analyze as ');
1.51      matthew  1414:             $Str .= &Apache::loncommon::help_open_topic
                   1415:                                                   ('Analysis_Analyze_as');
1.36      matthew  1416:             $Str .='<select name="AnalyzeAs" >';
                   1417:             $Str .= '<option value="Concepts" ';
                   1418:             if (! exists($ENV{'form.AnalyzeAs'}) || 
                   1419:                 $ENV{'form.AnalyzeAs'} eq 'Concepts'){
                   1420:                 # Default to Concepts
                   1421:                 $Str .= ' selected ';
                   1422:             }
                   1423:             $Str .= '>'.&mt('Concepts').'</option>';
                   1424:             $Str .= '<option value="Foils" ';
                   1425:             $Str .= ' selected ' if ($ENV{'form.AnalyzeAs'} eq 'Foils');
                   1426:             $Str .= '>'.&mt('Foils').'</option>';
                   1427:             $Str .= '</select></nobr><br />';
                   1428:         }
                   1429:         {
                   1430:             $Str .= '<br /><nobr>'.&mt('Number of Plots:');
1.52      matthew  1431:             $Str .= &Apache::loncommon::help_open_topic
                   1432:                                                   ('Analysis_num_plots');
1.36      matthew  1433:             $Str .= '<select name="NumPlots">';
                   1434:             if (! exists($ENV{'form.NumPlots'}) 
                   1435:                 || $ENV{'form.NumPlots'} < 1 
                   1436:                 || $ENV{'form.NumPlots'} > 20) {
                   1437:                 $ENV{'form.NumPlots'} = 5;
                   1438:             }
                   1439:             foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
                   1440:                 $Str .= '<option value="'.$i.'" ';
                   1441:                 if ($ENV{'form.NumPlots'} == $i) { $Str.=' selected '; }
                   1442:                 $Str .= '>'.$i.'</option>';
                   1443:             }
                   1444:             $Str .= '</select></nobr>';
                   1445:         }
1.28      matthew  1446:     }
                   1447:     $Str .= '</td>';
1.36      matthew  1448:     ##
                   1449:     ##
1.28      matthew  1450:     $Str .= '</tr>'."\n";
1.23      matthew  1451:     $Str .= '</table>'."\n";
1.42      matthew  1452:     return $Str;
1.54      matthew  1453: }
1.47      matthew  1454: 
                   1455: #########################################################
                   1456: #########################################################
                   1457: ##
                   1458: ##              Misc Option Response functions
                   1459: ##
                   1460: #########################################################
                   1461: #########################################################
                   1462: sub get_time_from_row {
1.42      matthew  1463:     my ($row) = @_;
                   1464:     if (ref($row)) {
1.47      matthew  1465:         return $row->[&Apache::loncoursedata::RD_timestamp()];
1.42      matthew  1466:     } 
                   1467:     return undef;
                   1468: }
                   1469: 
1.47      matthew  1470: sub get_tries_from_row {
1.42      matthew  1471:     my ($row) = @_;
                   1472:     if (ref($row)) {
1.47      matthew  1473:         return $row->[&Apache::loncoursedata::RD_tries()];
1.42      matthew  1474:     }
                   1475:     return undef;
                   1476: }
                   1477: 
1.48      matthew  1478: sub hashify_attempt {
                   1479:     my ($row) = @_;
                   1480:     my %attempt;
                   1481:     $attempt{'tries'}      = $row->[&Apache::loncoursedata::RD_tries()];
                   1482:     $attempt{'submission'} = $row->[&Apache::loncoursedata::RD_submission()];
                   1483:     $attempt{'award'}      = $row->[&Apache::loncoursedata::RD_awarddetail()];
                   1484:     $attempt{'timestamp'}  = $row->[&Apache::loncoursedata::RD_timestamp()];
                   1485:     return %attempt;
                   1486: }
                   1487: 
1.46      matthew  1488: sub Process_OR_Row {
1.42      matthew  1489:     my ($row) = @_;
                   1490:     my %RowData;
1.47      matthew  1491:     my $student_id = $row->[&Apache::loncoursedata::RD_student_id()];
                   1492:     my $award      = $row->[&Apache::loncoursedata::RD_awarddetail()];
                   1493:     my $grading    = $row->[&Apache::loncoursedata::RD_response_eval()];
                   1494:     my $submission = $row->[&Apache::loncoursedata::RD_submission()];
                   1495:     my $time       = $row->[&Apache::loncoursedata::RD_timestamp()];
                   1496:     my $tries      = $row->[&Apache::loncoursedata::RD_tries()];
1.43      matthew  1497:     return undef if ($award eq 'MISSING_ANSWER');
1.42      matthew  1498:     if ($award =~ /(APPROX_ANS|EXACT_ANS)/) {
                   1499:         $RowData{'_correct'} = 1;
                   1500:     }
                   1501:     $RowData{'_total'} = 1;
                   1502:     my @Foilgrades = split('&',$grading);
                   1503:     my @Foilsubs   = split('&',$submission);
                   1504:     for (my $j=0;$j<=$#Foilgrades;$j++) {
                   1505:         my ($foilid,$correct)  = split('=',$Foilgrades[$j]);
1.58      matthew  1506:         $foilid = &Apache::lonnet::unescape($foilid);
1.42      matthew  1507:         my (undef,$submission) = split('=',$Foilsubs[$j]);
                   1508:         if ($correct) {
                   1509:             $RowData{$foilid}->{'_correct'}++;
                   1510:         } else {
                   1511:             $submission = &Apache::lonnet::unescape($submission);
                   1512:             $RowData{$foilid}->{$submission}++;
                   1513:         }
                   1514:         $RowData{$foilid}->{'_total'}++;
                   1515:     }
                   1516:     return %RowData;
1.47      matthew  1517: }
                   1518: 
1.23      matthew  1519: 1;
1.1       stredwic 1520: 
                   1521: __END__

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