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