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