Annotation of loncom/interface/statistics/lonproblemanalysis.pm, revision 1.91
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: #
1.91 ! matthew 3: # $Id: lonproblemanalysis.pm,v 1.90 2004/09/29 14:38:35 matthew Exp $
1.1 stredwic 4: #
5: # Copyright Michigan State University Board of Trustees
6: #
7: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
8: #
9: # LON-CAPA is free software; you can redistribute it and/or modify
10: # it under the terms of the GNU General Public License as published by
11: # the Free Software Foundation; either version 2 of the License, or
12: # (at your option) any later version.
13: #
14: # LON-CAPA is distributed in the hope that it will be useful,
15: # but WITHOUT ANY WARRANTY; without even the implied warranty of
16: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17: # GNU General Public License for more details.
18: #
19: # You should have received a copy of the GNU General Public License
20: # along with LON-CAPA; if not, write to the Free Software
21: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22: #
23: # /home/httpd/html/adm/gpl.txt
24: #
25: # http://www.lon-capa.org/
26: #
1.11 minaeibi 27: package Apache::lonproblemanalysis;
1.1 stredwic 28:
29: use strict;
30: use Apache::lonnet();
1.25 matthew 31: use Apache::loncommon();
1.7 stredwic 32: use Apache::lonhtmlcommon();
1.23 matthew 33: use Apache::loncoursedata();
34: use Apache::lonstatistics;
35: use Apache::lonlocal;
1.71 matthew 36: use Apache::lonstathelpers();
37: use Apache::lonstudentsubmissions();
1.37 matthew 38: use HTML::Entities();
1.42 matthew 39: use Time::Local();
1.43 matthew 40: use Spreadsheet::WriteExcel();
1.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)';
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.56 matthew 151: &RadioResponseAnalysis($r,$current_problem,
1.88 matthew 152: $problem_data,
1.47 matthew 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 {
167: $r->print('<h2>This analysis is not supported</h2>');
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.85 matthew 225: my ($max,$min) =
226: &Apache::lonstathelpers::GetStudentAnswers($r,$problem,$Students,
227: 'Statistics',
228: 'stats_status');
1.79 matthew 229: return if ($c->aborted());
1.78 matthew 230: #
231: # Collate the data
1.68 matthew 232: my %Data;
233: foreach my $student (@$Students) {
234: my $answer = $student->{'answer'};
235: $Data{$answer}++;
236: }
237: my @Labels = sort {$a <=> $b } keys(%Data);
238: my @PlotData = @Data{@Labels};
1.78 matthew 239: #
240: my $width = 500;
241: my $height = 100;
242: my $plot = &one_dimensional_plot($r,500,100,scalar(@$Students),
243: \@Labels,\@PlotData);
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: #########################################################
379: sub RadioResponseAnalysis {
1.88 matthew 380: my ($r,$problem,$problem_data,$Students) = @_;
1.56 matthew 381: my ($resource,$respid) = ($problem->{'resource'},
1.66 matthew 382: $problem->{'respid'});
1.48 matthew 383: my $analysis_html;
1.82 matthew 384: my $PerformanceData = &Apache::loncoursedata::get_response_data
385: (\@Apache::lonstatistics::SelectedSections,
386: $Apache::lonstatistics::enrollment_status,
387: $resource->{'symb'},$respid);
1.48 matthew 388: if (! defined($PerformanceData) ||
389: ref($PerformanceData) ne 'ARRAY' ) {
390: $analysis_html = '<h2>'.
391: &mt('There is no submission data for this resource').
392: '</h2>';
393: $r->print($analysis_html);
1.47 matthew 394: return;
395: }
1.48 matthew 396: if (exists($ENV{'form.ExcelOutput'})) {
1.56 matthew 397: $analysis_html .= &RR_Excel_output($r,$problem->{'resource'},
1.88 matthew 398: $PerformanceData,$problem_data);
1.48 matthew 399: } elsif ($ENV{'form.AnalyzeOver'} eq 'Tries') {
1.56 matthew 400: $analysis_html .= &RR_Tries_Analysis($r,$problem->{'resource'},
1.88 matthew 401: $PerformanceData,$problem_data);
1.48 matthew 402: } elsif ($ENV{'form.AnalyzeOver'} eq 'Time') {
1.56 matthew 403: $analysis_html .= &RR_Time_Analysis($r,$problem->{'resource'},
1.88 matthew 404: $PerformanceData,$problem_data);
1.48 matthew 405: } else {
406: $analysis_html .= '<h2>'.
407: &mt('The analysis you have selected is not supported at this time').
1.91 ! matthew 408: '</h2>';
1.48 matthew 409: }
410: $r->print($analysis_html);
411: }
412:
413: sub RR_Excel_output {
1.88 matthew 414: my ($r,$PerformanceData,$problem_data) = @_;
1.48 matthew 415: return '<h1>No!</h1>';
416: }
417:
418: sub RR_Tries_Analysis {
1.88 matthew 419: my ($r,$resource,$PerformanceData,$problem_data) = @_;
1.48 matthew 420: my $analysis_html;
421: my $mintries = 1;
422: my $maxtries = $ENV{'form.NumPlots'};
1.88 matthew 423: my ($table,$Foils,$Concepts) = &build_foil_index($problem_data);
424: if ((! defined($Concepts)) || (@$Concepts < 2)) {
1.48 matthew 425: $table = '<h3>'.
426: &mt('Not enough data for concept analysis. '.
427: 'Performing Foil Analysis').
428: '</h3>'.$table;
429: }
430: $analysis_html .= $table;
431: my @TryData = &RR_tries_data_analysis($r,$PerformanceData);
1.56 matthew 432: $analysis_html .= &RR_Tries_Foil_Analysis($mintries,$maxtries,$Foils,
1.88 matthew 433: \@TryData,$problem_data);
1.48 matthew 434: return $analysis_html;
435: }
436:
437: sub RR_tries_data_analysis {
438: my ($r,$Attempt_data) = @_;
439: my @TryData;
440: foreach my $attempt (@$Attempt_data) {
441: my %Attempt = &hashify_attempt($attempt);
442: my ($answer,undef) = split('=',$Attempt{'submission'});
443: $TryData[$Attempt{'tries'}]->{$answer}++;
444: }
445: return @TryData;
446: }
447:
448: sub RR_Time_Analysis {
1.88 matthew 449: my ($r,$PerformanceData,$problem_data) = @_;
1.48 matthew 450: my $html;
451: return $html;
452: }
453:
454: sub RR_Tries_Foil_Analysis {
1.88 matthew 455: my ($min,$max,$Foils,$TryData,$problem_data) = @_;
1.48 matthew 456: my $html;
457: #
458: # Compute the data neccessary to make the plots
459: for (my $try=$min;$try<=$max;$try++) {
460: my @PlotData_Correct;
461: my @PlotData_Incorrect;
462: next if ($try > scalar(@{$TryData}));
1.56 matthew 463: next if (! defined($TryData->[$try]));
464: my %DataSet = %{$TryData->[$try]};
1.48 matthew 465: my $total = 0;
466: foreach my $foilid (@$Foils) {
467: $total += $DataSet{$foilid};
468: }
469: foreach my $foilid (@$Foils) {
470: if ($total == 0) {
471: push (@PlotData_Correct,0);
472: push (@PlotData_Incorrect,0);
473: } else {
1.88 matthew 474: if ($problem_data->{'_Foils'}->{$foilid}->{'value'} eq 'true') {
1.48 matthew 475: push (@PlotData_Correct,
476: int(100*$DataSet{$foilid}/$total));
477: push (@PlotData_Incorrect,0);
478: } else {
479: push (@PlotData_Correct,0);
480: push (@PlotData_Incorrect,
481: int(100*$DataSet{$foilid}/$total));
482: }
483: }
484: }
1.91 ! matthew 485: my $title='Attempt '.$try.' (N='.$total.')';
! 486: my $xlabel = 'Foil Chosen';
1.48 matthew 487: $html.= &Apache::loncommon::DrawBarGraph($title,
488: $xlabel,
489: 'Percent Choosing',
490: 100,
491: ['#33ff00','#ff3300'],
1.64 matthew 492: undef,
1.48 matthew 493: \@PlotData_Correct,
494: \@PlotData_Incorrect);
495: }
496: return $html;
497: }
498:
499: sub RR_Tries_Concept_Analysis {
1.88 matthew 500: my ($min,$max,$Concepts,$ResponseData,$problem_data) = @_;
1.48 matthew 501: my $html;
502: return $html;
503: }
504:
505: sub RR_Time_Foil_Analysis {
1.88 matthew 506: my ($min,$max,$Foils,$ResponseData,$problem_data) = @_;
1.48 matthew 507: my $html;
508: return $html;
509: }
510:
511: sub RR_Time_Concept_Analysis {
1.88 matthew 512: my ($min,$max,$Concepts,$ResponseData,$problem_data) = @_;
1.48 matthew 513: my $html;
514: return $html;
515: }
516:
517:
518: sub get_Radio_problem_data {
519: my ($url) = @_;
520: my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze'));
521: (my $garbage,$Answ)=split('_HASH_REF__',$Answ,2);
522: my %Answer = &Apache::lonnet::str2hash($Answ);
523: my %Partdata;
524: foreach my $part (@{$Answer{'parts'}}) {
525: while (my($key,$value) = each(%Answer)) {
526: # if (ref($value) eq 'ARRAY') {
527: # &Apache::lonnet::logthis('is ref part:'.$part.' '.$key.'='.join(',',@$value));
528: # } else {
529: # &Apache::lonnet::logthis('notref part:'.$part.' '.$key.'='.$value);
530: # }
531: next if ($key !~ /^$part/);
532: $key =~ s/^$part\.//;
533: if ($key eq 'foils') {
534: $Partdata{$part}->{'_Foils'}=$value;
535: } elsif ($key eq 'options') {
536: $Partdata{$part}->{'_Options'}=$value;
537: } elsif ($key eq 'shown') {
538: $Partdata{$part}->{'_Shown'}=$value;
539: } elsif ($key =~ /^foil.value.(.*)$/) {
540: $Partdata{$part}->{$1}->{'value'}=$value;
541: } elsif ($key =~ /^foil.text.(.*)$/) {
542: $Partdata{$part}->{$1}->{'text'}=$value;
543: }
544: }
545: }
546: return %Partdata;
1.47 matthew 547: }
1.48 matthew 548:
1.33 matthew 549: #########################################################
550: #########################################################
551: ##
1.46 matthew 552: ## Option Response Routines
1.33 matthew 553: ##
554: #########################################################
555: #########################################################
1.46 matthew 556: sub OptionResponseAnalysis {
1.88 matthew 557: my ($r,$problem,$problem_data,$Students) = @_;
1.56 matthew 558: my ($resource,$respid) = ($problem->{'resource'},
559: $problem->{'respid'});
560: # Note: part data is not needed.
1.82 matthew 561: my $PerformanceData = &Apache::loncoursedata::get_response_data
562: (\@Apache::lonstatistics::SelectedSections,
563: $Apache::lonstatistics::enrollment_status,
564: $resource->{'symb'},$respid);
1.46 matthew 565: if (! defined($PerformanceData) ||
566: ref($PerformanceData) ne 'ARRAY' ) {
567: $r->print('<h2>'.
568: &mt('There is no student data for this problem.').
569: '</h2>');
570: } else {
571: $r->rflush();
572: if (exists($ENV{'form.ExcelOutput'})) {
1.57 matthew 573: my $result = &OR_excel_sheet($r,$resource,
574: $PerformanceData,
1.88 matthew 575: $problem_data);
1.46 matthew 576: $r->print($result);
577: $r->rflush();
1.39 matthew 578: } else {
1.46 matthew 579: if ($ENV{'form.AnalyzeOver'} eq 'Tries') {
1.57 matthew 580: my $analysis_html = &OR_tries_analysis($r,
1.46 matthew 581: $PerformanceData,
1.88 matthew 582: $problem_data);
1.46 matthew 583: $r->print($analysis_html);
584: $r->rflush();
585: } elsif ($ENV{'form.AnalyzeOver'} eq 'Time') {
1.57 matthew 586: my $analysis_html = &OR_time_analysis($PerformanceData,
1.88 matthew 587: $problem_data);
1.46 matthew 588: $r->print($analysis_html);
589: $r->rflush();
1.39 matthew 590: } else {
1.46 matthew 591: $r->print('<h2>'.
592: &mt('The analysis you have selected is '.
593: 'not supported at this time').
594: '</h2>');
595: }
1.36 matthew 596: }
1.39 matthew 597: }
598: }
599:
1.33 matthew 600: #########################################################
1.46 matthew 601: #
602: # Option Response: Tries Analysis
603: #
1.33 matthew 604: #########################################################
1.57 matthew 605: sub OR_tries_analysis {
1.43 matthew 606: my ($r,$PerformanceData,$ORdata) = @_;
1.33 matthew 607: my $mintries = 1;
608: my $maxtries = $ENV{'form.NumPlots'};
1.39 matthew 609: my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
1.88 matthew 610: my %response_data = &OR_analyze_by_tries($r,$PerformanceData,
1.36 matthew 611: $mintries,$maxtries);
1.42 matthew 612: my $analysis = '';
1.31 matthew 613: #
1.88 matthew 614: # Compute the data necessary to make the plots
615: my @foil_plot;
616: my @concept_data;
617: for (my $j=0;$j<=scalar(@$Concepts);$j++) {
618: my $concept = $Concepts->[$j];
1.75 matthew 619: foreach my $foilid (@{$concept->{'foils'}}) {
1.76 matthew 620: for (my $try=$mintries;$try<=$maxtries;$try++) {
1.88 matthew 621: # concept analysis data
622: $concept_data[$j]->{'_correct'} +=
623: $response_data{$foilid}->[$try]->{'_correct'};
624: $concept_data[$j]->{'_total'} +=
625: $response_data{$foilid}->[$try]->{'_total'};
626: #
627: # foil analysis data
628: if ($response_data{$foilid}->[$try]->{'_total'} == 0) {
629: push(@{$foil_plot[$try]->{'_correct'}},0);
1.42 matthew 630: } else {
1.88 matthew 631: push(@{$foil_plot[$try]->{'_correct'}},
632: 100*$response_data{$foilid}->[$try]->{'_correct'}/
633: $response_data{$foilid}->[$try]->{'_total'});
1.75 matthew 634: }
635: foreach my $option (@{$ORdata->{'_Options'}}) {
1.88 matthew 636: push(@{$foil_plot[$try]->{'_total'}},
637: $response_data{$foilid}->[$try]->{'_total'});
638: if ($response_data{$foilid}->[$try]->{'_total'} == 0) {
639: push (@{$foil_plot[$try]->{$option}},0);
1.39 matthew 640: } else {
1.88 matthew 641: if ($response_data{$foilid}->[$try]->{'_total'} ==
642: $response_data{$foilid}->[$try]->{'_correct'}) {
643: push(@{$foil_plot[$try]->{$option}},0);
1.75 matthew 644: } else {
1.88 matthew 645: push (@{$foil_plot[$try]->{$option}},
1.76 matthew 646: 100 *
1.88 matthew 647: $response_data{$foilid}->[$try]->{$option} /
648: ($response_data{$foilid}->[$try]->{'_total'}
1.76 matthew 649: -
1.88 matthew 650: $response_data{$foilid}->[$try]->{'_correct'}
1.76 matthew 651: ));
1.75 matthew 652: }
1.39 matthew 653: }
1.76 matthew 654: } # End of foreach my $option
1.36 matthew 655: }
1.76 matthew 656: } # End of foreach my $foilid
1.88 matthew 657: } # End of concept loops
1.42 matthew 658: #
659: # Build a table for the plots
660: my $analysis_html = "<table>\n";
1.75 matthew 661: my $optionkey = &build_option_index($ORdata);
1.88 matthew 662: my $num_concepts = 1;
663: if (defined($Concepts)) { $num_concepts = scalar(@$Concepts); }
664: #
1.75 matthew 665: for (my $try=$mintries;$try<=$maxtries;$try++) {
1.88 matthew 666: my $concept_graph='';
667: if ($num_concepts > 1) {
668: #
669: # Create concept plot
670: my @concept_plot_data;
671: for (my $j=0;$j<=$#concept_data;$j++) {
672: my $total = $concept_data[$j]->{'_total'};
673: if ($total == 0) {
674: $concept_plot_data[$j] = 0;
675: } else {
676: $concept_plot_data[$j] = 100 *
677: sprintf('%0.3f',
678: $concept_data[$j]->{'_correct'} / $total);
679: }
680: }
681: #
682: my $title;
683: my $count = $response_data{'_total'}->[$try];
684: $title = 'Attempt '.$try.' (N='.$count.')';
685: $concept_graph = &Apache::loncommon::DrawBarGraph
686: ($title,'Concept Number','Percent Correct',
687: 100,$plotcolors,undef,\@concept_plot_data);
688: }
689: #
690: # Create Foil Plots
691: my $count = $response_data{'_total'}->[$try];
692: my $title = 'Attempt '.$try.' (N='.$count.')';
1.42 matthew 693: my @Datasets;
1.48 matthew 694: foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {
1.88 matthew 695: next if (! exists($foil_plot[$try]->{$option}));
696: push(@Datasets,$foil_plot[$try]->{$option});
1.42 matthew 697: }
1.76 matthew 698: #
699: # Put a blank in the data set between concepts
700: for (my $set =0;$set<=$#Datasets;$set++) {
701: my @Data = @{$Datasets[$set]};
702: my $idx = 0;
703: foreach my $concept (@{$Concepts}) {
704: foreach my $foilid (@{$concept->{'foils'}}) {
705: $Datasets[$set]->[$idx++]=shift(@Data);
706: }
707: if ($concept->{'name'} ne $Concepts->[-1]->{'name'}) {
708: $Datasets[$set]->[$idx++] = 0;
709: }
710: }
711: }
712: #
713: # Set up the labels needed for the bar graph
714: my @Labels;
715: my $idx = 1;
716: foreach my $concept (@{$Concepts}) {
717: foreach my $foilid (@{$concept->{'foils'}}) {
718: push(@Labels,$idx++);
719: }
720: push(@Labels,'');
721: }
722: #
1.88 matthew 723: my $correct_graph = &Apache::loncommon::DrawBarGraph
1.42 matthew 724: ($title,'Foil Number','Percent Correct',
1.76 matthew 725: 100,$plotcolors,\@Labels,$Datasets[0]);
1.75 matthew 726:
727: #
728: #
1.57 matthew 729: next if (! defined($Datasets[0]));
1.42 matthew 730: for (my $i=0; $i< scalar(@{$Datasets[0]});$i++) {
731: $Datasets[0]->[$i]=0;
732: }
1.88 matthew 733: $count = $response_data{'_total'}->[$try] -
734: $response_data{'_correct'}->[$try];
735: $title = 'Attempt '.$try.' (N='.$count.')';
736: my $incorrect_graph = &Apache::loncommon::DrawBarGraph
1.42 matthew 737: ($title,'Foil Number','% Option Chosen Incorrectly',
1.76 matthew 738: 100,$plotcolors,\@Labels,@Datasets);
1.88 matthew 739: $analysis_html.=
740: '<tr>'.
741: '<td>'.$concept_graph.'</td>'.
742: '<td>'.$correct_graph.'</td>'.
743: '<td>'.$incorrect_graph.'</td>'.
744: '<td>'.$optionkey.'<td>'.
745: '</tr>'.$/;
1.42 matthew 746: }
747: $analysis_html .= "</table>\n";
1.88 matthew 748: $table .= $analysis_html;
749: return $table;
1.25 matthew 750: }
751:
1.57 matthew 752: sub OR_analyze_by_tries {
1.43 matthew 753: my ($r,$PerformanceData,$mintries,$maxtries) = @_;
1.25 matthew 754: my %Trydata;
755: $mintries = 1 if (! defined($mintries) || $mintries < 1);
756: $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
1.26 matthew 757: foreach my $row (@$PerformanceData) {
758: next if (! defined($row));
1.47 matthew 759: my $tries = &get_tries_from_row($row);
1.46 matthew 760: my %Row = &Process_OR_Row($row);
1.43 matthew 761: next if (! %Row);
1.42 matthew 762: while (my ($foilid,$href) = each(%Row)) {
763: if (! ref($href)) {
764: $Trydata{$foilid}->[$tries] += $href;
765: next;
766: }
767: while (my ($option,$value) = each(%$href)) {
768: $Trydata{$foilid}->[$tries]->{$option}+=$value;
1.25 matthew 769: }
770: }
771: }
772: return %Trydata;
773: }
774:
1.33 matthew 775: #########################################################
1.46 matthew 776: #
777: # Option Response: Time Analysis
778: #
1.33 matthew 779: #########################################################
1.57 matthew 780: sub OR_time_analysis {
1.88 matthew 781: my ($performance_data,$ORdata) = @_;
1.42 matthew 782: my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
1.88 matthew 783: my $foilkey = &build_option_index($ORdata);
784: my $num_concepts = 1;
785: if (defined($Concepts)) { $num_concepts = scalar(@$Concepts); }
786: #
787: if ($num_concepts < 2) {
1.42 matthew 788: $table = '<h3>'.
789: &mt('Not enough data for concept analysis. '.
790: 'Performing Foil Analysis').
1.88 matthew 791: '</h3>'.$table;
1.42 matthew 792: }
1.88 matthew 793: #
1.33 matthew 794: my $num_plots = $ENV{'form.NumPlots'};
1.88 matthew 795: my $num_data = scalar(@$performance_data)-1;
1.33 matthew 796: my $percent = sprintf('%2f',100/$num_plots);
1.42 matthew 797: #
1.37 matthew 798: $table .= "<table>\n";
1.33 matthew 799: for (my $i=0;$i<$num_plots;$i++) {
1.42 matthew 800: ##
1.34 matthew 801: my $starttime = &Apache::lonhtmlcommon::get_date_from_form
802: ('startdate_'.$i);
803: my $endtime = &Apache::lonhtmlcommon::get_date_from_form
804: ('enddate_'.$i);
805: if (! defined($starttime) || ! defined($endtime)) {
1.42 matthew 806: my $sec_in_day = 86400;
1.88 matthew 807: my $last_sub_time = &get_time_from_row($performance_data->[-1]);
1.42 matthew 808: my ($sday,$smon,$syear);
809: (undef,undef,undef,$sday,$smon,$syear) =
810: localtime($last_sub_time - $sec_in_day*$i);
811: $starttime = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear);
812: $endtime = $starttime + $sec_in_day;
813: if ($i == ($num_plots -1 )) {
1.88 matthew 814: $starttime = &get_time_from_row($performance_data->[0]);
1.42 matthew 815: }
816: }
1.88 matthew 817: $table .= '<tr><td colspan="4" align="center">'.
818: &mt('Data from [_1] to [_2]',
819: &Apache::lonlocal::locallocaltime($starttime),
820: &Apache::lonlocal::locallocaltime($endtime)).'</td></tr>'.$/;
1.34 matthew 821: my $startdateform = &Apache::lonhtmlcommon::date_setter
822: ('Statistics','startdate_'.$i,$starttime);
823: my $enddateform = &Apache::lonhtmlcommon::date_setter
824: ('Statistics','enddate_'.$i,$endtime);
1.42 matthew 825: #
826: my $begin_index;
827: my $end_index;
828: my $j;
1.88 matthew 829: while (++$j < scalar(@$performance_data)) {
830: last if (&get_time_from_row($performance_data->[$j])
1.46 matthew 831: > $starttime);
1.42 matthew 832: }
833: $begin_index = $j;
1.91 ! matthew 834: while ($j < scalar(@$performance_data)) {
! 835: if (&get_time_from_row($performance_data->[$j]) > $endtime) {
! 836: last;
! 837: } else {
! 838: $j++;
! 839: }
1.42 matthew 840: }
841: $end_index = $j;
842: ##
843: my $interval = {
844: begin_index => $begin_index,
845: end_index => $end_index,
846: startdateform => $startdateform,
847: enddateform => $enddateform,
848: };
1.88 matthew 849: my $concept_correct_plot = '';
850: if ($num_concepts > 1) {
851: $concept_correct_plot =
852: &OR_Concept_Time_Analysis($performance_data,
853: $ORdata,$Concepts,
1.42 matthew 854: $interval);
855: }
1.88 matthew 856: my ($foil_correct_plot,$foil_incorrect_plot) =
857: &OR_Foil_Time_Analysis($performance_data,$ORdata,
858: $Foils,$Concepts,$interval);
859: $table .= '<tr>'.
860: '<td>'.$concept_correct_plot.'</td>'.
861: '<td>'.$foil_correct_plot.'</td>'.
862: '<td>'.$foil_incorrect_plot.'</td>'.
863: '<td align="left" valign="top">'.$foilkey.'</td></tr>'.$/;
864: $table .= '<tr><td colspan="4" align="center">'.
865: &mt('Start time: [_1]',
866: $interval->{'startdateform'}).'<br />'.
867: &mt('End time: [_1]',
868: $interval->{'enddateform'}).
869: '</td></tr>'.$/;
870: $table.= '<tr><td colspan="4"> </td></tr>'.$/;
1.33 matthew 871: }
1.88 matthew 872: $table .= '</table>';
1.42 matthew 873: #
1.33 matthew 874: return $table;
875: }
876:
1.57 matthew 877: sub OR_Foil_Time_Analysis {
1.88 matthew 878: my ($performance_data,$ORdata,$Foils,$Concepts,$interval) = @_;
1.42 matthew 879: my $analysis_html;
880: my ($begin_index,$end_index) = ($interval->{'begin_index'},
881: $interval->{'end_index'});
1.33 matthew 882: my %TimeData;
883: #
884: # Compute the number getting the foils correct or incorrects
1.42 matthew 885: for (my $j=$begin_index;$j<=$end_index;$j++) {
1.88 matthew 886: my $row = $performance_data->[$j];
1.33 matthew 887: next if (! defined($row));
1.46 matthew 888: my %Row = &Process_OR_Row($row);
1.42 matthew 889: while (my ($foilid,$href) = each(%Row)) {
890: if (! ref($href)) {
891: $TimeData{$foilid} += $href;
892: next;
893: }
894: while (my ($option,$value) = each(%$href)) {
895: $TimeData{$foilid}->{$option}+=$value;
1.33 matthew 896: }
897: }
898: }
1.88 matthew 899: my @plotdata;
900: my @labels;
901: foreach my $concept (@{$Concepts}) {
902: foreach my $foil (@{$concept->{'foils'}}) {
903: push(@labels,scalar(@labels)+1);
904: my $total = $TimeData{$foil}->{'_total'};
905: if ($total == 0) {
906: push(@{$plotdata[0]},0);
1.42 matthew 907: } else {
1.88 matthew 908: push(@{$plotdata[0]},
909: 100 * $TimeData{$foil}->{'_correct'} / $total);
1.37 matthew 910: }
1.88 matthew 911: my $total_incorrect = $total - $TimeData{$foil}->{'_correct'};
912: for (my $i=0;$i<scalar(@{$ORdata->{'_Options'}});$i++) {
913: my $option = $ORdata->{'_Options'}->[$i];
914: if ($total_incorrect == 0) {
915: push(@{$plotdata[$i+1]},0);
916: } else {
917: push(@{$plotdata[$i+1]},
918: 100 * $TimeData{$foil}->{$option} / $total_incorrect);
919: }
920: }
921: }
922: # Put in a blank one
923: push(@labels,'');
924: push(@{$plotdata[0]},0);
925: for (my $i=0;$i<scalar(@{$ORdata->{'_Options'}});$i++) {
926: push(@{$plotdata[$i+1]},0);
1.39 matthew 927: }
1.42 matthew 928: }
929: #
930: # Create the plot
931: my $count = $end_index-$begin_index;
1.91 ! matthew 932: return ('No data','') if ($count <= 0);
1.42 matthew 933: my $title;
934: if ($count == 0) {
935: $title = 'no submissions';
936: } elsif ($count == 1) {
937: $title = 'one submission';
1.91 ! matthew 938: } elsif ($count > 1) {
1.42 matthew 939: $title = $count.' submissions';
940: }
1.88 matthew 941: my $correct_plot = &Apache::loncommon::DrawBarGraph($title,
1.46 matthew 942: 'Foil Number',
943: 'Percent Correct',
944: 100,
945: $plotcolors,
1.64 matthew 946: undef,
1.88 matthew 947: $plotdata[0]);
948: for (my $j=0; $j< scalar(@{$plotdata[0]});$j++) {
949: $plotdata[0]->[$j]=0;
1.42 matthew 950: }
951: $count = $end_index-$begin_index-$TimeData{'_correct'};
952: if ($count == 0) {
953: $title = 'no submissions';
1.91 ! matthew 954: } elsif ($count < 0) {
! 955: return ($correct_plot,'');
1.42 matthew 956: } elsif ($count == 1) {
957: $title = 'one submission';
958: } else {
959: $title = $count.' submissions';
960: }
1.88 matthew 961: my $incorrect_plot = &Apache::loncommon::DrawBarGraph($title,
1.42 matthew 962: 'Foil Number',
963: 'Incorrect Option Choice',
964: 100,
965: $plotcolors,
1.64 matthew 966: undef,
1.91 ! matthew 967: @plotdata);
1.88 matthew 968: return ($correct_plot,$incorrect_plot);
1.42 matthew 969: }
970:
1.57 matthew 971: sub OR_Concept_Time_Analysis {
1.88 matthew 972: my ($performance_data,$ORdata,$Concepts,$interval) = @_;
1.42 matthew 973: ##
974: ## Determine starttime, endtime, startindex, endindex
975: my ($begin_index,$end_index) = ($interval->{'begin_index'},
976: $interval->{'end_index'});
977: my %TimeData;
978: #
979: # Compute the number getting the foils correct or incorrects
980: for (my $j=$begin_index;$j<=$end_index;$j++) {
1.88 matthew 981: my $row = $performance_data->[$j];
1.42 matthew 982: next if (! defined($row));
1.46 matthew 983: my %Row = &Process_OR_Row($row);
1.42 matthew 984: while (my ($foilid,$href) = each(%Row)) {
985: if (! ref($href)) {
986: $TimeData{$foilid} += $href;
987: next;
1.37 matthew 988: }
1.42 matthew 989: while (my ($option,$value) = each(%$href)) {
990: $TimeData{$foilid}->{$option}+=$value;
1.37 matthew 991: }
1.33 matthew 992: }
993: }
994: #
1.42 matthew 995: # Put the data in plottable form
1.88 matthew 996: my @plotdata;
1.42 matthew 997: foreach my $concept (@$Concepts) {
998: my ($total,$correct);
999: foreach my $foil (@{$concept->{'foils'}}) {
1000: $total += $TimeData{$foil}->{'_total'};
1001: $correct += $TimeData{$foil}->{'_correct'};
1002: }
1003: if ($total == 0) {
1.88 matthew 1004: push(@plotdata,0);
1.42 matthew 1005: } else {
1.88 matthew 1006: push(@plotdata,100 * $correct / $total);
1.42 matthew 1007: }
1008: }
1009: #
1.33 matthew 1010: # Create the plot
1.42 matthew 1011: my $title = ($end_index - $begin_index).' submissions';
1.88 matthew 1012: return &Apache::loncommon::DrawBarGraph($title,
1013: 'Concept Number',
1014: 'Percent Correct',
1015: 100,
1016: $plotcolors,
1017: undef,
1018: \@plotdata);
1.42 matthew 1019: }
1020:
1021: #########################################################
1022: #########################################################
1023: ##
1024: ## Excel output
1025: ##
1026: #########################################################
1027: #########################################################
1.57 matthew 1028: sub OR_excel_sheet {
1.88 matthew 1029: my ($r,$resource,$performance_data,$ORdata) = @_;
1.44 matthew 1030: my $response = '';
1.42 matthew 1031: my (undef,$Foils,$Concepts) = &build_foil_index($ORdata);
1.43 matthew 1032: #
1033: # Create excel worksheet
1034: my $filename = '/prtspool/'.
1035: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
1036: time.'_'.rand(1000000000).'.xls';
1037: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1038: if (! defined($workbook)) {
1039: $r->log_error("Error creating excel spreadsheet $filename: $!");
1040: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1041: "This error has been logged. ".
1042: "Please alert your LON-CAPA administrator").
1043: '</p>');
1044: return undef;
1045: }
1046: #
1047: $workbook->set_tempdir('/home/httpd/perl/tmp');
1.69 matthew 1048: my $format = &Apache::loncommon::define_excel_formats($workbook);
1.43 matthew 1049: #
1050: # Create and populate main worksheets
1051: my $problem_data_sheet = $workbook->addworksheet('Problem Data');
1.69 matthew 1052: my $student_data_sheet = &build_student_data_worksheet($workbook,$format);
1.43 matthew 1053: my $response_data_sheet = $workbook->addworksheet('Response Data');
1054: foreach my $sheet ($problem_data_sheet,$student_data_sheet,
1055: $response_data_sheet) {
1056: $sheet->write(0,0,$resource->{'title'},$format->{'h2'});
1057: $sheet->write(1,0,$resource->{'src'},$format->{'h3'});
1058: }
1059: #
1060: my $result;
1.59 matthew 1061: $result = &OR_build_problem_data_worksheet($problem_data_sheet,$format,
1.43 matthew 1062: $Concepts,$ORdata);
1063: if ($result ne 'okay') {
1064: # Do something useful
1065: }
1.59 matthew 1066: $result = &OR_build_response_data_worksheet($response_data_sheet,$format,
1.88 matthew 1067: $performance_data,$Foils,
1.43 matthew 1068: $ORdata);
1069: if ($result ne 'okay') {
1070: # Do something useful
1071: }
1.44 matthew 1072: $response_data_sheet->activate();
1.43 matthew 1073: #
1074: # Close the excel file
1075: $workbook->close();
1076: #
1077: # Write a link to allow them to download it
1.44 matthew 1078: $result .= '<h2>'.&mt('Excel Raw Data Output').'</h2>'.
1079: '<p><a href="'.$filename.'">'.
1080: &mt('Your Excel spreadsheet.').
1081: '</a></p>'."\n";
1.43 matthew 1082: return $result;
1083: }
1084:
1.57 matthew 1085: sub OR_build_problem_data_worksheet {
1.43 matthew 1086: my ($worksheet,$format,$Concepts,$ORdata) = @_;
1087: my $rows_output = 3;
1088: my $cols_output = 0;
1089: $worksheet->write($rows_output++,0,'Problem Structure',$format->{'h3'});
1090: ##
1091: ##
1092: my @Headers;
1093: if (@$Concepts > 1) {
1094: @Headers = ("Concept\nNumber",'Concept',"Foil\nNumber",
1095: 'Foil Name','Foil Text','Correct value');
1096: } else {
1097: @Headers = ('Foil Number','FoilName','Foil Text','Correct value');
1098: }
1099: $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
1.48 matthew 1100: my %Foildata = %{$ORdata->{'_Foils'}};
1.43 matthew 1101: my $conceptindex = 1;
1102: my $foilindex = 1;
1103: foreach my $concept (@$Concepts) {
1104: my @FoilsInConcept = @{$concept->{'foils'}};
1105: my $firstfoil = shift(@FoilsInConcept);
1106: if (@$Concepts > 1) {
1107: $worksheet->write_row($rows_output++,0,
1108: [$conceptindex,
1109: $concept->{'name'},
1110: $foilindex++,
1111: $Foildata{$firstfoil}->{'name'},
1112: $Foildata{$firstfoil}->{'text'},
1113: $Foildata{$firstfoil}->{'value'},]);
1114: } else {
1115: $worksheet->write_row($rows_output++,0,
1116: [ $foilindex++,
1117: $Foildata{$firstfoil}->{'name'},
1118: $Foildata{$firstfoil}->{'text'},
1119: $Foildata{$firstfoil}->{'value'},]);
1120: }
1121: foreach my $foilid (@FoilsInConcept) {
1122: if (@$Concepts > 1) {
1123: $worksheet->write_row($rows_output++,0,
1124: ['',
1125: '',
1126: $foilindex,
1127: $Foildata{$foilid}->{'name'},
1128: $Foildata{$foilid}->{'text'},
1129: $Foildata{$foilid}->{'value'},]);
1130: } else {
1131: $worksheet->write_row($rows_output++,0,
1132: [$foilindex,
1133: $Foildata{$foilid}->{'name'},
1134: $Foildata{$foilid}->{'text'},
1135: $Foildata{$foilid}->{'value'},]);
1136: }
1137: } continue {
1138: $foilindex++;
1139: }
1140: } continue {
1141: $conceptindex++;
1142: }
1143: $rows_output++;
1144: $rows_output++;
1145: ##
1146: ## Option data output
1147: $worksheet->write($rows_output++,0,'Options',$format->{'header'});
1.48 matthew 1148: foreach my $string (@{$ORdata->{'_Options'}}) {
1.43 matthew 1149: $worksheet->write($rows_output++,0,$string);
1150: }
1151: return 'okay';
1152: }
1153:
1.57 matthew 1154: sub OR_build_response_data_worksheet {
1.88 matthew 1155: my ($worksheet,$format,$performance_data,$Foils,$ORdata)=@_;
1.43 matthew 1156: my $rows_output = 3;
1157: my $cols_output = 0;
1158: $worksheet->write($rows_output++,0,'Response Data',$format->{'h3'});
1159: $worksheet->set_column(1,1,20);
1160: $worksheet->set_column(2,2,13);
1161: my @Headers = ('identifier','time','award detail','attempt');
1162: foreach my $foil (@$Foils) {
1163: push (@Headers,$foil.' submission');
1164: push (@Headers,$foil.' grading');
1165: }
1166: $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
1167: #
1.88 matthew 1168: foreach my $row (@$performance_data) {
1.43 matthew 1169: next if (! defined($row));
1170: my ($student,$award,$grading,$submission,$time,$tries) = @$row;
1171: my @Foilgrades = split('&',$grading);
1172: my @Foilsubs = split('&',$submission);
1.88 matthew 1173: my %response_data;
1.43 matthew 1174: for (my $j=0;$j<=$#Foilgrades;$j++) {
1175: my ($foilid,$correct) = split('=',$Foilgrades[$j]);
1176: my (undef,$submission) = split('=',$Foilsubs[$j]);
1177: $submission = &Apache::lonnet::unescape($submission);
1.88 matthew 1178: $response_data{$foilid.' submission'}=$submission;
1179: $response_data{$foilid.' award'}=$correct;
1.43 matthew 1180: }
1181: $worksheet->write($rows_output,$cols_output++,$student);
1182: $worksheet->write($rows_output,$cols_output++,
1.71 matthew 1183: &Apache::lonstathelpers::calc_serial($time),$format->{'date'});
1.43 matthew 1184: $worksheet->write($rows_output,$cols_output++,$award);
1185: $worksheet->write($rows_output,$cols_output++,$tries);
1186: foreach my $foilid (@$Foils) {
1187: $worksheet->write($rows_output,$cols_output++,
1.88 matthew 1188: $response_data{$foilid.' submission'});
1.43 matthew 1189: $worksheet->write($rows_output,$cols_output++,
1.88 matthew 1190: $response_data{$foilid.' award'});
1.43 matthew 1191: }
1192: $rows_output++;
1193: $cols_output = 0;
1194: }
1195: return;
1.42 matthew 1196: }
1197:
1.46 matthew 1198: sub build_foil_index {
1199: my ($ORdata) = @_;
1.48 matthew 1200: return if (! exists($ORdata->{'_Foils'}));
1201: my %Foildata = %{$ORdata->{'_Foils'}};
1.46 matthew 1202: my @Foils = sort(keys(%Foildata));
1203: my %Concepts;
1204: foreach my $foilid (@Foils) {
1.48 matthew 1205: push(@{$Concepts{$Foildata{$foilid}->{'_Concept'}}},
1.46 matthew 1206: $foilid);
1207: }
1208: undef(@Foils);
1209: # Having gathered the concept information in a hash, we now translate it
1210: # into an array because we need to be consistent about order.
1211: # Also put the foils in order, too.
1212: my $sortfunction = sub {
1213: my %Numbers = (one => 1,
1214: two => 2,
1215: three => 3,
1216: four => 4,
1217: five => 5,
1218: six => 6,
1219: seven => 7,
1220: eight => 8,
1221: nine => 9,
1222: ten => 10,);
1223: my $a1 = lc($a);
1224: my $b1 = lc($b);
1.57 matthew 1225: if (exists($Numbers{$a1})) {
1.67 matthew 1226: $a1 = $Numbers{$a1};
1.57 matthew 1227: }
1228: if (exists($Numbers{$b1})) {
1.67 matthew 1229: $b1 = $Numbers{$b1};
1.46 matthew 1230: }
1.67 matthew 1231: if (($a1 =~/^\d+$/) && ($b1 =~/^\d+$/)) {
1232: return $a1 <=> $b1;
1.57 matthew 1233: } else {
1.67 matthew 1234: return $a1 cmp $b1;
1.46 matthew 1235: }
1236: };
1237: my @Concepts;
1238: foreach my $concept (sort $sortfunction (keys(%Concepts))) {
1.57 matthew 1239: if (! defined($Concepts{$concept})) {
1240: $Concepts{$concept}=[];
1241: # next;
1242: }
1.46 matthew 1243: push(@Concepts,{ name => $concept,
1244: foils => [@{$Concepts{$concept}}]});
1245: push(@Foils,(@{$Concepts{$concept}}));
1246: }
1247: #
1248: # Build up the table of row labels.
1249: my $table = '<table border="1" >'."\n";
1250: if (@Concepts > 1) {
1251: $table .= '<tr>'.
1252: '<th>'.&mt('Concept Number').'</th>'.
1253: '<th>'.&mt('Concept').'</th>'.
1254: '<th>'.&mt('Foil Number').'</th>'.
1255: '<th>'.&mt('Foil Name').'</th>'.
1256: '<th>'.&mt('Foil Text').'</th>'.
1257: '<th>'.&mt('Correct Value').'</th>'.
1258: "</tr>\n";
1259: } else {
1260: $table .= '<tr>'.
1261: '<th>'.&mt('Foil Number').'</th>'.
1262: '<th>'.&mt('Foil Name').'</th>'.
1263: '<th>'.&mt('Foil Text').'</th>'.
1264: '<th>'.&mt('Correct Value').'</th>'.
1265: "</tr>\n";
1266: }
1267: my $conceptindex = 1;
1268: my $foilindex = 1;
1269: foreach my $concept (@Concepts) {
1270: my @FoilsInConcept = @{$concept->{'foils'}};
1271: my $firstfoil = shift(@FoilsInConcept);
1272: if (@Concepts > 1) {
1273: $table .= '<tr>'.
1274: '<td>'.$conceptindex.'</td>'.
1.83 albertel 1275: '<td>'.&HTML::Entities::encode($concept->{'name'},'<>&"').'</td>'.
1.46 matthew 1276: '<td>'.$foilindex++.'</td>'.
1.83 albertel 1277: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').'</td>'.
1.65 matthew 1278: '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
1.83 albertel 1279: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').'</td>'.
1.46 matthew 1280: "</tr>\n";
1281: } else {
1282: $table .= '<tr>'.
1283: '<td>'.$foilindex++.'</td>'.
1.83 albertel 1284: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').'</td>'.
1.65 matthew 1285: '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
1.83 albertel 1286: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').'</td>'.
1.46 matthew 1287: "</tr>\n";
1288: }
1289: foreach my $foilid (@FoilsInConcept) {
1290: if (@Concepts > 1) {
1291: $table .= '<tr>'.
1292: '<td></td>'.
1293: '<td></td>'.
1294: '<td>'.$foilindex.'</td>'.
1.83 albertel 1295: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').'</td>'.
1.65 matthew 1296: '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
1.84 albertel 1297: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').'</td>'.
1.46 matthew 1298: "</tr>\n";
1299: } else {
1300: $table .= '<tr>'.
1301: '<td>'.$foilindex.'</td>'.
1.83 albertel 1302: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').'</td>'.
1.65 matthew 1303: '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
1.83 albertel 1304: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').'</td>'.
1.46 matthew 1305: "</tr>\n";
1306: }
1307: } continue {
1308: $foilindex++;
1309: }
1310: } continue {
1311: $conceptindex++;
1312: }
1313: $table .= "</table>\n";
1314: #
1315: # Build option index with color stuff
1316: return ($table,\@Foils,\@Concepts);
1317: }
1318:
1319: sub build_option_index {
1320: my ($ORdata)= @_;
1321: my $table = "<table>\n";
1322: my $optionindex = 0;
1323: my @Rows;
1.48 matthew 1324: foreach my $option (&mt('correct option chosen'),@{$ORdata->{'_Options'}}) {
1.46 matthew 1325: push (@Rows,
1326: '<tr>'.
1327: '<td bgcolor="'.$plotcolors->[$optionindex++].'">'.
1328: (' 'x4).'</td>'.
1.83 albertel 1329: '<td>'.&HTML::Entities::encode($option,'<>&"').'</td>'.
1.46 matthew 1330: "</tr>\n");
1331: }
1332: shift(@Rows); # Throw away 'correct option chosen' color
1333: $table .= join('',reverse(@Rows));
1334: $table .= "</table>\n";
1335: }
1336:
1.33 matthew 1337: #########################################################
1338: #########################################################
1339: ##
1.46 matthew 1340: ## Generic Interface Routines
1.33 matthew 1341: ##
1342: #########################################################
1343: #########################################################
1.23 matthew 1344: sub CreateInterface {
1.28 matthew 1345: ##
1346: ## Environment variable initialization
1.36 matthew 1347: if (! exists$ENV{'form.AnalyzeOver'}) {
1348: $ENV{'form.AnalyzeOver'} = 'Tries';
1.28 matthew 1349: }
1350: ##
1351: ## Build the menu
1.7 stredwic 1352: my $Str = '';
1.72 matthew 1353: $Str .= &Apache::lonhtmlcommon::breadcrumbs
1.74 matthew 1354: (undef,'Detailed Problem Analysis');
1.23 matthew 1355: $Str .= '<table cellspacing="5">'."\n";
1356: $Str .= '<tr>';
1357: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
1358: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
1.31 matthew 1359: # $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
1360: $Str .= '<td align="center"> </td>';
1.23 matthew 1361: $Str .= '</tr>'."\n";
1.31 matthew 1362: ##
1363: ##
1.23 matthew 1364: $Str .= '<tr><td align="center">'."\n";
1365: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1.28 matthew 1366: $Str .= '</td>';
1367: #
1368: $Str .= '<td align="center">';
1.23 matthew 1369: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1.28 matthew 1370: $Str .= '</td>';
1371: #
1.31 matthew 1372: # $Str .= '<td align="center">';
1.23 matthew 1373: my $only_seq_with_assessments = sub {
1374: my $s=shift;
1375: if ($s->{'num_assess'} < 1) {
1376: return 0;
1377: } else {
1378: return 1;
1379: }
1380: };
1.31 matthew 1381: &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
1.23 matthew 1382: $only_seq_with_assessments);
1.36 matthew 1383: ##
1384: ##
1.28 matthew 1385: $Str .= '<td>';
1.91 ! matthew 1386: ##
! 1387: my $showprob_checkbox =
! 1388: '<input type="checkbox" name="show_prob" value="true" ';
! 1389: if ($ENV{'form.show_prob'} eq 'true') {
! 1390: $showprob_checkbox .= 'checked ';
! 1391: }
! 1392: $showprob_checkbox.= ' />';
! 1393: $Str.= '<nobr><label>'.
! 1394: &mt('Show problem [_1]',$showprob_checkbox).
! 1395: '</label></nobr><br />';
! 1396: ##
1.90 matthew 1397: my $analyze_selector = '<select name="AnalyzeOver" >';
1398: $analyze_selector .= '<option value="Tries" ';
1399: if (! exists($ENV{'form.AnalyzeOver'}) ||
1400: $ENV{'form.AnalyzeOver'} eq 'Tries'){
1401: # Default to Tries
1402: $analyze_selector .= ' selected ';
1403: }
1404: $analyze_selector .= '>'.&mt('Tries').'</option>';
1405: $analyze_selector .= '<option value="Time" ';
1406: $analyze_selector .= ' selected ' if ($ENV{'form.AnalyzeOver'} eq 'Time');
1407: $analyze_selector .= '>'.&mt('Time').'</option>';
1408: $analyze_selector .= '</select>';
1.91 ! matthew 1409: $Str .= '<nobr><label>'.
1.90 matthew 1410: &mt('Analyze Over [_1] [_2]',
1411: $analyze_selector,
1412: &Apache::loncommon::help_open_topic('Analysis_Analyze_Over')).
1.91 ! matthew 1413: '</label></nobr><br />'.$/;
1.90 matthew 1414: ##
1415: my $numplots_selector = '<select name="NumPlots">';
1416: if (! exists($ENV{'form.NumPlots'})
1417: || $ENV{'form.NumPlots'} < 1
1418: || $ENV{'form.NumPlots'} > 20) {
1419: $ENV{'form.NumPlots'} = 5;
1420: }
1421: foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
1422: $numplots_selector .= '<option value="'.$i.'" ';
1423: if ($ENV{'form.NumPlots'} == $i) { $numplots_selector.=' selected '; }
1424: $numplots_selector .= '>'.$i.'</option>';
1425: }
1426: $numplots_selector .= '</select></nobr><br />';
1427: $Str .= '<nobr><label>'.&mt('Number of Plots [_1]',$numplots_selector).
1428: '</label></nobr>';
1429: ##
1430: $Str .= '<nobr><label>'.&mt('Status: [_1]',
1.85 matthew 1431: '<input type="text" '.
1432: 'name="stats_status" size="60" value="" />'
1433: ).
1.90 matthew 1434: '</label></nobr>';
1.28 matthew 1435: $Str .= '</td>';
1.36 matthew 1436: ##
1437: ##
1.28 matthew 1438: $Str .= '</tr>'."\n";
1.23 matthew 1439: $Str .= '</table>'."\n";
1.42 matthew 1440: return $Str;
1.54 matthew 1441: }
1.47 matthew 1442:
1443: #########################################################
1444: #########################################################
1445: ##
1446: ## Misc Option Response functions
1447: ##
1448: #########################################################
1449: #########################################################
1450: sub get_time_from_row {
1.42 matthew 1451: my ($row) = @_;
1452: if (ref($row)) {
1.47 matthew 1453: return $row->[&Apache::loncoursedata::RD_timestamp()];
1.42 matthew 1454: }
1455: return undef;
1456: }
1457:
1.47 matthew 1458: sub get_tries_from_row {
1.42 matthew 1459: my ($row) = @_;
1460: if (ref($row)) {
1.47 matthew 1461: return $row->[&Apache::loncoursedata::RD_tries()];
1.42 matthew 1462: }
1463: return undef;
1464: }
1465:
1.48 matthew 1466: sub hashify_attempt {
1467: my ($row) = @_;
1468: my %attempt;
1469: $attempt{'tries'} = $row->[&Apache::loncoursedata::RD_tries()];
1470: $attempt{'submission'} = $row->[&Apache::loncoursedata::RD_submission()];
1471: $attempt{'award'} = $row->[&Apache::loncoursedata::RD_awarddetail()];
1472: $attempt{'timestamp'} = $row->[&Apache::loncoursedata::RD_timestamp()];
1473: return %attempt;
1474: }
1475:
1.46 matthew 1476: sub Process_OR_Row {
1.42 matthew 1477: my ($row) = @_;
1478: my %RowData;
1.47 matthew 1479: my $student_id = $row->[&Apache::loncoursedata::RD_student_id()];
1480: my $award = $row->[&Apache::loncoursedata::RD_awarddetail()];
1481: my $grading = $row->[&Apache::loncoursedata::RD_response_eval()];
1482: my $submission = $row->[&Apache::loncoursedata::RD_submission()];
1483: my $time = $row->[&Apache::loncoursedata::RD_timestamp()];
1484: my $tries = $row->[&Apache::loncoursedata::RD_tries()];
1.43 matthew 1485: return undef if ($award eq 'MISSING_ANSWER');
1.42 matthew 1486: if ($award =~ /(APPROX_ANS|EXACT_ANS)/) {
1487: $RowData{'_correct'} = 1;
1488: }
1489: $RowData{'_total'} = 1;
1490: my @Foilgrades = split('&',$grading);
1491: my @Foilsubs = split('&',$submission);
1492: for (my $j=0;$j<=$#Foilgrades;$j++) {
1493: my ($foilid,$correct) = split('=',$Foilgrades[$j]);
1.58 matthew 1494: $foilid = &Apache::lonnet::unescape($foilid);
1.42 matthew 1495: my (undef,$submission) = split('=',$Foilsubs[$j]);
1496: if ($correct) {
1497: $RowData{$foilid}->{'_correct'}++;
1498: } else {
1499: $submission = &Apache::lonnet::unescape($submission);
1500: $RowData{$foilid}->{$submission}++;
1501: }
1502: $RowData{$foilid}->{'_total'}++;
1503: }
1504: return %RowData;
1.47 matthew 1505: }
1506:
1.23 matthew 1507: 1;
1.1 stredwic 1508:
1509: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>