File:  [LON-CAPA] / loncom / interface / statistics / lonproblemanalysis.pm
Revision 1.34: download - view: text, annotated - select for diffs
Mon Oct 13 21:12:56 2003 UTC (20 years, 8 months ago) by matthew
Branches: MAIN
CVS tags: HEAD
Added date specification ability to time analysis.
Makes the interface seem really ugly.  Advice would be appreciated.

    1: # The LearningOnline Network with CAPA
    2: #
    3: 
    4: # $Id: lonproblemanalysis.pm,v 1.34 2003/10/13 21:12:56 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: 
   39: sub BuildProblemAnalysisPage {
   40:     my ($r,$c)=@_;
   41:     $r->print('<h2>'.&mt('Option Response Problem Analysis').'</h2>');
   42:     $r->print(&CreateInterface());
   43:     #
   44:     my @Students = @Apache::lonstatistics::Students;
   45:     #
   46:     if (exists($ENV{'form.updatecaches'}) ||
   47:         (exists($ENV{'form.firstanalysis'}) &&
   48:          $ENV{'form.firstanalysis'} ne 'no')) {
   49:         &Apache::lonstatistics::Gather_Full_Student_Data($r);
   50:     }
   51:     if (! exists($ENV{'form.firstanalysis'})) {
   52:         $r->print('<input type="hidden" name="firstanalysis" value="yes" />');
   53:     } else {
   54:         $r->print('<input type="hidden" name="firstanalysis" value="no" />');
   55:     }
   56:     if (exists($ENV{'form.problemchoice'}) && 
   57:         ! exists($ENV{'form.SelectAnother'})) {
   58:         $r->print('<input type="submit" name="ProblemAnalysis" value="'.
   59:                   &mt('Analyze Problem Again').'" />');
   60:         $r->print('&nbsp;'x5);
   61:         $r->print('<input type="submit" name="ClearCache" value="'.
   62:                   &mt('Clear Caches').'" />');
   63:         $r->print('&nbsp;'x5);
   64:         $r->print('<input type="submit" name="updatecaches" value="'.
   65:                   &mt('Update Student Data').'" />');
   66:         $r->print('&nbsp;'x5);
   67:         $r->print('<input type="hidden" name="problemchoice" value="'.
   68:                   $ENV{'form.problemchoice'}.'" />');
   69:         $r->print('<input type="submit" name="SelectAnother" value="'.
   70:                   &mt('Choose a different resource').'" />');
   71:         $r->print('&nbsp;'x5);
   72:         #
   73:         $r->print('<hr />');
   74:         #
   75:         my ($symb,$part,$resid) = &get_problem_symb(
   76:                      &Apache::lonnet::unescape($ENV{'form.problemchoice'})
   77:                                            );
   78:         #
   79:         my $resource = &get_resource_from_symb($symb);
   80:         if (defined($resource)) {
   81:             my %Data = &get_problem_data($resource->{'src'});
   82:             my $ORdata = $Data{$part.'.'.$resid};
   83:             ##
   84:             ## Render the problem
   85:             my $base;
   86:             ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|);
   87:             $base = "http://".$ENV{'SERVER_NAME'}.$base;
   88:             my $rendered_problem = 
   89:                 &Apache::lonnet::ssi_body($resource->{'src'});
   90:             $rendered_problem =~ s/<\s*form\s*/<nop /g;
   91:             $rendered_problem =~ s|(<\s*/form\s*>)|<\/nop>|g;
   92:             $r->print('<table bgcolor="ffffff"><tr><td>'.
   93:                       '<base href="'.$base.'" />'.
   94:                       $rendered_problem.
   95:                       '</td></tr></table>');
   96:             ##
   97:             ## Analyze the problem
   98:             my $PerformanceData = 
   99:                 &Apache::loncoursedata::get_optionresponse_data
  100:                                            (\@Students,$symb,$resid);
  101:             if (defined($PerformanceData) && 
  102:                 ref($PerformanceData) eq 'ARRAY') {
  103:                 if ($ENV{'form.AnalyzeBy'} eq 'Tries') {
  104:                     my $analysis_html = &tries_analysis($PerformanceData,
  105:                                                          $ORdata);
  106:                     $r->print($analysis_html);
  107:                 } elsif ($ENV{'form.AnalyzeBy'} eq 'Time') {
  108:                     my $analysis_html = &time_analysis($PerformanceData,
  109:                                                          $ORdata);
  110:                 $r->print($analysis_html);
  111:                 } else {
  112:                     $r->print('<h2>'.
  113:                               &mt('The analysis you have selected is '.
  114:                                          'not supported at this time').
  115:                               '</h2>');
  116:                 }
  117:             } else {
  118:                 $r->print('<h2>'.
  119:                           &mt('There is no student data for this problem.').
  120:                           '</h2>');
  121:             }
  122:         } else {
  123:             $r->print('resource is undefined');
  124:         }
  125:         $r->print('<hr />');
  126:     } else {
  127:         $r->print('<input type="submit" name="ProblemAnalysis" value="'.
  128:                   &mt('Analyze Problem').'" />');
  129:         $r->print('&nbsp;'x5);
  130:         $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
  131:         $r->print(&OptionResponseProblemSelector());
  132:     }
  133: }
  134: 
  135: 
  136: #########################################################
  137: #########################################################
  138: ##
  139: ##      Misc interface routines use by analysis code
  140: ##
  141: #########################################################
  142: #########################################################
  143: sub build_foil_index {
  144:     my ($ORdata) = @_;
  145:     my @Foils = sort(keys(%{$ORdata->{'Foiltext'}}));
  146:     my %Row_Label;
  147:     foreach my $foilid (@Foils) {
  148:         my $value = $ORdata->{'Foiltext'}->{$foilid};
  149:         $Row_Label{$foilid} = $ORdata->{'Foiltext'}->{$foilid};
  150:     }
  151:     #
  152:     # Build up the table of row labels.
  153:     my $table = '<table border="1" >'."\n";
  154:     $table .= '<tr><th>'.&mt('Foil Number').'</th>'.
  155:         '<th>'.&mt('Foil Text')."</th></tr>\n";
  156:     my $index = 1;
  157:     foreach my $foilid (@Foils) {
  158:         $table .= '<tr><td>'.$index.'</td>'.
  159:             '<td>'.$Row_Label{$foilid}."</td></tr>\n";
  160:     } continue {
  161:         $index++;
  162:     }
  163:     $table .= "</table>\n";
  164:     return ($table,@Foils);
  165: }
  166: 
  167: #########################################################
  168: #########################################################
  169: ##
  170: ##         Tries Analysis
  171: ##
  172: #########################################################
  173: #########################################################
  174: sub tries_analysis {
  175:     my ($PerformanceData,$ORdata) = @_;
  176:     my $mintries = 1;
  177:     my $maxtries = $ENV{'form.NumPlots'};
  178:     my %ResponseData = &analyze_option_data_by_tries($PerformanceData,
  179:                                                  $mintries,$maxtries);
  180:     my ($table,@Foils) = &build_foil_index($ORdata);
  181:     #
  182:     # Compute the data neccessary to make the plots
  183:     my @PlotData;
  184:     my @CumulativePlotData;
  185:     foreach my $foilid (@Foils) {
  186:         for (my $i=$mintries;$i<=$maxtries;$i++) {
  187:             #
  188:             # Gather the per-attempt data
  189:             push (@{$PlotData[$i]->{'good'}},
  190:                   $ResponseData{$foilid}->[$i]->{'percent_corr'});
  191:             push (@{$PlotData[$i]->{'bad'}},
  192:                   100-$ResponseData{$foilid}->[$i]->{'percent_corr'});
  193:             #
  194:             # Someday we may need the cumulative data and I think
  195:             # this is a neat way of computing it as we go along.
  196:             push (@{$CumulativePlotData[$i]->{'good'}},
  197:                   $CumulativePlotData[-1]->{'good'}+
  198:                   $ResponseData{$foilid}->[$i]->{'correct'});
  199:             push (@{$CumulativePlotData[$i]->{'bad'}},
  200:                   $CumulativePlotData[-1]->{'bad'}+
  201:                   $ResponseData{$foilid}->[$i]->{'incorrect'});
  202:         }
  203:     }
  204:     # 
  205:     # Build a table for the plots
  206:     $table .= "<table>\n";
  207:     my @Plots;
  208:     for (my $i=$mintries;$i<=$maxtries;$i++) {
  209:         my $minstu = $ResponseData{$Foils[0]}->[$i]->{'total'};
  210:         my $maxstu = $ResponseData{$Foils[0]}->[$i]->{'total'};
  211:         foreach my $foilid (@Foils) {
  212:             if ($minstu > $ResponseData{$foilid}->[$i]->{'total'}) {
  213:                 $minstu = $ResponseData{$foilid}->[$i]->{'total'};
  214:             }
  215:             if ($maxstu < $ResponseData{$foilid}->[$i]->{'total'}) {
  216:                 $maxstu = $ResponseData{$foilid}->[$i]->{'total'};
  217:             }
  218:         }
  219:         $maxstu = 0 if (! $maxstu);
  220:         $minstu = 0 if (! $minstu);
  221:         my $graphlink;
  222:         if ($maxstu == $minstu) {
  223:             $graphlink = &Apache::loncommon::DrawGraph
  224:                 ('Attempt '.$i.', '.$maxstu.' students',
  225:                  'Foil Number',
  226:                  'Percent Correct',
  227:                  100,
  228:                  $PlotData[$i]->{'good'},
  229:                  $PlotData[$i]->{'bad'});
  230:         } else {
  231:             $graphlink = &Apache::loncommon::DrawGraph
  232:                 ('Attempt '.$i.', '.$minstu.'-'.$maxstu.
  233:                  ' students',
  234:                  'Foil Number',
  235:                  'Percent Correct',
  236:                  100,
  237:                  $PlotData[$i]->{'good'},
  238:                  $PlotData[$i]->{'bad'});
  239:         }
  240:         push(@Plots,$graphlink);
  241:     }
  242:     #
  243:     # Should this be something the user can set?  Too many dialogs!
  244:     my $plots_per_row = 2;
  245:     while (my $plotlink = shift(@Plots)) {
  246:         $table .= '<tr><td>'.$plotlink.'</td>';
  247:         for (my $i=1;$i<$plots_per_row;$i++) {
  248:             if ($plotlink = shift(@Plots)) {
  249:                 $table .= '<td>'.$plotlink.'</td>';
  250:             } else {
  251:                 $table .= '<td></td>';
  252:             }
  253:         }
  254:         $table .= "</tr>\n";
  255:     }
  256:     $table .= "</table>\n";
  257:     return ($table);
  258: }
  259: 
  260: sub analyze_option_data_by_tries {
  261:     my ($PerformanceData,$mintries,$maxtries) = @_;
  262:     my %Trydata;
  263:     $mintries = 1         if (! defined($mintries) || $mintries < 1);
  264:     $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
  265:     foreach my $row (@$PerformanceData) {
  266:         next if (! defined($row));
  267:         my ($grading,$submission,$time,$tries) = @$row;
  268:         my @Foilgrades = split('&',$grading);
  269:         my @Foilsubs   = split('&',$submission);
  270:         for (my $numtries = 1; $numtries <= $maxtries; $numtries++) {
  271:             if ($tries == $numtries) {
  272:                 foreach my $foilgrade (@Foilgrades) {
  273:                     my ($foilid,$correct) = split('=',$foilgrade);
  274:                     if ($correct) {
  275:                         $Trydata{$foilid}->[$numtries]->{'correct'}++;
  276:                     } else {
  277:                         $Trydata{$foilid}->[$numtries]->{'incorrect'}++;
  278:                     }                        
  279:                 }
  280:             }
  281:         }
  282:     }
  283:     foreach my $foilid (keys(%Trydata)) {
  284:         foreach my $tryhash (@{$Trydata{$foilid}}) {
  285:             next if ((! exists($tryhash->{'correct'}) && 
  286:                       ! exists($tryhash->{'incorrect'})) ||
  287:                      ($tryhash->{'correct'} < 1 &&
  288:                       $tryhash->{'incorrect'} < 1));
  289:             $tryhash->{'total'} = $tryhash->{'correct'} + 
  290:                                         $tryhash->{'incorrect'};
  291:             $tryhash->{'percent_corr'} = 100 *
  292:                 ($tryhash->{'correct'} /
  293:                          ($tryhash->{'correct'} + $tryhash->{'incorrect'})
  294:                  );
  295:         }
  296:     }
  297:     return %Trydata;
  298: }
  299: 
  300: #########################################################
  301: #########################################################
  302: ##
  303: ##                 Time Analysis
  304: ##
  305: #########################################################
  306: #########################################################
  307: sub time_analysis {
  308:     my ($PerformanceData,$ORdata) = @_;
  309:     my $num_plots = $ENV{'form.NumPlots'};
  310:     my ($table,@Foils) = &build_foil_index($ORdata);
  311:     my $num_data = scalar(@$PerformanceData)-1;
  312:     my $percent = sprintf('%2f',100/$num_plots);
  313:     for (my $i=0;$i<$num_plots;$i++) {
  314:         my $starttime = &Apache::lonhtmlcommon::get_date_from_form
  315:             ('startdate_'.$i);
  316:         my $endtime = &Apache::lonhtmlcommon::get_date_from_form
  317:             ('enddate_'.$i);
  318:         my ($begin_index,$end_index,$plottitle,$plothtml,$data);
  319:         if (! defined($starttime) || ! defined($endtime)) {
  320:             $begin_index = $i*int($num_data/$num_plots);
  321:             $end_index = ($i+1)*int($num_data/$num_plots);
  322:             my $lownum  = sprintf('%2.1f',$i*$percent);
  323:             $lownum =~ s/(\.0)$//;
  324:             my $highnum = sprintf('%2.1f',($i+1)*$percent);
  325:             $highnum =~ s/(\.0)$//;
  326:             $plottitle = $lownum.'% to '.$highnum.'% of submissions';
  327:         } else {
  328:             my $j;
  329:             while (++$j < scalar(@$PerformanceData)) {
  330:                 last if ($PerformanceData->[$j]->[2] > $starttime);
  331:             }
  332:             $begin_index = $j;
  333:             while (++$j < scalar(@$PerformanceData)) {
  334:                 last if ($PerformanceData->[$j]->[2] > $endtime);
  335:             }
  336:             $end_index = $j;
  337:             $plottitle = 'Tries plot '.$i;
  338:         }
  339: 
  340:         ($plothtml,$starttime,$endtime,$data) = 
  341:             &analyze_option_data_by_time($PerformanceData,
  342:                                          $begin_index,$end_index,
  343:                                          $plottitle,
  344:                                          @Foils);
  345:         my $startdateform = &Apache::lonhtmlcommon::date_setter
  346:             ('Statistics','startdate_'.$i,$starttime);
  347:         my $enddateform = &Apache::lonhtmlcommon::date_setter
  348:             ('Statistics','enddate_'.$i,$endtime);
  349:         $plothtml.= "<br />\n".
  350:             "<b>Start Time</b>: "."&nbsp;".$startdateform."<br />\n".
  351:             "<b>End Time</b>&nbsp;&nbsp;: "."&nbsp;".$enddateform."<br />\n";
  352:         $table.=$plothtml;
  353:     }
  354:     return $table;
  355: }
  356: 
  357: sub analyze_option_data_by_time {
  358:     my ($PerformanceData,$begin_index,$end_index,$description,@Foils) = @_;
  359:     my %TimeData;
  360:     #
  361:     # Get the start and end times for this segment of the plot
  362:     my $starttime = $PerformanceData->[$begin_index]->[2];
  363:     my $endtime   = $PerformanceData->[$end_index  ]->[2];
  364:     #
  365:     # Compute the number getting the foils correct or incorrects
  366:     for (my $i=$begin_index;$i<=$end_index;$i++) {
  367:         my $row = $PerformanceData->[$i];
  368:         next if (! defined($row));
  369:         my ($grading,$submission,$time,$tries) = @$row;
  370:         my @Foilgrades = split('&',$grading);
  371:         my @Foilsubs   = split('&',$submission);
  372:         foreach my $foilgrade (@Foilgrades) {
  373:             my ($foilid,$correct) = split('=',$foilgrade);
  374:             if ($correct) {
  375:                 $TimeData{$foilid}->{'correct'}++;
  376:             } else {
  377:                 $TimeData{$foilid}->{'incorrect'}++;
  378:             }
  379:         }
  380:     }
  381:     #
  382:     # Compute the total and percent correct
  383:     my @Plotdata1;
  384:     my @Plotdata2;
  385:     foreach my $foilid (@Foils) {
  386:         if (! exists($TimeData{$foilid}->{'correct'})) {
  387:             $TimeData{$foilid}->{'correct'} = 0;
  388:         }
  389:         if (! exists($TimeData{$foilid}->{'incorrect'})) {
  390:             $TimeData{$foilid}->{'incorrect'} = 0;
  391:         }
  392:         $TimeData{$foilid}->{'total'} = $TimeData{$foilid}->{'correct'} +
  393:                                 $TimeData{$foilid}->{'incorrect'};
  394:         $TimeData{$foilid}->{'percent_corr'} = 100 *
  395:             $TimeData{$foilid}->{'correct'} / 
  396:             $TimeData{$foilid}->{'total'};
  397:         push (@Plotdata1,    $TimeData{$foilid}->{'percent_corr'});
  398:         push (@Plotdata2,100-$TimeData{$foilid}->{'percent_corr'});
  399:     }
  400:     #
  401:     # Create the plot
  402:     my $graphlink = &Apache::loncommon::DrawGraph
  403:         ($description,#'Time Interval Analysis',
  404:          'Foil Number',
  405:          'Percent Correct / Incorrect',
  406:          100,
  407:          \@Plotdata1,\@Plotdata2);
  408:     #
  409:     return ($graphlink,$starttime,$endtime,\%TimeData);
  410: }
  411: 
  412: 
  413: 
  414: 
  415: #########################################################
  416: #########################################################
  417: ##
  418: ##             Interface 
  419: ##
  420: #########################################################
  421: #########################################################
  422: sub CreateInterface {
  423:     ##
  424:     ## Environment variable initialization
  425:     if (! exists$ENV{'form.AnalyzeBy'}) {
  426:         $ENV{'form.AnalyzeBy'} = 'Tries';
  427:     }
  428:     ##
  429:     ## Build the menu
  430:     my $Str = '';
  431:     $Str .= '<table cellspacing="5">'."\n";
  432:     $Str .= '<tr>';
  433:     $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
  434:     $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
  435: #    $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
  436:     $Str .= '<td align="center">&nbsp;</td>';
  437:     $Str .= '</tr>'."\n";
  438:     ##
  439:     ## 
  440:     $Str .= '<tr><td align="center">'."\n";
  441:     $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
  442:     $Str .= '</td>';
  443:     #
  444:     $Str .= '<td align="center">';
  445:     $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
  446:     $Str .= '</td>';
  447:     #
  448: #    $Str .= '<td align="center">';
  449:     my $only_seq_with_assessments = sub { 
  450:         my $s=shift;
  451:         if ($s->{'num_assess'} < 1) { 
  452:             return 0;
  453:         } else { 
  454:             return 1;
  455:         }
  456:     };
  457:     &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
  458:                                               $only_seq_with_assessments);
  459: #    $Str .= '</td>';
  460:     #
  461:     $Str .= '<td>';
  462:     $Str .= '<nobr>'.&mt('Analyze By ');
  463:     $Str .='<select name="AnalyzeBy" >';
  464:     #
  465:     $Str .= '<option value="Tries" ';
  466:     if (! exists($ENV{'form.AnalyzeBy'}) || $ENV{'form.AnalyzeBy'} eq 'Tries'){
  467:         # Default to Tries
  468:         $Str .= ' selected ';
  469:     }
  470:     $Str .= '>'.&mt('Tries').'</option>';
  471:     #
  472:     $Str .= '<option value="Time" ';
  473:     $Str .= ' selected ' if ($ENV{'form.AnalyzeBy'} eq 'Time');
  474:     $Str .= '>'.&mt('Time').'</option>';
  475:     $Str .= '</select></nobr><br />';
  476:     #
  477:     $Str .= '<br /><nobr>'.&mt('Number of Plots:');
  478:     $Str .= '<select name="NumPlots">';
  479:     if (! exists($ENV{'form.NumPlots'}) 
  480:         || $ENV{'form.NumPlots'} < 1 
  481:         || $ENV{'form.NumPlots'} > 20) {
  482:         $ENV{'form.NumPlots'} = 5;
  483:     }
  484:     foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
  485:         $Str .= '<option value="'.$i.'" ';
  486:         if ($ENV{'form.NumPlots'} == $i) { $Str.=' selected '; }
  487:         $Str .= '>'.$i.'</option>';
  488:     }
  489:     $Str .= '</select></nobr>';
  490:     $Str .= '</td>';
  491:     #
  492:     $Str .= '</tr>'."\n";
  493:     $Str .= '</table>'."\n";
  494:     return ($Str);
  495: }
  496: 
  497: sub OptionResponseProblemSelector {
  498:     my $Str;
  499:     $Str = "\n<table>\n";
  500:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  501:         next if ($seq->{'num_assess'}<1);
  502:         my $seq_str = '';
  503:         foreach my $res (@{$seq->{'contents'}}) {
  504: #            &Apache::lonnet::logthis('checking '.$res->{'title'});
  505:             next if ($res->{'type'} ne 'assessment');
  506:             foreach my $part (@{$res->{'parts'}}) {
  507:                 my $partdata = $res->{'partdata'}->{$part};
  508:                 if (! exists($partdata->{'option'}) || 
  509:                     $partdata->{'option'} == 0) {
  510:                     next;
  511:                 }
  512:                 for (my $i=0;$i<scalar(@{$partdata->{'ResponseTypes'}});$i++){
  513:                     my $respid = $partdata->{'ResponseIds'}->[$i];
  514:                     my $resptype = $partdata->{'ResponseTypes'}->[$i];
  515:                     if ($resptype eq 'option') {
  516:                         my $value = &Apache::lonnet::escape($res->{'symb'}.':'.$part.':'.$respid);
  517:                         my $checked = '';
  518:                         if ($ENV{'form.problemchoice'} eq $value) {
  519:                             $checked = 'checked ';
  520:                         }
  521:                         $seq_str .= '<tr><td>'.
  522:   '<input type="radio" name="problemchoice" value="'.$value.'" '.$checked.'/>'.
  523:   '</td><td>'.
  524:   '<a href="'.$res->{'src'}.'">'.$res->{'title'}.'</a> ';
  525:                         if ($partdata->{'option'} > 1) {
  526:                             $seq_str .= &mt('response').' '.$respid;
  527:                         }
  528:                         $seq_str .= "</td></tr>\n";
  529:                     }
  530:                 }
  531:             }
  532:         }
  533:         if ($seq_str ne '') {
  534:             $Str .= '<tr><td>&nbsp</td><td><b>'.$seq->{'title'}.'</b></td>'.
  535:                 "</tr>\n".$seq_str;
  536:         }
  537:     }
  538:     $Str .= "</table>\n";
  539:     return $Str;
  540: }
  541: 
  542: #########################################################
  543: #########################################################
  544: ##
  545: ##              Misc functions
  546: ##
  547: #########################################################
  548: #########################################################
  549: sub get_problem_symb {
  550:     my $problemstring = shift();
  551:     my ($symb,$partid,$resid) = ($problemstring=~ /^(.*):([^:]*):([^:]*)$/);
  552:     return ($symb,$partid,$resid);
  553: }
  554: 
  555: sub get_resource_from_symb {
  556:     my ($symb) = @_;
  557:     foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
  558:         foreach my $res (@{$seq->{'contents'}}) {
  559:             if ($res->{'symb'} eq $symb) {
  560:                 return $res;
  561:             }
  562:         }
  563:     }
  564:     return undef;
  565: }
  566: 
  567: sub get_problem_data {
  568:     my ($url) = @_;
  569: #    my $Answ=&Apache::lonnet::ssi($URI,('grade_target' => 'analyze',
  570: #                                  'grade_username' => $sname,
  571: #                                  'grade_domain' => $sdom,
  572: #                                  'grade_courseid' => $cid,
  573: #                                  'grade_symb' => $symb));
  574:     my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze'));
  575:     (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2);
  576:     my %Answer;
  577:     %Answer=&Apache::lonnet::str2hash($Answ);
  578: #    &Apache::lonnet::logthis('keys of %Answer = '.join(', ',(keys(%Answer))));
  579: #    &Apache::lonnet::logthis('$Answer{parts} = '.
  580: #                             join(', ',@{$Answer{'parts'}}));
  581:     my %Partdata;
  582:     foreach my $part (@{$Answer{'parts'}}) {
  583:         while (my($key,$value) = each(%Answer)) {
  584:             next if ($key !~ /^$part/);
  585:             $key =~ s/^$part\.//;
  586:             if (ref($value) eq 'ARRAY') {
  587:                 if ($key eq 'options') {
  588:                     $Partdata{$part}->{'Options'}=$value;
  589:                 } elsif ($key eq 'concepts') {
  590:                     $Partdata{$part}->{'Concepts'}=$value;
  591:                 } elsif ($key =~ /^concept\.(.*)$/) {
  592:                     my $concept = $1;
  593:                     foreach my $foil (@$value) {
  594:                         $Partdata{$part}->{$foil}->{'Concept'}=$concept;
  595:                     }
  596:                 }
  597:  #               &Apache::lonnet::logthis($part.' '.$key.' (array) = '.
  598:  #                                        join(', ',@$value));
  599:             } else {
  600:                 $value =~ s/^\s*//g;
  601:                 $value =~ s/\s*$//g;
  602:                 if ($key=~ /^foil\.text\.(.*)$/) {
  603:                     my $foil = $1;
  604:                     $Partdata{$part}->{'Foiltext'}->{$foil}=$value;
  605:                 } elsif ($key =~ /^foil\.value\.(.*)$/) {
  606:                     my $foil = $1;
  607:                     $Partdata{$part}->{'FoilValues'}->{$foil}=$value;
  608:                 }
  609: #                &Apache::lonnet::logthis($part.' '.$key.' = '.$value);
  610:             }
  611:         }
  612:     }
  613: 
  614: #    my $parts='';
  615: #    foreach my $elm (@{$Answer{"parts"}}) {
  616: #        $parts.="$elm,";
  617: #    }
  618: #    chop($parts);
  619: #    my $conc='';
  620: #    foreach my $elm (@{$Answer{"$parts.concepts"}}) {
  621: #        $conc.="$elm@";
  622: #    }
  623: #    chop($conc);
  624: #
  625: #    @Concepts=split(/\@/,$conc);
  626: #    foreach my $concept (@{$Answer{"$parts.concepts"}}) {
  627: #        foreach my $foil (@{$Answer{"$parts.concept.$concept"}}) {
  628: #            $foil_to_concept{$foil} = $concept;
  629: #            #$ConceptData{$foil} = $Answer{"$parts.foil.value.$foil"};
  630: #        }
  631: #    }
  632: #    return $symb;
  633:     return %Partdata;
  634: }
  635: 
  636: 1;
  637: 
  638: __END__

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