".$ENV{'course.'.$ENV{'request.course.id'}.'.description'}.
+ $r->print("".$env{'course.'.$env{'request.course.id'}.'.description'}.
" ".localtime(time)."
");
+ #
+ if ($chosen_output->{'base'} !~ /^final table/) {
+ $r->print("".&mt($chosen_output->{'shortdesc'})."
");
+ }
my $Str = "\n";
# First, the @StudentData fields need to be listed
my @to_show = &get_student_fields_to_show();
@@ -463,23 +696,133 @@ sub html_initialize {
my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
$Str .= $title.' 'x($width-$base).$padding;
}
- # Now the selected sequences need to be listed
- foreach my $sequence (&get_sequences_to_show) {
- my $title = $sequence->{'title'};
- my $base = $sequence->{'base_width'};
- my $width = $sequence->{'width'};
- $Str .= $title.' 'x($width-$base).$padding;
+ #
+ # Compute the column widths and output the sequence titles
+ my $total_count;
+ #
+ # Compute sequence widths
+ my $starttime = Time::HiRes::time;
+ foreach my $seq (@sequences) {
+ my $symb = $seq->symb;
+ my $title = $seq->compTitle;
+ $width{$symb}->{'width_sum'} = 0;
+ # Compute width of sum
+ if ($chosen_output->{'sequence_sum'}) {
+ if ($chosen_output->{'every_problem'}) {
+ # Use 1 digit for a space
+ $width{$symb}->{'width_sum'} += 1;
+ }
+ $total_count += &count_parts($navmap,$seq);
+ # Use 6 digits for the sum
+ $width{$symb}->{'width_sum'} += 6;
+ }
+ # Compute width of maximum
+ if ($chosen_output->{'sequence_max'}) {
+ if ($width{$symb}->{'width_sum'}>0) {
+ # One digit for the '/'
+ $width{$symb}->{'width_sum'} +=1;
+ }
+ # Use 6 digits for the total
+ $width{$symb}->{'width_sum'}+=6;
+ }
+ #
+ if ($chosen_output->{'every_problem'}) {
+ # one problem per digit
+ $width{$symb}->{'width_parts'}= &count_parts($navmap,$seq);
+ $width{$symb}->{'width_problem'} += $width{$symb}->{'width_parts'};
+ } else {
+ $width{$symb}->{'width_problem'} = 0;
+ }
+ $width{$symb}->{'width_total'} = $width{$symb}->{'width_problem'} +
+ $width{$symb}->{'width_sum'};
+ if ($width{$symb}->{'width_total'} < length(&HTML::Entities::decode($title))) {
+ $width{$symb}->{'width_total'} = length(&HTML::Entities::decode($title));
+ }
+ #
+ # Output the sequence titles
+ $Str .= $title.(' 'x($width{$symb}->{'width_total'}-
+ length($title)
+ )).$padding;
}
- $Str .= "total (of shown problems)
\n";
+ $total_sum_width = length($total_count)+1;
+ $Str .= " total\n";
$Str .= "";
$r->print($Str);
$r->rflush();
+
+ $r->print(<
+// get the left offset of a given widget as an absolute position
+function getLeftOffset (element) {
+ return collect(element, "offsetLeft");
+}
+
+// get the top offset of a given widget as an absolute position
+function getTopOffset (element) {
+ return collect(element, "offsetTop");
+}
+
+function collect(element, att) {
+ var val = 0;
+ while(element) {
+ val += element[att];
+ element = element.offsetParent;
+ }
+ return val;
+}
+
+var currentDiv;
+var currentElement;
+function popup_score(element, score) {
+ popdown_score();
+ var left = getLeftOffset(element);
+ var top = getTopOffset(element);
+ var div = document.createElement("div");
+ div.className = "LC_chrt_popup";
+ div.appendChild(document.createTextNode(score));
+ div.style.position = "absolute";
+ div.style.top = (top - 25) + "px";
+ div.style.left = (left - 10) + "px";
+ currentDiv = div;
+ document.body.insertBefore(div, document.body.childNodes[0]);
+ element.className = "LC_chrt_popup_up";
+ currentElement = element;
+}
+
+function popdown_score() {
+ if (currentDiv) {
+ document.body.removeChild(currentDiv);
+ }
+ if (currentElement) {
+ currentElement.className = 'LC_chrt_popup_exists';
+ }
+ currentDiv = undefined;
+}
+
+JS
+
+ #
+ # Let the user know what we are doing
+ my $studentcount = scalar(@Apache::lonstatistics::Students);
+ if ($env{'form.SelectedStudent'}) {
+ $studentcount = '1';
+ }
+ #
+ # Initialize progress window
+ %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
+ ($r,'HTML Chart Status',
+ 'HTML Chart Progress', $studentcount,
+ 'inline',undef,'Statistics','stats_status');
+ #
+ &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
+ 'Processing first student');
return;
}
sub html_outputstudent {
my ($r,$student) = @_;
my $Str = '';
+ return if (! defined($navmap));
#
if($count++ % 5 == 0 && $count > 0) {
$r->print("
");
@@ -488,6 +831,10 @@ sub html_outputstudent {
my @to_show = &get_student_fields_to_show();
foreach my $field (@to_show) {
my $title=$student->{$field};
+ # Deal with 'comments' - how I love special cases
+ if ($field eq 'comments') {
+ $title = ''.&mt('Comments').'';
+ }
my $base = length($title);
my $width=$Apache::lonstatistics::StudentData{$field}->{'width'};
$Str .= $title.' 'x($width-$base).$padding;
@@ -496,12 +843,21 @@ sub html_outputstudent {
my %StudentsData;
my @tmp = &Apache::loncoursedata::get_current_state
($student->{'username'},$student->{'domain'},undef,
- $ENV{'request.course.id'});
- if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
+ $env{'request.course.id'});
+ if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:(.*)/)) {
%StudentsData = @tmp;
- }
- if (scalar(@tmp) < 1) {
- $Str .= 'No Course Data'."\n";
+ } else {
+ my $error = $1;
+ if (scalar(@tmp) < 1) {
+ $Str .= ''
+ .&mt('No Course Data')
+ .''."\n";
+ } else {
+ $Str .= ''
+ .&mt('Error getting student data ([_1])',$error)
+ .''."\n";
+ }
+ $nodata_count++;
$r->print($Str);
$r->rflush();
return;
@@ -510,128 +866,174 @@ sub html_outputstudent {
# By sequence build up the data
my $studentstats;
my $PerformanceStr = '';
- foreach my $seq (&get_sequences_to_show) {
- my ($performance,$score,$seq_max) =
- &StudentPerformanceOnSequence($student,\%StudentsData,
- $seq,$show_links);
- my $ratio = $score.'/'.$seq_max;
- #
- if ($show eq 'totals') {
- $performance = ' 'x(length($seq_max)-length($score)).$ratio;
- $performance .= ' 'x($seq->{'width'}-length($performance));
- } elsif ($show eq 'scores') {
- $performance = $score;
- $performance .= ' 'x($seq->{'width'}-length($performance));
+ foreach my $seq (@sequences) {
+ my $symb = $seq->symb;
+ my ($performance,$performance_length,$score,$seq_max,$rawdata);
+ if ($chosen_output->{'tries'}) {
+ ($performance,$performance_length,$score,$seq_max,$rawdata) =
+ &student_tries_on_sequence($student,\%StudentsData,
+ $navmap,$seq,$show_links);
} else {
- # Pad with extra spaces
- $performance .= ' 'x($seq->{'width'}-$seq_max-
- length($ratio)
- ).$ratio;
+ ($performance,$performance_length,$score,$seq_max,$rawdata) =
+ &student_performance_on_sequence($student,\%StudentsData,
+ $navmap,$seq,$show_links,
+ $chosen_output->{ignore_weight});
+ }
+ my $ratio='';
+ if ($chosen_output->{'every_problem'} &&
+ $chosen_output->{'sequence_sum'}) {
+ $ratio .= ' ';
+ }
+ if ($chosen_output->{'sequence_sum'} && $score ne ' ') {
+ my $score .= sprintf("%3.2f",$score);
+ $ratio .= (' 'x(6-length($score))).$score;
+ } elsif($chosen_output->{'sequence_sum'}) {
+ $ratio .= ' 'x6;
}
+ if ($chosen_output->{'sequence_max'}) {
+ if ($chosen_output->{'sequence_sum'}) {
+ $ratio .= '/';
+ }
+ my $sequence_total=sprintf("%3.2f",$seq_max);
+ $ratio .= $sequence_total.(' 'x(6-length($sequence_total)));
+ }
+ #
+ if (! $chosen_output->{'every_problem'}) {
+ $performance = '';
+ $performance_length=0;
+ }
+ $performance .= ' 'x($width{$symb}->{'width_total'} -
+ $performance_length -
+ $width{$symb}->{'width_sum'}).
+ $ratio;
#
$Str .= $performance.$padding;
#
- $studentstats->{$seq->{'symb'}}->{'score'}= $score;
- $studentstats->{$seq->{'symb'}}->{'max'} = $seq_max;
+ $studentstats->{$symb}->{'score'}= $score;
+ $studentstats->{$symb}->{'max'} = $seq_max;
}
#
# Total it up and store the statistics info.
- my ($score,$max) = (0,0);
+ my ($score,$max);
while (my ($symb,$seq_stats) = each (%{$studentstats})) {
$Statistics->{$symb}->{'score'} += $seq_stats->{'score'};
- $Statistics->{$symb}->{'max'} += $seq_stats->{'max'};
- $score += $seq_stats->{'score'};
+ if ($Statistics->{$symb}->{'max'} < $seq_stats->{'max'}) {
+ $Statistics->{$symb}->{'max'} = $seq_stats->{'max'};
+ }
+ if ($seq_stats->{'score'} ne ' ') {
+ $score += $seq_stats->{'score'};
+ $Statistics->{$symb}->{'num_students'}++;
+ }
$max += $seq_stats->{'max'};
}
- $Str .= ' '.' 'x(length($max)-length($score)).$score.'/'.$max;
+ if (! defined($score)) {
+ $score = ' ' x $total_sum_width;
+ } else {
+ $score = sprintf("%.2f",$score);
+ $score = (' 'x(6-length($score))).$score;
+ }
+ $Str .= ' '.' 'x($total_sum_width-length($score)).$score.' / '.$max;
$Str .= " \n";
+ #
$r->print($Str);
#
$r->rflush();
+ &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,'last student');
return;
}
sub html_finish {
my ($r) = @_;
+ return if (! defined($navmap));
+ #
+ # Check for suppressed output and close the progress window if so
$r->print("
\n");
+ if ($chosen_output->{'summary_table'}) {
+ if ($single_student_mode) {
+ $r->print(&SingleStudentTotal());
+ } else {
+ $r->print(&StudentAverageTotal());
+ }
+ }
$r->rflush();
+ &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
+ &html_cleanup();
return;
}
-}
-
-#######################################################
-#######################################################
-
-=pod
-
-=head2 Multi-Sheet EXCEL subroutines
-
-=item &multi_sheet_excel_initialize($r)
-
-=item &multi_sheet_excel_outputstudent($r,$student)
-
-=item &multi_sheet_excel_finish($r)
-
-=cut
-
-#######################################################
-#######################################################
-{
-
-sub multi_sheet_excel_initialize {
- my ($r)=@_;
- $r->print("Not yet implemented
");
- #
- # Estimate the size of the file. We would like to have < 5 megs of data.
- my $max_size = 5000000;
- my $num_students = scalar(@Apache::lonstatistics::Students);
- my $num_sequences = 0;
- my $num_data_per_part = 2; # 'status' and 'numtries'
- my $fields_per_student = scalar(&get_student_fields_to_show());
- my $bytes_per_field = 20; # Back of the envelope calculation
- foreach my $seq (&get_sequences_to_show) {
- $num_sequences++ if ($seq->{'num_assess'} > 0);
- $fields_per_student += $num_data_per_part * $seq->{'num_assess_parts'};
- }
- my $size_estimate = $fields_per_student*$num_students*$bytes_per_field;
- #
- # Compute number of workbooks
- my $num_workbooks = 1;
- if ($size_estimate > $max_size) { # try to stay under 5 megs
- $num_workbooks += int($size_estimate / $max_size);
- }
- if ($show eq 'by section') {
- if (@Apache::lonstatistics::SelectedSections > 1 &&
- $Apache::lonstatistics::SelectedSections[0] ne 'all') {
- $num_workbooks = scalar(@Apache::lonstatistics::SelectedSections);
+sub StudentAverageTotal {
+ my $Str = ''.&mt('Summary Tables').'
'.$/;
+ $Str .= &Apache::loncommon::start_data_table();
+ $Str .= &Apache::loncommon::start_data_table_header_row().
+ ''.&mt('Title').' | '.
+ ''.&mt('Average').' | '.
+ ''.&mt('Maximum').' | '.
+ &Apache::loncommon::end_data_table_header_row().$/;
+ foreach my $seq (@sequences) {
+ my $symb = $seq->symb;
+ my $ave;
+ my $num_students = $Statistics->{$symb}->{'num_students'};
+ if ($num_students > 0) {
+ $ave = int(100*
+ ($Statistics->{$symb}->{'score'}/$num_students)
+ )/100;
} else {
- # @Apache::lonstatistics::Sections contains 'all' as well.
- $num_workbooks = scalar(@Apache::lonstatistics::Sections) - 1;
+ $ave = 0;
}
+ my $max = $Statistics->{$symb}->{'max'};
+ $ave = sprintf("%.2f",$ave);
+ $Str .= &Apache::loncommon::start_data_table_row().
+ ''.$seq->compTitle.' | '.
+ ''.$ave.' | '.
+ ''.$max.' '.' | '.
+ &Apache::loncommon::end_data_table_row()."\n";
}
-
- $r->print("Maximum allowed size: ".$max_size." bytes
");
- $r->print("Number of students: ".$num_students."
");
- $r->print("Number of fields per student: ".$fields_per_student."
");
- $r->print("Total number of fields: ".($fields_per_student*$num_students).
- "
");
- $r->print("Bytes per field: ".$bytes_per_field." (estimated)"."
");
- $r->print("Estimated size: ".$size_estimate." bytes
");
- $r->print("Number of workbooks: ".$num_workbooks."
");
- $r->rflush();
- return;
+ $Str .= &Apache::loncommon::end_data_table()."\n";
+ return $Str;
}
-sub multi_sheet_excel_outputstudent {
- my ($r,$student) = @_;
+sub SingleStudentTotal {
+ return if (! defined($navmap));
+ my $student = &Apache::lonstatistics::current_student();
+ my $Str = ''.&mt('Summary table for [_1] ([_2]@[_3])',
+ $student->{'fullname'},
+ $student->{'username'},$student->{'domain'}).'
';
+ $Str .= $/;
+ $Str .= &Apache::loncommon::start_data_table()."\n";
+ $Str .=
+ &Apache::loncommon::start_data_table_header_row().
+ ''.&mt('Sequence or Folder').' | ';
+ if ($chosen_output->{'base'} eq 'tries') {
+ $Str .= ''.&mt('Parts Correct').' | ';
+ } else {
+ $Str .= ''.&mt('Score').' | ';
+ }
+ $Str .= ''.&mt('Maximum').' | '.
+ &Apache::loncommon::end_data_table_header_row()."\n";
+ my $total = 0;
+ my $total_max = 0;
+ foreach my $seq (@sequences) {
+ my $value = $Statistics->{$seq->symb}->{'score'};
+ my $max = $Statistics->{$seq->symb}->{'max'};
+ $Str .= &Apache::loncommon::start_data_table_row().
+ ''.&HTML::Entities::encode($seq->compTitle).' | '.
+ ''.$value.' | '.
+ ''.$max.' | '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ $total += $value;
+ $total_max +=$max;
+ }
+ $Str .= &Apache::loncommon::start_data_table_row().
+ ''.&mt('Total').' | '.
+ ''.$total.' | '.
+ ''.$total_max.' | '.
+ &Apache::loncommon::end_data_table_row()."\n";
+ $Str .= &Apache::loncommon::end_data_table()."\n";
+ return $Str;
}
-sub multi_sheet_excel_finish {
- my ($r) = @_;
}
-}
#######################################################
#######################################################
@@ -653,19 +1055,78 @@ sub multi_sheet_excel_finish {
my $excel_sheet;
my $excel_workbook;
+my $format;
my $filename;
my $rows_output;
my $cols_output;
my %prog_state; # progress window state
+my $request_aborted;
+
+my $total_formula;
+my $maximum_formula;
+my %formula_data;
+
+my $navmap;
+my @sequences;
+
+sub excel_cleanup {
+ #
+ undef ($excel_sheet);
+ undef ($excel_workbook);
+ undef ($filename);
+ undef ($rows_output);
+ undef ($cols_output);
+ undef (%prog_state);
+ undef ($request_aborted);
+ undef ($total_formula);
+ undef ($maximum_formula);
+ #
+ undef(%formula_data);
+ #
+ undef($navmap);
+ undef(@sequences);
+}
sub excel_initialize {
my ($r) = @_;
+
+ &excel_cleanup();
+ ($navmap,@sequences) =
+ &Apache::lonstatistics::selected_sequences_with_assessments();
+ if (! ref($navmap)) {
+ # Unable to get data, so bail out
+ $r->print("".
+ &mt('Unable to retrieve course information.').
+ '
');
+ }
+ #
+ my $total_columns = scalar(&get_student_fields_to_show());
+ my $num_students = scalar(@Apache::lonstatistics::Students);
+ #
+ foreach my $seq (@sequences) {
+ if ($chosen_output->{'every_problem'}) {
+ $total_columns+=&count_parts($navmap,$seq);
+ }
+ # Add 2 because we need a 'sequence_sum' and 'total' column for each
+ $total_columns += 2;
+ }
+ my $too_many_cols_error_message =
+ ''.&mt('Unable to Complete Request').'
'.$/.
+ '
'.&mt('LON-CAPA is unable to produce your Excel spreadsheet because your selections will result in more than 255 columns. Excel allows only 255 columns in a spreadsheet.').'
'.$/.
+ ''
+ .&mt('Compiling Excel spreadsheet for [quant,_1,student]...',$studentcount)
+ ."
\n"
+ );
$r->rflush();
#
# Initialize progress window
%prog_state=&Apache::lonhtmlcommon::Create_PrgWin
($r,'Excel File Compilation Status',
- 'Excel File Compilation Progress', $studentcount);
+ 'Excel File Compilation Progress', $studentcount,
+ 'inline',undef,'Statistics','stats_status');
#
+ &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
+ 'Processing first student');
return;
}
sub excel_outputstudent {
my ($r,$student) = @_;
- return if (! defined($excel_sheet));
+ if ($request_aborted || ! defined($navmap) || ! defined($excel_sheet)) {
+ return;
+ }
$cols_output=0;
#
# Write out student data
my @to_show = &get_student_fields_to_show();
foreach my $field (@to_show) {
- $excel_sheet->write($rows_output,$cols_output++,$student->{$field});
+ my $value = $student->{$field};
+ if ($field eq 'comments') {
+ $value = &Apache::lonmsgdisplay::retrieve_instructor_comments
+ ($student->{'username'},$student->{'domain'});
+ }
+ $excel_sheet->write($rows_output,$cols_output++,$value);
}
#
# Get student assessment data
@@ -786,24 +1479,93 @@ sub excel_outputstudent {
my @tmp = &Apache::loncoursedata::get_current_state($student->{'username'},
$student->{'domain'},
undef,
- $ENV{'request.course.id'});
+ $env{'request.course.id'});
if ((scalar @tmp > 0) && ($tmp[0] !~ /^error:/)) {
%StudentsData = @tmp;
}
#
# Write out sequence scores and totals data
- foreach my $seq (&get_sequences_to_show) {
- my ($performance,$score,$seq_max) =
- &StudentPerformanceOnSequence($student,\%StudentsData,
- $seq,'no');
- if ($show eq 'totals' || $show eq 'scores') {
- $excel_sheet->write($rows_output,$cols_output++,$score);
+ my %total_cell_translation;
+ my %maximum_cell_translation;
+ foreach my $seq (@sequences) {
+ my $symb = $seq->symb;
+ $cols_output = $formula_data{$symb}->{'Excel:startcol'};
+ # Keep track of cells to translate in total cell
+ $total_cell_translation{$formula_data{$symb}->{'Excel:scorecell'}} =
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($rows_output,$formula_data{$symb}->{'Excel:scorecol'});
+ # and maximum cell
+ $maximum_cell_translation{$formula_data{$symb}->{'Excel:maxcell'}} =
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($rows_output,$formula_data{$symb}->{'Excel:maxcol'});
+ #
+ my ($performance,$performance_length,$score,$seq_max,$rawdata);
+ if ($chosen_output->{'tries'} || $chosen_output->{'correct'}){
+ ($performance,$performance_length,$score,$seq_max,$rawdata) =
+ &student_tries_on_sequence($student,\%StudentsData,
+ $navmap,$seq,'no');
+ } else {
+ ($performance,$performance_length,$score,$seq_max,$rawdata) =
+ &student_performance_on_sequence($student,\%StudentsData,
+ $navmap,$seq,'no',
+ $chosen_output->{ignore_weight});
+ }
+ if ($chosen_output->{'every_problem'}) {
+ if ($chosen_output->{'correct'}) {
+ # only indiciate if each item is correct or not
+ foreach my $value (@$rawdata) {
+ # positive means correct, 0 or negative means
+ # incorrect
+ $value = $value > 0 ? 1 : 0;
+ $excel_sheet->write($rows_output,$cols_output++,$value);
+ }
+ } else {
+ foreach my $value (@$rawdata) {
+ if ($score eq ' ' || !defined($value)) {
+ $cols_output++;
+ } else {
+ $excel_sheet->write($rows_output,$cols_output++,
+ $value);
+ }
+ }
+ }
+ }
+ if ($chosen_output->{'sequence_sum'} &&
+ $chosen_output->{'every_problem'}) {
+ # Write a formula for the sum of this sequence
+ my %replaceCells=
+ ('^'.$formula_data{$symb}->{'Excel:startcell'}.':'.$formula_data{$symb}->{'Excel:endcell'}.'$'
+ =>
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell($rows_output,$formula_data{$symb}->{'Excel:startcol'}).':'.
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell($rows_output,$formula_data{$symb}->{'Excel:endcol'})
+ );
+ # The undef is for the format
+ $excel_sheet->repeat_formula($rows_output,$cols_output++,
+ $formula_data{$symb}->{'Excel:sum'},undef,
+ %replaceCells, %replaceCells);
+ } elsif ($chosen_output->{'sequence_sum'}) {
+ if ($score eq ' ') {
+ $cols_output++;
+ } else {
+ $excel_sheet->write($rows_output,$cols_output++,$score);
+ }
}
- if ($show eq 'totals') {
+ if ($chosen_output->{'sequence_max'}) {
$excel_sheet->write($rows_output,$cols_output++,$seq_max);
}
}
#
+ if ($chosen_output->{'grand_total'}) {
+ $excel_sheet->repeat_formula($rows_output,$cols_output++,
+ $total_formula,undef,
+ %total_cell_translation);
+ }
+ if ($chosen_output->{'grand_maximum'}) {
+ $excel_sheet->repeat_formula($rows_output,$cols_output++,
+ $maximum_formula,undef,
+ %maximum_cell_translation);
+ }
+ #
# Bookkeeping
$rows_output++;
$cols_output=0;
@@ -815,21 +1577,22 @@ sub excel_outputstudent {
sub excel_finish {
my ($r) = @_;
- return if (! defined($excel_sheet));
+ if ($request_aborted || ! defined($navmap) || ! defined($excel_sheet)) {
+ &excel_cleanup();
+ return;
+ }
#
# Write the excel file
$excel_workbook->close();
- my $c = $r->connection();
- #
- return if($c->aborted());
#
# Close the progress window
&Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
#
# Tell the user where to get their excel file
$r->print('