--- loncom/interface/statistics/loncorrectproblemplot.pm 2004/03/08 18:42:58 1.10 +++ loncom/interface/statistics/loncorrectproblemplot.pm 2012/05/07 10:12:42 1.28 @@ -1,6 +1,6 @@ # The LearningOnline Network with CAPA # -# $Id: loncorrectproblemplot.pm,v 1.10 2004/03/08 18:42:58 matthew Exp $ +# $Id: loncorrectproblemplot.pm,v 1.28 2012/05/07 10:12:42 goltermann Exp $ # # Copyright Michigan State University Board of Trustees # @@ -28,9 +28,10 @@ package Apache::loncorrectproblemplot; use strict; -use Apache::lonnet(); +use Apache::lonnet; use Apache::loncommon(); use Apache::lonhtmlcommon(); +use Apache::lonquickgrades(); use Apache::loncoursedata(); use Apache::lonstatistics; use Apache::lonstathelpers; @@ -39,10 +40,6 @@ use Apache::lonlocal; my @SubmitButtons = ( { name => 'CreatePlot', text => 'Create Plot' }, - { name => 'ClearCache', - text => 'Clear Caches' }, - { name => 'updatecaches', - text => 'Update Student Data' }, ); ######################################################### @@ -63,13 +60,17 @@ sub BuildCorrectProblemsPage { my ($r,$c)=@_; # my %Saveable_Parameters = ('Status' => 'scalar', - 'Section' => 'array'); + 'Section' => 'array', + 'Groups' => 'array'); &Apache::loncommon::store_course_settings('correct_problems_plot', \%Saveable_Parameters); &Apache::loncommon::restore_course_settings('correct_problems_plot', \%Saveable_Parameters); # &Apache::lonstatistics::PrepareClasslist(); + + $r->print(&Apache::lonhtmlcommon::breadcrumbs('Correct Problems Plot')); + &Apache::lonquickgrades::startGradeScreen($r,'statistics'); # $r->print(&CreateInterface()); # @@ -77,51 +78,58 @@ sub BuildCorrectProblemsPage { # if (@Students < 1) { $r->print('

'. - &mt('There are no students in the sections selected'). + &mt('There are no students in the sections/groups selected'). '

'); } # - &Apache::loncoursedata::clear_internal_caches(); - if (exists($ENV{'form.ClearCache'}) || - exists($ENV{'form.updatecaches'}) || - (exists($ENV{'form.firstanalysis'}) && - $ENV{'form.firstanalysis'} ne 'no')) { - &Apache::lonstatistics::Gather_Full_Student_Data($r); - } - if (! exists($ENV{'form.firstanalysis'})) { - $r->print(''); - } else { - $r->print(''); - } + my @CacheButtonHTML = + &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status'); foreach my $button (@SubmitButtons) { $r->print(''); $r->print(' 'x5); } + foreach my $html (@CacheButtonHTML) { + $r->print($html.(' 'x5)); + } $r->rflush(); # # Determine which problem symbs we are to sum over - if (exists($ENV{'form.CreatePlot'})) { + if (exists($env{'form.CreatePlot'})) { my @ProblemSymbs; - my $total_parts = 0; + my $total_weights = 0; my $title = ''; - if ($Apache::lonstatistics::SelectedMaps[0] ne 'all') { - foreach my $seq (&Apache::lonstatistics::Sequences_with_Assess()){ + my @maps = &Apache::lonstatistics::get_selected_maps('Maps'); + my ($navmap,@sequences) = + &Apache::lonstatistics::selected_sequences_with_assessments(); + if ($maps[0] ne 'all') { + foreach my $seq (@sequences) { if ($title eq '') { - $title = $seq->{'title'}; + $title = $seq->compTitle; } else { $title = 'Multiple Sequences'; } - foreach my $res (@{$seq->{'contents'}}) { - next if ($res->{'type'} ne 'assessment'); - foreach my $part (@{$res->{'parts'}}) { - $total_parts++; - push(@ProblemSymbs,{symb=>$res->{'symb'}, - part=>$part}); - } + } + } else { + $title = 'All Problems'; + } + foreach my $seq (@sequences) { + my @resources = + &Apache::lonstathelpers::get_resources($navmap,$seq); + foreach my $res (@resources) { + foreach my $partid (@{$res->parts}) { + push(@ProblemSymbs,{symb=>$res->symb, + part=>$partid}); + $total_weights += + &Apache::lonnet::EXT('resource.'.$partid.'.weight', + $res->symb, + undef,undef,undef); } } } + $r->print('

'. + &Apache::lonstatistics::section_and_enrollment_description(). + '

'); my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits(); if (defined($starttime) || defined($endtime)) { # Inform the user what the time limits on the data are. @@ -129,12 +137,16 @@ sub BuildCorrectProblemsPage { &Apache::lonlocal::locallocaltime($starttime), &Apache::lonlocal::locallocaltime($endtime))); } + &Apache::loncoursedata::populate_weight_table(); my $score_data = &Apache::loncoursedata::get_student_scores - (\@Apache::lonstatistics::SelectedSections, + ([&Apache::lonstatistics::get_selected_sections()], + [&Apache::lonstatistics::get_selected_groups()], \@ProblemSymbs, $Apache::lonstatistics::enrollment_status,undef, $starttime,$endtime); - $r->print(&AnalyzeScoreData($score_data,$title,$total_parts)); + $r->print(&AnalyzeScoreData($score_data,$title,$total_weights)); + } else { + $r->print('

'.&mt('Make a sequence selection from the "Sequences and Folders" menu and hit "Create Plot" to begin').'

'); } return; } @@ -154,18 +166,17 @@ return html with a plot of the data and ######################################################### ######################################################### sub AnalyzeScoreData { - my ($score_data,$title,$total_parts) = @_; + my ($score_data,$title,$maximum) = @_; # # Basic check first - if (@$score_data < 1) { - return '

There is no data to plot

'; + if (ref($score_data) ne 'ARRAY' || @$score_data < 1) { + return '

'.&mt('There is no data to plot').'

'; } # # Determine which bins to use my $lowest = $score_data->[0]->[0]; $lowest = 0; my $highest = $score_data->[-1]->[0]; - &Apache::lonnet::logthis('highest = '.$highest); my $binsize = 1; if ($highest > 50) { $binsize = 2; } if ($highest > 100) { $binsize = 5; } @@ -177,7 +188,14 @@ sub AnalyzeScoreData { # Get the data into the bins (destroying $score_data in the process) my @Bins = &bin_data($score_data,$binsize,$lowest,$highest); my @Xdata; my @Ydata; my $max; - my $Str = ''."\n".''."\n"; + my $Str = + '

'. + &mt('Problem weights do not reflect individual student settings.') + .'

'. + &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ''. + &Apache::loncommon::end_data_table_header_row(); my $sum = 0; while (my $bin = shift(@Bins)) { push (@Xdata,$bin->{'start'}); @@ -186,21 +204,23 @@ sub AnalyzeScoreData { if ($bin->{'count'} > $max) { $max = $bin->{'count'}; } - $Str.= ''. - ''."\n"; + $Str.= &Apache::loncommon::start_data_table_row(). + ''. + ''. + &Apache::loncommon::end_data_table_row().'
'; } # scale max to an integer. $max = 5*(int($max/5)+1); - $Str .= "
RangeCount
'.&mt('Range').''.&mt('Count').'
'.$bin->{'start'}.' - '.$bin->{'end'}.''.$bin->{'count'}.'
'.$bin->{'start'}.' - '.$bin->{'end'}.''.$bin->{'count'}.'

\n"; + $Str .= &Apache::loncommon::end_data_table()."
\n"; $title = &HTML::Entities::decode($title); - $Str = "
\n".&Apache::loncommon::DrawBarGraph($title.' N = '.$sum, - 'Num Correct Problems (max:'.$total_parts.')', - 'Number of students', - $max, - undef, # colors - \@Xdata, - \@Ydata). - "\n
\n".$Str; + $Str = "\n

". + &Apache::loncommon::DrawBarGraph($title.' ('.$sum.' students)', + 'Correct Problems (max possible = '.$maximum.')', + 'Number of students', + $max,undef, # colors + \@Xdata,\@Ydata). + "\n
\n".$Str; + $Str .= '

'."\n"; return $Str; } @@ -237,7 +257,7 @@ sub bin_data { my @Bins; my $count=0; my $idx=0; - while ($idx < scalar(@$data) && ($endbin-$binend + $binsize)>0) { + while ($idx < scalar(@$data) && ($endbin-$binend + $binsize)>=0) { my $dataset = $data->[$idx++]; my ($x,$y) = @{$dataset}; while ($x > ($binend-.001)) { @@ -279,41 +299,40 @@ sub CreateInterface { ## ## Environment variable initialization my $Str; - $Str .= &Apache::lonhtmlcommon::breadcrumbs - (undef,'Correct Problems Plot'); - $Str .= ''."\n"; - $Str .= ''; - $Str .= ''; - $Str .= ''; - $Str .= ''; - $Str .= ''; - $Str .= ''."\n"; - ## - ## - $Str .= ''; + $Str .= ''; + $Str .= ''; + $Str .= ''; + $Str .= ''; + $Str .= &Apache::loncommon::end_data_table_header_row(); + # + $Str .= &Apache::loncommon::start_data_table_row(); + $Str .= ''; # - $Str .= ''; + $Str .= ''."\n"; # - my $only_seq_with_assessments = sub { - my $s=shift; - if ($s->{'num_assess'} < 1) { - return 0; - } else { - return 1; - } - }; - $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5, - $only_seq_with_assessments); + $Str .= ''; + # + $Str .= ''; # + $Str .= &Apache::loncommon::end_data_table_row(); + $Str .= &Apache::loncommon::end_data_table(); ## - $Str .= ''."\n"; - $Str .= '
'.&mt('Sections').''.&mt('Enrollment Status').''.&mt('Sequences and Folders').''. - &Apache::lonstathelpers::limit_by_time_form().'
'."\n"; + $Str .= '

'; + # + $Str .= &Apache::loncommon::start_data_table(); + $Str .= &Apache::loncommon::start_data_table_header_row(); + $Str .= '

'.&mt('Sections').''.&mt('Groups').''.&mt('Access Status').''.&mt('Sequences and Folders').''.&mt('Time Period').''."\n"; $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5); $Str .= ''; + $Str .= ''."\n"; + $Str .= &Apache::lonstatistics::GroupSelect('Group','multiple',5); + $Str .= ''; $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5); - $Str .= ''."\n"; + $Str .= ''."\n"; + $Str .= &Apache::lonstatistics::map_select('Maps','multiple,all',5); + $Str .= ''."\n"; + $Str .= &Apache::lonstathelpers::limit_by_time_form(); $Str .= '
'."\n"; return $Str; }