--- loncom/homework/bridgetask.pm 2005/05/27 17:08:03 1.32
+++ loncom/homework/bridgetask.pm 2005/08/09 07:34:51 1.38
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.32 2005/05/27 17:08:03 albertel Exp $
+# $Id: bridgetask.pm,v 1.38 2005/08/09 07:34:51 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -36,6 +36,7 @@ use Apache::File();
use Apache::lonmenu;
use Apache::lonlocal;
use Apache::lonxml;
+use Apache::slotrequest();
use Time::HiRes qw( gettimeofday tv_interval );
BEGIN {
@@ -91,6 +92,7 @@ sub proctor_check_auth {
sub get_version {
my ($version,$previous);
if ($env{'form.previousversion'} &&
+ $env{'form.previousversion'} ne 'current' &&
defined($Apache::lonhomework::history{'resource.'.$env{'form.previousversion'}.'.status'})) {
$version=$env{'form.previousversion'};
$previous=1;
@@ -129,6 +131,7 @@ sub add_previous_version_button {
my $list='\n\n";
+ $list.='';
$result.='
';
if ( 1) {
#need a permissions for limitng this to 'powerful users'
- #check if review queue has items
+
+ my ($entries,$ready,$locks)=&get_queue_counts('gradingqueue');
+ $result.='
'.&mt("Grading Queue has [_1] entries. [_2] of them are ready to be graded and [_3] of them are currently being graded",$entries,$ready,$locks);
+
+ $result.='
'.&mt("Review Queue has [_1] entries. [_2] of them are ready to be graded and [_3] of them are currently being graded",$entries,$ready,$locks);
$result.=' ';
+ &mt("Select an entry from the review queue").'" />
'."\n";
}
return $result;
}
sub add_request_another_attempt_button {
+ my ($text)=@_;
+ if (!$text) { $text="Request another attempt"; }
my $result;
- $result.=' ';
+ my $symb=&Apache::lonnet::symbread();
+ my ($slot_name,$slot)=&Apache::slotrequest::check_for_reservation($symb);
+ my $action='get_reservation';
+ if ($slot_name) {
+ $text="Change reservation.";
+ $action='change_reservation';
+ my $description=&Apache::slotrequest::get_description($slot_name,
+ $slot);
+ $result.=(< Will be next available: $description
+STUFF
+ }
+
+ if ($env{'request.enc'}) { $symb=&Apache::lonenc::encrypted($symb); }
+ $symb=&Apache::lonnet::escape($symb);
+ $result.='';
return $result;
}
@@ -192,6 +224,14 @@ sub start_Task {
my $uri=$env{'request.uri'};
if ($env{'request.enc'}) { $uri=&Apache::lonenc::encrypted($uri); }
$body_tag_start.=$uri.'">'.&add_grading_button()."";
+ my $symb=&Apache::lonnet::symbread();
+ $body_tag_start.='';
+
}
}
if ($target eq 'web' || ($target eq 'grade' && !$env{'form.webgrade'}) || $target eq 'answer' ||
@@ -222,6 +262,7 @@ sub start_Task {
$msg.='
'.&mt('Unable to determine if this resource is open due to network problems. Please try again later.').'
';
} elsif ($status eq 'NOT_IN_A_SLOT') {
$msg.='
'.&mt('You are not currently signed up to work at this time and/or place.').'
';
+ $msg.=&add_request_another_attempt_button("Sign up for time to work.");
} elsif ($status eq 'NEEDS_CHECKIN') {
$msg.='
'.&mt('You need the Proctor to validate you.').
'
'.&proctor_validation_screen($slot);
@@ -256,9 +297,8 @@ sub start_Task {
} elsif ($target eq 'web') {
my $name= &Apache::structuretags::get_resource_name($parstack,$safeeval);
$result.="$head_tag_start$name
- $body_tag_start \n $form_tag_start".
- '';
- $result.=&preserve_grade_info();
+ $body_tag_start \n";
+
my ($version,$previous)=&get_version();
if ($Apache::lonhomework::history{"resource.$version.status"} eq 'fail') {
$result.='
'.&mt('Did not pass').'
';
@@ -269,52 +309,64 @@ sub start_Task {
if ($Apache::lonhomework::history{"resource.$version.status"} eq 'pass') {
$result.='
'.&mt('Passed').'
';
}
+ $result.=$form_tag_start.
+ '';
+ $result.=&preserve_grade_info();
+
}
} elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
$target eq 'webgrade') {
my $webgrade='yes';
if ($target eq 'webgrade') {
- #FIXME FORM conflcit with the 'show queue',1
$result.=$head_tag_start.$body_tag_start;
$result.=' Review'.&show_queue('reviewqueue');
- $result.=' Before'.&show_queue('gradingqueue');
+ $result.=' Grade'.&show_queue('gradingqueue');
}
- if (defined($env{'form.reviewasubmission'})) {
- $result.=&show_queue('reviewqueue',1);
- my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
- } else {
- my ($todo,$status_code)=&get_key_todo($target);
- if ($todo) {
- &setup_env_for_other_user($todo,$safeeval);
- my ($symb,$uname,$udom)=&decode_queue_key($todo);
- $result.="\n".'
Found '.
- &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'
';
+ # FIXME Blast! still need to reorg this, need to reshow the
+ # queue being reviewed once done with the grade pass...
+ # Hrrm, vaildation pass should perhaps say 'not_locked'
+ # perhaps do a search if there is a key that is mine and if
+ # there isn't reshow the queue....
+ my ($todo,$status_code)=&get_key_todo($target);
+
+ &Apache::lonnet::logthis("got todo -$todo- stat -$status_code-");
+ if ($todo) {
+ &setup_env_for_other_user($todo,$safeeval);
+ my ($symb,$uname,$udom)=&decode_queue_key($todo);
+ $result.="\n".'
Found '.
+ &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'
';
- if ($status_code eq 'stop') {
- $result.=&mt("Stopped grading.");
- } elsif ($status_code eq 'lock_failed') {
- $result.=&mt("Failed to lock the request record.");
- } elsif ($status_code eq 'unlock') {
- $result.=&mt("Unlocked the requested user.");
- } else {
- $result.=&mt("No user to be graded.");
- }
- $result.='
';
+ }
+ } else {
+ if ($target eq 'webgrade') {
+ $result.="\n";
+ if ($status_code eq 'stop') {
+ $result.=''.&mt("Stopped grading.").'';
+ } elsif ($status_code eq 'lock_failed') {
+ $result.=''.&mt("Failed to lock the request record.").'';
+ } elsif ($status_code eq 'unlock') {
+ $result.=''.&mt("Unlocked the requested record.").'';
+ $result.=&show_queue($env{'form.queue'},1);
+ } elsif ($status_code eq 'show_list') {
+ $result.=&show_queue($env{'form.queue'},1);
+ } else {
+ $result.=''.&mt("No user to be graded.").'';
}
- $webgrade='no';
- my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
}
+ $webgrade='no';
+ my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
}
if ($target eq 'webgrade' && defined($env{'form.queue'})) {
$result.=$form_tag_start;
@@ -333,36 +385,73 @@ sub start_Task {
sub get_key_todo {
my ($target)=@_;
my $todo;
+
+ if (defined($env{'form.reviewasubmission'})) {
+ &Apache::lonnet::logthis("review a submission....");
+ $env{'form.queue'}='reviewqueue';
+ return (undef,'show_list');
+ }
+
+ if (defined($env{'form.reviewagrading'})) {
+ &Apache::lonxml::debug("review a grading....");
+ $env{'form.queue'}='gradingqueue';
+ return (undef,'show_list');
+ }
+
my $queue=$env{'form.queue'};
+
if (!defined($queue)) {
$env{'form.queue'}=$queue='gradingqueue';
}
+
my $gradingkey=&Apache::lonnet::unescape($env{'form.gradingkey'});
+
if (defined($env{'form.queue'}) && defined($env{'form.gradingkey'})
- && !defined($env{'form.action'})) {
- #FIXME probably need to do some cheking here for more validity
- &Apache::lonnet::logthis("Found a key was given to me");
- return ($gradingkey);
- }
- if ($env{'form.action'} eq 'resume') {
- &Apache::lonnet::logthis("Resuming a key");
- return ($gradingkey);
- } elsif ($env{'form.action'} eq 'unlock') {
- &Apache::lonnet::logthis("Unlocking a key ".
- &check_queue_unlock($queue,$gradingkey,1));
- return (undef,'unlock');
- } elsif ($env{'form.action'} eq 'select') {
- if (&lock_key($queue,$gradingkey)) {
+ && !defined($env{'form.gradingaction'})
+ && $env{'form.queuemode'} eq 'selected') {
+
+ my $who=&queue_key_locked($queue,$gradingkey);
+ my $me=$env{'user.name'}.'@'.$env{'user.domain'};
+ if ($who eq $me) {
+ &Apache::lonxml::debug("Found a key was given to me");
+ return ($gradingkey,'selected');
+ } else {
+ return (undef,'show_list');
+ }
+
+ }
+
+ if ($target eq 'webgrade' && $env{'form.queuemode'} eq 'selected') {
+ if ($env{'form.gradingaction'} eq 'resume') {
+ delete($env{'form.gradingaction'});
+ &Apache::lonxml::debug("Resuming a key");
return ($gradingkey);
+ } elsif ($env{'form.gradingaction'} eq 'unlock') {
+ &Apache::lonxml::debug("Unlocking a key ".
+ &check_queue_unlock($queue,$gradingkey,1));
+ return (undef,'unlock');
+ } elsif ($env{'form.gradingaction'} eq 'select') {
+ &Apache::lonxml::debug("Locking a key");
+ if (&lock_key($queue,$gradingkey)) {
+ &Apache::lonxml::debug("Success $queue");
+ return ($gradingkey);
+ }
+ &Apache::lonxml::debug("Failed $queue");
+ return (undef,'lock_failed');
}
- return (undef,'lock_failed');
}
- # don't get something new from the queue if they hit the stop button
- if (!($env{'form.stop'} && $target eq 'webgrade')) {
- return (&get_from_queue($queue));
- } else {
- return (undef,'stop');
+
+ if ($env{'form.queuemode'} ne 'selected') {
+ # don't get something new from the queue if they hit the stop button
+ if (!($env{'form.stop'} && $target eq 'webgrade')
+ && !$env{'form.gradingaction'}) {
+ &Apache::lonxml::debug("Getting anew $queue");
+ return (&get_from_queue($queue));
+ } else {
+ return (undef,'stop');
+ }
}
+ return (undef,undef)
}
sub end_Task {
@@ -442,12 +531,21 @@ sub end_Task {
$env{'user.name'}.'@'.$env{'user.domain'};
if ($review) {
$Apache::lonhomework::results{"resource.$version.status"}='review';
- # FIXME won't work well when already in review queues
- &move_between_queues('gradingqueue','reviewqueue');
+ if ($env{'form.queue'} eq 'reviewqueue') {
+ &check_queue_unlock($env{'form.queue'});
+ &Apache::lonxml::debug(" still needs review not changing status.");
+ } else {
+ &move_between_queues('gradingqueue','reviewqueue');
+ }
} elsif ($ungraded) {
$Apache::lonhomework::results{"resource.$version.status"}='ungraded';
# FIXME if in review queue need to move back to grading queue
- &check_queue_unlock($env{'form.queue'});
+ if ($env{'form.queue'} eq 'reviewqueue') {
+ &Apache::lonxml::debug("moving back.");
+ &move_between_queues('reviewqueue','gradingqueue');
+ } else {
+ &check_queue_unlock($env{'form.queue'});
+ }
} elsif ($mandatory_failed) {
$Apache::lonhomework::results{"resource.$version.status"}='fail';
$Apache::lonhomework::results{"resource.$version.0.solved"}='incorrect_by_override';
@@ -518,7 +616,7 @@ sub check_queue_unlock {
if ($who eq $me) {
return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
} elsif ($allow_not_me) {
- &Apache::lonnet::logthis("unlocking $who by $me");
+ &Apache::lonxml::debug("unlocking $who by $me");
return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
}
return 'not_owner';
@@ -578,9 +676,9 @@ sub show_queue {
my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
my ($tmp)=%queue;
if ($tmp=~/^error: 2 /) {
- return "\n
Current Queue
Empty
";
+ return "\n
Current Queue - $queue
Empty
";
}
- $result.="\n
Current Queue
";
+ $result.="\n
Current Queue - $queue
";
if ($with_selects) { $result.="
"; }
$result.="
resource
user
type
data
";
foreach my $key (sort(keys(%queue))) {
@@ -599,6 +697,8 @@ sub show_queue {
my ($symb,$uname,$udom) = &decode_queue_key($key);
my $title=&Apache::lonnet::gettitle($symb);
$result.="
";
+ my $slot=$queue{$key}->[0];
+ my %slot_data=&Apache::lonnet::get_slot($slot);
if ($with_selects) {
my $ekey=&Apache::lonnet::escape($key);
my ($action,$description)=('select',&mt('Select'));
@@ -610,21 +710,25 @@ sub show_queue {
($action,$description)=('unlock',&mt('Unlock'));
}
}
- $result.=(<
FORM
+
+ } else {
+ $result.='
'.&mt("In Progress").'
'
+ }
}
$result.="
$title
$uname
";
- my $slot=$queue{$key}->[0];
- my %slot_data=&Apache::lonnet::get_slot($slot);
$result.='
queue entry
Slot: '.$slot.' End time: '.
&Apache::lonlocal::locallocaltime($slot_data{'endtime'}).
"
";
@@ -634,6 +738,37 @@ FORM
return $result;
}
+sub get_queue_counts {
+ my ($queue)=@_;
+ my $result;
+ my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
+ my $cnum=$env{'course.'.$cid.'.num'};
+ my $cdom=$env{'course.'.$cid.'.domain'};
+ my $regexp="^$symb\0";
+ my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
+ my ($tmp)=%queue;
+ if ($tmp=~/^error: 2 /) {
+ return (0,0,0);
+ }
+ my ($entries,$ready_to_grade,$locks)=(0,0,0);
+ foreach my $key (sort(keys(%queue))) {
+ if ($key=~/locked$/) {
+ $locks++;
+ } elsif ($key=~/timestamp$/) {
+ #ignore
+ } elsif ($key!~/(timestamp|locked)$/) {
+ my ($symb,$uname,$udom) = &decode_queue_key($key);
+ $entries++;
+ my $slot=$queue{$key}->[0];
+ my %slot_data=&Apache::lonnet::get_slot($slot);
+ if (time > $slot_data{'endtime'}) {
+ $ready_to_grade++;
+ }
+ }
+ }
+ return ($entries,$ready_to_grade,$locks);
+}
+
sub decode_queue_key {
my ($key)=@_;
my ($symb,undef,$user) = split("\0",$key);
@@ -643,6 +778,11 @@ sub decode_queue_key {
sub queue_key_locked {
my ($queue,$key,$cdom,$cnum)=@_;
+ if (!defined($cdom) || !defined($cnum)) {
+ my (undef,$cid)=&Apache::lonxml::whichuser();
+ $cnum=$env{'course.'.$cid.'.num'};
+ $cdom=$env{'course.'.$cid.'.domain'};
+ }
my ($key_locked,$value)=
&Apache::lonnet::get($queue,["$key\0locked"],$cdom,$cnum);
if ($key_locked eq "$key\0locked") {
@@ -658,18 +798,18 @@ sub pick_from_queue_data {
if ($check_section) {
my $section=&Apache::lonnet::getsection($uname,$udom);
if ($section eq $check_section) {
- &Apache::lonnet::logthis("my sec");
+ &Apache::lonxml::debug("my sec");
next;
}
}
my $slot=$queuedata->{$key}[0];
my %slot_data=&Apache::lonnet::get_slot($slot);
if ($slot_data{'endtime'} > time) {
- &Apache::lonnet::logthis("not time");
+ &Apache::lonxml::debug("not time");
next;
}
if (&queue_key_locked($queue,$key,$cdom,$cnum)) {
- &Apache::lonnet::logthis("someone already has um.");
+ &Apache::lonxml::debug("someone already has um.");
next;
}
return $key;
@@ -706,7 +846,7 @@ sub lock_key {
my $cdom=$env{'course.'.$cid.'.domain'};
my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
$cdom,$cnum);
- &Apache::lonnet::logthis("success $success $todo");
+ &Apache::lonxml::debug("success $success $todo");
if ($success eq 'ok') {
return 1;
}
@@ -720,39 +860,40 @@ sub get_from_queue {
my $cnum=$env{'course.'.$cid.'.num'};
my $cdom=$env{'course.'.$cid.'.domain'};
my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
- &Apache::lonnet::logthis("found ".join(':',&decode_queue_key($todo)));
+ &Apache::lonxml::debug("found ".join(':',&decode_queue_key($todo)));
if ($todo) { return $todo; }
while (1) {
my $starttime=time;
&Apache::lonnet::put($queue,{"$symb\0timestamp"=>$starttime},
$cdom,$cnum);
- &Apache::lonnet::logthis("$starttime");
+ &Apache::lonxml::debug("$starttime");
my $regexp="^$symb\0queue\0";
my %queue=&Apache::lonnet::dump($queue,$cdom,$cnum,$regexp);
- #make a pass looking for a user in my section
+ #make a pass looking for a user _not_ in my section
if ($env{'request.course.sec'}) {
- &Apache::lonnet::logthis("sce");
+ &Apache::lonxml::debug("sce");
$todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
\%queue,$cdom,$cnum);
- &Apache::lonnet::logthis("sce $todo");
+ &Apache::lonxml::debug("sce $todo");
}
- # no one in our section so look for any user that is ready for grading
+ # no one _not_ in our section so look for any user that is
+ # ready for grading
if (!$todo) {
- &Apache::lonnet::logthis("no sce");
+ &Apache::lonxml::debug("no sce");
$todo=&pick_from_queue_data($queue,$env{'request.course.sec'},
\%queue,$cdom,$cnum);
- &Apache::lonnet::logthis("no sce $todo");
+ &Apache::lonxml::debug("no sce $todo");
}
# no user to grade
if (!$todo) { last; }
- &Apache::lonnet::logthis("got $todo");
+ &Apache::lonxml::debug("got $todo");
# otherwise found someone so lets try to lock them
# unless someone else already picked them
if (!&lock_key($queue,$todo)) { next; }
my (undef,$endtime)=
&Apache::lonnet::get($queue,["$symb\0timestamp"],
$cdom,$cnum);
- &Apache::lonnet::logthis("emd $endtime");
+ &Apache::lonxml::debug("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
@@ -761,16 +902,16 @@ sub get_from_queue {
my ($key,$value)=
&Apache::lonnet::get($queue,["$todo"],
$cdom,$cnum);
- &Apache::lonnet::logthis("check $key .. $value");
+ &Apache::lonxml::debug("check $key .. $value");
if ($key eq $todo && ref($value)) {
} else {
&Apache::lonnet::del($queue,["$todo\0locked"],
$cdom,$cnum);
- &Apache::lonnet::logthis("del");
+ &Apache::lonxml::debug("del");
next;
}
}
- &Apache::lonnet::logthis("last $todo");
+ &Apache::lonxml::debug("last $todo");
last;
}
return $todo;