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