--- loncom/homework/grades.pm 2007/10/08 22:29:59 1.446 +++ loncom/homework/grades.pm 2007/10/09 09:16:04 1.447 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.446 2007/10/08 22:29:59 banghart Exp $ +# $Id: grades.pm,v 1.447 2007/10/09 09:16:04 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -47,11 +47,88 @@ use POSIX qw(floor); my %perm=(); -my %bubble_lines_per_response; # no. bubble lines for each response. +my %bubble_lines_per_response = (); # no. bubble lines for each response. # index is "symb.part_id" +my %first_bubble_line = (); # First bubble line no. for each bubble. + +# Save and restore the bubble lines array to the form env. + + +sub save_bubble_lines { + + foreach my $line (keys(%bubble_lines_per_response)) { + $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line}; + $env{"form.scantron.first_bubble_line.$line"} = + $first_bubble_line{$line}; + } +} + + +sub restore_bubble_lines { + my $line = 0; + %bubble_lines_per_response = (); + while ($env{"form.scantron.bubblelines.$line"}) { + my $value = $env{"form.scantron.bubblelines.$line"}; + $bubble_lines_per_response{$line} = $value; + $first_bubble_line{$line} = + $env{"form.scantron.first_bubble_line.$line"}; + $line++; + } + +} + +# Given the parsed scanline, get the response for +# 'answer' number n: + +sub get_response_bubbles { + my ($parsed_line, $response) = @_; + + my $bubble_line = $first_bubble_line{$response}; + my $bubble_lines= $bubble_linse_per_response{$response}; + my $selected = ""; + + for (my $bline = 0; $bline < $bubble_lines; $bline++) { + $selected .= $$parsed_line{"scantron.$bubble_line.answer"}; + $bubble_line++; + } + return $selected; +} + # ----- These first few routines are general use routines.---- + +# Return the number of occurences of a pattern in a string. + +sub occurence_count { + my ($string, $pattern) = @_; + + my @matches = ($string =~ /$pattern/g); + + return scalar(@matches); +} + + +# Take a string known to have digits and convert all the +# digits into letters in the range J,A..I. + +sub digits_to_letters { + my ($input) = @_; + + my @alphabet = ('J', 'A'..'I'); + + my @input = split(//, $input); + my $output =''; + for (my $i = 0; $i < scalar(@input); $i++) { + if ($input[$i] =~ /\d/) { + $output .= $alphabet[$input[$i]]; + } else { + $output .= $input[$i]; + } + } + return $output; +} + # # --- Retrieve the parts from the metadata file.--- sub getpartlist { @@ -531,6 +608,8 @@ 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. @@ -2789,7 +2868,6 @@ sub version_selected_portfile { my $new_answer; $env{'form.copy'} = &Apache::lonnet::getfile("/uploaded/$domain/$stu_name/portfolio$directory$file_name"); if($env{'form.copy'} eq '-1') { - &Apache::lonnet::logthis('problem getting file '.$file_name); $new_answer = 'problem getting file'; } else { $new_answer = $answer_name.'.'.$version.'.'.$answer_ext; @@ -3823,7 +3901,6 @@ sub csvuploadassign { } if (! %grades) { push(@skipped,"$username:$domain no data to save"); } $grades{"resource.regrader"}="$env{'user.name'}:$env{'user.domain'}"; -# &Apache::lonnet::logthis(" storing ".(join('-',%grades))); my $result=&Apache::lonnet::cstore(\%grades,$symb, $env{'request.course.id'}, $domain,$username); @@ -4176,7 +4253,6 @@ sub displaySubByDates { my $where = ($isTask ? "$version:resource.$interaction" : "$version:resource"); - #&Apache::lonnet::logthis(" got $where"); $studentTable.='
Please indicate which bubble should be used for grading
"); foreach my $question (@{$arg}) { - my $selected=$$scan_record{"scantron.$question.answer"}; + + my $selected = &get_response_bubbles($scan_record, $question); &scantron_bubble_selector($r,$scan_config,$question, split('',$selected)); } @@ -6228,7 +6401,7 @@ ENDSCRIPT $r->print(''); foreach my $question (@{$arg}) { - my $selected=$$scan_record{"scantron.$question.answer"}; + my $selected = &get_response_bubbles($scan_record, $quesion); &scantron_bubble_selector($r,$scan_config,$question); } } else { @@ -6250,21 +6423,21 @@ ENDSCRIPT $scan_config - hash from &get_scantron_config() $quest - number of the bubble line to make a corrector for $selected - array of letters of previously selected bubbles - $lines - if present, number of bubble lines to show =cut sub scantron_bubble_selector { - my ($r,$scan_config,$quest,@selected, $lines)=@_; + my ($r,$scan_config,$quest,@selected)=@_; my $max=$$scan_config{'Qlength'}; my $scmode=$$scan_config{'Qon'}; + + if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; } - if (!defined($lines)) { - $lines = 1; - } + my $lines = $bubble_lines_per_response{$quest}; + my $total_lines = $lines*2; my @alphabet=('A'..'Z'); $r->print("$quest | "); @@ -6438,6 +6611,8 @@ sub scantron_validate_CODE { my %allcodes=&get_codes(); + &scantron_get_maxbubble(); # parse needs the lines per response array. + my ($scanlines,$scan_data)=&scantron_getfile(); for (my $i=0;$i<=$scanlines->{'count'};$i++) { my $line=&scantron_get_line($scanlines,$scan_data,$i); @@ -6490,6 +6665,9 @@ sub scantron_validate_doublebubble { #get scantron line setup my %scantron_config=&get_scantron_config($env{'form.scantron_format'}); my ($scanlines,$scan_data)=&scantron_getfile(); + + &scantron_get_maxbubble(); # parse needs the bubble line array. + for (my $i=0;$i<=$scanlines->{'count'};$i++) { my $line=&scantron_get_line($scanlines,$scan_data,$i); if ($line=~/^[\s\cz]*$/) { next; } @@ -6513,7 +6691,11 @@ sub scantron_validate_doublebubble { resource and then checking &Apache::lonxml::get_problem_counter() for what the current value of the problem counter is. - Caches the result to $env{'form.scantron_maxbubble'} + Caches the results to $env{'form.scantron_maxbubble'}, + $env{'form.scantron.bubble_lines.n'} and + $env{'form.scantron.first_bubble_line.n'} + which are the total number of bubble, lines, the number of bubble + lines for reponse n and number of the first bubble line for response n. =cut @@ -6521,13 +6703,14 @@ sub scantron_get_maxbubble { if (defined($env{'form.scantron_maxbubble'}) && $env{'form.scantron_maxbubble'}) { + &restore_bubble_lines(); return $env{'form.scantron_maxbubble'}; } - my $navmap=Apache::lonnavmaps::navmap->new(); - my (undef,undef,$sequence)= + my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'}); + my $navmap=Apache::lonnavmaps::navmap->new(); my $map=$navmap->getResourceByUrl($sequence); my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0); @@ -6538,9 +6721,14 @@ sub scantron_get_maxbubble { my $cid = $env{'request.course.id'}; my $total_lines = 0; %bubble_lines_per_response = (); + %first_bubble_line = (); + + my $response_number = 0; + my $bubble_line = 0; foreach my $resource (@resources) { my $symb = $resource->symb(); + &Apache::lonxml::clear_bubble_lines_for_part(); my $result=&Apache::lonnet::ssi($resource->src(), ('symb' => $resource->symb()), ('grade_target' => 'analyze'), @@ -6555,16 +6743,25 @@ sub scantron_get_maxbubble { foreach my $part_id (@{$analysis{'parts'}}) { - my $bubble_lines = $analysis{"$part_id.bubble_lines"}[0]; - if (!$bubble_lines) { - $bubble_lines = 1; - } - $bubble_lines_per_response{"$symb.$part_id"} = $bubble_lines; - $total_lines = $total_lines + $bubble_lines; + my ($trash, $part) = split(/\./, $part_id); + + my $lines = $analysis{"$part_id.bubble_lines"}[0]; + + # TODO - make this a persistent hash not an array. + + + $first_bubble_line{$response_number} = $bubble_line; + $bubble_lines_per_response{$response_number} = $lines; + $response_number++; + + $bubble_line += $lines; + $total_lines += $lines; } } &Apache::lonnet::delenv('scantron\.'); + + &save_bubble_lines(); $env{'form.scantron_maxbubble'} = $total_lines; return $env{'form.scantron_maxbubble'}; @@ -6575,7 +6772,8 @@ sub scantron_get_maxbubble { =item scantron_validate_missingbubbles Validates all scanlines in the selected file to not have any - bubble lines with missing bubbles that haven't been verified as missing. + answers that don't have bubbles that have not been verified + to be bubble free. =cut @@ -6669,6 +6867,9 @@ SCANTRONFORM my $start=&Time::HiRes::time(); my $i=-1; my ($uname,$udom,$started); + + &scantron_get_maxbubble(); # Need the bubble lines array to parse. + while ($i<$scanlines->{'count'}) { ($uname,$udom)=('',''); $i++; @@ -6719,8 +6920,6 @@ SCANTRONFORM } my $result=&Apache::lonnet::ssi($resource->src(),%form); if ($result ne '') { - &Apache::lonnet::logthis("scantron grading error -> $result"); - &Apache::lonnet::logthis("scantron grading error info name $uname domain $udom course $env{'request.course.id'} url ".$resource->src()); } if (&Apache::loncommon::connection_aborted($r)) { last; } } @@ -7798,6 +7997,7 @@ ENDHEADER sub handler { my $request=$_[0]; + &reset_caches(); if ($env{'browser.mathml'}) { &Apache::loncommon::content_type($request,'text/xml'); @@ -7810,9 +8010,12 @@ sub handler { my $symb=&get_symb($request,1); my @commands=&Apache::loncommon::get_env_multiple('form.command'); my $command=$commands[0]; + if ($#commands > 0) { &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands)); } + + $request->print(&Apache::loncommon::start_page('Grading')); if ($symb eq '' && $command eq '') { if ($env{'user.adv'}) { @@ -7890,6 +8093,7 @@ sub handler { } elsif ($command eq 'csvuploadassign' && $perm{'mgr'} ) { $request->print(&csvuploadassign($request)); } elsif ($command eq 'scantron_selectphase' && $perm{'mgr'}) { + &Apache::lonnet::logthis("Selecting pyhase"); $request->print(&scantron_selectphase($request)); } elsif ($command eq 'scantron_warning' && $perm{'mgr'}) { $request->print(&scantron_do_warning($request));