--- loncom/interface/statistics/lonproblemanalysis.pm 2004/10/29 16:39:42 1.101 +++ loncom/interface/statistics/lonproblemanalysis.pm 2020/11/10 19:28:32 1.147 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonproblemanalysis.pm,v 1.101 2004/10/29 16:39:42 matthew Exp $ +# $Id: lonproblemanalysis.pm,v 1.147 2020/11/10 19:28:32 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,17 +27,21 @@ package Apache::lonproblemanalysis; use strict; -use Apache::lonnet(); +use Apache::lonnet; use Apache::loncommon(); use Apache::lonhtmlcommon(); use Apache::loncoursedata(); +use Apache::lonquickgrades(); use Apache::lonstatistics; use Apache::lonlocal; use Apache::lonstathelpers(); use Apache::lonstudentsubmissions(); use HTML::Entities(); use Time::Local(); -use Spreadsheet::WriteExcel(); +use capa; +use lib '/home/httpd/lib/perl/'; +use LONCAPA; + my $plotcolors = ['#33ff00', '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933', @@ -52,15 +56,14 @@ my @SubmitButtons = ({ name => 'PrevProb text => 'Next Problem' }, { name => 'break'}, { name => 'SelectAnother', - text => 'Choose a different Problem' }, - { name => 'ExcelOutput', - text => 'Produce Excel Output' }); + text => 'Choose a different Problem' }); sub BuildProblemAnalysisPage { my ($r,$c)=@_; # my %Saveable_Parameters = ('Status' => 'scalar', 'Section' => 'array', + 'Groups' => 'array', 'NumPlots' => 'scalar', 'AnalyzeOver' => 'scalar', ); @@ -71,24 +74,27 @@ sub BuildProblemAnalysisPage { # &Apache::lonstatistics::PrepareClasslist(); # + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Detailed Problem Analysis')); + &Apache::lonquickgrades::startGradeScreen($r,'statistics'); + $r->print(&CreateInterface()); # my @Students = @Apache::lonstatistics::Students; # - if (@Students < 1 && exists($ENV{'form.firstrun'})) { - $r->print('
'.&Apache::lonstatistics::section_and_enrollment_description().'
'); + if ($env{'form.show_prob'} eq 'true') { + $r->print(''.
+ &mt($no_data_message,$plot_num,@extra_data).
+ ' | |
'. + &mt($header_message,$plot_num,@extra_data). + ' | |
'. + &mt($stats_message, + $stats->{'submission_count'}, + $stats->{'correct_count'}, + $stats->{'incorrect_count'}, + $stats->{'students'}, + @extra_data). + ' | |
'. + &numerical_plot_percent($r,$responses,$stats).' | '. + ''. + &numerical_plot_differences($r,$responses,$stats).' | '. + '
'.$post_message.' |
'.&mt('Bar').' | '. + ''.&mt('Range').' | '. + ''.&mt('Incorrect').' | '. + ''.&mt('Correct').' | '. + ''.&mt('Count').' | '. + '||
---|---|---|---|---|---|---|
'.$labels->[$i].' | '. + ''.$lownum.' | '. + '- | '. + ''.$highnum.' | '. + ''.$incorrect->[$i].' | '. + ''.$correct->[$i].' | '. + ''.$count->[$i].' | '. + '
'.
- ''.$title.' (N='.$N.')'.
- ''.
+ ''.&mt('Distribution of correct answers').''.
+ ' '.&mt('[_1] students, [_2] distinct correct answers', + $n,scalar(keys(%$data))). + ' '.&mt('Maximum number of coinciding values: [_1]',$max_y). ' | ||||
'.$min.' | '. + ''.$min_x.' | '. ''.$plotresult.' | '. - ''.$max.' | '. + ''.$max_x.' | '. '
'. - 'Maximum Number of Coinciding Values: '.$max_y. - ' |
'. ''. &mt($pre_graph_text, $plot_num,$foil_choice_data->{'_count'}, - $correct, - $foil_choice_data->{'_count'}-$correct, + $correct, + $incorrect, + $foil_choice_data->{'_students'}, @extra_data). ' | |||||||||||||||||||
'.
+ ' '.
&mt($no_data_text,
$plot_num,$foil_choice_data->{'_count'},
$correct,
$foil_choice_data->{'_count'}-$correct,
- @extra_data);
+ @extra_data).
+ ' ';
if (defined($post_graph_text)) {
$analysis_html.=''.$post_graph_text; } @@ -573,7 +1007,7 @@ sub ensure_start_end_times { (localtime($last - $sec_in_day*($plot_num-1)))[3..5]; $start = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear); $end = $start + $sec_in_day; - if ($plot_num == $ENV{'form.NumPlots'}) { + if ($plot_num == $env{'form.NumPlots'}) { $start = $first; } } @@ -596,7 +1030,6 @@ sub RR_concept_plot { } else { $incorrect_by_concept{$concept->{'name'}} += $foil_data->{$foil}->{$choice}; - } } } @@ -617,10 +1050,11 @@ sub RR_concept_plot { for (my $i=0;$i<=$#correct;$i++) { $correct[$i] = sprintf('%0f',$correct[$i]/$total*100); } - my $xlabel = 'concept'; + my $xlabel = &mt('concept'); + my $ylabel = &mt('Percent Choosing'); my $plot= &Apache::loncommon::DrawBarGraph($title, $xlabel, - 'Percent Choosing', + $ylabel, 100, ['#33ff00','#ff3300'], undef, @@ -686,10 +1120,11 @@ sub RR_create_percent_selected_plot { @labels = (1 .. scalar(@correct)); } # - my $xlabel = 'foil chosen'; + my $xlabel = &mt('foil chosen'); + my $ylabel = &mt('Percent Choosing'); my $plot= &Apache::loncommon::DrawBarGraph($title, $xlabel, - 'Percent Choosing', + $ylabel, 100, ['#33ff00','#ff3300'], \@labels, @@ -750,17 +1185,30 @@ sub RR_create_stacked_selection_plot { push(@empty_row,0); } # + my $xlabel = &mt('Correct Foil'); + my $ylabel = &mt('foils chosen Incorrectly'); my $graph = &Apache::loncommon::DrawBarGraph - ($title,'Correct Foil','foils chosen Incorrectly', + ($title,$xlabel,$ylabel, 100,$plotcolors,\@labels,\@empty_row,@dataset); return ($graph,\%count_per_foil); } + +######################################################### +######################################################### +## +## Misc routines +## +######################################################### +######################################################### + # if $correct is a hash ref, it is assumed to be indexed by student names. # the values are assumed to be hash refs with a key of 'answer'. -sub RR_classify_response_data { +sub classify_response_data { my ($full_row_data,$correct,$function) = @_; my %submission_data; + my %students; + my $max=0; foreach my $row (@$full_row_data) { my %subm = &hashify_attempt($row); if (ref($correct) eq 'HASH') { @@ -770,13 +1218,19 @@ sub RR_classify_response_data { } $subm{'submission'} =~ s/=\d+\s*$//; if (&$function(\%subm)) { + $students{$subm{'student'}}++; $submission_data{'_count'}++; if (&submission_is_correct($subm{'award'})) { $submission_data{'_correct'}++; } - $submission_data{$subm{'correct'}}->{$subm{'submission'}}++; + + if($max<++$submission_data{$subm{'correct'}}->{$subm{'submission'}}) { + $max=$submission_data{$subm{'correct'}}->{$subm{'submission'}}; + } } } + $submission_data{'_max'} = $max; + $submission_data{'_students'}=scalar(keys(%students)); return \%submission_data; } @@ -794,40 +1248,34 @@ sub OptionResponseAnalysis { $problem->{'respid'}); # Note: part data is not needed. my $PerformanceData = &Apache::loncoursedata::get_response_data - (\@Apache::lonstatistics::SelectedSections, + ([&Apache::lonstatistics::get_selected_sections()], + [&Apache::lonstatistics::get_selected_groups()], $Apache::lonstatistics::enrollment_status, - $resource->{'symb'},$respid); + $resource->symb,$respid); if (! defined($PerformanceData) || ref($PerformanceData) ne 'ARRAY' ) { - $r->print(' '. - &mt('There is no student data for this problem.'). - ''); + $r->print(''
+ .&mt('There is no student data for this problem.')
+ .' '
+ );
} else {
$r->rflush();
- if (exists($ENV{'form.ExcelOutput'})) {
- my $result = &OR_excel_sheet($r,$resource,
- $PerformanceData,
- $problem_data);
- $r->print($result);
+ if ($env{'form.AnalyzeOver'} eq 'tries') {
+ my $analysis_html = &OR_tries_analysis($r,
+ $PerformanceData,
+ $problem_data);
+ $r->print($analysis_html);
+ $r->rflush();
+ } elsif ($env{'form.AnalyzeOver'} eq 'time') {
+ my $analysis_html = &OR_time_analysis($PerformanceData,
+ $problem_data);
+ $r->print($analysis_html);
$r->rflush();
} else {
- if ($ENV{'form.AnalyzeOver'} eq 'tries') {
- my $analysis_html = &OR_tries_analysis($r,
- $PerformanceData,
- $problem_data);
- $r->print($analysis_html);
- $r->rflush();
- } elsif ($ENV{'form.AnalyzeOver'} eq 'time') {
- my $analysis_html = &OR_time_analysis($PerformanceData,
- $problem_data);
- $r->print($analysis_html);
- $r->rflush();
- } else {
- $r->print(''. - &mt('The analysis you have selected is '. - 'not supported at this time'). - ''); - } + $r->print(''
+ .&mt('The analysis you have selected is not supported at this time.')
+ .' '
+ );
}
}
}
@@ -840,8 +1288,11 @@ sub OptionResponseAnalysis {
sub OR_tries_analysis {
my ($r,$PerformanceData,$ORdata) = @_;
my $mintries = 1;
- my $maxtries = $ENV{'form.NumPlots'};
+ my $maxtries = $env{'form.NumPlots'};
my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
+ if (! defined($Concepts)) {
+ $Concepts = [];
+ }
my %response_data = &OR_analyze_by_tries($r,$PerformanceData,
$mintries,$maxtries);
my $analysis = '';
@@ -901,12 +1352,18 @@ sub OR_tries_analysis {
if (! defined($response_data{'_total'}->[$try]) ||
$response_data{'_total'}->[$try] == 0) {
if ($try > 1) {
- $analysis_html.= ' | |||||||||||||||||||
'. - &mt('None of the selected students attempted the problem more than [_1] times.',$try-1). - ' | |||||||||||||||||||
'
+ .' '
+ .&mt('None of the selected students attempted the problem more than [quant,_1,time].'
+ ,$try-1)
+ .' '
+ .' | |||||||||||||||||||
'. - &mt('None of the selected students have attempted the problem').' | |||||||||||||||||||
'
+ .' '
+ .&mt('None of the selected students have attempted the problem.')
+ .' '
+ .' | |||||||||||||||||||
'.
''.
@@ -1040,13 +1510,14 @@ sub OR_time_analysis {
if (defined($Concepts)) { $num_concepts = scalar(@$Concepts); }
#
if ($num_concepts < 2) {
- $table = ''. - &mt('Not enough data for concept analysis. '. - 'Performing Foil Analysis'). - ''.$table; + $table = ''. + &mt('Not enough data for concept analysis.'. + ' Performing Foil Analysis instead.'). + ' '. + $table; } # - my $num_plots = $ENV{'form.NumPlots'}; + my $num_plots = $env{'form.NumPlots'}; my $num_data = scalar(@$performance_data)-1; # my $current_index; @@ -1097,9 +1568,10 @@ sub OR_time_analysis { ## my ($processed_time_data,$correct,$data_count,$student_count) = &OR_time_process_data($performance_data,$begin_index,$end_index); + $correct |= 0; ## $table .= ''.
- &mt('[_1] submissions from [_2] students submitting, [_3] correct, [_4] incorrect',
+ &mt('[quant,_1,submission,submissions,No submissions] from [quant,_2,student], [_3] correct, [_4] incorrect',
$data_count,$student_count,$correct,$data_count-$correct).
' | '.
&mt('Start time: [_1]',$startdateform).' | '. &mt('End time: [_1]',$enddateform).'   | | |
'.&mt("Unable to create new Excel file. ". - "This error has been logged. ". - "Please alert your LON-CAPA administrator"). - '
'); - 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, - $performance_data,$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('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,$performance_data,$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 (@$performance_data) { - next if (! defined($row)); - my ($student,$award,$grading,$submission,$time,$tries) = @$row; - my @Foilgrades = split('&',$grading); - my @Foilsubs = split('&',$submission); - my %response_data; - for (my $j=0;$j<=$#Foilgrades;$j++) { - my ($foilid,$correct) = split('=',$Foilgrades[$j]); - my (undef,$submission) = split('=',$Foilsubs[$j]); - $submission = &Apache::lonnet::unescape($submission); - $response_data{$foilid.' submission'}=$submission; - $response_data{$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++, - $response_data{$foilid.' submission'}); - $worksheet->write($rows_output,$cols_output++, - $response_data{$foilid.' award'}); - } - $rows_output++; - $cols_output = 0; - } - return; -} - sub build_foil_index { my ($ORdata) = @_; return if (! exists($ORdata->{'_Foils'})); @@ -1484,23 +1796,23 @@ sub build_foil_index { } # # Build up the table of row labels. - my $table = ''.&mt('Concept Number').' | '. ''.&mt('Concept').' | '. ''.&mt('Foil Number').' | '. ''.&mt('Foil Name').' | '. ''.&mt('Foil Text').' | '. ''.&mt('Correct Value').' | '. - "
---|---|---|---|---|---|
'.&mt('Foil Number').' | '. ''.&mt('Foil Name').' | '. ''.&mt('Foil Text').' | '. ''.&mt('Correct Value').' | '. - "||
'.$conceptindex.' | '. ''.&HTML::Entities::encode($concept->{'name'},'<>&"').' | '. ''.$foilindex++.' | '. ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').' | '. ''.$Foildata{$firstfoil}->{'text'}.' | '. ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').' | '. - "
'.$foilindex++.' | '. ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').' | '. ''.$Foildata{$firstfoil}->{'text'}.' | '. ''.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').' | '. - "||
'. ' | '. ' | '.$foilindex.' | '. ''.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').' | '. ''.$Foildata{$foilid}->{'text'}.' | '. ''.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').' | '. - "
'.$foilindex.' | '. ''.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').' | '. ''.$Foildata{$foilid}->{'text'}.' | '. ''.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').' | '. - "
'.&mt('Sections').' | '; - $Str .= ''.&mt('Enrollment Status').' | '; -# $Str .= ''.&mt('Sequences and Folders').' | '; - $Str .= ''; - $Str .= ' | '.&mt('Sections').' | '; + $Str .= ''.&mt('Groups').' | '; + $Str .= ''.&mt('Access Status').' | '; + $Str .= ''.&mt('Options').' | '; + $Str .= &Apache::loncommon::end_data_table_header_row(); ## ## - $Str .= '
---|---|---|---|---|---|---|
'."\n"; + $Str .= &Apache::loncommon::start_data_table_row(); + $Str .= ' | '."\n"; $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5); $Str .= ' | '; # + $Str .= ''."\n"; + $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5); + $Str .= ' | '; + # $Str .= ''; $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5); $Str .= ' | '; # -# $Str .= ''; - my $only_seq_with_assessments = sub { - my $s=shift; - if ($s->{'num_assess'} < 1) { - return 0; - } else { - return 1; - } - }; - &Apache::lonstatistics::MapSelect('Maps','multiple,all',5, - $only_seq_with_assessments); ## ## - $Str .= ' | '; + $Str .= ' | ';
##
my $showprob_checkbox =
- '';
- $Str.= ' '; + $Str.= ' '; ## - my $analyze_selector = ''; - $Str .= ' '.$/; + ' '.$/; ## my $numplots_selector = ' '; - $Str .= ' '; ## - $Str .= ' | ';
##
##
- $Str .= '