--- loncom/interface/lonwhatsnew.pm 2005/05/23 23:06:23 1.13 +++ loncom/interface/lonwhatsnew.pm 2005/09/21 18:20:22 1.31 @@ -1,5 +1,5 @@ # -# $Id: lonwhatsnew.pm,v 1.13 2005/05/23 23:06:23 raeburn Exp $ +# $Id: lonwhatsnew.pm,v 1.31 2005/09/21 18:20:22 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,8 +35,10 @@ use Apache::lonhtmlcommon(); use Apache::lonlocal; use Apache::loncoursedata(); use Apache::lonnavmaps(); +use Apache::lonuserstate; use Apache::Constants qw(:common :http); use Time::Local; +use GDBM_File; #---------------------------- # handler @@ -85,6 +87,7 @@ sub handler { (undef,'Course Action Items','Course_Action_Items_Display')); } &display_main_box($r,$command); + return OK; } #------------------------------ @@ -104,10 +107,13 @@ sub display_main_box { degdiff => 'Degree of difficulty', numstudents => 'Total number of students with submissions', ); + my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; + my $crs = $env{'course.'.$env{'request.course.id'}.'.num'}; + if ($command eq 'chgthreshold') { - &display_config_box($r,$command,$tabbg,\%threshold_titles); + &display_config_box($r,$command,$tabbg,\%threshold_titles,$cdom,$crs); } else { - &display_actions_box($r,$command,\%threshold_titles); + &display_actions_box($r,$command,\%threshold_titles,$cdom,$crs); } $r->print(< @@ -145,7 +151,7 @@ ENDHEAD #------------------------------- sub display_actions_box() { - my ($r,$command,$threshold_titles) = @_; + my ($r,$command,$threshold_titles,$cdom,$crs) = @_; my $rowColor1 = "#ffffff"; my $rowColor2 = "#eeeeee"; @@ -161,6 +167,7 @@ sub display_actions_box() { my @tograde = (); my @bombs = (); my @warnings = (); + my %res_title = (); my $domain=&Apache::loncommon::determinedomain(); my $function; @@ -172,22 +179,26 @@ sub display_actions_box() { } my %threshold = ( - av_attempts => 0, - degdiff => 0.01, - numstudents => 0, + av_attempts => 2, + degdiff => 0.5, + numstudents => 2, ); my $pgbg=&Apache::loncommon::designparm($function.'.pgbg',$domain); my $tabbg=&Apache::loncommon::designparm($function.'.tabbg',$domain); unless ($env{'request.course.id'}) { - $r->print('
You are accessing an invalid course


'); + $r->print('
You are accessing an invalid course.


'); return; } + if (tie(my %bighash,'GDBM_File',$env{'request.course.fn'}.'.db', + &GDBM_READER(),0640)) { + my $furl=$bighash{'first_url'}; + $r->print('Go to first resource
Change your preferences
to suppress display of this screen when accessing courses as Course Coordinator in the future.

'); + untie(%bighash); + } my $result; - my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; - my $crs = $env{'course.'.$env{'request.course.id'}.'.num'}; if ($command eq 'reset') { $result = &process_reset($cdom,$crs); @@ -197,9 +208,10 @@ sub display_actions_box() { if ($result) { $r->print($result.'
'); } + $r->rflush(); &get_curr_thresholds(\%threshold,$cdom,$crs); - &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs); + &getitems(\%unread,\%ungraded,\%bombed,\%triggered,\@newdiscussions,\@tograde,\@bombs,\@warnings,$rowColor1,$rowColor2,\%threshold,$cdom,$crs,%res_title); my ($msgcount,$critmsgcount) = &getmail(\@newmsgs,\@critmsgs); $r->print('
'); -# @bombs = sort { &cmp_title($a,$b) } @bombs; + @bombs = sort { &cmp_title($a,$b,\%res_title) } @bombs; foreach my $bomb (@bombs) { if ($bombnum %2 == 1) { - $rowColor = $rowColor1; + $rowColor = $rowColor1; } else { $rowColor = $rowColor2; } @@ -282,13 +294,13 @@ END
'); @@ -253,10 +265,10 @@ END my $bombnum = 0; if (@bombs > 0) { $r->print('
ResourceNumber of errors
- +
END my $warningnum = 0; if (@warnings > 0) { -# @warnings = sort { &cmp_title($a,$b) } @warnings; + @warnings = sort { &cmp_title($a,$b,\%res_title) } @warnings; $r->print(''. - ' '."\n"); $r->print(''); foreach my $res (@warnings) { if ($warningnum %2 == 1) { @@ -329,7 +341,7 @@ END if (@newdiscussions > 0) { $r->print(''); -# @newdiscussions = sort { &cmp_title($a,$b) } @newdiscussions; + @newdiscussions = sort { &cmp_title($a,$b,\%res_title) } @newdiscussions; my $rowNum = 0; foreach my $ressymb (@newdiscussions) { my $forum_title = $unread{$ressymb}{'title'}; @@ -378,7 +390,7 @@ END } else { $rowColor = $rowColor2; } - $r->print(''); + $r->print(''); $rowNum ++; $mailcount ++; } @@ -410,7 +422,7 @@ END } else { $rowColor = $rowColor2; } - $r->print(''); + $r->print(''); $rowNum ++; $mailcount ++; } @@ -436,7 +448,7 @@ END #------------------------------- sub display_config_box() { - my ($r,$command,$tabbg,$threshold_titles) = @_; + my ($r,$command,$tabbg,$threshold_titles,$cdom,$crs) = @_; my %threshold = (); my $rowColor1 = "#ffffff"; my $rowColor2 = "#eeeeee"; @@ -448,7 +460,7 @@ sub display_config_box() { degdiff => 'Degree of difficulty', numstudents => 'Total number of students with submissions', ); - &get_curr_thresholds(\%threshold); + &get_curr_thresholds(\%threshold,$cdom,$crs); $r->print('
ResourcePartNum. studentsAv. AttemptsDeg. DiffLast ResetReset Count?
LocationTypeNumber of new posts
'.$mailcount.'.  '.$msg->{'shortsub'}.'    '.$msg->{'from'}.'@'.$msg->{'fromdom'}.' '.$msg->{'sendtime'}.'
'.$mailcount.'.  '.$msg->{'shortsub'}.'    '.$msg->{'from'}.'@'.$msg->{'fromdom'}.' '.$msg->{'sendtime'}.'
'.$mailcount.'.  '.$msg->{'shortsub'}.'    '.$msg->{'from'}.'@'.$msg->{'fromdom'}.' '.$msg->{'sendtime'}.'
'.$mailcount.'.  '.$msg->{'shortsub'}.'    '.$msg->{'from'}.'@'.$msg->{'fromdom'}.' '.$msg->{'sendtime'}.'
@@ -494,9 +506,10 @@ sub display_config_box() { } sub getitems { - my ($unread,$ungraded,$bombed,$triggered,$newdiscussions,$tograde,$bombs,$warnings,$rowColor1,$rowColor2,$threshold,$cdom,$crs) = @_; + my ($unread,$ungraded,$bombed,$triggered,$newdiscussions,$tograde,$bombs,$warnings,$rowColor1,$rowColor2,$threshold,$cdom,$crs,$res_title) = @_; my $navmap = Apache::lonnavmaps::navmap->new(); - my @allres=$navmap->retrieveResources(); + # force retrieve Resource to seed the part id cache we'll need it later + my @allres=$navmap->retrieveResources(undef,sub {if ($_[0]->is_problem) { $_[0]->parts();} return 1;}); my %discussiontime = &Apache::lonnet::dump('discussiontimes',$cdom,$crs); my %lastread = &Apache::lonnet::dump('nohist_'.$env{'request.course.id'}. '_discuss',$env{'user.domain'},$env{'user.name'},'lastread'); @@ -506,7 +519,6 @@ sub getitems { my %resourcetracker = &Apache::lonnet::dump('nohist_resourcetracker', $cdom,$crs); - my %res_title; my $warningnum = 0; foreach my $key (keys(%lastread)) { my $newkey = $key; @@ -522,10 +534,10 @@ sub getitems { %{$$triggered{$symb}} = (); $$triggered{$symb}{numparts} = 0; my $title = $resource->compTitle(); - $res_title{$symb} = $title; + $$res_title{$symb} = $title; my $ressymb = $resource->wrap_symb(); # Check for unread discussion postings - if (defined($discussiontime{$ressymb})) { + if ($resource->hasDiscussion()) { push(@discussions,$ressymb); my $prevread = 0; my $unreadcount = 0; @@ -554,34 +566,42 @@ sub getitems { if ($resource->is_problem()) { my $ctr = 0; my ($map,$ind,$url)=&Apache::lonnet::decode_symb($symb); - my ($partlist,$handgrade,$responseType) = &Apache::grades::response_type($url,$symb); - foreach my $student (keys(%$classlist)) { - my ($uname,$udom) = split(/:/,$student); - my %status=&Apache::grades::student_gradeStatus($url,$symb,$udom,$uname,$partlist); - my $submitted = 0; - my $ungraded = 0; - foreach (keys(%status)) { - $submitted = 1 if ($status{$_} ne 'nothing'); - $ungraded = 1 if ($status{$_} =~ /^ungraded/); - my ($foo,$partid,$foo1) = split(/\./,$_); - if ($status{'resource.'.$partid.'.submitted_by'} ne '') { - $submitted = 0; - } - } - next if (!$submitted || !$ungraded); - $ctr ++; - } - if ($ctr) { - $$ungraded{$symb}{count} = $ctr; - $$ungraded{$symb}{title} = $title; - push(@{$tograde}, $symb); - } + my $partlist=$resource->parts(); + my $handgradeable; + foreach my $part (@$partlist) { + if ($resource->handgrade($part) eq 'yes') { + $handgradeable=1; last; + } + } + if ($handgradeable) { + foreach my $student (keys(%$classlist)) { + my ($uname,$udom) = split(/:/,$student); + my %status=&Apache::grades::student_gradeStatus($url,$symb,$udom,$uname,$partlist); + my $submitted = 0; + my $ungraded = 0; + foreach (keys(%status)) { + $submitted = 1 if ($status{$_} ne 'nothing'); + $ungraded = 1 if ($status{$_} =~ /^ungraded/); + my ($foo,$partid,$foo1) = split(/\./,$_); + if ($status{'resource.'.$partid.'.submitted_by'} ne '') { + $submitted = 0; + } + } + next if (!$submitted || !$ungraded); + $ctr ++; + } + if ($ctr) { + $$ungraded{$symb}{count} = $ctr; + $$ungraded{$symb}{title} = $title; + push(@{$tograde}, $symb); + } + } } # Check for bombs if ($resource->getErrors()) { my $errors = $resource->getErrors(); - $errors =~ s/^,//; + $errors =~ s/^,//; my @bombs = split(/,/, $errors); my $errorcount = scalar(@bombs); my $errorlink = ' 0) { $av_attempts = $attempts/$users; + $av_attempts = sprintf("%.2f",$av_attempts); } if ((($degdiff ne '' && $degdiff >= $$threshold{'degdiff'}) || ($av_attempts ne '' && $av_attempts >= $$threshold{'av_attempts'})) && ($users >= $$threshold{'numstudents'})) { $stats{$part}{degdiff} = $degdiff; $stats{$part}{attempts} = $av_attempts; $stats{$part}{users} = $users; - my %resethash = &Apache::lonnet::restore($symb,'nohist_resourcetracker',$cdom,$crs); - $lastreset{$part} = &get_counter_resets(\%resethash,$part); + $lastreset{$part} = $resourcetracker{$symb."\0".$part."\0resettime"}; $warning = 1; } } @@ -662,22 +685,6 @@ sub getitems { } } -sub get_counter_resets { - my ($resethash,$part) = @_; - my $lastreset = 'None'; - if ($$resethash{'version'}) { - for (my $version=1;$version<=$$resethash{'version'};$version++) { - if (exists($$resethash{$version.':'.$part.'prev_attempts'})) { - $lastreset = $$resethash{$version.':timestamp'}; - } - } - } - unless ($lastreset eq 'None') { - $lastreset = localtime($lastreset); - } - return $lastreset; -} - sub get_curr_thresholds { my ($threshold,$cdom,$crs) = @_; my %coursesettings = &Apache::lonnet::dump('environment', @@ -704,22 +711,20 @@ sub process_reset { ); my @resets = (); my %titles = (); - foreach my $key (keys %env) { + foreach my $key (keys(%env)) { next if ($key !~ /^form\.reset_(.+)$/); my $title = &Apache::lonnet::unescape($env{'form.title_'.$1}); my $reset_item = &Apache::lonnet::unescape($1); my %curr_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item); - my %resethash = (); my %aggregates = (); - my ($symb,$part) = split/\0/,$reset_item; + my ($symb,$part) = split(/\0/,$reset_item); foreach my $type (@agg_types) { $aggregates{$reset_item."\0".$type} = 0; - $resethash{$part."\0".'prev_'.$type} = $curr_aggregates{$reset_item."\0".$type}; } + $aggregates{$reset_item."\0".'resettime'} = time; my $putresult = &Apache::lonnet::put('nohist_resourcetracker',\%aggregates, $dom,$crs); if ($putresult eq 'ok') { - my $storeresult = &Apache::lonnet::cstore(\%resethash,$symb,'nohist_resourcetracker',$dom,$crs); $result .= $title.' -part '.$part.': '; my %new_aggregates = &Apache::lonnet::dump('nohist_resourcetracker',$dom,$crs,$reset_item); foreach my $type (@agg_types) { @@ -728,7 +733,7 @@ sub process_reset { $result =~ s/; $//; $result .= '
'; } else { - $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to ').$putresult.'.
'."\n"; + $result = $title.' -part '.$part.': '.&mt('Unable to reset counters to zero due to [_1]',$putresult).'.
'."\n"; } } return $result; @@ -736,7 +741,7 @@ sub process_reset { sub process_update { my ($dom,$crs,$threshold_titles) = @_; - my $setoutput = 'Changes to threshold(s):
'; + my $setoutput = 'Changes to threshold(s) for problem tracking:
'; foreach (keys %env) { next if ($_!~/^form\.(.+)\_setparmval$/); my $name = $1; @@ -747,10 +752,13 @@ sub process_update { my ($shortname) = ($name =~ /^internal\.threshold_(.+)$/); if ($put_result eq 'ok') { - $setoutput.=&mt('Set threshold for').' '.$$threshold_titles{$shortname}.' '.&mt('to').' '.$value.'.
'; - } else { - $setoutput.=&mt('Unable to set threshold for').' '.$name.' '.&mt('to'). - ' '.$value.' '.&mt('due to').' '.$put_result.'.
'; + $setoutput.=&mt('Set threshold for [_1] to [_2]', + ''.$$threshold_titles{$shortname}.'', + ''.$value.'').'
'; + } else { + $setoutput.=&mt('Unable to set threshold for [_1] to [_2] due to [_3].', + ''.$name.'',''.$value.'', + ''.$put_result.'').'
'; } } } @@ -819,7 +827,8 @@ sub getmail { } sub cmp_title { - my ($atitle,$btitle) = (lc($_[0]->compTitle),lc($_[1]->compTitle)); + my ($a,$b,$res_title) = @_; + my ($atitle,$btitle) = (lc($$res_title{$a}),lc($$res_title{$b})); $atitle=~s/^\s*//; $btitle=~s/^\s*//; return $atitle cmp $btitle;