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