--- loncom/homework/grades.pm 2013/06/28 22:54:50 1.596.2.12.2.16 +++ loncom/homework/grades.pm 2011/11/29 17:00:19 1.664 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.596.2.12.2.16 2013/06/28 22:54:50 raeburn Exp $ +# $Id: grades.pm,v 1.664 2011/11/29 17:00:19 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -43,6 +43,8 @@ use Apache::lonmsg(); use Apache::Constants qw(:common :http); use Apache::lonlocal; use Apache::lonenc; +use Apache::lonstathelpers; +use Apache::lonquickgrades; use Apache::bridgetask(); use String::Similarity; use LONCAPA; @@ -52,7 +54,6 @@ use POSIX qw(floor); my %perm=(); -my %old_essays=(); # These variables are used to recover from ssi errors @@ -98,6 +99,9 @@ sub ssi_print_error { # # --- Retrieve the parts from the metadata file.--- +# Returns an array of everything that the resources stores away +# + sub getpartlist { my ($symb,$errorref) = @_; @@ -122,24 +126,6 @@ sub getpartlist { return @stores; } -# --- Get the symbolic name of a problem and the url -sub get_symb { - my ($request,$silent) = @_; - my $symb=$env{'form.symb'}; - unless ($symb) { - (my $url=$env{'form.url'}) =~ s-^http://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--; - $symb = &Apache::lonnet::symbread($url); - if ($symb eq '') { - if (!$silent) { - $request->print(&mt("Unable to handle ambiguous references: [_1].",$url)); - return (); - } - } - } - &Apache::lonenc::check_decrypt(\$symb); - return ($symb); -} - #--- Format fullname, username:domain if different for display #--- Use anywhere where the student names are listed sub nameUserString { @@ -154,6 +140,7 @@ sub nameUserString { #--- Get the partlist and the response type for a given problem. --- #--- Indicate if a response type is coded handgraded or not. --- +#--- Sets response_error pointer to "1" if navmaps object broken --- sub response_type { my ($symb,$response_error) = @_; @@ -212,59 +199,9 @@ sub get_display_part { return $display; } -#--- Show resource title -#--- and parts and response type -sub showResourceInfo { - my ($symb,$probTitle,$checkboxes,$res_error) = @_; - my $result = '
'.&mt('No grading privileges').'
'); return; } else { $request->print(''."\n"); } # essay grading message center - if ($env{'form.handgrade'} eq 'yes') { +# if ($env{'form.handgrade'} eq 'yes') { + if (1) { my $result=''.&mt('[_1]Message:[_2] No more students for this section or class.','','').'
'."\n"; - $the_end.=&mt('Click on the button below to return to the grading menu.').''.&mt('[_1]Message:[_2] No more students for this section or class.','','').'
'."\n"; $request->print($the_end); } return ''; @@ -3193,8 +2896,8 @@ sub handback_files { my $part_resp = join('_',@{ $part_response_id }); if (($env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'} =~ /^\d+$/) & ($new_part eq $part_id)) { for (my $counter=1; $counter<=$env{'form.'.$newflg.'_'.$part_resp.'_countreturndoc'}; $counter++) { - # if multiple files are uploaded names will be 'returndoc2','returndoc3' - if ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter}) { + # if multiple files are uploaded names will be 'returndoc2','returndoc3' + if ($env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter}) { my $fname=$env{'form.'.$newflg.'_'.$part_resp.'_returndoc'.$counter.'.filename'}; my ($directory,$answer_file) = ($env{'form.'.$newflg.'_'.$part_resp.'_origdoc'.$counter} =~ /^(.*?)([^\/]*)$/); @@ -3202,11 +2905,11 @@ sub handback_files { &file_name_version_ext($answer_file); my ($portfolio_path) = ($directory =~ /^.+$stuname\/portfolio(.*)/); my $getpropath = 1; - my ($dir_list,$listerror) = + my ($dir_list,$listerror) = &Apache::lonnet::dirlist($portfolio_root.$portfolio_path, $domain,$stuname,$getpropath); my $version = &get_next_version($answer_name,$answer_ext,$dir_list); - # fix filename + # fix file name my ($save_file_name) = (($directory.$answer_name.".$version.".$answer_ext) =~ /^.+\/${stuname}\/(.*)/); my $result=&Apache::lonnet::finishuserfileupload($stuname,$domain, $newflg.'_'.$part_resp.'_returndoc'.$counter, @@ -3223,10 +2926,9 @@ sub handback_files { $$newrecord{"resource.$new_part.$resp_id.handback"}.=','; } $$newrecord{"resource.$new_part.$resp_id.handback"} .= $save_file_name; - $file_msg.=''.$save_file_name."'.
&mt('Number of records updated = [_1] for [quant,_2,student].',
$rec_update,$count).'
'.
@@ -4190,21 +3886,14 @@ sub csvuploadmap_header {
$javascript=&csvupload_javascript_forward_associate();
}
- my ($result) = &showResourceInfo($symb,$env{'form.probTitle'});
- my $checked=(($env{'form.noFirstLine'})?' checked="checked"':'');
- my $ignore=&mt('Ignore First Line');
$symb = &Apache::lonenc::check_encrypt($symb);
+ $request->print('
". &mt("Failed to save data for student [_1]. Message when trying to save was: [_2]", "$username:$domain",$result)."
"); } $request->rflush(); - $countdone++; } } $request->print(''.&mt("If this information is correct, please click on '[_1]'.",&mt($button_text)).'
-'.&mt("If something is incorrect, please click the 'Grading Menu' button to start over.").'
+ '.&mt('If this information is correct, please click on \'[_1]\'.',&mt($button_text)).'
+'.&mt('If something is incorrect, please return to [_1]Grade/Manage/Review Bubblesheets[_2] to start over.','','').'
'.&mt("You have not selected the format of the student's response data.").'
'); } } else { - my $warning=&scantron_warning_screen('Grading: Validate Records'); + my $warning=&scantron_warning_screen('Grading: Validate Records',$symb); my $bubbledbyhand=&hand_bubble_option(); $r->print(' '.$warning.$bubbledbyhand.' @@ -6765,7 +6285,7 @@ sub scantron_do_warning { '); } - $r->print("".&mt("Or click the 'Grading Menu' button to start over.")."
"); + $r->print(''.&mt('Or return to [_1]Grade/Manage/Review Bubblesheets[_2] to start over.','','').'
'); } else { if ($validate_phases[$currentphase] eq 'doublebubble' || $validate_phases[$currentphase] eq 'missingbubbles') { $r->print(''); @@ -6921,7 +6437,7 @@ sub scantron_validate_file { $r->print(" ".&mt("this scanline saving it for later.")); } } - $r->print("' - .&mt('Some resources in the sequence currently are not set to' - .' exam mode. Grading these resources currently may not' - .' work correctly.') - .'
' - ); + $r->print("".&mt('Some resources in the sequence currently are not set to exam mode. Grading these resources currently may not work correctly.')."
"); return (1,$currentphase); } } @@ -7374,8 +6885,7 @@ sub scantron_validate_ID { sub scantron_get_correction { - my ($r,$i,$scan_record,$scan_config,$line,$error,$arg, - $randomorder,$randompick,$respnumlookup,$startline)=@_; + my ($r,$i,$scan_record,$scan_config,$line,$error,$arg)=@_; #FIXME in the case of a duplicated ID the previous line, probably need #to show both the current line and the previous one and allow skipping #the previous one or the current one @@ -7399,7 +6909,7 @@ sub scantron_get_correction { .&mt('The ID on the form is [_1]', "$$scan_record{'scantron.ID'}") .''.&mt("The encoded ID is not in the classlist"). + $r->print('
'.&mt("The encoded ID is not in the classlist"). "
\n"); } elsif ($error eq 'duplicateID') { - $r->print(''.&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."
\n"); + $r->print(''.&mt("The encoded ID has also been used by a previous paper [_1]",$arg)."
\n"); } $r->print($message); $r->print("".&mt("How should I handle this?")."
\n");
@@ -7425,7 +6935,7 @@ sub scantron_get_correction {
$r->print(&Apache::loncommon::selectstudent_link('scantronupload',
'scantron_username','scantron_domain'));
$r->print(": ");
- $r->print("\n:\n".
+ $r->print("\n@".
&Apache::loncommon::select_dom_form($env{'request.role.domain'},'scantron_domain'));
$r->print('');
@@ -7435,8 +6945,8 @@ sub scantron_get_correction {
} elsif ($error eq 'duplicateCODE') {
$r->print('
'.&mt("The encoded CODE has also been used by a previous paper [_1], and CODEs are supposed to be unique.",join(', ',@{$arg}))."
\n"); } - $r->print("".&mt('The CODE on the form is [_1]', - "'$$scan_record{'scantron.CODE'}'") + $r->print("
".&mt('The CODE on the form is [_1]', + "'$$scan_record{'scantron.CODE'}'") ."
\n"); $r->print($message); $r->print("".&mt("How should I handle this?")."
\n"); @@ -7472,8 +6982,7 @@ sub scantron_get_correction { $r->print("\n".&mt("Please indicate which bubble should be used for grading")."
"); foreach my $question (@{$arg}) { my @linenums = &prompt_for_corrections($r,$question,$scan_config, - $scan_record, $error, - $randomorder,$randompick, - $respnumlookup,$startline); + $scan_record, $error); push(@lines_to_correct,@linenums); } $r->print(&verify_bubbles_checked(@lines_to_correct)); @@ -7536,16 +7041,13 @@ ENDSCRIPT # a list of question numbers. Therefore: # - my $line_list = &questions_to_line_list($arg,$randomorder,$randompick, - $respnumlookup,$startline); + my $line_list = &questions_to_line_list($arg); $r->print(''); foreach my $question (@{$arg}) { my @linenums = &prompt_for_corrections($r,$question,$scan_config, - $scan_record, $error, - $randomorder,$randompick, - $respnumlookup,$startline); + $scan_record, $error); push(@lines_to_correct,@linenums); } $r->print(&verify_bubbles_checked(@lines_to_correct)); @@ -7559,8 +7061,7 @@ sub verify_bubbles_checked { my (@ansnums) = @_; my $ansnumstr = join('","',@ansnums); my $warning = &mt("A bubble or 'No bubble' selection has not been made for one or more lines."); - my $output = (<took $lasttime
"); $r->print(""); - $r->print(&show_grading_menu_form($symb)); return ''; } @@ -8610,8 +7946,7 @@ sub graders_resources_pass { my $ressymb = $resource->symb(); my ($analysis,$parts) = &scantron_partids_tograde($resource,$env{'request.course.id'}, - $env{'user.name'},$env{'user.domain'}, - 1,$bubbles_per_row); + $env{'user.name'},$env{'user.domain'},1,$bubbles_per_row); $grader_partids_by_symb->{$ressymb} = $parts; if (ref($analysis) eq 'HASH') { if (ref($analysis->{'parts_withrandomlist'}) eq 'ARRAY') { @@ -8624,67 +7959,9 @@ sub graders_resources_pass { return; } -=pod - -=item users_order - - Returns array of resources in current map, ordered based on either CODE, - if this is a CODEd exam, or based on student's identity if this is a - "NAMEd" exam. - - Should be used when randomorder and/or randompick applied when the - corresponding exam was printed, prior to students completing bubblesheets - for the version of the exam the student received. - -=cut - -sub users_order { - my ($user,$scancode,$mapurl,$master_seq,$symb_to_resource,$orderedforcode) = @_; - my @mapresources; - unless ((ref($master_seq) eq 'ARRAY') && (ref($symb_to_resource) eq 'HASH')) { - return @mapresources; - } - if ($scancode) { - if ((ref($orderedforcode) eq 'HASH') && (ref($orderedforcode->{$scancode}) eq 'ARRAY')) { - @mapresources = @{$orderedforcode->{$scancode}}; - } else { - $env{'form.CODE'} = $scancode; - my $actual_seq = - &Apache::lonprintout::master_seq_to_person_seq($mapurl, - $master_seq, - $user,$scancode,1); - if (ref($actual_seq) eq 'ARRAY') { - @mapresources = map { $symb_to_resource->{$_}; } @{$actual_seq}; - if (ref($orderedforcode) eq 'HASH') { - if (@mapresources > 0) { - $orderedforcode->{$scancode} = \@mapresources; - } - } - } - delete($env{'form.CODE'}); - } - } else { - my $actual_seq = - &Apache::lonprintout::master_seq_to_person_seq($mapurl, - $master_seq, - $user,undef,1); - if (ref($actual_seq) eq 'ARRAY') { - @mapresources = - map { $symb_to_resource->{$_}; } @{$actual_seq}; - } - } - return @mapresources; -} - sub grade_student_bubbles { - my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row, - $randomorder,$randompick,$respnumlookup,$startline) = @_; - my $uselookup = 0; - if (($randomorder || $randompick) && (ref($respnumlookup) eq 'HASH') && - (ref($startline) eq 'HASH')) { - $uselookup = 1; - } - + my ($r,$uname,$udom,$scan_record,$scancode,$resources,$parts,$bubbles_per_row) = @_; +# Walk folder as student here to get resources in order student sees. if (ref($resources) eq 'ARRAY') { my $count = 0; foreach my $resource (@{$resources}) { @@ -8706,12 +7983,8 @@ sub grade_student_bubbles { if (ref($parts) eq 'HASH') { if (ref($parts->{$ressymb}) eq 'ARRAY') { foreach my $part (@{$parts->{$ressymb}}) { - if ($uselookup) { - $form{'scantron_questnum_start.'.$part} = $startline->{$count} + 1; - } else { - $form{'scantron_questnum_start.'.$part} = - 1+$env{'form.scantron.first_bubble_line.'.$count}; - } + $form{'scantron_questnum_start.'.$part} = + 1+$env{'form.scantron.first_bubble_line.'.$count}; $count++; } } @@ -8725,7 +7998,7 @@ sub grade_student_bubbles { } sub scantron_upload_scantron_data { - my ($r)=@_; + my ($r,$symb)=@_; my $dom = $env{'request.role.domain'}; my $domdesc = &Apache::lonnet::domain($dom,'description'); $r->print(&Apache::loncommon::coursebrowser_javascript($dom)); @@ -8733,13 +8006,11 @@ sub scantron_upload_scantron_data { 'domainid', 'coursename',$dom); my $syllabuslink = ''.&mt('Syllabus').''. - (' 'x2).&mt('(shows course personnel)'); - my ($symb) = &get_symb($r,1); + (' 'x2).&mt('(shows course personnel)'); my $default_form_data=&defaultFormData($symb); my $nofile_alert = &mt('Please use the browse button to select a file from your local directory.'); my $nocourseid_alert = &mt("Please use the 'Select Course' link to open a separate window where you can search for a course to which a file can be uploaded."); - $r->print(' - - +')); + $r->print('- '.&mt('The requested filename was invalid.').' + '.&mt('The requested file name was invalid.').'
'); - $r->print(&show_grading_menu_form($symb)); return; } my $orig='/uploaded/'.$cdom.'/'.$cname.'/scantron_orig_'.$file; @@ -8974,15 +8240,12 @@ sub scantron_download_scantron_data { '','').' '); - $r->print(&show_grading_menu_form($symb)); return ''; } sub checkscantron_results { - my ($r) = @_; - my ($symb)=&get_symb($r); + my ($r,$symb) = @_; if (!$symb) {return '';} - my $grading_menu_button=&show_grading_menu_form($symb); my $cid = $env{'request.course.id'}; my %lettdig = &letter_to_digits(); my $numletts = scalar(keys(%lettdig)); @@ -9002,19 +8265,10 @@ sub checkscantron_results { return ''; } my $map=$navmap->getResourceByUrl($sequence); - my ($randomorder,$randompick,@master_seq,%symb_to_resource,%grader_partids_by_symb, - %grader_randomlists_by_symb,%orderedforcode); - if (ref($map)) { - $randomorder=$map->randomorder(); - } my @resources=$navmap->retrieveResources($map,\&scantron_filter,1,0); - my $nav_error = &get_master_seq(\@resources,\@master_seq,\%symb_to_resource); - if ($nav_error) { - $r->print(&navmap_errormsg()); - return ''; - } - &graders_resources_pass(\@resources,\%grader_partids_by_symb, - \%grader_randomlists_by_symb,$bubbles_per_row); + my (%grader_partids_by_symb,%grader_randomlists_by_symb); + &graders_resources_pass(\@resources,\%grader_partids_by_symb, \%grader_randomlists_by_symb); + my ($uname,$udom); my (%scandata,%lastname,%bylast); $r->print(' @@ -9023,9 +8277,12 @@ sub checkscantron_results { my @delayqueue; my %completedstudents; - my $count=&get_todo_count($scanlines,$scan_data); - my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count); - my ($username,$domain,$started,%ordered); + my $count=&Apache::grades::get_todo_count($scanlines,$scan_data); + my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,'Bubblesheet/Submissions Comparison Status', + 'Progress of Bubblesheet Data/Submission Records Comparison',$count, + 'inline',undef,'checkscantron'); + my ($username,$domain,$started); + my $nav_error; &scantron_get_maxbubble(\$nav_error,\%scantron_config); # Need the bubble lines array to parse. if ($nav_error) { $r->print(&navmap_errormsg()); @@ -9050,8 +8307,8 @@ sub checkscantron_results { my $scan_record= &Apache::grades::scantron_parse_scanline($line,$i,\%scantron_config, $scan_data); - unless ($uname=&scantron_find_student($scan_record,$scan_data, - \%idmap,$i)) { + unless ($uname=&Apache::grades::scantron_find_student($scan_record,$scan_data, + \%idmap,$i)) { &Apache::grades::scantron_add_delay(\@delayqueue,$line, 'Unable to find a student that matches',1); next; @@ -9064,57 +8321,26 @@ sub checkscantron_results { my $pid = $scan_record->{'scantron.ID'}; $lastname{$pid} = $scan_record->{'scantron.LastName'}; push(@{$bylast{$lastname{$pid}}},$pid); - my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION]; - my $user = $uname.':'.$usec; - ($username,$domain)=split(/:/,$uname); - - my $scancode; - if ((exists($scan_record->{'scantron.CODE'})) && - (&Apache::lonnet::validCODE($scan_record->{'scantron.CODE'}))) { - $scancode = $scan_record->{'scantron.CODE'}; - } else { - $scancode = ''; - } - - my @mapresources = @resources; my $lastpos = $env{'form.scantron_maxbubble'}*$scantron_config{'Qlength'}; - my %respnumlookup=(); - my %startline=(); - if ($randomorder || $randompick) { - @mapresources = - &users_order($user,$scancode,$sequence,\@master_seq,\%symb_to_resource, - \%orderedforcode); - my $total = &get_respnum_lookups($sequence,$scan_data,\%idmap,$line, - $scan_record,\@master_seq,\%symb_to_resource, - \%grader_partids_by_symb,\%orderedforcode, - \%respnumlookup,\%startline); - if ($randompick && $total) { - $lastpos = $total*$scantron_config{'Qlength'}; - } - } $scandata{$pid} = substr($line,$scantron_config{'Qstart'}-1,$lastpos); chomp($scandata{$pid}); $scandata{$pid} =~ s/\r$//; - + ($username,$domain)=split(/:/,$uname); my $counter = -1; - foreach my $resource (@mapresources) { + foreach my $resource (@resources) { my $parts; my $ressymb = $resource->symb(); if ((exists($grader_randomlists_by_symb{$ressymb})) || (ref($grader_partids_by_symb{$ressymb}) ne 'ARRAY')) { (my $analysis,$parts) = - &scantron_partids_tograde($resource,$env{'request.course.id'}, - $username,$domain,undef, - $bubbles_per_row); + &scantron_partids_tograde($resource,$env{'request.course.id'},$username,$domain,undef,$bubbles_per_row); } else { $parts = $grader_partids_by_symb{$ressymb}; } ($counter,my $recording) = &verify_scantron_grading($resource,$domain,$username,$cid,$counter, $scandata{$pid},$parts, - \%scantron_config,\%lettdig,$numletts, - $randomorder,$randompick, - \%respnumlookup,\%startline); + \%scantron_config,\%lettdig,$numletts); $record{$pid} .= $recording; } } @@ -9152,19 +8378,16 @@ sub checkscantron_results { } } } - $r->print(''. - &mt('Comparison of bubblesheet data (including corrections) with corresponding submission records (most recent submission) for [_1][quant,_2,student][_3] ([quant,_4,bubblesheet line] per student).', - '', - $numstudents, - '', - $env{'form.scantron_maxbubble'}). - '
' + $r->print( + '' + .&mt('Comparison of bubblesheet data (including corrections) with corresponding submission records (most recent submission) for [_1][quant,_2,student][_3] ([quant,_4,bubblesheet line] per student).', + '', + $numstudents, + '', + $env{'form.scantron_maxbubble'}) + .'
' ); - $r->print(''
- .&mt('Exact matches for [_1][quant,_2,student][_3].','',$passed,'')
- .'
'
- .&mt('Discrepancies detected for [_1][quant,_2,student][_3].','',$failed,'')
- .'
'.&mt('Exact matches for [quant,_1,student].',$passed).'
'.&mt('Discrepancies detected for [quant,_1,student].',$failed).'
'."\n";
- $result.='
|
-
|
'.&mt('Access Denied ([_1])',$command).'
'); } } if ($ssi_error) { &ssi_print_error($request); } + &Apache::lonquickgrades::endGradeScreen($request); $request->print(&Apache::loncommon::end_page()); &reset_caches(); return OK; @@ -10546,16 +9666,6 @@ ssi_with_retries() - missingbubble - array ref of the bubble lines that have missing bubble errors - $randomorder - True if exam folder has randomorder set - $randompick - True if exam folder has randompick set - $respnumlookup - Reference to HASH mapping question numbers in bubble lines - for current line to question number used for same question - in "Master Seqence" (as seen by Course Coordinator). - $startline - Reference to hash where key is question number (0 is first) - and value is number of first bubble line for current student - or code-based randompick and/or randomorder. - - =item scantron_get_maxbubble() : Arguments: @@ -10576,7 +9686,7 @@ ssi_with_retries() $env{'form.scantron.bubble_lines.n'}, $env{'form.scantron.first_bubble_line.n'} and $env{"form.scantron.sub_bubblelines.n"} - which are the total number of bubble lines, the number of bubble + which are the total number of bubble, lines, the number of bubble lines for response n and number of the first bubble line for response n, and a comma separated list of numbers of bubble lines for sub-questions (for optionresponse, matchresponse, and rankresponse items), for response n.