File:  [LON-CAPA] / loncom / interface / statistics / lonproblemanalysis.pm
Revision 1.37: download - view: text, annotated - select for diffs
Tue Oct 14 21:58:25 2003 UTC (20 years, 8 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Concept analysis is now implemented for Times as well as Tries.
Time plots now have user-specifiable titles.
Removed old &logthis calls and unused code.

    1: # The LearningOnline Network with CAPA
    2: #
    3: 
    4: # $Id: lonproblemanalysis.pm,v 1.37 2003/10/14 21:58:25 matthew Exp $
    5: #
    6: # Copyright Michigan State University Board of Trustees
    7: #
    8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
    9: #
   10: # LON-CAPA is free software; you can redistribute it and/or modify
   11: # it under the terms of the GNU General Public License as published by
   12: # the Free Software Foundation; either version 2 of the License, or
   13: # (at your option) any later version.
   14: #
   15: # LON-CAPA is distributed in the hope that it will be useful,
   16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   18: # GNU General Public License for more details.
   19: #
   20: # You should have received a copy of the GNU General Public License
   21: # along with LON-CAPA; if not, write to the Free Software
   22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   23: #
   24: # /home/httpd/html/adm/gpl.txt
   25: #
   26: # http://www.lon-capa.org/
   27: #
   28: 
   29: package Apache::lonproblemanalysis;
   30: 
   31: use strict;
   32: use Apache::lonnet();
   33: use Apache::loncommon();
   34: use Apache::lonhtmlcommon();
   35: use Apache::loncoursedata();
   36: use Apache::lonstatistics;
   37: use Apache::lonlocal;
   38: use HTML::Entities();
   39: 
   40: sub BuildProblemAnalysisPage {
   41:     my ($r,$c)=@_;
   42:     $r->print('<h2>'.&mt('Option Response Problem Analysis').'</h2>');
   43:     $r->print(&CreateInterface());
   44:     #
   45:     my @Students = @Apache::lonstatistics::Students;
   46:     #
   47:     if (exists($ENV{'form.updatecaches'}) ||
   48:         (exists($ENV{'form.firstanalysis'}) &&
   49:          $ENV{'form.firstanalysis'} ne 'no')) {
   50:         &Apache::lonstatistics::Gather_Full_Student_Data($r);
   51:     }
   52:     if (! exists($ENV{'form.firstanalysis'})) {
   53:         $r->print('<input type="hidden" name="firstanalysis" value="yes" />');
   54:     } else {
   55:         $r->print('<input type="hidden" name="firstanalysis" value="no" />');
   56:     }
   57:     if (exists($ENV{'form.problemchoice'}) && 
   58:         ! exists($ENV{'form.SelectAnother'})) {
   59:         $r->print('<input type="submit" name="ProblemAnalysis" value="'.
   60:                   &mt('Analyze Problem Again').'" />');
   61:         $r->print('&nbsp;'x5);
   62:         $r->print('<input type="submit" name="ClearCache" value="'.
   63:                   &mt('Clear Caches').'" />');
   64:         $r->print('&nbsp;'x5);
   65:         $r->print('<input type="submit" name="updatecaches" value="'.
   66:                   &mt('Update Student Data').'" />');
   67:         $r->print('&nbsp;'x5);
   68:         $r->print('<input type="hidden" name="problemchoice" value="'.
   69:                   $ENV{'form.problemchoice'}.'" />');
   70:         $r->print('<input type="submit" name="SelectAnother" value="'.
   71:                   &mt('Choose a different resource').'" />');
   72:         $r->print('&nbsp;'x5);
   73:         #
   74:         $r->print('<hr />');
   75:         #
   76:         my ($symb,$part,$resid) = &get_problem_symb(
   77:                      &Apache::lonnet::unescape($ENV{'form.problemchoice'})
   78:                                            );
   79:         #
   80:         my $resource = &get_resource_from_symb($symb);
   81:         if (defined($resource)) {
   82:             my %Data = &get_problem_data($resource->{'src'});
   83:             my $ORdata = $Data{$part.'.'.$resid};
   84:             ##
   85:             ## Render the problem
   86:             my $base;
   87:             ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|);
   88:             $base = "http://".$ENV{'SERVER_NAME'}.$base;
   89:             my $rendered_problem = 
   90:                 &Apache::lonnet::ssi_body($resource->{'src'});
   91:             $rendered_problem =~ s/<\s*form\s*/<nop /g;
   92:             $rendered_problem =~ s|(<\s*/form\s*>)|<\/nop>|g;
   93:             $r->print('<table bgcolor="ffffff"><tr><td>'.
   94:                       '<base href="'.$base.'" />'.
   95:                       $rendered_problem.
   96:                       '</td></tr></table>');
   97:             ##
   98:             ## Analyze the problem
   99:             my $PerformanceData = 
  100:                 &Apache::loncoursedata::get_optionresponse_data
  101:                                            (\@Students,$symb,$resid);
  102:             if (defined($PerformanceData) && 
  103:                 ref($PerformanceData) eq 'ARRAY') {
  104:                 if ($ENV{'form.AnalyzeOver'} eq 'Tries') {
  105:                     my $analysis_html = &tries_analysis($PerformanceData,
  106:                                                          $ORdata);
  107:                     $r->print($analysis_html);
  108:                 } elsif ($ENV{'form.AnalyzeOver'} eq 'Time') {
  109:                     my $analysis_html = &time_analysis($PerformanceData,
  110:                                                          $ORdata);
  111:                 $r->print($analysis_html);
  112:                 } else {
  113:                     $r->print('<h2>'.
  114:                               &mt('The analysis you have selected is '.
  115:                                          'not supported at this time').
  116:                               '</h2>');
  117:                 }
  118:             } else {
  119:                 $r->print('<h2>'.
  120:                           &mt('There is no student data for this problem.').
  121:                           '</h2>');
  122:             }
  123:         } else {
  124:             $r->print('resource is undefined');
  125:         }
  126:         $r->print('<hr />');
  127:     } else {
  128:         $r->print('<input type="submit" name="ProblemAnalysis" value="'.
  129:                   &mt('Analyze Problem').'" />');
  130:         $r->print('&nbsp;'x5);
  131:         $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
  132:         $r->print(&OptionResponseProblemSelector());
  133:     }
  134: }
  135: 
  136: 
  137: #########################################################
  138: #########################################################
  139: ##
  140: ##      Misc interface routines use by analysis code
  141: ##
  142: #########################################################
  143: #########################################################
  144: sub build_foil_index {
  145:     my ($ORdata) = @_;
  146:     my %Foildata = %{$ORdata->{'Foils'}};
  147:     my @Foils = sort(keys(%Foildata));
  148:     my %Concepts;
  149:     foreach my $foilid (@Foils) {
  150:         push(@{$Concepts{$Foildata{$foilid}->{'Concept'}}},
  151:              $foilid);
  152:     }
  153:     undef(@Foils);
  154:     # Having gathered the concept information in a hash, we now translate it
  155:     # into an array because we need to be consistent about order.
  156:     # Also put the foils in order, too.
  157:     my $sortfunction = sub {
  158:         my %Numbers = (one   => 1,
  159:                        two   => 2,
  160:                        three => 3,
  161:                        four  => 4,
  162:                        five  => 5,
  163:                        six   => 6,
  164:                        seven => 7,
  165:                        eight => 8,
  166:                        nine  => 9,
  167:                        ten   => 10,);
  168:         my $a1 = $a; 
  169:         my $b1 = $b;
  170:         if (exists($Numbers{$a})) {
  171:             $a1 = $Numbers{$a};
  172:         }
  173:         if (exists($Numbers{$b})) {
  174:             $b1 = $Numbers{$b};
  175:         }
  176:         $a1 cmp $b1;
  177:     };
  178:     my @Concepts;
  179:     foreach my $concept (sort $sortfunction (keys(%Concepts))) {
  180:         push(@Concepts,{name => $concept,
  181:                         foils => [@{$Concepts{$concept}}]});
  182:         push(@Foils,(@{$Concepts{$concept}}));
  183:     }
  184:     #
  185:     # Build up the table of row labels.
  186:     my $table = '<table border="1" >'."\n";
  187:     $table .= '<tr>'.
  188:         '<th>'.&mt('Concept Number').'</th>'.
  189:         '<th>'.&mt('Concept').'</th>'.
  190:         '<th>'.&mt('Foil Number').'</th>'.
  191:         '<th>'.&mt('Foil Name').'</th>'.
  192:         '<th>'.&mt('Foil Text').'</th>'.
  193:         '<th>'.&mt('Correct Value').'</th>'.
  194:         "</tr>\n";
  195:     my $conceptindex = 1;
  196:     my $foilindex = 1;
  197:     foreach my $concept (@Concepts) {
  198:         my @FoilsInConcept = @{$concept->{'foils'}};
  199:         my $firstfoil = shift(@FoilsInConcept);
  200:         $table .= '<tr>'.
  201:             '<td>'.$conceptindex.'</td>'.
  202:             '<td>'.$concept->{'name'}.'</td>'.
  203:             '<td>'.$foilindex++.'</td>'.
  204:             '<td>'.$Foildata{$firstfoil}->{'name'}.'</td>'.
  205:             '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
  206:             '<td>'.$Foildata{$firstfoil}->{'value'}.'</td>'.
  207:             "</tr>\n";
  208:         foreach my $foilid (@FoilsInConcept) {
  209:             $table .= '<tr>'.
  210:                 '<td></td>'.
  211:                 '<td></td>'.
  212:                 '<td>'.$foilindex.'</td>'.
  213:                 '<td>'.$Foildata{$foilid}->{'name'}.'</td>'.
  214:                 '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
  215:                 '<td>'.$Foildata{$foilid}->{'value'}.'</td>'.
  216:                 "</tr>\n";
  217:         } continue {
  218:             $foilindex++;
  219:         }
  220:     } continue {
  221:         $conceptindex++;
  222:     }
  223:     $table .= "</table>\n";
  224:     return ($table,\@Foils,\@Concepts);
  225: }
  226: 
  227: #########################################################
  228: #########################################################
  229: ##
  230: ##         Tries Analysis
  231: ##
  232: #########################################################
  233: #########################################################
  234: sub tries_analysis {
  235:     my ($PerformanceData,$ORdata) = @_;
  236:     my $mintries = 1;
  237:     my $maxtries = $ENV{'form.NumPlots'};
  238:     my %ResponseData = &analyze_option_data_by_tries($PerformanceData,
  239:                                                      $mintries,$maxtries);
  240:     my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
  241:     #
  242:     # Compute the data neccessary to make the plots
  243:     my @PlotData;
  244:     my $xlabel;
  245:     if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
  246:         $xlabel = 'Foil Number';
  247:         foreach my $foilid (@$Foils) {
  248:             for (my $i=$mintries;$i<=$maxtries;$i++) {
  249:                 #
  250:                 # Gather the per-attempt data
  251:                 my $percent;
  252:                 if ($ResponseData{$foilid}->[$i]->{'total'} == 0) {
  253:                     $percent = 0;
  254:                 } else {
  255:                     $percent = $ResponseData{$foilid}->[$i]->{'correct'} /
  256:                         $ResponseData{$foilid}->[$i]->{'total'};
  257:                 }
  258:                 push (@{$PlotData[$i]->{'total'}},
  259:                                  $ResponseData{$foilid}->[$i]->{'total'});
  260:                 push (@{$PlotData[$i]->{'good'}},100 * $percent);
  261:                 push (@{$PlotData[$i]->{'bad'}}, 100 *(1-$percent));
  262:             }
  263:         }
  264:     } else {
  265:         # Concept analysis
  266:         $xlabel = 'Concept Number';
  267:         foreach my $concept (@$Concepts) {
  268:             for (my $i=$mintries;$i<=$maxtries;$i++) {
  269:                 #
  270:                 # Gather the per-attempt data
  271:                 my ($correct,$incorrect,$total);
  272:                 foreach my $foil (@{$concept->{'foils'}}) {
  273:                     $correct   += $ResponseData{$foil}->[$i]->{'correct'};
  274:                     $incorrect += $ResponseData{$foil}->[$i]->{'incorrect'};
  275:                     $total     += $ResponseData{$foil}->[$i]->{'total'};
  276:                 }
  277:                 push (@{$PlotData[$i]->{'correct'}},  $correct);
  278:                 push (@{$PlotData[$i]->{'incorrect'}},$incorrect);
  279:                 push (@{$PlotData[$i]->{'total'}},    $total);
  280:                 my $percent;
  281:                 if ($total == 0) {
  282:                     $percent = 0;
  283:                 } else {
  284:                     $percent = $correct/$total;
  285:                 }
  286:                 push (@{$PlotData[$i]->{'good'}},100*$percent);
  287:                 push (@{$PlotData[$i]->{'bad'}},100*(1-$percent));
  288:             }
  289:         }
  290:     }
  291:     # 
  292:     # Build a table for the plots
  293:     $table .= "<table>\n";
  294:     my @Plots;
  295:     for (my $i=$mintries;$i<=$maxtries;$i++) {
  296:         my $minstu = $PlotData[$i]->{'total'}->[0];
  297:         my $maxstu = $PlotData[$i]->{'total'}->[0];
  298:         foreach my $count (@{$PlotData[$i]->{'total'}}) {
  299:             if ($minstu > $count) {
  300:                 $minstu = $count;
  301:             }
  302:             if ($maxstu < $count) {
  303:                 $maxstu = $count;
  304:             }
  305:         }
  306:         $maxstu = 0 if (! $maxstu);
  307:         $minstu = 0 if (! $minstu);
  308:         my $title;
  309:         if ($maxstu == $minstu) {
  310:             $title = 'Attempt '.$i.', '.$maxstu.' students';
  311:         } else {
  312:             $title = 'Attempt '.$i.', '.$minstu.'-'.$maxstu.' students';
  313:         }
  314:         my $graphlink = &Apache::loncommon::DrawGraph($title,
  315:                                                       $xlabel,
  316:                                                       'Percent Correct',
  317:                                                       100,
  318:                                                       $PlotData[$i]->{'good'},
  319:                                                       $PlotData[$i]->{'bad'});
  320:         push(@Plots,$graphlink);
  321:     }
  322:     #
  323:     # Should this be something the user can set?  Too many dialogs!
  324:     my $plots_per_row = 2;
  325:     while (my $plotlink = shift(@Plots)) {
  326:         $table .= '<tr><td>'.$plotlink.'</td>';
  327:         for (my $i=1;$i<$plots_per_row;$i++) {
  328:             if ($plotlink = shift(@Plots)) {
  329:                 $table .= '<td>'.$plotlink.'</td>';
  330:             } else {
  331:                 $table .= '<td></td>';
  332:             }
  333:         }
  334:         $table .= "</tr>\n";
  335:     }
  336:     $table .= "</table>\n";
  337:     return ($table);
  338: }
  339: 
  340: sub analyze_option_data_by_tries {
  341:     my ($PerformanceData,$mintries,$maxtries) = @_;
  342:     my %Trydata;
  343:     $mintries = 1         if (! defined($mintries) || $mintries < 1);
  344:     $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
  345:     foreach my $row (@$PerformanceData) {
  346:         next if (! defined($row));
  347:         my ($grading,$submission,$time,$tries) = @$row;
  348:         my @Foilgrades = split('&',$grading);
  349:         my @Foilsubs   = split('&',$submission);
  350:         for (my $numtries = 1; $numtries <= $maxtries; $numtries++) {
  351:             if ($tries == $numtries) {
  352:                 foreach my $foilgrade (@Foilgrades) {
  353:                     my ($foilid,$correct) = split('=',$foilgrade);
  354:                     if ($correct) {
  355:                         $Trydata{$foilid}->[$numtries]->{'correct'}++;
  356:                     } else {
  357:                         $Trydata{$foilid}->[$numtries]->{'incorrect'}++;
  358:                     }                        
  359:                 }
  360:             }
  361:         }
  362:     }
  363:     foreach my $foilid (keys(%Trydata)) {
  364:         foreach my $tryhash (@{$Trydata{$foilid}}) {
  365:             next if ((! exists($tryhash->{'correct'}) && 
  366:                       ! exists($tryhash->{'incorrect'})) ||
  367:                      ($tryhash->{'correct'} < 1 &&
  368:                       $tryhash->{'incorrect'} < 1));
  369:             $tryhash->{'total'} = $tryhash->{'correct'} + 
  370:                 $tryhash->{'incorrect'};
  371:         }
  372:     }
  373:     return %Trydata;
  374: }
  375: 
  376: #########################################################
  377: #########################################################
  378: ##
  379: ##                 Time Analysis
  380: ##
  381: #########################################################
  382: #########################################################
  383: sub time_analysis {
  384:     my ($PerformanceData,$ORdata) = @_;
  385:     my $num_plots = $ENV{'form.NumPlots'};
  386:     my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
  387:     my $num_data = scalar(@$PerformanceData)-1;
  388:     my $percent = sprintf('%2f',100/$num_plots);
  389:     $table .= "<table>\n";
  390:     for (my $i=0;$i<$num_plots;$i++) {
  391:         my $starttime = &Apache::lonhtmlcommon::get_date_from_form
  392:             ('startdate_'.$i);
  393:         my $endtime = &Apache::lonhtmlcommon::get_date_from_form
  394:             ('enddate_'.$i);
  395:         my ($begin_index,$end_index,$plottitle,$plothtml,$data);
  396:         if (! defined($starttime) || ! defined($endtime)) {
  397:             $begin_index = $i*int($num_data/$num_plots);
  398:             $end_index = ($i+1)*int($num_data/$num_plots);
  399:             my $lownum  = sprintf('%2.1f',$i*$percent);
  400:             $lownum =~ s/(\.0)$//;
  401:             my $highnum = sprintf('%2.1f',($i+1)*$percent);
  402:             $highnum =~ s/(\.0)$//;
  403:             $plottitle = $lownum.'% to '.$highnum.'% of submissions';
  404:         } else {
  405:             my $j;
  406:             while (++$j < scalar(@$PerformanceData)) {
  407:                 last if ($PerformanceData->[$j]->[2] > $starttime);
  408:             }
  409:             $begin_index = $j;
  410:             while (++$j < scalar(@$PerformanceData)) {
  411:                 last if ($PerformanceData->[$j]->[2] > $endtime);
  412:             }
  413:             $end_index = $j;
  414:             $plottitle = $ENV{'form.plottitle_'.$i};
  415:         }
  416:         ($plothtml,$starttime,$endtime,$data) = 
  417:             &analyze_option_data_by_time($PerformanceData,
  418:                                          $begin_index,$end_index,
  419:                                          $plottitle,
  420:                                          @$Concepts);
  421:         my $startdateform = &Apache::lonhtmlcommon::date_setter
  422:             ('Statistics','startdate_'.$i,$starttime);
  423:         my $enddateform = &Apache::lonhtmlcommon::date_setter
  424:             ('Statistics','enddate_'.$i,$endtime);
  425:         $table.="<tr><td>".$plothtml.'</td><td align="left" valign="top">'.
  426:             "<b>Start Time</b>: &nbsp;".$startdateform."<br />".
  427:             "<b>End Time</b>&nbsp;&nbsp;: "."&nbsp;".$enddateform."<br />".
  428:             '<b>Plot Title</b>&nbsp;&nbsp;:'.
  429:             '<input type="text" size="30" name="plottitle_'.$i.'" value="'.
  430:                   &HTML::Entities::encode($plottitle).'" /><br />'.
  431:             "</td></tr>\n";
  432:     }
  433:     $table .="</table>\n";
  434:     return $table;
  435: }
  436: 
  437: sub analyze_option_data_by_time {
  438:     my ($PerformanceData,$begin_index,$end_index,$description,@Concepts) = @_;
  439:     my %TimeData;
  440:     #
  441:     # Get the start and end times for this segment of the plot
  442:     my $starttime = $PerformanceData->[$begin_index]->[2];
  443:     my $endtime   = $PerformanceData->[$end_index  ]->[2];
  444:     #
  445:     # Compute the number getting the foils correct or incorrects
  446:     for (my $i=$begin_index;$i<=$end_index;$i++) {
  447:         my $row = $PerformanceData->[$i];
  448:         next if (! defined($row));
  449:         my ($grading,$submission,$time,$tries) = @$row;
  450:         my @Foilgrades = split('&',$grading);
  451:         my @Foilsubs   = split('&',$submission);
  452:         foreach my $foilgrade (@Foilgrades) {
  453:             my ($foilid,$correct) = split('=',$foilgrade);
  454:             if ($correct) {
  455:                 $TimeData{$foilid}->{'correct'}++;
  456:             } else {
  457:                 $TimeData{$foilid}->{'incorrect'}++;
  458:             }
  459:         }
  460:     }
  461:     #
  462:     # Compute the total and percent correct
  463:     my @Plotdata1;
  464:     my @Plotdata2;
  465:     foreach my $concept (@Concepts) {
  466:         my ($correct,$incorrect,$total);
  467:         foreach my $foilid (@{$concept->{'foils'}}) {
  468:             if (! exists($TimeData{$foilid}->{'correct'})) {
  469:                 $TimeData{$foilid}->{'correct'} = 0;
  470:             }
  471:             if (! exists($TimeData{$foilid}->{'incorrect'})) {
  472:                 $incorrect = 0;
  473:                 $TimeData{$foilid}->{'incorrect'} = 0;
  474:             }
  475:             $correct   += $TimeData{$foilid}->{'correct'};
  476:             $incorrect += $TimeData{$foilid}->{'incorrect'};
  477:             $total     += $TimeData{$foilid}->{'correct'}+
  478:                 $TimeData{$foilid}->{'incorrect'};
  479:             $TimeData{$foilid}->{'total'} = $TimeData{$foilid}->{'correct'} +
  480:                 $TimeData{$foilid}->{'incorrect'};
  481:             my $percent;
  482:             if ($TimeData{$foilid}->{'total'} == 0) {
  483:                 $percent = 0;
  484:             } else {
  485:                 $percent = $TimeData{$foilid}->{'correct'} / 
  486:                     $TimeData{$foilid}->{'total'};
  487:             }
  488:             $TimeData{$foilid}->{'percent_corr'} = 100 * $percent;
  489:             if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
  490:                 push (@Plotdata1,    $TimeData{$foilid}->{'percent_corr'});
  491:                 push (@Plotdata2,100-$TimeData{$foilid}->{'percent_corr'});
  492:             }
  493:         }
  494:         if ($ENV{'form.AnalyzeAs'} ne 'Foils') {
  495:             if ($total == 0) {
  496:                 push (@Plotdata1,0);
  497:                 push (@Plotdata2,100);
  498:             } else {
  499:                 push (@Plotdata1,100 *   $correct / $total);
  500:                 push (@Plotdata2,100 * (1-$correct / $total));
  501:             }
  502:         }
  503:     }
  504:     #
  505:     # Create the plot
  506:     my $xlabel;
  507:     if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
  508:         $xlabel = 'Foil Number';
  509:     } else {
  510:         $xlabel = 'Concept Number';
  511:     }
  512:     my $graphlink = &Apache::loncommon::DrawGraph
  513:         ($description,#'Time Interval Analysis',
  514:          $xlabel,
  515:          'Percent Correct / Incorrect',
  516:          100,
  517:          \@Plotdata1,\@Plotdata2);
  518:     #
  519:     return ($graphlink,$starttime,$endtime,\%TimeData);
  520: }
  521: 
  522: #########################################################
  523: #########################################################
  524: ##
  525: ##             Interface 
  526: ##
  527: #########################################################
  528: #########################################################
  529: sub CreateInterface {
  530:     ##
  531:     ## Environment variable initialization
  532:     if (! exists$ENV{'form.AnalyzeOver'}) {
  533:         $ENV{'form.AnalyzeOver'} = 'Tries';
  534:     }
  535:     ##
  536:     ## Build the menu
  537:     my $Str = '';
  538:     $Str .= '<table cellspacing="5">'."\n";
  539:     $Str .= '<tr>';
  540:     $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
  541:     $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
  542: #    $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
  543:     $Str .= '<td align="center">&nbsp;</td>';
  544:     $Str .= '</tr>'."\n";
  545:     ##
  546:     ## 
  547:     $Str .= '<tr><td align="center">'."\n";
  548:     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
  549:     $Str .= '</td>';
  550:     #
  551:     $Str .= '<td align="center">';
  552:     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
  553:     $Str .= '</td>';
  554:     #
  555: #    $Str .= '<td align="center">';
  556:     my $only_seq_with_assessments = sub { 
  557:         my $s=shift;
  558:         if ($s->{'num_assess'} < 1) { 
  559:             return 0;
  560:         } else { 
  561:             return 1;
  562:         }
  563:     };
  564:     &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
  565:                                               $only_seq_with_assessments);
  566:     ##
  567:     ##
  568:     $Str .= '<td>';
  569:     { # These braces are here to organize the code, not scope it.
  570:         {
  571:             $Str .= '<nobr>'.&mt('Analyze Over ');
  572:             $Str .='<select name="AnalyzeOver" >';
  573:             $Str .= '<option value="Tries" ';
  574:             if (! exists($ENV{'form.AnalyzeOver'}) || 
  575:                 $ENV{'form.AnalyzeOver'} eq 'Tries'){
  576:                 # Default to Tries
  577:                 $Str .= ' selected ';
  578:             }
  579:             $Str .= '>'.&mt('Tries').'</option>';
  580:             $Str .= '<option value="Time" ';
  581:             $Str .= ' selected ' if ($ENV{'form.AnalyzeOver'} eq 'Time');
  582:             $Str .= '>'.&mt('Time').'</option>';
  583:             $Str .= '</select></nobr><br />';
  584:         }
  585:         {
  586:             $Str .= '<nobr>'.&mt('Analyze as ');
  587:             $Str .='<select name="AnalyzeAs" >';
  588:             $Str .= '<option value="Concepts" ';
  589:             if (! exists($ENV{'form.AnalyzeAs'}) || 
  590:                 $ENV{'form.AnalyzeAs'} eq 'Concepts'){
  591:                 # Default to Concepts
  592:                 $Str .= ' selected ';
  593:             }
  594:             $Str .= '>'.&mt('Concepts').'</option>';
  595:             $Str .= '<option value="Foils" ';
  596:             $Str .= ' selected ' if ($ENV{'form.AnalyzeAs'} eq 'Foils');
  597:             $Str .= '>'.&mt('Foils').'</option>';
  598:             $Str .= '</select></nobr><br />';
  599:         }
  600:         {
  601:             $Str .= '<br /><nobr>'.&mt('Number of Plots:');
  602:             $Str .= '<select name="NumPlots">';
  603:             if (! exists($ENV{'form.NumPlots'}) 
  604:                 || $ENV{'form.NumPlots'} < 1 
  605:                 || $ENV{'form.NumPlots'} > 20) {
  606:                 $ENV{'form.NumPlots'} = 5;
  607:             }
  608:             foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
  609:                 $Str .= '<option value="'.$i.'" ';
  610:                 if ($ENV{'form.NumPlots'} == $i) { $Str.=' selected '; }
  611:                 $Str .= '>'.$i.'</option>';
  612:             }
  613:             $Str .= '</select></nobr>';
  614:         }
  615:     }
  616:     $Str .= '</td>';
  617:     ##
  618:     ##
  619:     $Str .= '</tr>'."\n";
  620:     $Str .= '</table>'."\n";
  621:     return ($Str);
  622: }
  623: 
  624: sub OptionResponseProblemSelector {
  625:     my $Str;
  626:     $Str = "\n<table>\n";
  627:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  628:         next if ($seq->{'num_assess'}<1);
  629:         my $seq_str = '';
  630:         foreach my $res (@{$seq->{'contents'}}) {
  631:             next if ($res->{'type'} ne 'assessment');
  632:             foreach my $part (@{$res->{'parts'}}) {
  633:                 my $partdata = $res->{'partdata'}->{$part};
  634:                 if (! exists($partdata->{'option'}) || 
  635:                     $partdata->{'option'} == 0) {
  636:                     next;
  637:                 }
  638:                 for (my $i=0;$i<scalar(@{$partdata->{'ResponseTypes'}});$i++){
  639:                     my $respid = $partdata->{'ResponseIds'}->[$i];
  640:                     my $resptype = $partdata->{'ResponseTypes'}->[$i];
  641:                     if ($resptype eq 'option') {
  642:                         my $value = &Apache::lonnet::escape($res->{'symb'}.':'.$part.':'.$respid);
  643:                         my $checked = '';
  644:                         if ($ENV{'form.problemchoice'} eq $value) {
  645:                             $checked = 'checked ';
  646:                         }
  647:                         $seq_str .= '<tr><td>'.
  648:   '<input type="radio" name="problemchoice" value="'.$value.'" '.$checked.'/>'.
  649:   '</td><td>'.
  650:   '<a href="'.$res->{'src'}.'">'.$res->{'title'}.'</a> ';
  651:                         if ($partdata->{'option'} > 1) {
  652:                             $seq_str .= &mt('response').' '.$respid;
  653:                         }
  654:                         $seq_str .= "</td></tr>\n";
  655:                     }
  656:                 }
  657:             }
  658:         }
  659:         if ($seq_str ne '') {
  660:             $Str .= '<tr><td>&nbsp</td><td><b>'.$seq->{'title'}.'</b></td>'.
  661:                 "</tr>\n".$seq_str;
  662:         }
  663:     }
  664:     $Str .= "</table>\n";
  665:     return $Str;
  666: }
  667: 
  668: #########################################################
  669: #########################################################
  670: ##
  671: ##              Misc functions
  672: ##
  673: #########################################################
  674: #########################################################
  675: sub get_problem_symb {
  676:     my $problemstring = shift();
  677:     my ($symb,$partid,$resid) = ($problemstring=~ /^(.*):([^:]*):([^:]*)$/);
  678:     return ($symb,$partid,$resid);
  679: }
  680: 
  681: sub get_resource_from_symb {
  682:     my ($symb) = @_;
  683:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  684:         foreach my $res (@{$seq->{'contents'}}) {
  685:             if ($res->{'symb'} eq $symb) {
  686:                 return $res;
  687:             }
  688:         }
  689:     }
  690:     return undef;
  691: }
  692: 
  693: sub get_problem_data {
  694:     my ($url) = @_;
  695:     my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze'));
  696:     (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
  697:     my %Answer;
  698:     %Answer=&Apache::lonnet::str2hash($Answ);
  699:     my %Partdata;
  700:     foreach my $part (@{$Answer{'parts'}}) {
  701:         while (my($key,$value) = each(%Answer)) {
  702:             next if ($key !~ /^$part/);
  703:             $key =~ s/^$part\.//;
  704:             if (ref($value) eq 'ARRAY') {
  705:                 if ($key eq 'options') {
  706:                     $Partdata{$part}->{'Options'}=$value;
  707:                 } elsif ($key eq 'concepts') {
  708:                     $Partdata{$part}->{'Concepts'}=$value;
  709:                 } elsif ($key =~ /^concept\.(.*)$/) {
  710:                     my $concept = $1;
  711:                     foreach my $foil (@$value) {
  712:                         $Partdata{$part}->{'Foils'}->{$foil}->{'Concept'}=
  713:                                                                       $concept;
  714:                     }
  715:                 }
  716:             } else {
  717:                 $value =~ s/^\s*//g;
  718:                 $value =~ s/\s*$//g;
  719:                 if ($key=~ /^foil\.text\.(.*)$/) {
  720:                     my $foil = $1;
  721:                     $Partdata{$part}->{'Foils'}->{$foil}->{'name'}=$foil;
  722:                     $Partdata{$part}->{'Foils'}->{$foil}->{'text'}=$value;
  723:                 } elsif ($key =~ /^foil\.value\.(.*)$/) {
  724:                     my $foil = $1;
  725:                     $Partdata{$part}->{'Foils'}->{$foil}->{'value'}=$value;
  726:                 }
  727:             }
  728:         }
  729:     }
  730:     return %Partdata;
  731: }
  732: 
  733: 1;
  734: 
  735: __END__

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