--- loncom/homework/grades.pm 2007/05/20 21:10:46 1.400 +++ loncom/homework/grades.pm 2007/06/15 22:00:42 1.406 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.400 2007/05/20 21:10:46 www Exp $ +# $Id: grades.pm,v 1.406 2007/06/15 22:00:42 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -180,7 +180,7 @@ sub showResourceInfo { if (exists($partsseen{$partID})) { $result.=" "; } else { - $result.=""; + $result.=""; } $partsseen{$partID}=1; } @@ -708,16 +708,16 @@ LISTJAVASCRIPT &commonJSfunctions($request); $request->print($result); - my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked' : ''; - my $checklastsub = $checkhdgrade eq '' ? 'checked' : ''; + my $checkhdgrade = ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1 ) ? 'checked="checked"' : ''; + my $checklastsub = $checkhdgrade eq '' ? 'checked="checked"' : ''; my $gradeTable='
'. "\n".$table. - ' View Problem Text: '."\n". + ' View Problem Text: '."\n". ''."\n". '
'."\n". ' View Answer: '."\n". ''."\n". - '
'."\n". + '
'."\n". ' Submissions: '."\n"; if ($env{'form.handgrade'} eq 'yes' && scalar(@$partlist) > 1) { $gradeTable.=''."\n"; @@ -763,7 +763,7 @@ LISTJAVASCRIPT 'onClick="javascript:checkSelect(this.form.stuinfo);" '."\n". 'value="Next->" />
'."\n"; $gradeTable.=&check_buttons(); - $gradeTable.=''; + $gradeTable.=''; my ($classlist, undef, $fullname) = &getclasslist($getsec,'1'); $gradeTable.='
'. ''; @@ -1501,7 +1501,7 @@ sub gradeBox { $result.= '\n"; + ($score eq $thisweight ? 'checked="checked"':'').' /> '.$thisweight."\n"; $result.=(($ctr+1)%10 == 0 ? '' : ''); $thisweight += $increment; $ctr++; @@ -1519,9 +1519,9 @@ sub gradeBox { 'onChange="javascript:clearRadBox(this.form,\''.$counter.'_'.$partid.'\')" >'."\n"; if ($$record{'resource.'.$partid.'.solved'} eq 'excused') { $result.=''. - ''; + ''; } else { - $result.=''. + $result.=''. ''; } $result.=''."\n"; @@ -1959,8 +1959,8 @@ KEYWORDS ($env{'form.lastSub'} eq 'hdgrade' && $$handgrade{$$part[0].'_'.$$part[1]} eq 'yes')) { my $display_part=&get_display_part($partid,$symb); - $lastsubonly.=''. ''."\n"; @@ -3146,8 +3146,8 @@ sub viewstudentgrade { $result.='  \n"; } else { @@ -3848,7 +3848,7 @@ LISTJAVASCRIPT foreach (@$titles) { my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/); $result.=''."\n"; $ctr++; } @@ -3863,12 +3863,12 @@ LISTJAVASCRIPT $result.=''."\n". ''."\n"; - $result.=' View Problems Text: '."\n". + $result.=' View Problems Text: '."\n". ''."
\n"; $result.=' Submission Details: '. ''."\n". - ''."\n". + ''."\n". ''."\n"; $result.=''."\n". @@ -4384,7 +4384,7 @@ sub getSequenceDropDown { foreach (@$titles) { my ($minder,$showtitle) = ($_ =~ /(\d+)\.(.*)/); $result.=''."\n"; $ctr++; } @@ -4412,7 +4412,7 @@ sub scantron_uploads { my $result= '"; return $result; @@ -4963,7 +4963,7 @@ sub remember_current_skipped { sub check_for_error { my ($r,$result)=@_; if ($result ne 'ok' && $result ne 'not_found' ) { - $r->print("An error occured ($result) when trying to Remove the existing corrections."); + $r->print("An error occurred ($result) when trying to Remove the existing corrections."); } } @@ -5425,7 +5425,7 @@ sub scantron_get_correction { if ($closest > 0) { foreach my $testcode (@{$closest}) { my $checked=''; - if (!$i) { $checked=' checked="on" '; } + if (!$i) { $checked=' checked="checked" '; } $r->print(""); $r->print("\n
"); $i++; @@ -5433,7 +5433,7 @@ sub scantron_get_correction { } } if ($$scan_record{'scantron.CODE'}=~/\S/ ) { - my $checked; if (!$i) { $checked=' checked="on" '; } + my $checked; if (!$i) { $checked=' checked="checked" '; } $r->print(""); $r->print("\n
"); } @@ -6033,38 +6033,38 @@ GRADINGMENUJS if (ref($sections)) { foreach (sort (@$sections)) { $result.=''."\n"; + ($saveSec eq $_ ? 'selected="selected"':'').'>'.$_.''."\n"; } } - $result.= '   '; + $result.= '   '; - $result.=&mt('Student Status').':'.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,undef); + $result.=&mt('Student Status').':'.&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,1,undef); $result.=''; $result.=''."\n"; + ($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').''."\n"; $result.=''."\n"; $result.=''."\n"; $result.=''."\n"; -# $result.=''."\n"; - + $result.=''."\n"; $result.=''."\n"; - $result.='
Debug -'.'Part: '. - $display_part.' ( hhhh ID '.$respid. + $lastsubonly.='
Part: '. + $display_part.' ( ID '.$respid. ' )   '; my $files=&get_submitted_files($udom,$uname,$partid,$respid,\%record); if (@$files) { @@ -2082,7 +2082,7 @@ KEYWORDS ''. ''."\n"; my $nsel = ($env{'form.NTSTU'} ne '' ? $env{'form.NTSTU'} : '1'); - $ntstu =~ s/
'. '
'. '

'. @@ -6078,10 +6078,9 @@ GRADINGMENUJS ''. ' '.&mt('scores from file').'
'. -# ''. -# ' '.&mt('clicker file').'
'. + ''. + ' '.&mt('clicker file').'
'. ' saved CODEs.
'."\n". + $result.='
'."\n". ''."\n". - ''."\n"; + ''."\n"; return $result; } @@ -6146,6 +6145,7 @@ sub gather_clicker_ids { my $clickers = (&Apache::lonnet::userenvironment($domain,$username,'clickers'))[1]; foreach my $id (split(/\,/,$clickers)) { + $id=~s/^0+//; if (exists($clickerids{$id})) { $clickerids{$id}.=','.$username.':'.$domain; } else { @@ -6156,6 +6156,29 @@ sub gather_clicker_ids { return %clickerids; } +sub gather_adv_clicker_ids { + my %clickerids=(); + 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 $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+//; + if (exists($clickerids{$id})) { + $clickerids{$id}.=','.$puname.':'.$pudom; + } else { + $clickerids{$id}=$puname.':'.$pudom; + } + } + } + } + return %clickerids; +} + sub process_clicker { my ($r)=@_; my ($symb)=&get_symb($r); @@ -6171,10 +6194,54 @@ sub process_clicker { $result.=''."\n"; 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 $pcorrect=&mt("Percentage points for correct solution"); + my $pincorrect=&mt("Percentage points for incorrect solution"); my $selectform=&Apache::loncommon::select_form('iclicker','upfiletype', - ('iclicker' => 'iClicker')); + ('iclicker' => 'i>clicker')); $result.=< +function sanitycheck() { +// Accept only integer percentages + document.forms.gradesupload.pcorrect.value=Math.round(document.forms.gradesupload.pcorrect.value); + document.forms.gradesupload.pincorrect.value=Math.round(document.forms.gradesupload.pincorrect.value); +// Find out grading choice + for (i=0; i
@@ -6182,6 +6249,13 @@ sub process_clicker {
+
+
+
+ + +
+

ENDUPFORM @@ -6196,12 +6270,92 @@ sub process_clicker_file { my ($symb)=&get_symb($r); if (!$symb) {return '';} my ($result) = &showResourceInfo($symb,$env{'form.probTitle'}); - $result.=&show_grading_menu_form($symb); + 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); + } my %clickerids=&gather_clicker_ids(); - foreach my $key (keys %clickerids) { - $result.='
'.$key.' - '.$clickerids{$key}; + my %correctids=(); + if ($env{'form.gradingmechanism'} eq 'personnel') { + %correctids=&gather_adv_clicker_ids(); + } + if ($env{'form.gradingmechanism'} eq 'specific') { + my $correctid=$env{'form.specificid'}; + $correctid=~tr/a-z/A-Z/; + $correctid=~s/\s//gs; + $correctid=~s/^0+//; + $correctids{$correctid}='specified'; } - return $result; + 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').'

'; + foreach my $id (sort(keys(%correctids))) { + $result.=''.$id.' - '; + if ($correctids{$id} eq 'specified') { + $result.=&mt('specified'); + } else { + my ($uname,$udom)=split(/\:/,$correctids{$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); + } + } + if (length($env{'form.upfile'}) < 2) { + $result.="Error: The file you attempted to upload, ".&HTML::Entities::encode($env{'form.upfile.filename'},'<>&"').", contained no information. Please check that you entered the correct filename."; + return $result.&show_grading_menu_form($symb); + } + my %responses=(); + my @questiontitles=(); + my $errormsg=''; + my $number=0; + if ($env{'form.upfiletype'} eq 'iclicker') { + ($errormsg,$number)=&iclicker_eval(\@questiontitles,\%responses); + } + $result.='
'.&mt('Found [_1] questions',$number).'
'; + foreach my $id (keys %responses) { + $result.='
'.$id.' - '.$responses{$id}; + } + return $result.&show_grading_menu_form($symb); +} + +sub iclicker_eval { + my ($questiontitles,$responses)=@_; + 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++; + } + } + 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 handler {