--- loncom/homework/grades.pm 2005/05/26 21:15:04 1.267
+++ loncom/homework/grades.pm 2006/02/26 02:55:11 1.318
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.267 2005/05/26 21:15:04 albertel Exp $
+# $Id: grades.pm,v 1.318 2006/02/26 02:55:11 banghart Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -40,6 +40,7 @@ use Apache::lonmsg qw(:user_normal_msg);
use Apache::Constants qw(:common);
use Apache::lonlocal;
use String::Similarity;
+use POSIX qw(floor);
my %oldessays=();
my %perm=();
@@ -152,6 +153,7 @@ sub get_display_part {
}
return $display;
}
+
#--- Show resource title
#--- and parts and response type
sub showResourceInfo {
@@ -284,6 +286,11 @@ sub cleanRecord {
}
$answer =~ s-\n- -g;
return '
'.&keywords_highlight($answer).'
';
+ } elsif ( $response eq 'organic') {
+ my $result='Smile representation: "'.$answer.'"';
+ my $jme=$record->{$version."resource.$partid.$respid.molecule"};
+ $result.=&Apache::chemresponse::jme_img($jme,$answer,400);
+ return $result;
}
return $answer;
}
@@ -328,7 +335,16 @@ COMMONJSFUNCTIONS
#--- section, ids and fullnames for each user.
sub getclasslist {
my ($getsec,$filterlist) = @_;
- $getsec = $getsec eq '' ? 'all' : $getsec;
+ my @getsec;
+ if (!ref($getsec)) {
+ if ($getsec ne '' && $getsec ne 'all') {
+ @getsec=($getsec);
+ }
+ } else {
+ @getsec=@{$getsec};
+ }
+ if (grep(/^all$/,@getsec)) { undef(@getsec); }
+
my $classlist=&Apache::loncoursedata::get_classlist();
# Bail out if we were unable to get the classlist
return if (! defined($classlist));
@@ -357,7 +373,7 @@ sub getclasslist {
}
$section = ($section ne '' ? $section : 'none');
if (&canview($section)) {
- if ($getsec eq 'all' || $getsec eq $section) {
+ if (!@getsec || grep(/^\Q$section\E$/,@getsec)) {
$sections{$section}++;
$fullnames{$student}=$fullname;
} else {
@@ -452,6 +468,33 @@ sub jscriptNform {
return $jscript;
}
+# Given the score (as a number [0-1] and the weight) what is the final
+# point value? This function will round to the nearest tenth, third,
+# or quarter if one of those is within the tolerance of .00001.
+sub compute_points {
+ my ($score, $weight) = @_;
+
+ my $tolerance = .00001;
+ my $points = $score * $weight;
+
+ # Check for nearness to 1/x.
+ my $check_for_nearness = sub {
+ my ($factor) = @_;
+ my $num = ($points * $factor) + $tolerance;
+ my $floored_num = floor($num);
+ if ($num - $floored_num < 2 * $tolerance * $factor) {
+ return $floored_num / $factor;
+ }
+ return $points;
+ };
+
+ $points = $check_for_nearness->(10);
+ $points = $check_for_nearness->(3);
+ $points = $check_for_nearness->(4);
+
+ return $points;
+}
+
#------------------ End of general use routines --------------------
#
@@ -465,6 +508,10 @@ sub most_similar {
$uessay=~s/\W+/ /gs;
+# ignore empty submissions (occuring when only files are sent)
+
+ unless ($uessay=~/\w+/) { return ''; }
+
# these will be returned. Do not care if not at least 50 percent similar
my $limit=0.6;
my $sname='';
@@ -526,7 +573,13 @@ sub verifyreceipt {
if ($env{"course.$courseid.receiptalg"} eq 'receipt2') { $receiptparts=1; }
my $parts=['0'];
if ($receiptparts) { ($parts)=&response_type($url,$symb); }
- foreach (sort {lc($$fullname{$a}) cmp lc($$fullname{$b}) } keys %$fullname) {
+ foreach (sort
+ {
+ if (lc($$fullname{$a}) ne lc($$fullname{$b})) {
+ return (lc($$fullname{$a}) cmp lc($$fullname{$b}));
+ }
+ return $a cmp $b;
+ } (keys(%$fullname))) {
my ($uname,$udom)=split(/\:/);
foreach my $part (@$parts) {
if ($receipt eq &Apache::lonnet::ireceipt($uname,$udom,$courseid,$symb,$part)) {
@@ -679,12 +732,16 @@ LISTJAVASCRIPT
while ($loop < 2) {
$gradeTable.='
No.
Select
'.
'
'.&nameUserString('header').' Section/Group
';
- if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') {
+ if ($env{'form.showgrading'} eq 'yes'
+ && $submitonly ne 'queued'
+ && $submitonly ne 'all') {
foreach (sort(@$partlist)) {
my $display_part=&get_display_part((split(/_/))[0],$url,$symb);
$gradeTable.='
' : '');
$ptr++;
}
@@ -3332,7 +3727,11 @@ sub displayPage {
my $navmap = Apache::lonnavmaps::navmap->new();
my ($mapUrl, $id, $resUrl)=&Apache::lonnet::decode_symb($env{'form.page'});
my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
-
+ if (!$map) {
+ $request->print('Unable to view requested sequence. ('.$resUrl.')');
+ $request->print(&show_grading_menu_form($symb,$url));
+ return;
+ }
my $iterator = $navmap->getIterator($map->map_start(),
$map->map_finish());
@@ -3538,7 +3937,12 @@ sub updateGradeByPage {
my $navmap = Apache::lonnavmaps::navmap->new();
my ($mapUrl, $id, $resUrl) = &Apache::lonnet::decode_symb( $env{'form.page'});
my $map = $navmap->getResourceByUrl($resUrl); # add to navmaps
-
+ if (!$map) {
+ $request->print('Unable to grade requested sequence. ('.$resUrl.')');
+ my ($symb,$url)=&get_symb_and_url($request);
+ $request->print(&show_grading_menu_form($symb,$url));
+ return;
+ }
my $iterator = $navmap->getIterator($map->map_start(),
$map->map_finish());
@@ -3566,6 +3970,8 @@ sub updateGradeByPage {
my %newrecord=();
my @displayPts=();
+ my %aggregate = ();
+ my $aggregateflag = 0;
foreach my $partid (@{$parts}) {
my $newpts = $env{'form.GD_BOX'.$question.'_'.$partid};
my $oldpts = $env{'form.oldpts'.$question.'_'.$partid};
@@ -3592,6 +3998,14 @@ sub updateGradeByPage {
$newrecord{'resource.'.$partid.'.regrader'} = "$env{'user.name'}:$env{'user.domain'}";
$changeflag++;
$newpts = '';
+
+ my $aggtries = $env{'form.aggtries'.$question.'_'.$partid};
+ my $totaltries = $env{'form.totaltries'.$question.'_'.$partid};
+ my $solvedstatus = $env{'form.solved'.$question.'_'.$partid};
+ if ($aggtries > 0) {
+ &decrement_aggs($symbx,$partid,\%aggregate,$aggtries,$totaltries,$solvedstatus);
+ $aggregateflag = 1;
+ }
}
my $display_part=&get_display_part($partid,undef,
$curRes->symb());
@@ -3617,6 +4031,11 @@ sub updateGradeByPage {
&Apache::lonnet::cstore(\%newrecord,$symbx,$env{'request.course.id'},
$udom,$uname);
}
+ if ($aggregateflag) {
+ &Apache::lonnet::cinc('nohist_resourcetracker',\%aggregate,
+ $env{'course.'.$env{'request.course.id'}.'.domain'},
+ $env{'course.'.$env{'request.course.id'}.'.num'});
+ }
$studentTable.='
'.$displayPts[0].'
'.
'
'.$displayPts[1].'
'.
@@ -3718,6 +4137,7 @@ sub scantron_CODElist {
my $namechoice='';
foreach my $name (sort {uc($a) cmp uc($b)} @names) {
if ($name =~ /^error: 2 /) { next; }
+ if ($name =~ /^type\0/) { next; }
$namechoice.='';
}
$namechoice='';
@@ -3726,12 +4146,12 @@ sub scantron_CODElist {
sub scantron_CODEunique {
my $result='
- Yes
+
- No
+
';
return $result;
}
@@ -3781,8 +4201,8 @@ sub scantron_selectphase {
Options:
- Do only previously skipped records
- Remove all exisiting corrections
+
+
@@ -3862,7 +4282,7 @@ SCANTRONFORM
-
+
@@ -3961,7 +4381,14 @@ sub scantron_fixup_scanline {
&scan_data($scan_data,
"$whichline.no_bubble.".$args->{'question'},'1');
} else {
- substr($answer,$args->{'response'},1)=$on;
+ if ($on eq 'letter') {
+ my @alphabet=('A'..'Z');
+ $answer=$alphabet[$args->{'response'}];
+ } elsif ($on eq 'number') {
+ $answer=$args->{'response'}+1;
+ } else {
+ substr($answer,$args->{'response'},1)=$on;
+ }
&scan_data($scan_data,
"$whichline.no_bubble.".$args->{'question'},undef,'1');
}
@@ -3986,8 +4413,11 @@ sub scantron_parse_scanline {
my %record;
my $questions=substr($line,$$scantron_config{'Qstart'}-1);
my $data=substr($line,0,$$scantron_config{'Qstart'}-1);
- if ($$scantron_config{'CODElocation'} ne 0) {
- if ($$scantron_config{'CODElocation'} < 0) {
+ if (!($$scantron_config{'CODElocation'} eq 0 ||
+ $$scantron_config{'CODElocation'} eq 'none')) {
+ if ($$scantron_config{'CODElocation'} < 0 ||
+ $$scantron_config{'CODElocation'} eq 'letter' ||
+ $$scantron_config{'CODElocation'} eq 'number') {
$record{'scantron.CODE'}=substr($data,
$$scantron_config{'CODEstart'}-1,
$$scantron_config{'CODElength'});
@@ -4022,8 +4452,12 @@ sub scantron_parse_scanline {
substr($questions,0,$$scantron_config{'Qlength'})='';
if (length($currentquest) < $$scantron_config{'Qlength'}) { next; }
if ($$scantron_config{'Qon'} eq 'letter') {
- if (!$currentquest || $currentquest eq $$scantron_config{'Qoff'} ||
- $currentquest !~ /^[A-Z]$/) {
+ if ($currentquest eq '?') {
+ push(@{$record{'scantron.doubleerror'}},$questnum);
+ $record{"scantron.$questnum.answer"}='';
+ } elsif (!$currentquest
+ || $currentquest eq $$scantron_config{'Qoff'}
+ || $currentquest !~ /^[A-Z]$/) {
$record{"scantron.$questnum.answer"}='';
if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
push(@{$record{"scantron.missingerror"}},$questnum);
@@ -4032,8 +4466,12 @@ sub scantron_parse_scanline {
$record{"scantron.$questnum.answer"}=$currentquest;
}
} elsif ($$scantron_config{'Qon'} eq 'number') {
- if (!$currentquest || $currentquest eq $$scantron_config{'Qoff'} ||
- $currentquest !~ /^\d$/) {
+ if ($currentquest eq '?') {
+ push(@{$record{'scantron.doubleerror'}},$questnum);
+ $record{"scantron.$questnum.answer"}='';
+ } elsif (!$currentquest
+ || $currentquest eq $$scantron_config{'Qoff'}
+ || $currentquest !~ /^\d$/) {
$record{"scantron.$questnum.answer"}='';
if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) {
push(@{$record{"scantron.missingerror"}},$questnum);
@@ -4150,7 +4588,7 @@ sub scantron_process_corrections {
}
}
if ($err) {
- $r->print("Unable to accept last correction, an error occurred :$errmsg:");
+ $r->print("Unable to accept last correction, an error occurred :$errmsg:");
} else {
&scantron_put_line($scanlines,$scan_data,$which,$line,$skip);
&scantron_putfile($scanlines,$scan_data);
@@ -4204,14 +4642,26 @@ sub check_for_error {
sub scantron_warning_screen {
my ($button_text)=@_;
my $title=&Apache::lonnet::gettitle($env{'form.selectpage'});
+ my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
+ my $CODElist="a";
+ if ($scantron_config{'CODElocation'} &&
+ $scantron_config{'CODEstart'} &&
+ $scantron_config{'CODElength'}) {
+ $CODElist=$env{'form.scantron_CODElist'};
+ if ($CODElist eq '') { $CODElist='None'; }
+ $CODElist=
+ '
List of CODES to validate against:
'.
+ $CODElist.'
';
+ }
return (<
Please double check the information
below before clicking on '$button_text'
-
Sequence To be Graded:
$title
+
Sequence to be Graded:
$title
Data File that will be used:
$env{'form.scantron_selectfile'}
+$CODElist
@@ -4418,9 +4868,8 @@ sub lonnet_putfile {
my ($contents,$filename)=@_;
my $docuname=$env{'course.'.$env{'request.course.id'}.'.num'};
my $docudom=$env{'course.'.$env{'request.course.id'}.'.domain'};
- my $docuhome=$env{'course.'.$env{'request.course.id'}.'.home'};
$env{'form.sillywaytopassafilearound'}=$contents;
- &Apache::lonnet::finishuserfileupload($docuname,$docudom,$docuhome,'sillywaytopassafilearound',$filename);
+ &Apache::lonnet::finishuserfileupload($docuname,$docudom,'sillywaytopassafilearound',$filename);
}
@@ -4588,19 +5037,24 @@ sub scantron_get_correction {
$r->print("
How should I handle this? \n");
$r->print("\n ");
my $i=0;
- if ($error eq 'incorrectCODE') {
+ if ($error eq 'incorrectCODE'
+ && $$scan_record{'scantron.CODE'}=~/\S/ ) {
my ($max,$closest)=&scantron_get_closely_matching_CODEs($arg,$$scan_record{'scantron.CODE'});
- foreach my $testcode (@{$closest}) {
- my $checked='';
- if (!$i) { $checked=' checked="on" '; }
- $r->print(" Use the similar CODE ".$testcode." instead.");
- $r->print("\n ");
- $i++;
+ if ($closest > 0) {
+ foreach my $testcode (@{$closest}) {
+ my $checked='';
+ if (!$i) { $checked=' checked="on" '; }
+ $r->print("");
+ $r->print("\n ");
+ $i++;
+ }
}
}
- my $checked; if (!$i) { $checked=' checked="on" '; }
- $r->print(" Use the CODE ".$$scan_record{'scantron.CODE'}." that is was on the paper, ignoring the error.");
- $r->print("\n ");
+ if ($$scan_record{'scantron.CODE'}=~/\S/ ) {
+ my $checked; if (!$i) { $checked=' checked="on" '; }
+ $r->print("");
+ $r->print("\n ");
+ }
$r->print(<
@@ -4619,9 +5073,9 @@ ENDSCRIPT
"&scantron_CODElist=".&Apache::lonnet::escape($env{'form.scantron_CODElist'}).
"&curCODE=".&Apache::lonnet::escape($$scan_record{'scantron.CODE'}).
"&scantron_selectfile=".&Apache::lonnet::escape($env{'form.scantron_selectfile'});
- $r->print(" Select a CODE from the list of all CODEs and use it. Selected CODE is ");
+ $r->print(" Selected CODE is ");
$r->print("\n ");
- $r->print(" Use as the CODE.");
+ $r->print(" as the CODE.");
$r->print("\n