--- loncom/interface/statistics/lonstathelpers.pm 2004/03/16 16:30:31 1.8 +++ loncom/interface/statistics/lonstathelpers.pm 2004/03/16 16:41:26 1.9 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstathelpers.pm,v 1.8 2004/03/16 16:30:31 matthew Exp $ +# $Id: lonstathelpers.pm,v 1.9 2004/03/16 16:41:26 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -342,6 +342,60 @@ sub get_prev_curr_next { ##################################################### ##################################################### + +=pod + +=item GetStudentAnswers($r,$problem,$Students) + +Determines the correct answer for a set of students on a given problem. +The students answers are stored in the student hashes pointed to by the +array @$Students under the key 'answer'. + +Inputs: $r +$problem: hash reference containing the keys 'resource', 'part', and 'respid'. +$Students: reference to array containing student hashes (need 'username', + 'domain'). + +Returns: nothing + +=cut + +##################################################### +##################################################### +sub GetStudentAnswers { + my ($r,$problem,$Students) = @_; + my $c = $r->connection(); + my %Answers; + my ($resource,$partid,$respid) = ($problem->{'resource'}, + $problem->{'part'}, + $problem->{'respid'}); + # Read in the cache (if it exists) before we start timing things. + &Apache::lonstathelpers::ensure_proper_cache($resource->{'symb'}); + # Open progress window + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin + ($r,'Student Answer Compilation Status', + 'Student Answer Compilation Progress', scalar(@$Students)); + $r->rflush(); + foreach my $student (@$Students) { + last if ($c->aborted()); + my $sname = $student->{'username'}; + my $sdom = $student->{'domain'}; + my $answer = &Apache::lonstathelpers::analyze_problem_as_student + ($resource,$sname,$sdom,$partid,$respid); + &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, + &mt('last student')); + $student->{'answer'} = $answer; + } + &Apache::lonstathelpers::write_answer_cache(); + return if ($c->aborted()); + $r->rflush(); + # close progress window + &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); + return; +} + +##################################################### +##################################################### =pod