--- loncom/interface/statistics/lonproblemanalysis.pm 2003/10/24 13:38:06 1.46 +++ loncom/interface/statistics/lonproblemanalysis.pm 2003/10/30 16:24:36 1.47 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonproblemanalysis.pm,v 1.46 2003/10/24 13:38:06 matthew Exp $ +# $Id: lonproblemanalysis.pm,v 1.47 2003/10/30 16:24:36 matthew Exp $ # # Copyright Michigan State University Board of Trustees # @@ -108,21 +108,32 @@ sub BuildProblemAnalysisPage { # $r->print('
'); # - my ($symb,$part,$resid) = &get_problem_symb( + my ($symb,$part,$resid,$resptype) = &get_problem_symb( &Apache::lonnet::unescape($ENV{'form.problemchoice'})); $r->rflush(); # my $resource = &get_resource_from_symb($symb); - if (! defined($resource)) { + if (! defined($resource) || ! defined($resptype)) { $r->print('resource is undefined'); } else { $r->print('

'.$resource->{'title'}.'

'); $r->print('

'.$resource->{'src'}.'

'); + $r->print(&render_resource($resource)); $r->rflush(); - my %Data = &get_problem_data($resource->{'src'}); - my $ProblemData = $Data{$part.'.'.$resid}; - &OptionResponseAnalysis($r,$resource,$resid,$ProblemData, - \@Students); + if ($resptype eq 'option') { + my %Data = &get_OR_problem_data($resource->{'src'}); + my $ProblemData = $Data{$part.'.'.$resid}; + &OptionResponseAnalysis($r,$resource,$resid,$ProblemData, + \@Students); + } elsif ($resptype eq 'radiobutton') { + $r->print('

This analysis is not supported

'); + my %Data = &get_Radio_problem_data($resource->{'src'}); + my $ProblemData = $Data{$part.'.'.$resid}; + &RadioResponseAnalysis($r,$resource,$resid,$ProblemData, + \@Students); + } else { + $r->print('

This analysis is not supported

'); + } } $r->print('
'); } else { @@ -134,6 +145,28 @@ sub BuildProblemAnalysisPage { } } + +######################################################### +######################################################### +## +## Radio Response Routines +## +######################################################### +######################################################### +sub RadioResponseAnalysis { + my ($r,$resource,$resid,$ProblemData,$Students) = @_; + my $PerformanceData = + &Apache::loncoursedata::get_response_data + ($Students,$resource->{'symb'},$resid); + if (! ref($PerformanceData)) { + $r->print('

There is no submission data for this resource

'); + return; + } +# foreach my $row (@$PerformanceData) { +# &Apache::lonnet::logthis('row = '.join(',',@$row)); +# } + return; +} ######################################################### ######################################################### ## @@ -143,9 +176,8 @@ sub BuildProblemAnalysisPage { ######################################################### sub OptionResponseAnalysis { my ($r,$resource,$resid,$ProblemData,$Students) = @_; - &Apache::lonnet::logthis('resid = '.$resid); my $PerformanceData = - &Apache::loncoursedata::get_optionresponse_data + &Apache::loncoursedata::get_response_data ($Students,$resource->{'symb'},$resid); if (! defined($PerformanceData) || ref($PerformanceData) ne 'ARRAY' ) { @@ -153,7 +185,6 @@ sub OptionResponseAnalysis { &mt('There is no student data for this problem.'). ''); } else { - $r->print(&render_resource($resource)); $r->rflush(); if (exists($ENV{'form.ExcelOutput'})) { my $result = &prepare_optionresponse_excel_sheet($r,$resource, @@ -368,7 +399,7 @@ sub analyze_option_data_by_tries { $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries); foreach my $row (@$PerformanceData) { next if (! defined($row)); - my $tries = &get_tries_from_OR_row($row); + my $tries = &get_tries_from_row($row); my %Row = &Process_OR_Row($row); next if (! %Row); while (my ($foilid,$href) = each(%Row)) { @@ -412,14 +443,14 @@ sub time_analysis { ('enddate_'.$i); if (! defined($starttime) || ! defined($endtime)) { my $sec_in_day = 86400; - my $last_sub_time = &get_time_from_OR_row($PerformanceData->[-1]); + my $last_sub_time = &get_time_from_row($PerformanceData->[-1]); my ($sday,$smon,$syear); (undef,undef,undef,$sday,$smon,$syear) = localtime($last_sub_time - $sec_in_day*$i); $starttime = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear); $endtime = $starttime + $sec_in_day; if ($i == ($num_plots -1 )) { - $starttime = &get_time_from_OR_row($PerformanceData->[0]); + $starttime = &get_time_from_row($PerformanceData->[0]); } } my $startdateform = &Apache::lonhtmlcommon::date_setter @@ -431,12 +462,12 @@ sub time_analysis { my $end_index; my $j; while (++$j < scalar(@$PerformanceData)) { - last if (&get_time_from_OR_row($PerformanceData->[$j]) + last if (&get_time_from_row($PerformanceData->[$j]) > $starttime); } $begin_index = $j; while (++$j < scalar(@$PerformanceData)) { - last if (&get_time_from_OR_row($PerformanceData->[$j]) > $endtime); + last if (&get_time_from_row($PerformanceData->[$j]) > $endtime); } $end_index = $j; ## @@ -1254,15 +1285,25 @@ sub ProblemSelector { next if ($res->{'type'} ne 'assessment'); foreach my $part (@{$res->{'parts'}}) { my $partdata = $res->{'partdata'}->{$part}; - if (! exists($partdata->{'option'}) || - $partdata->{'option'} == 0) { +# &Apache::lonnet::logthis('----------------'); +# while (my ($k,$v)=each(%$partdata)) { +# if (ref($v) eq 'ARRAY') { +# &Apache::lonnet::logthis($k.' = '.join(',',@$v)); +# } else { +# &Apache::lonnet::logthis($k.' = '.$v); +# } +# } + if ((! exists($partdata->{'option'}) || + $partdata->{'option'} == 0 ) && + (! exists($partdata->{'radiobutton'}) || + $partdata->{'radiobutton'} == 0)) { next; } for (my $i=0;$i{'ResponseTypes'}});$i++){ my $respid = $partdata->{'ResponseIds'}->[$i]; my $resptype = $partdata->{'ResponseTypes'}->[$i]; - if ($resptype eq 'option') { - my $value = &Apache::lonnet::escape($res->{'symb'}.':'.$part.':'.$respid); + if ($resptype eq 'option' || $resptype eq 'radiobutton') { + my $value = &Apache::lonnet::escape($res->{'symb'}.':'.$part.':'.$respid.':'.$resptype); my $checked = ''; if ($ENV{'form.problemchoice'} eq $value) { $checked = 'checked '; @@ -1270,7 +1311,7 @@ sub ProblemSelector { $seq_str .= ''. ''. ''. - ''.$res->{'title'}.' '; + ''.$resptype.' '.$res->{'title'}.' '; if ($partdata->{'option'} > 1) { $seq_str .= &mt('response').' '.$respid; } @@ -1297,8 +1338,9 @@ sub ProblemSelector { ######################################################### sub get_problem_symb { my $problemstring = shift(); - my ($symb,$partid,$resid) = ($problemstring=~ /^(.*):([^:]*):([^:]*)$/); - return ($symb,$partid,$resid); + my ($symb,$partid,$resid,$resptype) = + ($problemstring=~ /^(.*):([^:]*):([^:]*):([^:]*)$/); + return ($symb,$partid,$resid,$resptype); } sub get_resource_from_symb { @@ -1313,18 +1355,26 @@ sub get_resource_from_symb { return undef; } -sub get_time_from_OR_row { + +######################################################### +######################################################### +## +## Misc Option Response functions +## +######################################################### +######################################################### +sub get_time_from_row { my ($row) = @_; if (ref($row)) { - return $row->[4]; + return $row->[&Apache::loncoursedata::RD_timestamp()]; } return undef; } -sub get_tries_from_OR_row { +sub get_tries_from_row { my ($row) = @_; if (ref($row)) { - return $row->[5]; + return $row->[&Apache::loncoursedata::RD_tries()]; } return undef; } @@ -1332,7 +1382,12 @@ sub get_tries_from_OR_row { sub Process_OR_Row { my ($row) = @_; my %RowData; - my ($student_id,$award,$grading,$submission,$time,$tries) = @$row; + my $student_id = $row->[&Apache::loncoursedata::RD_student_id()]; + my $award = $row->[&Apache::loncoursedata::RD_awarddetail()]; + my $grading = $row->[&Apache::loncoursedata::RD_response_eval()]; + my $submission = $row->[&Apache::loncoursedata::RD_submission()]; + my $time = $row->[&Apache::loncoursedata::RD_timestamp()]; + my $tries = $row->[&Apache::loncoursedata::RD_tries()]; return undef if ($award eq 'MISSING_ANSWER'); if ($award =~ /(APPROX_ANS|EXACT_ANS)/) { $RowData{'_correct'} = 1; @@ -1359,7 +1414,7 @@ sub Process_OR_Row { ## note: we must force each foil and option to not begin or end with ## spaces as they are stored without such data. ## -sub get_problem_data { +sub get_OR_problem_data { my ($url) = @_; my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze')); (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2); @@ -1395,6 +1450,50 @@ sub get_problem_data { } } } + return %Partdata; +} + +######################################################### +######################################################### +## +## Misc Radio Response functions +## +######################################################### +######################################################### +sub get_Radio_problem_student_data { + my ($row) = @_; +} + +sub get_Radio_problem_data { + my ($url) = @_; + my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze')); + (my $garbage,$Answ)=split(/_HASH_REF__/,$Answ,2); + my %Answer; + %Answer=&Apache::lonnet::str2hash($Answ); + my %Partdata; + &Apache::lonnet::logthis('url = '.$url); + foreach my $part (@{$Answer{'parts'}}) { + while (my($key,$value) = each(%Answer)) { + if (ref($value) eq 'ARRAY') { + &Apache::lonnet::logthis('is ref part:'.$part.' '.$key.'='.join(',',@$value)); + } else { + &Apache::lonnet::logthis('notref part:'.$part.' '.$key.'='.$value); + } + next if ($key !~ /^$part/); + $key =~ s/^$part\.//; + if ($key eq 'foils') { + $Partdata{$part}->{'_Foils'}=$value; + } elsif ($key eq 'options') { + $Partdata{$part}->{'_Options'}=$value; + } elsif ($key eq 'shown') { + $Partdata{$part}->{'_Shown'}=$value; + } elsif ($key =~ /^foil.value.(.*)$/) { + $Partdata{$part}->{$1}->{'value'}=$value; + } elsif ($key =~ /^foil.text.(.*)$/) { + $Partdata{$part}->{$1}->{'text'}=$value; + } + } + } return %Partdata; }