--- loncom/homework/bridgetask.pm 2005/05/03 00:05:41 1.14 +++ loncom/homework/bridgetask.pm 2005/05/03 05:31:51 1.15 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # definition of tags that give a structure to a document # -# $Id: bridgetask.pm,v 1.14 2005/05/03 00:05:41 albertel Exp $ +# $Id: bridgetask.pm,v 1.15 2005/05/03 05:31:51 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -52,6 +52,8 @@ sub initialize_bridgetask { @Apache::bridgetask::instance=(); # list of all Instance ids seen in this problem @Apache::bridgetask::instancelist=(); + # key of queud user data that we are currently grading + $Apache::bridgetask::queue_key=''; } sub proctor_check_auth { @@ -174,11 +176,22 @@ sub start_Task { } } } elsif ($target eq 'webgrade') { - $result.=$head_tag_start.$body_tag_start.$form_tag_start. - 'Yahoo!'; + $result.=$head_tag_start.$body_tag_start.$form_tag_start; $result.=&show_queue(); - $result.=&get_from_queue(); - + my $todo=&get_from_queue(); + if ($todo) { + my ($symb,$uname,$udom)=&decode_queue_key($todo); + $result.="\n".'
Found'. + $symb.':'.$uname.':'.$udom.'
'; + $result.=''; + $Apache::bridgetask::queue_key=$todo; + } else { + $result.="\n". + '
No user to be graded.
'; + my $bodytext=&Apache::lonxml::get_all_text("/task",$parser); + } + } else { # page_start returned a starting result, delete it if we don't need it $result = ''; @@ -191,14 +204,14 @@ sub end_Task { my $result=''; my $status=$Apache::inputtags::status['-1']; if ($target eq 'grade' || $target eq 'web' || $target eq 'answer' || - $target eq 'tex' || $target eq 'webgrade') { + $target eq 'tex') { if ( (($target eq 'web') && ($env{'request.state'} ne 'construct')) || ($target eq 'answer') || ($target eq 'tex') ) { if ($target eq 'web') { if ($status eq 'CAN_ANSWER') { - $result.=''. + $result.="\n".'
'. &Apache::inputtags::file_selector('0',"bridgetask","*", 'portfolioonly'). "
"; @@ -224,6 +237,15 @@ sub end_Task { &add_to_queue(); } } + } elsif ($target eq 'webgrade') { + $result.="\n
"; + $result.=' '; + $result.=' '; + $result.=' '; + $result.=''.&Apache::loncommon::endbodytag().''; } elsif ($target eq 'meta') { $result.=''."\n"; #$result.=&Apache::response::meta_part_order(); @@ -250,7 +272,7 @@ sub show_queue { my $cdom=$env{'course.'.$cid.'.domain'}; my $regexp="^$symb\0queue"; my %queue=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp); - $result.=""; + $result.="\n

Current Queue

resourceuserTime available for grading
"; foreach my $key (sort(keys(%queue))) { my ($symb,undef,$user) = split("\0",$key); my ($uname,$udom) = split('@',$user); @@ -260,7 +282,7 @@ sub show_queue { my %slot_data=&Apache::lonnet::get_slot($slot); $result.="End time: ".&Apache::lonlocal::locallocaltime($slot_data{'endtime'}).""; } - $result.="
resourceuserTime available for grading
"; + $result.="
\n"; return $result; } @@ -272,7 +294,7 @@ sub decode_queue_key { } sub queue_key_locked { - my ($key)=@_; + my ($key,$cdom,$cnum)=@_; my ($key_locked,$value)= &Apache::lonnet::get('gradingqueue',["$key\0locked"],$cdom,$cnum); if ($key_locked eq "$key\0locked") { @@ -282,54 +304,97 @@ sub queue_key_locked { } sub pick_from_queue_data { - my ($check_section,$queue)=@_; + my ($check_section,$queue,$cdom,$cnum)=@_; foreach my $key (sort(keys(%$queue))) { my ($symb,$uname,$udom)=&decode_queue_key($key); if ($check_section) { my $section=&Apache::lonnet::getsection($uname,$udom); - if ($section ne $check_section) { next; } + if ($section ne $check_section) { + &Apache::lonnet::logthis("not my sec"); + next; + } } my $slot=$queue->{$key}[0]; my %slot_data=&Apache::lonnet::get_slot($slot); - if ($slot_data{'endtime'} > time) { next; } - if (&queue_key_locked($key)) { next; } + if ($slot_data{'endtime'} > time) { + &Apache::lonnet::logthis("not time"); + next; + } + if (&queue_key_locked($key,$cdom,$cnum)) { + &Apache::lonnet::logthis("someone already has um."); + next; + } return $key; } return undef; } +sub find_mid_grade { + my ($symb,$cdom,$cnum)=@_; + my $todo=$env{'form.gradingkey'}; + my $me=$env{'user.name'}.'@'.$env{'user.domain'}; + if ($todo) { + my $who=&queue_key_locked($todo,$cdom,$cnum); + if ($who eq $me) { return $todo; } + } + my $regexp="^$symb\0.*\0locked\$"; + my %locks=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp); + foreach my $key (keys(%locks)) { + my $who=$locks{$key}; + if ($who eq $me) { + $todo=$key; + $todo=~s/\0locked$//; + return $todo; + } + } + return undef; +} + sub get_from_queue { my $result; my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser(); my $cnum=$env{'course.'.$cid.'.num'}; my $cdom=$env{'course.'.$cid.'.domain'}; my $todo; + # FIXME need to find if I am 'mid grading' + $todo=&find_mid_grade($symb,$cdom,$cnum); + &Apache::lonnet::logthis("found ".join(':',&decode_queue_key($todo))); while (1) { my $starttime=time; &Apache::lonnet::put('gradingqueue',{"$symb\0timestamp"=>$starttime}, $cdom,$cnum); + &Apache::lonnet::logthis("$starttime"); my $regexp="^$symb\0queue\0"; my %queue=&Apache::lonnet::dump('gradingqueue',$cdom,$cnum,$regexp); #make a pass looking for a user in my section if ($env{'request.course.sec'}) { - $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue); + &Apache::lonnet::logthis("sce"); + $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue, + $cdom,$cnum); + &Apache::lonnet::logthis("sce $todo"); } # no one in our section so look for any user that is ready for grading if (!$todo) { - $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue); + &Apache::lonnet::logthis("no sce"); + $todo=&pick_from_queue_data($env{'request.course.sec'},\%queue, + $cdom,$cnum); + &Apache::lonnet::logthis("no sce $todo"); } # no user to grade if (!$todo) { last; } + &Apache::lonnet::logthis("got $todo"); # otherwise found someone so lets try to lock them my $success=&Apache::lonnet::newput('gradingqueue', {"$todo\0locked"=> $env{'user.name'}.'@'.$env{'user.domain'}}, $cdom,$cnum); # someone else already picked them + &Apache::lonnet::logthis("success $todo"); if ($success ne 'ok') { next; } my (undef,$endtime)= &Apache::lonnet::get('gradingqueue',["$symb\0timestamp"], $cdom,$cnum); + &Apache::lonnet::logthis("emd $endtime"); # someone else already modified the queue, # perhaps our picked user wass already fully graded between # when we picked him and when we locked his record? so lets @@ -338,13 +403,16 @@ sub get_from_queue { my ($key,$value)= &Apache::lonnet::get('gradingqueue',["$todo"], $cdom,$cnum); + &Apache::lonnet::logthis("check $key .. $value"); if ($key eq $todo && ref($value)) { } else { &Apache::lonnet::del('gradingqueue',["$todo\0locked"], $cdom,$cnum); + &Apache::lonnet::logthis("del"); next; } } + &Apache::lonnet::logthis("last $todo"); last; } return $todo; @@ -398,7 +466,7 @@ sub end_Dimension { $result=$dimension{'intro'}.$dimension{$instance.'.text'}; } elsif ($target eq 'webgrade') { my $instance=&get_instance(); - $result.=''; + $result.="\n".'
'; foreach my $id (@{$dimension{$instance.'.criterias'}}) { $result.='';
'. $dimension{$instance.'.criteria.'.$id}.'