File:  [LON-CAPA] / loncom / homework / inputtags.pm
Revision 1.13: download - view: text, annotated - select for diffs
Fri Dec 8 20:53:45 2000 UTC (23 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- debug messages only appear for user debug
- empty responses are ignored
- try counts don't appear once the problem is correct

    1: # The LearningOnline Network with CAPA
    2: # input  definitons
    3: 
    4: package Apache::inputtags;
    5: use strict;
    6: 
    7: sub BEGIN {
    8:   &Apache::lonxml::register('Apache::inputtags',('textarea','textline','datasubmission'));
    9: }
   10: 
   11: 
   12: sub initialize_inputtags {
   13:   @Apache::inputtags::input=();
   14:   @Apache::inputtags::response=();
   15:   @Apache::inputtags::responselist=();
   16:   @Apache::inputtags::answergroup=();
   17:   $Apache::inputtags::part='';
   18:   %Apache::inputtags::params=();
   19: }
   20: 
   21: sub start_textarea {
   22:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
   23:   my $result = "";
   24:   if ($target eq 'web') {
   25:     $result= '<textarea name="HWVAL'.$Apache::inputtags::curvalue.'" value="">';
   26:   }
   27:   return $result;
   28: }
   29: 
   30: sub end_textarea {
   31:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
   32:   if ($target eq 'web') {
   33:     return "</textarea>";
   34:   } 
   35:   return '';
   36: }
   37: 
   38: sub start_textline {
   39:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
   40:   my $result = "";
   41:   if ($target eq 'web') {
   42:     my $args ='';
   43:     if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
   44:     my $size = &Apache::run::run("{$args;".'return $size}',$safeeval);
   45:     if ($size eq '') { $size=20; }
   46:     $result= '<input type="text" name="HWVAL'.$Apache::inputtags::curvalue.'" value="" size="'.$size.'">';
   47:   }
   48:   return $result;
   49: }
   50: 
   51: sub end_textline {
   52:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
   53:   return "";
   54: }
   55: 
   56: #answergroup is deprecated
   57: #sub start_answergroup {
   58: #  my ($target,$token,$parstack,$parser,$safeeval)=@_;
   59: #  my $args ='';
   60: #  if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
   61: #  my $id = &Apache::run::run("{$args;".'return $id}',$safeeval);
   62: #  push (@Apache::inputtags::answergroup,$id);
   63: #  if ($target == 'web') {
   64: #    
   65: #  }
   66: #  return '';
   67: #}
   68: #
   69: #sub end_answergroup {
   70: #  my ($target,$token,$parstack,$parser,$safeeval)=@_;
   71: #  return ''; # <answergroup> has ben deprecated
   72: #  my $args ='';
   73: #  if ( $#$parstack > -1 ) { $args=$$parstack[$#$parstack]; }
   74: #  my $id = &Apache::run::run("{$args;".'return $id}',$safeeval);
   75: #  push (@Apache::inputtags::answergroup,$id);
   76: #  my $result='';
   77: #  my $button='<input type="submit" name="submit" value="Submit All Answers">';
   78: #  my $showbutton='1';
   79: #  my $usedtry='1';
   80: #  my $response='';
   81: #  if ( $target == 'web' ) {
   82: #    if ( defined $ENV{'form.submit'}) {
   83: #    }
   84: #    if ($showbutton > 0) { $result.=$button }
   85: #  }
   86: #  pop @Apache::inputtags::answergroup;
   87: #  return $result;
   88: #}
   89: 
   90: 
   91: sub start_datasubmission {
   92: }
   93: 
   94: sub end_datasubmission {
   95:   my ($target,$token,$parstack,$parser,$safeeval)=@_;
   96:   if ( $target == 'web' ) {
   97:     return '<input type="submit" name="submit" value="Submit All Data">';
   98:   }
   99:   return '';
  100: }
  101: 
  102: sub finalizeawards {
  103:   my $result='';
  104:   my $award;
  105:   if ($#_ == '-1') { $result = "NO_RESPONSE"; }
  106:   foreach $award (@_) { if ($award eq '') {$result='MISSING_ANSWER'; last;}}
  107:   if ($result eq '' ) {
  108:     foreach $award (@_) { 
  109:       if ($award eq 'UNIT_FAIL' ||
  110: 	  $award eq 'NO_UNIT' ||
  111: 	  $award eq 'UNIT_NOTNEEDED') {
  112: 	$result=$award; last;
  113:       }
  114:     }
  115:   }
  116:   if ($result eq '' ) {
  117:     foreach $award (@_) { 
  118:       if ($award eq 'WANTED_NUMERIC' || 
  119: 	  $award eq 'BAD_FORMULA') {$result=$award; last;}
  120:     }
  121:   }
  122:   if ($result eq '' ) {
  123:     foreach $award (@_) { if ($award eq 'SIG_FAIL') {$result=$award; last;} }
  124:   }
  125:   if ($result eq '' ) {
  126:     foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} }
  127:   }
  128:   if ($result eq '' ) {
  129:     foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} }
  130:   }
  131:   if ($result eq '' ) { $result='EXACT_ANS'; }
  132:   return $result
  133: }
  134: 
  135: sub decideoutput {
  136:   my ($award)=@_;
  137:   my $message='';
  138:   my $button=0;
  139:   if      ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
  140:     $message = "Correct computer gets %s";
  141:     $button=0;
  142:   } elsif ($award eq 'NO_RESPONSE') {
  143:     $message = '';
  144:     $button=1;
  145:   } elsif ($award eq 'WANTED_NUMERIC') {
  146:     $message = "This question expects a numeric answer";
  147:     $button=1;
  148:   } elsif ($award eq 'SIG_FAIL') {
  149:     $message = "Please adjust significant figures, you provided %s significant figures";
  150:     $button=1;
  151:   } elsif ($award eq 'UNIT_FAIL') {
  152:     $message = "Units incorrect, Computer reads units as %s";
  153:     $button=1;
  154:   } elsif ($award eq 'UNIT_NOTNEEDED') {
  155:     $message = "Only a number required, Computer reads units of %s";
  156:     $button=1;
  157:   } elsif ($award eq 'NO_UNIT') {
  158:     $message = "Units required";
  159:     $button=1;
  160:   } elsif ($award eq 'BAD_FORMULA') {
  161:     $message = "Unable to understand formula";
  162:     $button=1;
  163:   } elsif ($award eq 'INCORRECT') {
  164:     $message = "Incorrect";
  165:     $button=1;
  166:   } else {
  167:     $message = "Unknown message: $award";
  168:     $button=1;
  169:   }
  170:   return ($button,$message);
  171: }
  172: 
  173: sub setgradedata {
  174:   my ($award,$id) = @_;
  175:   if ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
  176:     $Apache::lonhomework::results{"resource.tries.$id"} =
  177:       $Apache::lonhomework::history{"resource.tries.$id"} + 1;
  178:     $Apache::lonhomework::results{"resource.solved.$id"} =
  179:       'correct_by_student';
  180:     $Apache::lonhomework::results{"resource.awarded.$id"} = '1';
  181:   } elsif ( $award eq 'INCORRECT' ) {
  182:     $Apache::lonhomework::results{"resource.tries.$id"} =
  183:       $Apache::lonhomework::history{"resource.tries.$id"} + 1;
  184:     $Apache::lonhomework::results{"resource.solved.$id"} =
  185:       'incorrect_attempted';
  186:   } else {
  187:     $Apache::lonhomework::results{"resource.solved.$id"} =
  188:       'incorrect_attempted';
  189:   }
  190:   $Apache::lonhomework::results{"resource.award.$id"} = $award;
  191: }
  192: 
  193: sub grade {
  194:   my ($target) = @_;
  195:   my $id = $Apache::inputtags::part;
  196:   my $result='';
  197:   my $response='';
  198:   if ( $target == 'web' ) {
  199:     if ( defined $ENV{'form.submit'}) {
  200:       my @awards = ();
  201:       &Apache::lonxml::debug("$#Apache::inputtags::responselist");
  202:       foreach $response (@Apache::inputtags::responselist) {
  203: 	&Apache::lonxml::debug("looking for response.awarddetail.$id.$response");
  204: 	my $value=$Apache::lonhomework::results{"resource.awarddetail.$id.$response"};
  205: 	if ( $value ne '' ) {
  206: 	  &Apache::lonxml::debug("keep ing $value from $response for $id");
  207: 	  push (@awards,$value);
  208: 	} else {
  209: 	  &Apache::lonxml::debug("skipping $value from $response for $id");
  210: 	}
  211:       }
  212:       my $finalaward = &finalizeawards(@awards);
  213:       &Apache::lonxml::debug("final award $finalaward");
  214:       &setgradedata($finalaward,$id);
  215:     }
  216:   }
  217:   return $result;
  218: }
  219: 
  220: sub gradestatus {
  221:   my ($id) = @_;
  222:   my $showbutton = 1;
  223:   my $message = '';
  224:   my $award = $Apache::lonhomework::history{"resource.award.$id"};
  225:   &Apache::lonxml::debug("Found Award |$award|");
  226:   if ( $award ne '' ) {
  227:     &Apache::lonxml::debug('Getting message');
  228:     ($showbutton,$message) = &decideoutput($award);
  229:   }
  230:   my $button='';
  231:   my $tries = $Apache::lonhomework::history{"resource.tries.$id"};
  232:   my $maxtries = $Apache::lonhomework::history{"resource.maxtries.$id"};
  233:   if ( $tries eq '' ) { $tries = '0'; }
  234:   if ( $maxtries eq '' ) { $maxtries = '2'; } 
  235:   my $trystr='';
  236:   if ( $showbutton ) {
  237:     $trystr = "<br></br>Tries $tries/$maxtries";
  238:   }
  239:   if ( $tries >= $maxtries ) { $showbutton = 0; }
  240:   if ( $showbutton ) { 
  241:     $button = '<input type="submit" name="submit" value="Submit All Answers"><br></br>';
  242:   }
  243:   return $button.$message.$trystr;
  244: }
  245: 1;
  246: __END__
  247:  

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