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