1: # The LearningOnline Network with CAPA
2: #
3: # $Id: lonproblemanalysis.pm,v 1.114 2005/02/22 22:51:16 matthew Exp $
4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
27: package Apache::lonproblemanalysis;
28:
29: use strict;
30: use Apache::lonnet();
31: use Apache::loncommon();
32: use Apache::lonhtmlcommon();
33: use Apache::loncoursedata();
34: use Apache::lonstatistics;
35: use Apache::lonlocal;
36: use Apache::lonstathelpers();
37: use Apache::lonstudentsubmissions();
38: use HTML::Entities();
39: use Time::Local();
40: use capa;
41:
42: my $plotcolors = ['#33ff00',
43: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
44: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
45: ];
46:
47: my @SubmitButtons = ({ name => 'PrevProblemAnalysis',
48: text => 'Previous Problem' },
49: { name => 'ProblemAnalysis',
50: text => 'Analyze Problem Again' },
51: { name => 'NextProblemAnalysis',
52: text => 'Next Problem' },
53: { name => 'break'},
54: { name => 'SelectAnother',
55: text => 'Choose a different Problem' });
56:
57: sub BuildProblemAnalysisPage {
58: my ($r,$c)=@_;
59: #
60: my %Saveable_Parameters = ('Status' => 'scalar',
61: 'Section' => 'array',
62: 'NumPlots' => 'scalar',
63: 'AnalyzeOver' => 'scalar',
64: );
65: &Apache::loncommon::store_course_settings('problem_analysis',
66: \%Saveable_Parameters);
67: &Apache::loncommon::restore_course_settings('problem_analysis',
68: \%Saveable_Parameters);
69: #
70: &Apache::lonstatistics::PrepareClasslist();
71: #
72: $r->print(&CreateInterface());
73: #
74: my @Students = @Apache::lonstatistics::Students;
75: #
76: if (@Students < 1 && exists($ENV{'form.firstrun'})) {
77: $r->print('<h2>There are no students in the sections selected</h2>');
78: }
79: #
80: my @CacheButtonHTML =
81: &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
82: $r->rflush();
83: #
84: my $problem_types = '(option|radiobutton|numerical)';
85: if (exists($ENV{'form.problemchoice'}) &&
86: ! exists($ENV{'form.SelectAnother'})) {
87: foreach my $button (@SubmitButtons) {
88: if ($button->{'name'} eq 'break') {
89: $r->print("<br />\n");
90: } else {
91: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
92: 'value="'.&mt($button->{'text'}).'" />');
93: $r->print(' 'x5);
94: }
95: }
96: foreach my $html (@CacheButtonHTML) {
97: $r->print($html.(' 'x5));
98: }
99: #
100: $r->print('<hr />');
101: $r->rflush();
102: #
103: # Determine which problem we are to analyze
104: my $current_problem = &Apache::lonstathelpers::get_target_from_id
105: ($ENV{'form.problemchoice'});
106: #
107: my ($prev,$curr,$next) =
108: &Apache::lonstathelpers::get_prev_curr_next($current_problem,
109: $problem_types,
110: 'response',
111: );
112: if (exists($ENV{'form.PrevProblemAnalysis'}) && defined($prev)) {
113: $current_problem = $prev;
114: } elsif (exists($ENV{'form.NextProblemAnalysis'}) && defined($next)) {
115: $current_problem = $next;
116: } else {
117: $current_problem = $curr;
118: }
119: #
120: # Store the current problem choice and send it out in the form
121: $ENV{'form.problemchoice'} =
122: &Apache::lonstathelpers::make_target_id($current_problem);
123: $r->print('<input type="hidden" name="problemchoice" value="'.
124: $ENV{'form.problemchoice'}.'" />');
125: #
126: if (! defined($current_problem->{'resource'})) {
127: $r->print('resource is undefined');
128: } else {
129: my $resource = $current_problem->{'resource'};
130: $r->print('<h1>'.$resource->{'title'}.'</h1>');
131: $r->print('<h3>'.$resource->{'src'}.'</h3>');
132: if ($ENV{'form.show_prob'} eq 'true') {
133: $r->print(&Apache::lonstathelpers::render_resource($resource));
134: }
135: $r->rflush();
136: my %Data = &Apache::lonstathelpers::get_problem_data
137: ($resource->{'src'});
138: my $problem_data = $Data{$current_problem->{'part'}.
139: '.'.
140: $current_problem->{'respid'}};
141: if ($current_problem->{'resptype'} eq 'option') {
142: &OptionResponseAnalysis($r,$current_problem,
143: $problem_data,
144: \@Students);
145: } elsif ($current_problem->{'resptype'} eq 'radiobutton') {
146: &radio_response_analysis($r,$current_problem,
147: $problem_data,
148: \@Students);
149: } elsif ($current_problem->{'resptype'} eq 'numerical') {
150: &numerical_response_analysis($r,$current_problem,
151: $problem_data,\@Students);
152: } else {
153: $r->print('<h2>Analysis of '.$current_problem->{'resptype'}.' is not supported</h2>');
154: }
155: }
156: $r->print('<hr />');
157: } else {
158: $r->print('<input type="submit" name="ProblemAnalysis" value="'.
159: &mt('Analyze Problem').'" />');
160: $r->print(' 'x5);
161: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
162: $r->print(&Apache::lonstathelpers::ProblemSelector
163: ($problem_types));
164: }
165: }
166:
167: #########################################################
168: #########################################################
169: ##
170: ## Numerical Response Routines
171: ##
172: #########################################################
173: #########################################################
174: sub numerical_response_analysis {
175: my ($r,$problem,$problem_analysis,$students) = @_;
176: my $c = $r->connection();
177: #
178: if ($ENV{'form.AnalyzeOver'} !~ /^(tries|time)$/) {
179: $r->print('Bad request');
180: }
181: #
182: my ($resource,$partid,$respid) = ($problem->{'resource'},
183: $problem->{'part'},
184: $problem->{'respid'});
185: # Gather student data
186: my $response_data = &Apache::loncoursedata::get_response_data
187: (\@Apache::lonstatistics::SelectedSections,
188: $Apache::lonstatistics::enrollment_status,
189: $resource->{'symb'},$respid);
190: #
191: $problem_analysis->{'answercomputed'} = 1;
192: if ($problem_analysis->{'answercomputed'}) {
193: my $answers =
194: &Apache::lonstathelpers::GetStudentAnswers($r,$problem,$students,
195: 'Statistics',
196: 'stats_status');
197: $r->print(&numerical_one_dimensional_plot($r,600,150,$answers));
198: }
199: #
200: if (ref($response_data) ne 'ARRAY') {
201: $r->print('<h2>'.
202: &mt('There is no submission data for this resource').
203: '</h2>');
204: return;
205: }
206: my $analysis_html = '<table>';
207: for (my $plot_num = 1;$plot_num<=$ENV{'form.NumPlots'};$plot_num++) {
208: my $restriction_function;
209: my $header_message;
210: my $stats_message;
211: my $post_message; # passed through &mt sooner rather than later
212: my $no_data_message;
213: my @extra_data;
214: if ($ENV{'form.AnalyzeOver'} eq 'tries') {
215: $restriction_function = sub {($_[0]->{'tries'} == $plot_num?1:0)};
216: $header_message = 'Attempt [_1]';
217: $stats_message =
218: '[_1] submissions, [_2] correct, [_3] incorrect';
219: $post_message = '';
220: $no_data_message = 'No data exists for attempt [_1]';
221: } else {
222: my $starttime = &Apache::lonhtmlcommon::get_date_from_form
223: ('startdate_'.$plot_num);
224: my $endtime = &Apache::lonhtmlcommon::get_date_from_form
225: ('enddate_'.$plot_num);
226: ($starttime,$endtime) = &ensure_start_end_times
227: ($starttime,$endtime,
228: &get_time_from_row($response_data->[0]),
229: &get_time_from_row($response_data->[-1]),
230: $plot_num);
231: $header_message = 'Data from [_2] to [_3]';
232: $extra_data[0] = &Apache::lonlocal::locallocaltime($starttime);
233: $extra_data[1] = &Apache::lonlocal::locallocaltime($endtime);
234: #
235: $stats_message =
236: '[_1] submissions from [_4] students, [_2] correct, [_3] incorrect';
237: #
238: $post_message =
239: &mt('Start time: [_1]',
240: &Apache::lonhtmlcommon::date_setter
241: ('Statistics','startdate_'.$plot_num,$starttime)).
242: '<br />'.
243: &mt('End time: [_1]',
244: &Apache::lonhtmlcommon::date_setter
245: ('Statistics','enddate_'.$plot_num,$endtime));
246: $restriction_function =
247: sub {
248: my $t = $_[0]->{'timestamp'};
249: if ($t >= $starttime && $t < $endtime) {
250: return 1;
251: } else {
252: return 0;
253: }
254: };
255: $no_data_message = 'No data for [_2] to [_3]';
256: }
257: #
258: my ($correct,$answers) =
259: &numerical_determine_answers($r,$resource,$partid,
260: $respid,$students);
261: if ($c->aborted()) { return; };
262: #
263: my ($responses,$stats) =
264: &numerical_classify_responses($response_data,$correct,
265: $restriction_function);
266: if ($stats->{'submission_count'} == 0) {
267: $analysis_html.=
268: '<tr><td colspan="2"><font size="+1"><b>'.
269: &mt($no_data_message,$plot_num,@extra_data).
270: '</b></font></td></tr>';
271: } else {
272: $analysis_html.=
273: '<tr><td colspan="2" align="center"><font size="+1"><b>'.
274: &mt($header_message,$plot_num,@extra_data).
275: '</b></font></td></tr>'.
276: '<tr><td colspan="2" align="center">'.
277: &mt($stats_message,
278: $stats->{'submission_count'},
279: $stats->{'correct_count'},
280: $stats->{'incorrect_count'},
281: $stats->{'students'},
282: @extra_data).
283: '</td></tr>'.
284: '<tr>'.'<td valign="top" align="center">'.
285: &numerical_plot_percent($r,$responses,$stats).'</td>'.
286: '<td align="center" valign="top">'.
287: &numerical_plot_differences($r,$responses,$stats).'</td>'.
288: '</tr>';
289: }
290: if ($post_message ne '') {
291: $analysis_html .=
292: '<tr><td colspan="2">'.$post_message.'</td></tr>';
293: }
294: }
295: $analysis_html.='</table>';
296: $r->print($analysis_html);
297: #
298: return;
299: }
300:
301: sub numerical_plot_percent {
302: my ($r,$responses,$stats) = @_;
303: #
304: my $total = $stats->{'submission_count'};
305: return '' if ($total == 0);
306: my $max_bins = 50;
307: my $lowest_percent = $stats->{'min_percent'};
308: my $highest_percent = $stats->{'max_percent'};
309: my $percent_spread = $highest_percent - $lowest_percent;
310: foreach (qw/20 30 40 50 100 200/) {
311: if ($percent_spread < $_) {
312: $highest_percent =$_/2;
313: last;
314: }
315: }
316: my $bin_size = 1;
317: foreach (qw/0.01 0.05 0.1 0.5 1 2 5 10 20 25 50 100/) {
318: if ($lowest_percent/2 < $_){
319: $bin_size = $_;
320: last;
321: }
322: }
323: my @bins;
324: for (my $bin = -$highest_percent;$bin<0;$bin+=$bin_size) {
325: push (@bins,$bin);
326: }
327: for (my $bin = 0; $bin<$highest_percent;$bin+=$bin_size) {
328: push (@bins,$bin);
329: }
330: push(@bins,$highest_percent);
331: #
332: my @correct;
333: my @incorrect;
334: my @count;
335: while (my ($ans,$submissions) = each(%$responses)) {
336: while (my ($submission,$counts) = each(%$submissions)) {
337: my ($correct_count,$incorrect_count) = @$counts;
338: my $scaled_value = 100*($submission-$ans)/abs($ans);
339: if ($scaled_value < $bins[0]) {
340: $bins[0]=$scaled_value -1;
341: }
342: my $bin;
343: for ($bin=0;$bin<$#bins;$bin++) {
344: last if ($bins[$bin]>$scaled_value);
345: }
346: $correct[$bin-1]+=$correct_count;
347: $incorrect[$bin-1]+=$incorrect_count;
348: $count[$bin-1]+=$correct_count+$incorrect_count;
349: }
350: }
351: #
352: my @plot_correct = @correct;
353: my @plot_incorrect = @incorrect;
354: my $max;
355: for (my $i=0;$i<$#bins;$i++) {
356: $plot_correct[$i] *= 100/$total;
357: $plot_incorrect[$i] *= 100/$total;
358: if (! defined($max) ||
359: $max < $plot_correct[$i]+$plot_incorrect[$i] ) {
360: $max = $plot_correct[$i]+$plot_incorrect[$i];
361: }
362: }
363: foreach (qw/1 5 10 15 20 25 30 40 50 75 100/) {
364: if ($max <$_) { $max = $_; last; }
365: }
366: #
367: my $title = &mt('Percent Difference');
368: my @labels = (1..scalar(@bins)-1);
369: my $graph = &Apache::loncommon::DrawBarGraph
370: ($title,'Percent Difference from Correct','Percent of Answers',
371: $max,['#33FF00','#FF3300'],\@labels,\@plot_correct,\@plot_incorrect,
372: {xskip=>1});
373: #
374: my $table = $graph.$/.
375: &numerical_bin_table(\@bins,\@labels,\@incorrect,\@correct,\@count).$/;
376: return $table;
377: }
378:
379: sub numerical_plot_differences {
380: my ($r,$responses,$stats) = @_;
381: #
382: my $total = $stats->{'submission_count'};
383: return '' if ($total == 0);
384: my $max_bins = 21;
385: my $min_bin_size = $stats->{'min_abs'};
386: my $low_bin = $stats->{'lowest_ans'}-$stats->{'max_bin_size'};
387: my $high_bin = $stats->{'highest_ans'}+$stats->{'max_bin_size'};
388: if ($high_bin > 0 && $low_bin > -$high_bin) {
389: $low_bin = -$high_bin;
390: } elsif ($low_bin < 0 && $high_bin < -$low_bin) {
391: $high_bin = -$low_bin;
392: }
393: if (($high_bin -$low_bin)/$min_bin_size * 2 > $max_bins) {
394: $min_bin_size = abs($high_bin - $low_bin) / $max_bins * 2;
395: }
396: my @bins;
397: for (my $num = $low_bin;$num <= $high_bin;$num+=($min_bin_size/2)) {
398: push(@bins,$num);
399: }
400: #
401: my @correct;
402: my @incorrect;
403: my @count;
404: while (my ($ans,$submissions) = each(%$responses)) {
405: while (my ($submission,$counts) = each(%$submissions)) {
406: my ($correct_count,$incorrect_count) = @$counts;
407: my $scaled_value = $submission-$ans;
408: if ($scaled_value < $bins[0]) {
409: $bins[0]=$scaled_value-1;
410: }
411: my $bin=0;
412: for ($bin=0;$bin<$#bins;$bin++) {
413: last if ($bins[$bin]>$scaled_value);
414: }
415: $correct[$bin-1]+=$correct_count;
416: $incorrect[$bin-1]+=$incorrect_count;
417: $count[$bin-1]+=$correct_count+$incorrect_count;
418: }
419: }
420: my @plot_correct = @correct;
421: my @plot_incorrect = @incorrect;
422: my $max;
423: for (my $i=0;$i<=$#bins;$i++) {
424: $plot_correct[$i] *= 100/$total;
425: $plot_incorrect[$i] *= 100/$total;
426: if (! defined($max) ||
427: $max < $plot_correct[$i]+$plot_incorrect[$i] ) {
428: $max = $plot_correct[$i]+$plot_incorrect[$i];
429: }
430: }
431: foreach (qw/1 5 10 15 20 25 30 40 50 75 100/) {
432: if ($max <$_) { $max = $_; last; }
433: }
434: #
435: my $title = &mt('Difference between submission and correct');
436: my @labels = (1..scalar(@bins)-1);
437: my $graph = &Apache::loncommon::DrawBarGraph
438: ($title,'Difference from Correct','Percent of Answers',
439: $max,['#33FF00','#FF3300'],\@labels,\@plot_correct,\@plot_incorrect,
440: {xskip=>1});
441: #
442: my $table = $graph.$/.
443: &numerical_bin_table(\@bins,\@labels,\@incorrect,\@correct,\@count).$/;
444: return $table;
445: }
446:
447: sub numerical_classify_responses {
448: my ($full_row_data,$correct,$function) = @_;
449: my %submission_data;
450: my %students;
451: my %stats;
452: my $max=0;
453: foreach my $row (@$full_row_data) {
454: my %subm = &hashify_attempt($row);
455: if (ref($correct) eq 'HASH') {
456: my $s_correct = $correct->{$subm{'student'}};
457: $subm{'correct'} = $s_correct->{'answer'};
458: foreach my $item ('unit','ans_low','ans_high') {
459: $subm{$item} = $s_correct->{$item};
460: }
461: } else { # This probably never happens....
462: $subm{'correct'} = $correct->{'answer'};
463: $subm{'unit'} = $correct->{'unit'};
464: }
465: #
466: my $abs_low =abs($subm{'correct'}-$subm{'ans_low'});
467: my $abs_high=abs($subm{'correct'}-$subm{'ans_high'});
468: if (! defined($stats{'min_abs'}) ||
469: $stats{'min_abs'} > $abs_low) {
470: $stats{'min_abs'} = $abs_low;
471: }
472: if ($stats{'min_abs'} > $abs_high) {
473: $stats{'min_abs'} = $abs_high;
474: }
475: if (! defined($stats{'max_abs'}) ||
476: $stats{'max_abs'} < $abs_low) {
477: $stats{'max_abs'} = $abs_low;
478: }
479: if ($stats{'max_abs'} < $abs_high) {
480: $stats{'max_abs'} = $abs_high;
481: }
482: my $low_percent = 100 * abs($abs_low / $subm{'correct'});
483: my $high_percent = 100 * abs($abs_high / $subm{'correct'});
484: if (! defined($stats{'min_percent'}) ||
485: $stats{'min_percent'} > $low_percent) {
486: $stats{'min_percent'} = $low_percent;
487: }
488: if ($stats{'min_percent'} > $high_percent) {
489: $stats{'min_percent'} = $high_percent;
490: }
491: if (! defined($stats{'max_percent'}) ||
492: $stats{'max_percent'} < $low_percent) {
493: $stats{'max_percent'} = $low_percent;
494: }
495: if ($stats{'max_percent'} < $high_percent) {
496: $stats{'max_percent'} = $high_percent;
497: }
498: if (! defined($stats{'lowest_ans'}) ||
499: $stats{'lowest_ans'} > $subm{'correct'}) {
500: $stats{'lowest_ans'} = $subm{'correct'};
501: }
502: if (! defined($stats{'highest_ans'}) ||
503: $stats{'highest_ans'} < $subm{'correct'}) {
504: $stats{'highest_ans'} = $subm{'correct'};
505: }
506: #
507: $subm{'submission'} =~ s/=\d+\s*$//;
508: if (&$function(\%subm)) {
509: my $scaled = '1';
510: my ($sname,$sdom) = split(':',$subm{'student'});
511: my ($myunit,$mysub) = ($subm{'unit'},$subm{'submission'});
512: my $result =
513: &capa::caparesponse_get_real_response($myunit,
514: $mysub,
515: \$scaled);
516: # &Apache::lonnet::logthis('scaled = '.$scaled.' result ='.$result);
517: next if (! defined($scaled));
518: # next if ($result ne '6');
519: my $submission = $scaled;
520: $students{$subm{'student'}}++;
521: $stats{'submission_count'}++;
522: if (&numerical_submission_is_correct($subm{'award'})) {
523: $stats{'correct_count'}++;
524: $submission_data{$subm{'correct'}}->{$submission}->[0]++;
525: } elsif (&numerical_submission_is_incorrect($subm{'award'})) {
526: $stats{'incorrect_count'}++;
527: $submission_data{$subm{'correct'}}->{$submission}->[1]++;
528: }
529: }
530: }
531: $stats{'students'}=scalar(keys(%students));
532: return (\%submission_data,\%stats);
533: }
534:
535: sub numerical_submission_is_correct {
536: my ($award) = @_;
537: if ($award =~ /^(APPROX_ANS|EXACT_ANS)$/) {
538: return 1;
539: } else {
540: return 0;
541: }
542: }
543:
544: sub numerical_submission_is_incorrect {
545: my ($award) = @_;
546: if ($award =~ /^(INCORRECT)$/) {
547: return 1;
548: } else {
549: return 0;
550: }
551: }
552:
553: sub numerical_bin_table {
554: my ($bins,$labels,$incorrect,$correct,$count)=@_;
555: my $table =
556: '<table><tr><th>'.&mt('Bar').'</th>'.
557: '<th colspan="3">'.&mt('Range').'</th>'.
558: '<th>'.&mt('Incorrect').'</th>'.
559: '<th>'.&mt('Correct').'</th>'.
560: '<th>'.&mt('Count').'</th>'.
561: '</tr>'.$/;
562: for (my $i=0;$i<scalar(@{$bins}-1);$i++) {
563: my $lownum = $bins->[$i];
564: if ($i == 0) { $lownum = '-∞'; }
565: my $highnum = $bins->[$i+1];
566: if ($i == scalar(@{$bins})-2) { $highnum = '∞'; }
567: $table .=
568: '<tr>'.
569: '<td>'.$labels->[$i].'</td>'.
570: '<td align="right">'.$lownum.'</td>'.
571: '<td> - </td>'.
572: '<td align="right">'.$highnum.'</td>'.
573: '<td align="right">'.$incorrect->[$i].'</td>'.
574: '<td align="right">'.$correct->[$i].'</td>'.
575: '<td align="right">'.$count->[$i].'</td>'.
576: '</tr>'.$/;
577: }
578: $table.= '</table>';
579: return $table;
580: }
581:
582: sub numerical_determine_answers {
583: my ($r,$resource,$partid,$respid,$students)=@_;
584: my $c = $r->connection();
585: #
586: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
587: ($r,'Student Answer Compilation Status',
588: 'Student Answer Compilation Progress', scalar(@$students),
589: 'inline',undef,'Statistics','stats_status');
590: #
591: # Read in the cache (if it exists) before we start timing things.
592: &Apache::lonstathelpers::ensure_proper_cache($resource->{'symb'});
593: #
594: my $correct;
595: my %answers;
596: foreach my $student (@$students) {
597: last if ($c->aborted());
598: my $sname = $student->{'username'};
599: my $sdom = $student->{'domain'};
600: # analyze problem
601: my $analysis =
602: &Apache::lonstathelpers::analyze_problem_as_student($resource,
603: $sname,
604: $sdom);
605: # make the key
606: my $key = $partid.'.'.$respid;
607: foreach my $item ('answer','unit','ans_high','ans_low') {
608: $correct->{$sname.':'.$sdom}->{$item} =
609: $analysis->{$key.'.'.$item}->[0];
610: }
611: $answers{$analysis->{$key.'.answer'}->[0]}++;
612: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
613: &mt('last student'));
614: }
615: &Apache::lonstathelpers::write_analysis_cache();
616: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
617: return ($correct,\%answers);
618: }
619:
620: #
621: # Inputs: $r, $width, $height, $data
622: # $n = number of students
623: # $data = hashref of $answer => $frequency pairs
624: sub numerical_one_dimensional_plot {
625: my ($r,$width,$height,$data)=@_;
626: #
627: # Compute data -> image scaling factors
628: my $max_y = 0;
629: my $min_x = undef;
630: my $max_x = undef;
631: my $n = 0;
632: while (my ($answer,$count) = each(%$data)) {
633: $n+=$count;
634: $max_y = $count if ($max_y < $count);
635: if (! defined($min_x) || $answer < $min_x) {
636: $min_x = $answer;
637: }
638: if (! defined($max_x) || $answer > $max_x) {
639: $max_x = $answer;
640: }
641: }
642: #
643: my $min_max_difference = $max_x - $min_x;
644: if (! defined($min_max_difference) || $min_max_difference == 0) {
645: $min_max_difference = 1;
646: }
647: my $h_scale = ($width-10)/$min_max_difference;
648: #
649: my $ticscale = 5;
650: if ($max_y * $ticscale > $height/2) {
651: $ticscale = int($height/2/$max_y);
652: $ticscale = 1 if ($ticscale < 1);
653: }
654: #
655: # Create the plot
656: my $plot =
657: qq{<drawimage width="$width" height="$height" bgcolor="transparent" >};
658: while (my ($answer,$count) = each(%$data)) {
659: my $xloc = 5+$h_scale*($answer - $min_x);
660: my $top = $height/2-$count*$ticscale;
661: my $bottom = $height/2+$count*$ticscale;
662: $plot .= &line($xloc,$top,$xloc,$bottom,'888888',1);
663: }
664: #
665: # Put the scale on last to ensure it is on top of the data.
666: if ($min_x < 0 && $max_x > 0) {
667: my $circle_x = 5+$h_scale*abs($min_x); # '0' in data coordinates
668: my $r = 4;
669: $plot .= &line(5,$height/2,$circle_x-$r,$height/2,'000000',1);
670: $plot .= &circle($circle_x,$height/2,$r+1,'000000');
671: $plot .= &line($circle_x+$r,$height/2,$width-5,$height/2,'000000',1);
672: } else {
673: $plot .= &line(5,$height/2,$width-5,$height/2,'000000',1);
674: }
675: $plot .= '</drawimage>';
676: my $plotresult = &Apache::lonxml::xmlparse($r,'web',$plot);
677: my $result = '<table>'.
678: '<tr><td colspan="3" align="center">'.
679: '<font size="+2">'.&mt('Distribution of correct answers').'</font>'.
680: '<br />'.&mt('[_1] students, [_2] distinct correct answers',
681: $n,scalar(keys(%$data))).
682: '<br />'.&mt('Maximum number of coinciding values: [_1]',$max_y).
683: '</td></tr>'.
684: '<tr>'.
685: '<td valign="center">'.$min_x.'</td>'.
686: '<td>'.$plotresult.'</td>'.
687: '<td valign="center">'.$max_x.'</td>'.
688: '</tr>'.
689: '</table>';
690: return $result;
691: }
692:
693: ##
694: ## Helper subroutines for <drawimage>.
695: ## These should probably go somewhere more suitable soon.
696: sub line {
697: my ($x1,$y1,$x2,$y2,$color,$thickness) = @_;
698: return qq{<line x1="$x1" y1="$y1" x2="$x2" y2="$y2" color="$color" thickness="$thickness" />};
699: }
700:
701: sub text {
702: my ($x,$y,$color,$text,$font,$direction) = @_;
703: if (! defined($font) || $font !~ /^(tiny|small|medium|large|giant)$/) {
704: $font = 'medium';
705: }
706: if (! defined($direction) || $direction ne 'vertical') {
707: $direction = '';
708: }
709: return qq{<text x="$x" y="$y" color="$color" font="$font" direction="$direction" >$text</text>};
710: }
711:
712: sub rectangle {
713: my ($x1,$y1,$x2,$y2,$color,$thickness,$filled) = @_;
714: return qq{<rectangle x1="$x1" y1="$y1" x2="$x2" y2="$y2" color="$color" thickness="$thickness" filled="$filled" />};
715: }
716:
717: sub arc {
718: my ($x,$y,$width,$height,$start,$end,$color,$thickness,$filled)=@_;
719: return qq{<arc x="$x" y="$y" width="$width" height="$height" start="$start" end="$end" color="$color" thickness="$thickness" filled="$filled" />};
720: }
721:
722: sub circle {
723: my ($x,$y,$radius,$color,$thickness,$filled)=@_;
724: return &arc($x,$y,$radius,$radius,0,360,$color,$thickness,$filled);
725: }
726:
727: #########################################################
728: #########################################################
729: ##
730: ## Radio Response Routines
731: ##
732: #########################################################
733: #########################################################
734: sub radio_response_analysis {
735: my ($r,$problem,$problem_analysis,$students) = @_;
736: #
737: if ($ENV{'form.AnalyzeOver'} !~ /^(tries|time)$/) {
738: $r->print('Bad request');
739: }
740: #
741: my ($resource,$partid,$respid) = ($problem->{'resource'},
742: $problem->{'part'},
743: $problem->{'respid'});
744: #
745: my $analysis_html;
746: my $foildata = $problem_analysis->{'_Foils'};
747: my ($table,$foils,$concepts) = &build_foil_index($problem_analysis);
748: if (! defined($concepts)) {
749: $concepts = [];
750: }
751: #
752: my %true_foils;
753: my $num_true = 0;
754: if (! $problem_analysis->{'answercomputed'}) {
755: foreach my $foil (@$foils) {
756: if ($foildata->{$foil}->{'value'} eq 'true') {
757: $true_foils{$foil}++;
758: }
759: }
760: $num_true = scalar(keys(%true_foils));
761: }
762: #
763: $analysis_html .= $table;
764: # Gather student data
765: my $response_data = &Apache::loncoursedata::get_response_data
766: (\@Apache::lonstatistics::SelectedSections,
767: $Apache::lonstatistics::enrollment_status,
768: $resource->{'symb'},$respid);
769: my $correct; # either a hash reference or a scalar
770: if ($problem_analysis->{'answercomputed'} || scalar(@$concepts) > 1) {
771: # This takes a while for large classes...
772: &Apache::lonstathelpers::GetStudentAnswers($r,$problem,$students,
773: 'Statistics',
774: 'stats_status');
775: foreach my $student (@$students) {
776: my ($idx,@remainder) = split('&',$student->{'answer'});
777: my ($answer) = ($remainder[$idx]=~/^(.*)=([^=]*)$/);
778: $correct->{$student->{'username'}.':'.$student->{'domain'}}=
779: &Apache::lonnet::unescape($answer);
780: }
781: } else {
782: foreach my $foil (keys(%$foildata)) {
783: if ($foildata->{$foil}->{'value'} eq 'true') {
784: $correct = $foildata->{$foil}->{'name'};
785: }
786: }
787: }
788: #
789: if (! defined($response_data) || ref($response_data) ne 'ARRAY' ) {
790: $analysis_html = '<h2>'.
791: &mt('There is no submission data for this resource').
792: '</h2>';
793: $r->print($analysis_html);
794: return;
795: }
796: #
797: $analysis_html.='<table>';
798: for (my $plot_num = 1;$plot_num<=$ENV{'form.NumPlots'};$plot_num++) {
799: # classify data ->correct foil -> selected foil
800: my ($restriction_function,
801: $correct_foil_title,$incorrect_foil_title,
802: $pre_graph_text,$post_graph_text,
803: $no_data_text,@extra_data);
804: if ($ENV{'form.AnalyzeOver'} eq 'tries') {
805: $restriction_function = sub {($_[0]->{'tries'} == $plot_num?1:0)};
806: $correct_foil_title = 'Attempt '.$plot_num;
807: $incorrect_foil_title = 'Attempt '.$plot_num;
808: $pre_graph_text =
809: 'Attempt [_1], [_2] submissions, [_3] correct, [_4] incorrect';
810: $post_graph_text = '';
811: $no_data_text = 'No data exists for attempt [_1]';
812: } elsif ($ENV{'form.AnalyzeOver'} eq 'time') {
813: my $starttime = &Apache::lonhtmlcommon::get_date_from_form
814: ('startdate_'.$plot_num);
815: my $endtime = &Apache::lonhtmlcommon::get_date_from_form
816: ('enddate_'.$plot_num);
817: ($starttime,$endtime) = &ensure_start_end_times
818: ($starttime,$endtime,
819: &get_time_from_row($response_data->[0]),
820: &get_time_from_row($response_data->[-1]),
821: $plot_num);
822: $pre_graph_text =
823: 'Data from [_6] to [_7]<br /> [_2] submissions from [_5] students, [_3] correct, [_4] incorrect';
824: $extra_data[0] = &Apache::lonlocal::locallocaltime($starttime);
825: $extra_data[1] = &Apache::lonlocal::locallocaltime($endtime);
826: #
827: $post_graph_text =
828: &mt('Start time: [_1]',
829: &Apache::lonhtmlcommon::date_setter
830: ('Statistics','startdate_'.$plot_num,$starttime)).
831: '<br />'.
832: &mt('End time: [_1]',
833: &Apache::lonhtmlcommon::date_setter
834: ('Statistics','enddate_'.$plot_num,$endtime));
835: $restriction_function =
836: sub {
837: my $t = $_[0]->{'timestamp'};
838: if ($t >= $starttime && $t < $endtime) {
839: return 1;
840: } else {
841: return 0;
842: }
843: };
844: $no_data_text = 'No data for [_5] to [_6]';
845: }
846: my $foil_choice_data =
847: &classify_response_data($response_data,$correct,
848: $restriction_function);
849: # &Apache::lonstathelpers::log_hash_ref($foil_choice_data);
850: my $answers;
851: if (ref($correct)) {
852: my %tmp;
853: foreach my $foil (values(%$correct)) {
854: $tmp{$foil}++;
855: }
856: $answers = [keys(%tmp)];
857: } else {
858: $answers = [$correct];
859: }
860: # Concept Plot
861: my $concept_plot = '';
862: if (scalar(@$concepts) > 1) {
863: $concept_plot = &RR_concept_plot($concepts,$foil_choice_data,
864: 'Correct Concepts');
865: }
866: # % Choosing plot
867: my $choice_plot = &RR_create_percent_selected_plot
868: ($concepts,$foils,$foil_choice_data,$correct_foil_title);
869: # for each correct foil, how did they mark it? (stacked bar graph)
870: my ($stacked_plot,$count_by_foil);
871: if ($problem_analysis->{'answercomputed'} || $num_true > 1) {
872: ($stacked_plot,$count_by_foil) =
873: &RR_create_stacked_selection_plot($foils,$foil_choice_data,
874: $incorrect_foil_title,
875: \%true_foils);
876: }
877: #
878: if ($concept_plot ne '' ||
879: $choice_plot ne '' ||
880: $stacked_plot ne '') {
881: my $correct = $foil_choice_data->{'_correct'};
882: if (! defined($correct) || $correct eq '') {
883: $correct = 0;
884: }
885: my $incorrect =
886: $analysis_html.= '<tr><td colspan="4" align="center">'.
887: '<font size="+1">'.
888: &mt($pre_graph_text,
889: $plot_num,$foil_choice_data->{'_count'},
890: $correct,
891: $foil_choice_data->{'_count'}-$correct,
892: $foil_choice_data->{'_students'},
893: @extra_data).
894: '</td></tr>'.$/;
895: $analysis_html.=
896: '<tr>'.
897: '<td>'.$concept_plot.'</td>'.
898: '<td>'.$choice_plot.'</td>';
899: if ($stacked_plot ne '') {
900: $analysis_html .=
901: '<td>'.$stacked_plot.'</td>'.
902: '<td>'.&build_foil_key($foils,$count_by_foil).'</td>';
903: } else {
904: $analysis_html .= ('<td></td>'x2);
905: }
906: $analysis_html.='</tr>'.$/;
907: if (defined($post_graph_text)) {
908: $analysis_html.= '<tr><td colspan="4" align="center">'.
909: $post_graph_text.'</td></tr>'.$/;
910: }
911: } elsif ($no_data_text ne '') {
912: $analysis_html.='<tr><td colspan="4" align="center">'.
913: &mt($no_data_text,
914: $plot_num,$foil_choice_data->{'_count'},
915: $correct,
916: $foil_choice_data->{'_count'}-$correct,
917: @extra_data);
918: if (defined($post_graph_text)) {
919: $analysis_html.='<br />'.$post_graph_text;
920: }
921: $analysis_html.='</td></tr>'.$/;
922: }
923: } # end of loop for plots
924: $analysis_html.='</table>';
925: $r->print($analysis_html);
926: }
927:
928: sub ensure_start_end_times {
929: my ($start,$end,$first,$last,$plot_num) = @_;
930: if (! defined($start) || ! defined($end)) {
931: my $sec_in_day = 86400;
932: my ($sday,$smon,$syear) =
933: (localtime($last - $sec_in_day*($plot_num-1)))[3..5];
934: $start = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear);
935: $end = $start + $sec_in_day;
936: if ($plot_num == $ENV{'form.NumPlots'}) {
937: $start = $first;
938: }
939: }
940: return ($start,$end);
941: }
942:
943: sub RR_concept_plot {
944: my ($concepts,$foil_data,$title) = @_;
945: #
946: my %correct_by_concept;
947: my %incorrect_by_concept;
948: my %true;
949: foreach my $concept (@$concepts) {
950: foreach my $foil (@{$concept->{'foils'}}) {
951: next if (! exists($foil_data->{$foil}));
952: foreach my $choice (keys(%{$foil_data->{$foil}})) {
953: if ($choice eq $foil) {
954: $correct_by_concept{$concept->{'name'}} +=
955: $foil_data->{$foil}->{$choice};
956: } else {
957: $incorrect_by_concept{$concept->{'name'}} +=
958: $foil_data->{$foil}->{$choice};
959: }
960: }
961: }
962: }
963: #
964: # need arrays for incorrect and correct because we want to use different
965: # colors for them
966: my @correct;
967: #
968: my $total =0;
969: for (my $i=0;$i<scalar(@$concepts);$i++) {
970: my $concept = $concepts->[$i];
971: $correct[$i] = $correct_by_concept{$concept->{'name'}};
972: $total += $correct_by_concept{$concept->{'name'}}+
973: $incorrect_by_concept{$concept->{'name'}};
974: }
975: if ($total == 0) { return ''; };
976: for (my $i=0;$i<=$#correct;$i++) {
977: $correct[$i] = sprintf('%0f',$correct[$i]/$total*100);
978: }
979: my $xlabel = 'concept';
980: my $plot= &Apache::loncommon::DrawBarGraph($title,
981: $xlabel,
982: 'Percent Choosing',
983: 100,
984: ['#33ff00','#ff3300'],
985: undef,
986: \@correct);
987: return $plot;
988: }
989:
990: sub RR_create_percent_selected_plot {
991: my ($concepts,$foils,$foil_data,$title) = @_;
992: #
993: if ($foil_data->{'_count'} == 0) { return ''; };
994: my %correct_selections;
995: my %incorrect_selections;
996: foreach my $foil (@$foils) {
997: # foil_data has format $foil_data->{true_foil}->{selected foil}=count
998: next if (! exists($foil_data->{$foil}));
999: while (my ($f,$count)= each(%{$foil_data->{$foil}})) {
1000: if ($f eq $foil) {
1001: $correct_selections{$foil} += $count;
1002: } else {
1003: $incorrect_selections{$f} += $count;
1004: }
1005: }
1006: }
1007: #
1008: # need arrays for incorrect and correct because we want to use different
1009: # colors for them
1010: my @correct;
1011: my @incorrect;
1012: #
1013: my $total = $foil_data->{'_count'};
1014: for (my $i=0;$i<scalar(@$foils);$i++) {
1015: my $foil = $foils->[$i];
1016: $correct[$i] = $correct_selections{$foil};
1017: $incorrect[$i] = $incorrect_selections{$foil};
1018: }
1019: for (my $i=0;$i<=$#correct;$i++) {
1020: $correct[$i] = sprintf('%2f',$correct[$i]/$total*100);
1021: }
1022: for (my $i=0;$i<=$#incorrect;$i++) {
1023: $incorrect[$i] = sprintf('%2f',$incorrect[$i]/$total*100);
1024: }
1025: #
1026: # Put a blank in the data sets between concepts, if there are concepts
1027: my @labels;
1028: if (defined($concepts) && scalar(@$concepts) > 1) {
1029: my @new_correct;
1030: my @new_incorrect;
1031: my $foil_count = 0;
1032: foreach my $concept (@$concepts) {
1033: foreach (@{$concept->{'foils'}}) {
1034: push(@new_correct, $correct[$foil_count]);
1035: push(@new_incorrect,$incorrect[$foil_count]);
1036: push(@labels,++$foil_count);
1037: }
1038: push(@new_correct,'');
1039: push(@new_incorrect,'');
1040: push(@labels,'');
1041: }
1042: @correct = @new_correct;
1043: @incorrect = @new_incorrect;
1044: } else {
1045: @labels = (1 .. scalar(@correct));
1046: }
1047: #
1048: my $xlabel = 'foil chosen';
1049: my $plot= &Apache::loncommon::DrawBarGraph($title,
1050: $xlabel,
1051: 'Percent Choosing',
1052: 100,
1053: ['#33ff00','#ff3300'],
1054: \@labels,
1055: \@correct,
1056: \@incorrect);
1057: return $plot;
1058: }
1059:
1060: sub RR_create_stacked_selection_plot {
1061: my ($foils,$foil_data,$title,$true_foils)=@_;
1062: #
1063: my @dataset; # array of array refs - multicolor rows $datasets[row]->[col]
1064: my @labels;
1065: my $count;
1066: my %column; # maps foil name to column in @datasets
1067: for (my $i=0;$i<scalar(@$foils);$i++) {
1068: my $foil = $foils->[$i];
1069: if (defined($true_foils) && scalar(keys(%$true_foils)) > 0 ) {
1070: next if (! $true_foils->{$foil} );
1071: push(@labels,$i+1);
1072: } else {
1073: next if (! exists($foil_data->{$foil}));
1074: push(@labels,$i+1);
1075: }
1076: next if (! exists($foil_data->{$foils->[$i]}));
1077: $column{$foil}= $count++;
1078: for (my $j=0;$j<scalar(@$foils);$j++) {
1079: my $value = 0;
1080: if ($i != $j ) {
1081: $value += $foil_data->{$foil}->{$foils->[$j]};
1082: }
1083: $dataset[$j]->[$column{$foil}]=$value;
1084: }
1085: }
1086: #
1087: return '' if (! scalar(keys(%column)));
1088: #
1089: my $grand_total = 0;
1090: my %count_per_foil;
1091: while (my ($foil,$bar) = each (%column)) {
1092: my $bar_total = 0;
1093: for (my $j=0;$j<scalar(@dataset);$j++) {
1094: $bar_total += $dataset[$j]->[$bar];
1095: }
1096: next if ($bar_total == 0);
1097: for (my $j=0;$j<scalar(@dataset);$j++) {
1098: $dataset[$j]->[$bar] =
1099: sprintf('%2f',$dataset[$j]->[$bar]/$bar_total * 100);
1100: }
1101: $count_per_foil{$foil}=' ( '.$bar_total.' )';
1102: $grand_total += $bar_total;
1103: }
1104: if ($grand_total == 0) {
1105: return ('',undef);
1106: }
1107: my @empty_row = ();
1108: foreach (@{$dataset[0]}) {
1109: push(@empty_row,0);
1110: }
1111: #
1112: my $graph = &Apache::loncommon::DrawBarGraph
1113: ($title,'Correct Foil','foils chosen Incorrectly',
1114: 100,$plotcolors,\@labels,\@empty_row,@dataset);
1115: return ($graph,\%count_per_foil);
1116: }
1117:
1118:
1119: #########################################################
1120: #########################################################
1121: ##
1122: ## Misc routines
1123: ##
1124: #########################################################
1125: #########################################################
1126:
1127: # if $correct is a hash ref, it is assumed to be indexed by student names.
1128: # the values are assumed to be hash refs with a key of 'answer'.
1129: sub classify_response_data {
1130: my ($full_row_data,$correct,$function) = @_;
1131: my %submission_data;
1132: my %students;
1133: my $max=0;
1134: foreach my $row (@$full_row_data) {
1135: my %subm = &hashify_attempt($row);
1136: if (ref($correct) eq 'HASH') {
1137: $subm{'correct'} = $correct->{$subm{'student'}};
1138: } else {
1139: $subm{'correct'} = $correct;
1140: }
1141: $subm{'submission'} =~ s/=\d+\s*$//;
1142: if (&$function(\%subm)) {
1143: $students{$subm{'student'}}++;
1144: $submission_data{'_count'}++;
1145: if (&submission_is_correct($subm{'award'})) {
1146: $submission_data{'_correct'}++;
1147: }
1148:
1149: if($max<++$submission_data{$subm{'correct'}}->{$subm{'submission'}}) {
1150: $max=$submission_data{$subm{'correct'}}->{$subm{'submission'}};
1151: }
1152: }
1153: }
1154: $submission_data{'_max'} = $max;
1155: $submission_data{'_students'}=scalar(keys(%students));
1156: return \%submission_data;
1157: }
1158:
1159:
1160: #########################################################
1161: #########################################################
1162: ##
1163: ## Option Response Routines
1164: ##
1165: #########################################################
1166: #########################################################
1167: sub OptionResponseAnalysis {
1168: my ($r,$problem,$problem_data,$Students) = @_;
1169: my ($resource,$respid) = ($problem->{'resource'},
1170: $problem->{'respid'});
1171: # Note: part data is not needed.
1172: my $PerformanceData = &Apache::loncoursedata::get_response_data
1173: (\@Apache::lonstatistics::SelectedSections,
1174: $Apache::lonstatistics::enrollment_status,
1175: $resource->{'symb'},$respid);
1176: if (! defined($PerformanceData) ||
1177: ref($PerformanceData) ne 'ARRAY' ) {
1178: $r->print('<h2>'.
1179: &mt('There is no student data for this problem.').
1180: '</h2>');
1181: } else {
1182: $r->rflush();
1183: if ($ENV{'form.AnalyzeOver'} eq 'tries') {
1184: my $analysis_html = &OR_tries_analysis($r,
1185: $PerformanceData,
1186: $problem_data);
1187: $r->print($analysis_html);
1188: $r->rflush();
1189: } elsif ($ENV{'form.AnalyzeOver'} eq 'time') {
1190: my $analysis_html = &OR_time_analysis($PerformanceData,
1191: $problem_data);
1192: $r->print($analysis_html);
1193: $r->rflush();
1194: } else {
1195: $r->print('<h2>'.
1196: &mt('The analysis you have selected is '.
1197: 'not supported at this time').
1198: '</h2>');
1199: }
1200: }
1201: }
1202:
1203: #########################################################
1204: #
1205: # Option Response: tries Analysis
1206: #
1207: #########################################################
1208: sub OR_tries_analysis {
1209: my ($r,$PerformanceData,$ORdata) = @_;
1210: my $mintries = 1;
1211: my $maxtries = $ENV{'form.NumPlots'};
1212: my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
1213: if (! defined($Concepts)) {
1214: $Concepts = [];
1215: }
1216: my %response_data = &OR_analyze_by_tries($r,$PerformanceData,
1217: $mintries,$maxtries);
1218: my $analysis = '';
1219: #
1220: # Compute the data necessary to make the plots
1221: my @foil_plot;
1222: my @concept_data;
1223: for (my $j=0;$j<=scalar(@$Concepts);$j++) {
1224: my $concept = $Concepts->[$j];
1225: foreach my $foilid (@{$concept->{'foils'}}) {
1226: for (my $try=$mintries;$try<=$maxtries;$try++) {
1227: # concept analysis data
1228: $concept_data[$j]->[$try]->{'_correct'} +=
1229: $response_data{$foilid}->[$try]->{'_correct'};
1230: $concept_data[$j]->[$try]->{'_total'} +=
1231: $response_data{$foilid}->[$try]->{'_total'};
1232: #
1233: # foil analysis data
1234: if ($response_data{$foilid}->[$try]->{'_total'} == 0) {
1235: push(@{$foil_plot[$try]->{'_correct'}},0);
1236: } else {
1237: push(@{$foil_plot[$try]->{'_correct'}},
1238: 100*$response_data{$foilid}->[$try]->{'_correct'}/
1239: $response_data{$foilid}->[$try]->{'_total'});
1240: }
1241: foreach my $option (@{$ORdata->{'_Options'}}) {
1242: push(@{$foil_plot[$try]->{'_total'}},
1243: $response_data{$foilid}->[$try]->{'_total'});
1244: if ($response_data{$foilid}->[$try]->{'_total'} == 0) {
1245: push (@{$foil_plot[$try]->{$option}},0);
1246: } else {
1247: if ($response_data{$foilid}->[$try]->{'_total'} ==
1248: $response_data{$foilid}->[$try]->{'_correct'}) {
1249: push(@{$foil_plot[$try]->{$option}},0);
1250: } else {
1251: push (@{$foil_plot[$try]->{$option}},
1252: 100 *
1253: $response_data{$foilid}->[$try]->{$option} /
1254: ($response_data{$foilid}->[$try]->{'_total'}
1255: -
1256: $response_data{$foilid}->[$try]->{'_correct'}
1257: ));
1258: }
1259: }
1260: } # End of foreach my $option
1261: }
1262: } # End of foreach my $foilid
1263: } # End of concept loops
1264: #
1265: # Build a table for the plots
1266: my $analysis_html = "<br /><table>\n";
1267: my $optionkey = &build_option_index($ORdata);
1268: my $num_concepts = 1;
1269: if (defined($Concepts)) { $num_concepts = scalar(@$Concepts); }
1270: #
1271: for (my $try=$mintries;$try<=$maxtries;$try++) {
1272: if (! defined($response_data{'_total'}->[$try]) ||
1273: $response_data{'_total'}->[$try] == 0) {
1274: if ($try > 1) {
1275: $analysis_html.= '<tr><td align="center" colspan="4"><b>'.
1276: &mt('None of the selected students attempted the problem more than [_1] times.',$try-1).
1277: '</b></td></tr>';
1278: } else {
1279: $analysis_html.= '<tr><td colspan="4" align="center"><b>'.
1280: &mt('None of the selected students have attempted the problem').'</b></td></tr>';
1281: }
1282: last;
1283: }
1284: my $concept_graph='';
1285: if ($num_concepts > 1) {
1286: #
1287: # Create concept plot
1288: my @concept_plot_data;
1289: for (my $j=0;$j<=$#concept_data;$j++) {
1290: my $total = $concept_data[$j]->[$try]->{'_total'};
1291: if ($total == 0) {
1292: $concept_plot_data[$j] = 0;
1293: } else {
1294: $concept_plot_data[$j] = 100 *
1295: sprintf('%0.3f',
1296: $concept_data[$j]->[$try]->{'_correct'} /
1297: $total);
1298: }
1299: }
1300: #
1301: $concept_graph = &Apache::loncommon::DrawBarGraph
1302: ('Correct Concepts','Concept Number','Percent Correct',
1303: 100,$plotcolors,undef,\@concept_plot_data,{xskip=>1});
1304: }
1305: #
1306: # Create Foil Plots
1307: my $data_count = $response_data{'_total'}->[$try];
1308: my $correct = $response_data{'_correct'}->[$try];
1309: my @Datasets;
1310: foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {
1311: next if (! exists($foil_plot[$try]->{$option}));
1312: push(@Datasets,$foil_plot[$try]->{$option});
1313: }
1314: #
1315: # Put a blank in the data set between concepts
1316: for (my $set =0;$set<=$#Datasets;$set++) {
1317: my @Data = @{$Datasets[$set]};
1318: my $idx = 0;
1319: foreach my $concept (@{$Concepts}) {
1320: foreach my $foilid (@{$concept->{'foils'}}) {
1321: $Datasets[$set]->[$idx++]=shift(@Data);
1322: }
1323: if ($concept->{'name'} ne $Concepts->[-1]->{'name'}) {
1324: $Datasets[$set]->[$idx++] = 0;
1325: }
1326: }
1327: }
1328: #
1329: # Set up the labels needed for the bar graph
1330: my @Labels;
1331: my $idx = 1;
1332: foreach my $concept (@{$Concepts}) {
1333: foreach my $foilid (@{$concept->{'foils'}}) {
1334: push(@Labels,$idx++);
1335: }
1336: push(@Labels,'');
1337: }
1338: #
1339: my $correct_graph = &Apache::loncommon::DrawBarGraph
1340: ('Correct Statements','Statement','% Answered Correct',
1341: 100,$plotcolors,\@Labels,$Datasets[0],{xskip=>1});
1342:
1343: #
1344: #
1345: next if (! defined($Datasets[0]));
1346: for (my $i=0; $i< scalar(@{$Datasets[0]});$i++) {
1347: $Datasets[0]->[$i]=0;
1348: }
1349: my $count = $response_data{'_total'}->[$try] -
1350: $response_data{'_correct'}->[$try];
1351: my $incorrect_graph = &Apache::loncommon::DrawBarGraph
1352: ('Incorrect Statements','Statement','% Chosen Incorrectly',
1353: 100,$plotcolors,\@Labels,@Datasets,{xskip=>1});
1354: $analysis_html.=
1355: '<tr><td colspan="4" align="center">'.
1356: '<font size="+1">'.
1357: &mt('Attempt [_1], [_2] submissions, [_3] correct, [_4] incorrect',
1358: $try,$data_count,$correct,$data_count-$correct).
1359: '</font>'.'</td></tr>'.$/.
1360: '<tr>'.
1361: '<td>'.$concept_graph.'</td>'.
1362: '<td>'.$correct_graph.'</td>'.
1363: '<td>'.$incorrect_graph.'</td>'.
1364: '<td>'.$optionkey.'<td>'.
1365: '</tr>'.$/;
1366: }
1367: $analysis_html .= "</table>\n";
1368: $table .= $analysis_html;
1369: return $table;
1370: }
1371:
1372: sub OR_analyze_by_tries {
1373: my ($r,$PerformanceData,$mintries,$maxtries) = @_;
1374: my %Trydata;
1375: $mintries = 1 if (! defined($mintries) || $mintries < 1);
1376: $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
1377: my @students;
1378: foreach my $row (@$PerformanceData) {
1379: next if (! defined($row));
1380: my $tries = &get_tries_from_row($row);
1381: my %Row = &Process_OR_Row($row);
1382: next if (! %Row);
1383: my $student_id = $row->[&Apache::loncoursedata::RD_student_id()];
1384: $students[$tries]->{$student_id}++;
1385: while (my ($foilid,$href) = each(%Row)) {
1386: if (! ref($href)) {
1387: $Trydata{$foilid}->[$tries] += $href;
1388: next;
1389: }
1390: while (my ($option,$value) = each(%$href)) {
1391: $Trydata{$foilid}->[$tries]->{$option}+=$value;
1392: }
1393: }
1394: }
1395: for (my $try=$mintries;$try<=$maxtries;$try++) {
1396: $Trydata{'_studentcount'}->[$try] = scalar(keys(%{$students[$try]}));
1397: }
1398: return %Trydata;
1399: }
1400:
1401: #########################################################
1402: #
1403: # Option Response: Time Analysis
1404: #
1405: #########################################################
1406: sub OR_time_analysis {
1407: my ($performance_data,$ORdata) = @_;
1408: my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
1409: my $foilkey = &build_option_index($ORdata);
1410: my $num_concepts = 1;
1411: if (defined($Concepts)) { $num_concepts = scalar(@$Concepts); }
1412: #
1413: if ($num_concepts < 2) {
1414: $table = '<h3>'.
1415: &mt('Not enough data for concept analysis. '.
1416: 'Performing Foil Analysis').
1417: '</h3>'.$table;
1418: }
1419: #
1420: my $num_plots = $ENV{'form.NumPlots'};
1421: my $num_data = scalar(@$performance_data)-1;
1422: #
1423: my $current_index;
1424: $table .= "<table>\n";
1425: for (my $i=0;$i<$num_plots;$i++) {
1426: ##
1427: my $starttime = &Apache::lonhtmlcommon::get_date_from_form
1428: ('startdate_'.$i);
1429: my $endtime = &Apache::lonhtmlcommon::get_date_from_form
1430: ('enddate_'.$i);
1431: if (! defined($starttime) || ! defined($endtime)) {
1432: my $sec_in_day = 86400;
1433: my $last_sub_time = &get_time_from_row($performance_data->[-1]);
1434: my ($sday,$smon,$syear) =
1435: (localtime($last_sub_time - $sec_in_day*$i))[3..5];
1436: $starttime = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear);
1437: $endtime = $starttime + $sec_in_day;
1438: if ($i == ($num_plots -1 )) {
1439: $starttime = &get_time_from_row($performance_data->[0]);
1440: }
1441: }
1442: $table .= '<tr><td colspan="4" align="center"><font size="+1">'.
1443: &mt('Data from [_1] to [_2]',
1444: &Apache::lonlocal::locallocaltime($starttime),
1445: &Apache::lonlocal::locallocaltime($endtime)).
1446: '</font></td></tr>'.$/;
1447: my $startdateform = &Apache::lonhtmlcommon::date_setter
1448: ('Statistics','startdate_'.$i,$starttime);
1449: my $enddateform = &Apache::lonhtmlcommon::date_setter
1450: ('Statistics','enddate_'.$i,$endtime);
1451: #
1452: my $begin_index;
1453: my $end_index;
1454: my $j;
1455: while (++$j < scalar(@$performance_data)) {
1456: last if (&get_time_from_row($performance_data->[$j])
1457: > $starttime);
1458: }
1459: $begin_index = $j;
1460: while ($j < scalar(@$performance_data)) {
1461: if (&get_time_from_row($performance_data->[$j]) > $endtime) {
1462: last;
1463: } else {
1464: $j++;
1465: }
1466: }
1467: $end_index = $j;
1468: ##
1469: my ($processed_time_data,$correct,$data_count,$student_count) =
1470: &OR_time_process_data($performance_data,$begin_index,$end_index);
1471: ##
1472: $table .= '<tr><td colspan="4" align="center"><font size="+1">'.
1473: &mt('[_1] submissions from [_2] students, [_3] correct, [_4] incorrect',
1474: $data_count,$student_count,$correct,$data_count-$correct).
1475: '</font></td></tr>'.$/;
1476: my $concept_correct_plot = '';
1477: if ($num_concepts > 1) {
1478: $concept_correct_plot =
1479: &OR_Concept_Time_Analysis($processed_time_data,
1480: $correct,$data_count,$student_count,
1481: $ORdata,$Concepts);
1482: }
1483: my ($foil_correct_plot,$foil_incorrect_plot) =
1484: &OR_Foil_Time_Analysis($processed_time_data,
1485: $correct,$data_count,$student_count,
1486: $ORdata,$Foils,$Concepts);
1487: $table .= '<tr>'.
1488: '<td>'.$concept_correct_plot.'</td>'.
1489: '<td>'.$foil_correct_plot.'</td>'.
1490: '<td>'.$foil_incorrect_plot.'</td>'.
1491: '<td align="left" valign="top">'.$foilkey.'</td></tr>'.$/;
1492: $table .= '<tr><td colspan="4" align="center">'.
1493: &mt('Start time: [_1]',$startdateform).'<br />'.
1494: &mt('End time: [_1]',$enddateform).'</td></tr>'.$/;
1495: $table.= '<tr><td colspan="4"> </td></tr>'.$/;
1496: }
1497: $table .= '</table>';
1498: #
1499: return $table;
1500: }
1501:
1502: sub OR_Foil_Time_Analysis {
1503: my ($processed_time_data,$correct,$data_count,$student_count,
1504: $ORdata,$Foils,$Concepts) = @_;
1505: if ($data_count <= 0) {
1506: return ('<h2>'.&mt('There is no data to plot').'</h2>','');
1507: }
1508: my $analysis_html;
1509: my @plotdata;
1510: my @labels;
1511: foreach my $concept (@{$Concepts}) {
1512: foreach my $foil (@{$concept->{'foils'}}) {
1513: push(@labels,scalar(@labels)+1);
1514: my $total = $processed_time_data->{$foil}->{'_total'};
1515: if ($total == 0) {
1516: push(@{$plotdata[0]},0);
1517: } else {
1518: push(@{$plotdata[0]},
1519: 100 * $processed_time_data->{$foil}->{'_correct'} / $total);
1520: }
1521: my $total_incorrect = $total - $processed_time_data->{$foil}->{'_correct'};
1522: for (my $i=0;$i<scalar(@{$ORdata->{'_Options'}});$i++) {
1523: my $option = $ORdata->{'_Options'}->[$i];
1524: if ($total_incorrect == 0) {
1525: push(@{$plotdata[$i+1]},0);
1526: } else {
1527: push(@{$plotdata[$i+1]},
1528: 100 * $processed_time_data->{$foil}->{$option} / $total_incorrect);
1529: }
1530: }
1531: }
1532: # Put in a blank one
1533: push(@labels,'');
1534: push(@{$plotdata[0]},0);
1535: for (my $i=0;$i<scalar(@{$ORdata->{'_Options'}});$i++) {
1536: push(@{$plotdata[$i+1]},0);
1537: }
1538: }
1539: #
1540: # Create the plot
1541: my $correct_plot = &Apache::loncommon::DrawBarGraph('Correct Statements',
1542: 'Statement Number',
1543: 'Percent Correct',
1544: 100,
1545: $plotcolors,
1546: undef,
1547: $plotdata[0],
1548: {xskip=>1});
1549: for (my $j=0; $j< scalar(@{$plotdata[0]});$j++) {
1550: $plotdata[0]->[$j]=0;
1551: }
1552: my $incorrect_plot =
1553: &Apache::loncommon::DrawBarGraph('Incorrect Statements',
1554: 'Statement Number',
1555: 'Incorrect Option Choice',
1556: 100,
1557: $plotcolors,
1558: undef,
1559: @plotdata,{xskip=>1});
1560: return ($correct_plot,$incorrect_plot);
1561: }
1562:
1563: sub OR_Concept_Time_Analysis {
1564: my ($processed_time_data,$correct,$data_count,$student_count,
1565: $ORdata,$Concepts) = @_;
1566: return '' if ($data_count == 0);
1567: #
1568: # Put the data in plottable form
1569: my @plotdata;
1570: foreach my $concept (@$Concepts) {
1571: my ($total,$correct);
1572: foreach my $foil (@{$concept->{'foils'}}) {
1573: $total += $processed_time_data->{$foil}->{'_total'};
1574: $correct += $processed_time_data->{$foil}->{'_correct'};
1575: }
1576: if ($total == 0) {
1577: push(@plotdata,0);
1578: } else {
1579: push(@plotdata,100 * $correct / $total);
1580: }
1581: }
1582: #
1583: # Create the plot
1584: return &Apache::loncommon::DrawBarGraph('Correct Concepts',
1585: 'Concept Number',
1586: 'Percent Correct',
1587: 100,
1588: $plotcolors,
1589: undef,
1590: \@plotdata,{xskip=>1});
1591: }
1592:
1593: sub OR_time_process_data {
1594: my ($performance_data,$begin_index,$end_index)=@_;
1595: my %processed_time_data;
1596: my %distinct_students;
1597: my ($correct,$data_count);
1598: if (($begin_index == $end_index) &&
1599: ($end_index != scalar(@$performance_data)-1)) {
1600: return undef;
1601: }
1602: # Be sure we include the last one if we are asked for it.
1603: # That we have to correct here (and not when $end_index is
1604: # given a value) should probably be considered a bug.
1605: if ($end_index == scalar(@$performance_data)-1) {
1606: $end_index++;
1607: }
1608: my $count;
1609: for (my $i=$begin_index;$i<$end_index;$i++) {
1610: my $attempt = $performance_data->[$i];
1611: $count++;
1612: next if (! defined($attempt));
1613: my %attempt = &Process_OR_Row($attempt);
1614: $data_count++;
1615: $correct += $attempt{'_correct'};
1616: $distinct_students{$attempt->[&Apache::loncoursedata::RD_student_id()]}++;
1617: while (my ($foilid,$href) = each(%attempt)) {
1618: if (! ref($href)) {
1619: $processed_time_data{$foilid} += $href;
1620: next;
1621: }
1622: while (my ($option,$value) = each(%$href)) {
1623: $processed_time_data{$foilid}->{$option}+=$value;
1624: }
1625: }
1626: }
1627: return (\%processed_time_data,$correct,$data_count,
1628: scalar(keys(%distinct_students)));
1629: }
1630:
1631: sub build_foil_index {
1632: my ($ORdata) = @_;
1633: return if (! exists($ORdata->{'_Foils'}));
1634: my %Foildata = %{$ORdata->{'_Foils'}};
1635: my @Foils = sort(keys(%Foildata));
1636: my %Concepts;
1637: foreach my $foilid (@Foils) {
1638: push(@{$Concepts{$Foildata{$foilid}->{'_Concept'}}},
1639: $foilid);
1640: }
1641: undef(@Foils);
1642: # Having gathered the concept information in a hash, we now translate it
1643: # into an array because we need to be consistent about order.
1644: # Also put the foils in order, too.
1645: my $sortfunction = sub {
1646: my %Numbers = (one => 1,
1647: two => 2,
1648: three => 3,
1649: four => 4,
1650: five => 5,
1651: six => 6,
1652: seven => 7,
1653: eight => 8,
1654: nine => 9,
1655: ten => 10,);
1656: my $a1 = lc($a);
1657: my $b1 = lc($b);
1658: if (exists($Numbers{$a1})) {
1659: $a1 = $Numbers{$a1};
1660: }
1661: if (exists($Numbers{$b1})) {
1662: $b1 = $Numbers{$b1};
1663: }
1664: if (($a1 =~/^\d+$/) && ($b1 =~/^\d+$/)) {
1665: return $a1 <=> $b1;
1666: } else {
1667: return $a1 cmp $b1;
1668: }
1669: };
1670: my @Concepts;
1671: foreach my $concept (sort $sortfunction (keys(%Concepts))) {
1672: if (! defined($Concepts{$concept})) {
1673: $Concepts{$concept}=[];
1674: # next;
1675: }
1676: push(@Concepts,{ name => $concept,
1677: foils => [@{$Concepts{$concept}}]});
1678: push(@Foils,(@{$Concepts{$concept}}));
1679: }
1680: #
1681: # Build up the table of row labels.
1682: my $table = '<table border="1" >'."\n";
1683: if (@Concepts > 1) {
1684: $table .= '<tr>'.
1685: '<th>'.&mt('Concept Number').'</th>'.
1686: '<th>'.&mt('Concept').'</th>'.
1687: '<th>'.&mt('Foil Number').'</th>'.
1688: '<th>'.&mt('Foil Name').'</th>'.
1689: '<th>'.&mt('Foil Text').'</th>'.
1690: '<th>'.&mt('Correct Value').'</th>'.
1691: "</tr>\n";
1692: } else {
1693: $table .= '<tr>'.
1694: '<th>'.&mt('Foil Number').'</th>'.
1695: '<th>'.&mt('Foil Name').'</th>'.
1696: '<th>'.&mt('Foil Text').'</th>'.
1697: '<th>'.&mt('Correct Value').'</th>'.
1698: "</tr>\n";
1699: }
1700: my $conceptindex = 1;
1701: my $foilindex = 1;
1702: foreach my $concept (@Concepts) {
1703: my @FoilsInConcept = @{$concept->{'foils'}};
1704: my $firstfoil = shift(@FoilsInConcept);
1705: if (@Concepts > 1) {
1706: $table .= '<tr>'.
1707: '<td>'.$conceptindex.'</td>'.
1708: '<td>'.&HTML::Entities::encode($concept->{'name'},'<>&"').'</td>'.
1709: '<td>'.$foilindex++.'</td>'.
1710: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').'</td>'.
1711: '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
1712: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').'</td>'.
1713: "</tr>\n";
1714: } else {
1715: $table .= '<tr>'.
1716: '<td>'.$foilindex++.'</td>'.
1717: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').'</td>'.
1718: '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
1719: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').'</td>'.
1720: "</tr>\n";
1721: }
1722: foreach my $foilid (@FoilsInConcept) {
1723: if (@Concepts > 1) {
1724: $table .= '<tr>'.
1725: '<td></td>'.
1726: '<td></td>'.
1727: '<td>'.$foilindex.'</td>'.
1728: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').'</td>'.
1729: '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
1730: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').'</td>'.
1731: "</tr>\n";
1732: } else {
1733: $table .= '<tr>'.
1734: '<td>'.$foilindex.'</td>'.
1735: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').'</td>'.
1736: '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
1737: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').'</td>'.
1738: "</tr>\n";
1739: }
1740: } continue {
1741: $foilindex++;
1742: }
1743: } continue {
1744: $conceptindex++;
1745: }
1746: $table .= "</table>\n";
1747: #
1748: # Build option index with color stuff
1749: return ($table,\@Foils,\@Concepts);
1750: }
1751:
1752: sub build_option_index {
1753: my ($ORdata)= @_;
1754: my $table = "<table>\n";
1755: my $optionindex = 0;
1756: my @Rows;
1757: foreach my $option (&mt('correct option chosen'),@{$ORdata->{'_Options'}}) {
1758: my $color = $plotcolors->[$optionindex++];
1759: push (@Rows,
1760: '<tr>'.
1761: '<td bgcolor="'.$color.'">'.
1762: '<font color="'.$color.'">'.('*'x3).'</font>'.'</td>'.
1763: '<td>'.&HTML::Entities::encode($option,'<>&"').'</td>'.
1764: "</tr>\n");
1765: }
1766: shift(@Rows); # Throw away 'correct option chosen' color
1767: $table .= join('',reverse(@Rows));
1768: $table .= "</table>\n";
1769: }
1770:
1771: sub build_foil_key {
1772: my ($foils,$extra_data)= @_;
1773: if (! defined($extra_data)) { $extra_data = {}; }
1774: my $table = "<table>\n";
1775: my $foil_index = 0;
1776: my @rows;
1777: foreach my $foil (&mt('correct foil chosen'),@{$foils}) {
1778: my $color = $plotcolors->[$foil_index++];
1779: push (@rows,
1780: '<tr>'.
1781: '<td bgcolor="'.$color.'" class="key">'.
1782: '<font color="'.$color.'">'.('*'x4).'</font></td>'.
1783: '<td>'.&HTML::Entities::encode($foil,'<>&"').
1784: (' 'x2).$extra_data->{$foil}.'</td>'.
1785: "</tr>\n");
1786: }
1787: shift(@rows); # Throw away 'correct foil chosen' color
1788: $table .= join('',reverse(@rows));
1789: $table .= "</table>\n";
1790: }
1791:
1792: #########################################################
1793: #########################################################
1794: ##
1795: ## Generic Interface Routines
1796: ##
1797: #########################################################
1798: #########################################################
1799: sub CreateInterface {
1800: ##
1801: ## Environment variable initialization
1802: if (! exists$ENV{'form.AnalyzeOver'}) {
1803: $ENV{'form.AnalyzeOver'} = 'tries';
1804: }
1805: ##
1806: ## Build the menu
1807: my $Str = '';
1808: $Str .= &Apache::lonhtmlcommon::breadcrumbs
1809: (undef,'Detailed Problem Analysis');
1810: $Str .= '<table cellspacing="5">'."\n";
1811: $Str .= '<tr>';
1812: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
1813: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
1814: # $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
1815: $Str .= '<td align="center"> </td>';
1816: $Str .= '</tr>'."\n";
1817: ##
1818: ##
1819: $Str .= '<tr><td align="center">'."\n";
1820: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1821: $Str .= '</td>';
1822: #
1823: $Str .= '<td align="center">';
1824: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1825: $Str .= '</td>';
1826: #
1827: # $Str .= '<td align="center">';
1828: my $only_seq_with_assessments = sub {
1829: my $s=shift;
1830: if ($s->{'num_assess'} < 1) {
1831: return 0;
1832: } else {
1833: return 1;
1834: }
1835: };
1836: &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
1837: $only_seq_with_assessments);
1838: ##
1839: ##
1840: $Str .= '<td>';
1841: ##
1842: my $showprob_checkbox =
1843: '<input type="checkbox" name="show_prob" value="true" ';
1844: if ($ENV{'form.show_prob'} eq 'true') {
1845: $showprob_checkbox .= 'checked ';
1846: }
1847: $showprob_checkbox.= ' />';
1848: $Str.= '<nobr><label>'.
1849: &mt('Show problem [_1]',$showprob_checkbox).
1850: '</label></nobr><br />';
1851: ##
1852: my $analyze_selector = '<select name="AnalyzeOver" >';
1853: $analyze_selector .= '<option value="tries" ';
1854: if (! exists($ENV{'form.AnalyzeOver'}) ||
1855: $ENV{'form.AnalyzeOver'} eq 'tries'){
1856: # Default to tries
1857: $analyze_selector .= ' selected ';
1858: }
1859: $analyze_selector .= '>'.&mt('Tries').'</option>';
1860: $analyze_selector .= '<option value="time" ';
1861: $analyze_selector .= ' selected ' if ($ENV{'form.AnalyzeOver'} eq 'time');
1862: $analyze_selector .= '>'.&mt('Time').'</option>';
1863: $analyze_selector .= '</select>';
1864: $Str .= '<nobr><label>'.
1865: &mt('Analyze Over [_1] [_2]',
1866: $analyze_selector,
1867: &Apache::loncommon::help_open_topic('Analysis_Analyze_Over')).
1868: '</label></nobr><br />'.$/;
1869: ##
1870: my $numplots_selector = '<select name="NumPlots">';
1871: if (! exists($ENV{'form.NumPlots'})
1872: || $ENV{'form.NumPlots'} < 1
1873: || $ENV{'form.NumPlots'} > 20) {
1874: $ENV{'form.NumPlots'} = 5;
1875: }
1876: foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
1877: $numplots_selector .= '<option value="'.$i.'" ';
1878: if ($ENV{'form.NumPlots'} == $i) { $numplots_selector.=' selected '; }
1879: $numplots_selector .= '>'.$i.'</option>';
1880: }
1881: $numplots_selector .= '</select></nobr><br />';
1882: $Str .= '<nobr><label>'.&mt('Number of Plots [_1]',$numplots_selector).
1883: '</label></nobr>';
1884: ##
1885: $Str .= '<nobr><label>'.&mt('Status: [_1]',
1886: '<input type="text" '.
1887: 'name="stats_status" size="60" value="" />'
1888: ).
1889: '</label></nobr>';
1890: $Str .= '</td>';
1891: ##
1892: ##
1893: $Str .= '</tr>'."\n";
1894: $Str .= '</table>'."\n";
1895: return $Str;
1896: }
1897:
1898: #########################################################
1899: #########################################################
1900: ##
1901: ## Misc Option Response functions
1902: ##
1903: #########################################################
1904: #########################################################
1905: sub get_time_from_row {
1906: my ($row) = @_;
1907: if (ref($row)) {
1908: return $row->[&Apache::loncoursedata::RD_timestamp()];
1909: }
1910: return undef;
1911: }
1912:
1913: sub get_tries_from_row {
1914: my ($row) = @_;
1915: if (ref($row)) {
1916: return $row->[&Apache::loncoursedata::RD_tries()];
1917: }
1918: return undef;
1919: }
1920:
1921: sub hashify_attempt {
1922: my ($row) = @_;
1923: my %attempt;
1924: $attempt{'student'} = $row->[&Apache::loncoursedata::RD_sname()];
1925: $attempt{'tries'} = $row->[&Apache::loncoursedata::RD_tries()];
1926: $attempt{'submission'} = &Apache::lonnet::unescape($row->[&Apache::loncoursedata::RD_submission()]);
1927: $attempt{'award'} = $row->[&Apache::loncoursedata::RD_awarddetail()];
1928: $attempt{'timestamp'} = $row->[&Apache::loncoursedata::RD_timestamp()];
1929: return %attempt;
1930: }
1931:
1932: sub Process_OR_Row {
1933: my ($row) = @_;
1934: my %RowData;
1935: # my $student_id = $row->[&Apache::loncoursedata::RD_student_id()];
1936: my $award = $row->[&Apache::loncoursedata::RD_awarddetail()];
1937: my $grading = $row->[&Apache::loncoursedata::RD_response_eval()];
1938: my $submission = $row->[&Apache::loncoursedata::RD_submission()];
1939: my $time = $row->[&Apache::loncoursedata::RD_timestamp()];
1940: # my $tries = $row->[&Apache::loncoursedata::RD_tries()];
1941: return undef if ($award eq 'MISSING_ANSWER');
1942: if (&submission_is_correct($award)) {
1943: $RowData{'_correct'} = 1;
1944: }
1945: $RowData{'_total'} = 1;
1946: my @Foilgrades = split('&',$grading);
1947: my @Foilsubs = split('&',$submission);
1948: for (my $j=0;$j<=$#Foilgrades;$j++) {
1949: my ($foilid,$correct) = split('=',$Foilgrades[$j]);
1950: $foilid = &Apache::lonnet::unescape($foilid);
1951: my (undef,$submission) = split('=',$Foilsubs[$j]);
1952: if ($correct) {
1953: $RowData{$foilid}->{'_correct'}++;
1954: } else {
1955: $submission = &Apache::lonnet::unescape($submission);
1956: $RowData{$foilid}->{$submission}++;
1957: }
1958: $RowData{$foilid}->{'_total'}++;
1959: }
1960: return %RowData;
1961: }
1962:
1963: sub submission_is_correct {
1964: my ($award) = @_;
1965: if ($award =~ /(APPROX_ANS|EXACT_ANS)/) {
1966: return 1;
1967: } else {
1968: return 0;
1969: }
1970: }
1971:
1972: 1;
1973:
1974: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>