Diff for /loncom/homework/grades.pm between versions 1.508 and 1.515

version 1.508, 2008/02/05 18:32:34 version 1.515, 2008/03/17 20:39:50
Line 47  use LONCAPA; Line 47  use LONCAPA;
 use POSIX qw(floor);  use POSIX qw(floor);
   
   
   
 my %perm=();  my %perm=();
   
   #  These variables are used to recover from ssi errors
   
   my $ssi_retries = 5;
   my $ssi_error;
   my $ssi_error_resource;
   my $ssi_error_message;
   
   
   #  Do an ssi with retries:
   #  While I'd love to factor out this with the vesrion in lonprintout,
   #  that would either require a data coupling between modules, which I refuse to perpetuate
   #  (there's quite enough of that already), or would require the invention of another infrastructure
   #  I'm not quite ready to invent (e.g. an ssi_with_retry object).
   #
   # At least the logic that drives this has been pulled out into loncommon.
   
   
   #
   #   ssi_with_retries - Does the server side include of a resource.
   #                      if the ssi call returns an error we'll retry it up to
   #                      the number of times requested by the caller.
   #                      If we still have a proble, no text is appended to the
   #                      output and we set some global variables.
   #                      to indicate to the caller an SSI error occured.  
   #                      All of this is supposed to deal with the issues described
   #                      in LonCAPA BZ 5631 see:
   #                      http://bugs.lon-capa.org/show_bug.cgi?id=5631
   #                      by informing the user that this happened.
   #
   # Parameters:
   #   resource   - The resource to include.  This is passed directly, without
   #                interpretation to lonnet::ssi.
   #   form       - The form hash parameters that guide the interpretation of the resource
   #                
   #   retries    - Number of retries allowed before giving up completely.
   # Returns:
   #   On success, returns the rendered resource identified by the resource parameter.
   # Side Effects:
   #   The following global variables can be set:
   #    ssi_error                - If an unrecoverable error occured this becomes true.
   #                               It is up to the caller to initialize this to false
   #                               if desired.
   #    ssi_last_error_resource  - If an unrecoverable error occured, this is the value
   #                               of the resource that could not be rendered by the ssi
   #                               call.
   #    ssi_last_error           - The error string fetched from the ssi response
   #                               in the event of an error.
   #
   sub ssi_with_retries {
       my ($resource, $retries, %form) = @_;
       my ($content, $response) = &Apache::loncommon::ssi_with_retries($resource, $retries, %form);
       if ($response->is_error) {
    $ssi_error          = 1;
    $ssi_error_resource = $resource;
    $ssi_error_message  = $response->code . " " . $response->message;
       }
   
       return $content;
   
   }
   #
   #  Prodcuces an ssi retry failure error message to the user:
   #
   
   sub ssi_print_error {
       my ($r) = @_;
       $r->print('<h2>Unrecoverable network error</h2>');
       $r->print('<p>Unable to perform a resource fetch from a server: <br />');
       $r->print("Resource: $ssi_error_resource <br />");
       $r->print("Error: $ssi_error_message <br /> Try again later.");
       $r->print('If errors persist, contact LonCAPA support for assistance</p>');
   }
   
 #  #
 # --- Retrieve the parts from the metadata file.---  # --- Retrieve the parts from the metadata file.---
 sub getpartlist {  sub getpartlist {
Line 201  sub reset_caches { Line 275  sub reset_caches {
   
  my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);   my (undef,undef,$url)=&Apache::lonnet::decode_symb($symb);
  $url=&Apache::lonnet::clutter($url);   $url=&Apache::lonnet::clutter($url);
  my $subresult=&Apache::lonnet::ssi($url,   my $subresult=&ssi_with_retries($url, $ssi_retries,
    ('grade_target' => 'analyze'),     ('grade_target' => 'analyze'),
    ('grade_domain' => $udom),     ('grade_domain' => $udom),
    ('grade_symb' => $symb),     ('grade_symb' => $symb),
Line 1759  sub download_all_link { Line 1833  sub download_all_link {
  join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));   join("\n",&Apache::loncommon::get_env_multiple('form.vPart'));
   
     my $identifier = &Apache::loncommon::get_cgi_id();      my $identifier = &Apache::loncommon::get_cgi_id();
     &Apache::lonnet::appenv('cgi.'.$identifier.'.students' => $all_students,      &Apache::lonnet::appenv({'cgi.'.$identifier.'.students' => $all_students,
                             'cgi.'.$identifier.'.symb' => $symb,                               'cgi.'.$identifier.'.symb' => $symb,
                             'cgi.'.$identifier.'.parts' => $parts,);                               'cgi.'.$identifier.'.parts' => $parts,});
     $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.      $r->print('<a href="/cgi-bin/multidownload.pl?'.$identifier.'">'.
       &mt('Download All Submitted Documents').'</a>');        &mt('Download All Submitted Documents').'</a>');
     return      return
Line 4681  my %bubble_lines_per_response;     # no. Line 4755  my %bubble_lines_per_response;     # no.
   
 my %first_bubble_line;             # First bubble line no. for each bubble.  my %first_bubble_line;             # First bubble line no. for each bubble.
   
 my %subdivided_bubble_lines;       # no. bubble lines for optionresponse   my %subdivided_bubble_lines;       # no. bubble lines for optionresponse, 
                                    # or matchresponse where an individual                                      # matchresponse or rankresponse, where 
                                    # response can have multiple lines                                     # an individual response can have multiple 
                                      # lines
   
 my %responsetype_per_response;     # responsetype for each response  my %responsetype_per_response;     # responsetype for each response
   
Line 4880  sub scantron_selectphase { Line 4955  sub scantron_selectphase {
     my $CODE_unique=&scantron_CODEunique();      my $CODE_unique=&scantron_CODEunique();
     my $result;      my $result;
   
       $ssi_error = 0;
   
     # Chunk of form to prompt for a file to grade and how:      # Chunk of form to prompt for a file to grade and how:
   
     $result.= '      $result.= '
Line 5457  sub scantron_validator_lettnum { Line 5534  sub scantron_validator_lettnum {
     my $occurrences = 0;      my $occurrences = 0;
     if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||      if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
         ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||          ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
         ($responsetype_per_response{$questnum-1} eq 'stringresponse')) {          ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
           ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
           ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
           ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
         my @singlelines = split('',$currquest);          my @singlelines = split('',$currquest);
         foreach my $entry (@singlelines) {          foreach my $entry (@singlelines) {
             $occurrences = &occurence_count($entry,$matchon);              $occurrences = &occurence_count($entry,$matchon);
Line 5556  sub scantron_validator_positional { Line 5636  sub scantron_validator_positional {
         #          #
         if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||          if (($responsetype_per_response{$questnum-1} eq 'essayresponse') ||
             ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||              ($responsetype_per_response{$questnum-1} eq 'formularesponse') ||
             ($responsetype_per_response{$questnum-1} eq 'stringresponse')) {              ($responsetype_per_response{$questnum-1} eq 'stringresponse') ||
               ($responsetype_per_response{$questnum-1} eq 'imageresponse') ||
               ($responsetype_per_response{$questnum-1} eq 'reactionresponse') ||
               ($responsetype_per_response{$questnum-1} eq 'organicresponse')) {
             my $doubleerror = 0;              my $doubleerror = 0;
             while (($currquest >= $$scantron_config{'Qlength'}) &&               while (($currquest >= $$scantron_config{'Qlength'}) && 
                    (!$doubleerror)) {                     (!$doubleerror)) {
Line 6030  sub scantron_validate_file { Line 6113  sub scantron_validate_file {
     }      }
     if (!$stop) {      if (!$stop) {
  my $warning=&scantron_warning_screen('Start Grading');   my $warning=&scantron_warning_screen('Start Grading');
  $r->print('   $r->print(&mt('Validation process complete.').'<br />
 <b>'.&mt('Validation process complete.').'<b><br />  
 '.$warning.'  '.$warning.'
 <input type="submit" name="submit" value="'.&mt('Start Grading').'" />  <input type="submit" name="submit" value="'.&mt('Start Grading').'" />
 <input type="hidden" name="command" value="scantron_process" />  <input type="hidden" name="command" value="scantron_process" />
Line 6792  for multi and missing bubble cases). Line 6874  for multi and missing bubble cases).
                                   Numbered from 0 (but question numbers are from                                    Numbered from 0 (but question numbers are from
                                   1.                                    1.
    %first_bubble_line           - Starting bubble line for each question.     %first_bubble_line           - Starting bubble line for each question.
    %subdivided_bubble_lines     - optionresponse and matchresponse type     %subdivided_bubble_lines     - optionresponse, matchresponse and rankresponse 
                                   problems render as separate sub-questions,                                     type problems render as separate sub-questions, 
                                   in exam mode. This hash contains a                                     in exam mode. This hash contains a 
                                   comma-separated list of the lines per                                     comma-separated list of the lines per 
                                   sub-question.                                    sub-question.
    %responsetype_per_response   - essayresponse, forumalaresponse, and     %responsetype_per_response   - essayresponse, formularesponse,
                                   stringresponse type problem parts can have                                    stringresponse, imageresponse, reactionresponse,
                                     and organicresponse type problem parts can have
                                   multiple lines per response if the weight                                    multiple lines per response if the weight
                                   assigned exceeds 10.  In this case, only                                    assigned exceeds 10.  In this case, only
                                   one bubble per line is permitted, but more                                     one bubble per line is permitted, but more 
Line 6832  sub prompt_for_corrections { Line 6915  sub prompt_for_corrections {
         $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');          $r->print(&mt('The group of bubble lines below responds to a single question.').'<br />');
         if (($responsetype_per_response{$question-1} eq 'essayresponse') ||          if (($responsetype_per_response{$question-1} eq 'essayresponse') ||
             ($responsetype_per_response{$question-1} eq 'formularesponse') ||              ($responsetype_per_response{$question-1} eq 'formularesponse') ||
             ($responsetype_per_response{$question-1} eq 'stringresponse')) {              ($responsetype_per_response{$question-1} eq 'stringresponse') ||
               ($responsetype_per_response{$question-1} eq 'imageresponse') ||
               ($responsetype_per_response{$question-1} eq 'reactionresponse') ||
               ($responsetype_per_response{$question-1} eq 'organicresponse')) {
             $r->print(&mt("Although this particular question type requires handgrading, the instructions for this question in the exam directed students to leave [quant,_1,line] blank on their scantron sheets.",$lines).'<br /><br />'.&mt('A non-zero score can be assigned to the student during scantron grading by selecting a bubble in at least one line.').'<br />'.&mt('The score for this question will be a sum of the numeric values for the selected bubbles from each line, where A=1 point, B=2 points etc.').'<br />'.&mt("To assign a score of zero for this question, mark all lines as 'No bubble'.").'<br /><br />');              $r->print(&mt("Although this particular question type requires handgrading, the instructions for this question in the exam directed students to leave [quant,_1,line] blank on their scantron sheets.",$lines).'<br /><br />'.&mt('A non-zero score can be assigned to the student during scantron grading by selecting a bubble in at least one line.').'<br />'.&mt('The score for this question will be a sum of the numeric values for the selected bubbles from each line, where A=1 point, B=2 points etc.').'<br />'.&mt("To assign a score of zero for this question, mark all lines as 'No bubble'.").'<br /><br />');
         } else {          } else {
             $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");              $r->print(&mt("Select at most one bubble in a single line and select 'No Bubble' in all the other lines. ")."<br />");
Line 7113  sub scantron_validate_doublebubble { Line 7199  sub scantron_validate_doublebubble {
    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,     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     and a comma separated list of numbers of bubble lines for sub-questions
    (for optionresponse items only), for response n.       (for optionresponse, matchresponse, and rankresponse items), for response n.  
   
 =cut  =cut
   
Line 7145  sub scantron_get_maxbubble { Line 7231  sub scantron_get_maxbubble {
     my $response_number = 0;      my $response_number = 0;
     my $bubble_line     = 0;      my $bubble_line     = 0;
     foreach my $resource (@resources) {      foreach my $resource (@resources) {
         # Need to retrieve part IDs and response IDs because essayresponse          my $symb = $resource->symb();
         # items are not included in $analysis{'parts'} from lonnet::ssi.            # Need to retrieve part IDs and response IDs because essayresponse,
           # reactionresponse and organicresponse items are not included in 
           # $analysis{'parts'} from lonnet::ssi.  
         my %possible_part_ids;           my %possible_part_ids; 
         if (ref($resource->parts()) eq 'ARRAY') {           if (ref($resource->parts()) eq 'ARRAY') { 
             foreach my $part (@{$resource->parts()}) {              foreach my $part (@{$resource->parts()}) {
                 my @resp_ids = $resource->responseIds($part);                  if (!&Apache::loncommon::check_if_partid_hidden($part,$symb,$udom,$uname)) {
                 foreach my $id (@resp_ids) {                      my @resp_ids = $resource->responseIds($part);
                     $possible_part_ids{$part.'.'.$id} = 1;                      foreach my $id (@resp_ids) {
                           $possible_part_ids{$part.'.'.$id} = 1;
                       }
                 }                  }
             }              }
         }          }
  my $result=&Apache::lonnet::ssi($resource->src(),   my $result=&ssi_with_retries($resource->src(), $ssi_retries,
  ('symb' => $resource->symb()),   ('symb' => $symb),
  ('grade_target' => 'analyze'),   ('grade_target' => 'analyze'),
  ('grade_courseid' => $cid),   ('grade_courseid' => $cid),
  ('grade_domain' => $udom),   ('grade_domain' => $udom),
Line 7170  sub scantron_get_maxbubble { Line 7260  sub scantron_get_maxbubble {
  my %analysis = &Apache::lonnet::str2hash($an);   my %analysis = &Apache::lonnet::str2hash($an);
   
         if (ref($analysis{'parts'}) eq 'ARRAY') {          if (ref($analysis{'parts'}) eq 'ARRAY') {
             @parts = @{$analysis{'parts'}};              foreach my $part (@{$analysis{'parts'}}) {
                   my ($id,$respid) = split(/\./,$part);
                   if (!&Apache::loncommon::check_if_partid_hidden($id,$symb,$udom,$uname)) {
                       push(@parts,$part);
                   }
               }
         }          }
         # Add part_ids for any essayresponse items.           # Add part_ids for any essayresponse items. 
         foreach my $part_id (keys(%possible_part_ids)) {          foreach my $part_id (keys(%possible_part_ids)) {
             if ($analysis{$part_id.'.type'} eq 'essayresponse') {              if (($analysis{$part_id.'.type'} eq 'essayresponse') ||
                   ($analysis{$part_id.'.type'} eq 'reactionresponse') ||
                   ($analysis{$part_id.'.type'} eq 'organicresponse')) {
                 if (!grep(/^\Q$part_id\E$/,@parts)) {                  if (!grep(/^\Q$part_id\E$/,@parts)) {
                     push (@parts,$part_id);                      push (@parts,$part_id);
                 }                  }
Line 7186  sub scantron_get_maxbubble { Line 7283  sub scantron_get_maxbubble {
   
     # TODO - make this a persistent hash not an array.      # TODO - make this a persistent hash not an array.
   
             # optionresponse and matchresponse type items render as              # optionresponse, matchresponse and rankresponse type items 
             # separate sub-questions in exam mode.              # render as separate sub-questions in exam mode.
             if (($analysis{$part_id.'.type'} eq 'optionresponse') ||              if (($analysis{$part_id.'.type'} eq 'optionresponse') ||
                 ($analysis{$part_id.'.type'} eq 'matchresponse')) {                  ($analysis{$part_id.'.type'} eq 'matchresponse') ||
                   ($analysis{$part_id.'.type'} eq 'rankresponse')) {
                 my ($numbub,$numshown);                  my ($numbub,$numshown);
                 if ($analysis{$part_id.'.type'} eq 'optionresponse') {                  if ($analysis{$part_id.'.type'} eq 'optionresponse') {
                     if (ref($analysis{$part_id.'.options'}) eq 'ARRAY') {                      if (ref($analysis{$part_id.'.options'}) eq 'ARRAY') {
Line 7199  sub scantron_get_maxbubble { Line 7297  sub scantron_get_maxbubble {
                     if (ref($analysis{$part_id.'.items'}) eq 'ARRAY') {                      if (ref($analysis{$part_id.'.items'}) eq 'ARRAY') {
                         $numbub = scalar(@{$analysis{$part_id.'.items'}});                          $numbub = scalar(@{$analysis{$part_id.'.items'}});
                     }                      }
                   } elsif ($analysis{$part_id.'.type'} eq 'rankresponse') {
                       if (ref($analysis{$part_id.'.foils'}) eq 'ARRAY') {
                           $numbub = scalar(@{$analysis{$part_id.'.foils'}});
                       }
                 }                  }
                 if (ref($analysis{$part_id.'.shown'}) eq 'ARRAY') {                  if (ref($analysis{$part_id.'.shown'}) eq 'ARRAY') {
                     $numshown = scalar(@{$analysis{$part_id.'.shown'}});                      $numshown = scalar(@{$analysis{$part_id.'.shown'}});
Line 7323  sub scantron_validate_missingbubbles { Line 7425  sub scantron_validate_missingbubbles {
   
 sub scantron_process_students {  sub scantron_process_students {
     my ($r) = @_;      my ($r) = @_;
   
     my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});      my (undef,undef,$sequence)=&Apache::lonnet::decode_symb($env{'form.selectpage'});
     my ($symb)=&get_symb($r);      my ($symb)=&get_symb($r);
     if (!$symb) {return '';}      if (!$symb) {
    return '';
       }
     my $default_form_data=&defaultFormData($symb);      my $default_form_data=&defaultFormData($symb);
   
     my %scantron_config=&get_scantron_config($env{'form.scantron_format'});      my %scantron_config=&get_scantron_config($env{'form.scantron_format'});
Line 7357  SCANTRONFORM Line 7462  SCANTRONFORM
     my ($uname,$udom,$started);      my ($uname,$udom,$started);
   
     &scantron_get_maxbubble(); # Need the bubble lines array to parse.      &scantron_get_maxbubble(); # Need the bubble lines array to parse.
       
   
       # If an ssi failed in scantron_get_maxbubble, put an error message out to
       # the user and return.
   
       if ($ssi_error) {
    $r->print("</form>");
    &ssi_print_error($r);
    $r->print(&show_grading_menu_form($symb));
    return ''; # Dunno why the other returns return '' rather than just returning.
       }
   
     while ($i<$scanlines->{'count'}) {      while ($i<$scanlines->{'count'}) {
   ($uname,$udom)=('','');    ($uname,$udom)=('','');
Line 7384  SCANTRONFORM Line 7500  SCANTRONFORM
   ($uname,$udom)=split(/:/,$uname);    ($uname,$udom)=split(/:/,$uname);
   
  &Apache::lonxml::clear_problem_counter();   &Apache::lonxml::clear_problem_counter();
   &Apache::lonnet::appenv(%$scan_record);    &Apache::lonnet::appenv($scan_record);
   
  if (&scantron_clear_skip($scanlines,$scan_data,$i)) {   if (&scantron_clear_skip($scanlines,$scan_data,$i)) {
     &scantron_putfile($scanlines,$scan_data);      &scantron_putfile($scanlines,$scan_data);
Line 7405  SCANTRONFORM Line 7521  SCANTRONFORM
  $form{'CODE'}=$scan_record->{'scantron.CODE'};   $form{'CODE'}=$scan_record->{'scantron.CODE'};
     } else {      } else {
  $form{'CODE'}='';   $form{'CODE'}='';
       } 
       my $result=&ssi_with_retries($resource->src(), $ssi_retries, %form);
       if ($ssi_error) {
    $ssi_error = 0; # So end of handler error message does not trigger.
    $r->print("</form>");
    &ssi_print_error($r);
    $r->print(&show_grading_menu_form($symb));
    return ''; # Why return ''?  Beats me.
     }      }
     my $result=&Apache::lonnet::ssi($resource->src(),%form);  
     if ($result ne '') {  
     }  
     if (&Apache::loncommon::connection_aborted($r)) { last; }      if (&Apache::loncommon::connection_aborted($r)) { last; }
  }   }
  $completedstudents{$uname}={'line'=>$line};   $completedstudents{$uname}={'line'=>$line};
Line 7710  sub grading_menu { Line 7832  sub grading_menu {
                 $menudata->{'url'}.'" >'.                  $menudata->{'url'}.'" >'.
                 $menudata->{'name'}."</a></h3>\n";                  $menudata->{'name'}."</a></h3>\n";
         } else {          } else {
             $Str .='    <h3><input type="button" value="'.&mt('Verify Receipt').'" '.              $Str .='<hr /><input type="button" value="'.&mt('Verify Receipt').'" '.
                 $menudata->{'jscript'}.                  $menudata->{'jscript'}.
                 ' onClick="javascript:checkChoice(document.forms.gradingMenu,\'5\',\'verify\')" '.                  ' onClick="javascript:checkChoice(document.forms.gradingMenu,\'5\',\'verify\')" '.
                 ' /></h3>';                  ' /> '.
             $Str .= ('&nbsp;'x8).   &Apache::lonnet::recprefix($env{'request.course.id'}).
  &mt(' receipt: [_1]',                      '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')" />';
     &Apache::lonnet::recprefix($env{'request.course.id'}).  
                     '-<input type="text" name="receipt" size="4" onChange="javascript:checkReceiptNo(this.form,\'OK\')" />');  
         }          }
         $Str .= '    '.('&nbsp;'x8).$menudata->{'short_description'}.          $Str .= '    '.('&nbsp;'x8).$menudata->{'short_description'}.
             "\n";              "\n";
Line 8450  sub handler { Line 8570  sub handler {
  &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));   &Apache::lonnet::logthis("grades got multiple commands ".join(':',@commands));
     }      }
   
       $ssi_error = 0;
     $request->print(&Apache::loncommon::start_page('Grading'));      $request->print(&Apache::loncommon::start_page('Grading'));
     if ($symb eq '' && $command eq '') {      if ($symb eq '' && $command eq '') {
  if ($env{'user.adv'}) {   if ($env{'user.adv'}) {
Line 8463  sub handler { Line 8583  sub handler {
  if ($tsymb) {   if ($tsymb) {
     my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);      my ($map,$id,$url)=&Apache::lonnet::decode_symb($tsymb);
     if (&Apache::lonnet::allowed('mgr',$tcrsid)) {      if (&Apache::lonnet::allowed('mgr',$tcrsid)) {
  $request->print(&Apache::lonnet::ssi_body('/res/'.$url,   $request->print(&ssi_with_retries('/res/'.$url, $ssi_retries,
   ('grade_username' => $tuname,    ('grade_username' => $tuname,
    'grade_domain' => $tudom,     'grade_domain' => $tudom,
    'grade_courseid' => $tcrsid,     'grade_courseid' => $tcrsid,
Line 8550  sub handler { Line 8670  sub handler {
     $request->print("Access Denied ($command)");      $request->print("Access Denied ($command)");
  }   }
     }      }
       if ($ssi_error) {
    &ssi_print_error($request);
       }
     $request->print(&Apache::loncommon::end_page());      $request->print(&Apache::loncommon::end_page());
     &reset_caches();      &reset_caches();
     return '';      return '';

Removed from v.1.508  
changed lines
  Added in v.1.515


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>