Annotation of loncom/homework/inputtags.pm, revision 1.12
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # input definitons
3:
4: package Apache::inputtags;
5: use strict;
6:
7: sub BEGIN {
1.10 albertel 8: &Apache::lonxml::register('Apache::inputtags',('textarea','textline','datasubmission'));
1.1 albertel 9: }
10:
1.7 albertel 11:
1.1 albertel 12: sub initialize_inputtags {
1.7 albertel 13: @Apache::inputtags::input=();
14: @Apache::inputtags::response=();
1.9 albertel 15: @Apache::inputtags::responselist=();
1.7 albertel 16: @Apache::inputtags::answergroup=();
1.8 albertel 17: $Apache::inputtags::part='';
1.7 albertel 18: %Apache::inputtags::params=();
1.1 albertel 19: }
20:
1.6 albertel 21: sub start_textarea {
22: my ($target,$token,$parstack,$parser,$safeeval)=@_;
23: my $result = "";
24: if ($target eq 'web') {
1.7 albertel 25: $result= '<textarea name="HWVAL'.$Apache::inputtags::curvalue.'" value="">';
1.6 albertel 26: }
27: return $result;
28: }
29:
30: sub end_textarea {
31: my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.10 albertel 32: if ($target eq 'web') {
33: return "</textarea>";
34: }
35: return '';
1.6 albertel 36: }
37:
1.1 albertel 38: sub start_textline {
39: my ($target,$token,$parstack,$parser,$safeeval)=@_;
40: my $result = "";
41: if ($target eq 'web') {
1.10 albertel 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; }
1.7 albertel 46: $result= '<input type="text" name="HWVAL'.$Apache::inputtags::curvalue.'" value="" size="'.$size.'">';
1.1 albertel 47: }
48: return $result;
49: }
50:
51: sub end_textline {
52: my ($target,$token,$parstack,$parser,$safeeval)=@_;
1.6 albertel 53: return "";
1.1 albertel 54: }
55:
1.10 albertel 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: #}
1.6 albertel 89:
90:
91: sub start_datasubmission {
92: }
93:
94: sub end_datasubmission {
95: my ($target,$token,$parstack,$parser,$safeeval)=@_;
96: if ( $target == 'web' ) {
1.7 albertel 97: return '<input type="submit" name="submit" value="Submit All Data">';
1.2 albertel 98: }
1.10 albertel 99: return '';
1.9 albertel 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:
1.10 albertel 135: sub decideoutput {
136: my ($award)=@_;
137: my $message='';
138: my $button=0;
139: if ($award eq 'EXACT_ANS' || $award eq 'APPROX_ANS' ) {
1.12 ! albertel 140: $message = "Correct computer gets %s";
! 141: $button=0;
1.10 albertel 142: } elsif ($award eq 'WANTED_NUMERIC') {
143: $message = "This question expects a numeric answer";
1.12 ! albertel 144: $button=1;
1.10 albertel 145: } elsif ($award eq 'SIG_FAIL') {
146: $message = "Please adjust significant figures, you provided %s significant figures";
1.12 ! albertel 147: $button=1;
1.10 albertel 148: } elsif ($award eq 'UNIT_FAIL') {
149: $message = "Units incorrect, Computer reads units as %s";
1.12 ! albertel 150: $button=1;
1.10 albertel 151: } elsif ($award eq 'UNIT_NOTNEEDED') {
152: $message = "Only a number required, Computer reads units of %s";
1.12 ! albertel 153: $button=1;
1.10 albertel 154: } elsif ($award eq 'NO_UNIT') {
155: $message = "Units required";
1.12 ! albertel 156: $button=1;
1.10 albertel 157: } elsif ($award eq 'BAD_FORMULA') {
158: $message = "Unable to understand formula";
1.12 ! albertel 159: $button=1;
1.10 albertel 160: } elsif ($award eq 'INCORRECT') {
161: $message = "Incorrect";
1.12 ! albertel 162: $button=1;
1.10 albertel 163: } else {
164: $message = "Unknown message: $award";
1.12 ! albertel 165: $button=1;
1.10 albertel 166: }
1.12 ! albertel 167: return ($button,$message);
! 168: }
! 169:
! 170: sub setgradedata {
! 171: my ($award,$id) = @_;
! 172: if ( $award eq 'APPROX_ANS' || $award eq 'EXACT_ANS' ) {
! 173: $Apache::lonhomework::results{"resource.tries.$id"} =
! 174: $Apache::lonhomework::history{"resource.tries.$id"} + 1;
! 175: $Apache::lonhomework::results{"resource.solved.$id"} =
! 176: 'correct_by_student';
! 177: $Apache::lonhomework::results{"resource.awarded.$id"} = '1';
! 178: } elsif ( $award eq 'INCORRECT' ) {
! 179: $Apache::lonhomework::results{"resource.tries.$id"} =
! 180: $Apache::lonhomework::history{"resource.tries.$id"} + 1;
! 181: $Apache::lonhomework::results{"resource.solved.$id"} =
! 182: 'incorrect_attempted';
! 183: } else {
! 184: $Apache::lonhomework::results{"resource.solved.$id"} =
! 185: 'incorrect_attempted';
! 186: }
! 187: $Apache::lonhomework::results{"resource.award.$id"} = $award;
1.10 albertel 188: }
189:
1.9 albertel 190: sub grade {
191: my ($target) = @_;
192: my $id = $Apache::inputtags::part;
193: my $result='';
194: my $response='';
195: if ( $target == 'web' ) {
196: if ( defined $ENV{'form.submit'}) {
197: my @awards = ();
1.10 albertel 198: &Apache::lonxml::debug("$#Apache::inputtags::responselist");
1.9 albertel 199: foreach $response (@Apache::inputtags::responselist) {
1.10 albertel 200: &Apache::lonxml::debug("looking for response.awarddetail.$id.$response");
201: my $value=$Apache::lonhomework::results{"resource.awarddetail.$id.$response"};
1.9 albertel 202: if ( $value ne '' ) {
203: &Apache::lonxml::debug("keep ing $value from $response for $id");
204: push (@awards,$value);
205: } else {
206: &Apache::lonxml::debug("skipping $value from $response for $id");
207: }
208: }
209: my $finalaward = &finalizeawards(@awards);
210: &Apache::lonxml::debug("final award $finalaward");
1.12 ! albertel 211: &setgradedata($finalaward,$id);
1.9 albertel 212: }
213: }
214: return $result;
1.1 albertel 215: }
216:
1.11 albertel 217: sub gradestatus {
1.12 ! albertel 218: my ($id) = @_;
! 219: my $showbutton = 1;
! 220: my $message = '';
! 221: my $award = $Apache::lonhomework::history{"resource.award.$id"};
! 222: &Apache::lonxml::debug("Found Award |$award|");
! 223: if ( $award ne '' ) {
! 224: &Apache::lonxml::debug('Getting message');
! 225: ($showbutton,$message) = &decideoutput($award);
! 226: }
! 227: my $button='';
! 228: my $tries = $Apache::lonhomework::history{"resource.tries.$id"};
! 229: my $maxtries = $Apache::lonhomework::history{"resource.maxtries.$id"};
! 230: if ( $tries eq '' ) { $tries = '0'; }
! 231: if ( $maxtries eq '' ) { $maxtries = '99'; }
! 232: if ( $tries >= $maxtries ) { $showbutton = 0; }
! 233: my $trystr = "Tries $tries/$maxtries";
! 234: if ( $showbutton ) {
! 235: $button = '<input type="submit" name="submit" value="Submit All Answers"><br></br>';
! 236: }
! 237: return $button.$message.$trystr;
1.11 albertel 238: }
1.1 albertel 239: 1;
240: __END__
241:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>