--- loncom/homework/grades.pm 2002/04/06 21:07:08 1.19
+++ 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.19 2002/04/06 21:07:08 www Exp $
+# $Id: grades.pm,v 1.42 2002/07/26 20:28:42 ng Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -29,6 +29,9 @@
# 6/8 Gerd Kortemeyer
# 7/26 H.K. Ng
# 8/20 Gerd Kortemeyer
+# Year 2002
+# June, July 2002 H.K. Ng
+#
package Apache::grades;
use strict;
@@ -37,404 +40,1982 @@ 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) = @_;
- $request->print("Unable to process request: $reason");
- if ( $Apache::grades::viewgrades eq 'F' ) {
- $request->print('
');
}
- if ($ENV{'form.symb'}) {
- $request->print(''."\n");
+ return '';
+}
+
+sub verifyreceipt {
+ my $request=shift;
+ my $courseid=$ENV{'request.course.id'};
+# 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;
+ my $symb=$ENV{'form.symb'};
+ unless ($symb) {
+ $symb=&Apache::lonnet::symbread($ENV{'form.url'});
}
- $request->print(''."\n");
- $request->print("Student:".''." \n");
- $request->print("Domain:".''." \n");
- $request->print(''." \n");
- $request->print('');
- }
- return '';
+ if ((&Apache::lonnet::allowed('mgr',$courseid)) && ($symb)) {
+ $request->print('
Verifying Submission Receipt '.$receipt.'
');
+ my $matches=0;
+ 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)) {
+ $request->print('Matching '.$student.' ');
+ $matches++;
+ }
+ }
+ $request->printf('
'.$matches." match%s
",$matches <= 1 ? '' : 'es');
+# needs to print who is matched
+ }
+ return '';
+}
+
+sub student_gradeStatus {
+ 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 %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 $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,$cnum) = split(/_/,$ENV{'request.course.id'});
- my $chome=$ENV{"course.$ENV{'request.course.id'}.home"};
- $request->print ('
Show Student Submissions on Assessment
'.
- '
Username
Domain
Name
'
- );
- my (%classlist) = &getclasslist($cdom,$cnum,$chome,'0');
- foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
- my ($sname,$sdom) = split(/:/,$student);
-
- my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.
- ':environment:lastname&generation&firstname&middlename',
- &Apache::lonnet::homeserver($sname,$sdom));
- #print "reply=$reply ";
- my (@nameparts) = split /&/,$reply;
-# my $sfullname = $Apache::lonnet::unescape($nameparts[0]);
-
- if ( $Apache::grades::viewgrades eq 'F' ) {
- $request->print(
- "\n".'
');
- }
- }
- $request->print('
');
+ 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:
+ 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 ($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');
+
+ if ( $Apache::grades::viewgrades eq 'F' ) {
+ $result='
'.
+ '
'."\n".
+ '
'.$uname.'
'."\n".
+ '
'.$$fullname{$student}.'
'."\n".
+ '
'.$udom.'
'."\n";
+
+ foreach (sort keys(%status)) {
+ next if (/^resource.*?submitted_by$/);
+ $result.='
'.$status{$_}.'
'."\n";
+ }
+ $request->print($result.'
'."\n");
+ }
+ }
+ $request->print('
');
+ $request->print('');
}
+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'});
- my $chome=$ENV{"course.$ENV{'request.course.id'}.home"};
- #print "Found $cdom:$cnum:$chome ";
- my (%classlist) = &getclasslist($cdom,$cnum,$chome,'0');
- foreach my $student ( sort(@{ $classlist{'allids'} }) ) {
- my ($posname,$posdomain) = split(/:/,$student);
- if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; }
- }
- return ($name,$domain);
- } else {
- return ($ENV{'user.name'},$ENV{'user.domain'});
- }
+ my ($name) = @_;
+ my $domain = '';
+ if ( $Apache::grades::viewgrades eq 'F' ) {
+ my ($classlist) = &getclasslist('all','0');
+ foreach ( sort(@{ $$classlist{'all'} }) ) {
+ my ($posname,$posdomain) = split(/:/);
+ if ($posname =~ $name) { $name=$posname; $domain=$posdomain; last; }
+ }
+ return ($name,$domain);
+ } else {
+ return ($ENV{'user.name'},$ENV{'user.domain'});
+ }
}
sub getclasslist {
- my ($coursedomain,$coursenum,$coursehome,$hideexpired) = @_;
- my $classlist=&Apache::lonnet::reply("dump:$coursedomain:$coursenum:classlist",$coursehome);
- my %classlist=();
- my $now = time;
- foreach my $record (split /&/, $classlist) {
- my ($name,$value)=split(/=/,&Apache::lonnet::unescape($record));
- my ($end,$start)=split(/:/,$value);
- # still a student?
- if (($hideexpired) && ($end) && ($end < $now)) {
- #print "Skipping:$name:$end:$now \n";
- next;
+ my ($getsec,$hideexpired) = @_;
+ my $now = time;
+ my %classlist=&Apache::lonnet::dump('classlist',
+ $ENV{'course.'.$ENV{'request.course.id'}.'.domain'},
+ $ENV{'course.'.$ENV{'request.course.id'}.'.num'});
+ 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;
+ }
}
- #print "record=$record ";
- push( @{ $classlist{'allids'} }, $name);
- }
- return (%classlist);
+ my %seen = ();
+ foreach my $item (@holdsec) {
+ push (@sections, $item) unless $seen{$item}++;
+ }
+ return (\%classlist,\@sections,\%allids,\%stusec,\%fullname);
}
sub getpartlist {
- my ($url) = @_;
- my @parts =();
- my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
- foreach my $key (@metakeys) {
- if ( $key =~ m/stores_([0-9]+)_.*/ ) {
- push(@parts,$key);
+ my ($url) = @_;
+ my @parts =();
+ my (@metakeys) = split(/,/,&Apache::lonnet::metadata($url,'keys'));
+ foreach my $key (@metakeys) {
+ if ( $key =~ m/stores_([0-9]+)_.*/) {
+ push(@parts,$key);
+ }
}
- }
- return @parts;
+ return @parts;
}
-sub viewstudentgrade {
- my ($url,$symb,$courseid,$student,@parts) = @_;
- my $result ='';
- my $cellclr = '"#ffffdd"';
- my ($stuname,$domain) = split(/:/,$student);
-
- my %record=&Apache::lonnet::restore($symb,$courseid,$domain,$stuname);
-
- $result.="
$stuname
$domain
\n";
- foreach my $part (@parts) {
- my ($temp,$part,$type)=split(/_/,$part);
- #print "resource.$part.$type = ".$record{"resource.$part.$type"}." \n";
- if ($type eq 'awarded') {
- my $score=$record{"resource.$part.$type"};
- $result.="
');
+ return '';
}
-#FIXME need to look at the meatdata spec on what type of data to accept and provide an
-#interface based on that, also do that to above function.
-sub setstudentgrade {
- my ($url,$symb,$courseid,$student,@parts) = @_;
+#
+# --------------------------- show submissions of a student, option to grade --------
+sub submission {
+ my ($request,$counter,$total) = @_;
- my $result ='';
+ (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 ($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;
+}
+
+sub viewgrades_js {
+ my ($request) = shift;
+
+ $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
+VIEWJAVASCRIPT
}
sub viewgrades {
- my ($request) = @_;
- my $result='';
+ my ($request) = shift;
+ &viewgrades_js($request);
+
+ my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'});
+ $request->print ('
Manual Grading
');
- #get resource reference
- my $url=$ENV{'form.url'};
- $url=~s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
- my $symb=$ENV{'form.symb'};
- if (!$symb) { $symb=&Apache::lonnet::symbread($url); }
- if ($symb eq '') { $request->print("Unable to handle ambiguous references:$url:."); return ''; }
-
- #get classlist
- my ($cdom,$cnum) = split(/_/,$ENV{'request.course.id'});
- my $chome=$ENV{"course.$ENV{'request.course.id'}.home"};
- #print "Found $cdom:$cnum:$chome ";
- my (%classlist) = &getclasslist($cdom,$cnum,$chome,'0');
- my $headerclr = '"#ccffff"';
- my $cellclr = '"#ffffcc"';
-
- #get list of parts for this problem
- my (@parts) = &getpartlist($url);
-
- $request->print ("
Manual Grading
");
-
- #start the form
- $result = ''."\n";
+
+ #start the form
+ $result.= '';
+ ''."\n";
- return $result;
+ $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}.')