--- loncom/homework/grades.pm 2002/07/10 21:08:38 1.38
+++ loncom/homework/grades.pm 2002/07/26 20:28:42 1.42
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.38 2002/07/10 21:08:38 ng Exp $
+# $Id: grades.pm,v 1.42 2002/07/26 20:28:42 ng Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -42,27 +42,27 @@ 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 );
+#use Time::HiRes qw( gettimeofday tv_interval );
sub moreinfo {
- my ($request,$reason) = @_;
- $request->print("Unable to process request: $reason");
- if ( $Apache::grades::viewgrades eq 'F' ) {
- $request->print('
');
- }
- return '';
+ $request->print(''."\n");
+ $request->print("Student:".''." \n");
+ $request->print("Domain:".''." \n");
+ $request->print(''." \n");
+ $request->print('');
+ }
+ return '';
}
sub verifyreceipt {
@@ -71,7 +71,7 @@ sub verifyreceipt {
# my $cdom=$ENV{"course.$courseid.domain"};
# my $cnum=$ENV{"course.$courseid.num"};
my $receipt=unpack("%32C*",$Apache::lonnet::perlvar{'lonHostID'}).'-'.
- $ENV{'form.receipt'};
+ $ENV{'form.receipt'};
$receipt=~s/[^\-\d]//g;
my $symb=$ENV{'form.symb'};
unless ($symb) {
@@ -84,9 +84,9 @@ sub verifyreceipt {
foreach my $student ( sort(@{ $$classlist{'all'} }) ) {
my ($uname,$udom)=split(/\:/,$student);
if ($receipt eq
- &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
- $request->print('Matching '.$student.' ');
- $matches++;
+ &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb)) {
+ $request->print('Matching '.$student.' ');
+ $matches++;
}
}
$request->printf('
'.$matches." match%s
",$matches <= 1 ? '' : 'es');
@@ -96,26 +96,24 @@ sub verifyreceipt {
}
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);
- $status = 'partial' if ($foo =~ /^partially/);
- $status = 'nothing' if ($status eq '');
- return $type,$status;
+ 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 '');
+ $partstatus{$_} = $status;
+ $partstatus{"resource.$_.submitted_by"} = $record{"resource.$_.submitted_by"}
+ if ($record{"resource.$_.submitted_by"} ne '');
}
- }
- return '';
+ return %partstatus;
}
sub get_fullname {
- my ($sname,$sdom) = @_;
+ my ($uname,$udom) = @_;
my %name=&Apache::lonnet::get('environment', ['lastname','generation',
- 'firstname','middlename'],
- $sdom,$sname);
+ 'firstname','middlename'],$udom,$uname);
my $fullname;
my ($tmp) = keys(%name);
if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
@@ -126,89 +124,135 @@ sub get_fullname {
return $fullname;
}
+sub response_type {
+ my ($url) = shift;
+ my $allkeys = &Apache::lonnet::metadata($url,'keys');
+# print "allkeys=>$allkeys ";
+ 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 $getsec =$ENV{'form.section'};
- my $submitonly=$ENV{'form.submitonly'};
-
- $request->print(< View Submissions for a Student or a Group of Students
- Resource: $ENV{'form.url'}
-
+ my ($request) = shift;
+ my $cdom =$ENV{"course.$ENV{'request.course.id'}.domain"};
+ my $cnum =$ENV{"course.$ENV{'request.course.id'}.num"};
+ my $getsec =$ENV{'form.section'} eq '' ? 'all' : $ENV{'form.section'};
+ my $submitonly=$ENV{'form.submitonly'} eq '' ? 'all' : $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{$_});
+ $ENV{'form.handgrade'} = 'yes' if ($handgrade eq 'yes');
+ $result.='
Part id: '.$_.'
'.
+ '
Type: '.$responsetype.'
'.
+ '
Handgrade: '.$handgrade.'
';
+ }
+ $result.='
';
+ $request->print($result);
+
+ $request->print(<View Problem: no
yes Submissions:
- last sub only
- last sub & parts info
- all details
-
-
-
-
-
-
-
Select
Username
-
Fullname
Domain
-
Grade Status
+ handgrade only
+ last sub only
+ last sub & parts info
+ all details
+
+
+
+
+
+
ENDTABLEST
- if ($ENV{'form.url'}) {
- $request->print(''."\n");
- }
- if ($ENV{'form.symb'}) {
- $request->print(''."\n");
- }
- $request->print(''."\n");
-
- my $t0=&Time::HiRes::time();
-
- my ($classlist) = &getclasslist($getsec,'0');
- my $t1=&Time::HiRes::time();
- print "getclasslist=",$t1-$t0," ";
-
- foreach my $student ( sort(@{ $$classlist{$getsec} }) ) {
- my ($sname,$sdom) = split(/:/,$student);
- my ($type,$status) = &student_gradeStatus($ENV{'form.url'},$cdom,$sname);
- next if ($status eq 'nothing' && $submitonly eq 'yes');
-
- my $fullname = &get_fullname($sname,$sdom);
- if ( $Apache::grades::viewgrades eq 'F' ) {
- $request->print("\n".'
'.
- '
'."\n".
- '
'.$sname.'
'."\n".
- '
'.$fullname.'
'."\n".
- '
'.$sdom.'
'."\n");
- $request->print('
'.$status.'
'."\n");
+ if ($ENV{'form.url'}) {
+ $request->print(''."\n");
+ }
+ if ($ENV{'form.symb'}) {
+ $request->print(''."\n");
+ }
+ $request->print(''."\n");
+
+ my ($classlist,$seclist,$ids,$stusec,$fullname) = &getclasslist($getsec,'0');
+
+ $result='
'.
+ '
'.
+ '
Select
Username
'.
+ '
Fullname
Domain
';
+ foreach (sort(@$partlist)) {
+ $result.='
Part ID '.$_.' Status
';
+ }
+ $request->print($result.'
'."\n");
+
+ foreach my $student (sort(@{ $$classlist{$getsec} }) ) {
+ my ($uname,$udom) = split(/:/,$student);
+ my (%status) = &student_gradeStatus($ENV{'form.url'},$udom,$uname,$partlist);
+ my $statusflg = '';
+ foreach (keys(%status)) {
+ $statusflg = 1 if ($status{$_} ne 'nothing');
+ my ($foo,$partid,$foo) = split(/\./,$_);
+ if ($status{'resource.'.$partid.'.submitted_by'} ne '') {
+ $statusflg = '';
+ $request->print('');
+ }
+ }
+ next if ($statusflg eq '' && $submitonly eq 'yes');
- $request->print('');
- }
- }
- my $t2=&Time::HiRes::time();
- print "processclasslist=",$t2-$t1," ";
- $request->print('
');
+ return '';
}
-
#
# --------------------------- show submissions of a student, option to grade --------
sub submission {
- my ($request,$counter,$total) = @_;
-
- (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 ''; }
-
- 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 ''; }
- my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
-
- # header info
- if ($counter == 0) {
- &sub_page_js($request);
- $request->print('
Submission Record
'.
- ' 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.='
';
- $request->print($result);
- }
+ my ($request,$counter,$total) = @_;
- # kwclr is the only variable that is non blank if this has been used once.
- my %keyhash = ();
- if ($ENV{'form.kwclr'} eq '') {
- %keyhash = &Apache::lonnet::dump('nohist_handgrade',
- $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
- $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
-
- my $loginuser = $ENV{'user.name'}.':'.$ENV{'user.domain'};
- $ENV{'form.keywords'} = $keyhash{$symb.'_keywords'} ne '' ? $keyhash{$symb.'_keywords'} : '';
- $ENV{'form.kwclr'} = $keyhash{$loginuser.'_kwclr'} ne '' ? $keyhash{$loginuser.'_kwclr'} : 'red';
- $ENV{'form.kwsize'} = $keyhash{$loginuser.'_kwsize'} ne '' ? $keyhash{$loginuser.'_kwsize'} : '0';
- $ENV{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : '';
- $ENV{'form.msgsub'} = $keyhash{$symb.'_subject'} ne '' ?
- $keyhash{$symb.'_subject'} : &Apache::lonnet::metadata($url,'title');
- $ENV{'form.savemsgN'} = $keyhash{$symb.'_savemsgN'} ne '' ? $keyhash{$symb.'_savemsgN'} : '0';
+ (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 ''; }
+
+ 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 ''; }
+ my $last = ($ENV{'form.lastSub'} eq 'last' ? 'last' : '');
+ $ENV{'form.vProb'} = $ENV{'form.vProb'} ne '' ? $ENV{'form.vProb'} : 'yes';
+ my ($classlist,$seclist,$ids,$stusec,$fullname);
+
+ # header info
+ if ($counter == 0) {
+ &sub_page_js($request);
+ $request->print('
Submission Record
'.
+ ' 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;
}
sub viewGradeaStu_form {
- my ($symb,$url,$response,$handgrade) = @_;
+ my ($symb,$url,$response,$handgrade) = @_;
+ my ($classlist,$sections) = &getclasslist('all','0');
+ my $result.='
'."\n";
+ $result.='
'."\n";
+ $result.=' View/Grade an Individual Student\'s Submission
'."\n";
+ $result.='
'."\n";
+ $result.=''."\n";
+ $result.='
'."\n";
+ $result.='
'."\n";
+ return $result;
+}
+sub verifyReceipt_form {
+ my ($symb,$url) = @_;
+ 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'});
+
+ my $result.='
'."\n";
+ $result.='
'."\n";
+ $result.=' Verify a Submission Receipt Issued by this Server
'."\n";
+ $result.='
'."\n";
+ $result.='';
+ $result.='
'."\n";
+ $result.='
'."\n";
+ return $result;
+}
- my $t3=&Time::HiRes::time();
+sub viewgrades_js {
+ my ($request) = shift;
- my ($classlist,$sections) = &getclasslist('all','0');
+ $request->print(<
+ function viewOneStudent(user) {
+ document.onestudent.student.value = user;
+ document.onestudent.submit();
+ }
+
+ function writePoint(partid,weight,point) {
+ var radioButton = eval("document.classgrade.RADVAL_"+partid);
+ var textbox = eval("document.classgrade.TEXTVAL_"+partid);
+ if (point == "textval") {
+ var point = eval("document.classgrade.TEXTVAL_"+partid+".value");
+ if (isNaN(point) || point < 0) {
+ alert("A number equal or greater than 0 is expected. Entered value = "+point);
+ var resetbox = false;
+ for (var i=0; i";
+ function changeSelect(partid,user) {
+ var selval = eval("document.classgrade.GRADE_"+user+'_'+partid+"_solved");
+ selval[0].selected = true;
+ }
+ function changeOneScore(partid,user) {
+ var selval = eval("document.classgrade.GRADE_"+user+'_'+partid+"_solved");
+ if (selval[1].selected) {
+ var boxval = eval("document.classgrade.GRADE_"+user+'_'+partid+"_awarded");
+ boxval.value = "";
+ }
+ }
- my $result.='
'."\n";
- $result.='
'."\n";
- $result.=' View/Grade an Individual Student\'s Submission
'."\n";
- $result.='
'."\n";
- $result.=''."\n";
- $result.='
'."\n";
- $result.='
'."\n";
- return $result;
-}
-sub verifyReceipt_form {
- my ($symb,$url) = @_;
- 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'});
-
- my $result.='
'."\n";
- $result.='
'."\n";
- $result.=' Verify a Submission Receipt Issued by this Server
'."\n";
- $result.='
'."\n";
- $result.='';
- $result.='
'."\n";
- $result.='
'."\n";
- return $result;
+
+VIEWJAVASCRIPT
}
sub viewgrades {
- my ($request) = @_;
- my $result='';
+ my ($request) = shift;
+ &viewgrades_js($request);
- #get resource reference
- my ($symb,$url)=&get_symb_and_url($request);
- if (!$symb) {return '';}
- #get classlist
- my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
- #print "Found $cdom:$cnum ";
- my ($classlist) = &getclasslist('all','0');
- my $headerclr = '"#ddffff"';
- my $cellclr = '"#ffffdd"';
-
- #get list of parts for this problem
- my (@parts) = sort(&getpartlist($url));
-
- $request->print ("
Manual Grading
");
-
- #start the form
- $result = ''."\n";
+
+ #start the form
+ $result.= '';
- $result.=&show_grading_menu_form($symb,$url);
- return $result;
+ ''."\n";
+
+ $result.='To assign the same score for all the students use the radio buttons or '.
+ 'text box below. To assign scores individually fill in the score boxes for '.
+ 'each student in the table below. A score that has already '.
+ 'been graded does not get changed using the radio buttons or text box. '.
+ 'If needed, it has to be changed individually.';
+
+ my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
+ my %weight = ();
+ my $ctsparts = 0;
+ $result.='
';
+ for (sort keys(%$handgrade)) {
+ my ($responsetype,$handgrade)=split(/:/,$$handgrade{$_});
+ my ($partid,$respid) = split (/_/);
+ my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb);
+ $weight{$partid} = $wgt eq '' ? '1' : $wgt;
+
+ $result.=''."\n";
+ $result.='
Part ID: '.$partid.'
';
+ $result.='
';
+ my $ctr = 0;
+ while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across
+ $result.= '
'."\n";
+ #get list of parts for this problem
+ my (@parts) = sort(&getpartlist($url));
+ foreach my $part (@parts) {
+ my $display=&Apache::lonnet::metadata($url,$part.'.display');
+ next if ($display =~ /^Number of Attempts/);
+ if (!$display) { $display = &Apache::lonnet::metadata($url,$part.'.name'); }
+ if ($display =~ /^Partial Credit Factor/) {
+ $_ = $display;
+ my ($partid) = /.*?(\d+).*/;
+ $result.='
Score Part '.$partid.' (weight = '.
+ $weight{$partid}.')