--- loncom/homework/grades.pm 2007/10/26 20:18:43 1.469 +++ loncom/homework/grades.pm 2007/11/05 10:19:03 1.479 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # The LON-CAPA Grading handler # -# $Id: grades.pm,v 1.469 2007/10/26 20:18:43 albertel Exp $ +# $Id: grades.pm,v 1.479 2007/11/05 10:19:03 foxr Exp $ # # Copyright Michigan State University Board of Trustees # @@ -42,6 +42,7 @@ use Apache::Constants qw(:common); use Apache::lonlocal; use Apache::lonenc; use String::Similarity; +use Data::Dumper; use LONCAPA; use POSIX qw(floor); @@ -865,7 +866,7 @@ LISTJAVASCRIPT my $saveStatus = $stu_status eq '' ? 'Active' : $stu_status; $env{'form.Status'} = $saveStatus; $gradeTable.=''."\n". - ''."\n". + ''."\n". ''."\n". '
'."\n". ' Grading Increments: Check For Plagiarism'; my ($classlist, undef, $fullname) = &getclasslist($getsec,'1',$getgroup); - $gradeTable.='
'. - ''; + $gradeTable.= &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(); my $loop = 0; while ($loop < 2) { - $gradeTable.=''. - ''; + $gradeTable.=''. + ''; if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'queued' && $submitonly ne 'all') { foreach (sort(@$partlist)) { my $display_part=&get_display_part((split(/_/))[0],$symb); - $gradeTable.=''; + $gradeTable.=''; + $gradeTable.=''; } $loop++; # $gradeTable.='' if ($loop%2 ==1); } - $gradeTable.=''."\n"; + $gradeTable.=&Apache::loncommon::end_data_table_header_row()."\n"; my $ctr = 0; foreach my $student (sort @@ -978,13 +979,15 @@ LISTJAVASCRIPT 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); + if ($ctr%2 ==1) { + $gradeTable.= &Apache::loncommon::start_data_table_row(); + } $gradeTable.=''. ''."\n".''."\n"; + ' '.$section.($group ne '' ?'/'.$group:'').''."\n"; if ($env{'form.showgrading'} eq 'yes' && $submitonly ne 'all') { foreach (sort keys(%status)) { @@ -993,7 +996,9 @@ LISTJAVASCRIPT } } # $gradeTable.='' if ($ctr%2 ==1); - $gradeTable.=''."\n" if ($ctr%2 ==0); + if ($ctr%2 ==0) { + $gradeTable.=&Apache::loncommon::end_data_table_row()."\n"; + } } } if ($ctr%2 ==1) { @@ -1007,10 +1012,10 @@ LISTJAVASCRIPT } elsif ($submitonly eq 'queued') { $gradeTable.=''; } - $gradeTable.=''; + $gradeTable.=&Apache::loncommon::end_data_table_row(); } - $gradeTable.='
 No.  Select '.&nameUserString('header').' Section/GroupNo.Select'.&nameUserString('header').' '.'Section/Group Part: '.$display_part. - ' Status Part: '.$display_part. + ' Status'; } } elsif ($submitonly eq 'queued') { - $gradeTable.=' '.&mt('Queue Status').' '.&mt('Queue Status').' 
'.$ctr.' '. &nameUserString(undef,$$fullname{$student},$uname,$udom). - ' '.$section.'/'.$group.'
 
'."\n". + $gradeTable.=&Apache::loncommon::end_data_table()."\n". ''."\n"; @@ -1028,7 +1033,7 @@ LISTJAVASCRIPT ' students checked for '.$submissions.')
'; } } elsif ($ctr == 1) { - $gradeTable =~ s/type=checkbox/type=checkbox checked/; + $gradeTable =~ s/type="checkbox"/type="checkbox" checked="checked"/; } $gradeTable.=&show_grading_menu_form($symb); $request->print($gradeTable); @@ -1969,7 +1974,7 @@ KEYWORDS $mode='answer'; } &Apache::lonxml::clear_problem_counter(); - $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode)); + $request->print(&show_problem($request,$symb,$uname,$udom,1,1,$mode,{'request.prefix' => 'ctr'.$counter})); } my %record = &Apache::lonnet::restore($symb,$env{'request.course.id'},$udom,$uname); @@ -3169,14 +3174,12 @@ sub viewgrades { $sectionClass=&mt('Students in Section(s) [_1]',$section_display).''; } $result.='

'.&mt('Assign Common Grade To [_1]',$sectionClass); - $result.= ''."\n"; } } - $result.=''; + $result.=&Apache::loncommon::end_data_table_row(); return $result; } @@ -3357,15 +3363,14 @@ sub editgrades { my $symb=&get_symb($request); my $section_display = join (", ",&Apache::loncommon::get_env_multiple('form.section')); - my $title='

'.&mt('Current Grade Status').'

'; - $title.='

'.&mt('Current Resource: [_1]',$env{'form.probTitle'}).'


'."\n"; + my $title='

'.&mt('Current Grade Status').'

'; + $title.='

'.&mt('Current Resource: [_1]',$env{'form.probTitle'}).'

'."\n"; $title.='

'.&mt('Section: [_1]',$section_display).'

'."\n"; - my $result= '
'."\n". - '
'; + $result.= &Apache::loncommon::start_data_table(); #radio buttons/text box for assigning points for a section or class. #handles different parts of a problem my ($partlist,$handgrade,$responseType) = &response_type($symb); my %weight = (); my $ctsparts = 0; - $result.=''; my %seen = (); my @part_response_id = &flatten_responseType($responseType); foreach my $part_response_id (@part_response_id) { @@ -3188,12 +3191,14 @@ sub viewgrades { my $wgt = &Apache::lonnet::EXT('resource.'.$partid.'.weight',$symb); $weight{$partid} = $wgt eq '' ? '1' : $wgt; + $result.=&Apache::loncommon::start_data_table_row().'
'; $result.=''."\n"; $result.=''."\n"; my $display_part=&get_display_part($partid,$symb); - $result.='
Part: '.$display_part.'   Point: '; + $result.= + 'Part: '.$display_part.'   Point: '; $result.=''; my $ctr = 0; while ($ctr<=$weight{$partid}) { # display radio buttons in a nice table 10 across @@ -3208,26 +3213,27 @@ sub viewgrades { $partid.'" size="4" '.'onChange="javascript:writePoint(\''. $partid.'\','.$weight{$partid}.',\'textval\')" /> /'. $weight{$partid}.' (problem weight)'."\n"; - $result.= ''. - ''."\n"; + ''.&Apache::loncommon::end_data_table_row()."\n"; $ctsparts++; } - $result.='
'.'
'.'
'."\n". + $result.=&Apache::loncommon::end_data_table()."\n". ''; $result.=''; + 'onClick="javascript:resetEntry('.$ctsparts.');" />'; #table listing all the students in a section/class #header of table $result.= '

Assign Grade to Specific Students in '.$sectionClass; - $result.= '
'."\n". - ''. - '\n"; + $result.= &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ''. + '\n"; my (@parts) = sort(&getpartlist($symb)); my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb); my @partids = (); @@ -3239,16 +3245,16 @@ sub viewgrades { push(@partids, $partid); my $display_part=&get_display_part($partid,$symb); if ($display =~ /^Partial Credit Factor/) { - $result.=''."\n"; + $result.=''."\n"; next; } else { $display =~s/\[Part: \Q$partid\E\]/Part:<\/b> $display_part/; } $display =~ s|Problem Status|Grade Status
|; - $result.=''."\n"; + $result.=''."\n"; } - $result.=''; + $result.=&Apache::loncommon::end_data_table_header_row(); my %last_resets = &get_last_resets($symb,$env{'request.course.id'},\@partids); @@ -3268,7 +3274,7 @@ sub viewgrades { $result.=&viewstudentgrade($symb,$env{'request.course.id'}, $_,$$fullname{$_},\@parts,\%weight,$ctr,\%last_resets); } - $result.='
 No. '.&nameUserString('header')."No.'.&nameUserString('header')."Score Part: '.$display_part. - '
(weight = '.$weight{$partid}.')
Score Part: '.$display_part. + '
(weight = '.$weight{$partid}.')
'.$display.''.$display.'
'; + $result.=&Apache::loncommon::end_data_table(); $result.=''."\n"; $result.=''."\n"; @@ -3291,7 +3297,7 @@ sub viewstudentgrade { my ($uname,$udom) = split(/:/,$student); my %record=&Apache::lonnet::restore($symb,$courseid,$udom,$uname); my %aggregates = (); - my $result='

'. + my $result=&Apache::loncommon::start_data_table_row().''. ''. "\n".$ctr.'  '. '
'."\n"; - $result.= ''. - ''. - '\n"; - + my $result= &Apache::loncommon::start_data_table(). + &Apache::loncommon::start_data_table_header_row(). + ''. + '\n"; my %scoreptr = ( 'correct' =>'correct_by_override', 'incorrect'=>'incorrect_by_override', @@ -3390,8 +3395,8 @@ sub editgrades { } my (undef,undef,$url) = &Apache::lonnet::decode_symb($symb); foreach my $partid (@partid) { - $header .= ''. - ''; + $header .= ''. + ''; $columns{$partid}=2; foreach my $stores (@parts) { my ($part,$type) = &split_part_type($stores); @@ -3400,22 +3405,23 @@ sub editgrades { my $display=&Apache::lonnet::metadata($url,$stores.'.display'); $display =~ s/\[Part: (\w)+\]//; $display =~ s/Number of Attempts/Tries/; - $header .= ''. - ''; + $header .= ''. + ''; $columns{$partid}+=2; } } foreach my $partid (@partid) { my $display_part=&get_display_part($partid,$symb); - $result .= ''; + $result .= ''; } - $result .= ''; - $result .= $header; - $result .= ''."\n"; - my $noupdate; + $result .= &Apache::loncommon::end_data_table_header_row(). + &Apache::loncommon::start_data_table_header_row(). + $header. + &Apache::loncommon::end_data_table_header_row(); + my @noupdate; my ($updateCtr,$noupdateCtr) = (1,1); for ($i=0; $i<$env{'form.total'}; $i++) { my $line; @@ -3427,7 +3433,9 @@ sub editgrades { my $usec=$classlist->{"$uname:$udom"}[5]; if (!&canmodify($usec)) { my $numcols=scalar(@partid)*4+2; - $noupdate.=$line.""; + push(@noupdate, + $line.""); next; } my %aggregate = (); @@ -3496,7 +3504,7 @@ sub editgrades { ''; } } - $line.=''."\n"; + $line.="\n"; my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'}; my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'}; @@ -3529,10 +3537,13 @@ sub editgrades { } } - $result.=''.$line; + $result.=&Apache::loncommon::start_data_table_row(). + ''.$line. + &Apache::loncommon::end_data_table_row(); $updateCtr++; } else { - $noupdate.=''.$line; + push(@noupdate, + ''.$line); $noupdateCtr++; } if ($aggregateflag) { @@ -3540,16 +3551,28 @@ sub editgrades { $cdom,$cnum); } } - if ($noupdate) { + if (@noupdate) { # my $numcols=(scalar(@partid)*(scalar(@parts)-1)*2)+3; my $numcols=scalar(@partid)*4+2; - $result .= ''.$noupdate; + $result .= &Apache::loncommon::start_data_table_row('LC_empty_row'). + ''. + &Apache::loncommon::end_data_table_row(); + foreach my $line (@noupdate) { + $result.= + &Apache::loncommon::start_data_table_row(). + $line. + &Apache::loncommon::end_data_table_row(); + } } - $result .= '
 No. '.&nameUserString('header')."'.&mt('No.').''.&nameUserString('header')." Old Score  New Score '.&mt('Old Score').''.&mt('New Score').' Old '.$display.'  New '.$display.' '.&mt('Old '.$display).''.&mt('New '.$display).'Part: '.$display_part. - ' (Weight = '.$weight{$partid}.')'. + &mt('Part: [_1] (Weight = [_2])',$display_part,$weight{$partid}). + '
Not allowed to modify student
". + &mt('Not allowed to modify student')."
'.$awarded.' 
 '.$updateCtr.'  '.$updateCtr.' 
 '.$noupdateCtr.'  '.$noupdateCtr.' 
No Changes Occurred For the Students Below
'. + &mt('No Changes Occurred For the Students Below'). + '
'."\n". - &show_grading_menu_form ($symb); - my $msg = '
Number of records updated = '.$rec_update. - ' for '.$count.' student'.($count <= 1 ? '' : 's').'.
'. - 'Total number of students = '.$env{'form.total'}.'
'; + $result .= &Apache::loncommon::end_data_table(). + &show_grading_menu_form($symb); + my $msg = '

'. + &mt('Number of records updated = [_1] for [quant,_2,student].', + $rec_update,$count).'
'. + ''.&mt('Total number of students = [_1]',$env{'form.total'}). + '

'; return $title.$msg.$result; } @@ -5094,7 +5117,8 @@ sub username_to_idmap { sub scantron_fixup_scanline { my ($scantron_config,$scan_data,$line,$whichline,$field,$args)=@_; - + + if ($field eq 'ID') { if (length($args->{'newid'}) > $$scantron_config{'IDlength'}) { return ($line,1,'New value too large'); @@ -5125,28 +5149,54 @@ sub scantron_fixup_scanline { $$scantron_config{'CODElength'})=$args->{'CODE'}; } } elsif ($field eq 'answer') { + &scantron_get_maxbubble(); # Need the bubble counter info. my $length=$scantron_config->{'Qlength'}; my $off=$scantron_config->{'Qoff'}; my $on=$scantron_config->{'Qon'}; my $answer=${off}x$length; - if ($args->{'response'} eq 'none') { - &scan_data($scan_data, - "$whichline.no_bubble.".$args->{'question'},'1'); - } else { - if ($on eq 'letter') { - my @alphabet=('A'..'Z'); - $answer=$alphabet[$args->{'response'}]; - } elsif ($on eq 'number') { - $answer=$args->{'response'}+1; - if ($answer == 10) { $answer = '0'; } + my $question_number = $args->{'question'} -1; + my $first_position = $first_bubble_line{$question_number}; + my $bubble_count = $bubble_lines_per_response{$question_number}; + my $bubbles_per_line= $$scantron_config{'Qlength'}; + my $final_answer; + if ($$scantron_config{'Qon'} eq 'letter' || + $$scantron_config{'Qon'} eq 'number') { + $bubbles_per_line = 10; + } + if (defined $args->{'response'}) { + + if ($args->{'response'} eq 'none') { + &scan_data($scan_data, + "$whichline.no_bubble.".$args->{'question'},'1'); } else { - substr($answer,$args->{'response'},1)=$on; + my ($bubble_line, $bubble_number) = split(/:/,$args->{'response'}); + if ($on eq 'letter') { + my @alphabet=('A'..'Z'); + $answer=$alphabet[$bubble_number]; + } elsif ($on eq 'number') { + $answer=$args->$bubble_number+1; + if ($answer == 10) { $answer = '0'; } + } else { + substr($answer,$args->{'response'},1)=$on; + } + my $before = Dumper($scan_data); + &scan_data($scan_data, + "$whichline.no_bubble.".$args->{'question'},undef,'1'); + my $after = Dumper($scan_data); + for (my $l = 0; $l < $bubble_count; $l++) { + if ($l eq $bubble_line) { + $final_answer .= $answer; + } else { + $final_answer .= ' '; + } + } } - &scan_data($scan_data, - "$whichline.no_bubble.".$args->{'question'},undef,'1'); + # $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'}; + #substr($line,$where-1,$length)=$answer; + substr($line, + $scantron_config->{'Qstart'}+$first_position-1, + $bubbles_per_line) = $final_answer; } - my $where=$length*($args->{'question'}-1)+$scantron_config->{'Qstart'}; - substr($line,$where-1,$length)=$answer; } return $line; } @@ -5239,6 +5289,7 @@ sub scan_data { sub scantron_parse_scanline { my ($line,$whichline,$scantron_config,$scan_data,$just_header)=@_; + my %record; my $questions=substr($line,$$scantron_config{'Qstart'}-1); # Answers my $data=substr($line,0,$$scantron_config{'Qstart'}-1); # earlier stuff @@ -5277,7 +5328,9 @@ sub scantron_parse_scanline { my $questnum=0; my $ansnum =1; # Multiple 'answer lines'/question. - while ($questions) { + chomp($questions); # Get rid of any trailing \n. + $questions =~ s/\r$//; # Get rid of trailing \r too (MAC or Win uploads). + while (length($questions)) { my $answers_needed = $bubble_lines_per_response{$questnum}; my $answer_length = $$scantron_config{'Qlength'} * $answers_needed; @@ -5320,9 +5373,8 @@ sub scantron_parse_scanline { } if (!&scan_data($scan_data,"$whichline.no_bubble.$questnum")) { push(@{$record{"scantron.missingerror"}},$questnum); - $ansnum += $answers_needed; + # $ansnum += $answers_needed; } - } else { for (my $ans = 0; $ans < $answers_needed; $ans++) { $record{"scantron.$ansnum.answer"} = substr($currentquest, $ans, 1); @@ -6468,6 +6520,7 @@ ENDSCRIPT foreach my $question (@{$arg}) { my $selected = &get_response_bubbles($scan_record, $question); my @select_array = split(/:/,$selected); + &Apache::lonnet::logthis("Questnum: $question, bubbles: $selected scanline $i"); &scantron_bubble_selector($r,$scan_config,$question, @select_array); } @@ -6480,7 +6533,8 @@ ENDSCRIPT join(',',@{$arg}).'" />'); foreach my $question (@{$arg}) { my $selected = &get_response_bubbles($scan_record, $question); - &scantron_bubble_selector($r,$scan_config,$question); + my @select_array = split(/:/,$selected); # ought to be an array of empties. + &scantron_bubble_selector($r,$scan_config,$question, @select_array); } } else { $r->print("\n