Annotation of loncom/homework/response.pm, revision 1.87
1.38 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # various response type definitons response definition
1.53 albertel 3: #
1.87 ! albertel 4: # $Id: response.pm,v 1.86 2003/10/06 21:57:54 albertel Exp $
1.53 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.5 www 28:
1.1 albertel 29: package Apache::response;
30: use strict;
31:
1.57 harris41 32: BEGIN {
1.73 albertel 33: &Apache::lonxml::register('Apache::response',('responseparam','parameter','dataresponse'));
1.1 albertel 34: }
35:
1.13 albertel 36: sub start_response {
1.73 albertel 37: my ($parstack,$safeeval)=@_;
38: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
39: if ($id eq '') { $id = $Apache::lonxml::curdepth; }
40: if ($#Apache::inputtags::import > -1) {
41: &Apache::lonxml::debug("Turning :$id: into");
42: $id = join('_',@Apache::inputtags::import).'_'.$id;
43: &Apache::lonxml::debug("New :$id:");
44: }
45: push (@Apache::inputtags::response,$id);
46: push (@Apache::inputtags::responselist,$id);
47: @Apache::inputtags::inputlist=();
48: return $id;
1.13 albertel 49: }
50:
51: sub end_response {
1.79 albertel 52: #pop @Apache::inputtags::response;
1.73 albertel 53: @Apache::inputtags::inputlist=();
54: return '';
1.13 albertel 55: }
56:
1.41 albertel 57: sub start_hintresponse {
1.73 albertel 58: my ($parstack,$safeeval)=@_;
59: my $id= &Apache::lonxml::get_param('id',$parstack,$safeeval);
60: if ($id eq '') { $id = $Apache::lonxml::curdepth; }
61: push (@Apache::inputtags::response,$id);
1.79 albertel 62: push (@Apache::inputtags::responselist,$id);
1.73 albertel 63: push (@Apache::inputtags::paramstack,[%Apache::inputtags::params]);
64: return $id;
1.41 albertel 65: }
66:
67: sub end_hintresponse {
1.73 albertel 68: pop @Apache::inputtags::response;
69: if (defined($Apache::inputtags::paramstack[-1])) {
70: %Apache::inputtags::params=
71: @{ pop(@Apache::inputtags::paramstack) };
72: }
73: return '';
1.41 albertel 74: }
75:
1.38 albertel 76: # used by response to set the non-safe space random number generator to something
77: # that is stable and unique based on the part number and response number
1.26 albertel 78: sub setrandomnumber {
1.73 albertel 79: my $rndseed;
80: if ($ENV{'request.state'} eq "construct") {
81: $rndseed=$ENV{'form.rndseed'};
82: if (!$rndseed) { $rndseed=time; }
83: } else {
1.74 albertel 84: $rndseed=&Apache::lonnet::rndseed();
1.73 albertel 85: }
86: &Apache::lonxml::debug("randseed $rndseed");
87: # $rndseed=unpack("%32i",$rndseed);
1.74 albertel 88: my $rndmod=(&Apache::lonnet::numval($Apache::inputtags::part) << 10);
1.73 albertel 89: if (defined($Apache::inputtags::response['-1'])) {
1.74 albertel 90: $rndmod+=&Apache::lonnet::numval($Apache::inputtags::response[-1]);
1.73 albertel 91: }
1.74 albertel 92: if ($rndseed =~/,/) {
1.82 albertel 93: {
94: use integer;
95: my ($num1,$num2)=split(/,/,$rndseed);
96: $num1+=$rndmod;
97: $num2+=$rndmod;
98: $rndseed="$num1,$num2";
99: }
1.74 albertel 100: } else {
101: $rndseed+=$rndmod;
102: }
103: &Apache::lonnet::setup_random_from_rndseed($rndseed);
1.73 albertel 104: &Apache::lonxml::debug("randseed $rndseed");
105: return '';
1.26 albertel 106: }
107:
1.7 www 108: sub meta_parameter_write {
1.38 albertel 109: my ($name,$type,$default,$display)=@_;
1.41 albertel 110: my $partref=$Apache::inputtags::part;
111: my $result='<parameter part="'.$Apache::inputtags::part.'"';
112: if (defined($Apache::inputtags::response[-1])) {
1.73 albertel 113: $result.= ' id="'.$Apache::inputtags::response[-1].'"';
114: $partref.='_'.$Apache::inputtags::response[-1];
1.41 albertel 115: }
116: $result.= ' name="'.$name.'"'.
117: ' type="'.$type.'"'.
118: ($default?' default="'.$default.'"':'').
119: ($display?' display="'.$display.' [Part: '.$partref.']"':'')
120: .'></parameter>'
121: ."\n";
122: return $result;
1.33 www 123: }
124:
125: sub meta_package_write {
126: my $name=shift;
1.41 albertel 127: my $result = '<parameter part="'.$Apache::inputtags::part.'"';
128: if(defined($Apache::inputtags::response[-1])) {
1.73 albertel 129: $result.= ' id="'.$Apache::inputtags::response[-1].'"';
1.41 albertel 130: }
131: $result.=' package="'.$name.'"></parameter>'."\n";
132: return $result;
1.7 www 133: }
134:
135: sub meta_stores_write {
1.10 www 136: my ($name,$type,$display)=@_;
1.41 albertel 137: my $partref=$Apache::inputtags::part;
138: my $result = '<stores part="'.$Apache::inputtags::part.'"';
139: if (defined($Apache::inputtags::response[-1])) {
1.73 albertel 140: $result.= ' id="'.$Apache::inputtags::response[-1].'"';
141: $partref.='_'.$Apache::inputtags::response[-1];
1.41 albertel 142: }
143: $result.= ' name="'.$name.'"'.
144: ' type="'.$type.'"'.
145: ' display="'.$display.' [Part: '.$partref.']"'.
146: "></stores>\n";
1.7 www 147: }
148:
149: sub mandatory_part_meta {
150: #
151: # Autogenerate metadata for mandatory
152: # input (from RAT or lonparmset) and
153: # output (to lonspreadsheet)
154: # of each part
155: #
1.73 albertel 156: return
1.34 www 157: # &meta_parameter_write('opendate','date_start','',
158: # 'Opening Date').
159: # &meta_parameter_write('duedate','date_end','',
160: # 'Due Date').
161: # &meta_parameter_write('answerdate','date_start','',
162: # 'Show Answer Date').
163: # &meta_parameter_write('weight','int_zeropos','',
164: # 'Available Points').
165: # &meta_parameter_write('maxtries','int_pos','',
166: # 'Maximum Number of Tries').
1.73 albertel 167: &meta_package_write('part').
168: &meta_stores_write('solved','string',
169: 'Problem Status').
170: &meta_stores_write('tries','int_zeropos',
171: 'Number of Attempts').
172: &meta_stores_write('awarded','float',
173: 'Partial Credit Factor');
1.7 www 174: #
175: # Note: responseid-specific data 'submission' and 'awarddetail'
176: # not available to spreadsheet -> skip here
177: #
1.86 albertel 178: }
179:
180: sub meta_part_order {
181: if (@Apache::inputtags::partlist) {
182: my @parts=@Apache::inputtags::partlist;
183: shift(@parts);
184: return '<partorder>'.join(',',@parts).'</partorder>';
185: } else {
186: return '<partorder>0</partorder>';
187: }
1.14 albertel 188: }
189:
1.15 albertel 190: sub check_for_previous {
1.73 albertel 191: my ($curresponse,$partid,$id) = @_;
192: my %previous;
193: $previous{'used'} = 0;
194: foreach my $key (sort(keys(%Apache::lonhomework::history))) {
195: if ($key =~ /resource\.$partid\.$id\.submission/) {
196: &Apache::lonxml::debug("Trying $key");
197: my $pastresponse=$Apache::lonhomework::history{$key};
198: if ($pastresponse eq $curresponse) {
199: $previous{'used'} = 1;
200: my $history;
201: if ( $key =~ /^(\d+):/ ) {
202: $history=$1;
203: $previous{'award'} = $Apache::lonhomework::history{"$history:resource.$partid.$id.awarddetail"};
204: $previous{'last'}='0';
205: push(@{ $previous{'version'} },$history);
206: } else {
207: $previous{'award'} = $Apache::lonhomework::history{"resource.$partid.$id.awarddetail"};
208: $previous{'last'}='1';
209: }
210: if (! $previous{'award'} ) { $previous{'award'} = 'UNKNOWN'; }
211: &Apache::lonxml::debug("got a match :$previous{'award'}:$previous{'used'}:");
212: }
1.32 albertel 213: }
1.73 albertel 214: }
215: &Apache::lonhomework::showhash(%previous);
216: return %previous;
1.54 albertel 217: }
218:
219: sub handle_previous {
1.73 albertel 220: my ($previous,$ad)=@_;
221: if ($$previous{'used'} && ($$previous{'award'} eq $ad) ) {
222: if ($$previous{'last'}) {
223: push(@Apache::inputtags::previous,'PREVIOUSLY_LAST');
224: } else {
225: push(@Apache::inputtags::previous,'PREVIOUSLY_USED');
226: }
227: push(@Apache::inputtags::previous_version,$$previous{'version'});
1.54 albertel 228: }
1.44 albertel 229: }
230:
1.45 albertel 231: sub view_or_modify {
1.73 albertel 232: my ($symb,$courseid,$domain,$name) = &Apache::lonxml::whichuser();
233: my $myself=0;
234: if ( ($name eq $ENV{'user.name'}) && ($domain eq $ENV{'user.domain'}) ) {
235: $myself=1;
236: }
237: my $vgr=&Apache::lonnet::allowed('vgr',$courseid);
238: my $mgr=&Apache::lonnet::allowed('vgr',$courseid);
239: if ($mgr) { return "M"; }
240: if ($vgr) { return "V"; }
241: if ($myself) { return "V"; }
242: return '';
1.45 albertel 243: }
244:
1.44 albertel 245: sub start_dataresponse {
1.73 albertel 246: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
247: my $id = &Apache::response::start_response($parstack,$safeeval);
248: my $result;
249: if ($target eq 'web') {
250: $result = $token->[2]->{'display'}.':';
251: } elsif ($target eq 'meta') {
252: $result = &Apache::response::meta_stores_write($token->[2]->{'name'},
253: $token->[2]->{'type'},
254: $token->[2]->{'display'});
255: $result .= &Apache::response::meta_package_write('dataresponse');
256: }
257: return $result;
1.44 albertel 258: }
259:
260: sub end_dataresponse {
1.73 albertel 261: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
262: my $result;
263: if ( $target eq 'web' ) {
264: } elsif ($target eq 'grade' ) {
265: if ( defined $ENV{'form.submitted'}) {
266: my ($symb,$courseid,$domain,$name)=&Apache::lonxml::whichuser();
267: my $allowed=&Apache::lonnet::allowed('mgr',$courseid);
268: if ($allowed) {
269: &Apache::response::setup_params('dataresponse');
270: my $partid = $Apache::inputtags::part;
271: my $id = $Apache::inputtags::response['-1'];
272: my $response = $ENV{'form.HWVAL_'.$id};
273: my $name = &Apache::lonxml::get_param('name',$parstack,$safeeval);
274: if ( $response =~ /[^\s]/) {
275: $Apache::lonhomework::results{"resource.$partid.$id.$name"}=$response;
276: $Apache::lonhomework::results{"resource.$partid.$id.submission"}=$response;
277: $Apache::lonhomework::results{"resource.$partid.$id.awarddetail"}='SUBMITTED';
278: }
279: } else {
280: $result='Not Permitted to change values.'
281: }
1.45 albertel 282: }
1.73 albertel 283: }
284: &Apache::response::end_response;
285: return $result;
1.3 albertel 286: }
287:
1.83 albertel 288: sub decide_package {
289: my ($tagstack)=@_;
290: my $package;
291: if ($$tagstack[-1] eq 'parameter') {
292: $package='part';
293: } else {
294: my $i=-1;
295: while (defined($$tagstack[$i])) {
296: if ($$tagstack[$i] =~ /(response|hint)$/) {
297: $package=$$tagstack[$i];
298: last;
299: }
300: $i--;
301: }
302: }
303: return $package;
304: }
305:
1.3 albertel 306: sub start_responseparam {
1.73 albertel 307: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
308: my $result='';
309: if ($target eq 'meta') {
310: $result = &meta_parameter_write($token->[2]->{'name'},
311: $token->[2]->{'type'},
312: $token->[2]->{'default'},
313: $token->[2]->{'description'});
314: } elsif ($target eq 'edit') {
315: $result.=&Apache::edit::tag_start($target,$token);
1.83 albertel 316: my $optionlist;
317: my $package=&decide_package($tagstack);
318: foreach my $key (sort(keys(%Apache::lonnet::packagetab))) {
319: if ($key =~ /^\Q$package\E&(.*)&display$/) {
320: $optionlist.='<option value="'.$1.'">'.
321: $Apache::lonnet::packagetab{$key}.'</option>';
322: }
323: }
324: if (defined($optionlist)) {
325: $result.='Use template: <select name="'.
326: &Apache::edit::html_element_name('parameter_package').'">'.
327: '<option value=""></option>'.$optionlist.'</select><br />';
328: }
1.73 albertel 329: $result.=&Apache::edit::text_arg('Name:','name',$token).
330: &Apache::edit::text_arg('Type:','type',$token).
331: &Apache::edit::text_arg('Description:','description',$token).
332: &Apache::edit::text_arg('Default:','default',$token).
333: "</td></tr>";
334: $result.=&Apache::edit::end_table;
335: } elsif ($target eq 'modified') {
1.83 albertel 336: my $constructtag=&Apache::edit::get_new_args($token,$parstack,
337: $safeeval,'name','type',
338: 'description','default');
339: my $element=&Apache::edit::html_element_name('parameter_package');
340: if (defined($ENV{"form.$element"}) && $ENV{"form.$element"} ne '') {
341: my $name=$ENV{"form.$element"};
342: my $tag=&decide_package($tagstack);
343: $token->[2]->{'name'}=$name;
344: $token->[2]->{'type'}=
345: $Apache::lonnet::packagetab{"$tag&$name&type"};
346: $token->[2]->{'description'}=
347: $Apache::lonnet::packagetab{"$tag&$name&display"};
348: $token->[2]->{'default'}=
349: $Apache::lonnet::packagetab{"$tag&$name&default"};
350: $constructtag=1;
351: }
1.73 albertel 352: if ($constructtag) {
353: $result = &Apache::edit::rebuild_tag($token);
354: $result.=&Apache::edit::handle_insert();
355: }
356: } elsif ($target eq 'grade' || $target eq 'answer' || $target eq 'web' ||
357: $target eq 'tex' || $target eq 'analyze' ) {
358: if ($ENV{'request.state'} eq 'construct') {
359: my $name =&Apache::lonxml::get_param('name',$parstack,$safeeval);
360: my $default=&Apache::lonxml::get_param('default',$parstack,
361: $safeeval);
362: if ($name) {$Apache::inputtags::params{$name}=$default;}
363: }
1.52 albertel 364: }
1.73 albertel 365: return $result;
1.3 albertel 366: }
367:
368: sub end_responseparam {
1.73 albertel 369: my ($target,$token,$tagstack,$parstack,$parser,$safeeval)=@_;
370: if ($target eq 'edit') { return ('','no'); }
371: return '';
1.55 albertel 372: }
373:
374: sub start_parameter {
1.73 albertel 375: my $result = &start_responseparam(@_);
376: return $result;
1.55 albertel 377: }
378:
379: sub end_parameter {
1.73 albertel 380: my $result = &end_responseparam(@_);
381: return $result;
1.42 albertel 382: }
383:
1.67 albertel 384: sub reset_params {
385: %Apache::inputtags::params=();
386: }
387:
1.42 albertel 388: sub setup_params {
1.73 albertel 389: my ($tag) = @_;
1.42 albertel 390:
1.73 albertel 391: if ($ENV{'request.state'} eq 'construct') { return; }
392: my %paramlist=();
393: foreach my $key (keys(%Apache::lonnet::packagetab)) {
394: if ($key =~ /^$tag/) {
395: my ($package,$name) = split(/&/,$key);
396: $paramlist{$name}=1;
397: }
1.42 albertel 398: }
1.73 albertel 399: foreach my $key (keys(%paramlist)) {
400: my $entry= 'resource.'.$Apache::inputtags::part;
401: if (defined($Apache::inputtags::response[-1])) {
402: $entry.='_'.$Apache::inputtags::response[-1];
403: }
404: $entry.='.'.$key;
405: &Apache::lonxml::debug("looking for $entry");
406: my $value = &Apache::lonnet::EXT("$entry");
407: &Apache::lonxml::debug("$key has value :$value:");
408: if ($value eq 'con_lost' || $value =~ /^error:/) {
409: &Apache::lonxml::debug("using nothing");
410: $Apache::inputtags::params{$key}='';
411: } else {
412: &Apache::lonxml::debug("using value");
413: $Apache::inputtags::params{$key}=$value;
414: }
1.42 albertel 415: }
1.48 albertel 416: }
417:
418: sub answer_header {
1.73 albertel 419: my ($type) = @_;
420: my $result;
1.77 albertel 421: if ($ENV{'form.answer_output_mode'} eq 'tex') {
1.84 sakharuk 422: $result = ' \vskip 0 mm \begin{tabular}{|c|}\hline Answer for Part: \verb|'.
423: $Apache::inputtags::part.'| \\\\ \hline ';
1.73 albertel 424: } else {
1.80 albertel 425: $result = '<table border="1"><tr><td>Answer for Part:'.
426: $Apache::inputtags::part. '</td>'."\n";
1.73 albertel 427: }
428: return $result;
1.48 albertel 429: }
430:
431: sub answer_part {
1.73 albertel 432: my ($type,$answer) = @_;
433: my $result;
1.77 albertel 434: if ($ENV{'form.answer_output_mode'} eq 'tex') {
1.81 sakharuk 435: $result = ' \verb|'.$answer.'|\\\\ \hline ';
1.73 albertel 436: } else {
1.80 albertel 437: $result = '<td>'.$answer.'</td>';
1.73 albertel 438: }
439: return $result;
1.48 albertel 440: }
441:
442: sub answer_footer {
1.73 albertel 443: my ($type) = @_;
444: my $result;
1.77 albertel 445: if ($ENV{'form.answer_output_mode'} eq 'tex') {
1.75 sakharuk 446: $result = ' \end{tabular} \vskip 0 mm ';
1.73 albertel 447: } else {
1.80 albertel 448: $result = '</tr></table>';
1.73 albertel 449: }
450: return $result;
1.1 albertel 451: }
1.2 albertel 452:
1.62 albertel 453: sub showallfoils {
1.73 albertel 454: my $return=0;
455: if (defined($ENV{'form.showallfoils'}) &&
456: $ENV{'request.state'} eq 'construct') {
457: $return=1;
458: }
459: return $return;
1.70 albertel 460: }
461:
462: sub getresponse {
463: my ($temp)=@_;
464: my $formparm='form.HWVAL_'.$Apache::inputtags::response['-1'];
465: my $response;
466: if (!defined($temp)) {
467: $temp=1;
468: } else {
469: $formparm.=":$temp";
470: }
471: my %let_to_num=('A'=>0,'B'=>1,'C'=>2,'D'=>3,'E'=>4,'F'=>5,'G'=>6,'H'=>7,
472: 'I'=>8,'J'=>9,'K'=>10,'L'=>11,'M'=>12,'N'=>13,'O'=>14,
473: 'P'=>15,'Q'=>16,'R'=>17,'S'=>18,'T'=>19,'U'=>20,'V'=>21,
474: 'W'=>22,'X'=>23,'Y'=>24,'Z'=>25);
475: if ($ENV{'form.submitted'} eq 'scantron') {
1.71 albertel 476: my $part = $Apache::inputtags::part;
477: my $id = $Apache::inputtags::response[-1];
1.70 albertel 478: $response = $ENV{'scantron.'.($Apache::lonxml::counter+$temp-1).
479: '.answer'};
1.71 albertel 480: # save bubbled letter for later
481: $Apache::lonhomework::results{"resource.$part.$id.scantron"}.=
482: $response;
1.70 albertel 483: $response = $let_to_num{$response};
484: } else {
485: $response = $ENV{$formparm};
486: }
487: return $response;
1.62 albertel 488: }
1.71 albertel 489:
490: sub repetition {
491: my $id = $Apache::inputtags::part;
492: my $weight = &Apache::lonnet::EXT("resource.$id.weight");
493: my $repetition = int $weight/9;
494: if ($weight % 9 != 0) {$repetition++;}
1.72 albertel 495: return $repetition;
496: }
497:
498: sub scored_response {
499: my ($part,$id)=@_;
500: my $repetition=&repetition();
501: my $score=0;
502: for (my $i=0;$i<$repetition;$i++) {
503: my $increase=&Apache::response::getresponse($i+1);
504: if ($increase ne '') { $score+=$increase+1; }
505: }
506: my $weight = &Apache::lonnet::EXT("resource.$part.weight");
507: my $pcr=$score/$weight;
508: $Apache::lonhomework::results{"resource.$part.$id.awarded"}=$pcr;
509: $Apache::lonhomework::results{"resource.$part.$id.awarddetail"}=
510: 'ASSIGNED_SCORE';
1.71 albertel 511: return $repetition;
1.78 albertel 512: }
513:
514: sub whichorder {
515: my ($max,$randomize,$showall,$hash)=@_;
516: #&Apache::lonxml::debug("man $max randomize $randomize");
517: if (!defined(@{ $$hash{'names'} })) { return; }
518: my @names = @{ $$hash{'names'} };
519: my @whichopt =();
520: my (%top,@toplist,%bottom,@bottomlist);
521: if (!($showall || ($randomize eq 'no'))) {
522: my $current=0;
523: foreach my $name (@names) {
524: $current++;
525: if ($$hash{"$name.location"} eq 'top') {
526: $top{$name}=$current;
527: } elsif ($$hash{"$name.location"} eq 'bottom') {
528: $bottom{$name}=$current;
529: }
530: }
531: }
532: my $topcount=0;
533: my $bottomcount=0;
534: while (((scalar(@whichopt)+$topcount+$bottomcount) < $max || $showall)
535: && ($#names > -1)) {
536: #&Apache::lonxml::debug("Have $#whichopt max is $max");
537: my $aopt;
538: if ($showall || ($randomize eq 'no')) {
539: $aopt=0;
540: } else {
541: $aopt=int(&Math::Random::random_uniform() * ($#names+1));
542: }
543: #&Apache::lonxml::debug("From $#whichopt $max $#names elms, picking $aopt");
544: $aopt=splice(@names,$aopt,1);
545: #&Apache::lonxml::debug("Picked $aopt");
546: if ($top{$aopt}) {
547: $toplist[$top{$aopt}]=$aopt;
548: $topcount++;
549: } elsif ($bottom{$aopt}) {
550: $bottomlist[$bottom{$aopt}]=$aopt;
551: $bottomcount++;
552: } else {
553: push (@whichopt,$aopt);
554: }
555: }
556: for (my $i=0;$i<=$#toplist;$i++) {
557: if ($toplist[$i]) { unshift(@whichopt,$toplist[$i]) }
558: }
559: for (my $i=0;$i<=$#bottomlist;$i++) {
560: if ($bottomlist[$i]) { push(@whichopt,$bottomlist[$i]) }
561: }
562:
563: return @whichopt;
1.71 albertel 564: }
565:
1.85 albertel 566: sub show_answer {
567: my $part = $Apache::inputtags::part;
568: my $award = $Apache::lonhomework::history{"resource.$part.solved"};
569: my $status = $Apache::inputtags::status[-1];
570: return ( ($award =~ /^correct/
571: && lc($Apache::lonhomework::problemstatus) ne 'no')
572: || $status eq "SHOW_ANSWER");
573: }
1.87 ! albertel 574:
! 575: sub analyze_store_foilgroup {
! 576: my ($shown,$attrs)=@_;
! 577: my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
! 578: foreach my $name (@{ $Apache::response::foilgroup{'names'} }) {
! 579: if (defined($Apache::lonhomework::analyze{"$part_id.foil.value.$name"})) { next; }
! 580: push (@{ $Apache::lonhomework::analyze{"$part_id.foils"} },$name);
! 581: foreach my $attr (@$attrs) {
! 582: $Apache::lonhomework::analyze{"$part_id.foil.".$attr.".$name"} =
! 583: $Apache::response::foilgroup{"$name.".$attr};
! 584: }
! 585: }
! 586: push (@{ $Apache::lonhomework::analyze{"$part_id.shown"} }, @{ $shown });
! 587: }
! 588:
! 589: sub pick_foil_for_concept {
! 590: my ($target,$attrs,$hinthash,$parstack,$safeeval)=@_;
! 591: if (not defined(@{ $Apache::response::conceptgroup{'names'} })) { return; }
! 592: my @names = @{ $Apache::response::conceptgroup{'names'} };
! 593: my $pick=int(&Math::Random::random_uniform() * ($#names+1));
! 594: my $name=$names[$pick];
! 595: push @{ $Apache::response::foilgroup{'names'} }, $name;
! 596: foreach my $attr (@$attrs) {
! 597: $Apache::response::foilgroup{"$name.".$attr} =
! 598: $Apache::response::conceptgroup{"$name.".$attr};
! 599: }
! 600: my $concept = &Apache::lonxml::get_param('concept',$parstack,$safeeval);
! 601: $Apache::response::foilgroup{"$name.concept"} = $concept;
! 602: &Apache::lonxml::debug("Selecting $name in $concept");
! 603: my $part_id="$Apache::inputtags::part.$Apache::inputtags::response[-1]";
! 604: if ($target eq 'analyze') {
! 605: push (@{ $Apache::lonhomework::analyze{"$part_id.concepts"} },
! 606: $concept);
! 607: $Apache::lonhomework::analyze{"$part_id.concept.$concept"}=
! 608: $Apache::response::conceptgroup{'names'};
! 609: foreach my $name (@{ $Apache::response::conceptgroup{'names'} }) {
! 610: push (@{ $Apache::lonhomework::analyze{"$part_id.foils"} },
! 611: $name);
! 612: foreach my $attr (@$attrs) {
! 613: $Apache::lonhomework::analyze{"$part_id.foil.$attr.$name"}=
! 614: $Apache::response::conceptgroup{"$name.$attr"};
! 615: }
! 616: }
! 617: }
! 618: push(@{ $hinthash->{"$part_id.concepts"} },$concept);
! 619: $hinthash->{"$part_id.concept.$concept"}=
! 620: $Apache::response::conceptgroup{'names'};
! 621:
! 622: }
! 623:
! 624:
1.1 albertel 625: 1;
626: __END__
1.38 albertel 627:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>