--- loncom/homework/grades.pm 2023/03/10 23:36:22 1.596.2.12.2.60.2.3
+++ loncom/homework/grades.pm 2011/09/22 23:03:09 1.651
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# The LON-CAPA Grading handler
#
-# $Id: grades.pm,v 1.596.2.12.2.60.2.3 2023/03/10 23:36:22 raeburn Exp $
+# $Id: grades.pm,v 1.651 2011/09/22 23:03:09 raeburn Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -44,10 +44,7 @@ use Apache::Constants qw(:common :http);
use Apache::lonlocal;
use Apache::lonenc;
use Apache::lonstathelpers;
-use Apache::bridgetask();
-use Apache::lontexconvert();
-use HTML::Parser();
-use File::MMagic;
+use Apache::lonquickgrades;
use String::Similarity;
use LONCAPA;
@@ -56,7 +53,6 @@ use POSIX qw(floor);
my %perm=();
-my %old_essays=();
# These variables are used to recover from ssi errors
@@ -143,7 +139,6 @@ 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) = @_;
@@ -161,7 +156,6 @@ 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);
@@ -171,20 +165,13 @@ 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,$numresp,$numessay,$numdropbox);
+ return ($partlist,\%handgrade,\%response_types);
}
sub flatten_responseType {
@@ -211,133 +198,9 @@ 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.'). - '
'; - } else { - return ''; + $grayFont.$bottomrow.''.''; } elsif ($response eq 'match') { my %answer=&Apache::lonnet::str2hash($answer); - my @answer = %answer; - %answer = map {&HTML::Entities::encode($_, '"<>&')} @answer; my %grading=&Apache::lonnet::str2hash($record->{$version."resource.$partid.$respid.submissiongrading"}); my @items=&Apache::lonnet::str2array($record->{$version."resource.$partid.$respid.submissionitems"}); my ($toprow,$middlerow,$bottomrow); @@ -510,11 +362,9 @@ sub cleanRecord { ''. '
'. ' '.&mt('Answer').' '.$toprow.''.$grayFont.&mt('Option ID').' '. - $bottomrow.'
'; + $bottomrow.''.''; } elsif ($response eq 'essay') { if (! exists ($env{'form.'.$symb})) { my (%keyhash) = &Apache::lonnet::dump('nohist_handgrade', @@ -547,11 +397,10 @@ sub cleanRecord { $env{'form.kwstyle'} = $keyhash{$loginuser.'_kwstyle'} ne '' ? $keyhash{$loginuser.'_kwstyle'} : ''; $env{'form.'.$symb} = 1; # so that we don't have to read it from disk for multiple sub of the same prob. } - $answer = &Apache::lontexconvert::msgtexconverted($answer); + $answer =~ s-\n-'. '
'. ' '.&mt('Answer').' '.$toprow.''.$grayFont.&mt('Option ID').' '. - $bottomrow.'
'.&keywords_highlight($answer).''; } elsif ( $response eq 'organic') { - my $result=&mt('Smile representation: [_1]', - '"'.&HTML::Entities::encode($answer, '"<>&').'"'); + my $result='Smile representation: "'.$answer.'"'; my $jme=$record->{$version."resource.$partid.$respid.molecule"}; $result.=&Apache::chemresponse::jme_img($jme,$answer,400); return $result; @@ -585,14 +434,12 @@ sub cleanRecord { $result.=''; return $result; } - } elsif ( $response =~ m/(?:numerical|formula|custom)/) { - # Respect multiple input fields, see Bug #5409 + } elsif ( $response =~ m/(?:numerical|formula)/) { $answer = &Apache::loncommon::format_previous_attempt_value('submission', $answer); - return $answer; } - return &HTML::Entities::encode($answer, '"<>&'); + return $answer; } #-- A couple of common js functions @@ -632,7 +479,7 @@ COMMONJSFUNCTIONS #--- Dumps the class list with usernames,list of sections, #--- section, ids and fullnames for each user. sub getclasslist { - my ($getsec,$filterbyaccstatus,$getgroup,$symb,$submitonly,$filterbysubmstatus) = @_; + my ($getsec,$filterlist,$getgroup) = @_; my @getsec; my @getgroup; my $stu_status = join(':',&Apache::loncommon::get_env_multiple('form.Status')); @@ -660,13 +507,6 @@ sub getclasslist { # my %sections; my %fullnames; - my ($cdom,$cnum,$partlist); - if (($filterbysubmstatus) && ($submitonly ne 'all') && ($symb ne '')) { - $cdom = $env{"course.$env{'request.course.id'}.domain"}; - $cnum = $env{"course.$env{'request.course.id'}.num"}; - my $res_error; - ($partlist) = &response_type($symb,\$res_error); - } foreach my $student (keys(%$classlist)) { my $end = $classlist->{$student}->[&Apache::loncoursedata::CL_END()]; @@ -683,7 +523,7 @@ sub getclasslist { my $group = $classlist->{$student}->[&Apache::loncoursedata::CL_GROUP()]; # filter students according to status selected - if ($filterbyaccstatus && (!($stu_status =~ /Any/))) { + if ($filterlist && (!($stu_status =~ /Any/))) { if (!($stu_status =~ $status)) { delete($classlist->{$student}); next; @@ -700,58 +540,13 @@ sub getclasslist { } } if (($grp eq 'none') && !$group) { - $exclude = 0; + $exclude = 0; } } if ($exclude) { delete($classlist->{$student}); - next; } } - if (($filterbysubmstatus) && ($submitonly ne 'all') && ($symb ne '')) { - my $udom = - $classlist->{$student}->[&Apache::loncoursedata::CL_SDOM()]; - my $uname = - $classlist->{$student}->[&Apache::loncoursedata::CL_SNAME()]; - if (($symb ne '') && ($udom ne '') && ($uname ne '')) { - if ($submitonly eq 'queued') { - my %queue_status = - &Apache::bridgetask::get_student_status($symb,$cdom,$cnum, - $udom,$uname); - if (!defined($queue_status{'gradingqueue'})) { - delete($classlist->{$student}); - next; - } - } else { - my (%status) =&student_gradeStatus($symb,$udom,$uname,$partlist); - my $submitted = 0; - my $graded = 0; - my $incorrect = 0; - foreach (keys(%status)) { - $submitted = 1 if ($status{$_} ne 'nothing'); - $graded = 1 if ($status{$_} =~ /^ungraded/); - $incorrect = 1 if ($status{$_} =~ /^incorrect/); - - my ($foo,$partid,$foo1) = split(/\./,$_); - if ($status{'resource.'.$partid.'.submitted_by'} ne '') { - $submitted = 0; - } - } - if (!$submitted && ($submitonly eq 'yes' || - $submitonly eq 'incorrect' || - $submitonly eq 'graded')) { - delete($classlist->{$student}); - next; - } elsif (!$graded && ($submitonly eq 'graded')) { - delete($classlist->{$student}); - next; - } elsif (!$incorrect && $submitonly eq 'incorrect') { - delete($classlist->{$student}); - next; - } - } - } - } $section = ($section ne '' ? $section : 'none'); if (&canview($section)) { if (!@getsec || grep(/^\Q$section\E$/,@getsec)) { @@ -766,6 +561,7 @@ sub getclasslist { delete($classlist->{$student}); } } + my %seen = (); my @sections = sort(keys(%sections)); return ($classlist,\@sections,\%fullnames); } @@ -781,7 +577,7 @@ sub canmodify { #can modify the requested section return 1; } else { - # can't modify the requested section + # can't modify the request section return 0; } } @@ -794,19 +590,19 @@ sub canview { my ($sec)=@_; if ($perm{'vgr'}) { if (!defined($perm{'vgr_section'})) { - # can view whole class + # can modify whole class return 1; } else { if ($sec eq $perm{'vgr_section'}) { - #can view the requested section + #can modify the requested section return 1; } else { - # can't view the requested section + # can't modify the request section return 0; } } } - #can't view + #can't modify return 0; } @@ -884,11 +680,7 @@ sub compute_points { # sub most_similar { - my ($uname,$udom,$symb,$uessay)=@_; - - unless ($symb) { return ''; } - - unless (ref($old_essays{$symb}) eq 'HASH') { return ''; } + my ($uname,$udom,$uessay,$old_essays)=@_; # ignore spaces and punctuation @@ -905,11 +697,11 @@ sub most_similar { my $scrsid=''; my $sessay=''; # go through all essays ... - foreach my $tkey (keys(%{$old_essays{$symb}})) { + foreach my $tkey (keys(%$old_essays)) { my ($tname,$tdom,$tcrsid)=map {&unescape($_)} (split(/\./,$tkey)); # ... except the same student next if (($tname eq $uname) && ($tdom eq $udom)); - my $tessay=$old_essays{$symb}{$tkey}; + my $tessay=$old_essays->{$tkey}; $tessay=~s/\W+/ /gs; # String similarity gives up if not even limit my $tsimilar=&String::Similarity::similarity($uessay,$tessay,$limit); @@ -919,7 +711,7 @@ sub most_similar { $sname=$tname; $sdom=$tdom; $scrsid=$tcrsid; - $sessay=$old_essays{$symb}{$tkey}; + $sessay=$old_essays->{$tkey}; } } if ($limit>0.6) { @@ -937,7 +729,7 @@ sub most_similar { sub initialverifyreceipt { my ($request,$symb) = @_; &commonJSfunctions($request); - return ''."\n". ''. ''."\n". + &mt('last submission & parts info').' '."\n". ''. ''."\n". + &mt('by dates and submissions').''."\n". ''. ''; - my ($compmsg,$nocompmsg); - $nocompmsg = ' checked="checked"'; - if ($numessay) { - $compmsg = $nocompmsg; - $nocompmsg = ''; - } + &mt('all details').''; $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Submissions')) - .$submission_options; -# Check if any gradable - my $showmore; - if ($perm{'mgr'}) { - my @sections; - if ($env{'request.course.sec'} ne '') { - @sections = ($env{'request.course.sec'}); - } elsif ($env{'form.section'} eq '') { - @sections = ('all'); - } else { - @sections = &Apache::loncommon::get_env_multiple('form.section'); - } - if (grep(/^all$/,@sections)) { - $showmore = 1; - } else { - foreach my $sec (@sections) { - if (&canmodify($sec)) { - $showmore = 1; - last; - } - } - } - } - - if ($showmore) { - $gradeTable .= - &Apache::lonhtmlcommon::row_closure() - .&Apache::lonhtmlcommon::row_title(&mt('Send Messages')) - .'' - .'' - .'' + .$submission_options .&Apache::lonhtmlcommon::row_closure(); - $gradeTable .= - &Apache::lonhtmlcommon::row_title(&mt('Grading Increments')) + $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Grading Increments')) .''; - } + .'' + .&Apache::lonhtmlcommon::row_closure(); + $gradeTable .= &build_section_inputs(). ''."\n". ''."\n". ''."\n"; + if (exists($env{'form.Status'})) { - $gradeTable .= ''."\n"; + $gradeTable .= ''."\n"; } else { - $gradeTable .= &Apache::lonhtmlcommon::row_closure() - .&Apache::lonhtmlcommon::row_title(&mt('Student Status')) + $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Student Status')) .&Apache::lonhtmlcommon::StatusOptions( - $saveStatus,undef,1,'javascript:reLoadList(this.form);'); - } - if ($numessay) { - $gradeTable .= &Apache::lonhtmlcommon::row_closure() - .&Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism')) - .''; + $saveStatus,undef,1,'javascript:reLoadList(this.form);') + .&Apache::lonhtmlcommon::row_closure(); } - $gradeTable .= &Apache::lonhtmlcommon::row_closure(1) + + $gradeTable .= &Apache::lonhtmlcommon::row_title(&mt('Check For Plagiarism')) + .'' + .&Apache::lonhtmlcommon::row_closure(1) .&Apache::lonhtmlcommon::end_pick_box(); $gradeTable .= '
'
@@ -1341,7 +1077,7 @@ LISTJAVASCRIPT
if ($submitonly eq 'graded' ) { $submissions = 'ungraded submissions'; }
if ($submitonly eq 'queued' ) { $submissions = 'queued submissions'; }
$gradeTable='
'.
- &mt('No '.$submissions.' found for this resource for any students. ([quant,_1,student] checked for '.$submissions.')',
+ &mt('No '.$submissions.' found for this resource for any students. ([_1] students checked for '.$submissions.')',
$num_students).
'
';
}
@@ -1355,8 +1091,8 @@ LISTJAVASCRIPT
#---- Called from the listStudents routine
sub check_script {
- my ($form,$type) = @_;
- my $chkallscript = &Apache::lonhtmlcommon::scripttag('
+ my ($form, $type)=@_;
+ my $chkallscript= &Apache::lonhtmlcommon::scripttag('
function checkall() {
for (i=0; i $html_js_lt{'comp'}\"+fullname+\"<\\/h1>");
+ pDoc.write("
Compose Message for \"+fullname+\"<\\/span><\\/h3>
");
- pDoc.write('');
- pDoc.write(" $html_js_lt{'incl'}<\\/b><\\/td> $html_js_lt{'type'}<\\/b><\\/td> $html_js_lt{'mesa'}<\\/td><\\/tr>");
+ pDoc.write(' ');
+ pDoc.write(' ');
+ pDoc.write(" Type<\\/b><\\/td> Include<\\/b><\\/td> Message<\\/td><\\/tr>");
}
function displaySubject(msg,shwsel) {
pDoc = pWin.document;
- pDoc.write(" ");
+ pDoc.write(" ");
+ pDoc.write(" Subject<\\/td>");
pDoc.write(" <\\/td>");
- pDoc.write(" $html_js_lt{'subj'}<\\/td>");
- pDoc.write(" <\\/td><\\/tr>");
+ pDoc.write(" <\\/td><\\/tr>");
}
function displaySavedMsg(ctr,msg,shwsel) {
pDoc = pWin.document;
- pDoc.write(" ");
- pDoc.write(" <\\/td>");
+ pDoc.write(" ");
pDoc.write(" "+ctr+"<\\/td>");
+ pDoc.write(" <\\/td>");
pDoc.write("