--- loncom/homework/grades.pm 2002/10/17 14:35:34 1.57
+++ loncom/homework/grades.pm 2003/03/28 23:44:31 1.81
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.57 2002/10/17 14:35:34 matthew Exp $
+# $Id: grades.pm,v 1.81 2003/03/28 23:44:31 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -31,6 +31,8 @@
# 8/20 Gerd Kortemeyer
# Year 2002
# June-August H.K. Ng
+# Year 2003
+# February, March H.K. Ng
#
package Apache::grades;
@@ -39,12 +41,13 @@ use Apache::style;
use Apache::lonxml;
use Apache::lonnet;
use Apache::loncommon;
+use Apache::lonnavmaps;
use Apache::lonhomework;
use Apache::loncoursedata;
use Apache::lonmsg qw(:user_normal_msg);
use Apache::Constants qw(:common);
-# ----- These first few routines are general use routines.-----
+# ----- These first few routines are general use routines.----
#
# --- Retrieve the parts that matches stores_\d+ from the metadata file.---
sub getpartlist {
@@ -110,7 +113,7 @@ sub response_type {
#--- Dumps the class list with usernames,list of sections,
#--- section, ids and fullnames for each user.
sub getclasslist {
- my ($getsec,$hideexpired) = @_;
+ my ($getsec,$filterlist) = @_;
my $classlist=&Apache::loncoursedata::get_classlist();
# Bail out if we were unable to get the classlist
return if (! defined($classlist));
@@ -121,11 +124,13 @@ sub getclasslist {
# the following undefs are for 'domain', and 'username' respectively.
my (undef,undef,$end,$start,$id,$section,$fullname,$status)=
@{$classlist->{$_}};
- # still a student?
- if (($hideexpired) && ($status ne 'Active')) {
- delete ($classlist->{$_});
- next;
- }
+ # filter students according to status selected
+ if ($filterlist && $ENV{'form.status'} ne 'Any') {
+ if ($ENV{'form.status'} ne $status) {
+ delete ($classlist->{$_});
+ next;
+ }
+ }
$section = ($section ne '' ? $section : 'no');
if ($getsec eq 'all' || $getsec eq $section) {
$sections{$section}++;
@@ -206,6 +211,8 @@ sub jscriptNform {
$jscript.= '
';
@@ -1146,9 +1322,7 @@ sub get_last_submission {
for ($version=1;$version<=$returnhash{'version'};$version++) {
foreach (sort(split(/\:/,$returnhash{$version.':keys'}))) {
$lasthash{$_}=$returnhash{$version.':'.$_};
- if ($returnhash{$version.':'.$_} =~ /(SUBMITTED|DRAFT)$/) {
$timestamp = scalar(localtime($returnhash{$version.':timestamp'}));
- }
}
}
foreach ((keys %lasthash)) {
@@ -1172,7 +1346,7 @@ sub keywords_highlight {
(my $styleoff = $styleon) =~ s/\\<\//;
my @keylist = split(/[,\s+]/,$ENV{'form.keywords'});
foreach (@keylist) {
- $string =~ s/\b$_(\b|\.)/\$styleon$_$styleoff\<\/font\>/gi;
+ $string =~ s/\b\Q$_\E(\b|\.)/\$styleon$_$styleoff\<\/font\>/gi;
}
# This is not really the right place to do this, but I cannot find a
# better one at this time. So here we go - the m in the s:::mg causes
@@ -1195,17 +1369,24 @@ sub processHandGrade {
my $ctr = 0;
while ($ctr < $ngrade) {
my ($uname,$udom) = split(/:/,$ENV{'form.unamedom'.$ctr});
- my ($errorflag) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
-
+ my ($errorflag,$pts,$wgt) = &saveHandGrade($request,$url,$symb,$uname,$udom,$ctr);
+ if ($errorflag eq 'no_score') {
+ $ctr++;
+ next;
+ }
my $includemsg = $ENV{'form.includemsg'.$ctr};
my ($subject,$message,$msgstatus) = ('','','');
- if ($includemsg =~ /savemsg|new$ctr/) {
+ if ($includemsg =~ /savemsg|newmsg\Q$ctr\E/) {
$subject = $ENV{'form.msgsub'} if ($includemsg =~ /^msgsub/);
my (@msgnum) = split(/,/,$includemsg);
foreach (@msgnum) {
$message.=$ENV{'form.'.$_} if ($_ =~ /savemsg|newmsg/ && $_ ne '');
}
- $message =~ s/\s+/ /g;
+ $message =&Apache::lonfeedback::clear_out_html($message);
+ $message.="\n\nPoint".($pts > 1 ? 's':'').' awarded = '.$pts.' out of '.$wgt;
+ $message.=" for $ENV{'form.probTitle'}";
$msgstatus = &Apache::lonmsg::user_normal_msg ($uname,$udom,
$ENV{'form.msgsub'},$message);
}
@@ -1327,8 +1508,6 @@ sub processHandGrade {
$ENV{'form.student'} = $uname;
$ENV{'form.userdom'} = $udom;
$ENV{'form.fullname'} = $$fullname{$_};
-# $ENV{'form.'.$_.':submitted_by'} = $submitter;
-# print "submitter=$ENV{'form.'.$_.':submitted_by'}= $submitter: ";
&submission($request,$ctr,$total);
$ctr++;
}
@@ -1345,17 +1524,23 @@ sub processHandGrade {
#---- Save the score and award for each student, if changed
sub saveHandGrade {
my ($request,$url,$symb,$stuname,$domain,$newflg,$submitter) = @_;
- my %record=&Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
- my %newrecord;
+ my %record = &Apache::lonnet::restore($symb,$ENV{'request.course.id'},$domain,$stuname);
+ my %newrecord = ();
+ my ($pts,$wgt) = ('','');
foreach (split(/:/,$ENV{'form.partlist'.$newflg})) {
if ($ENV{'form.GD_SEL'.$newflg.'_'.$_} eq 'excused') {
- $newrecord{'resource.'.$_.'.solved'} = 'excused'
- if ($record{'resource.'.$_.'.solved'} ne 'excused');
+ if ($record{'resource.'.$_.'.solved'} ne 'excused') {
+ $newrecord{'resource.'.$_.'.solved'} = 'excused';
+ if (exists($record{'resource.'.$_.'.awarded'})) {
+ $newrecord{'resource.'.$_.'.awarded'} = '';
+ }
+ }
} else {
- my $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ?
- $ENV{'form.GD_BOX'.$newflg.'_'.$_} :
- $ENV{'form.RADVAL'.$newflg.'_'.$_});
- my $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 :
+ $pts = ($ENV{'form.GD_BOX'.$newflg.'_'.$_} ne '' ?
+ $ENV{'form.GD_BOX'.$newflg.'_'.$_} :
+ $ENV{'form.RADVAL'.$newflg.'_'.$_});
+ return 'no_score' if ($pts eq '' && $ENV{'form.GD_SEL'.$newflg.'_'.$_} eq '');
+ $wgt = $ENV{'form.WGT'.$newflg.'_'.$_} eq '' ? 1 :
$ENV{'form.WGT'.$newflg.'_'.$_};
my $partial= $pts/$wgt;
$newrecord{'resource.'.$_.'.awarded'} = $partial
@@ -1370,15 +1555,15 @@ sub saveHandGrade {
}
$newrecord{'resource.'.$_.'.submitted_by'} = $submitter
if ($submitter && ($record{'resource.'.$_.'.submitted_by'} ne $submitter));
+ $newrecord{'resource.'.$_.'regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
}
}
if (scalar(keys(%newrecord)) > 0) {
- $newrecord{'resource.regrader'}="$ENV{'user.name'}:$ENV{'user.domain'}";
&Apache::lonnet::cstore(\%newrecord,$symb,
$ENV{'request.course.id'},$domain,$stuname);
}
- return '';
+ return '',$pts,$wgt;
}
#--------------------------------------------------------------------------------------
@@ -1563,7 +1748,7 @@ sub viewgrades {
my ($symb,$url) = ($ENV{'form.symb'},$ENV{'form.url'});
my $result='
Manual Grading
';
- $result.='Resource: '.$ENV{'form.url'}.''."\n";
+ $result.='Problem: '.$ENV{'form.probTitle'}.''."\n";
#view individual student submission form - called using Javascript viewOneStudent
$result.=&jscriptNform($url,$symb);
@@ -1573,7 +1758,10 @@ sub viewgrades {
''."\n".
''."\n".
''."\n".
- ''."\n";
+ ''."\n".
+ ''."\n".
+ ''."\n";
+
$result.='
Assign Common Grade To ';
if ($ENV{'form.section'} eq 'all') {
$result.='Class
';
-# $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 part that has already '.
-# 'been graded does not get changed using the radio buttons or text box. '.
-# 'If needed, it has to be changed individually.';
-# $result.='
';
#radio buttons/text box for assigning points for a section or class.
#handles different parts of a problem
my ($partlist,$handgrade) = &response_type($ENV{'form.url'});
@@ -1626,7 +1808,7 @@ sub viewgrades {
$weight{$partid}.' (problem weight)
'."\n";
$result.= '
'.
+ $weight{$partid}.')"> '.
''.
'
'."\n";
$ctsparts++;
@@ -1668,7 +1850,7 @@ sub viewgrades {
#get info for each student
#list all the students - with points and grade status
- my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'0');
+ my (undef,undef,$fullname) = &getclasslist($ENV{'form.section'},'1');
my $ctr = 0;
foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
my ($uname,$udom) = split(/:/);
@@ -1694,8 +1876,8 @@ sub viewstudentgrade {
''.$fullname.''.
'
'.$uname.'
'.$udom.'
'."\n";
- foreach my $part (@$parts) {
- my ($part,$type) = &split_part_type($part);
+ foreach my $apart (@$parts) {
+ my ($part,$type) = &split_part_type($apart);
my $score=$record{"resource.$part.$type"};
if ($type eq 'awarded') {
my $pts = $score eq '' ? '' : $score*$$weight{$part};
@@ -1739,9 +1921,8 @@ sub editgrades {
my $symb=$ENV{'form.symb'};
my $url =$ENV{'form.url'};
my $title='
'."\n".
+ &show_grading_menu_form ($symb,$url);
my $msg = 'Number of records updated = '.$rec_update.
' for '.$count.' student'.($count <= 1 ? '' : 's').'. '.
'Total number of students = '.$ENV{'form.total'}.' ';
@@ -1963,7 +2145,7 @@ sub csvuploadmap_header {
}
my $result='
';
- $result.='
Resource: '.$url.'
';
+ $result.='
Problem: '.$ENV{'form.probTitle'}.'
';
my ($partlist,$handgrade) = &response_type($url);
my ($resptype,$hdgrade)=('','no');
for (sort keys(%$handgrade)) {
@@ -1994,6 +2176,8 @@ to this page if the data selected is ins
value="$ENV{'form.upfile_associate'}" />
+
+
+LISTJAVASCRIPT
+
+ my ($symb,$url) = &get_symb_and_url($request);
+ 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 $result='
';
+
+ my ($depth,$ctr,$question) = (1,0,1);
+ $iterator->next(); # skip the first BEGIN_MAP
+ my $curRes = $iterator->next(); # for "current resource"
+ while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop
+ if($curRes == $iterator->BEGIN_MAP) { $depth++; }
+ if($curRes == $iterator->END_MAP) { $depth++; }
+
+ if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
+ my $parts = $curRes->parts();
+ $parts = &temp_parts_fix($parts); # remove line when lonnavmap is fixed
+ my $title = $curRes->compTitle();
+ my $symbx = $curRes->symb();
+ $studentTable.='
/g;
+ $studentTable.=' '.$title.' Correct answer: '.$companswer;
+ }
+
+ my %record = &Apache::lonnet::restore($symbx,$ENV{'request.course.id'},$udom,$uname);
+
+ if ($ENV{'form.lastSub'} eq 'datesub') {
+ if ($record{'version'} eq '') {
+ $studentTable.=' No recorded submission for this problem ';
+ } else {
+ $studentTable.='
'.
+ '
'.
+ '
Date/Time
'.
+ '
Submission
'.
+ '
Status
';
+ my ($version);
+ for ($version=1;$version<=$record{'version'};$version++) {
+ my $timestamp = scalar(localtime($record{$version.':timestamp'}));
+ $studentTable.='
'."\n";
+
+ $request->print($result);
+
+ my $navmap = Apache::lonnavmaps::navmap-> new($ENV{'request.course.fn'}.'.db',
+ $ENV{'request.course.fn'}.'_parms.db',1, 1);
+ my ($mapUrl, $id, $resUrl) = split(/___/, $ENV{'form.page'});
+ my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
+
+ my $iterator = $navmap->getIterator($map->map_start(),
+ $map->map_finish());
+
+ my $studentTable='
'.
+ '
'.
+ '
No
'.
+ '
Title
'.
+ '
Previous Score
'.
+ '
New Score
';
+
+ $iterator->next(); # skip the first BEGIN_MAP
+ my $curRes = $iterator->next(); # for "current resource"
+ my ($depth,$ctr,$question,$changeflag)= (1,0,1,0);
+ while ($depth > 0 && $ctr < 100) { # ctr, just in case it never gets out of loop
+ if($curRes == $iterator->BEGIN_MAP) { $depth++; }
+ if($curRes == $iterator->END_MAP) { $depth++; }
+
+ if (ref($curRes) && $curRes->is_problem() && !$curRes->randomout) {
+ my $parts = $curRes->parts();
+ $parts = &temp_parts_fix($parts); # remove line when lonnavmap is fixed
+ my $title = $curRes->compTitle();
+ my $symbx = $curRes->symb();
+ $studentTable.='
';
+ $studentTable.=&show_grading_menu_form($ENV{'form.symb'},$ENV{'form.url'});
+ my $grademsg=($changeflag == 0 ? 'No score was changed or updated.' :
+ 'The scores were changed for '.
+ $changeflag.' problem'.($changeflag == 1 ? '.' : 's.'));
+ $request->print($grademsg.$studentTable);
+
+ return '';
+}
+
+#-------- end of section for handling grading by page/sequence ---------
+#
+#-------------------------------------------------------------------
+
+#--------------------Scantron Grading-----------------------------------
+#
+#------ start of section for handling grading by page/sequence ---------
+
+sub defaultFormData {
+ my ($symb,$url)=@_;
+ return '
+ '."\n".
+ ''."\n".
+ ''."\n".
+ ''."\n";
+}
+
+sub getSequenceDropDown {
+ my ($request,$symb)=@_;
+ my $result='';
+ return $result;
+}
+
+sub scantron_uploads {
+ if (!-e $Apache::lonnet::perlvar{'lonScansDir'}) { return ''};
+ my $result= '";
+ return $result;
+}
+
+sub scantron_selectphase {
+ my ($r) = @_;
+ my ($symb,$url)=&get_symb_and_url($r);
+ if (!$symb) {return '';}
+ my $sequence_selector=&getSequenceDropDown($r,$symb);
+ my $default_form_data=&defaultFormData($symb,$url);
+ my $grading_menu_button=&show_grading_menu_form($symb,$url);
+ my $file_selector=&scantron_uploads();
+ my $result;
+ $result.= <
+
+ $default_form_data
+
+
+
+
+
+
+ Specify file location and which Folder/Sequence to grade
+
+
+
+
+ Sequence to grade: $sequence_selector
+
+
+
+
+ Filename of scoring office file: $file_selector
+
+
+
+
+
+
+
+
+$grading_menu_button
+SCANTRONFORM
+
+ return $result;
+}
+
+sub scantron_configphase {
+ my ($r) = @_;
+ my (undef,undef,$sequence)=split(/___/,$ENV{'form.selectpage'});
+ my $result;
+ my ($symb,$url)=&get_symb_and_url($r);
+ if (!$symb) {return '';}
+ my $default_form_data=&defaultFormData($symb,$url);
+ my $grading_menu_button=&show_grading_menu_form($symb,$url);
+ my $file_selector;
+ $result.= <
+
+ $default_form_data
+
+
+
+
+
+
+ Select a format for the data file.
+
+
+
+
+ Format of data file:
+
+
+
+
+ Filename of scoring office file: $file_selector
+
+
+
+
+
+
+
+
+$grading_menu_button
+SCANTRONFORM
+ #FIXME Needs to present some lines from the file and allow the instructor to specify which columns represent what data, possibly have some nice defaults setup, probably should do a pass through all problems for a student to get an idea of how many questions there are, and homw many lines we'll have,
+ return $result;
+}
+
+sub scantron_process_students {
+ #FIXME
+ # loop through students, {
+ # Check if studnet info valid, if not add line to delay queue
+ # foreach question 'submit' the students answer to the server
+ # through grade target {
+ # generate data to pass back that includes grade recevied
+ # }
+ # }
+ # loop through delay queue {
+ # print out each delayed student with interface to select how
+ # to repair student provided info
+ # Expected errors include
+ # 1 bad/no stuid/username
+ # 2 invalid bubblings
+ # }
+ # if delay queue exists 2 submits one to process delayed students one
+ # to ignore delayed students, possibly saving the delay queue for later
+
+}
+#-------- end of section for handling grading scantron forms -------
+#
+#-------------------------------------------------------------------
+
#-------------------------- Menu interface -------------------------
#
@@ -2134,20 +2940,147 @@ sub show_grading_menu_form {
my $result.='
'."\n";
-#--- Menu for grading a section or the whole class ---
-sub view_edit_entire_class_form {
- my ($symb,$url)=@_;
- my ($classlist,$sections,undef) = &getclasslist('all','0');
- my $result.='
'."\n";
- $result.='
'."\n";
- $result.=' Grade Entire Section or Class