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