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