File:  [LON-CAPA] / loncom / homework / inputtags.pm
Revision 1.10: download - view: text, annotated - select for diffs
Mon Dec 4 21:15:33 2000 UTC (23 years, 5 months ago) by albertel
Branches: MAIN
CVS tags: HEAD
- fixed things up to work with grade
- removed <answergroup>
- added grad evalutors

    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:   &Apache::lonxml::debug("1 $result");
  117:   if ($result eq '' ) {
  118:     foreach $award (@_) { 
  119:       if ($award eq 'WANTED_NUMERIC' || 
  120: 	  $award eq 'BAD_FORMULA') {$result=$award; last;}
  121:     }
  122:   }
  123:   &Apache::lonxml::debug("2 $result");
  124:   if ($result eq '' ) {
  125:     foreach $award (@_) { if ($award eq 'SIG_FAIL') {$result=$award; last;} }
  126:   }
  127:   &Apache::lonxml::debug("3 $result");
  128:   if ($result eq '' ) {
  129:     foreach $award (@_) { if ($award eq 'INCORRECT') {$result=$award; last;} }
  130:   }
  131:   &Apache::lonxml::debug("4 $result");
  132:   if ($result eq '' ) {
  133:     foreach $award (@_) { if ($award eq 'APPROX_ANS') {$result=$award; last;} }
  134:   }
  135:   &Apache::lonxml::debug("5 $result");
  136:   if ($result eq '' ) { $result='EXACT_ANS'; }
  137:   &Apache::lonxml::debug("6 $result");
  138:   return $result
  139: }
  140: 
  141: sub decideoutput {
  142:   my ($award)=@_;
  143:   my $message='';
  144:   my $button=0;
  145:   my $tries=0;
  146:   if      ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
  147:     $message = "Yes, Computer gets: ";
  148:     $tries=1; $button=0;
  149:     
  150:   } elsif ($award eq 'WANTED_NUMERIC') {
  151:     $message = "This question expects a numeric answer";
  152:     $tries=0; $button=1;
  153:   } elsif ($award eq 'SIG_FAIL') {
  154:     $message = "Please adjust significant figures, you provided %s significant figures";
  155:     $tries=0; $button=1;
  156:   } elsif ($award eq 'UNIT_FAIL') {
  157:     $message = "Units incorrect, Computer reads units as %s";
  158:     $tries=0; $button=1;
  159:   } elsif ($award eq 'UNIT_NOTNEEDED') {
  160:     $message = "Only a number required, Computer reads units of %s";
  161:     $tries=0; $button=1;
  162:   } elsif ($award eq 'NO_UNIT') {
  163:     $message = "Units required";
  164:     $tries=0; $button=1;
  165:   } elsif ($award eq 'BAD_FORMULA') {
  166:     $message = "Unable to understand formula";
  167:     $tries=0; $button=1;
  168:   } elsif ($award eq 'INCORRECT') {
  169:     $message = "Incorrect";
  170:     $tries=0; $button=1;
  171:   } else {
  172:     $message = "Unknown message: $award";
  173:     $tries=0; $button=1;
  174:   }
  175:   return ($tries,$button,$message);
  176: }
  177: 
  178: sub grade {
  179:   my ($target) = @_;
  180:   my $id = $Apache::inputtags::part;
  181:   my $result='';
  182:   my $button='<input type="submit" name="submit" value="Submit All Answers">';
  183:   my $response='';
  184:   if ( $target == 'web' ) {
  185:     if ( defined $ENV{'form.submit'}) {
  186:       my @awards = ();
  187:       &Apache::lonxml::debug("$#Apache::inputtags::responselist");
  188:       foreach $response (@Apache::inputtags::responselist) {
  189: 	&Apache::lonxml::debug("looking for response.awarddetail.$id.$response");
  190: 	my $value=$Apache::lonhomework::results{"resource.awarddetail.$id.$response"};
  191: 	if ( $value ne '' ) {
  192: 	  &Apache::lonxml::debug("keep ing $value from $response for $id");
  193: 	  push (@awards,$value);
  194: 	} else {
  195: 	  &Apache::lonxml::debug("skipping $value from $response for $id");
  196: 	}
  197:       }
  198:       my $finalaward = &finalizeawards(@awards);
  199:       my ($triesinc,$showbutton,$message) = &decideoutput($finalaward);
  200:       $Apache::lonhomework::results{"resource.tries.$id"} =
  201: 	$Apache::lonhomework::history{"resource.tries.$id"} + 1;
  202:       &Apache::lonxml::debug("final award $finalaward");
  203:     }
  204:     if ($showbutton > 0) { $result.=$button }
  205:   }
  206:   return $result;
  207: }
  208: 
  209: 1;
  210: __END__
  211:  

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