--- loncom/homework/grades.pm 2007/06/15 22:10:15 1.407
+++ loncom/homework/grades.pm 2007/06/16 20:24:25 1.414
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.407 2007/06/15 22:10:15 albertel Exp $
+# $Id: grades.pm,v 1.414 2007/06/16 20:24:25 www Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -6129,7 +6129,7 @@ sub init_perm {
}
sub gather_clicker_ids {
- my %clicker_ids=();
+ my %clicker_ids;
my $classlist = &Apache::loncoursedata::get_classlist();
@@ -6142,13 +6142,13 @@ sub gather_clicker_ids {
my $username = $classlist->{$student}->[$username_idx];
my $domain = $classlist->{$student}->[$domain_idx];
my $clickers =
- (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
+ (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1];
foreach my $id (split(/\,/,$clickers)) {
- $id=~s/^0+//;
+ $id=~s/^[\#0]+//;
if (exists($clicker_ids{$id})) {
- $clicker_ids{$id}.=','.$username.':'.$domain;
+ $clicker_ids{$id}.=','.$username.':'.$domain;
} else {
- $clicker_ids{$id}=$username.':'.$domain;
+ $clicker_ids{$id}=$username.':'.$domain;
}
}
}
@@ -6156,28 +6156,36 @@ sub gather_clicker_ids {
}
sub gather_adv_clicker_ids {
- my %clicker_ids=();
+ my %clicker_ids;
my $cnum=$env{'course.'.$env{'request.course.id'}.'.num'};
my $cdom=$env{'course.'.$env{'request.course.id'}.'.domain'};
my %coursepersonnel=&Apache::lonnet::get_course_adv_roles($cdom.'/'.$cnum);
- foreach my $element (sort keys %coursepersonnel) {
+ foreach my $element (sort(keys(%coursepersonnel))) {
foreach my $person (split(/\,/,$coursepersonnel{$element})) {
my ($puname,$pudom)=split(/\:/,$person);
my $clickers =
- (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
+ (&Apache::lonnet::userenvironment($pudom,$puname,'clickers'))[1];
foreach my $id (split(/\,/,$clickers)) {
- $id=~s/^0+//;
- if (exists($clicker_ids{$id})) {
- $clicker_ids{$id}.=','.$puname.':'.$pudom;
- } else {
- $clicker_ids{$id}=$puname.':'.$pudom;
- }
+ $id=~s/^[\#0]+//;
+ if (exists($clicker_ids{$id})) {
+ $clicker_ids{$id}.=','.$puname.':'.$pudom;
+ } else {
+ $clicker_ids{$id}=$puname.':'.$pudom;
+ }
}
}
}
return %clicker_ids;
}
+sub clicker_grading_parameters {
+ return ('gradingmechanism' => 'scalar',
+ 'upfiletype' => 'scalar',
+ 'specificid' => 'scalar',
+ 'pcorrect' => 'scalar',
+ 'pincorrect' => 'scalar');
+}
+
sub process_clicker {
my ($r)=@_;
my ($symb)=&get_symb($r);
@@ -6191,15 +6199,31 @@ sub process_clicker {
$result.=' '.&mt('Specify a file containing the clicker information for this resource').
'.'."\n";
$result.='
'."\n";
+# Attempt to restore parameters from last session, set defaults if not present
+ my %Saveable_Parameters=&clicker_grading_parameters();
+ &Apache::loncommon::restore_course_settings('grades_clicker',
+ \%Saveable_Parameters);
+ if (!$env{'form.pcorrect'}) { $env{'form.pcorrect'}=100; }
+ if (!$env{'form.pincorrect'}) { $env{'form.pincorrect'}=100; }
+ if (!$env{'form.gradingmechanism'}) { $env{'form.gradingmechanism'}='attendance'; }
+ if (!$env{'form.upfiletype'}) { $env{'form.upfiletype'}='iclicker'; }
+
+ my %checked;
+ foreach my $gradingmechanism ('attendance','personnel','specific') {
+ if ($env{'form.gradingmechanism'} eq $gradingmechanism) {
+ $checked{$gradingmechanism}="checked='checked'";
+ }
+ }
+
my $upload=&mt("Upload File");
my $type=&mt("Type");
my $attendance=&mt("Award points just for participation");
my $personnel=&mt("Correctness determined from response by course personnel");
- my $specific=&mt("Correctness determined from response with clicker ID");
+ my $specific=&mt("Correctness determined from response with clicker ID(s)");
my $pcorrect=&mt("Percentage points for correct solution");
my $pincorrect=&mt("Percentage points for incorrect solution");
- my $selectform=&Apache::loncommon::select_form('iclicker','upfiletype',
- ('iclicker' => 'i>clicker'));
+ my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
+ ('iclicker' => 'i>clicker'));
$result.=<
@@ -6248,13 +6272,13 @@ function sanitycheck() {
-
-
-
-
-
-
-
+
+
+
+
+
+
+
ENDUPFORM
@@ -6268,43 +6292,51 @@ sub process_clicker_file {
my ($r)=@_;
my ($symb)=&get_symb($r);
if (!$symb) {return '';}
+
+ my %Saveable_Parameters=&clicker_grading_parameters();
+ &Apache::loncommon::store_course_settings('grades_clicker',
+ \%Saveable_Parameters);
+
my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
if (($env{'form.gradingmechanism'} eq 'specific') && ($env{'form.specificid'}!~/\w/)) {
- $result.=''.&mt('You need to specify a clicker ID for the correct answer').'';
- return $result.&show_grading_menu_form($symb);
+ $result.=''.&mt('You need to specify a clicker ID for the correct answer').'';
+ return $result.&show_grading_menu_form($symb);
}
my %clicker_ids=&gather_clicker_ids();
- my %correct_ids=();
+ my %correct_ids;
if ($env{'form.gradingmechanism'} eq 'personnel') {
- %correct_ids=&gather_adv_clicker_ids();
+ %correct_ids=&gather_adv_clicker_ids();
}
if ($env{'form.gradingmechanism'} eq 'specific') {
- my $correct_id=$env{'form.specificid'};
- $correct_id=~tr/a-z/A-Z/;
- $correct_id=~s/\s//gs;
- $correct_id=~s/^0+//;
- $correct_ids{$correct_id}='specified';
+ foreach my $correct_id (split(/[\s\,]/,$env{'form.specificid'})) {;
+ $correct_id=~tr/a-z/A-Z/;
+ $correct_id=~s/\s//gs;
+ $correct_id=~s/^[\#0]+//;
+ if ($correct_id) {
+ $correct_ids{$correct_id}='specified';
+ }
+ }
}
if ($env{'form.gradingmechanism'} eq 'attendance') {
- $result.=&mt('Score based on attendance only');
+ $result.=&mt('Score based on attendance only');
} else {
- my $number=0;
- $result.='
'.&mt('Correctness determined by the following IDs').'
';
- foreach my $id (sort(keys(%correct_ids))) {
- $result.=''.$id.' - ';
- if ($correct_ids{$id} eq 'specified') {
- $result.=&mt('specified');
- } else {
- my ($uname,$udom)=split(/\:/,$correct_ids{$id});
- $result.=&Apache::loncommon::plainname($uname,$udom);
- }
- $result.=' ';
- $number++;
- }
- if ($number==0) {
- $result.=''.&mt('No IDs found to determine correct answer').'';
- return $result.&show_grading_menu_form($symb);
- }
+ my $number=0;
+ $result.='
'.&mt('Correctness determined by the following IDs').'';
+ foreach my $id (sort(keys(%correct_ids))) {
+ $result.=' '.$id.' - ';
+ if ($correct_ids{$id} eq 'specified') {
+ $result.=&mt('specified');
+ } else {
+ my ($uname,$udom)=split(/\:/,$correct_ids{$id});
+ $result.=&Apache::loncommon::plainname($uname,$udom);
+ }
+ $number++;
+ }
+ $result.="
\n";
+ if ($number==0) {
+ $result.=''.&mt('No IDs found to determine correct answer').'';
+ return $result.&show_grading_menu_form($symb);
+ }
}
if (length($env{'form.upfile'}) < 2) {
$result.=&mt('[_1] Error: [_2] The file you attempted to upload, [_3] contained no information. Please check that you entered the correct filename.',
@@ -6313,17 +6345,80 @@ sub process_clicker_file {
''.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'');
return $result.&show_grading_menu_form($symb);
}
- my %responses=();
- my @questiontitles=();
+
+# Were able to get all the info needed, now analyze the file
+
+ $result.=&Apache::loncommon::studentbrowser_javascript();
+ my $heading=&mt('Scanning clicker file');
+ $result.=(<
+
+$heading
+
'."\n".
+ '
'."\n";
return $result.&show_grading_menu_form($symb);
}
@@ -6332,32 +6427,71 @@ sub iclicker_eval {
my $number=0;
my $errormsg='';
foreach my $line (split(/[\n\r]/,$env{'form.upfile'})) {
- chomp($line);
- foreach my $quoted ($line=~/\,\s*\"([^\"]*)\"\s*\,/g) {
- my $replace=$quoted;
- $replace=~s/\,//g;
- &Apache::lonnet::logthis($quoted.' - '.$replace.' ');
- $line=~s/\,\s*\"\Q$quoted\E\"\s*\,/,$replace,/gs;
- }
- my @entries=split(/\,/,$line);
- if ($entries[0] eq 'Question') {
- for (my $i=3;$i<$#entries;$i+=6) {
- $$questiontitles[$number]=$entries[$i];
- $number++;
+ my %components=&Apache::loncommon::record_sep($line);
+ my @entries=map {$components{$_}} (sort(keys(%components)));
+ if ($entries[0] eq 'Question') {
+ for (my $i=3;$i<$#entries;$i+=6) {
+ $$questiontitles[$number]=$entries[$i];
+ $number++;
+ }
+ }
+ if ($entries[0]=~/^\#/) {
+ my $id=$entries[0];
+ my @idresponses;
+ $id=~s/^[\#0]+//;
+ for (my $i=0;$i<$number;$i++) {
+ my $idx=3+$i*6;
+ push(@idresponses,$entries[$idx]);
+ }
+ $$responses{$id}=join(',',@idresponses);
+ }
+ }
+ return ($errormsg,$number);
+}
+
+sub assign_clicker_grades {
+ my ($r)=@_;
+ my ($symb)=&get_symb($r);
+ if (!$symb) {return '';}
+ my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
+ my $heading=&mt('Assigning grades based on clicker file');
+ $result.=(<
+
+$heading
+ENDHEADER
+# Get correct result
+# FIXME: Possibly need delimiter other than ":"
+ my @correct=();
+ if ($env{'form.gradingmechanism'} ne 'attendance') {
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.correct\:/) {
+ my @input=split(/\,/,$env{$key});
+ for (my $i=0;$i<=$#input;$i++) {
+ if (($correct[$i]) && ($input[$i]) &&
+ ($correct[$i] ne $input[$i])) {
+ $result.=' '.
+ &mt('More than one correct result given for question "[_1]": [_2] versus [_3].',
+ $env{'form.question:'.$i},$correct[$i],$input[$i]).'';
+ } elsif ($input[$i]) {
+ $correct[$i]=$input[$i];
+ }
+ }
}
}
- if ($entries[0]=~/^\#/) {
- my $id=$entries[0];
- my @idresponses=();
- $id=~s/^[\#0]+//;
- for (my $i=0;$i<$number;$i++) {
- my $idx=3+$i*6;
- push(@idresponses,$entries[$idx]);
+ for (my $i=0;$i<$env{'form.number'};$i++) {
+ if (!$correct[$i]) {
+ $result.=' '.
+ &mt('No correct result given for question "[_1]"!',
+ $env{'form.question:'.$i}).'';
}
- $$responses{$id}=join(',',@idresponses);
}
+ $result.=' '.&mt("Correct answer: [_1]",join(', ',map { ($_?$_:'-') } @correct));
}
- return ($errormsg,$number);
+# Start grading
+ $result.='