--- loncom/homework/grades.pm 2003/09/29 21:31:30 1.130.2.1.2.6 +++ loncom/homework/grades.pm 2003/08/18 18:24:32 1.134 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.130.2.1.2.6 2003/09/29 21:31:30 albertel Exp $ +# $Id: grades.pm,v 1.134 2003/08/18 18:24:32 www Exp $ # # Copyright Michigan State University Board of Trustees # @@ -544,7 +544,7 @@ LISTJAVASCRIPT $gradeTable.='" />'."\n"; - + $gradeTable.='Check For Plagiarism'; my (undef, undef, $fullname) = &getclasslist($getsec,'1'); $gradeTable.='
'.
'
'.$line.''); - substr($line,$where-1,$length)=$answer; - Apache->request->print('a: '.$line.''); - } - return $line; -} - -sub scan_data { - my ($scan_data,$key,$value,$delete)=@_; - my $filename=$ENV{'form.scantron_selectfile'}; - if (defined($value)) { - $scan_data->{$filename.'_'.$key} = $value; - } - if ($delete) { delete($scan_data->{$filename.'_'.$key}); } - return $scan_data->{$filename.'_'.$key}; -} - sub scantron_parse_scanline { - my ($line,$whichline,$scantron_config,$scan_data)=@_; + my ($line,$scantron_config)=@_; my %record; my $questions=substr($line,$$scantron_config{'Qstart'}-1); my $data=substr($line,0,$$scantron_config{'Qstart'}-1); @@ -3332,15 +3275,6 @@ sub scantron_parse_scanline { } $record{'scantron.ID'}=substr($data,$$scantron_config{'IDstart'}-1, $$scantron_config{'IDlength'}); - $record{'scantron.PaperID'}= - substr($data,$$scantron_config{'PaperID'}-1, - $$scantron_config{'PaperIDlength'}); - $record{'scantron.FirstName'}= - substr($data,$$scantron_config{'FirstName'}-1, - $$scantron_config{'FirstNamelength'}); - $record{'scantron.LastName'}= - substr($data,$$scantron_config{'LastName'}-1, - $$scantron_config{'LastNamelength'}); my @alphabet=('A'..'Z'); my $questnum=0; while ($questions) { @@ -3348,48 +3282,31 @@ sub scantron_parse_scanline { my $currentquest=substr($questions,0,$$scantron_config{'Qlength'}); substr($questions,0,$$scantron_config{'Qlength'})=''; if (length($currentquest) < $$scantron_config{'Qlength'}) { next; } - my @array=split($$scantron_config{'Qon'},$currentquest,-1); + my (@array)=split(/$$scantron_config{'Qon'}/,$currentquest); + if (scalar(@array) gt 2) { + #FIXME do something intelligent with double bubbles + Apache->request->print(" Wha!!! ".scalar(@array). + '-'.$currentquest.'-'.$questnum.' '); + } if (length($array[0]) eq $$scantron_config{'Qlength'}) { $record{"scantron.$questnum.answer"}=''; - if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) { - push(@{$record{"scantron.missingerror"}},$questnum); - } } else { $record{"scantron.$questnum.answer"}=$alphabet[length($array[0])]; } - if (scalar(@array) gt 2) { - push(@{$record{'scantron.doubleerror'}},$questnum); - my @ans=@array; - my $i=length($ans[0]);shift(@ans); - while (@ans) { - $i+=length($ans[0])+1; - $record{"scantron.$questnum.answer"}.=$alphabet[$i]; - shift(@ans); - } - } } $record{'scantron.maxquest'}=$questnum; return \%record; } sub scantron_add_delay { - my ($delayqueue,$scanline,$errormessage,$errorcode)=@_; - Apache->request->print('add_delay_error '.$_[2] ); - push(@$delayqueue, - {'line' => $scanline, 'emsg' => $errormessage, - 'ecode' => $errorcode } - ); } sub scantron_find_student { my ($scantron_record,$idmap)=@_; my $scanID=$$scantron_record{'scantron.ID'}; foreach my $id (keys(%$idmap)) { - #Apache->request->print(' checking studnet -'.$id.'- againt -'.$scanID.'-'); - if (lc($id) eq lc($scanID)) { - #Apache->request->print('success'); - return $$idmap{$id}; - } + Apache->request->print(' checking studnet -'.$id.'- againt -'.$scanID.'-'); + if (lc($id) eq lc($scanID)) { Apache->request->print('success');return $$idmap{$id}; } } return undef; } @@ -3402,366 +3319,6 @@ sub scantron_filter { return 0; } -#FIXME I think I am doing this in the wrong order, I think it would be -#better to make a several passes analyzing all of the lines in the -#file for common errors wrong/invalid PID/username duplicated -#PID/username, missing bubbles, double bubbles, missing/invalid CODE -#and then get the instructor to fix all of these errors, then grade -#the corrected one, I'll still need to catch error conditions, but -#maybe most will taken care even before we start - -sub scantron_process_corrections { - my ($r) = @_; - my %scantron_config=&get_scantron_config($ENV{'form.scantron_format'}); - my ($scanlines,$scan_data)=&scantron_getfile(); - my $classlist=&Apache::loncoursedata::get_classlist(); - my $which=$ENV{'form.scantron_line'}; - my $line=&scantron_get_line($scanlines,$which); - my ($skip,$err,$errmsg); - if ($ENV{'form.scantron_skip_record'}) { - $skip=1; - } elsif ($ENV{'form.scantron_corrections'} =~ /^(duplicate|incorrect)ID$/) { - my $newstudent=$ENV{'form.scantron_username'}.':'. - $ENV{'form.scantron_domain'}; - my $newid=$classlist->{$newstudent}->[&Apache::loncoursedata::CL_ID]; - ($line,$err,$errmsg)= - &scantron_fixup_scanline(\%scantron_config,$scan_data,$line,$which, - 'ID',$newid); - } elsif ($ENV{'form.scantron_corrections'} =~ /^(missing|double)bubble$/) { - foreach my $question (split(',',$ENV{'form.scantron_questions'})) { - ($line,$err,$errmsg)= - &scantron_fixup_scanline(\%scantron_config,$scan_data,$line, - $which,'answer',$question, - $ENV{"form.scantron_correct_Q_$question"}); - if ($err) { last; } - } - } - if ($err) { - $r->print("Unable to accept last correction, an error occurred :$errmsg:"); - } else { - &scantron_put_line($scanlines,$which,$line,$skip); - &scantron_putfile($scanlines,$scan_data); - } -} - - -sub scantron_validate_file { - my ($r) = @_; - my ($symb,$url)=&get_symb_and_url($r); - if (!$symb) {return '';} - my $default_form_data=&defaultFormData($symb,$url); - - if ($ENV{'form.scantron_corrections'}) { - &scantron_process_corrections($r); - } - #get the student pick code ready - $r->print(&Apache::loncommon::studentbrowser_javascript()); - my $result= < Checking ID ".$$scan_record{'scantron.ID'}. - " on paper ID ".$$scan_record{'scantron.PaperID'}." \n"); - my $found; - foreach my $checkid (keys(%idmap)) { - if (lc($checkid) eq lc($id)) { - if ($checkid ne $id) { - $r->print("Using $checkid for encoded $id \n"); - } - $found=$checkid;last; - } - } - if ($found) { - if ($found{'ids'}{$found}) { - #FIXME store away line we prviously saw the ID on - &scantron_get_correction($r,$i,$scan_record,\%scantron_config, - $line,'duplicateID',$found); - return(1); - } else { - $found{'ids'}{$found}++; - } - } else { - &scantron_get_correction($r,$i,$scan_record,\%scantron_config, - $line,'incorrectID'); - return(1); - } - } - - return (0,$currentphase+1); -} - -sub scantron_get_correction { - my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_; - -#FIXME in the case of a duplicated ID the previous line, probaly need -#to show both the current line and the previous one and allow skipping -#the previous one or the current one - - $r->print("This scantron record has an error ($error). "); - if ( defined($$scan_record{'scantron.PaperID'}) ) { - $r->print("The current PaperID is ". - $$scan_record{'scantron.PaperID'}." \n"); - } else { - $r->print("The current scanline is ". - $line."\n"); - } - $r->print(''."\n"); - $r->print(''."\n"); - if ($error =~ /ID$/) { - if ($error eq 'unknownID') { - $r->print("The encoded ID is not in the classlist\n"); - } elsif ($error eq 'duplicateID') { - $r->print("The encoded ID has also been used by a previous paper $arg\n"); - } - $r->print(" Original ID is ".$$scan_record{'scantron.ID'}.
- " Please correct
For question $question, selected bubbles were ".
- join(" ",split('',$selected)).
- " Question $question, Please select a bubble to use "); - &scantron_bubble_selector($r,$scan_config,$question); - } - } else { - $r->print("\n
'); -} - -sub scantron_validate_CODE { - my ($r,$currentphase) = @_; - #FIXME doesn't do anything yet - return (0,$currentphase+1); -} - -sub scantron_validate_doublebubble { - my ($r,$currentphase) = @_; - #get student info - my $classlist=&Apache::loncoursedata::get_classlist(); - my %idmap=&username_to_idmap($classlist); - - #get scantron line setup - my %scantron_config=&get_scantron_config($ENV{'form.scantron_format'}); - my ($scanlines,$scan_data)=&scantron_getfile(); - for (my $i=0;$i<=$scanlines->{'count'};$i++) { - my $line=&scantron_get_line($scanlines,$i); - if (!$line) { next; } - my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config, - $scan_data); - if (!defined($$scan_record{'scantron.doubleerror'})) { next; } - &scantron_get_correction($r,$i,$scan_record,\%scantron_config,$line, - 'doublebubble', - $$scan_record{'scantron.doubleerror'}); - return (1,$currentphase); - } - return (0,$currentphase+1); -} - -sub scantron_validate_missingbubbles { - my ($r,$currentphase) = @_; - #get student info - my $classlist=&Apache::loncoursedata::get_classlist(); - my %idmap=&username_to_idmap($classlist); - - #get scantron line setup - my %scantron_config=&get_scantron_config($ENV{'form.scantron_format'}); - my ($scanlines,$scan_data)=&scantron_getfile(); - my $max_bubble=$ENV{'form.scantron_maxbubble'}; - if (!$max_bubble) { $max_bubble=2**31; } - for (my $i=0;$i<=$scanlines->{'count'};$i++) { - my $line=&scantron_get_line($scanlines,$i); - if (!$line) { next; } - my $scan_record=&scantron_parse_scanline($line,$i,\%scantron_config, - $scan_data); - if (!defined($$scan_record{'scantron.missingerror'})) { next; } - my @to_correct; - foreach my $missing (@{$$scan_record{'scantron.missingerror'}}) { - if ($missing gt $max_bubble) { next; } - push(@to_correct,$missing); - } - if (@to_correct) { - &scantron_get_correction($r,$i,$scan_record,\%scantron_config, - $line,'missingbubble',\@to_correct); - return (1,$currentphase); - } - - } - return (0,$currentphase+1); -} - -sub scantron_end_validate_form { - my ($r) = @_; - $r->print(' |