--- loncom/interface/statistics/lonproblemanalysis.pm 2004/12/03 21:53:59 1.107 +++ loncom/interface/statistics/lonproblemanalysis.pm 2014/02/26 17:46:19 1.146 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: lonproblemanalysis.pm,v 1.107 2004/12/03 21:53:59 matthew Exp $ +# $Id: lonproblemanalysis.pm,v 1.146 2014/02/26 17:46:19 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,18 +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', @@ -53,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', ); @@ -72,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).
- ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'. @@ -280,16 +306,16 @@ sub numerical_response_analysis { ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'. &mt($stats_message, - $responses->{'_count'}, - $responses->{'_correct'}, - $responses->{'_count'}-$responses->{'_correct'}, - $responses->{'_students'}, + $stats->{'submission_count'}, + $stats->{'correct_count'}, + $stats->{'incorrect_count'}, + $stats->{'students'}, @extra_data). ' | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
'. - &numerical_plot_percent($r,$responses).' | '. + &numerical_plot_percent($r,$responses,$stats).''. ''. - &numerical_plot_differences($r,$responses).' | '. + &numerical_plot_differences($r,$responses,$stats).''. ''.&mt('Correct').' | '. ''.&mt('Count').' | '. ''.$/; - for (my $i=0;$i||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
'.$labels->[$i].' | '. @@ -546,7 +636,7 @@ sub numerical_determine_answers { my ($r,$resource,$partid,$respid,$students)=@_; my $c = $r->connection(); # - # FIX ME: May need progress dialog updates + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,scalar(@$students)); # # Read in the cache (if it exists) before we start timing things. &Apache::lonstathelpers::ensure_proper_cache($resource->{'symb'}); @@ -564,13 +654,26 @@ sub numerical_determine_answers { $sdom); # make the key my $key = $partid.'.'.$respid; - $correct->{$sname.':'.$sdom}->{'answer'} = - $analysis->{$key.'.answer'}->[0]; - $correct->{$sname.':'.$sdom}->{'unit'} = - $analysis->{$key.'.unit'}->[0]; - $answers{$analysis->{$key.'.answer'}->[0]}++; + # pick one of the possible answers + my $which = 'INTERNAL'; + if (!exists($analysis->{$key}{$which})) { + $which = (sort(keys(%{ $analysis->{$key} })))[0]; + } + foreach my $item ('answer','unit','ans_high','ans_low') { + if (ref($analysis->{$key.'.'.$item}) eq 'ARRAY') { + $correct->{$sname.':'.$sdom}->{$item} = + $analysis->{$key.'.'.$item}[0]; + } else { + $correct->{$sname.':'.$sdom}->{$item} = + $analysis->{$key.'.'.$item}{$which}[0][0]; + } + } + $answers{$correct->{$sname.':'.$sdom}{'answer'}}++; + &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state, + 'last student'); } &Apache::lonstathelpers::write_analysis_cache(); + &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state); return ($correct,\%answers); } @@ -691,7 +794,7 @@ sub circle { sub radio_response_analysis { my ($r,$problem,$problem_analysis,$students) = @_; # - if ($ENV{'form.AnalyzeOver'} !~ /^(tries|time)$/) { + if ($env{'form.AnalyzeOver'} !~ /^(tries|time)$/) { $r->print('Bad request'); } # @@ -720,9 +823,10 @@ sub radio_response_analysis { $analysis_html .= $table; # Gather student data my $response_data = &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); my $correct; # either a hash reference or a scalar if ($problem_analysis->{'answercomputed'} || scalar(@$concepts) > 1) { # This takes a while for large classes... @@ -733,7 +837,7 @@ sub radio_response_analysis { my ($idx,@remainder) = split('&',$student->{'answer'}); my ($answer) = ($remainder[$idx]=~/^(.*)=([^=]*)$/); $correct->{$student->{'username'}.':'.$student->{'domain'}}= - &Apache::lonnet::unescape($answer); + &unescape($answer); } } else { foreach my $foil (keys(%$foildata)) { @@ -744,29 +848,29 @@ sub radio_response_analysis { } # if (! defined($response_data) || ref($response_data) ne 'ARRAY' ) { - $analysis_html = '
'. ''. &mt($pre_graph_text, $plot_num,$foil_choice_data->{'_count'}, $correct, - $foil_choice_data->{'_count'}-$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; } @@ -890,7 +997,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; } } @@ -913,7 +1020,6 @@ sub RR_concept_plot { } else { $incorrect_by_concept{$concept->{'name'}} += $foil_data->{$foil}->{$choice}; - } } } @@ -934,10 +1040,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, @@ -1003,10 +1110,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, @@ -1067,8 +1175,10 @@ 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); } @@ -1128,40 +1238,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.')
+ .' '
+ );
}
}
}
@@ -1174,7 +1278,7 @@ 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 = [];
@@ -1238,12 +1342,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.')
+ .' '
+ .' | |||
'.
@@ -1377,13 +1500,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; @@ -1434,9 +1558,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, [_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'})); @@ -1849,23 +1786,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 .= '