[LON-CAPA-cvs] cvs: loncom /homework bridgetask.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Fri, 27 May 2005 17:08:08 -0000
This is a MIME encoded message
--albertel1117213688
Content-Type: text/plain
albertel Fri May 27 13:08:08 2005 EDT
Modified files:
/loncom/homework bridgetask.pm
Log:
- first pass at a review queue
- review grading goes to the review queue
- can select a record from the review queue
- can resume grading a user from the review queue
--albertel1117213688
Content-Type: text/plain
Content-Disposition: attachment; filename="albertel-20050527130808.txt"
Index: loncom/homework/bridgetask.pm
diff -u loncom/homework/bridgetask.pm:1.31 loncom/homework/bridgetask.pm:1.32
--- loncom/homework/bridgetask.pm:1.31 Tue May 24 18:06:39 2005
+++ loncom/homework/bridgetask.pm Fri May 27 13:08:03 2005
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# definition of tags that give a structure to a document
#
-# $Id: bridgetask.pm,v 1.31 2005/05/24 22:06:39 albertel Exp $
+# $Id: bridgetask.pm,v 1.32 2005/05/27 17:08:03 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -144,6 +144,12 @@
my $result=' <input type="submit" name="gradeasubmission" value="'.
&mt("Get a submission to grade").'" />';
$result.='<input type="hidden" name="grade_target" value="webgrade" />';
+ if ( 1) {
+ #need a permissions for limitng this to 'powerful users'
+ #check if review queue has items
+ $result.=' <input type="submit" name="reviewasubmission" value="'.
+ &mt("Select an entry from the review queue").'" />';
+ }
return $result;
}
@@ -266,42 +272,56 @@
}
} elsif ( ($target eq 'grade' && $env{'form.webgrade'}) ||
$target eq 'webgrade') {
+ my $webgrade='yes';
if ($target eq 'webgrade') {
- $result.=$head_tag_start.$body_tag_start.$form_tag_start;
- $result.='<input type="hidden" name="webgrade" value="yes" />';
+ #FIXME FORM conflcit with the 'show queue',1
+ $result.=$head_tag_start.$body_tag_start;
$result.='<br />Review'.&show_queue('reviewqueue');
$result.='<br />Before'.&show_queue('gradingqueue');
}
- my $todo;
- # don't get something new from the queue if they hit the stop button
- if (!($env{'form.stop'} && $target eq 'webgrade')) {
- $todo=&get_from_queue('gradingqueue');
- }
- if ($todo) {
- &setup_env_for_other_user($todo,$safeeval);
- my ($symb,$uname,$udom)=&decode_queue_key($todo);
- $result.="\n".'<table><tr><td>Found '.
- &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
- $result.='<input type="hidden" name="gradingkey" value="'.
- &Apache::lonnet::escape($todo).'" />';
- $Apache::bridgetask::queue_key=$todo;
- &Apache::structuretags::initialize_storage();
- &Apache::lonhomework::showhash(%Apache::lonhomework::history);
- if ($target eq 'webgrade') {
- $result.='<br />After'.&show_queue('gradingqueue');
- $result.="\n".'<table width="100%" style="width:100%" border="1">';
- }
+ if (defined($env{'form.reviewasubmission'})) {
+ $result.=&show_queue('reviewqueue',1);
+ my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
} else {
- if ($target eq 'webgrade') {
- $result.="\n".'<table><tr><td><b>';
- if ($env{'form.stop'}) {
- $result.=&mt("Stopped grading.");
- } else {
- $result.=&mt("No user to be graded.");
+ 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".'<table><tr><td>Found '.
+ &Apache::lonnet::gettitle($symb).' for '.$uname.' at '.$udom.'</td></tr></table>';
+ $result.='<input type="hidden" name="gradingkey" value="'.
+ &Apache::lonnet::escape($todo).'" />';
+ $Apache::bridgetask::queue_key=$todo;
+ &Apache::structuretags::initialize_storage();
+ &Apache::lonhomework::showhash(%Apache::lonhomework::history);
+ if ($target eq 'webgrade') {
+ $result.='<br />After'.&show_queue('gradingqueue');
+ $result.="\n".'<table width="100%" style="width:100%" border="1">';
}
- $result.='</b></td></tr></table>';
+ } else {
+ if ($target eq 'webgrade') {
+ $result.="\n".'<table><tr><td><b>';
+ 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.='</b></td></tr></table>';
+ }
+ $webgrade='no';
+ my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
}
- my $bodytext=&Apache::lonxml::get_all_text("/task",$parser);
+ }
+ if ($target eq 'webgrade' && defined($env{'form.queue'})) {
+ $result.=$form_tag_start;
+ $result.='<input type="hidden" name="webgrade" value="'.
+ $webgrade.'" />';
+ $result.='<input type="hidden" name="queue" value="'.
+ $env{'form.queue'}.'" />';
}
} else {
# page_start returned a starting result, delete it if we don't need it
@@ -310,6 +330,41 @@
return $result;
}
+sub get_key_todo {
+ my ($target)=@_;
+ my $todo;
+ 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)) {
+ return ($gradingkey);
+ }
+ 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');
+ }
+}
+
sub end_Task {
my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
my $result='';
@@ -355,7 +410,7 @@
&add_to_queue('gradingqueue',$Apache::inputtags::slot_name);
}
}
- if ($target eq 'grade' && $env{'form.webgrade'}) {
+ if ($target eq 'grade' && $env{'form.webgrade'} eq 'yes') {
my $optional_required=
&Apache::lonxml::get_param('OptionalRequired',$parstack,
$safeeval);
@@ -387,22 +442,24 @@
$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');
} elsif ($ungraded) {
$Apache::lonhomework::results{"resource.$version.status"}='ungraded';
- &check_queue_unlock('gradingqueue');
+ # FIXME if in review queue need to move back to grading queue
+ &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';
$Apache::lonhomework::results{"resource.$version.0.award"}='INCORRECT';
$Apache::lonhomework::results{"resource.$version.0.awarded"}='0';
- &remove_from_queue('gradingqueue');
+ &remove_from_queue($env{'form.queue'});
} else {
$Apache::lonhomework::results{"resource.$version.status"}='pass';
$Apache::lonhomework::results{"resource.$version.0.solved"}='correct_by_override';
$Apache::lonhomework::results{"resource.$version.0.award"}='EXACT_ANS';
$Apache::lonhomework::results{"resource.$version.0.awarded"}='1';
- &remove_from_queue('grading_queue');
+ &remove_from_queue($env{'form.queue'});
}
$Apache::lonhomework::results{"resource.status"}=
$Apache::lonhomework::results{"resource.$version.status"};
@@ -449,16 +506,22 @@
}
sub check_queue_unlock {
- my ($queue)=@_;
+ my ($queue,$key,$allow_not_me)=@_;
my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
+ if (!defined($key)) {
+ $key="$symb\0queue\0$uname\@$udom";
+ }
my $cnum=$env{'course.'.$cid.'.num'};
my $cdom=$env{'course.'.$cid.'.domain'};
- my $key="$symb\0queue\0$uname\@$udom";
my $me=$env{'user.name'}.'@'.$env{'user.domain'};
my $who=&queue_key_locked($queue,$key,$cdom,$cnum);
if ($who eq $me) {
- &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
+ return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
+ } elsif ($allow_not_me) {
+ &Apache::lonnet::logthis("unlocking $who by $me");
+ return &Apache::lonnet::del($queue,["$key\0locked"],$cdom,$cnum);
}
+ return 'not_owner';
}
sub remove_from_queue {
@@ -506,7 +569,7 @@
}
sub show_queue {
- my ($queue)=@_;
+ my ($queue,$with_selects)=@_;
my $result;
my ($symb,$cid,$udom,$uname)=&Apache::lonxml::whichuser();
my $cnum=$env{'course.'.$cid.'.num'};
@@ -517,24 +580,49 @@
if ($tmp=~/^error: 2 /) {
return "\n<h3>Current Queue</h3><table border='1'><tr><td>Empty</td></tr></table>";
}
- $result.="\n<h3>Current Queue</h3><table border='1'><tr><th>resource</th>".
- "<th>user</th><th>type</th><th>data</th></tr>";
+ $result.="\n<h3>Current Queue</h3><table border='1'><tr>";
+ if ($with_selects) { $result.="<th></th>"; }
+ $result.="<th>resource</th><th>user</th><th>type</th><th>data</th></tr>";
foreach my $key (sort(keys(%queue))) {
- if ($key=~/locked$/) {
+ if ($key=~/locked$/ && !$with_selects) {
my ($symb,$uname,$udom) = &decode_queue_key($key);
my $title=&Apache::lonnet::gettitle($symb);
$result.="<tr><td>$title</td><td>$uname</td>";
$result.='<td>lock</td><td>'.$queue{$key}.'</td></tr>';
- } elsif ($key=~/timestamp$/) {
+ } elsif ($key=~/timestamp$/ && !$with_selects) {
my ($symb,undef) = split("\0",$key);
my $title=&Apache::lonnet::gettitle($symb);
$result.="<tr><td>$title</td><td></td>";
$result.='<td>last queue modification time</td><td>'.
&Apache::lonlocal::locallocaltime($queue{$key})."</td></tr>";
- } else {
+ } elsif ($key!~/(timestamp|locked)$/) {
my ($symb,$uname,$udom) = &decode_queue_key($key);
my $title=&Apache::lonnet::gettitle($symb);
- $result.="<tr><td>$title</td><td>$uname</td>";
+ $result.="<tr>";
+ if ($with_selects) {
+ my $ekey=&Apache::lonnet::escape($key);
+ my ($action,$description)=('select',&mt('Select'));
+ if (exists($queue{"$key\0locked"})) {
+ my $me=$env{'user.name'}.'@'.$env{'user.domain'};
+ if ($me eq $queue{"$key\0locked"}) {
+ ($action,$description)=('resume',&mt('Resume'));
+ } else {
+ ($action,$description)=('unlock',&mt('Unlock'));
+ }
+ }
+ $result.=(<<FORM);
+<td>
+<form method="POST">
+ <input type="hidden" name="gradingkey" value="$ekey" />
+ <input type="hidden" name="queue" value="$queue" />
+ <input type="hidden" name="gradingaction" value="$action" />
+ <input type="hidden" name="webgrade" value="no" />
+ <input type="submit" name="submit" value="$description" />
+</form>
+</td>
+FORM
+ }
+ $result.="<td>$title</td><td>$uname</td>";
my $slot=$queue{$key}->[0];
my %slot_data=&Apache::lonnet::get_slot($slot);
$result.='<td>queue entry</td><td>Slot: '.$slot.' End time: '.
@@ -610,15 +698,28 @@
return undef;
}
+sub lock_key {
+ my ($queue,$todo)=@_;
+ my $me=$env{'user.name'}.'@'.$env{'user.domain'};
+ my (undef,$cid)=&Apache::lonxml::whichuser();
+ my $cnum=$env{'course.'.$cid.'.num'};
+ my $cdom=$env{'course.'.$cid.'.domain'};
+ my $success=&Apache::lonnet::newput($queue,{"$todo\0locked"=> $me},
+ $cdom,$cnum);
+ &Apache::lonnet::logthis("success $success $todo");
+ if ($success eq 'ok') {
+ return 1;
+ }
+ return 0;
+}
+
sub get_from_queue {
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 $todo;
- # FIXME need to find if I am 'mid grading'
- $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
+ my $todo=&find_mid_grade($queue,$symb,$cdom,$cnum);
&Apache::lonnet::logthis("found ".join(':',&decode_queue_key($todo)));
if ($todo) { return $todo; }
while (1) {
@@ -646,13 +747,8 @@
if (!$todo) { last; }
&Apache::lonnet::logthis("got $todo");
# otherwise found someone so lets try to lock them
- my $success=&Apache::lonnet::newput($queue,
- {"$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; }
+ # unless someone else already picked them
+ if (!&lock_key($queue,$todo)) { next; }
my (undef,$endtime)=
&Apache::lonnet::get($queue,["$symb\0timestamp"],
$cdom,$cnum);
@@ -721,9 +817,6 @@
}
sub get_instance {
- #FIXME just grabbing the first one for now, need
- #to randomly pick one until all have been seen
- #then start repicking
&Apache::response::pushrandomnumber();
my @order=&Math::Random::random_permutation(@{$dimension{'instances'}});
my $num=@order;
--albertel1117213688--