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