Annotation of loncom/interface/statistics/lonproblemanalysis.pm, revision 1.93
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: #
1.93 ! matthew 3: # $Id: lonproblemanalysis.pm,v 1.92 2004/10/04 19:49:41 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
1.93 ! matthew 622: $concept_data[$j]->[$try]->{'_correct'} +=
1.88 matthew 623: $response_data{$foilid}->[$try]->{'_correct'};
1.93 ! matthew 624: $concept_data[$j]->[$try]->{'_total'} +=
1.88 matthew 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.92 matthew 666: if (! defined($response_data{'_total'}->[$try]) ||
667: $response_data{'_total'}->[$try] == 0) {
668: if ($try > 1) {
669: $analysis_html.= '<tr><td align="center" colspan="4"><b>'.
670: &mt('None of the selected students attempted the problem more than [_1] times.',$try-1).
671: '</b></td></tr>';
672: } else {
673: $analysis_html.= '<tr><td colspan="4" align="center"><b>'.
674: &mt('None of the selected students have attempted the problem').'</b></td></tr>';
675: }
676: last;
677: }
1.88 matthew 678: my $concept_graph='';
679: if ($num_concepts > 1) {
680: #
681: # Create concept plot
682: my @concept_plot_data;
683: for (my $j=0;$j<=$#concept_data;$j++) {
1.93 ! matthew 684: my $total = $concept_data[$j]->[$try]->{'_total'};
1.88 matthew 685: if ($total == 0) {
686: $concept_plot_data[$j] = 0;
687: } else {
688: $concept_plot_data[$j] = 100 *
689: sprintf('%0.3f',
1.93 ! matthew 690: $concept_data[$j]->[$try]->{'_correct'} /
! 691: $total);
1.88 matthew 692: }
693: }
694: #
695: my $title;
696: my $count = $response_data{'_total'}->[$try];
697: $title = 'Attempt '.$try.' (N='.$count.')';
698: $concept_graph = &Apache::loncommon::DrawBarGraph
699: ($title,'Concept Number','Percent Correct',
700: 100,$plotcolors,undef,\@concept_plot_data);
701: }
702: #
703: # Create Foil Plots
704: my $count = $response_data{'_total'}->[$try];
705: my $title = 'Attempt '.$try.' (N='.$count.')';
1.42 matthew 706: my @Datasets;
1.48 matthew 707: foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {
1.88 matthew 708: next if (! exists($foil_plot[$try]->{$option}));
709: push(@Datasets,$foil_plot[$try]->{$option});
1.42 matthew 710: }
1.76 matthew 711: #
712: # Put a blank in the data set between concepts
713: for (my $set =0;$set<=$#Datasets;$set++) {
714: my @Data = @{$Datasets[$set]};
715: my $idx = 0;
716: foreach my $concept (@{$Concepts}) {
717: foreach my $foilid (@{$concept->{'foils'}}) {
718: $Datasets[$set]->[$idx++]=shift(@Data);
719: }
720: if ($concept->{'name'} ne $Concepts->[-1]->{'name'}) {
721: $Datasets[$set]->[$idx++] = 0;
722: }
723: }
724: }
725: #
726: # Set up the labels needed for the bar graph
727: my @Labels;
728: my $idx = 1;
729: foreach my $concept (@{$Concepts}) {
730: foreach my $foilid (@{$concept->{'foils'}}) {
731: push(@Labels,$idx++);
732: }
733: push(@Labels,'');
734: }
735: #
1.88 matthew 736: my $correct_graph = &Apache::loncommon::DrawBarGraph
1.42 matthew 737: ($title,'Foil Number','Percent Correct',
1.76 matthew 738: 100,$plotcolors,\@Labels,$Datasets[0]);
1.75 matthew 739:
740: #
741: #
1.57 matthew 742: next if (! defined($Datasets[0]));
1.42 matthew 743: for (my $i=0; $i< scalar(@{$Datasets[0]});$i++) {
744: $Datasets[0]->[$i]=0;
745: }
1.88 matthew 746: $count = $response_data{'_total'}->[$try] -
747: $response_data{'_correct'}->[$try];
748: $title = 'Attempt '.$try.' (N='.$count.')';
749: my $incorrect_graph = &Apache::loncommon::DrawBarGraph
1.42 matthew 750: ($title,'Foil Number','% Option Chosen Incorrectly',
1.76 matthew 751: 100,$plotcolors,\@Labels,@Datasets);
1.88 matthew 752: $analysis_html.=
753: '<tr>'.
754: '<td>'.$concept_graph.'</td>'.
755: '<td>'.$correct_graph.'</td>'.
756: '<td>'.$incorrect_graph.'</td>'.
757: '<td>'.$optionkey.'<td>'.
758: '</tr>'.$/;
1.42 matthew 759: }
760: $analysis_html .= "</table>\n";
1.88 matthew 761: $table .= $analysis_html;
762: return $table;
1.25 matthew 763: }
764:
1.57 matthew 765: sub OR_analyze_by_tries {
1.43 matthew 766: my ($r,$PerformanceData,$mintries,$maxtries) = @_;
1.25 matthew 767: my %Trydata;
768: $mintries = 1 if (! defined($mintries) || $mintries < 1);
769: $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
1.26 matthew 770: foreach my $row (@$PerformanceData) {
771: next if (! defined($row));
1.47 matthew 772: my $tries = &get_tries_from_row($row);
1.46 matthew 773: my %Row = &Process_OR_Row($row);
1.43 matthew 774: next if (! %Row);
1.42 matthew 775: while (my ($foilid,$href) = each(%Row)) {
776: if (! ref($href)) {
777: $Trydata{$foilid}->[$tries] += $href;
778: next;
779: }
780: while (my ($option,$value) = each(%$href)) {
781: $Trydata{$foilid}->[$tries]->{$option}+=$value;
1.25 matthew 782: }
783: }
784: }
785: return %Trydata;
786: }
787:
1.33 matthew 788: #########################################################
1.46 matthew 789: #
790: # Option Response: Time Analysis
791: #
1.33 matthew 792: #########################################################
1.57 matthew 793: sub OR_time_analysis {
1.88 matthew 794: my ($performance_data,$ORdata) = @_;
1.42 matthew 795: my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
1.88 matthew 796: my $foilkey = &build_option_index($ORdata);
797: my $num_concepts = 1;
798: if (defined($Concepts)) { $num_concepts = scalar(@$Concepts); }
799: #
800: if ($num_concepts < 2) {
1.42 matthew 801: $table = '<h3>'.
802: &mt('Not enough data for concept analysis. '.
803: 'Performing Foil Analysis').
1.88 matthew 804: '</h3>'.$table;
1.42 matthew 805: }
1.88 matthew 806: #
1.33 matthew 807: my $num_plots = $ENV{'form.NumPlots'};
1.88 matthew 808: my $num_data = scalar(@$performance_data)-1;
1.33 matthew 809: my $percent = sprintf('%2f',100/$num_plots);
1.42 matthew 810: #
1.37 matthew 811: $table .= "<table>\n";
1.33 matthew 812: for (my $i=0;$i<$num_plots;$i++) {
1.42 matthew 813: ##
1.34 matthew 814: my $starttime = &Apache::lonhtmlcommon::get_date_from_form
815: ('startdate_'.$i);
816: my $endtime = &Apache::lonhtmlcommon::get_date_from_form
817: ('enddate_'.$i);
818: if (! defined($starttime) || ! defined($endtime)) {
1.42 matthew 819: my $sec_in_day = 86400;
1.88 matthew 820: my $last_sub_time = &get_time_from_row($performance_data->[-1]);
1.42 matthew 821: my ($sday,$smon,$syear);
822: (undef,undef,undef,$sday,$smon,$syear) =
823: localtime($last_sub_time - $sec_in_day*$i);
824: $starttime = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear);
825: $endtime = $starttime + $sec_in_day;
826: if ($i == ($num_plots -1 )) {
1.88 matthew 827: $starttime = &get_time_from_row($performance_data->[0]);
1.42 matthew 828: }
829: }
1.88 matthew 830: $table .= '<tr><td colspan="4" align="center">'.
831: &mt('Data from [_1] to [_2]',
832: &Apache::lonlocal::locallocaltime($starttime),
833: &Apache::lonlocal::locallocaltime($endtime)).'</td></tr>'.$/;
1.34 matthew 834: my $startdateform = &Apache::lonhtmlcommon::date_setter
835: ('Statistics','startdate_'.$i,$starttime);
836: my $enddateform = &Apache::lonhtmlcommon::date_setter
837: ('Statistics','enddate_'.$i,$endtime);
1.42 matthew 838: #
839: my $begin_index;
840: my $end_index;
841: my $j;
1.88 matthew 842: while (++$j < scalar(@$performance_data)) {
843: last if (&get_time_from_row($performance_data->[$j])
1.46 matthew 844: > $starttime);
1.42 matthew 845: }
846: $begin_index = $j;
1.91 matthew 847: while ($j < scalar(@$performance_data)) {
848: if (&get_time_from_row($performance_data->[$j]) > $endtime) {
849: last;
850: } else {
851: $j++;
852: }
1.42 matthew 853: }
854: $end_index = $j;
855: ##
856: my $interval = {
857: begin_index => $begin_index,
858: end_index => $end_index,
859: startdateform => $startdateform,
860: enddateform => $enddateform,
861: };
1.88 matthew 862: my $concept_correct_plot = '';
863: if ($num_concepts > 1) {
864: $concept_correct_plot =
865: &OR_Concept_Time_Analysis($performance_data,
866: $ORdata,$Concepts,
1.42 matthew 867: $interval);
868: }
1.88 matthew 869: my ($foil_correct_plot,$foil_incorrect_plot) =
870: &OR_Foil_Time_Analysis($performance_data,$ORdata,
871: $Foils,$Concepts,$interval);
872: $table .= '<tr>'.
873: '<td>'.$concept_correct_plot.'</td>'.
874: '<td>'.$foil_correct_plot.'</td>'.
875: '<td>'.$foil_incorrect_plot.'</td>'.
876: '<td align="left" valign="top">'.$foilkey.'</td></tr>'.$/;
877: $table .= '<tr><td colspan="4" align="center">'.
878: &mt('Start time: [_1]',
879: $interval->{'startdateform'}).'<br />'.
880: &mt('End time: [_1]',
881: $interval->{'enddateform'}).
882: '</td></tr>'.$/;
883: $table.= '<tr><td colspan="4"> </td></tr>'.$/;
1.33 matthew 884: }
1.88 matthew 885: $table .= '</table>';
1.42 matthew 886: #
1.33 matthew 887: return $table;
888: }
889:
1.57 matthew 890: sub OR_Foil_Time_Analysis {
1.88 matthew 891: my ($performance_data,$ORdata,$Foils,$Concepts,$interval) = @_;
1.42 matthew 892: my $analysis_html;
893: my ($begin_index,$end_index) = ($interval->{'begin_index'},
894: $interval->{'end_index'});
1.33 matthew 895: my %TimeData;
896: #
897: # Compute the number getting the foils correct or incorrects
1.42 matthew 898: for (my $j=$begin_index;$j<=$end_index;$j++) {
1.88 matthew 899: my $row = $performance_data->[$j];
1.33 matthew 900: next if (! defined($row));
1.46 matthew 901: my %Row = &Process_OR_Row($row);
1.42 matthew 902: while (my ($foilid,$href) = each(%Row)) {
903: if (! ref($href)) {
904: $TimeData{$foilid} += $href;
905: next;
906: }
907: while (my ($option,$value) = each(%$href)) {
908: $TimeData{$foilid}->{$option}+=$value;
1.33 matthew 909: }
910: }
911: }
1.88 matthew 912: my @plotdata;
913: my @labels;
914: foreach my $concept (@{$Concepts}) {
915: foreach my $foil (@{$concept->{'foils'}}) {
916: push(@labels,scalar(@labels)+1);
917: my $total = $TimeData{$foil}->{'_total'};
918: if ($total == 0) {
919: push(@{$plotdata[0]},0);
1.42 matthew 920: } else {
1.88 matthew 921: push(@{$plotdata[0]},
922: 100 * $TimeData{$foil}->{'_correct'} / $total);
1.37 matthew 923: }
1.88 matthew 924: my $total_incorrect = $total - $TimeData{$foil}->{'_correct'};
925: for (my $i=0;$i<scalar(@{$ORdata->{'_Options'}});$i++) {
926: my $option = $ORdata->{'_Options'}->[$i];
927: if ($total_incorrect == 0) {
928: push(@{$plotdata[$i+1]},0);
929: } else {
930: push(@{$plotdata[$i+1]},
931: 100 * $TimeData{$foil}->{$option} / $total_incorrect);
932: }
933: }
934: }
935: # Put in a blank one
936: push(@labels,'');
937: push(@{$plotdata[0]},0);
938: for (my $i=0;$i<scalar(@{$ORdata->{'_Options'}});$i++) {
939: push(@{$plotdata[$i+1]},0);
1.39 matthew 940: }
1.42 matthew 941: }
942: #
943: # Create the plot
944: my $count = $end_index-$begin_index;
1.91 matthew 945: return ('No data','') if ($count <= 0);
1.42 matthew 946: my $title;
947: if ($count == 0) {
948: $title = 'no submissions';
949: } elsif ($count == 1) {
950: $title = 'one submission';
1.91 matthew 951: } elsif ($count > 1) {
1.42 matthew 952: $title = $count.' submissions';
953: }
1.88 matthew 954: my $correct_plot = &Apache::loncommon::DrawBarGraph($title,
1.46 matthew 955: 'Foil Number',
956: 'Percent Correct',
957: 100,
958: $plotcolors,
1.64 matthew 959: undef,
1.88 matthew 960: $plotdata[0]);
961: for (my $j=0; $j< scalar(@{$plotdata[0]});$j++) {
962: $plotdata[0]->[$j]=0;
1.42 matthew 963: }
964: $count = $end_index-$begin_index-$TimeData{'_correct'};
965: if ($count == 0) {
966: $title = 'no submissions';
1.91 matthew 967: } elsif ($count < 0) {
968: return ($correct_plot,'');
1.42 matthew 969: } elsif ($count == 1) {
970: $title = 'one submission';
971: } else {
972: $title = $count.' submissions';
973: }
1.88 matthew 974: my $incorrect_plot = &Apache::loncommon::DrawBarGraph($title,
1.42 matthew 975: 'Foil Number',
976: 'Incorrect Option Choice',
977: 100,
978: $plotcolors,
1.64 matthew 979: undef,
1.91 matthew 980: @plotdata);
1.88 matthew 981: return ($correct_plot,$incorrect_plot);
1.42 matthew 982: }
983:
1.57 matthew 984: sub OR_Concept_Time_Analysis {
1.88 matthew 985: my ($performance_data,$ORdata,$Concepts,$interval) = @_;
1.42 matthew 986: ##
987: ## Determine starttime, endtime, startindex, endindex
988: my ($begin_index,$end_index) = ($interval->{'begin_index'},
989: $interval->{'end_index'});
990: my %TimeData;
991: #
992: # Compute the number getting the foils correct or incorrects
993: for (my $j=$begin_index;$j<=$end_index;$j++) {
1.88 matthew 994: my $row = $performance_data->[$j];
1.42 matthew 995: next if (! defined($row));
1.46 matthew 996: my %Row = &Process_OR_Row($row);
1.42 matthew 997: while (my ($foilid,$href) = each(%Row)) {
998: if (! ref($href)) {
999: $TimeData{$foilid} += $href;
1000: next;
1.37 matthew 1001: }
1.42 matthew 1002: while (my ($option,$value) = each(%$href)) {
1003: $TimeData{$foilid}->{$option}+=$value;
1.37 matthew 1004: }
1.33 matthew 1005: }
1006: }
1007: #
1.42 matthew 1008: # Put the data in plottable form
1.88 matthew 1009: my @plotdata;
1.42 matthew 1010: foreach my $concept (@$Concepts) {
1011: my ($total,$correct);
1012: foreach my $foil (@{$concept->{'foils'}}) {
1013: $total += $TimeData{$foil}->{'_total'};
1014: $correct += $TimeData{$foil}->{'_correct'};
1015: }
1016: if ($total == 0) {
1.88 matthew 1017: push(@plotdata,0);
1.42 matthew 1018: } else {
1.88 matthew 1019: push(@plotdata,100 * $correct / $total);
1.42 matthew 1020: }
1021: }
1022: #
1.33 matthew 1023: # Create the plot
1.42 matthew 1024: my $title = ($end_index - $begin_index).' submissions';
1.88 matthew 1025: return &Apache::loncommon::DrawBarGraph($title,
1026: 'Concept Number',
1027: 'Percent Correct',
1028: 100,
1029: $plotcolors,
1030: undef,
1031: \@plotdata);
1.42 matthew 1032: }
1033:
1034: #########################################################
1035: #########################################################
1036: ##
1037: ## Excel output
1038: ##
1039: #########################################################
1040: #########################################################
1.57 matthew 1041: sub OR_excel_sheet {
1.88 matthew 1042: my ($r,$resource,$performance_data,$ORdata) = @_;
1.44 matthew 1043: my $response = '';
1.42 matthew 1044: my (undef,$Foils,$Concepts) = &build_foil_index($ORdata);
1.43 matthew 1045: #
1046: # Create excel worksheet
1047: my $filename = '/prtspool/'.
1048: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
1049: time.'_'.rand(1000000000).'.xls';
1050: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1051: if (! defined($workbook)) {
1052: $r->log_error("Error creating excel spreadsheet $filename: $!");
1053: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1054: "This error has been logged. ".
1055: "Please alert your LON-CAPA administrator").
1056: '</p>');
1057: return undef;
1058: }
1059: #
1060: $workbook->set_tempdir('/home/httpd/perl/tmp');
1.69 matthew 1061: my $format = &Apache::loncommon::define_excel_formats($workbook);
1.43 matthew 1062: #
1063: # Create and populate main worksheets
1064: my $problem_data_sheet = $workbook->addworksheet('Problem Data');
1.69 matthew 1065: my $student_data_sheet = &build_student_data_worksheet($workbook,$format);
1.43 matthew 1066: my $response_data_sheet = $workbook->addworksheet('Response Data');
1067: foreach my $sheet ($problem_data_sheet,$student_data_sheet,
1068: $response_data_sheet) {
1069: $sheet->write(0,0,$resource->{'title'},$format->{'h2'});
1070: $sheet->write(1,0,$resource->{'src'},$format->{'h3'});
1071: }
1072: #
1073: my $result;
1.59 matthew 1074: $result = &OR_build_problem_data_worksheet($problem_data_sheet,$format,
1.43 matthew 1075: $Concepts,$ORdata);
1076: if ($result ne 'okay') {
1077: # Do something useful
1078: }
1.59 matthew 1079: $result = &OR_build_response_data_worksheet($response_data_sheet,$format,
1.88 matthew 1080: $performance_data,$Foils,
1.43 matthew 1081: $ORdata);
1082: if ($result ne 'okay') {
1083: # Do something useful
1084: }
1.44 matthew 1085: $response_data_sheet->activate();
1.43 matthew 1086: #
1087: # Close the excel file
1088: $workbook->close();
1089: #
1090: # Write a link to allow them to download it
1.44 matthew 1091: $result .= '<h2>'.&mt('Excel Raw Data Output').'</h2>'.
1092: '<p><a href="'.$filename.'">'.
1093: &mt('Your Excel spreadsheet.').
1094: '</a></p>'."\n";
1.43 matthew 1095: return $result;
1096: }
1097:
1.57 matthew 1098: sub OR_build_problem_data_worksheet {
1.43 matthew 1099: my ($worksheet,$format,$Concepts,$ORdata) = @_;
1100: my $rows_output = 3;
1101: my $cols_output = 0;
1102: $worksheet->write($rows_output++,0,'Problem Structure',$format->{'h3'});
1103: ##
1104: ##
1105: my @Headers;
1106: if (@$Concepts > 1) {
1107: @Headers = ("Concept\nNumber",'Concept',"Foil\nNumber",
1108: 'Foil Name','Foil Text','Correct value');
1109: } else {
1110: @Headers = ('Foil Number','FoilName','Foil Text','Correct value');
1111: }
1112: $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
1.48 matthew 1113: my %Foildata = %{$ORdata->{'_Foils'}};
1.43 matthew 1114: my $conceptindex = 1;
1115: my $foilindex = 1;
1116: foreach my $concept (@$Concepts) {
1117: my @FoilsInConcept = @{$concept->{'foils'}};
1118: my $firstfoil = shift(@FoilsInConcept);
1119: if (@$Concepts > 1) {
1120: $worksheet->write_row($rows_output++,0,
1121: [$conceptindex,
1122: $concept->{'name'},
1123: $foilindex++,
1124: $Foildata{$firstfoil}->{'name'},
1125: $Foildata{$firstfoil}->{'text'},
1126: $Foildata{$firstfoil}->{'value'},]);
1127: } else {
1128: $worksheet->write_row($rows_output++,0,
1129: [ $foilindex++,
1130: $Foildata{$firstfoil}->{'name'},
1131: $Foildata{$firstfoil}->{'text'},
1132: $Foildata{$firstfoil}->{'value'},]);
1133: }
1134: foreach my $foilid (@FoilsInConcept) {
1135: if (@$Concepts > 1) {
1136: $worksheet->write_row($rows_output++,0,
1137: ['',
1138: '',
1139: $foilindex,
1140: $Foildata{$foilid}->{'name'},
1141: $Foildata{$foilid}->{'text'},
1142: $Foildata{$foilid}->{'value'},]);
1143: } else {
1144: $worksheet->write_row($rows_output++,0,
1145: [$foilindex,
1146: $Foildata{$foilid}->{'name'},
1147: $Foildata{$foilid}->{'text'},
1148: $Foildata{$foilid}->{'value'},]);
1149: }
1150: } continue {
1151: $foilindex++;
1152: }
1153: } continue {
1154: $conceptindex++;
1155: }
1156: $rows_output++;
1157: $rows_output++;
1158: ##
1159: ## Option data output
1160: $worksheet->write($rows_output++,0,'Options',$format->{'header'});
1.48 matthew 1161: foreach my $string (@{$ORdata->{'_Options'}}) {
1.43 matthew 1162: $worksheet->write($rows_output++,0,$string);
1163: }
1164: return 'okay';
1165: }
1166:
1.57 matthew 1167: sub OR_build_response_data_worksheet {
1.88 matthew 1168: my ($worksheet,$format,$performance_data,$Foils,$ORdata)=@_;
1.43 matthew 1169: my $rows_output = 3;
1170: my $cols_output = 0;
1171: $worksheet->write($rows_output++,0,'Response Data',$format->{'h3'});
1172: $worksheet->set_column(1,1,20);
1173: $worksheet->set_column(2,2,13);
1174: my @Headers = ('identifier','time','award detail','attempt');
1175: foreach my $foil (@$Foils) {
1176: push (@Headers,$foil.' submission');
1177: push (@Headers,$foil.' grading');
1178: }
1179: $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
1180: #
1.88 matthew 1181: foreach my $row (@$performance_data) {
1.43 matthew 1182: next if (! defined($row));
1183: my ($student,$award,$grading,$submission,$time,$tries) = @$row;
1184: my @Foilgrades = split('&',$grading);
1185: my @Foilsubs = split('&',$submission);
1.88 matthew 1186: my %response_data;
1.43 matthew 1187: for (my $j=0;$j<=$#Foilgrades;$j++) {
1188: my ($foilid,$correct) = split('=',$Foilgrades[$j]);
1189: my (undef,$submission) = split('=',$Foilsubs[$j]);
1190: $submission = &Apache::lonnet::unescape($submission);
1.88 matthew 1191: $response_data{$foilid.' submission'}=$submission;
1192: $response_data{$foilid.' award'}=$correct;
1.43 matthew 1193: }
1194: $worksheet->write($rows_output,$cols_output++,$student);
1195: $worksheet->write($rows_output,$cols_output++,
1.71 matthew 1196: &Apache::lonstathelpers::calc_serial($time),$format->{'date'});
1.43 matthew 1197: $worksheet->write($rows_output,$cols_output++,$award);
1198: $worksheet->write($rows_output,$cols_output++,$tries);
1199: foreach my $foilid (@$Foils) {
1200: $worksheet->write($rows_output,$cols_output++,
1.88 matthew 1201: $response_data{$foilid.' submission'});
1.43 matthew 1202: $worksheet->write($rows_output,$cols_output++,
1.88 matthew 1203: $response_data{$foilid.' award'});
1.43 matthew 1204: }
1205: $rows_output++;
1206: $cols_output = 0;
1207: }
1208: return;
1.42 matthew 1209: }
1210:
1.46 matthew 1211: sub build_foil_index {
1212: my ($ORdata) = @_;
1.48 matthew 1213: return if (! exists($ORdata->{'_Foils'}));
1214: my %Foildata = %{$ORdata->{'_Foils'}};
1.46 matthew 1215: my @Foils = sort(keys(%Foildata));
1216: my %Concepts;
1217: foreach my $foilid (@Foils) {
1.48 matthew 1218: push(@{$Concepts{$Foildata{$foilid}->{'_Concept'}}},
1.46 matthew 1219: $foilid);
1220: }
1221: undef(@Foils);
1222: # Having gathered the concept information in a hash, we now translate it
1223: # into an array because we need to be consistent about order.
1224: # Also put the foils in order, too.
1225: my $sortfunction = sub {
1226: my %Numbers = (one => 1,
1227: two => 2,
1228: three => 3,
1229: four => 4,
1230: five => 5,
1231: six => 6,
1232: seven => 7,
1233: eight => 8,
1234: nine => 9,
1235: ten => 10,);
1236: my $a1 = lc($a);
1237: my $b1 = lc($b);
1.57 matthew 1238: if (exists($Numbers{$a1})) {
1.67 matthew 1239: $a1 = $Numbers{$a1};
1.57 matthew 1240: }
1241: if (exists($Numbers{$b1})) {
1.67 matthew 1242: $b1 = $Numbers{$b1};
1.46 matthew 1243: }
1.67 matthew 1244: if (($a1 =~/^\d+$/) && ($b1 =~/^\d+$/)) {
1245: return $a1 <=> $b1;
1.57 matthew 1246: } else {
1.67 matthew 1247: return $a1 cmp $b1;
1.46 matthew 1248: }
1249: };
1250: my @Concepts;
1251: foreach my $concept (sort $sortfunction (keys(%Concepts))) {
1.57 matthew 1252: if (! defined($Concepts{$concept})) {
1253: $Concepts{$concept}=[];
1254: # next;
1255: }
1.46 matthew 1256: push(@Concepts,{ name => $concept,
1257: foils => [@{$Concepts{$concept}}]});
1258: push(@Foils,(@{$Concepts{$concept}}));
1259: }
1260: #
1261: # Build up the table of row labels.
1262: my $table = '<table border="1" >'."\n";
1263: if (@Concepts > 1) {
1264: $table .= '<tr>'.
1265: '<th>'.&mt('Concept Number').'</th>'.
1266: '<th>'.&mt('Concept').'</th>'.
1267: '<th>'.&mt('Foil Number').'</th>'.
1268: '<th>'.&mt('Foil Name').'</th>'.
1269: '<th>'.&mt('Foil Text').'</th>'.
1270: '<th>'.&mt('Correct Value').'</th>'.
1271: "</tr>\n";
1272: } else {
1273: $table .= '<tr>'.
1274: '<th>'.&mt('Foil Number').'</th>'.
1275: '<th>'.&mt('Foil Name').'</th>'.
1276: '<th>'.&mt('Foil Text').'</th>'.
1277: '<th>'.&mt('Correct Value').'</th>'.
1278: "</tr>\n";
1279: }
1280: my $conceptindex = 1;
1281: my $foilindex = 1;
1282: foreach my $concept (@Concepts) {
1283: my @FoilsInConcept = @{$concept->{'foils'}};
1284: my $firstfoil = shift(@FoilsInConcept);
1285: if (@Concepts > 1) {
1286: $table .= '<tr>'.
1287: '<td>'.$conceptindex.'</td>'.
1.83 albertel 1288: '<td>'.&HTML::Entities::encode($concept->{'name'},'<>&"').'</td>'.
1.46 matthew 1289: '<td>'.$foilindex++.'</td>'.
1.83 albertel 1290: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').'</td>'.
1.65 matthew 1291: '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
1.83 albertel 1292: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').'</td>'.
1.46 matthew 1293: "</tr>\n";
1294: } else {
1295: $table .= '<tr>'.
1296: '<td>'.$foilindex++.'</td>'.
1.83 albertel 1297: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'},'<>&"').'</td>'.
1.65 matthew 1298: '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
1.83 albertel 1299: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'},'<>&"').'</td>'.
1.46 matthew 1300: "</tr>\n";
1301: }
1302: foreach my $foilid (@FoilsInConcept) {
1303: if (@Concepts > 1) {
1304: $table .= '<tr>'.
1305: '<td></td>'.
1306: '<td></td>'.
1307: '<td>'.$foilindex.'</td>'.
1.83 albertel 1308: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').'</td>'.
1.65 matthew 1309: '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
1.84 albertel 1310: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').'</td>'.
1.46 matthew 1311: "</tr>\n";
1312: } else {
1313: $table .= '<tr>'.
1314: '<td>'.$foilindex.'</td>'.
1.83 albertel 1315: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'name'},'<>&"').'</td>'.
1.65 matthew 1316: '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
1.83 albertel 1317: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'value'},'<>&"').'</td>'.
1.46 matthew 1318: "</tr>\n";
1319: }
1320: } continue {
1321: $foilindex++;
1322: }
1323: } continue {
1324: $conceptindex++;
1325: }
1326: $table .= "</table>\n";
1327: #
1328: # Build option index with color stuff
1329: return ($table,\@Foils,\@Concepts);
1330: }
1331:
1332: sub build_option_index {
1333: my ($ORdata)= @_;
1334: my $table = "<table>\n";
1335: my $optionindex = 0;
1336: my @Rows;
1.48 matthew 1337: foreach my $option (&mt('correct option chosen'),@{$ORdata->{'_Options'}}) {
1.46 matthew 1338: push (@Rows,
1339: '<tr>'.
1340: '<td bgcolor="'.$plotcolors->[$optionindex++].'">'.
1341: (' 'x4).'</td>'.
1.83 albertel 1342: '<td>'.&HTML::Entities::encode($option,'<>&"').'</td>'.
1.46 matthew 1343: "</tr>\n");
1344: }
1345: shift(@Rows); # Throw away 'correct option chosen' color
1346: $table .= join('',reverse(@Rows));
1347: $table .= "</table>\n";
1348: }
1349:
1.33 matthew 1350: #########################################################
1351: #########################################################
1352: ##
1.46 matthew 1353: ## Generic Interface Routines
1.33 matthew 1354: ##
1355: #########################################################
1356: #########################################################
1.23 matthew 1357: sub CreateInterface {
1.28 matthew 1358: ##
1359: ## Environment variable initialization
1.36 matthew 1360: if (! exists$ENV{'form.AnalyzeOver'}) {
1361: $ENV{'form.AnalyzeOver'} = 'Tries';
1.28 matthew 1362: }
1363: ##
1364: ## Build the menu
1.7 stredwic 1365: my $Str = '';
1.72 matthew 1366: $Str .= &Apache::lonhtmlcommon::breadcrumbs
1.74 matthew 1367: (undef,'Detailed Problem Analysis');
1.23 matthew 1368: $Str .= '<table cellspacing="5">'."\n";
1369: $Str .= '<tr>';
1370: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
1371: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
1.31 matthew 1372: # $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
1373: $Str .= '<td align="center"> </td>';
1.23 matthew 1374: $Str .= '</tr>'."\n";
1.31 matthew 1375: ##
1376: ##
1.23 matthew 1377: $Str .= '<tr><td align="center">'."\n";
1378: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1.28 matthew 1379: $Str .= '</td>';
1380: #
1381: $Str .= '<td align="center">';
1.23 matthew 1382: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1.28 matthew 1383: $Str .= '</td>';
1384: #
1.31 matthew 1385: # $Str .= '<td align="center">';
1.23 matthew 1386: my $only_seq_with_assessments = sub {
1387: my $s=shift;
1388: if ($s->{'num_assess'} < 1) {
1389: return 0;
1390: } else {
1391: return 1;
1392: }
1393: };
1.31 matthew 1394: &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
1.23 matthew 1395: $only_seq_with_assessments);
1.36 matthew 1396: ##
1397: ##
1.28 matthew 1398: $Str .= '<td>';
1.91 matthew 1399: ##
1400: my $showprob_checkbox =
1401: '<input type="checkbox" name="show_prob" value="true" ';
1402: if ($ENV{'form.show_prob'} eq 'true') {
1403: $showprob_checkbox .= 'checked ';
1404: }
1405: $showprob_checkbox.= ' />';
1406: $Str.= '<nobr><label>'.
1407: &mt('Show problem [_1]',$showprob_checkbox).
1408: '</label></nobr><br />';
1409: ##
1.90 matthew 1410: my $analyze_selector = '<select name="AnalyzeOver" >';
1411: $analyze_selector .= '<option value="Tries" ';
1412: if (! exists($ENV{'form.AnalyzeOver'}) ||
1413: $ENV{'form.AnalyzeOver'} eq 'Tries'){
1414: # Default to Tries
1415: $analyze_selector .= ' selected ';
1416: }
1417: $analyze_selector .= '>'.&mt('Tries').'</option>';
1418: $analyze_selector .= '<option value="Time" ';
1419: $analyze_selector .= ' selected ' if ($ENV{'form.AnalyzeOver'} eq 'Time');
1420: $analyze_selector .= '>'.&mt('Time').'</option>';
1421: $analyze_selector .= '</select>';
1.91 matthew 1422: $Str .= '<nobr><label>'.
1.90 matthew 1423: &mt('Analyze Over [_1] [_2]',
1424: $analyze_selector,
1425: &Apache::loncommon::help_open_topic('Analysis_Analyze_Over')).
1.91 matthew 1426: '</label></nobr><br />'.$/;
1.90 matthew 1427: ##
1428: my $numplots_selector = '<select name="NumPlots">';
1429: if (! exists($ENV{'form.NumPlots'})
1430: || $ENV{'form.NumPlots'} < 1
1431: || $ENV{'form.NumPlots'} > 20) {
1432: $ENV{'form.NumPlots'} = 5;
1433: }
1434: foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
1435: $numplots_selector .= '<option value="'.$i.'" ';
1436: if ($ENV{'form.NumPlots'} == $i) { $numplots_selector.=' selected '; }
1437: $numplots_selector .= '>'.$i.'</option>';
1438: }
1439: $numplots_selector .= '</select></nobr><br />';
1440: $Str .= '<nobr><label>'.&mt('Number of Plots [_1]',$numplots_selector).
1441: '</label></nobr>';
1442: ##
1443: $Str .= '<nobr><label>'.&mt('Status: [_1]',
1.85 matthew 1444: '<input type="text" '.
1445: 'name="stats_status" size="60" value="" />'
1446: ).
1.90 matthew 1447: '</label></nobr>';
1.28 matthew 1448: $Str .= '</td>';
1.36 matthew 1449: ##
1450: ##
1.28 matthew 1451: $Str .= '</tr>'."\n";
1.23 matthew 1452: $Str .= '</table>'."\n";
1.42 matthew 1453: return $Str;
1.54 matthew 1454: }
1.47 matthew 1455:
1456: #########################################################
1457: #########################################################
1458: ##
1459: ## Misc Option Response functions
1460: ##
1461: #########################################################
1462: #########################################################
1463: sub get_time_from_row {
1.42 matthew 1464: my ($row) = @_;
1465: if (ref($row)) {
1.47 matthew 1466: return $row->[&Apache::loncoursedata::RD_timestamp()];
1.42 matthew 1467: }
1468: return undef;
1469: }
1470:
1.47 matthew 1471: sub get_tries_from_row {
1.42 matthew 1472: my ($row) = @_;
1473: if (ref($row)) {
1.47 matthew 1474: return $row->[&Apache::loncoursedata::RD_tries()];
1.42 matthew 1475: }
1476: return undef;
1477: }
1478:
1.48 matthew 1479: sub hashify_attempt {
1480: my ($row) = @_;
1481: my %attempt;
1482: $attempt{'tries'} = $row->[&Apache::loncoursedata::RD_tries()];
1483: $attempt{'submission'} = $row->[&Apache::loncoursedata::RD_submission()];
1484: $attempt{'award'} = $row->[&Apache::loncoursedata::RD_awarddetail()];
1485: $attempt{'timestamp'} = $row->[&Apache::loncoursedata::RD_timestamp()];
1486: return %attempt;
1487: }
1488:
1.46 matthew 1489: sub Process_OR_Row {
1.42 matthew 1490: my ($row) = @_;
1491: my %RowData;
1.47 matthew 1492: my $student_id = $row->[&Apache::loncoursedata::RD_student_id()];
1493: my $award = $row->[&Apache::loncoursedata::RD_awarddetail()];
1494: my $grading = $row->[&Apache::loncoursedata::RD_response_eval()];
1495: my $submission = $row->[&Apache::loncoursedata::RD_submission()];
1496: my $time = $row->[&Apache::loncoursedata::RD_timestamp()];
1497: my $tries = $row->[&Apache::loncoursedata::RD_tries()];
1.43 matthew 1498: return undef if ($award eq 'MISSING_ANSWER');
1.42 matthew 1499: if ($award =~ /(APPROX_ANS|EXACT_ANS)/) {
1500: $RowData{'_correct'} = 1;
1501: }
1502: $RowData{'_total'} = 1;
1503: my @Foilgrades = split('&',$grading);
1504: my @Foilsubs = split('&',$submission);
1505: for (my $j=0;$j<=$#Foilgrades;$j++) {
1506: my ($foilid,$correct) = split('=',$Foilgrades[$j]);
1.58 matthew 1507: $foilid = &Apache::lonnet::unescape($foilid);
1.42 matthew 1508: my (undef,$submission) = split('=',$Foilsubs[$j]);
1509: if ($correct) {
1510: $RowData{$foilid}->{'_correct'}++;
1511: } else {
1512: $submission = &Apache::lonnet::unescape($submission);
1513: $RowData{$foilid}->{$submission}++;
1514: }
1515: $RowData{$foilid}->{'_total'}++;
1516: }
1517: return %RowData;
1.47 matthew 1518: }
1519:
1.23 matthew 1520: 1;
1.1 stredwic 1521:
1522: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>