File:  [LON-CAPA] / loncom / interface / statistics / lonproblemanalysis.pm
Revision 1.14: download - view: text, annotated - select for diffs
Mon Nov 25 18:02:49 2002 UTC (21 years, 7 months ago) by minaeibi
Branches: MAIN
CVS tags: HEAD
Fixed inconsistency in computing the Option Response Problems Analysis. This module "restore" a particular problem results for every students. Since this restore function is very fast, it is no need to cache the data any more. For example for 835 students in phy231 cousre it takes 33 seconds or in other word it takes for 100 students less than 4 second. We don't use "dump" here.

    1: # The LearningOnline Network with CAPA
    2: # (Publication Handler
    3: #
    4: # $Id: lonproblemanalysis.pm,v 1.14 2002/11/25 18:02:49 minaeibi 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: # (Navigate problems for statistical reports
   29: # YEAR=2002
   30: # 5/12,7/26,9/7,11/22 Behrouz Minaei
   31: #
   32: ###
   33: 
   34: package Apache::lonproblemanalysis;
   35: 
   36: use strict;
   37: use Apache::lonnet();
   38: use Apache::lonhtmlcommon();
   39: use GDBM_File;
   40: 
   41: my $jr;
   42: 
   43: sub BuildProblemAnalysisPage {
   44:     my ($cacheDB, $r)=@_;
   45: 
   46:     my %cache;
   47:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
   48:         $r->print('Unable to tie database.');
   49:         return;
   50:     }
   51: 
   52:     my $Ptr = '';
   53:     $Ptr .= '<table border="0"><tbody>';
   54:     $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
   55:     $Ptr .= '</td>'."\n";
   56:     $Ptr .= '<td align="left">'."\n";
   57:     my @sectionsSelected = split(':',$cache{'sectionsSelected'});
   58:     my @sections = split(':',$cache{'sectionList'});
   59:     $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
   60:                                                           \@sectionsSelected,
   61:                                                           'Statistics');
   62:     $Ptr .= '</td></tr>'."\n";
   63:     $Ptr .= '<tr><td align="right"><b>Intervals</b></td>'."\n";
   64:     $Ptr .= '<td align="left">';
   65:     $Ptr .= &IntervalOptions($cache{'Interval'});
   66:     $Ptr .= '</td></tr></table><br>';
   67:     $r->print($Ptr);
   68:     $r->rflush();
   69:     $r->print(&OptionResponseTable($cache{'OptionResponses'}, \%cache, $r));
   70: 
   71:     untie(%cache);
   72: 
   73:     return;
   74: }
   75: 
   76: sub BuildAnalyzePage {
   77:     my ($cacheDB, $students, $courseID,$r)=@_;
   78: 
   79:     $jr = $r;
   80:     my $c = $r->connection;
   81: 
   82:     my $Str = '</form>';
   83:     my %cache;
   84: 
   85:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
   86:         $Str .= 'Unable to tie database.';
   87:         $r->print($Str);
   88:         return;
   89:     }
   90: 
   91:     # Remove students who don't have the proper section.
   92:     my @sectionsSelected = split(':',$cache{'sectionsSelected'});
   93: 
   94:     my $studentCount = scalar @$students;
   95:     for(my $studentIndex=$studentCount-1; $studentIndex>=0;
   96:         $studentIndex--) {
   97:         my $value = $cache{$students->[$studentIndex].':section'};
   98:         my $found = 0;
   99:         foreach (@sectionsSelected) {
  100:             if($_ eq 'none') {
  101:                 if($value eq '' || !defined($value) || $value eq ' ') {
  102:                     $found = 1;
  103:                     last;
  104:                 }
  105:             } else {
  106:                 if($value eq $_) {
  107:                     $found = 1;
  108:                     last;
  109:                 }
  110:             }
  111:         }
  112:         if($found == 0) {
  113:             splice(@$students, $studentIndex, 1);
  114:         }
  115:     }
  116:     unless(untie(%cache)) {
  117:         $r->print('Can not untie hash.');
  118:         $r->rflush();
  119:     }
  120:     #if($status eq 'true')
  121:     { &Apache::lonhtmlcommon::Close_PrgWin($r); }
  122: 
  123: 
  124: #    my $error =
  125: #        &Apache::loncoursedata::DownloadStudentCourseDataSeparate($students,
  126: #                                                                  'true',
  127: #                                                                  $cacheDB,
  128: #                                                                  'true',
  129: #                                                                  'true',
  130: #                                                                  $courseID,
  131: #                                                                  $r, $c);
  132: #    if($error ne 'OK') {
  133: #        $r->print($error.'<br>Error downloading course data<br>');
  134: #        return;
  135: #    }
  136: 
  137: 
  138:     unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
  139:         $Str .= 'Unable to tie database.';
  140:         $r->print($Str);
  141:         return;
  142:     }
  143: 
  144:     my ($problemId, $part, $responseId)=split(':',$cache{'AnalyzeInfo'});
  145:     my $uri      = $cache{$problemId.':source'};
  146:     my $problem  = $cache{$problemId.':problem'};
  147:     my $title    = $cache{$problemId.':title'};
  148:     my $interval = $cache{'Interval'};
  149: 
  150: #    my $title = 'LON-CAPA Statistics';
  151:     my $heading = 'Restore this particular Option Response Problem '.
  152:                   'Results, Please wait...';
  153: 
  154:     my %ConceptData;
  155:     $ConceptData{"Interval"} = $interval;
  156: 
  157:     #Initialize the option response true answers
  158:     my ($analyzeData) = &InitAnalysis($uri, $part, $responseId, $problem,
  159:                                       $students->[0], $courseID);
  160:     if(defined($analyzeData->{'error'})) {
  161:         $Str .= $analyzeData->{'error'}.'<br>Incorrect part requested.<br>';
  162:         $r->print($Str);
  163:         return;
  164:     }
  165: 
  166:     $r->print($Str);
  167:     $Str = '';
  168:     if($c->aborted()) {  untie(%cache); return; }
  169: 
  170:     #compute the intervals
  171:     &Interval($part, $problem, $interval, $analyzeData->{'concepts'},
  172:               \%ConceptData);
  173: 
  174:     $title =~ s/\ /"_"/eg;
  175:     $Str .= '<br><b>'.$uri.'</b>';
  176: 
  177:     $r->print($Str);
  178:     $Str = '';
  179:     if($c->aborted()) {  untie(%cache); return; }
  180: 
  181:     &Apache::lonhtmlcommon::Create_PrgWin($r, $title, $heading);
  182: 
  183:     my $count=0;
  184:     #Java script Progress window
  185:     for(my $index=0; $index<(scalar @$students); $index++) {
  186:         if($c->aborted()) {  untie(%cache); return; }
  187:         $count++;
  188:         my $displayString = $count.'/'.$studentCount.': '.$_;
  189:         &Apache::lonhtmlcommon::Update_PrgWin($displayString, $r);
  190: 	&OpStatus($problemId, $students->[$index], \%ConceptData,
  191:                   $analyzeData->{'foil_to_concept'}, $analyzeData,
  192: 		  \%cache, $courseID);
  193:     }
  194:     &Apache::lonhtmlcommon::Close_PrgWin($r);
  195: 
  196:     $Str .= '<br>';
  197:     for (my $k=0; $k<$interval; $k++ ) {
  198:         if($c->aborted()) {  untie(%cache); return $Str; }
  199: 	$Str .= &DrawGraph($k, $title, $analyzeData->{'concepts'},
  200:                            \%ConceptData);
  201:         $r->print($Str);
  202:         $Str = '';
  203:     }
  204:     for (my $k=0; $k<$interval; $k++ ) {
  205:         if($c->aborted()) {  untie(%cache); return $Str; }
  206: 	$Str .= &DrawTable($k, $analyzeData->{'concepts'}, \%ConceptData);
  207:         $r->print($Str);
  208:         $Str = '';
  209:     }
  210:     my $Answ=&Apache::lonnet::ssi($uri);
  211:     $Str .= '<br><b>Here you can see the Problem:</b><br>'.$Answ;
  212:     $Str .= '<form>';
  213:     $r->print($Str);
  214: 
  215:     untie(%cache);
  216: 
  217:     return;
  218: }
  219: 
  220: #---- Problem Analysis Web Page ----------------------------------------------
  221: 
  222: sub IntervalOptions {
  223:     my ($selectedInterval)=@_;
  224: 
  225:     my $interval = 1;
  226:     for(my $n=1; $n<=7; $n++) {
  227:         if($selectedInterval == $n) {
  228:             $interval = $n;
  229:         }
  230:     }
  231: 
  232:     my $Ptr = '<select name="Interval">'."\n";
  233:     for(my $n=1; $n<=7;$ n++) {
  234: 	$Ptr .= '<option';
  235:         if($interval == $n) {
  236:             $Ptr .= ' selected';
  237:         }
  238: 	$Ptr .= '>'.$n."</option>"."\n";
  239:     }
  240:     $Ptr .= '</select>'."\n";
  241: 
  242:     return $Ptr;
  243: }
  244: 
  245: sub OptionResponseTable {
  246:     my ($optionResponses,$cache,$r)=@_;
  247: 
  248:     my @optionResponses=split(':::', $optionResponses);
  249:     my %partCount;
  250:     my %sequences;
  251:     my @orderedSequences=();
  252:     foreach(@optionResponses) {
  253:         my ($sequence, $problemId, $part, undef)=split(':',$_);
  254:         $partCount{$problemId.':'.$part}++;
  255:         if(!defined($sequences{$sequence})) {
  256:             push(@orderedSequences, $sequence);
  257:             $sequences{$sequence} = $_;
  258:         } else {
  259:             $sequences{$sequence} .= ':::'.$_;
  260:         }
  261:     }
  262: 
  263:     my $Str = '';
  264: 
  265:     foreach my $sequence (@orderedSequences) {
  266:         my @optionProblems = split(':::', $sequences{$sequence});
  267: 
  268:         $Str .= '<b>'.$cache->{$sequence.':title'}.'</b>'."\n";
  269:         $Str .= "<table border=2><tr><th> \# </th><th> Problem Title </th>";
  270:         $Str .= '<th> Resource </th><th> Analysis  </th></tr>'."\n";
  271: 
  272:         my $count = 1;
  273:         foreach(@optionProblems) {
  274:             my (undef, $problemId, $part, $response)=
  275:                 split(':',$optionProblems[$count-1]);
  276: #                split(':',$sequences{$sequence});
  277:             my $uri = $cache->{$problemId.':source'};
  278:             my $title = $cache->{$problemId.':title'};
  279: 
  280:             my $Temp = '<a href="'.$uri.'" target="_blank">'.$title.'</a>';
  281:             $Str .= '<tr>';
  282:             $Str .= '<td> '.$count.' </td>';
  283:             $Str .= '<td bgcolor="#DDFFDD">'.$Temp.'</td>';
  284:             $Str .= '<td bgcolor="#EEFFCC">'.$uri.'</td>';
  285:             if($partCount{$problemId.':'.$part} < 2) {
  286:                 $Str .= '<td><input type="submit" name="Analyze:::';
  287:                 $Str .= $problemId.':'.$part.'" value="';
  288:                 $Str .= 'Part '.$part;
  289:                 $Str .= '" /></td></tr>'."\n";
  290:             } else {
  291:                 my $value = $problemId.':'.$part.':'.$response;
  292:                 $Str .= '<td><input type="submit" name="Analyze:::'.$value;
  293:                 $Str .= '" value="';
  294:                 $Str .= 'Part '.$part.' Response '.$response;
  295:                 $Str .= '" /></td></tr>'."\n";
  296:             }
  297:             $count++;
  298:         }
  299:         $Str .= '</table><br>'."\n";
  300:     }
  301: 
  302:     return $Str;
  303: }
  304: 
  305: #---- END Problem Analysis Web Page ------------------------------------------
  306: 
  307: #---- Analyze Web Page -------------------------------------------------------
  308: 
  309: #restore the student submissions and finding the result
  310: =pod
  311: sub OpStatus {
  312:     my ($problemID, $student, $ConceptData, $foil_to_concept,
  313:         $analyzeData, $cache)=@_;
  314: 
  315:     my $ids = $analyzeData->{'parts'};
  316: 
  317:     my @True = ();
  318:     my @False = ();
  319:     my $flag=0;
  320: 
  321:     my $tries=0;
  322: 
  323:     foreach my $id (@$ids) {
  324: 	my ($part, $response) = split(/\./, $id);
  325:         my $time=$cache->{$student.':'.$problemID.':'.$part.':timestamp'};
  326:         my @submissions = split(':::', $cache->{$student.':'.$problemID.':'.
  327:                                                 $part.':'.$response.
  328:                                                 ':submission'});
  329:         foreach my $Resp (@submissions) {
  330:             my %submission=&Apache::lonnet::str2hash($Resp);
  331:             foreach (keys(%submission)) {
  332:                 if($submission{$_}) {
  333:                     my $answer = $analyzeData->{$id.'.foil.value.'.$_};
  334:                     if($submission{$_} eq $answer) {
  335:                         &Decide("true", $foil_to_concept->{$_},
  336:                                 $time, $ConceptData);
  337:                     } else {
  338:                         &Decide("false", $foil_to_concept->{$_},
  339:                                 $time, $ConceptData);
  340:                     }
  341:                 }
  342:             }
  343:         }
  344:     }
  345: 
  346:     return;
  347: }
  348: =cut
  349: 
  350: sub OpStatus {
  351:     my ($problemID, $student, $ConceptData, $foil_to_concept,
  352:         $analyzeData, $cache, $courseID)=@_;
  353: 
  354:     my $ids = $analyzeData->{'parts'};
  355:     my ($uname,$udom)=split(/\:/,$student);
  356:     my $symb  = $cache->{$problemID.':problem'};
  357: 
  358:     my @True = ();
  359:     my @False = ();
  360:     my $flag=0;
  361:     my $tries=0;
  362: 
  363: #    $jr->print("<br> ID= $problemID <br> student= $student<br> prob= $symb<br>");
  364: 
  365:     foreach my $id (@$ids) {
  366: 	my ($part, $response) = split(/\./, $id);
  367: #=pod
  368:     my %reshash=&Apache::lonnet::restore($symb,$courseID,$udom,$uname);
  369:     if ($reshash{'version'}) {
  370:         my $tries=0;
  371: 	#&Apache::lonhomework::showhash(%$analyzeData);
  372: 	for (my $version=1;$version<=$reshash{'version'};$version++) {
  373: 	    my $time=$reshash{"$version:timestamp"};
  374: 
  375: 	    foreach my $key (sort(split(/\:/,$reshash{$version.':keys'}))) {
  376: 		if (($key=~/\.(\w+)\.(\w+)\.submission$/)) {
  377: 		    my $Id1 = $1; my $Id2 = $2;
  378: 		    #check if this is a repeat submission, if so skip it
  379:           	    if ($reshash{"$version:resource.$Id1.previous"}) { next; }
  380: 		    #if no solved this wasn't a real submission, ignore it
  381: 		    if (!defined($reshash{"$version:resource.$Id1.solved"})) {
  382: 			&Apache::lonxml::debug("skipping ");
  383: 			next;
  384: 		    }
  385: 		    my $Resp = $reshash{"$version:$key"};
  386: 		    my %submission=&Apache::lonnet::str2hash($Resp);
  387: 		    foreach (keys %submission) {
  388: 			my $Ansr = $analyzeData->{"$Id1.$Id2.foil.value.$_"};
  389:                     	if($submission{$_} eq $Ansr) {
  390:                         	&Decide("true", $foil_to_concept->{$_},
  391:                                 	$time, $ConceptData);
  392:                     	} else {
  393:                         	&Decide("false", $foil_to_concept->{$_},
  394: 					$time, $ConceptData);
  395:                     	}
  396: 		    }
  397: 	        }
  398: 	    }
  399:         }
  400:     }
  401: #=cut
  402: =pod
  403:         my $time=$cache->{$student.':'.$problemID.':'.$part.':timestamp'};
  404: 	my @submissions = split(':::', $cache->{$student.':'.$problemID.':'.
  405:                                                $part.':'.$response.
  406:                                                 ':submission'});
  407:         foreach my $Resp (@submissions) {
  408:             my %submission=&Apache::lonnet::str2hash($Resp);
  409:             foreach (keys(%submission)) {
  410:                 if($submission{$_}) {
  411:                     my $answer = $analyzeData->{$id.'.foil.value.'.$_};
  412:                     if($submission{$_} eq $answer) {
  413:                         &Decide("true", $foil_to_concept->{$_},
  414:                                 $time, $ConceptData);
  415:                     } else {
  416:                         &Decide("false", $foil_to_concept->{$_},
  417:                                 $time, $ConceptData);
  418:                     }
  419:                 }
  420:             }
  421:         }
  422: =cut
  423:     }
  424: 
  425:     return;
  426: }
  427: 
  428: =pod
  429: sub OpStatus {
  430:     my ($rid,$student,$ConceptData,$foil_to_concept,$analyzeData,$cache)=@_;
  431:     my ($uname,$udom)=split(/\:/,$student);
  432:     my $code='U';
  433:     $rid=~/(\d+)\.(\d+)/;
  434:     my $symb=&Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.
  435: 	     &Apache::lonnet::declutter($hash{'src_'.$rid});
  436:     my %reshash=&Apache::lonnet::restore($symb,$cid,$udom,$uname);
  437:     my @True = ();
  438:     my @False = ();
  439:     my $flag=0;
  440:     if ($reshash{'version'}) {
  441:         my $tries=0;
  442: 	&Apache::lonhomework::showhash(%Answer);
  443: 	for (my $version=1;$version<=$reshash{'version'};$version++) {
  444: 	    my $time=$reshash{"$version:timestamp"};
  445: 
  446: 	    foreach my $key (sort(split(/\:/,$reshash{$version.':keys'}))) {
  447: 		if (($key=~/\.(\w+)\.(\w+)\.submission$/)) {
  448: 		    my $Id1 = $1; my $Id2 = $2;
  449: 		    #check if this is a repeat submission, if so skip it
  450:           	    if ($reshash{"$version:resource.$Id1.previous"}) { next; }
  451: 		    #if no solved this wasn't a real submission, ignore it
  452: 		    if (!defined($reshash{"$version:resource.$Id1.solved"})) {
  453: 			&Apache::lonxml::debug("skipping ");
  454: 			next;
  455: 		    }
  456: 		    my $Resp = $reshash{"$version:$key"};
  457: 		    my %submission=&Apache::lonnet::str2hash($Resp);
  458: 		    foreach (keys %submission) {
  459: 			my $Ansr = $Answer{"$Id1.$Id2.foil.value.$_"};
  460: 			if ($submission{$_}) {
  461: 			    if ($submission{$_} eq $Ansr) {
  462: 				&Decide("true",$_,$time );
  463: 			    }
  464: 			    else {&Decide("false",$_,$time );}
  465: 			}
  466: 		    }
  467: 	        }
  468: 	    }
  469:         }
  470:     }
  471: }
  472: =cut
  473: 
  474: sub DrawGraph {
  475:     my ($k,$Src,$Concepts,$ConceptData)=@_;
  476:     my $Max=0;
  477:     my @data1;
  478:     my @data2;
  479: 
  480:     # Adjust Data and find the Max
  481:     for (my $n=0; $n<(scalar @$Concepts); $n++ ) {
  482: 	my $tmp=$Concepts->[$n];
  483: 	$data1[$n]=$ConceptData->{$tmp.'.'.$k.'.true'};
  484: 	$data2[$n]=$ConceptData->{$tmp.'.'.$k.'.false'};
  485: 	my $Sum=$data1[$n]+$data2[$n];
  486: 	if($Max < $Sum) {
  487:             $Max=$Sum;
  488:         }
  489:     }
  490:     for (my $n=0; $n<(scalar @$Concepts); $n++ ) {
  491: 	if ($data1[$n]+$data2[$n]<$Max) {
  492: 	    $data2[$n]+=$Max-($data1[$n]+$data2[$n]);
  493: 	}
  494:     }
  495:     my $P_No = (scalar @data1);
  496: 
  497:     if($Max > 1) { 
  498: 	$Max += (10 - $Max % 10);
  499: 	$Max = int($Max);
  500:     } else {
  501:         $Max = 1;
  502:     }
  503: 
  504:     my $Titr=($ConceptData->{'Interval'}>1) ? $Src.'_interval_'.($k+1) : $Src;
  505: #    $GData=$Titr.'&Concepts'.'&'.'Answers'.'&'.$Max.'&'.$P_No.'&'.$data1.'&'.$data2;
  506:     my $GData = '';
  507:     $GData  = $Titr.'&Concepts&Answers&'.$Max.'&'.$P_No.'&';
  508:     $GData .= (join(',',@data1)).'&'.(join(',',@data2));
  509: 
  510:     return '<IMG src="/cgi-bin/graph.gif?'.$GData.'" border=1/>';
  511: }
  512: 
  513: sub DrawTable {
  514:     my ($k,$Concepts,$ConceptData)=@_;
  515:     my $Max=0;
  516:     my @data1;
  517:     my @data2;
  518:     my $Correct=0;
  519:     my $Wrong=0;
  520:     for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
  521: 	my $tmp=$Concepts->[$n];
  522: 	$data1[$n]=$ConceptData->{$tmp.'.'.$k.'.true'};
  523: 	$Correct+=$data1[$n];
  524: 	$data2[$n]=$ConceptData->{$tmp.'.'.$k.'.false'};
  525: 	$Wrong+=$data2[$n];
  526: 	my $Sum=$data1[$n]+$data2[$n];
  527: 	if($Max < $Sum) {
  528:             $Max=$Sum;
  529:         }
  530:     }
  531:     for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
  532: 	if ($data1[$n]+$data2[$n]<$Max) {
  533: 	    $data2[$n]+=$Max-($data1[$n]+$data2[$n]);
  534: 	}
  535:     }
  536:     my $P_No = (scalar @data1);
  537:     my $Str = '';
  538: #    $Str .= '<br><b>From: ['.localtime($ConceptData->{'Int.'.($k-1)});
  539: #    $Str .= '] To: ['.localtime($ConceptData->{"Int.$k"}).']</b>';
  540:     $Str .= "\n".'<table border=2>'.
  541:             "\n".'<tr>'.
  542:             "\n".'<th> # </th>'.
  543:             "\n".'<th> Concept </th>'.
  544:             "\n".'<th> Correct </th>'.
  545:             "\n".'<th> Wrong </th>'.
  546:             "\n".'</tr>';
  547: 
  548:     for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
  549: 	$Str .= '<tr>'."\n";
  550:         $Str .= '<td>'.($n+1).'</td>'."\n";
  551:         my ($currentConcept) = split('::',$Concepts->[$n]);
  552:         $Str .= '<td bgcolor="EEFFCC">'.$currentConcept;
  553:         $Str .= '</td>'."\n";
  554:         $Str .= '<td bgcolor="DDFFDD">'.$data1[$n].'</td>'."\n";
  555:         $Str .= '<td bgcolor="FFDDDD">'.$data2[$n].'</td>'."\n";
  556:         $Str .= '</tr>'."\n";
  557:     }
  558:     $Str .= '<td></td><td><b>From:['.localtime($ConceptData->{'Int.'.$k});
  559:     $Str .= '] To: ['.localtime($ConceptData->{'Int.'.($k+1)}-1);
  560:     $Str .= ']</b></td><td>'.$Correct.'</td><td>'.$Wrong.'</td>';
  561:     $Str .= '</table>'."\n";
  562: 
  563:     return $Str;
  564: #$Apache::lonxml::debug=1;
  565: #&Apache::lonhomework::showhash(%ConceptData);
  566: #$Apache::lonxml::debug=0;
  567: }
  568: 
  569: #---- END Analyze Web Page ----------------------------------------------
  570: 
  571: sub Decide {
  572:     #deciding the true or false answer belongs to each interval
  573:     my ($type,$concept,$time,$ConceptData)=@_; 
  574:     my $k=0;
  575:     while($time > $ConceptData->{'Int.'.($k+1)} && 
  576:            $k < $ConceptData->{'Interval'}) {
  577:         $k++;
  578:     }
  579:     $ConceptData->{$concept.'.'.$k.'.'.$type}++;
  580: 
  581:     return;
  582: }
  583: 
  584: sub InitAnalysis {
  585:     my ($uri,$part,$responseId,$problem,$student,$courseID)=@_;
  586:     my ($name,$domain)=split(/\:/,$student);
  587: 
  588:     my %analyzeData;
  589:     # Render the student's view of the problem.  $Answ is the problem 
  590:     # Stringafied
  591:     my $Answ=&Apache::lonnet::ssi($uri,('grade_target'   => 'analyze',
  592:                                         'grade_username' => $name,
  593:                                         'grade_domain'   => $domain,
  594:                                         'grade_courseid' => $courseID,
  595:                                         'grade_symb'     => $problem));
  596:     my ($Answer)=&Apache::lonnet::str2hashref($Answ);
  597: 
  598:     my $found = 0;
  599:     my @parts=();
  600:     if(defined($responseId)) {
  601:         foreach (@{$Answer->{'parts'}}) {
  602:             if($_ eq $part.'.'.$responseId) {
  603:                 push(@parts, $_);
  604:                 $found = 1;
  605:                 last;
  606:             }
  607:         }
  608:     } else {
  609:         foreach (@{$Answer->{'parts'}}) {
  610:             if($_ =~ /$part/) {
  611:                 push(@parts, $_);
  612:                 $found = 1;
  613:                 last;
  614:             }
  615:         }
  616:     }
  617: 
  618:     if($found == 0) {
  619:         $analyzeData{'error'} = 'No parts matching selected values';
  620:         return \%analyzeData;
  621:     }
  622: 
  623:     my @Concepts=();
  624:     my %foil_to_concept;
  625:     foreach my $currentPart (@parts) {
  626:         if(defined($Answer->{$currentPart.'.concepts'})) {
  627:             foreach my $concept (@{$Answer->{$currentPart.'.concepts'}}) {
  628:                 push(@Concepts, $concept);
  629:                 foreach my $foil (@{$Answer->{$currentPart.'.concept.'.
  630:                                             $concept}}) {
  631:                     $analyzeData{$currentPart.'.foil.value.'.$foil} =
  632:                         $Answer->{$currentPart.'.foil.value.'.$foil};
  633:                     $foil_to_concept{$foil} = $concept;
  634:                 }
  635:             }
  636:         } else {
  637:             foreach (keys(%$Answer)) {
  638:                 if(/$currentPart.foil\.value\.(.*)$/) {
  639:                     push(@Concepts, $1);
  640:                     $foil_to_concept{$1} = $1;
  641:                     $analyzeData{$currentPart.'.foil.value.'.$1} =
  642:                         $Answer->{$currentPart.'.foil.value.'.$1};
  643:                 }
  644:             }
  645:         }
  646:     }
  647: 
  648:     $analyzeData{'parts'} = \@parts;
  649:     $analyzeData{'concepts'} = \@Concepts;
  650:     $analyzeData{'foil_to_concept'} = \%foil_to_concept;
  651: 
  652:     return \%analyzeData;
  653: }
  654: 
  655: sub Interval {
  656:     my ($part,$symb,$interval,$Concepts,$ConceptData)=@_;
  657:     my $Int=$interval;
  658:     my $due = &Apache::lonnet::EXT('resource.'.$part.'.duedate',$symb);
  659:     my $opn = &Apache::lonnet::EXT('resource.'.$part.'.opendate',$symb);
  660:     my $add=int(($due-$opn)/$Int);
  661:     $ConceptData->{'Int.0'}=$opn;
  662:     for(my $i=1; $i<$Int; $i++) {
  663: 	$ConceptData->{'Int.'.$i}=$opn+$i*$add;
  664:     }
  665:     $ConceptData->{'Int.'.$Int}=$due;
  666:     for(my $i=0; $i<$Int; $i++) {
  667: 	for(my $n=0; $n<(scalar @$Concepts); $n++ ) {
  668: 	    my $tmp=$Concepts->[$n];
  669: 	    $ConceptData->{$tmp.'.'.$i.'.true'}=0;
  670: 	    $ConceptData->{$tmp.'.'.$i.'.false'}=0;
  671: 	}
  672:     }
  673: }
  674: 1;
  675: __END__

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