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