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