Diff for /loncom/interface/statistics/lonstathelpers.pm between versions 1.29 and 1.30

version 1.29, 2004/11/03 16:13:08 version 1.30, 2004/11/08 15:14:52
Line 578  sub GetStudentAnswers { Line 578  sub GetStudentAnswers {
         last if ($c->aborted());          last if ($c->aborted());
         my $sname = $student->{'username'};          my $sname = $student->{'username'};
         my $sdom = $student->{'domain'};          my $sdom = $student->{'domain'};
         my $answer = &Apache::lonstathelpers::analyze_problem_as_student          my $answer = &Apache::lonstathelpers::get_student_answer
             ($resource,$sname,$sdom,$partid,$respid);              ($resource,$sname,$sdom,$partid,$respid);
         &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,          &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
                                                  &mt('last student'));                                                   &mt('last student'));
Line 599  sub GetStudentAnswers { Line 599  sub GetStudentAnswers {
   
 =item analyze_problem_as_student  =item analyze_problem_as_student
   
 Analyzes a homework problem for a student and returns the correct answer  Analyzes a homework problem for a student
 for the student.  Attempts to put together an answer for problem types   
 that do not natively support it.  
   
 Inputs: $resource: a resource object  Inputs: $resource: a resource object
         $sname, $sdom, $partid, $respid          $sname, $sdom, $partid, $respid
   
 Returns: $answer  Returns: the problem analysis hash
   
 If $partid and $respid are specified, $answer is simply a scalar containing  
 the correct answer for the response.  
   
 If $partid or $respid are undefined, $answer will be a hash reference with  
 keys $partid.'.'.$respid.'.answer'.  
   
 =cut  =cut
   
 #####################################################  #####################################################
 #####################################################  #####################################################
 sub analyze_problem_as_student {  sub analyze_problem_as_student {
     my ($resource,$sname,$sdom,$partid,$respid) = @_;      my ($resource,$sname,$sdom) = @_;
     if (ref($resource) ne 'HASH') {      if (ref($resource) ne 'HASH') {
         my $res = $resource;          my $res = $resource;
         $resource = { 'src' => $res->src,          $resource = { 'src' => $res->src,
Line 630  sub analyze_problem_as_student { Line 622  sub analyze_problem_as_student {
                 [$res->responseIds($part)];                  [$res->responseIds($part)];
         }          }
     }      }
     my $returnvalue;  
     my $url = $resource->{'src'};      my $url = $resource->{'src'};
     my $symb = $resource->{'symb'};      my $symb = $resource->{'symb'};
     my $analysis = &get_from_analysis_cache($sname,$sdom,$symb);      my $analysis = &get_from_analysis_cache($sname,$sdom,$symb);
     if (! defined($analysis)) {      if (! defined($analysis)) {
         &Apache::lonnet::logthis('uncached analysis');  
         my $courseid = $ENV{'request.course.id'};          my $courseid = $ENV{'request.course.id'};
         my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze',          my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze',
                                             'grade_domain' => $sdom,                                              'grade_domain' => $sdom,
Line 647  sub analyze_problem_as_student { Line 637  sub analyze_problem_as_student {
     }      }
     my %Answer=&Apache::lonnet::str2hash($analysis);      my %Answer=&Apache::lonnet::str2hash($analysis);
     #      #
       return \%Answer;
   }
   
   #####################################################
   #####################################################
   
   =pod
   
   =item get_student_answer
   
   Analyzes a homework problem for a particular student and returns the correct 
   answer.  Attempts to put together an answer for problem types 
   that do not natively support it.
   
   Inputs: $resource: a resource object (from navmaps or hash from loncoursedata)
           $sname, $sdom, $partid, $respid
   
   Returns: $answer
   
   If $partid and $respid are specified, $answer is simply a scalar containing
   the correct answer for the response.
   
   If $partid or $respid are undefined, $answer will be a hash reference with
   keys $partid.'.'.$respid.'.answer'.
   
   =cut
   
   #####################################################
   #####################################################
   sub get_student_answer {
       my ($resource,$sname,$sdom,$partid,$respid) = @_;
       #
       if (ref($resource) ne 'HASH') {
           my $res = $resource;
           $resource = { 'src' => $res->src,
                         'symb' => $res->symb,
                         'parts' => $res->parts };
           foreach my $part (@{$resource->{'parts'}}) {
               $resource->{'partdata'}->{$part}->{'ResponseIds'}=
                   [$res->responseIds($part)];
           }
       }
       #
       my $analysis = 
           &analyze_problem_as_student($resource,$sname,$sdom);
     my $answer;      my $answer;
     foreach my $partid (@{$resource->{'parts'}}) {      foreach my $partid (@{$resource->{'parts'}}) {
         my $partdata = $resource->{'partdata'}->{$partid};          my $partdata = $resource->{'partdata'}->{$partid};
         foreach my $respid (@{$partdata->{'ResponseIds'}}) {          foreach my $respid (@{$partdata->{'ResponseIds'}}) {
             my $prefix = $partid.'.'.$respid;              my $prefix = $partid.'.'.$respid;
             my $key = $prefix.'.answer';              my $key = $prefix.'.answer';
             $answer->{$partid}->{$respid} = &get_answer($prefix,$key,%Answer);              $answer->{$partid}->{$respid} = 
                   &get_answer($prefix,$key,%$analysis);
         }          }
     }      }
       my $returnvalue;
     if (! defined($partid)) {      if (! defined($partid)) {
         $returnvalue = $answer;          $returnvalue = $answer;
     } elsif (! defined($respid)) {      } elsif (! defined($respid)) {

Removed from v.1.29  
changed lines
  Added in v.1.30


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