'.&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.').'
'.$/.
+ 'Unable to Complete Request
@@ -1205,7 +1566,13 @@ 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,
+ 'inline',undef,'Statistics','stats_status');
#
# Open a file
$filename = '/prtspool/'.
@@ -1224,70 +1591,81 @@ END
print $outputfile '"'.&Apache::loncommon::csv_translate($description).'",'.
'"'.&Apache::loncommon::csv_translate(scalar(localtime(time))).'"'.
"\n";
+ foreach my $item ('shortdesc','non_html_notes') {
+ next if (! exists($chosen_output->{$item}));
+ print $outputfile
+ '"'.&Apache::loncommon::csv_translate($chosen_output->{$item}).'"'.
+ "\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).'",';
- }
- }
- 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);
- foreach my $res (@{$seq->{'contents'}}) {
- next if ($res->{'type'} ne 'assessment');
- foreach my $part (@{$res->{'parts'}}) {
- $Str2 .= '"'.&Apache::loncommon::csv_translate($res->{'title'}.', Part '.$part).'",';
+ $sequence_row .='"",';
+ $resource_row .= '"'.&Apache::loncommon::csv_translate($field).'",';
+ }
+ foreach my $seq (@sequences) {
+ $sequence_row .= '"'.
+ &Apache::loncommon::csv_translate($seq->compTitle).'",';
+ my $count = 0;
+ if ($chosen_output->{'every_problem'}) {
+ foreach my $res (&get_resources($navmap,$seq)) {
+ if (scalar(@{$res->parts}) < 1) {
+ next;
+ }
+ foreach my $part (@{$res->parts}) {
+ $resource_row .= '"'.
+ &Apache::loncommon::csv_translate
+ ($res->compTitle.', Part '.$res->part_display($part)).'",';
+ $count++;
}
}
- $Str2 .= '"score","total 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);
+ $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",';
+ }
+ }
+ if ($chosen_output->{'grand_total'}) {
+ $sequence_row.= '"",';
+ $resource_row.= '"Total",';
+ }
+ if ($chosen_output->{'grand_maximum'}) {
+ $sequence_row.= '"",';
+ $resource_row.= '"Maximum",';
+ }
+ chomp($sequence_row);
+ chomp($resource_row);
+ print $outputfile $sequence_row."\n";
+ print $outputfile $resource_row."\n";
return;
}
sub csv_outputstudent {
my ($r,$student) = @_;
- return if ($request_aborted);
- return if (! defined($outputfile));
+ if ($request_aborted || ! defined($navmap) || ! defined($outputfile)) {
+ return;
+ }
my $Str = '';
#
# Output student fields
my @to_show = &get_student_fields_to_show();
foreach my $field (@to_show) {
- $Str .= '"'.&Apache::loncommon::csv_translate($student->{$field}).'",';
+ my $value = $student->{$field};
+ if ($field eq 'comments') {
+ $value = &Apache::lonmsg::retrieve_instructor_comments
+ ($student->{'username'},$student->{'domain'});
+ }
+ $Str .= '"'.&Apache::loncommon::csv_translate($value).'",';
}
#
# Get student assessment data
@@ -1301,24 +1679,48 @@ sub csv_outputstudent {
}
#
# Output performance data
- foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()) {
+ my $total = 0;
+ my $maximum = 0;
+ foreach my $seq (@sequences) {
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');
+ &student_tries_on_sequence($student,\%StudentsData,
+ $navmap,$seq,'no');
} else {
($performance,$performance_length,$score,$seq_max,$rawdata) =
- &StudentPerformanceOnSequence($student,\%StudentsData,
- $seq,'no');
+ &student_performance_on_sequence($student,\%StudentsData,
+ $navmap,$seq,'no');
+ }
+ 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 ($data eq 'sum only' || $data eq 'parts correct') {
+ 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;
+ $maximum += $seq_max;
+ }
+ if ($chosen_output->{'grand_total'}) {
+ $Str .= '"'.$total.'",';
+ }
+ if ($chosen_output->{'grand_maximum'}) {
+ $Str .= '"'.$maximum.'",';
}
chop($Str);
$Str .= "\n";
@@ -1331,8 +1733,9 @@ sub csv_outputstudent {
sub csv_finish {
my ($r) = @_;
- return if ($request_aborted);
- return if (! defined($outputfile));
+ if ($request_aborted || ! defined($navmap) || ! defined($outputfile)) {
+ return;
+ }
close($outputfile);
#
my $c = $r->connection();
@@ -1343,7 +1746,7 @@ sub csv_finish {
#
# Tell the user where to get their csv file
$r->print('
'.
- 'Your csv file.'."\n");
+ ''.&mt('Your csv file.').''."\n");
$r->rflush();
return;
@@ -1376,69 +1779,88 @@ Inputs:
#######################################################
#######################################################
-sub StudentTriesOnSequence {
- my ($student,$studentdata,$seq,$links) = @_;
+sub student_tries_on_sequence {
+ my ($student,$studentdata,$navmap,$seq,$links) = @_;
$links = 'no' if (! defined($links));
my $Str = '';
my ($sum,$max) = (0,0);
my $performance_length = 0;
my @TriesData = ();
my $tries;
- foreach my $resource (@{$seq->{'contents'}}) {
- next if ($resource->{'type'} ne 'assessment');
- my $resource_data = $studentdata->{$resource->{'symb'}};
+ my $hasdata = 0; # flag - true if the student has any data on the sequence
+ foreach my $resource (&get_resources($navmap,$seq)) {
+ my $resource_data = $studentdata->{$resource->symb};
my $value = '';
- foreach my $partnum (@{$resource->{'parts'}}) {
+ foreach my $partnum (@{$resource->parts()}) {
$tries = undef;
$max++;
$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'};
+ $hasdata =1;
+ }
+ #
+ 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_scantron' ||
- $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=' ';
}
}
#
if (! defined($tries)) {
- $tries = $symbol;
+ $tries = 0;
+ }
+ if ($status =~ /^(incorrect|ungraded)/) {
+ # Bug 3390: show '-' for tries on incorrect problems
+ # (csv & excel only)
+ push(@TriesData,-$tries);
+ } else {
+ push (@TriesData,$tries);
}
- push (@TriesData,$tries);
#
if ( ($links eq 'yes' && $symbol ne ' ') ||
($links eq 'all')) {
@@ -1446,7 +1868,7 @@ sub StudentTriesOnSequence {
&Apache::lonnet::logthis('length of symbol "'.$symbol.'" > 1');
}
$symbol = ''.$symbol.'';
@@ -1455,8 +1877,11 @@ sub StudentTriesOnSequence {
}
$Str .= $value;
}
- if ($seq->{'randompick'}) {
- $max = $seq->{'randompick'};
+ if ($seq->randompick()) {
+ $max = $seq->randompick();
+ }
+ if (! $hasdata && $sum == 0) {
+ $sum = ' ';
}
return ($Str,$performance_length,$sum,$max,\@TriesData);
}
@@ -1466,7 +1891,7 @@ sub StudentTriesOnSequence {
=pod
-=item &StudentPerformanceOnSequence()
+=item &student_performance_on_sequence
Inputs:
@@ -1486,8 +1911,8 @@ Inputs:
#######################################################
#######################################################
-sub StudentPerformanceOnSequence {
- my ($student,$studentdata,$seq,$links) = @_;
+sub student_performance_on_sequence {
+ my ($student,$studentdata,$navmap,$seq,$links) = @_;
$links = 'no' if (! defined($links));
my $Str = ''; # final result string
my ($score,$max) = (0,0);
@@ -1495,13 +1920,14 @@ sub StudentPerformanceOnSequence {
my $symbol;
my @ScoreData = ();
my $partscore;
- foreach my $resource (@{$seq->{'contents'}}) {
- next if ($resource->{'type'} ne 'assessment');
- my $resource_data = $studentdata->{$resource->{'symb'}};
- foreach my $part (@{$resource->{'parts'}}) {
+ my $hasdata = 0; # flag, 0 if there were no submissions on the sequence
+ foreach my $resource (&get_resources($navmap,$seq)) {
+ my $symb = $resource->symb;
+ my $resource_data = $studentdata->{$symb};
+ foreach my $part (@{$resource->parts()}) {
$partscore = undef;
my $weight = &Apache::lonnet::EXT('resource.'.$part.'.weight',
- $resource->{'symb'},
+ $symb,
$student->{'domain'},
$student->{'username'},
$student->{'section'});
@@ -1513,13 +1939,17 @@ sub StudentPerformanceOnSequence {
$performance_length++; # one character per part
$symbol = ' '; # default to space
#
- my $awarded = 0;
+ my $awarded;
if (exists($resource_data->{'resource.'.$part.'.awarded'})) {
$awarded = $resource_data->{'resource.'.$part.'.awarded'};
$awarded = 0 if (! $awarded);
+ $hasdata = 1;
}
#
$partscore = $weight*$awarded;
+ if (! defined($awarded)) {
+ $partscore = undef;
+ }
$score += $partscore;
$symbol = $partscore;
if (abs($symbol - sprintf("%.0f",$symbol)) < 0.001) {
@@ -1534,10 +1964,12 @@ sub StudentPerformanceOnSequence {
$symbol = 'x';
$max -= $weight; # Do not count 'excused' problems.
}
- } else {
+ $hasdata = 1;
+ } elsif (!exists($resource_data->{'resource.'.$part.'.awarded'})){
# Unsolved. Did they try?
if (exists($resource_data->{'resource.'.$part.'.tries'})){
$symbol = '.';
+ $hasdata = 1;
} else {
$symbol = ' ';
}
@@ -1550,7 +1982,7 @@ sub StudentPerformanceOnSequence {
#
if ( ($links eq 'yes' && $symbol ne ' ') || ($links eq 'all')) {
$symbol = ''.$symbol.'';
@@ -1558,6 +1990,9 @@ sub StudentPerformanceOnSequence {
$Str .= $symbol;
}
}
+ if (! $hasdata && $score == 0) {
+ $score = ' ';
+ }
return ($Str,$performance_length,$score,$max,\@ScoreData);
}