--- loncom/homework/grades.pm 2007/10/09 10:31:21 1.448 +++ loncom/homework/grades.pm 2007/10/25 20:05:52 1.464 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.448 2007/10/09 10:31:21 foxr Exp $ +# $Id: grades.pm,v 1.464 2007/10/25 20:05:52 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -35,6 +35,7 @@ use Apache::loncommon; use Apache::lonhtmlcommon; use Apache::lonnavmaps; use Apache::lonhomework; +use Apache::lonpickcode; use Apache::loncoursedata; use Apache::lonmsg(); use Apache::Constants qw(:common); @@ -56,9 +57,7 @@ my %first_bubble_line = (); # First bubb sub save_bubble_lines { - &Apache::lonnet::logthis("Saving bubble_lines..."); foreach my $line (keys(%bubble_lines_per_response)) { - &Apache::lonnet::logthis("Saving form.scantron.bubblelines.$line value: $bubble_lines_per_response{$line}"); $env{"form.scantron.bubblelines.$line"} = $bubble_lines_per_response{$line}; $env{"form.scantron.first_bubble_line.$line"} = $first_bubble_line{$line}; @@ -71,7 +70,6 @@ sub restore_bubble_lines { %bubble_lines_per_response = (); while ($env{"form.scantron.bubblelines.$line"}) { my $value = $env{"form.scantron.bubblelines.$line"}; - &Apache::lonnet::logthis("Restoring form.scantron.bubblelines.$line value: $value"); $bubble_lines_per_response{$line} = $value; $first_bubble_line{$line} = $env{"form.scantron.first_bubble_line.$line"}; @@ -86,12 +84,14 @@ sub restore_bubble_lines { sub get_response_bubbles { my ($parsed_line, $response) = @_; - my $bubble_line = $first_bubble_line{$response}; - my $bubble_lines= $bubble_lines_per_response{$response}; + + my $bubble_line = $first_bubble_line{$response-1} +1; + my $bubble_lines= $bubble_lines_per_response{$response-1}; + my $selected = ""; for (my $bline = 0; $bline < $bubble_lines; $bline++) { - $selected .= $$parsed_line{"scantron.$bubble_line.answer"}; + $selected .= $$parsed_line{"scantron.$bubble_line.answer"}.":"; $bubble_line++; } return $selected; @@ -475,8 +475,9 @@ COMMONJSFUNCTIONS #--- Dumps the class list with usernames,list of sections, #--- section, ids and fullnames for each user. sub getclasslist { - my ($getsec,$filterlist) = @_; + my ($getsec,$filterlist,$getgroup) = @_; my @getsec; + my @getgroup; my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status')); if (!ref($getsec)) { if ($getsec ne '' && $getsec ne 'all') { @@ -486,10 +487,19 @@ sub getclasslist { @getsec=@{$getsec}; } if (grep(/^all$/,@getsec)) { undef(@getsec); } + if (!ref($getgroup)) { + if ($getgroup ne '' && $getgroup ne 'all') { + @getgroup=($getgroup); + } + } else { + @getgroup=@{$getgroup}; + } + if (grep(/^all$/,@getgroup)) { undef(@getgroup); } - my $classlist=&Apache::loncoursedata::get_classlist(); + my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist(); # Bail out if we were unable to get the classlist return if (! defined($classlist)); + &Apache::loncoursedata::get_group_memberships($classlist,$keylist); # my %sections; my %fullnames; @@ -506,18 +516,40 @@ sub getclasslist { $classlist->{$student}->[&Apache::loncoursedata::CL_FULLNAME()]; my $status = $classlist->{$student}->[&Apache::loncoursedata::CL_STATUS()]; + my $group = + $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()]; # filter students according to status selected if ($filterlist && (!($stu_status =~ /Any/))) { if (!($stu_status =~ $status)) { - delete ($classlist->{$student}); + delete($classlist->{$student}); next; } } + # filter students according to groups selected + my @stu_groups = split(/,/,$group); + if (@getgroup) { + my $exclude = 1; + foreach my $grp (@getgroup) { + foreach my $stu_group (@stu_groups) { + if ($stu_group eq $grp) { + $exclude = 0; + } + } + if (($grp eq 'none') && !$group) { + $exclude = 0; + } + } + if ($exclude) { + delete($classlist->{$student}); + } + } $section = ($section ne '' ? $section : 'none'); if (&canview($section)) { if (!@getsec || grep(/^\Q$section\E$/,@getsec)) { $sections{$section}++; - $fullnames{$student}=$fullname; + if ($classlist->{$student}) { + $fullnames{$student}=$fullname; + } } else { delete($classlist->{$student}); } @@ -768,8 +800,8 @@ sub listStudents { my $cdom = $env{"course.$env{'request.course.id'}.domain"}; my $cnum = $env{"course.$env{'request.course.id'}.num"}; my $getsec = $env{'form.section'} eq '' ? 'all' : $env{'form.section'}; + my $getgroup = $env{'form.group'} eq '' ? 'all' : $env{'form.group'}; my $submitonly= $env{'form.submitonly'} eq '' ? 'all' : $env{'form.submitonly'}; - my $viewgrade = $env{'form.showgrading'} eq 'yes' ? 'View/Grade/Regrade' : 'View'; $env{'form.probTitle'} = $env{'form.probTitle'} eq '' ? &Apache::lonnet::gettitle($symb) : $env{'form.probTitle'}; @@ -869,7 +901,7 @@ LISTJAVASCRIPT 'value="Next->" />
'."\n"; $gradeTable.=&check_buttons(); $gradeTable.=''; - my ($classlist, undef, $fullname) = &getclasslist($getsec,'1'); + my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup); $gradeTable.=''); } - - # FIXME: This loop probably has to be considerably more clever for - # multiline bubbles: User can multibubble by having bubbles in - # several lines. User can skip lines legitimately etc. etc. - + my @selected = split(//,$lines[$l]); for (my $i=0;$i<$max;$i++) { $r->print("\n".'
'. ''; my $loop = 0; @@ -944,7 +976,7 @@ LISTJAVASCRIPT $ctr++; my $section = $classlist->{$student}->[&Apache::loncoursedata::CL_SECTION()]; - + my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()]; if ( $perm{'vgr'} eq 'F' ) { $gradeTable.='' if ($ctr%2 ==1); $gradeTable.=''. @@ -952,7 +984,7 @@ LISTJAVASCRIPT $student.':'.$$fullname{$student}.':::SECTION'.$section. ') " />  '."\n".''."\n"; + ' '.$section.'/'.$group.''."\n"; if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') { foreach (sort keys(%status)) { @@ -1784,7 +1816,6 @@ sub build_section_inputs { # --------------------------- show submissions of a student, option to grade sub submission { my ($request,$counter,$total) = @_; - my ($uname,$udom) = ($env{'form.student'},$env{'form.userdom'}); $udom = ($udom eq '' ? $env{'user.domain'} : $udom); #has form.userdom changed for a student? my $usec = &Apache::lonnet::getsection($udom,$uname,$env{'request.course.id'}); @@ -1929,7 +1960,7 @@ KEYWORDS # This is where output for one specific student would start my $bgcolor='#DDEEDD'; - if (int($counter/2) eq $counter) { $bgcolor='#DDDDEE'; } + if ($counter%2) { $bgcolor='#DDDDEE'; } $request->print("\n\n". '

'.$ctr.' '. &nameUserString(undef,$$fullname{$student},$uname,$udom). - ' '.$section.'
SCANTRONFORM - $r->print(< -$grading_menu_button -SCANTRONFORM - + $r->print('
'.$env{'form.fullname'}.'
'); @@ -1959,60 +1990,13 @@ KEYWORDS '" value="'.$env{'form.fullname'}.'" />'."\n"; # If any part of the problem is an essay-response (handgraded), then check for collaborators - my @col_fullnames; - my ($classlist,$fullname); + my $fullname; + my $col_fullnames = []; if ($env{'form.handgrade'} eq 'yes') { - ($classlist,undef,$fullname) = &getclasslist('all','0'); - for (keys (%$handgrade)) { - my $ncol = &Apache::lonnet::EXT('resource.'.$_. - '.maxcollaborators', - $symb,$udom,$uname); - next if ($ncol <= 0); - s/\_/\./g; - next if ($record{'resource.'.$_.'.collaborators'} eq ''); - my @goodcollaborators = (); - my @badcollaborators = (); - foreach (split(/,?\s+/,$record{'resource.'.$_.'.collaborators'})) { - $_ =~ s/[\$\^\(\)]//g; - next if ($_ eq ''); - my ($co_name,$co_dom) = split /\@|:/,$_; - $co_dom = $udom if (! defined($co_dom) || $co_dom =~ /^domain$/i); - next if ($co_name eq $uname && $co_dom eq $udom); - # Doing this grep allows 'fuzzy' specification - my @Matches = grep /^$co_name:$co_dom$/i,keys %$classlist; - if (! scalar(@Matches)) { - push @badcollaborators,$_; - } else { - push @goodcollaborators, @Matches; - } - } - if (scalar(@goodcollaborators) != 0) { - $result.='Collaborators: '; - foreach (@goodcollaborators) { - my ($lastname,$givenn) = split(/,/,$$fullname{$_}); - push @col_fullnames, $givenn.' '.$lastname; - $result.=$$fullname{$_}.'     '; - } - $result.='
'."\n"; - my ($part)=split(/\./,$_); - $result.=''. - "\n"; - } - if (scalar(@badcollaborators) > 0) { - $result.='
'; - $result.='This student has submitted '; - $result.=(scalar(@badcollaborators) == 1) ? 'an invalid collaborator' : 'invalid collaborators'; - $result .= ': '.join(', ',@badcollaborators); - $result .= '
'; - } - if (scalar(@badcollaborators > $ncol)) { - $result .= '
'; - $result .= 'This student has submitted too many '. - 'collaborators. Maximum is '.$ncol.'.'; - $result .= '
'; - } - } + (my $sub_result,$fullname,$col_fullnames)= + &check_collaborators($symb,$uname,$udom,\%record,$handgrade, + $counter); + $result.=$sub_result; } $request->print($result."\n"); @@ -2148,16 +2132,16 @@ KEYWORDS if ($env{'form.handgrade'} eq 'yes') { my ($lastname,$givenn) = split(/,/,$env{'form.fullname'}); my $msgfor = $givenn.' '.$lastname; - if (scalar(@col_fullnames) > 0) { - my $lastone = pop @col_fullnames; - $msgfor .= ', '.(join ', ',@col_fullnames).' and '.$lastone.'.'; + if (scalar(@$col_fullnames) > 0) { + my $lastone = pop(@$col_fullnames); + $msgfor .= ', '.(join ', ',@$col_fullnames).' and '.$lastone.'.'; } $msgfor =~ s/\'/\\'/g; #' stupid emacs - no! javascript $result=''."\n". ''."\n"; $result.=' '. - &mt('Compose message to student').(scalar(@col_fullnames) >= 1 ? 's' : '').'
'); + &Apache::lonpickcode::code_list($r,2); + $r->print('
'); + $r->print($grading_menu_button); return } @@ -5238,7 +5278,12 @@ sub scantron_parse_scanline { || (&occurence_count($currentquest, "[A-Z]") > 1)) { push(@{$record{'scantron.doubleerror'}},$questnum); for (my $ans = 0; $ans < $answers_needed; $ans++) { - $record{"scantron.$ansnum.answer"}=''; + my $bubble = substr($currentquest, $ans, 1); + if ($bubble =~ /[A-Z]/ ) { + $record{"scantron.$ansnum.answer"} = $bubble; + } else { + $record{"scantron.$ansnum.answer"}=''; + } $ansnum++; } @@ -5273,7 +5318,12 @@ sub scantron_parse_scanline { || (&occurence_count($currentquest, '\d') > 1)) { push(@{$record{'scantron.doubleerror'}},$questnum); for (my $ans = 0; $ans < $answers_needed; $ans++) { - $record{"scantron.$ansnum.answer"}=''; + my $bubble = substr($currentquest, $ans, 1); + if ($bubble =~ /\d/) { + $record{"scantron.$ansnum.answer"} = $alphabet[$bubble]; + } else { + $record{"scantron.$ansnum.answer"}=' '; + } $ansnum++; } @@ -5320,7 +5370,7 @@ sub scantron_parse_scanline { } } elsif (scalar(@array) lt 2) { - my $location = [length($array[0])]; + my $location = length($array[0]); my $line_num = $location / $$scantron_config{'Qlength'}; my $bubble = $alphabet[$location % $$scantron_config{'Qlength'}]; @@ -5343,20 +5393,22 @@ sub scantron_parse_scanline { my $first_answer = $ansnum; for (my $ans =0; $ans < $answers_needed; $ans++) { - $record{"scantron.$ansnum.answer"} = ''; - $ans++; + my $item = $first_answer+$ans; + $record{"scantron.$item.answer"} = ''; } my @ans=@array; - my $i=length($ans[0]);shift(@ans); + my $i=0; + my $increment = 0; while ($#ans) { - $i+=length($ans[0])+1; - my $line = $i/$$scantron_config{'Qlength'} + $first_answer; + $i+=length($ans[0]) + $increment; + my $line = int($i/$$scantron_config{'Qlength'} + $first_answer); my $bubble = $i%$$scantron_config{'Qlength'}; - $record{"scantron.$line.answer"}.=$alphabet[$bubble]; shift(@ans); + $increment = 1; } + $ansnum += $answers_needed; } } } @@ -5716,7 +5768,6 @@ SCANTRONFORM my $line = 0; while (defined($env{"form.scantron.bubblelines.$line"})) { - &Apache::lonnet::logthis("Saving chunk for $line"); my $chunk = ''."\n"; $chunk .= @@ -5782,7 +5833,6 @@ sub scantron_validate_file { } my $currentphase=$env{'form.validatepass'}; - &Apache::lonnet::logthis("Phase: $currentphase"); my $stop=0; while (!$stop && $currentphase < scalar(@validate_phases)) { @@ -6294,7 +6344,7 @@ sub scantron_validate_ID { 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 +#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 @@ -6393,10 +6443,10 @@ ENDSCRIPT $r->print($message); $r->print("

Please indicate which bubble should be used for grading

"); foreach my $question (@{$arg}) { - my $selected = &get_response_bubbles($scan_record, $question); + my @select_array = split(/:/,$selected); &scantron_bubble_selector($r,$scan_config,$question, - split('',$selected)); + @select_array); } } elsif ($error eq 'missingbubble') { $r->print("

There have been no bubbles scanned for some question(s)

\n"); @@ -6427,22 +6477,24 @@ ENDSCRIPT $r - Apache request object $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 - array of answer lines. =cut sub scantron_bubble_selector { - my ($r,$scan_config,$quest,@selected)=@_; + my ($r,$scan_config,$quest,@lines)=@_; my $max=$$scan_config{'Qlength'}; + my $scmode=$$scan_config{'Qon'}; + my $bubble_length = scalar(@lines); + if ($scmode eq 'number' || $scmode eq 'letter') { $max=10; } my $response = $quest-1; my $lines = $bubble_lines_per_response{$response}; - &Apache::lonnet::logthis("Question $quest, lines: $lines"); my $total_lines = $lines*2; my @alphabet=('A'..'Z'); @@ -6452,11 +6504,7 @@ sub scantron_bubble_selector { if ($l != 0) { $r->print('
'); if ($selected[0] eq $alphabet[$i]) { @@ -6706,14 +6754,11 @@ sub scantron_validate_doublebubble { =cut sub scantron_get_maxbubble { - &Apache::lonnet::logthis("get_max_bubble"); if (defined($env{'form.scantron_maxbubble'}) && $env{'form.scantron_maxbubble'}) { - &Apache::lonnet::logthis("cached"); &restore_bubble_lines(); return $env{'form.scantron_maxbubble'}; } - &Apache::lonnet::logthis("computing"); my (undef, undef, $sequence) = &Apache::lonnet::decode_symb($env{'form.selectpage'}); @@ -6751,9 +6796,9 @@ sub scantron_get_maxbubble { foreach my $part_id (@{$analysis{'parts'}}) { - my ($trash, $part) = split(/\./, $part_id); - my $lines = $analysis{"$part_id.bubble_lines"}[0]; + + my $lines = $analysis{"$part_id.bubble_lines"};; # TODO - make this a persistent hash not an array. @@ -7159,10 +7204,6 @@ sub grading_menu { my $probTitle = &Apache::lonnet::gettitle($symb); my ($table,undef,$hdgrade) = &showResourceInfo($symb,$probTitle); - # - # Define menu data - $env{'form.probTitle'} = &Apache::lonnet::gettitle($symb); - my ($table) = &showResourceInfo($symb,$env{'form.probTitle'}); $request->print($table); my %fields = ('symb'=>&Apache::lonenc::check_encrypt($symb), 'handgrade'=>$hdgrade, @@ -7192,29 +7233,15 @@ sub grading_menu { $fields{'command'} = 'scantron_selectphase'; $url = &Apache::lonhtmlcommon::build_url('grades/',\%fields); push (@menu, { url => $url, - name => &mt('Grade Scantron Forms'), + name => &mt('Grade/Manage Scantron Forms'), short_description => &mt('')}); $fields{'command'} = 'verify'; $url = &Apache::lonhtmlcommon::build_url('grades/',\%fields); push (@menu, { url => "", - jscript => ' onClick="javascript:checkChoice2(document.forms.gradingMenu,\'5\',\'verify\')" ', name => &mt('Verify Receipt'), short_description => &mt('')}); - $fields{'command'} = 'manage'; - $url = &Apache::lonhtmlcommon::build_url('/adm/helper/resettimes.helper',\%fields); - push (@menu, { url => $url, - name => &mt('Manage Access Times'), - short_description => - &mt('')}); - $fields{'command'} = 'view'; - $url = &Apache::lonhtmlcommon::build_url('/adm/pickcode',\%fields); - push (@menu, { url => $url, - name => &mt('View Saved CODEs'), - short_description => - &mt('')}); - # # Create the menu my $Str; @@ -7236,10 +7263,10 @@ sub grading_menu { $menudata->{'url'}.'" >'. $menudata->{'name'}."\n"; } else { - $Str .='

{'jscript'}. - ' href="javascript:checkChoice2(document.forms.gradingMenu,\'5\',\'verify\')" >'. - $menudata->{'name'}."

\n"; + ' onClick="javascript:checkChoice(document.forms.gradingMenu,\'5\',\'verify\')" '. + ' />'; $Str .= (' 'x8). ' receipt: '.&Apache::lonnet::recprefix($env{'request.course.id'}). '-'; @@ -7260,30 +7287,14 @@ sub grading_menu { cmdsave = 'submission'; } formname.command.value = cmd; - formname.saveState.value = "saveCmd="+cmdsave+":saveSec="+pullDownSelection(formname.section)+ - ":saveSub="+pullDownSelection(formname.submitonly)+":saveStatus="+pullDownSelection(formname.Status); if (val < 5) formname.submit(); if (val == 5) { - if (!checkReceiptNo(formname,'notOK')) { return false;} - formname.submit(); - } - if (val < 7) formname.submit(); - } - function checkChoice2(formname,val,cmdx) { - if (val <= 2) { - var cmd = radioSelection(formname.radioChoice); - var cmdsave = cmd; - } else { - cmd = cmdx; - cmdsave = 'submission'; - } - formname.command.value = cmd; - if (val < 5) formname.submit(); - if (val == 5) { - if (!checkReceiptNo(formname,'notOK')) { return false;} - formname.submit(); + if (!checkReceiptNo(formname,'notOK')) { + return false; + } else { + formname.submit(); + } } - if (val < 7) formname.submit(); } function checkReceiptNo(formname,nospace) { @@ -7302,43 +7313,6 @@ sub grading_menu { GRADINGMENUJS &commonJSfunctions($request); - my $result='

 Manual Grading/View Submission

'; - $result.=$table; - my (undef,$sections) = &getclasslist('all','0'); - my $savedState = &savedState(); - my $saveCmd = ($$savedState{'saveCmd'} eq '' ? 'submission' : $$savedState{'saveCmd'}); - my $saveSec = ($$savedState{'saveSec'} eq '' ? 'all' : $$savedState{'saveSec'}); - my $saveSub = ($$savedState{'saveSub'} eq '' ? 'all' : $$savedState{'saveSub'}); - my $saveStatus = ($$savedState{'saveStatus'} eq '' ? 'Active' : $$savedState{'saveStatus'}); - - $result.='
'."\n". - ''."\n". - ''."\n". - ''."\n". - ''."\n". - ''."\n". - ''."\n"; - - $result.='
'."\n". - ''."\n". - '
'."\n". - ' Select a Grading/Viewing Option
'."\n"; - - $result.=''; - $result.=''."\n"; - $result.=''; -# $result.=''; - $result.=''."\n"; - $result.=''; - $result.=''; $result.=''; $result.=''."\n"; + $result.=''."\n"; $result.=''; $result.=''; - - $result.=''; + $result.=''."\n"; + ($saveSub eq 'all' ? 'selected="selected"' : '').'>'.&mt('with any status').''; - $result.=''."\n"; + + $result.=''."\n"; - $result.=''."\n"; + + + $result.=''."\n"; + 'The complete set/page/sequence/folder: For one student'."\n"; - $result.='
'.&mt('Sections').'Groups'.&mt('Access Status').'
'."\n". - '    '; return $Str; } @@ -7416,6 +7390,7 @@ GRADINGMENUJS $result.=''.&mt('Sections').''.&mt('Groups').''.&mt('Access Status').''.&mt('Submission Status').'
'."\n". ' '."\n"; $result.=&Apache::lonhtmlcommon::StatusOptions($saveStatus,undef,3,undef,'mult'); - $result.='
'. + $result.='
'. '
'. - '
'. + '

'. + $result.='

'. ''. '
'."\n"; @@ -7668,9 +7649,9 @@ function sanitycheck() {
-
-
-
+
+
+

@@ -8005,7 +7986,6 @@ ENDHEADER sub handler { my $request=$_[0]; - &reset_caches(); if ($env{'browser.mathml'}) { &Apache::loncommon::content_type($request,'text/xml'); @@ -8101,7 +8081,6 @@ 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));