--- loncom/interface/statistics/lonstathelpers.pm 2004/11/03 16:13:08 1.29 +++ loncom/interface/statistics/lonstathelpers.pm 2005/02/22 22:56:32 1.37 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonstathelpers.pm,v 1.29 2004/11/03 16:13:08 matthew Exp $ +# $Id: lonstathelpers.pm,v 1.37 2005/02/22 22:56:32 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -86,7 +86,7 @@ sub render_resource { ($base,undef) = ($resource->{'src'} =~ m|(.*/)[^/]*$|); $base = "http://".$ENV{'SERVER_NAME'}.$base; my $rendered_problem = - &Apache::lonnet::ssi_body($resource->{'src'}); + &Apache::lonnet::ssi_body($resource->{'src'}.'?symb='.&Apache::lonnet::escape($resource->{'symb'})); $rendered_problem =~ s/<\s*form\s*/)|<\/nop>|g; return '\n"; $rb_count++; } @@ -280,16 +282,6 @@ END return $Str; } -sub get_title { - my ($title,$src) = @_; - if ($title eq '') { - ($title) = ($src =~ m|/([^/]+)$|); - } else { - $title =~ s/\:/:/g; - } - return $title; -} - sub new_accumulator { my ($title,$src,$symb,$seq_id,$inputname) = @_; my $target; @@ -308,7 +300,8 @@ sub new_accumulator { 'value="'.&Apache::lonnet::escape($res->symb).'" />'. ' '.$res->compTitle.''. (' 'x2).'view'. + 'href="'.$res->src.'?symb='. + &Apache::lonnet::escape($res->{'symb'}).'">view'. ''.$/; } else { if (defined($target)) { @@ -555,6 +548,7 @@ Returns: nothing ##################################################### sub GetStudentAnswers { my ($r,$problem,$Students,$formname,$inputname) = @_; + my %answers; my $status_type; if (defined($formname)) { $status_type = 'inline'; @@ -578,10 +572,11 @@ sub GetStudentAnswers { last if ($c->aborted()); my $sname = $student->{'username'}; my $sdom = $student->{'domain'}; - my $answer = &Apache::lonstathelpers::analyze_problem_as_student + my $answer = &Apache::lonstathelpers::get_student_answer ($resource,$sname,$sdom,$partid,$respid); &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, &mt('last student')); + $answers{$answer}++; $student->{'answer'} = $answer; } &Apache::lonstathelpers::write_analysis_cache(); @@ -589,7 +584,7 @@ sub GetStudentAnswers { $r->rflush(); # close progress window &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); - return; + return \%answers; } ##################################################### @@ -599,27 +594,19 @@ sub GetStudentAnswers { =item analyze_problem_as_student -Analyzes a homework problem for a student and returns the correct answer -for the student. Attempts to put together an answer for problem types -that do not natively support it. +Analyzes a homework problem for a student Inputs: $resource: a resource object $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'. +Returns: the problem analysis hash =cut ##################################################### ##################################################### sub analyze_problem_as_student { - my ($resource,$sname,$sdom,$partid,$respid) = @_; + my ($resource,$sname,$sdom) = @_; if (ref($resource) ne 'HASH') { my $res = $resource; $resource = { 'src' => $res->src, @@ -630,12 +617,10 @@ sub analyze_problem_as_student { [$res->responseIds($part)]; } } - my $returnvalue; my $url = $resource->{'src'}; my $symb = $resource->{'symb'}; my $analysis = &get_from_analysis_cache($sname,$sdom,$symb); if (! defined($analysis)) { - &Apache::lonnet::logthis('uncached analysis'); my $courseid = $ENV{'request.course.id'}; my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze', 'grade_domain' => $sdom, @@ -647,15 +632,62 @@ sub analyze_problem_as_student { } 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; foreach my $partid (@{$resource->{'parts'}}) { my $partdata = $resource->{'partdata'}->{$partid}; foreach my $respid (@{$partdata->{'ResponseIds'}}) { my $prefix = $partid.'.'.$respid; 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)) { $returnvalue = $answer; } elsif (! defined($respid)) { @@ -1093,7 +1125,7 @@ sub get_problem_data { $Partdata{$part}->{'_Foils'}->{$foil}->{'_Concept'}= $concept; } - } elsif ($key =~ /^(incorrect|answer|ans_low|ans_high|str_type)$/) { + } elsif ($key =~ /^(unit|incorrect|answer|ans_low|ans_high|str_type)$/) { $Partdata{$part}->{$key}=$value; } } else { @@ -1299,9 +1331,7 @@ sub manage_caches { if (defined($update_message)) { $r->print($update_message); } - &Apache::lonstatistics::Gather_Full_Student_Data($r,$formname, - $inputname); - + &gather_full_student_data($r,$formname,$inputname); } # my @Buttons = @@ -1323,7 +1353,38 @@ sub manage_caches { return @Buttons; } - +sub gather_full_student_data { + my ($r,$formname,$inputname) = @_; + my $status_type; + if (defined($formname)) { + $status_type = 'inline'; + } else { + $status_type = 'popup'; + } + my $c = $r->connection(); + # + &Apache::loncoursedata::clear_internal_caches(); + # + my @Students = @Apache::lonstatistics::Students; + # + # Open the progress window + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin + ($r,&mt('Student Data Compilation Status'), + &mt('Student Data Compilation Progress'), scalar(@Students), + $status_type,undef,$formname,$inputname); + # + while (my $student = shift @Students) { + return if ($c->aborted()); + my $status = &Apache::loncoursedata::ensure_current_full_data + ($student->{'username'},$student->{'domain'}, + $ENV{'request.course.id'}); + &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, + &mt('last student')); + } + &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); + $r->rflush(); + return; +} ####################################################
'. @@ -149,8 +149,10 @@ sub ProblemSelector { if (scalar(@{$partdata->{'ResponseIds'}}) > 1) { $seq_str .= &mt('response').' '.$respid; } + my $link = $res->{'src'}.'?symb='. + &Apache::lonnet::escape($res->{'symb'}); $seq_str .= (' 'x2). - qq{view}; + qq{view}; $seq_str .= "