'.''."\n".
'';
$result.='';
+ 'onClick="javascript:resetEntry('.$ctsparts.');" target="_self" />';
#table listing all the students in a section/class
#header of table
@@ -3087,7 +3087,7 @@ sub viewgrades {
$result.='';
$result.=''."\n";
$result.=''."\n";
+ 'onClick="javascript:submit();" target="_self" />'."\n";
if (scalar(%$fullname) eq 0) {
my $colspan=3+scalar(@parts);
$result='There are no students in section "'.$env{'form.section'}.
@@ -3107,7 +3107,7 @@ sub viewstudentgrade {
''.
"\n".$ctr.'
'."\n";
$student=~s/:/_/; # colon doen't work in javascript for names
foreach my $apart (@$parts) {
@@ -6144,7 +6144,7 @@ sub gather_clicker_ids {
my $clickers =
(&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;
} else {
@@ -6160,13 +6160,13 @@ sub gather_adv_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];
foreach my $id (split(/\,/,$clickers)) {
- $id=~s/^0+//;
+ $id=~s/^[\#0]+//;
if (exists($clicker_ids{$id})) {
$clicker_ids{$id}.=','.$puname.':'.$pudom;
} else {
@@ -6178,6 +6178,14 @@ sub gather_adv_clicker_ids {
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,14 +6199,30 @@ 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',
+ my $selectform=&Apache::loncommon::select_form($env{'form.upfiletype'},'upfiletype',
('iclicker' => 'i>clicker'));
$result.=<
-
-
-
-
-
-
-
+
+
+
+
+
+
+
ENDUPFORM
@@ -6268,6 +6292,11 @@ 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').'';
@@ -6279,28 +6308,31 @@ sub process_clicker_file {
%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');
} else {
my $number=0;
- $result.='
'.&mt('Correctness determined by the following IDs').'
';
+ $result.='
'.&mt('Correctness determined by the following IDs').'';
foreach my $id (sort(keys(%correct_ids))) {
- $result.=''.$id.' - ';
+ $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++;
}
+ $result.="
\n";
if ($number==0) {
$result.=''.&mt('No IDs found to determine correct answer').'';
return $result.&show_grading_menu_form($symb);
@@ -6313,6 +6345,24 @@ sub process_clicker_file {
''.&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').'');
return $result.&show_grading_menu_form($symb);
}
+
+# 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,14 +6427,8 @@ 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);
+ 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];
@@ -6360,6 +6449,99 @@ sub iclicker_eval {
return ($errormsg,$number);
}
+sub assign_clicker_grades {
+ my ($r)=@_;
+ my ($symb)=&get_symb($r);
+ if (!$symb) {return '';}
+# See which part we are saving to
+ my ($partlist,$handgrade,$responseType) = &response_type($symb);
+# FIXME: This should probably look for the first handgradeable part
+ my $part=$$partlist[0];
+# Start screen output
+ 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=();
+ my $gradingmechanism=$env{'form.gradingmechanism'};
+ my $number=$env{'form.number'};
+ if ($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];
+ }
+ }
+ }
+ }
+ for (my $i=0;$i<$number;$i++) {
+ if (!$correct[$i]) {
+ $result.=' '.
+ &mt('No correct result given for question "[_1]"!',
+ $env{'form.question:'.$i}).'';
+ }
+ }
+ $result.=' '.&mt("Correct answer: [_1]",join(', ',map { ($_?$_:'-') } @correct));
+ }
+# Start grading
+ my $pcorrect=$env{'form.pcorrect'};
+ my $pincorrect=$env{'form.pincorrect'};
+ my $storecount=0;
+ foreach my $key (keys(%env)) {
+ if ($key=~/^form\.student\:(.*)$/) {
+ my $user=$1;
+ my @answer=split(/\,/,$env{$key});
+ my $sum=0;
+ for (my $i=0;$i<$number;$i++) {
+ if ($answer[$i]) {
+ if ($gradingmechanism eq 'attendance') {
+ $sum+=$pcorrect;
+ } else {
+ if ($answer[$i] eq $correct[$i]) {
+ $sum+=$pcorrect;
+ } else {
+ $sum+=$pincorrect;
+ }
+ }
+ }
+ }
+ my $ave=$sum/(100*$number);
+# Store
+ my ($username,$domain)=split(/\:/,$user);
+ my %grades=();
+ $grades{"resource.$part.solved"}='correct_by_override';
+ $grades{"resource.$part.awarded"}=$ave;
+ $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}";
+ my $returncode=&Apache::lonnet::cstore(\%grades,$symb,
+ $env{'request.course.id'},
+ $domain,$username);
+ if ($returncode ne 'ok') {
+ $result.=" Failed to save student $username:$domain. Message when trying to save was ($returncode)";
+ } else {
+ $storecount++;
+ }
+ }
+ }
+# We are done
+ $result.=' '.&mt('Successfully stored grades for [_1] student(s).',$storecount).
+ '