Unable to Complete Request
@@ -915,7 +905,7 @@ summary data (Parts Correct or 255) {
+ if ($chosen_output->{'base'} eq 'scores' && $total_columns > 255) {
$r->print(<Unable to Complete Request
@@ -927,16 +917,7 @@ You may consider reducing the number of
have selected.
LON-CAPA can produce CSV files of this data or Excel files of the
-summary data (Scores Sum or Scores Sum & Totals).
-
-END
- $request_aborted = 1;
- }
- if ($data =~ /^final table/) {
- $r->print(<Unable to Complete Request
-
-The Summary Table (Scores) option is not available for non-HTML output.
+Scores Summary data.
END
$request_aborted = 1;
@@ -953,6 +934,24 @@ END
$rows_output = 0;
$cols_output = 0;
#
+ # Determine rows
+ my $header_row = $rows_output++;
+ my $description_row = $rows_output++;
+ $rows_output++; # blank row
+ my $summary_header_row;
+ if ($chosen_output->{'summary_table'}) {
+ $summary_header_row = $rows_output++;
+ $rows_output+= scalar(&Apache::lonstatistics::Sequences_with_Assess());
+ $rows_output++;
+ }
+ my $sequence_name_row = $rows_output++;
+ my $resource_name_row = $rows_output++;
+ my $maximum_data_row = $rows_output++;
+ if (! $chosen_output->{'maximum_row'}) {
+ $rows_output--;
+ }
+ my $first_data_row = $rows_output++;
+ #
# Create sheet
$excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
#
@@ -973,14 +972,25 @@ END
#
# Add a worksheet
my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
- if (length($sheetname) > 31) {
- $sheetname = substr($sheetname,0,31);
- }
+ $sheetname = &Apache::loncommon::clean_excel_name($sheetname);
$excel_sheet = $excel_workbook->addworksheet($sheetname);
#
+ # Define some potentially useful formats
+ my $format;
+ $format->{'header'} = $excel_workbook->add_format(bold => 1,
+ bottom => 1,
+ align => 'center');
+ $format->{'bold'} = $excel_workbook->add_format(bold=>1);
+ $format->{'h1'} = $excel_workbook->add_format(bold=>1, size=>18);
+ $format->{'h2'} = $excel_workbook->add_format(bold=>1, size=>16);
+ $format->{'h3'} = $excel_workbook->add_format(bold=>1, size=>14);
+ $format->{'date'} = $excel_workbook->add_format(num_format=>
+ 'mmm d yyyy hh:mm AM/PM');
+ #
# Put the course description in the header
- $excel_sheet->write($rows_output,$cols_output++,
- $ENV{'course.'.$ENV{'request.course.id'}.'.description'});
+ $excel_sheet->write($header_row,$cols_output++,
+ $ENV{'course.'.$ENV{'request.course.id'}.'.description'},
+ $format->{'h1'});
$cols_output += 3;
#
# Put a description of the sections listed
@@ -1000,115 +1010,253 @@ END
$sectionstring = "Section ".$Sections[0];
}
}
- $excel_sheet->write($rows_output,$cols_output++,$sectionstring);
+ $excel_sheet->write($header_row,$cols_output++,$sectionstring,
+ $format->{'h3'});
$cols_output += scalar(@Sections);
#
# Put the date in there too
- $excel_sheet->write($rows_output++,$cols_output++,
- 'Compiled on '.localtime(time));
+ $excel_sheet->write($header_row,$cols_output++,
+ 'Compiled on '.localtime(time),$format->{'h3'});
#
$cols_output = 0;
- $excel_sheet->write($rows_output++,$cols_output++,$datadescription);
- #
- if ($data eq 'tries' || $data eq 'scores') {
- $rows_output++;
- }
+ $excel_sheet->write($description_row,$cols_output++,
+ $chosen_output->{'shortdesc'},
+ $format->{'h3'});
+ ##############################################
+ # Output headings for the raw data
+ ##############################################
#
# Add the student headers
$cols_output = 0;
foreach my $field (&get_student_fields_to_show()) {
- $excel_sheet->write($rows_output,$cols_output++,$field);
- }
- my $row_offset = 0;
- if ($data eq 'tries' || $data eq 'scores') {
- $row_offset = -1;
+ $excel_sheet->write($resource_name_row,$cols_output++,$field,
+ $format->{'bold'});
}
#
# Add the remaining column headers
+ my $total_formula_string = '=0';
foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
- $excel_sheet->write($rows_output+$row_offset,
- $cols_output,$seq->{'title'});
- if ($data eq 'tries' || $data eq 'scores') {
+ $excel_sheet->write($sequence_name_row,,
+ $cols_output,$seq->{'title'},$format->{'bold'});
+ # Determine starting cell
+ $seq->{'Excel:startcell'}=
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($first_data_row,$cols_output);
+ $seq->{'Excel:startcol'}=$cols_output;
+ my $count = 0;
+ if ($chosen_output->{'every_problem'}) {
+ # Put the names of the problems and parts into the sheet
foreach my $res (@{$seq->{'contents'}}) {
- next if ($res->{'type'} ne 'assessment');
+ if ($res->{'type'} ne 'assessment' ||
+ ! exists($res->{'parts'}) ||
+ ref($res->{'parts'}) ne 'ARRAY' ||
+ scalar(@{$res->{'parts'}}) < 1) {
+ next;
+ }
if (scalar(@{$res->{'parts'}}) > 1) {
foreach my $part (@{$res->{'parts'}}) {
- $excel_sheet->write($rows_output,
+ $excel_sheet->write($resource_name_row,
$cols_output++,
- $res->{'title'}.' part '.$part);
+ $res->{'title'}.' part '.$part,
+ $format->{'bold'});
}
} else {
- $excel_sheet->write($rows_output,
+ $excel_sheet->write($resource_name_row,
$cols_output++,
- $res->{'title'});
+ $res->{'title'},$format->{'bold'});
}
+ $count++;
}
- $excel_sheet->write($rows_output,$cols_output++,'score');
- $excel_sheet->write($rows_output,$cols_output++,'maximum');
- } elsif ($data eq 'sum and total' || $data eq 'parts correct total') {
- $excel_sheet->write($rows_output+1,$cols_output,'score');
- $excel_sheet->write($rows_output+1,$cols_output+1,'maximum');
- $cols_output += 2;
- } else {
- $cols_output++;
}
- }
- #
- # Bookkeeping
- if ($data eq 'sum and total' || $data eq 'parts correct total') {
- $rows_output += 2;
- } else {
- $rows_output += 1;
- }
- #
- # Output a row for MAX
- $cols_output = 0;
- foreach my $field (&get_student_fields_to_show()) {
- if ($field eq 'username' || $field eq 'fullname' ||
- $field eq 'id') {
- $excel_sheet->write($rows_output,$cols_output++,'Maximum');
+ # Determine ending cell
+ if ($count <= 1) {
+ $seq->{'Excel:endcell'} = $seq->{'Excel:startcell'};
+ $seq->{'Excel:endcol'} = $seq->{'Excel:startcol'};
} else {
- $excel_sheet->write($rows_output,$cols_output++,'');
+ $seq->{'Excel:endcell'} =
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($first_data_row,$cols_output-1);
+ $seq->{'Excel:endcol'} = $cols_output-1;
+ }
+ # Create the formula for summing up this sequence
+ if (! exists($seq->{'Excel:endcell'}) ||
+ ! defined($seq->{'Excel:endcell'})) {
+ $seq->{'Excel:endcell'} = $seq->{'Excel:startcell'};
+ }
+ $seq->{'Excel:sum'}= $excel_sheet->store_formula
+ ('=SUM('.$seq->{'Excel:startcell'}.
+ ':'.$seq->{'Excel:endcell'}.')');
+ # Determine cell the score is held in
+ $seq->{'Excel:scorecell'} =
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($first_data_row,$cols_output);
+ $seq->{'Excel:scorecol'}=$cols_output;
+ if ($chosen_output->{'base'} eq 'parts correct total') {
+ $excel_sheet->write($resource_name_row,$cols_output++,
+ 'parts correct',
+ $format->{'bold'});
+ } elsif ($chosen_output->{'sequence_sum'}) {
+ if ($chosen_output->{'correct'}) {
+ # Only reporting the number correct, so do not call it score
+ $excel_sheet->write($resource_name_row,$cols_output++,
+ 'sum',
+ $format->{'bold'});
+ } else {
+ $excel_sheet->write($resource_name_row,$cols_output++,
+ 'score',
+ $format->{'bold'});
+ }
}
- }
- #
- # Add the maximums for each sequence or assessment
- foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
- my $weight;
- my $max = 0;
- foreach my $resource (@{$seq->{'contents'}}) {
- next if ($resource->{'type'} ne 'assessment');
- foreach my $part (@{$resource->{'parts'}}) {
- $weight = 1;
- if ($base eq 'scores') {
- $weight = &Apache::lonnet::EXT
- ('resource.'.$part.'.weight',$resource->{'symb'},
- undef,undef,undef);
- if (!defined($weight) || ($weight eq '')) {
- $weight=1;
+ #
+ $total_formula_string.='+'.
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($first_data_row,$cols_output-1);
+ if ($chosen_output->{'sequence_max'}) {
+ $excel_sheet->write($resource_name_row,$cols_output++,
+ 'maximum',
+ $format->{'bold'});
+ }
+ }
+ if ($chosen_output->{'grand_total'}) {
+ $excel_sheet->write($resource_name_row,$cols_output++,'Total',
+ $format->{'bold'});
+ }
+ $total_formula = $excel_sheet->store_formula($total_formula_string);
+ ##############################################
+ # Output a row for MAX, if appropriate
+ ##############################################
+ if ($chosen_output->{'maximum_row'}) {
+ $cols_output = 0;
+ foreach my $field (&get_student_fields_to_show()) {
+ if ($field eq 'username' || $field eq 'fullname' ||
+ $field eq 'id') {
+ $excel_sheet->write($maximum_data_row,$cols_output++,'Maximum',
+ $format->{'bold'});
+ } else {
+ $excel_sheet->write($maximum_data_row,$cols_output++,'');
+ }
+ }
+ #
+ # Add the maximums for each sequence or assessment
+ my %total_cell_translation;
+ foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
+ $cols_output=$seq->{'Excel:startcol'};
+ $total_cell_translation{$seq->{'Excel:scorecell'}} =
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($maximum_data_row,$seq->{'Excel:scorecol'});
+ my $weight;
+ my $max = 0;
+ foreach my $resource (@{$seq->{'contents'}}) {
+ next if ($resource->{'type'} ne 'assessment');
+ foreach my $part (@{$resource->{'parts'}}) {
+ $weight = 1;
+ if ($chosen_output->{'scores'}) {
+ $weight = &Apache::lonnet::EXT
+ ('resource.'.$part.'.weight',$resource->{'symb'},
+ undef,undef,undef);
+ if (!defined($weight) || ($weight eq '')) {
+ $weight=1;
+ }
}
+ if ($chosen_output->{'scores'} &&
+ $chosen_output->{'every_problem'}) {
+ $excel_sheet->write($maximum_data_row,$cols_output++,
+ $weight);
+ }
+ $max += $weight;
}
- if ($data eq 'scores') {
- $excel_sheet->write($rows_output,$cols_output++,$weight);
- } elsif ($data eq 'tries') {
- $excel_sheet->write($rows_output,$cols_output++,'');
- }
- $max += $weight;
+ }
+ #
+ if ($chosen_output->{'sequence_sum'} &&
+ $chosen_output->{'every_problem'}) {
+ my %replaceCells;
+ $replaceCells{$seq->{'Excel:startcell'}} =
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($maximum_data_row,$seq->{'Excel:startcol'});
+ $replaceCells{$seq->{'Excel:endcell'}} =
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($maximum_data_row,$seq->{'Excel:endcol'});
+ $excel_sheet->repeat_formula($maximum_data_row,$cols_output++,
+ $seq->{'Excel:sum'},undef,
+ %replaceCells);
+ } elsif ($chosen_output->{'sequence_sum'}) {
+ $excel_sheet->write($maximum_data_row,$cols_output++,$max);
}
- }
- if (! ($data eq 'sum only' || $data eq 'parts correct')) {
- $excel_sheet->write($rows_output,$cols_output++,'');
+ if ($chosen_output->{'sequence_max'}) {
+ $excel_sheet->write($maximum_data_row,$cols_output++,$max);
+ }
+ #
}
- $excel_sheet->write($rows_output,$cols_output++,$max);
- }
- $rows_output++;
+ if ($chosen_output->{'grand_total'}) {
+ $excel_sheet->repeat_formula($maximum_data_row,$cols_output++,
+ $total_formula,undef,
+ %total_cell_translation);
+ }
+ } # End of MAXIMUM row output if ($chosen_output->{'maximum_row'}) {
+ $rows_output = $first_data_row;
+ ##############################################
+ # Output summary table, which actually is above the sequence name row.
+ ##############################################
+ if ($chosen_output->{'summary_table'}) {
+ $cols_output = 0;
+ $excel_sheet->write($summary_header_row,$cols_output++,
+ 'Summary Table',$format->{'bold'});
+ if ($chosen_output->{'maximum_row'}) {
+ $excel_sheet->write($summary_header_row,$cols_output++,
+ 'Maximum',$format->{'bold'});
+ }
+ $excel_sheet->write($summary_header_row,$cols_output++,
+ 'Average',$format->{'bold'});
+ $excel_sheet->write($summary_header_row,$cols_output++,
+ 'Median',$format->{'bold'});
+ $excel_sheet->write($summary_header_row,$cols_output++,
+ 'Std Dev',$format->{'bold'});
+ my $row = $summary_header_row+1;
+ foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
+ $cols_output = 0;
+ $excel_sheet->write($row,$cols_output++,
+ $seq->{'title'},
+ $format->{'bold'});
+ if ($chosen_output->{'maximum_row'}) {
+ $excel_sheet->write
+ ($row,$cols_output++,
+ '='.
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($maximum_data_row,$seq->{'Excel:scorecol'})
+ );
+ }
+ my $range =
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($first_data_row,$seq->{'Excel:scorecol'}).
+ ':'.
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($first_data_row+$num_students-1,$seq->{'Excel:scorecol'});
+ $excel_sheet->write($row,$cols_output++,
+ '=AVERAGE('.$range.')');
+ $excel_sheet->write($row,$cols_output++,
+ '=MEDIAN('.$range.')');
+ $excel_sheet->write($row,$cols_output++,
+ '=STDEV('.$range.')');
+ $row++;
+ }
+ }
+ ##############################################
+ # Take care of non-excel initialization
+ ##############################################
#
# Let the user know what we are doing
my $studentcount = scalar(@Apache::lonstatistics::Students);
- $r->print("Compiling Excel spreadsheet for ".
- $studentcount.' student');
- $r->print('s') if ($studentcount > 1);
- $r->print("
\n");
+ if ($ENV{'form.SelectedStudent'}) {
+ $studentcount = '1';
+ }
+ if ($studentcount > 1) {
+ $r->print(''.&mt('Compiling Excel spreadsheet for [_1] students',
+ $studentcount)."
\n");
+ } else {
+ $r->print(''.
+ &mt('Compiling Excel spreadsheet for 1 student').
+ "
\n");
+ }
$r->rflush();
#
# Initialize progress window
@@ -1116,6 +1264,8 @@ END
($r,'Excel File Compilation Status',
'Excel File Compilation Progress', $studentcount);
#
+ &Apache::lonhtmlcommon::Update_PrgWin($r,\%prog_state,
+ 'Processing first student');
return;
}
@@ -1142,9 +1292,16 @@ sub excel_outputstudent {
}
#
# Write out sequence scores and totals data
+ my %total_cell_translation;
foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
+ $cols_output = $seq->{'Excel:startcol'};
+ # Keep track of cells to translate in total cell
+ $total_cell_translation{$seq->{'Excel:scorecell'}} =
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($rows_output,$seq->{'Excel:scorecol'});
+ #
my ($performance,$performance_length,$score,$seq_max,$rawdata);
- if ($base eq 'tries') {
+ if ($chosen_output->{'tries'} || $chosen_output->{'correct'}){
($performance,$performance_length,$score,$seq_max,$rawdata) =
&StudentTriesOnSequence($student,\%StudentsData,
$seq,'no');
@@ -1152,22 +1309,55 @@ sub excel_outputstudent {
($performance,$performance_length,$score,$seq_max,$rawdata) =
&StudentPerformanceOnSequence($student,\%StudentsData,
$seq,'no');
+ }
+ if ($chosen_output->{'every_problem'}) {
+ if ($chosen_output->{'correct'}) {
+ # only indiciate if each item is correct or not
+ foreach my $value (@$rawdata) {
+ # nonzero means correct
+ $value = 1 if ($value > 0);
+ $excel_sheet->write($rows_output,$cols_output++,$value);
+ }
+ } else {
+ foreach my $value (@$rawdata) {
+ $excel_sheet->write($rows_output,$cols_output++,$value);
+ }
+ }
}
- if ($data eq 'tries' || $data eq 'scores') {
- foreach my $value (@$rawdata) {
- $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;
+ $replaceCells{$seq->{'Excel:startcell'}} =
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($rows_output,$seq->{'Excel:startcol'});
+ $replaceCells{$seq->{'Excel:endcell'}} =
+ &Spreadsheet::WriteExcel::Utility::xl_rowcol_to_cell
+ ($rows_output,$seq->{'Excel:endcol'});
+ # The undef is for the format
+ if (scalar(keys(%replaceCells)) == 1) {
+ $excel_sheet->repeat_formula($rows_output,$cols_output++,
+ $seq->{'Excel:sum'},undef,
+ %replaceCells,%replaceCells);
+ } else {
+ $excel_sheet->repeat_formula($rows_output,$cols_output++,
+ $seq->{'Excel:sum'},undef,
+ %replaceCells);
}
- $excel_sheet->write($rows_output,$cols_output++,$score);
- $excel_sheet->write($rows_output,$cols_output++,$seq_max);
- } elsif ($data eq 'sum and total' || $data eq 'sum only' ||
- $data eq 'parts correct' || $data eq 'parts correct total') {
+ } elsif ($chosen_output->{'sequence_sum'}) {
$excel_sheet->write($rows_output,$cols_output++,$score);
}
- if ($data eq 'sum and total' || $data eq 'parts correct total') {
+ 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);
+ }
+ #
# Bookkeeping
$rows_output++;
$cols_output=0;
@@ -1227,13 +1417,14 @@ sub csv_initialize{
my ($r) = @_;
#
# Clean up
- $filename = undef;
- $outputfile = undef;
+ undef($outputfile);
+ undef($filename);
+ undef($request_aborted);
undef(%prog_state);
#
# Deal with unimplemented requests
$request_aborted = undef;
- if ($data =~ /final table/) {
+ if ($chosen_output->{'base'} =~ /final table/) {
$r->print(<Unable to Complete Request
@@ -1243,7 +1434,12 @@ END
$request_aborted = 1;
}
return if ($request_aborted);
-
+ #
+ # Initialize progress window
+ my $studentcount = scalar(@Apache::lonstatistics::Students);
+ %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
+ ($r,'CSV File Compilation Status',
+ 'CSV File Compilation Progress', $studentcount);
#
# Open a file
$filename = '/prtspool/'.
@@ -1264,55 +1460,54 @@ END
"\n";
#
# Print out the headings
- my $Str = '';
- my $Str2 = undef;
+ my $sequence_row = '';
+ my $resource_row = undef;
foreach my $field (&get_student_fields_to_show()) {
- if ($data eq 'sum only') {
- $Str .= '"'.&Apache::loncommon::csv_translate($field).'",';
- } elsif ($data eq 'sum and total' || $data eq 'parts correct total') {
- $Str .= '"",'; # first row empty on the student fields
- $Str2 .= '"'.&Apache::loncommon::csv_translate($field).'",';
- } elsif ($data eq 'scores' || $data eq 'tries' ||
- $data eq 'parts correct') {
- $Str .= '"",';
- $Str2 .= '"'.&Apache::loncommon::csv_translate($field).'",';
- }
+ $sequence_row .='"",';
+ $resource_row .= '"'.&Apache::loncommon::csv_translate($field).'",';
}
foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
- if ($data eq 'sum only' || $data eq 'parts correct') {
- $Str .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}).
- '",';
- } elsif ($data eq 'sum and total' || $data eq 'parts correct total') {
- $Str .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}).
- '","",';
- $Str2 .= '"score","total possible",';
- } elsif ($data eq 'scores' || $data eq 'tries') {
- $Str .= '"'.&Apache::loncommon::csv_translate($seq->{'title'}).
- '",';
- $Str .= '"",'x($seq->{'num_assess_parts'}-1+2);
+ $sequence_row .= '"'.
+ &Apache::loncommon::csv_translate($seq->{'title'}).'",';
+ my $count = 0;
+ if ($chosen_output->{'every_problem'}) {
foreach my $res (@{$seq->{'contents'}}) {
- next if ($res->{'type'} ne 'assessment');
+ if ($res->{'type'} ne 'assessment' ||
+ ! exists($res->{'parts'}) ||
+ ref($res->{'parts'}) ne 'ARRAY' ||
+ scalar(@{$res->{'parts'}}) < 1) {
+ next;
+ }
foreach my $part (@{$res->{'parts'}}) {
- $Str2 .= '"'.&Apache::loncommon::csv_translate($res->{'title'}.', Part '.$part).'",';
+ $resource_row .= '"'.
+ &Apache::loncommon::csv_translate($res->{'title'}.
+ ', Part '.$part
+ ).'",';
+ $count++;
}
}
- $Str2 .= '"score","total possible",';
+ }
+ $sequence_row.='"",'x$count;
+ if ($chosen_output->{'sequence_sum'}) {
+ if($chosen_output->{'correct'}) {
+ $resource_row .= '"sum",';
+ } else {
+ $resource_row .= '"score",';
+ }
+ }
+ if ($chosen_output->{'sequence_max'}) {
+ $sequence_row.= '"",';
+ $resource_row .= '"maximum possible",';
}
}
- chop($Str);
- $Str .= "\n";
- print $outputfile $Str;
- if (defined($Str2)) {
- chop($Str2);
- $Str2 .= "\n";
- print $outputfile $Str2;
- }
- #
- # Initialize progress window
- my $studentcount = scalar(@Apache::lonstatistics::Students);
- %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
- ($r,'CSV File Compilation Status',
- 'CSV File Compilation Progress', $studentcount);
+ if ($chosen_output->{'grand_total'}) {
+ $sequence_row.= '"",';
+ $resource_row.= '"Total",';
+ }
+ chomp($sequence_row);
+ chomp($resource_row);
+ print $outputfile $sequence_row."\n";
+ print $outputfile $resource_row."\n";
return;
}
@@ -1339,9 +1534,10 @@ sub csv_outputstudent {
}
#
# Output performance data
+ my $total = 0;
foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
my ($performance,$performance_length,$score,$seq_max,$rawdata);
- if ($base eq 'tries') {
+ if ($chosen_output->{'tries'}){
($performance,$performance_length,$score,$seq_max,$rawdata) =
&StudentTriesOnSequence($student,\%StudentsData,
$seq,'no');
@@ -1350,13 +1546,31 @@ sub csv_outputstudent {
&StudentPerformanceOnSequence($student,\%StudentsData,
$seq,'no');
}
- if ($data eq 'sum only' || $data eq 'parts correct') {
+ if ($chosen_output->{'every_problem'}) {
+ if ($chosen_output->{'correct'}) {
+ $score = 0;
+ # Deal with number of parts correct data
+ $Str .= '"'.join('","',( map { if ($_>0) {
+ $score += 1;
+ 1;
+ } else {
+ 0;
+ }
+ } @$rawdata)).'",';
+ } else {
+ $Str .= '"'.join('","',(@$rawdata)).'",';
+ }
+ }
+ if ($chosen_output->{'sequence_sum'}) {
$Str .= '"'.$score.'",';
- } elsif ($data eq 'sum and total' || $data eq 'parts correct total') {
- $Str .= '"'.$score.'","'.$seq_max.'",';
- } elsif ($data eq 'scores' || $data eq 'tries') {
- $Str .= '"'.join('","',(@$rawdata,$score,$seq_max)).'",';
+ }
+ if ($chosen_output->{'sequence_max'}) {
+ $Str .= '"'.$seq_max.'",';
}
+ $total+=$score;
+ }
+ if ($chosen_output->{'grand_total'}) {
+ $Str .= '"'.$total.'",';
}
chop($Str);
$Str .= "\n";
@@ -1432,43 +1646,56 @@ sub StudentTriesOnSequence {
$performance_length++;
my $symbol = ' '; # default to space
#
+ my $awarded = 0;
+ if (exists($resource_data->{'resource.'.$partnum.'.awarded'})) {
+ $awarded = $resource_data->{'resource.'.$partnum.'.awarded'};
+ $awarded = 0 if (! $awarded);
+ }
+ #
+ my $status = '';
if (exists($resource_data->{'resource.'.$partnum.'.solved'})) {
- my $status = $resource_data->{'resource.'.$partnum.'.solved'};
- if ($status eq 'correct_by_override') {
- $symbol = '+';
- $sum++;
- } elsif ($status eq 'incorrect_by_override') {
- $symbol = '-';
- } elsif ($status eq 'ungraded_attempted') {
- $symbol = '#';
- } elsif ($status eq 'incorrect_attempted') {
- $symbol = '.';
- } elsif ($status eq 'excused') {
+ $status = $resource_data->{'resource.'.$partnum.'.solved'};
+ }
+ #
+ my $tries = 0;
+ if(exists($resource_data->{'resource.'.$partnum.'.tries'})) {
+ $tries = $resource_data->{'resource.'.$partnum.'.tries'};
+ }
+ #
+ if ($awarded > 0) {
+ # The student has gotten the problem correct to some degree
+ if ($status eq 'excused') {
$symbol = 'x';
$max--;
- } elsif ($status eq 'correct_by_student' &&
- exists($resource_data->{'resource.'.$partnum.'.tries'})){
- $tries = $resource_data->{'resource.'.$partnum.'.tries'};
+ } elsif ($status eq 'correct_by_override') {
+ $symbol = '+';
+ $sum++;
+ } elsif ($tries > 0) {
if ($tries > 9) {
$symbol = '*';
- } elsif ($tries > 0) {
- $symbol = $tries;
} else {
- $symbol = ' ';
+ $symbol = $tries;
}
$sum++;
- } elsif (exists($resource_data->{'resource.'.
- $partnum.'.tries'})){
- $symbol = '.';
} else {
- $symbol = ' ';
+ $symbol = '+';
+ $sum++;
}
} else {
- # Unsolved. Did they try?
- if (exists($resource_data->{'resource.'.$partnum.'.tries'})){
+ # The student has the problem incorrect or it is ungraded
+ if ($status eq 'excused') {
+ $symbol = 'x';
+ $max--;
+ } elsif ($status eq 'incorrect_by_override') {
+ $symbol = '-';
+ } elsif ($status eq 'ungraded_attempted') {
+ $symbol = '#';
+ } elsif ($status eq 'incorrect_attempted' ||
+ $tries > 0) {
$symbol = '.';
} else {
- $symbol = ' ';
+ # Problem is wrong and has not been attempted.
+ $symbol=' ';
}
}
#
@@ -1485,7 +1712,7 @@ sub StudentTriesOnSequence {
$symbol = ''.$symbol.'';
}
$value .= $symbol;
@@ -1553,11 +1780,15 @@ sub StudentPerformanceOnSequence {
my $awarded = 0;
if (exists($resource_data->{'resource.'.$part.'.awarded'})) {
$awarded = $resource_data->{'resource.'.$part.'.awarded'};
+ $awarded = 0 if (! $awarded);
}
#
$partscore = $weight*$awarded;
$score += $partscore;
- $symbol = $weight;
+ $symbol = $partscore;
+ if (abs($symbol - sprintf("%.0f",$symbol)) < 0.001) {
+ $symbol = sprintf("%.0f",$symbol);
+ }
if (length($symbol) > 1) {
$symbol = '*';
}
@@ -1576,19 +1807,20 @@ sub StudentPerformanceOnSequence {
}
}
#
+ if (! defined($partscore)) {
+ $partscore = $symbol;
+ }
+ push (@ScoreData,$partscore);
+ #
if ( ($links eq 'yes' && $symbol ne ' ') || ($links eq 'all')) {
$symbol = ''.$symbol.'';
}
- if (! defined($partscore)) {
- $partscore = $symbol;
- }
- push (@ScoreData,$partscore);
+ $Str .= $symbol;
}
- $Str .= $symbol;
}
return ($Str,$performance_length,$score,$max,\@ScoreData);
}