{'_Options'}});$i++) {
+ push(@{$plotdata[$i+1]},0);
}
}
#
# Create the plot
- my $count = $end_index-$begin_index;
- my $title;
- if ($count == 0) {
- $title = 'no submissions';
- } elsif ($count == 1) {
- $title = 'one submission';
- } else {
- $title = $count.' submissions';
- }
- my $correctplot = &Apache::loncommon::DrawBarGraph($title,
- 'Foil Number',
- 'Percent Correct',
- 100,
- $plotcolors,
- undef,
- $Plotdata[0]);
- for (my $j=0; $j< scalar(@{$Plotdata[0]});$j++) {
- $Plotdata[0]->[$j]=0;
- }
- $count = $end_index-$begin_index-$TimeData{'_correct'};
- if ($count == 0) {
- $title = 'no submissions';
- } elsif ($count == 1) {
- $title = 'one submission';
- } else {
- $title = $count.' submissions';
- }
- my $incorrectplot = &Apache::loncommon::DrawBarGraph($title,
- 'Foil Number',
- 'Incorrect Option Choice',
- 100,
- $plotcolors,
- undef,
- @Plotdata);
- $analysis_html.=''.
- ''.$correctplot.' | '.
- ''.$incorrectplot.' | '.
- ''.$foilkey.' | '."
\n";
- $analysis_html.= ''.''.
- 'Start Time:'.
- ' '.$interval->{'startdateform'}.' '.
- 'End Time : '.
- ' '.$interval->{'enddateform'}.' '.
-# 'Plot Title :'.
-# (" "x3).$interval->{'titleform'}.
- ' | '.
- "
\n";
- return $analysis_html;
+ my $correct_plot = &Apache::loncommon::DrawBarGraph('Correct Statements',
+ 'Statement Number',
+ 'Percent Correct',
+ 100,
+ $plotcolors,
+ undef,
+ $plotdata[0],
+ {xskip=>1});
+ for (my $j=0; $j< scalar(@{$plotdata[0]});$j++) {
+ $plotdata[0]->[$j]=0;
+ }
+ my $incorrect_plot =
+ &Apache::loncommon::DrawBarGraph('Incorrect Statements',
+ 'Statement Number',
+ 'Incorrect Option Choice',
+ 100,
+ $plotcolors,
+ undef,
+ @plotdata,{xskip=>1});
+ return ($correct_plot,$incorrect_plot);
}
sub OR_Concept_Time_Analysis {
- my ($PerformanceData,$ORdata,$Concepts,$interval) = @_;
- my $analysis_html;
- ##
- ## Determine starttime, endtime, startindex, endindex
- my ($begin_index,$end_index) = ($interval->{'begin_index'},
- $interval->{'end_index'});
- my %TimeData;
- #
- # Compute the number getting the foils correct or incorrects
- for (my $j=$begin_index;$j<=$end_index;$j++) {
- my $row = $PerformanceData->[$j];
- next if (! defined($row));
- my %Row = &Process_OR_Row($row);
- while (my ($foilid,$href) = each(%Row)) {
- if (! ref($href)) {
- $TimeData{$foilid} += $href;
- next;
- }
- while (my ($option,$value) = each(%$href)) {
- $TimeData{$foilid}->{$option}+=$value;
- }
- }
- }
+ my ($processed_time_data,$correct,$data_count,$student_count,
+ $ORdata,$Concepts) = @_;
+ return '' if ($data_count == 0);
#
# Put the data in plottable form
- my @Plotdata;
+ my @plotdata;
foreach my $concept (@$Concepts) {
my ($total,$correct);
foreach my $foil (@{$concept->{'foils'}}) {
- $total += $TimeData{$foil}->{'_total'};
- $correct += $TimeData{$foil}->{'_correct'};
+ $total += $processed_time_data->{$foil}->{'_total'};
+ $correct += $processed_time_data->{$foil}->{'_correct'};
}
if ($total == 0) {
- push(@Plotdata,0);
+ push(@plotdata,0);
} else {
- push(@Plotdata,100 * $correct / $total);
+ push(@plotdata,100 * $correct / $total);
}
}
#
# Create the plot
- my $title = ($end_index - $begin_index).' submissions';
- my $correctplot = &Apache::loncommon::DrawBarGraph($title,
- 'Concept Number',
- 'Percent Correct',
- 100,
- $plotcolors,
- undef,
- \@Plotdata);
- $analysis_html.=''.
- ''.$correctplot.' | '.
- ''.
- 'Start Time: '.$interval->{'startdateform'}.' '.
- 'End Time : '.
- ' '.$interval->{'enddateform'}.' '.
-# 'Plot Title :'.(" "x3).
-# $interval->{'titleform'}.
- ' | '.
- "
\n";
- return $analysis_html;
-}
-
-#########################################################
-#########################################################
-##
-## Excel output
-##
-#########################################################
-#########################################################
-sub OR_excel_sheet {
- my ($r,$resource,$PerformanceData,$ORdata) = @_;
- my $response = '';
- my (undef,$Foils,$Concepts) = &build_foil_index($ORdata);
- #
- # Create excel worksheet
- my $filename = '/prtspool/'.
- $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
- time.'_'.rand(1000000000).'.xls';
- my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
- if (! defined($workbook)) {
- $r->log_error("Error creating excel spreadsheet $filename: $!");
- $r->print(''.&mt("Unable to create new Excel file. ".
- "This error has been logged. ".
- "Please alert your LON-CAPA administrator").
- '
');
+ return &Apache::loncommon::DrawBarGraph('Correct Concepts',
+ 'Concept Number',
+ 'Percent Correct',
+ 100,
+ $plotcolors,
+ undef,
+ \@plotdata,{xskip=>1});
+}
+
+sub OR_time_process_data {
+ my ($performance_data,$begin_index,$end_index)=@_;
+ my %processed_time_data;
+ my %distinct_students;
+ my ($correct,$data_count);
+ if (($begin_index == $end_index) &&
+ ($end_index != scalar(@$performance_data)-1)) {
return undef;
}
- #
- $workbook->set_tempdir('/home/httpd/perl/tmp');
- my $format = &Apache::loncommon::define_excel_formats($workbook);
- #
- # Create and populate main worksheets
- my $problem_data_sheet = $workbook->addworksheet('Problem Data');
- my $student_data_sheet = &build_student_data_worksheet($workbook,$format);
- my $response_data_sheet = $workbook->addworksheet('Response Data');
- foreach my $sheet ($problem_data_sheet,$student_data_sheet,
- $response_data_sheet) {
- $sheet->write(0,0,$resource->{'title'},$format->{'h2'});
- $sheet->write(1,0,$resource->{'src'},$format->{'h3'});
- }
- #
- my $result;
- $result = &OR_build_problem_data_worksheet($problem_data_sheet,$format,
- $Concepts,$ORdata);
- if ($result ne 'okay') {
- # Do something useful
- }
- $result = &OR_build_response_data_worksheet($response_data_sheet,$format,
- $PerformanceData,$Foils,
- $ORdata);
- if ($result ne 'okay') {
- # Do something useful
- }
- $response_data_sheet->activate();
- #
- # Close the excel file
- $workbook->close();
- #
- # Write a link to allow them to download it
- $result .= ''.&mt('Excel Raw Data Output').'
'.
- ''.
- &mt('Your Excel spreadsheet.').
- '
'."\n";
- return $result;
-}
-
-sub OR_build_problem_data_worksheet {
- my ($worksheet,$format,$Concepts,$ORdata) = @_;
- my $rows_output = 3;
- my $cols_output = 0;
- $worksheet->write($rows_output++,0,'Problem Structure',$format->{'h3'});
- ##
- ##
- my @Headers;
- if (@$Concepts > 1) {
- @Headers = ("Concept\nNumber",'Concept',"Foil\nNumber",
- 'Foil Name','Foil Text','Correct value');
- } else {
- @Headers = ('Foil Number','FoilName','Foil Text','Correct value');
- }
- $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
- my %Foildata = %{$ORdata->{'_Foils'}};
- my $conceptindex = 1;
- my $foilindex = 1;
- foreach my $concept (@$Concepts) {
- my @FoilsInConcept = @{$concept->{'foils'}};
- my $firstfoil = shift(@FoilsInConcept);
- if (@$Concepts > 1) {
- $worksheet->write_row($rows_output++,0,
- [$conceptindex,
- $concept->{'name'},
- $foilindex++,
- $Foildata{$firstfoil}->{'name'},
- $Foildata{$firstfoil}->{'text'},
- $Foildata{$firstfoil}->{'value'},]);
- } else {
- $worksheet->write_row($rows_output++,0,
- [ $foilindex++,
- $Foildata{$firstfoil}->{'name'},
- $Foildata{$firstfoil}->{'text'},
- $Foildata{$firstfoil}->{'value'},]);
- }
- foreach my $foilid (@FoilsInConcept) {
- if (@$Concepts > 1) {
- $worksheet->write_row($rows_output++,0,
- ['',
- '',
- $foilindex,
- $Foildata{$foilid}->{'name'},
- $Foildata{$foilid}->{'text'},
- $Foildata{$foilid}->{'value'},]);
- } else {
- $worksheet->write_row($rows_output++,0,
- [$foilindex,
- $Foildata{$foilid}->{'name'},
- $Foildata{$foilid}->{'text'},
- $Foildata{$foilid}->{'value'},]);
- }
- } continue {
- $foilindex++;
- }
- } continue {
- $conceptindex++;
- }
- $rows_output++;
- $rows_output++;
- ##
- ## Option data output
- $worksheet->write($rows_output++,0,'Options',$format->{'header'});
- foreach my $string (@{$ORdata->{'_Options'}}) {
- $worksheet->write($rows_output++,0,$string);
- }
- return 'okay';
-}
-
-sub OR_build_response_data_worksheet {
- my ($worksheet,$format,$PerformanceData,$Foils,$ORdata)=@_;
- my $rows_output = 3;
- my $cols_output = 0;
- $worksheet->write($rows_output++,0,'Response Data',$format->{'h3'});
- $worksheet->set_column(1,1,20);
- $worksheet->set_column(2,2,13);
- my @Headers = ('identifier','time','award detail','attempt');
- foreach my $foil (@$Foils) {
- push (@Headers,$foil.' submission');
- push (@Headers,$foil.' grading');
- }
- $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
- #
- foreach my $row (@$PerformanceData) {
- next if (! defined($row));
- my ($student,$award,$grading,$submission,$time,$tries) = @$row;
- my @Foilgrades = split('&',$grading);
- my @Foilsubs = split('&',$submission);
- my %ResponseData;
- for (my $j=0;$j<=$#Foilgrades;$j++) {
- my ($foilid,$correct) = split('=',$Foilgrades[$j]);
- my (undef,$submission) = split('=',$Foilsubs[$j]);
- $submission = &Apache::lonnet::unescape($submission);
- $ResponseData{$foilid.' submission'}=$submission;
- $ResponseData{$foilid.' award'}=$correct;
- }
- $worksheet->write($rows_output,$cols_output++,$student);
- $worksheet->write($rows_output,$cols_output++,
- &Apache::lonstathelpers::calc_serial($time),$format->{'date'});
- $worksheet->write($rows_output,$cols_output++,$award);
- $worksheet->write($rows_output,$cols_output++,$tries);
- foreach my $foilid (@$Foils) {
- $worksheet->write($rows_output,$cols_output++,
- $ResponseData{$foilid.' submission'});
- $worksheet->write($rows_output,$cols_output++,
- $ResponseData{$foilid.' award'});
+ # Be sure we include the last one if we are asked for it.
+ # That we have to correct here (and not when $end_index is
+ # given a value) should probably be considered a bug.
+ if ($end_index == scalar(@$performance_data)-1) {
+ $end_index++;
+ }
+ my $count;
+ for (my $i=$begin_index;$i<$end_index;$i++) {
+ my $attempt = $performance_data->[$i];
+ $count++;
+ next if (! defined($attempt));
+ my %attempt = &Process_OR_Row($attempt);
+ $data_count++;
+ $correct += $attempt{'_correct'};
+ $distinct_students{$attempt->[&Apache::loncoursedata::RD_student_id()]}++;
+ while (my ($foilid,$href) = each(%attempt)) {
+ if (! ref($href)) {
+ $processed_time_data{$foilid} += $href;
+ next;
+ }
+ while (my ($option,$value) = each(%$href)) {
+ $processed_time_data{$foilid}->{$option}+=$value;
+ }
}
- $rows_output++;
- $cols_output = 0;
}
- return;
+ return (\%processed_time_data,$correct,$data_count,
+ scalar(keys(%distinct_students)));
}
sub build_foil_index {
@@ -1220,18 +1722,18 @@ sub build_foil_index {
if (@Concepts > 1) {
$table .= ''.
''.$conceptindex.' | '.
- ''.&HTML::Entities::encode($concept->{'name'}).' | '.
+ ''.&HTML::Entities::encode($concept->{'name'},'<>&"').' | '.
''.$foilindex++.' | '.
- ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'}).' | '.
+ ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').' | '.
''.$Foildata{$firstfoil}->{'text'}.' | '.
- ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'}).' | '.
+ ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').' | '.
"
\n";
} else {
$table .= ''.
''.$foilindex++.' | '.
- ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'}).' | '.
+ ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').' | '.
''.$Foildata{$firstfoil}->{'text'}.' | '.
- ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'}).' | '.
+ ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').' | '.
"
\n";
}
foreach my $foilid (@FoilsInConcept) {
@@ -1240,16 +1742,16 @@ sub build_foil_index {
' | '.
' | '.
''.$foilindex.' | '.
- ''.&HTML::Entities::encode($Foildata{$foilid}->{'name'}).' | '.
+ ''.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').' | '.
''.$Foildata{$foilid}->{'text'}.' | '.
- ''.&HTML::Entities::encode($Foildata{$foilid}->{'value'}).' | '.
+ ''.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').' | '.
"\n";
} else {
$table .= ''.
''.$foilindex.' | '.
- ''.&HTML::Entities::encode($Foildata{$foilid}->{'name'}).' | '.
+ ''.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').' | '.
''.$Foildata{$foilid}->{'text'}.' | '.
- ''.&HTML::Entities::encode($Foildata{$foilid}->{'value'}).' | '.
+ ''.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').' | '.
"
\n";
}
} continue {
@@ -1270,11 +1772,12 @@ sub build_option_index {
my $optionindex = 0;
my @Rows;
foreach my $option (&mt('correct option chosen'),@{$ORdata->{'_Options'}}) {
+ my $color = $plotcolors->[$optionindex++];
push (@Rows,
''.
- ''.
- (' 'x4).' | '.
- ''.&HTML::Entities::encode($option).' | '.
+ ''.
+ ''.('*'x3).''.' | '.
+ ''.&HTML::Entities::encode($option,'<>&"').' | '.
"
\n");
}
shift(@Rows); # Throw away 'correct option chosen' color
@@ -1282,6 +1785,27 @@ sub build_option_index {
$table .= "