--- loncom/homework/grades.pm 2002/06/26 21:25:31 1.32
+++ loncom/homework/grades.pm 2002/07/18 21:27:57 1.39
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.32 2002/06/26 21:25:31 ng Exp $
+# $Id: grades.pm,v 1.39 2002/07/18 21:27:57 ng Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -30,7 +30,7 @@
# 7/26 H.K. Ng
# 8/20 Gerd Kortemeyer
# Year 2002
-# June 2002 H.K. Ng
+# June, July 2002 H.K. Ng
#
package Apache::grades;
@@ -40,7 +40,9 @@ use Apache::lonxml;
use Apache::lonnet;
use Apache::loncommon;
use Apache::lonhomework;
+use Apache::lonmsg qw(:user_normal_msg);
use Apache::Constants qw(:common);
+#use Time::HiRes qw( gettimeofday tv_interval );
sub moreinfo {
my ($request,$reason) = @_;
@@ -53,6 +55,7 @@ sub moreinfo {
if ($ENV{'form.symb'}) {
$request->print(''."\n");
}
+# $request->print(''."\n");
$request->print(''."\n");
$request->print("Student:".''." \n");
$request->print("Domain:".''." \n");
@@ -65,8 +68,8 @@ sub moreinfo {
sub verifyreceipt {
my $request=shift;
my $courseid=$ENV{'request.course.id'};
- my $cdom=$ENV{"course.$courseid.domain"};
- my $cnum=$ENV{"course.$courseid.num"};
+# my $cdom=$ENV{"course.$courseid.domain"};
+# my $cnum=$ENV{"course.$courseid.num"};
my $receipt=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
$ENV{'form.receipt'};
$receipt=~s/[^\-\d]//g;
@@ -77,8 +80,8 @@ sub verifyreceipt {
if ((&Apache::lonnet::allowed('mgr',$courseid)) && ($symb)) {
$request->print('
Verifying Submission Receipt '.$receipt.'
');
my $matches=0;
- my (%classlist) = &getclasslist($cdom,$cnum,'0');
- foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
+ my ($classlist) = &getclasslist('all','0');
+ foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
my ($uname,$udom)=split(/\:/,$student);
if ($receipt eq
&Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
@@ -87,129 +90,175 @@ sub verifyreceipt {
}
}
$request->printf('
'.$matches." match%s
",$matches <= 1 ? '' : 'es');
+# needs to print who is matched
}
return '';
}
-sub receiptInput {
- my ($request) = shift;
- my $cdom=$ENV{"course.$ENV{'request.course.id'}.domain"};
- my $cnum=$ENV{"course.$ENV{'request.course.id'}.num"};
- my $hostver=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'});
- $request->print(<Verify a Submission Receipt Issued by this Server
-');
- return '';
-}
-
sub student_gradeStatus {
- my ($url,$udom,$uname) = @_;
- my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
- my %record= &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
- foreach my $part (&getpartlist($url)) {
- my ($temp,$part,$type)=split(/_/,$part);
- if ($type eq 'solved') {
- my ($status,$foo)=split(/_/,$record{"resource.$part.$type"},2);
+ my ($url,$udom,$uname,$partlist) = @_;
+ my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
+ my %record= &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$udom,$uname);
+ my %partstatus = ();
+ foreach (@$partlist) {
+ my ($status,$foo)=split(/_/,$record{"resource.$_.solved"},2);
$status = 'nothing' if ($status eq '');
- return $type,$status;
+ $partstatus{$_} = $status;
+ }
+ return %partstatus;
+}
+
+sub get_fullname {
+ my ($uname,$udom) = @_;
+ my %name=&Apache::lonnet::get('environment', ['lastname','generation',
+ 'firstname','middlename'],
+ $udom,$uname);
+ my $fullname;
+ my ($tmp) = keys(%name);
+ if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
+ $fullname=$name{'lastname'}.$name{'generation'};
+ if ($fullname =~ /[^\s]+/) { $fullname.=', '; }
+ $fullname.=$name{'firstname'}.' '.$name{'middlename'};
}
- }
- return '';
+ return $fullname;
+}
+
+sub response_type {
+ my ($url) = shift;
+ my $allkeys = &Apache::lonnet::metadata($url,'keys');
+ my %seen = ();
+ my (@partlist,%handgrade);
+ foreach (split(/,/,&Apache::lonnet::metadata($url,'packages'))) {
+ if (/^\w+response_\d{1,2}.*/) {
+ my ($responsetype,$part) = split(/_/,$_,2);
+ my ($partid,$respid) = split(/_/,$part);
+ $handgrade{$part} = $responsetype.':'.($allkeys =~ /parameter_$part\_handgrade/ ? 'yes' : 'no');
+ next if ($seen{$partid} > 0);
+ $seen{$partid}++;
+ push @partlist,$partid;
+ }
+ }
+ return \@partlist,\%handgrade;
}
+
sub listStudents {
my ($request) = shift;
- my $cdom=$ENV{"course.$ENV{'request.course.id'}.domain"};
- my $cnum=$ENV{"course.$ENV{'request.course.id'}.num"};
+ my $cdom =$ENV{"course.$ENV{'request.course.id'}.domain"};
+ my $cnum =$ENV{"course.$ENV{'request.course.id'}.num"};
+ my $getsec =$ENV{'form.section'};
+ my $submitonly=$ENV{'form.submitonly'};
+
+ my $result='
View Submissions for a Student or a Group of Students
';
+ $result.='
';
+ $result.='
Resource: '.$ENV{'form.url'}.'
';
+ my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
+ for (sort keys(%$handgrade)) {
+ my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
+ $result.='
Part id: '.$_.'
'.
+ '
Type: '.$responsetype.'
'.
+ '
Handgrade: '.$handgrade.'
';
+ }
+ $result.='
';
+ $request->print($result);
$request->print(<Show Student Submissions on Assessment
-
-
-
-
Resource: $ENV{'form.url'}
-
Username
Name
Domain
-
View Problem
Submissions
-
Grade Status
Action
+
');
+}
+
+sub processGroup {
+ my ($request) = shift;
+ my $ctr = 0;
+ my @stuchecked = (ref($ENV{'form.stuinfo'}) ? @{$ENV{'form.stuinfo'}}
+ : ($ENV{'form.stuinfo'}));
+ my $total = scalar(@stuchecked)-1;
+ if ($stuchecked[0] eq '') {
+ &userError($request,'No student was selected for viewing/grading.');
+ return;
+ }
+ foreach (@stuchecked) {
+ my ($uname,$udom,$fullname) = split(/:/);
+ $ENV{'form.student'} = $uname;
+ $ENV{'form.fullname'} = $fullname;
+ &submission($request,$ctr,$total);
+ $ctr++;
+ }
+ return '';
}
+sub userError {
+ my ($request, $reason, $step) = @_;
+ $request->print('
LON-CAPA User Error
'."\n");
+ $request->print('Reason: '.$reason.'
'."\n");
+ $request->print('Step: '.($step ne '' ? $step : 'Use your browser back button to correct')
+ .'
'."\n");
+ return '';
+}
#FIXME - needs to handle multiple matches
sub finduser {
my ($name) = @_;
my $domain = '';
-
if ( $Apache::grades::viewgrades eq 'F' ) {
- #get classlist
- my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
- #print "Found $cdom:$cnum ";
- my (%classlist) = &getclasslist($cdom,$cnum,'0');
- foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
- my ($posname,$posdomain) = split(/:/,$student);
+ my ($classlist) = &getclasslist('all','0');
+ foreach ( sort(@{ $$classlist{'all'} }) ) {
+ my ($posname,$posdomain) = split(/:/);
if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; }
}
return ($name,$domain);
@@ -219,20 +268,32 @@ sub finduser {
}
sub getclasslist {
- my ($coursedomain,$coursenum,$hideexpired) = @_;
- my %classlist=&Apache::lonnet::dump('classlist',$coursedomain,$coursenum);
- my $now = time;
- foreach my $student (keys(%classlist)) {
- my ($end,$start)=split(/:/,$classlist{$student});
- # still a student?
- if (($hideexpired) && ($end) && ($end < $now)) {
- #print "Skipping:$name:$end:$now \n";
- next;
- }
- #print "record=$record ";
- push( @{ $classlist{'allids'} }, $student);
- }
- return (%classlist);
+ my ($getsec,$hideexpired) = @_;
+ my %classlist=&Apache::lonnet::dump('classlist',
+ $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+ $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ my $now = time;
+ my (@holdsec,@sections,%allids,%stusec,%fullname);
+ foreach (keys(%classlist)) {
+ my ($end,$start,$id,$section,$fullname)=split(/:/,$classlist{$_});
+ # still a student?
+ if (($hideexpired) && ($end) && ($end < $now)) {
+ next;
+ }
+ $section = ($section ne '' ? $section : 'no');
+ push @holdsec,$section;
+ if ($getsec eq 'all' || $getsec eq $section) {
+ push (@{ $classlist{$getsec} }, $_);
+ $allids{$_}=$id;
+ $stusec{$_}=$section;
+ $fullname{$_}=$fullname;
+ }
+ }
+ my %seen = ();
+ foreach my $item (@holdsec) {
+ push (@sections, $item) unless $seen{$item}++;
+ }
+ return (\%classlist,\@sections,\%allids,\%stusec,\%fullname);
}
sub getpartlist {
@@ -249,19 +310,13 @@ sub getpartlist {
sub viewstudentgrade {
my ($url,$symb,$courseid,$student,@parts) = @_;
- my $result ='';
my $cellclr = '"#ffffdd"';
my ($username,$domain) = split(/:/,$student);
- my (@requests) = ('lastname','firstname','middlename','generation');
- my (%name) = &Apache::lonnet::get('environment',\@requests,$domain,$username);
+ my $fullname = &get_fullname($username,$domain);
my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$username);
- my $fullname=$name{'lastname'}.$name{'generation'};
- if ($fullname =~ /[^\s]+/) { $fullname.=', '; }
- $fullname.=$name{'firstname'}.' '.$name{'middlename'};
-
- $result.="
$username
$fullname
$domain
\n";
+ my $result="
$username
$fullname
$domain
\n";
foreach my $part (@parts) {
my ($temp,$part,$type)=split(/_/,$part);
my $score=$record{"resource.$part.$type"};
@@ -272,14 +327,14 @@ sub viewstudentgrade {
my ($status,$foo)=split(/_/,$score,2);
$result.="
\n";
}
}
- $result.='
';
+ $result.='';
return $result;
}
@@ -287,7 +342,7 @@ sub viewstudentgrade {
#interface based on that, also do that to above function.
sub setstudentgrade {
my ($url,$symb,$courseid,$student,@parts) = @_;
-
+ print "set student grade parts=@parts ";
my $result ='';
my ($stuname,$domain) = split(/:/,$student);
my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname);
@@ -308,10 +363,11 @@ sub setstudentgrade {
} elsif ($oldscore !~ m/^$newscore/) {
$update=1;
$result.="Updating $stuname to $newscore \n";
- if ($newscore eq 'correct') { $newscore = 'correct_by_override'; }
+ if ($newscore eq 'correct') { $newscore = 'correct_by_override'; }
if ($newscore eq 'incorrect') { $newscore = 'incorrect_by_override'; }
- if ($newscore eq 'excused') { $newscore = 'excused'; }
- if ($newscore eq 'ungraded') { $newscore = 'ungraded_attempted'; }
+ if ($newscore eq 'excused') { $newscore = 'excused'; }
+ if ($newscore eq 'ungraded') { $newscore = 'ungraded_attempted'; }
+# if ($newscore eq 'partial') { $newscore = 'correct_partially_by_override'; }
} else {
#$result.="$stuname:$part:$type:unchanged $oldscore to $newscore: \n";
}
@@ -327,181 +383,467 @@ sub setstudentgrade {
}
if ( scalar(keys(%newrecord)) > 0 ) {
$newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
- print "grader=$newrecord{'resource.regrader'}: records ";
- while (my ($k,$v) = each %newrecord) {
- print "k=$k:v=$v: \n";
- }
- &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$stuname);
+# &Apache::lonnet::cstore(\%newrecord,$symb,$courseid,$domain,$stuname);
$result.="Stored away ".scalar(keys(%newrecord))." elements. \n";
}
return $result;
}
-# --------------------------- show submissions of a student, option to grade --------
#
+# --------------------------- show submissions of a student, option to grade --------
sub submission {
- my ($request) = @_;
- $request->print(<
- function updateRadio() {
- var pts = document.SCORE.GRADE_BOX.value;
- var radioButton = document.SCORE.radval;
- var checked =true;
- var unchecked=false;
- var resetbox =false;
- if (isNaN(pts) || pts < 0) {
- alert("A number equal or greater than 0 is expected. Entered value = "+pts);
- for (var i=0; i
-JAVASCRIPT
- my $url=$ENV{'form.url'};
- $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
- if ($ENV{'form.student'} eq '') { &moreinfo($request,"Need student login id"); return ''; }
+ (my $url=$ENV{'form.url'})=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
+ if ($ENV{'form.student'} eq '') { &moreinfo($request,'Need student login id'); return ''; }
my ($uname,$udom) = &finduser($ENV{'form.student'});
- if ($uname eq '') { &moreinfo($request,"Unable to find student"); return ''; }
+ if ($uname eq '') { &moreinfo($request,'Unable to find student'); return ''; }
my $symb=($ENV{'form.symb'} ne '' ? $ENV{'form.symb'} : (&Apache::lonnet::symbread($url)));
if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
-#
-# header info
- my $result='
Submission Record
';
- $result.='
Username: '.$uname.'
Fullname: '.$ENV{'form.fullname'}.'
Domain: '.$udom.'
';
- $result.='
Resource: '.$url.'
';
-#
-# option to display problem
- if ($ENV{'form.vProb'} eq 'yes') {
- my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
- $ENV{'request.course.id'});
- my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
- $ENV{'request.course.id'});
- $result.='
'.
+ ' Resource: '.$url.'');
+
+ # option to display problem, only once else it cause problems with the form later
+ # since the problem has a form.
+ if ($ENV{'form.vProb'} eq 'yes') {
+ my $rendered=&Apache::loncommon::get_student_view($symb,$uname,$udom,
+ $ENV{'request.course.id'});
+ my $companswer=&Apache::loncommon::get_student_answers($symb,$uname,$udom,
+ $ENV{'request.course.id'});
+ my $result.='
'."\n";
return $result;
@@ -559,9 +1034,9 @@ sub viewgrades {
#get classlist
my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
#print "Found $cdom:$cnum ";
- my (%classlist) = &getclasslist($cdom,$cnum,'0');
- my $headerclr = '"#ccffff"';
- my $cellclr = '"#ffffcc"';
+ my ($classlist) = &getclasslist('all','0');
+ my $headerclr = '"#ddffff"';
+ my $cellclr = '"#ffffdd"';
#get list of parts for this problem
my (@parts) = sort(&getpartlist($url));
@@ -576,17 +1051,16 @@ sub viewgrades {
''."\n".
'
'."\n".
'
'."\n".
- '
Username
Name
Domain
'."\n";
+ '
Username
Fullname
Domain
'."\n";
foreach my $part (@parts) {
my $display=&Apache::lonnet::metadata($url,$part.'.display');
if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
- print "Manual grading:$url:$part:$display: ";
$result.='
'.$display.'
'."\n";
}
$result.='
';
#get info for each student
- foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
- my $display=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
+ foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
+# my $display=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
# print "ID=$ENV{'request.course.id'}:STU=$student:DIS=$display: \n";
$result.=&viewstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
}
@@ -604,9 +1078,9 @@ sub editgrades {
if ($symb eq '') { $request->print("Unable to handle ambiguous references:$symb:$ENV{'form.url'}"); return ''; }
my $url=$ENV{'form.url'};
#get classlist
- my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
+# my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
#print "Found $cdom:$cnum ";
- my (%classlist) = &getclasslist($cdom,$cnum,'0');
+ my ($classlist) = &getclasslist('all','0');
#get list of parts for this problem
my (@parts) = &getpartlist($url);
@@ -617,7 +1091,7 @@ sub editgrades {
''."\n".
' '."\n";
- foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
+ foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
$result.=&setstudentgrade($url,$symb,$ENV{'request.course.id'},$student,@parts);
}
@@ -625,23 +1099,301 @@ sub editgrades {
return $result;
}
-sub csvupload {
- my ($request)= @_;
- my $result;
- my ($symb,$url)=&get_symb_and_url($request);
- if (!$symb) {return '';}
- my $upfile_select=&Apache::loncommon::upfile_select_html();
- $result.=<
-
-
-
-
-
Specify a file containing the class grades for resource $url
-$upfile_select
-
-ENDUPFORM
- return $result;
+sub sub_page_js {
+ my $request = shift;
+ $request->print(<
+ function updateRadio(radioButton,formtextbox,formsel,scores) {
+ var pts = formtextbox.value;
+ var resetbox =false;
+ if (isNaN(pts) || pts < 0) {
+ alert("A number equal or greater than 0 is expected. Entered value = "+pts);
+ for (var i=0; i"+msgchk);
+ re = /msgsub/;
+ var shwsel = "";
+ if (re.test(msgchk)) { shwsel = "checked" }
+ displaySubject(subject,shwsel);
+ for (var i=1; i<=Nmsg; i++) {
+ var testpt = "savemsg"+i+",";
+ re = /testpt/;
+ shwsel = "";
+ if (re.test(msgchk)) { shwsel = "checked" }
+ var message = eval("document.SCORE.savemsg"+i+".value");
+ displaySavedMsg(i,message,shwsel);
+ }
+ newmsg = eval("document.SCORE.newmsg"+usrctr+".value");
+ shwsel = "";
+ re = /newmsg/;
+ if (re.test(msgchk)) { shwsel = "checked" }
+ newMsg(newmsg,shwsel);
+ msgTail();
+ return;
+ }
+
+ function savedMsgHeader(Nmsg,usrctr,fullname) {
+ var height = 30*Nmsg+250;
+ var scrollbar = "no";
+ if (height > 600) {
+ height = 600;
+ scrollbar = "yes";
+ }
+/* if (window.pWin)
+ window.pWin.close(); */
+ pWin = window.open('', 'MessageCenter', 'toolbar=no,location=no,scrollbars='+scrollbar+',screenx=70,screeny=75,width=600,height='+height);
+ pWin.document.write("");
+ pWin.document.write("Message Central");
+
+ pWin.document.write("
+SUBJAVASCRIPT
}
sub csvupload_javascript_reverse_associate {
@@ -836,16 +1588,16 @@ sub csvuploadassign {
}
$request->print('
Assigning Grades
');
my $courseid=$ENV{'request.course.id'};
- my $cdom=$ENV{"course.$courseid.domain"};
- my $cnum=$ENV{"course.$courseid.num"};
- my (%classlist) = &getclasslist($cdom,$cnum,'1');
+# my $cdom=$ENV{"course.$courseid.domain"};
+# my $cnum=$ENV{"course.$courseid.num"};
+ my ($classlist) = &getclasslist('all','1');
my @skipped;
my $countdone=0;
foreach my $grade (@gradedata) {
my %entries=&Apache::loncommon::record_sep($grade);
my $username=$entries{$fields{'username'}};
my $domain=$entries{$fields{'domain'}};
- if (!exists($classlist{"$username:$domain"})) {
+ if (!exists($$classlist{"$username:$domain"})) {
push(@skipped,"$username:$domain");
next;
}
@@ -944,21 +1696,27 @@ sub handler {
$Apache::grades::viewgrades=&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'});
if ($command eq 'submission') {
&listStudents($request) if ($ENV{'form.student'} eq '');
- $request->print(&submission($request)) if ($ENV{'form.student'} ne '');
+ &submission($request,0,0) if ($ENV{'form.student'} ne '');
+ } elsif ($command eq 'processGroup') {
+ &processGroup($request);
} elsif ($command eq 'gradingmenu') {
$request->print(&gradingmenu($request));
} elsif ($command eq 'viewgrades') {
$request->print(&viewgrades($request));
+ } elsif ($command eq 'handgrade') {
+ $request->print(&processHandGrade($request));
} elsif ($command eq 'editgrades') {
$request->print(&editgrades($request));
} elsif ($command eq 'verify') {
$request->print(&verifyreceipt($request));
} elsif ($command eq 'csvupload') {
$request->print(&csvupload($request));
+ } elsif ($command eq 'viewclasslist') {
+ $request->print(&viewclasslist($request));
} elsif ($command eq 'csvuploadmap') {
$request->print(&csvuploadmap($request));
- } elsif ($command eq 'receiptInput') {
- &receiptInput($request);
+# } elsif ($command eq 'receiptInput') {
+# &receiptInput($request);
} elsif ($command eq 'csvuploadassign') {
if ($ENV{'form.associate'} ne 'Reverse Association') {
$request->print(&csvuploadassign($request));