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