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