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