version 1.72, 2004/02/20 16:24:20
|
version 1.79, 2004/03/12 21:06:32
|
Line 161 sub BuildProblemAnalysisPage {
|
Line 161 sub BuildProblemAnalysisPage {
|
\@Students); |
\@Students); |
} elsif ($current_problem->{'resptype'} eq 'numerical') { |
} elsif ($current_problem->{'resptype'} eq 'numerical') { |
# if (exists($ENV{'form.ExcelOutput'})) { |
# if (exists($ENV{'form.ExcelOutput'})) { |
&Apache::lonstudentsubmissions::prepare_excel_output |
# &Apache::lonstudentsubmissions::prepare_excel_output |
($r,$current_problem,$ProblemData,\@Students); |
# ($r,$current_problem,$ProblemData,\@Students); |
# } else { |
# } else { |
# &NumericalResponseAnalysis($r,$current_problem, |
&NumericalResponseAnalysis($r,$current_problem, |
# $ProblemData,\@Students); |
$ProblemData,\@Students); |
# } |
# } |
} else { |
} else { |
$r->print('<h2>This analysis is not supported</h2>'); |
$r->print('<h2>This analysis is not supported</h2>'); |
Line 192 sub BuildProblemAnalysisPage {
|
Line 192 sub BuildProblemAnalysisPage {
|
######################################################### |
######################################################### |
sub NumericalResponseAnalysis { |
sub NumericalResponseAnalysis { |
my ($r,$problem,$ProblemData,$Students) = @_; |
my ($r,$problem,$ProblemData,$Students) = @_; |
$r->print('<h2>This analysis is not yet supported</h2>'); |
my $c = $r->connection(); |
my ($resource,$respid) = ($problem->{'resource'}, |
my ($resource,$respid) = ($problem->{'resource'}, |
$problem->{'respid'}); |
$problem->{'respid'}); |
my $analysis_html; |
my $analysis_html; |
Line 207 sub NumericalResponseAnalysis {
|
Line 207 sub NumericalResponseAnalysis {
|
$r->print($analysis_html); |
$r->print($analysis_html); |
return; |
return; |
} |
} |
|
# |
|
# This next call causes all the waiting around that people complain about |
my ($max,$min) = &GetStudentAnswers($r,$problem,$Students); |
my ($max,$min) = &GetStudentAnswers($r,$problem,$Students); |
$r->print('Maximum = '.$max.' Minimum = '.$min); |
return if ($c->aborted()); |
my $max_students = 0; |
# |
|
# Collate the data |
my %Data; |
my %Data; |
foreach my $student (@$Students) { |
foreach my $student (@$Students) { |
my $answer = $student->{'answer'}; |
my $answer = $student->{'answer'}; |
$Data{$answer}++; |
$Data{$answer}++; |
if ($max_students < $Data{$answer}) { |
|
$max_students = $Data{$answer}; |
|
} |
|
} |
|
foreach (5,10,20,25,50,75,100,150,200,250,500,1000,1500,2000,2500,5000) { |
|
if ($max_students < $_) { |
|
$max_students = $_; |
|
last; |
|
} |
|
} |
} |
my @Labels = sort {$a <=> $b } keys(%Data); |
my @Labels = sort {$a <=> $b } keys(%Data); |
$r->print('number of labels = '.scalar(@Labels)); |
|
my @PlotData = @Data{@Labels}; |
my @PlotData = @Data{@Labels}; |
$r->print('number of PlotData = '.scalar(@PlotData)); |
# |
my $graph = |
my $width = 500; |
&Apache::loncommon::DrawXYGraph('Correct Answer Distribution', |
my $height = 100; |
'Correct Answer', |
my $plot = &one_dimensional_plot($r,500,100,scalar(@$Students), |
'Number of students', |
\@Labels,\@PlotData); |
$max_students, |
$r->print($plot); |
undef, |
|
\@Labels, |
|
[\@PlotData], |
|
(xskip=>10)); |
|
$r->print($graph); |
|
return; |
return; |
} |
} |
|
|
|
sub one_dimensional_plot { |
|
my ($r,$width,$height,$N,$Labels,$Data)=@_; |
|
# |
|
# Compute data -> image scaling factors |
|
my $min = $Labels->[0]; |
|
my $max = $Labels->[-1]; |
|
my $h_scale = ($width-10)/($max-$min); |
|
# |
|
my $max_y = 0; |
|
foreach (@$Data) { |
|
$max_y = $_ if ($max_y < $_); |
|
} |
|
my $ticscale = 5; |
|
if ($max_y * $ticscale > $height/2) { |
|
$ticscale = int($height/2/$max_y); |
|
$ticscale = 1 if ($ticscale < 1); |
|
} |
|
# |
|
# Create the plot |
|
my $plot = |
|
qq{<drawimage width="$width" height="$height" bgcolor="transparent" >}; |
|
for (my $idx=0;$idx<scalar(@$Labels);$idx++) { |
|
my $xloc = 5+$h_scale*($Labels->[$idx] - $min); |
|
my $top = $height/2-$Data->[$idx]*$ticscale; |
|
my $bottom = $height/2+$Data->[$idx]*$ticscale; |
|
$plot .= |
|
&line($xloc,$top,$xloc,$bottom,'888888',1); |
|
} |
|
# |
|
# Put the scale on last to ensure it is on top of the data. |
|
if ($min < 0 && $max > 0) { |
|
my $circle_x = 5+$h_scale*abs($min); # '0' in data coordinates |
|
my $r = 4; |
|
$plot .= &line(5,$height/2,$circle_x-$r,$height/2,'000000',1); |
|
$plot .= &circle($circle_x,$height/2,$r+1,'000000'); |
|
$plot .= &line($circle_x+$r,$height/2,$width-5,$height/2,'000000',1); |
|
} else { |
|
$plot .= &line(5,$height/2,$width-5,$height/2,'000000',1); |
|
} |
|
$plot .= '</drawimage>'; |
|
my $plotresult = &Apache::lonxml::xmlparse($r,'web',$plot); |
|
|
|
my $title = 'Distribution of correct answers'; |
|
my $result = '<table>'. |
|
'<tr><td colspan="3" align="center">'. |
|
'<font size="+2">'.$title.' (N='.$N.')'. |
|
'</font>'. |
|
'</td></tr>'. |
|
'<tr>'. |
|
'<td valign="center">'.$min.'</td>'. |
|
'<td>'.$plotresult.'</td>'. |
|
'<td valign="center">'.$max.'</td>'. |
|
'</tr>'. |
|
'<tr><td colspan="3" align="center">'. |
|
'Maximum Number of Coinciding Values: '.$max_y. |
|
'</td></tr>'. |
|
'</table>'; |
|
return $result; |
|
} |
|
|
|
## |
|
## Helper subroutines for <drawimage>. |
|
## These should probably go somewhere more suitable soon. |
|
sub line { |
|
my ($x1,$y1,$x2,$y2,$color,$thickness) = @_; |
|
return qq{<line x1="$x1" y1="$y1" x2="$x2" y2="$y2" color="$color" thickness="$thickness" />$/}; |
|
} |
|
|
|
sub rectangle { |
|
my ($x1,$y1,$x2,$y2,$color,$thickness,$filled) = @_; |
|
return qq{<rectangle x1="$x1" y1="$y1" x2="$x2" y2="$y2" color="$color" thickness="$thickness" filled="$filled" />}; |
|
} |
|
|
|
sub arc { |
|
my ($x,$y,$width,$height,$start,$end,$color,$thickness,$filled)=@_; |
|
return qq{<arc x="$x" y="$y" width="$width" height="$height" start="$start" end="$end" color="$color" thickness="$thickness" filled="$filled" />}; |
|
} |
|
|
|
sub circle { |
|
my ($x,$y,$radius,$color,$thickness,$filled)=@_; |
|
return &arc($x,$y,$radius,$radius,0,360,$color,$thickness,$filled); |
|
} |
|
|
sub GetStudentAnswers { |
sub GetStudentAnswers { |
my ($r,$problem,$Students) = @_; |
my ($r,$problem,$Students) = @_; |
|
my $c = $r->connection(); |
my %Answers; |
my %Answers; |
my ($resource,$partid,$respid) = ($problem->{'resource'}, |
my ($resource,$partid,$respid) = ($problem->{'resource'}, |
$problem->{'part'}, |
$problem->{'part'}, |
Line 254 sub GetStudentAnswers {
|
Line 326 sub GetStudentAnswers {
|
$r->print("<table>\n"); |
$r->print("<table>\n"); |
$r->rflush(); |
$r->rflush(); |
foreach my $student (@$Students) { |
foreach my $student (@$Students) { |
|
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::analyze_problem_as_student |
Line 262 sub GetStudentAnswers {
|
Line 335 sub GetStudentAnswers {
|
&mt('last student')); |
&mt('last student')); |
$student->{'answer'} = $answer; |
$student->{'answer'} = $answer; |
} |
} |
|
return if ($c->aborted()); |
$r->print("</table>\n"); |
$r->print("</table>\n"); |
$r->rflush(); |
$r->rflush(); |
# close progress window |
# close progress window |
Line 541 sub OR_tries_analysis {
|
Line 615 sub OR_tries_analysis {
|
my $mintries = 1; |
my $mintries = 1; |
my $maxtries = $ENV{'form.NumPlots'}; |
my $maxtries = $ENV{'form.NumPlots'}; |
my ($table,$Foils,$Concepts) = &build_foil_index($ORdata); |
my ($table,$Foils,$Concepts) = &build_foil_index($ORdata); |
if ((@$Concepts < 2) && ($ENV{'form.AnalyzeAs'} ne 'Foils')) { |
if (! defined($Concepts) || |
|
((@$Concepts < 2) && ($ENV{'form.AnalyzeAs'} ne 'Foils'))) { |
$table = '<h3>'. |
$table = '<h3>'. |
&mt('Not enough data for concept analysis. '. |
&mt('Not enough data for concept analysis. '. |
'Performing Foil Analysis'). |
'Performing Foil Analysis'). |
Line 552 sub OR_tries_analysis {
|
Line 627 sub OR_tries_analysis {
|
$mintries,$maxtries); |
$mintries,$maxtries); |
my $analysis = ''; |
my $analysis = ''; |
if ($ENV{'form.AnalyzeAs'} eq 'Foils') { |
if ($ENV{'form.AnalyzeAs'} eq 'Foils') { |
$analysis = &OR_Tries_Foil_Analysis($mintries,$maxtries,$Foils, |
$analysis = &OR_Tries_Foil_Analysis($mintries,$maxtries,$Concepts, |
\%ResponseData,$ORdata); |
\%ResponseData,$ORdata); |
} else { |
} else { |
$analysis = &OR_Tries_Concept_Analysis($mintries,$maxtries, |
$analysis = &OR_Tries_Concept_Analysis($mintries,$maxtries, |
Line 563 sub OR_tries_analysis {
|
Line 638 sub OR_tries_analysis {
|
} |
} |
|
|
sub OR_Tries_Foil_Analysis { |
sub OR_Tries_Foil_Analysis { |
my ($mintries,$maxtries,$Foils,$respdat,$ORdata) = @_; |
my ($mintries,$maxtries,$Concepts,$respdat,$ORdata) = @_; |
my %ResponseData = %$respdat; |
my %ResponseData = %$respdat; |
# |
# |
# Compute the data neccessary to make the plots |
# Compute the data neccessary to make the plots |
my @PlotData; |
my @PlotData; |
foreach my $foilid (@$Foils) { |
foreach my $concept (@$Concepts) { |
for (my $i=$mintries;$i<=$maxtries;$i++) { |
foreach my $foilid (@{$concept->{'foils'}}) { |
if ($ResponseData{$foilid}->[$i]->{'_total'} == 0) { |
for (my $try=$mintries;$try<=$maxtries;$try++) { |
push(@{$PlotData[$i]->{'_correct'}},0); |
if ($ResponseData{$foilid}->[$try]->{'_total'} == 0) { |
} else { |
push(@{$PlotData[$try]->{'_correct'}},0); |
push(@{$PlotData[$i]->{'_correct'}}, |
|
100*$ResponseData{$foilid}->[$i]->{'_correct'}/ |
|
$ResponseData{$foilid}->[$i]->{'_total'}); |
|
} |
|
foreach my $option (@{$ORdata->{'_Options'}}) { |
|
push(@{$PlotData[$i]->{'_total'}}, |
|
$ResponseData{$foilid}->[$i]->{'_total'}); |
|
if ($ResponseData{$foilid}->[$i]->{'_total'} == 0) { |
|
push (@{$PlotData[$i]->{$option}},0); |
|
} else { |
} else { |
if ($ResponseData{$foilid}->[$i]->{'_total'} == |
push(@{$PlotData[$try]->{'_correct'}}, |
$ResponseData{$foilid}->[$i]->{'_correct'}) { |
100*$ResponseData{$foilid}->[$try]->{'_correct'}/ |
push(@{$PlotData[$i]->{$option}},0); |
$ResponseData{$foilid}->[$try]->{'_total'}); |
|
} |
|
foreach my $option (@{$ORdata->{'_Options'}}) { |
|
push(@{$PlotData[$try]->{'_total'}}, |
|
$ResponseData{$foilid}->[$try]->{'_total'}); |
|
if ($ResponseData{$foilid}->[$try]->{'_total'} == 0) { |
|
push (@{$PlotData[$try]->{$option}},0); |
} else { |
} else { |
push (@{$PlotData[$i]->{$option}}, |
if ($ResponseData{$foilid}->[$try]->{'_total'} == |
100 * $ResponseData{$foilid}->[$i]->{$option} / |
$ResponseData{$foilid}->[$try]->{'_correct'}) { |
($ResponseData{$foilid}->[$i]->{'_total'} - |
push(@{$PlotData[$try]->{$option}},0); |
$ResponseData{$foilid}->[$i]->{'_correct'})); |
} else { |
|
push (@{$PlotData[$try]->{$option}}, |
|
100 * |
|
$ResponseData{$foilid}->[$try]->{$option} / |
|
($ResponseData{$foilid}->[$try]->{'_total'} |
|
- |
|
$ResponseData{$foilid}->[$try]->{'_correct'} |
|
)); |
|
} |
} |
} |
} |
} # End of foreach my $option |
} |
} |
} |
} # End of foreach my $foilid |
} |
} # End of foreach my $concept |
# |
# |
# Build a table for the plots |
# Build a table for the plots |
my $analysis_html = "<table>\n"; |
my $analysis_html = "<table>\n"; |
my $foilkey = &build_option_index($ORdata); |
my $optionkey = &build_option_index($ORdata); |
for (my $i=$mintries;$i<=$maxtries;$i++) { |
for (my $try=$mintries;$try<=$maxtries;$try++) { |
my $count = $ResponseData{'_total'}->[$i]; |
my $count = $ResponseData{'_total'}->[$try]; |
if ($count == 0) { |
my $title = 'Submission '.$try.' (N='.$count.')'; |
$count = 'no submissions'; |
|
} elsif ($count == 1) { |
|
$count = '1 submission'; |
|
} else { |
|
$count = $count.' submissions'; |
|
} |
|
my $title = 'Attempt '.$i.', '.$count; |
|
my @Datasets; |
my @Datasets; |
foreach my $option ('_correct',@{$ORdata->{'_Options'}}) { |
foreach my $option ('_correct',@{$ORdata->{'_Options'}}) { |
next if (! exists($PlotData[$i]->{$option})); |
next if (! exists($PlotData[$try]->{$option})); |
push(@Datasets,$PlotData[$i]->{$option}); |
push(@Datasets,$PlotData[$try]->{$option}); |
|
} |
|
# |
|
# Put a blank in the data set between concepts |
|
for (my $set =0;$set<=$#Datasets;$set++) { |
|
my @Data = @{$Datasets[$set]}; |
|
my $idx = 0; |
|
foreach my $concept (@{$Concepts}) { |
|
foreach my $foilid (@{$concept->{'foils'}}) { |
|
$Datasets[$set]->[$idx++]=shift(@Data); |
|
} |
|
if ($concept->{'name'} ne $Concepts->[-1]->{'name'}) { |
|
$Datasets[$set]->[$idx++] = 0; |
|
} |
|
} |
|
} |
|
# |
|
# Set up the labels needed for the bar graph |
|
my @Labels; |
|
my $idx = 1; |
|
foreach my $concept (@{$Concepts}) { |
|
foreach my $foilid (@{$concept->{'foils'}}) { |
|
push(@Labels,$idx++); |
|
} |
|
push(@Labels,''); |
} |
} |
|
# |
my $correctgraph = &Apache::loncommon::DrawBarGraph |
my $correctgraph = &Apache::loncommon::DrawBarGraph |
($title,'Foil Number','Percent Correct', |
($title,'Foil Number','Percent Correct', |
100,$plotcolors,undef,$Datasets[0]); |
100,$plotcolors,\@Labels,$Datasets[0]); |
$analysis_html.= '<tr><td>'.$correctgraph.'</td>'; |
$analysis_html.= '<tr><td>'.$correctgraph.'</td>'; |
## |
|
## |
# |
|
# |
next if (! defined($Datasets[0])); |
next if (! defined($Datasets[0])); |
for (my $i=0; $i< scalar(@{$Datasets[0]});$i++) { |
for (my $i=0; $i< scalar(@{$Datasets[0]});$i++) { |
$Datasets[0]->[$i]=0; |
$Datasets[0]->[$i]=0; |
} |
} |
$count = $ResponseData{'_total'}->[$i]-$ResponseData{'_correct'}->[$i]; |
$count = $ResponseData{'_total'}->[$try] - |
if ($count == 0) { |
$ResponseData{'_correct'}->[$try]; |
$count = 'no submissions'; |
$title = 'Submission '.$try.' (N='.$count.')'; |
} elsif ($count == 1) { |
|
$count = '1 submission'; |
|
} else { |
|
$count = $count.' submissions'; |
|
} |
|
$title = 'Attempt '.$i.', '.$count; |
|
my $incorrectgraph = &Apache::loncommon::DrawBarGraph |
my $incorrectgraph = &Apache::loncommon::DrawBarGraph |
($title,'Foil Number','% Option Chosen Incorrectly', |
($title,'Foil Number','% Option Chosen Incorrectly', |
100,$plotcolors,undef,@Datasets); |
100,$plotcolors,\@Labels,@Datasets); |
$analysis_html.= '<td>'.$incorrectgraph.'</td>'; |
$analysis_html.= '<td>'.$incorrectgraph.'</td>'; |
$analysis_html.= '<td>'.$foilkey."<td></tr>\n"; |
$analysis_html.= '<td>'.$optionkey."<td></tr>\n"; |
} |
} |
$analysis_html .= "</table>\n"; |
$analysis_html .= "</table>\n"; |
return $analysis_html; |
return $analysis_html; |