--- loncom/homework/grades.pm 2018/10/08 19:11:01 1.752 +++ loncom/homework/grades.pm 2021/01/23 20:24:53 1.782 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.752 2018/10/08 19:11:01 raeburn Exp $ +# $Id: grades.pm,v 1.782 2021/01/23 20:24:53 raeburn Exp $ # # Copyright Michigan State University Board of Trustees # @@ -48,6 +48,8 @@ use Apache::lonquickgrades; use Apache::bridgetask(); use Apache::lontexconvert(); use String::Similarity; +use HTML::Parser(); +use File::MMagic; use LONCAPA; use POSIX qw(floor); @@ -145,7 +147,7 @@ sub nameUserString { } #--- Get the partlist and the response type for a given problem. --- -#--- Indicate if a response type is coded handgraded or not. --- +#--- Count responseIDs, essayresponse items, and dropbox items --- #--- Sets response_error pointer to "1" if navmaps object broken --- sub response_type { my ($symb,$response_error) = @_; @@ -163,6 +165,7 @@ sub response_type { return; } my $partlist = $res->parts(); + my ($numresp,$numessay,$numdropbox) = (0,0,0); my %vPart = map { $_ => 1 } (&Apache::loncommon::get_env_multiple('form.vPart')); my (%response_types,%handgrade); @@ -172,13 +175,20 @@ sub response_type { my @types = $res->responseType($part); my @ids = $res->responseIds($part); for (my $i=0; $i < scalar(@ids); $i++) { + $numresp ++; $response_types{$part}{$ids[$i]} = $types[$i]; + if ($types[$i] eq 'essay') { + $numessay ++; + if (&Apache::lonnet::EXT("resource.$part".'_'.$ids[$i].".uploadedfiletypes",$symb)) { + $numdropbox ++; + } + } $handgrade{$part.'_'.$ids[$i]} = &Apache::lonnet::EXT('resource.'.$part.'_'.$ids[$i]. '.handgrade',$symb); } } - return ($partlist,\%handgrade,\%response_types); + return ($partlist,\%handgrade,\%response_types,$numresp,$numessay,$numdropbox); } sub flatten_responseType { @@ -205,6 +215,129 @@ sub get_display_part { return $display; } +#--- Show parts and response type +sub showResourceInfo { + my ($symb,$partlist,$responseType,$formname,$checkboxes,$uploads) = @_; + unless ((ref($partlist) eq 'ARRAY') && (ref($responseType) eq 'HASH')) { + return ''; + } + my $coltitle = &mt('Problem Part Shown'); + if ($checkboxes) { + $coltitle = &mt('Problem Part'); + } else { + my $checkedparts = 0; + foreach my $partid (&Apache::loncommon::get_env_multiple('form.vPart')) { + if (grep(/^\Q$partid\E$/,@{$partlist})) { + $checkedparts ++; + } + } + if ($checkedparts == scalar(@{$partlist})) { + return ''; + } + if ($uploads) { + $coltitle = &mt('Problem Part Selected'); + } + } + my $result = '
'. + &mt('No dropbox items or essayresponse items with uploadedfiletypes set.'). + '
'.&keywords_highlight($answer).'
' .&mt('Part(s) graded correct by the computer is marked with a [_1] symbol.',$checkIcon) ."
'. - &keywords_highlight($oessay). - '
'. + &keywords_highlight($oessay). + '
'.&mt("Please double check the information below before clicking on '[_1]'",&mt($button_text)).' @@ -7087,9 +7207,7 @@ sub scantron_warning_screen {
'.&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 a file that contains the student's response data.").'
'.&mt("You have not selected the format of the student's response data.").'
'.$table.'
'. + &mt('You have role(s) in [quant,_1,other section,other sections] with privileges to manage grades.', + scalar(@possibles)).''. + &mt('Check which of those section(s), in addition to section [_1], you wish to grade using this bubblesheet file:', + ''.$checksec.'').' '; + foreach my $sec (sort {$a <=> $b } @possibles) { + $gradesections .= ''.$sec.''.(' 'x2); + } + $gradesections .= '
'.&mt('The selected file is unavailable').'
'.&mt('Gathering necessary information.').'
'. + &mt('Numbers of records for students in sections not being graded [_1]', + $seclist). + '
'. &mt('If you have already graded these by bubbling sheets to indicate points awarded, [_1]what point value is assigned to a filled last bubble in each row?',''). @@ -8712,7 +9016,7 @@ sub scantron_process_students { } my $default_form_data=&defaultFormData($symb); - my %scantron_config=&get_scantron_config($env{'form.scantron_format'}); + my %scantron_config=&Apache::lonnet::get_scantron_config($env{'form.scantron_format'}); my $bubbles_per_row = &bubblesheet_bubbles_per_row(\%scantron_config); my ($scanlines,$scan_data)=&scantron_getfile(); my $classlist=&Apache::loncoursedata::get_classlist(); @@ -8752,9 +9056,10 @@ sub scantron_process_students { SCANTRONFORM $r->print($result); + my ($checksec,@possibles)=&gradable_sections(); my @delayqueue; my (%completedstudents,%scandata); - + my $lock=&Apache::lonnet::set_lock(&mt('Grading bubblesheet exam')); my $count=&get_todo_count($scanlines,$scan_data); my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin($r,$count); @@ -8780,7 +9085,7 @@ SCANTRONFORM return ''; # Dunno why the other returns return '' rather than just returning. } - my %lettdig = &letter_to_digits(); + my %lettdig = &Apache::lonnet::letter_to_digits(); my $numletts = scalar(keys(%lettdig)); my %orderedforcode; @@ -8814,6 +9119,13 @@ SCANTRONFORM next; } my $usec = $classlist->{$uname}->[&Apache::loncoursedata::CL_SECTION]; + if (($checksec ne '') && ($checksec ne $usec)) { + unless (grep(/^\Q$usec\E$/,@possibles)) { + &scantron_add_delay(\@delayqueue,$line, + "No role with manage grades privilege in student's section ($usec)",3); + next; + } + } my $user = $uname.':'.$usec; ($uname,$udom)=split(/:/,$uname); @@ -9105,8 +9417,9 @@ sub grade_student_bubbles { } sub scantron_upload_scantron_data { - my ($r,$symb)=@_; + my ($r,$symb) = @_; my $dom = $env{'request.role.domain'}; + my ($formatoptions,$formattitle,$formatjs) = &scantron_upload_dataformat($dom); my $domdesc = &Apache::lonnet::domain($dom,'description'); $r->print(&Apache::loncommon::coursebrowser_javascript($dom)); my $select_link=&Apache::loncommon::selectcourse_link('rules','courseid', @@ -9146,6 +9459,7 @@ sub scantron_upload_scantron_data { return; } + '.$formatjs.' ')); $r->print('
'.&mt('You do not have permission to upload bubblesheet data').'
'. + &mt('Comparison of student IDs in the uploaded file with the course roster found [_1][quant,_2,match,matches][_3] for students in section(s) for which none of your role(s) have privileges to modify grades', + '',$counts{$max_match_format}{'othersec'},''). + ''. + &mt('Unless you are assigned role(s) which allow modification of grades in additional sections, [_1] of the records in this file will be automatically excluded when you perform bubblesheet grading.',''.$showpct.''). + '
'. + &mt('If you prefer to delete the file now, use: [_1]'). + '
'.&mt('Uploaded file contained no data').'
'. + &mt('The original uploaded file includes [_1] or more of records for students for which none of your roles have rights to modify grades, so files are unavailable for download.',$showpct). + '
'. + &Apache::lonhtmlcommon::confirm_success( + &mt('File format is neither csv (iclicker 6) nor xml (iclicker 7)'),1).'
'. + &Apache::lonhtmlcommon::confirm_success( + &mt('Invalid clicker type: choose one of: i>clicker, Interwrite PRS, or Turning Technologies.'),1).'