1: # The LearningOnline Network with CAPA
2: #
3: # $Id: lonproblemanalysis.pm,v 1.77 2004/03/11 20:11:18 matthew Exp $
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: #
27: package Apache::lonproblemanalysis;
28:
29: use strict;
30: use Apache::lonnet();
31: use Apache::loncommon();
32: use Apache::lonhtmlcommon();
33: use Apache::loncoursedata();
34: use Apache::lonstatistics;
35: use Apache::lonlocal;
36: use Apache::lonstathelpers();
37: use Apache::lonstudentsubmissions();
38: use HTML::Entities();
39: use Time::Local();
40: use Spreadsheet::WriteExcel();
41:
42: my $plotcolors = ['#33ff00',
43: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
44: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
45: ];
46:
47: my @SubmitButtons = ({ name => 'PrevProblemAnalysis',
48: text => 'Previous Problem' },
49: { name => 'ProblemAnalysis',
50: text => 'Analyze Problem Again' },
51: { name => 'NextProblemAnalysis',
52: text => 'Next Problem' },
53: { name => 'break'},
54: { name => 'ClearCache',
55: text => 'Clear Caches' },
56: { name => 'updatecaches',
57: text => 'Update Student Data' },
58: { name => 'SelectAnother',
59: text => 'Choose a different Problem' },
60: { name => 'ExcelOutput',
61: text => 'Produce Excel Output' });
62:
63:
64: sub BuildProblemAnalysisPage {
65: my ($r,$c)=@_;
66: #
67: my %Saveable_Parameters = ('Status' => 'scalar',
68: 'Section' => 'array',
69: 'NumPlots' => 'scalar',
70: 'AnalyzeAs' => 'scalar',
71: 'AnalyzeOver' => 'scalar',
72: );
73: &Apache::loncommon::store_course_settings('problem_analysis',
74: \%Saveable_Parameters);
75: &Apache::loncommon::restore_course_settings('problem_analysis',
76: \%Saveable_Parameters);
77: #
78: &Apache::lonstatistics::PrepareClasslist();
79: #
80: $r->print(&CreateInterface());
81: #
82: my @Students = @Apache::lonstatistics::Students;
83: #
84: if (@Students < 1) {
85: $r->print('<h2>There are no students in the sections selected</h2>');
86: }
87: #
88: &Apache::loncoursedata::clear_internal_caches();
89: if (exists($ENV{'form.ClearCache'}) ||
90: exists($ENV{'form.updatecaches'}) ||
91: (exists($ENV{'form.firstanalysis'}) &&
92: $ENV{'form.firstanalysis'} ne 'no')) {
93: &Apache::lonstatistics::Gather_Full_Student_Data($r);
94: }
95: if (! exists($ENV{'form.firstanalysis'})) {
96: $r->print('<input type="hidden" name="firstanalysis" value="yes" />');
97: } else {
98: $r->print('<input type="hidden" name="firstanalysis" value="no" />');
99: }
100: $r->rflush();
101: #
102: my $problem_types = '(option|radiobutton)';
103: if (exists($ENV{'form.problemchoice'}) &&
104: ! exists($ENV{'form.SelectAnother'})) {
105: foreach my $button (@SubmitButtons) {
106: if ($button->{'name'} eq 'break') {
107: $r->print("<br />\n");
108: } else {
109: $r->print('<input type="submit" name="'.$button->{'name'}.'" '.
110: 'value="'.&mt($button->{'text'}).'" />');
111: $r->print(' 'x5);
112: }
113: }
114: #
115: $r->print('<hr />');
116: $r->rflush();
117: #
118: # Determine which problem we are to analyze
119: my $current_problem = &Apache::lonstathelpers::get_target_from_id
120: ($ENV{'form.problemchoice'});
121: #
122: my ($prev,$curr,$next) =
123: &Apache::lonstathelpers::get_prev_curr_next($current_problem,
124: $problem_types,
125: 'response',
126: );
127: if (exists($ENV{'form.PrevProblemAnalysis'}) && defined($prev)) {
128: $current_problem = $prev;
129: } elsif (exists($ENV{'form.NextProblemAnalysis'}) && defined($next)) {
130: $current_problem = $next;
131: } else {
132: $current_problem = $curr;
133: }
134: #
135: # Store the current problem choice and send it out in the form
136: $ENV{'form.problemchoice'} =
137: &Apache::lonstathelpers::make_target_id($current_problem);
138: $r->print('<input type="hidden" name="problemchoice" value="'.
139: $ENV{'form.problemchoice'}.'" />');
140: #
141: if (! defined($current_problem->{'resource'})) {
142: $r->print('resource is undefined');
143: } else {
144: my $resource = $current_problem->{'resource'};
145: $r->print('<h1>'.$resource->{'title'}.'</h1>');
146: $r->print('<h3>'.$resource->{'src'}.'</h3>');
147: $r->print(&Apache::lonstathelpers::render_resource($resource));
148: $r->rflush();
149: my %Data = &Apache::lonstathelpers::get_problem_data
150: ($resource->{'src'});
151: my $ProblemData = $Data{$current_problem->{'part'}.
152: '.'.
153: $current_problem->{'respid'}};
154: if ($current_problem->{'resptype'} eq 'option') {
155: &OptionResponseAnalysis($r,$current_problem,
156: $ProblemData,
157: \@Students);
158: } elsif ($current_problem->{'resptype'} eq 'radiobutton') {
159: &RadioResponseAnalysis($r,$current_problem,
160: $ProblemData,
161: \@Students);
162: } elsif ($current_problem->{'resptype'} eq 'numerical') {
163: # if (exists($ENV{'form.ExcelOutput'})) {
164: &Apache::lonstudentsubmissions::prepare_excel_output
165: ($r,$current_problem,$ProblemData,\@Students);
166: # } else {
167: # &NumericalResponseAnalysis($r,$current_problem,
168: # $ProblemData,\@Students);
169: # }
170: } else {
171: $r->print('<h2>This analysis is not supported</h2>');
172: }
173: }
174: $r->print('<hr />');
175: } else {
176: $r->print('<input type="submit" name="ProblemAnalysis" value="'.
177: &mt('Analyze Problem').'" />');
178: $r->print(' 'x5);
179: $r->print('<h3>'.&mt('Please select a problem to analyze').'</h3>');
180: $r->print(&Apache::lonstathelpers::ProblemSelector
181: ($problem_types));
182: }
183: }
184:
185:
186: #########################################################
187: #########################################################
188: ##
189: ## Numerical Response Routines
190: ##
191: #########################################################
192: #########################################################
193: sub NumericalResponseAnalysis {
194: my ($r,$problem,$ProblemData,$Students) = @_;
195: $r->print('<h2>This analysis is not yet supported</h2>');
196: my ($resource,$respid) = ($problem->{'resource'},
197: $problem->{'respid'});
198: my $analysis_html;
199: my $PerformanceData =
200: &Apache::loncoursedata::get_response_data
201: ($Students,$resource->{'symb'},$respid);
202: if (! defined($PerformanceData) ||
203: ref($PerformanceData) ne 'ARRAY' ) {
204: $analysis_html = '<h2>'.
205: &mt('There is no submission data for this resource').
206: '</h2>';
207: $r->print($analysis_html);
208: return;
209: }
210: my ($max,$min) = &GetStudentAnswers($r,$problem,$Students);
211: $r->print('Maximum = '.$max.' Minimum = '.$min);
212: my $max_students = 0;
213: my %Data;
214: foreach my $student (@$Students) {
215: my $answer = $student->{'answer'};
216: $Data{$answer}++;
217: if ($max_students < $Data{$answer}) {
218: $max_students = $Data{$answer};
219: }
220: }
221: foreach (5,10,20,25,50,75,100,150,200,250,500,1000,1500,2000,2500,5000) {
222: if ($max_students < $_) {
223: $max_students = $_;
224: last;
225: }
226: }
227: my @Labels = sort {$a <=> $b } keys(%Data);
228: $r->print('number of labels = '.scalar(@Labels));
229: my @PlotData = @Data{@Labels};
230: $r->print('number of PlotData = '.scalar(@PlotData));
231: my $graph =
232: &Apache::loncommon::DrawXYGraph('Correct Answer Distribution',
233: 'Correct Answer',
234: 'Number of students',
235: $max_students,
236: undef,
237: \@Labels,
238: [\@PlotData],
239: (xskip=>10));
240: $r->print($graph);
241: return;
242: }
243:
244: sub GetStudentAnswers {
245: my ($r,$problem,$Students) = @_;
246: my %Answers;
247: my ($resource,$partid,$respid) = ($problem->{'resource'},
248: $problem->{'part'},
249: $problem->{'respid'});
250: # Open progress window
251: my %prog_state=&Apache::lonhtmlcommon::Create_PrgWin
252: ($r,'Student Answer Compilation Status',
253: 'Student Answer Compilation Progress', scalar(@$Students));
254: $r->print("<table>\n");
255: $r->rflush();
256: foreach my $student (@$Students) {
257: my $sname = $student->{'username'};
258: my $sdom = $student->{'domain'};
259: my $answer = &Apache::lonstathelpers::analyze_problem_as_student
260: ($resource,$sname,$sdom,$partid,$respid);
261: &Apache::lonhtmlcommon::Increment_PrgWin($r,\%prog_state,
262: &mt('last student'));
263: $student->{'answer'} = $answer;
264: }
265: $r->print("</table>\n");
266: $r->rflush();
267: # close progress window
268: &Apache::lonhtmlcommon::Close_PrgWin($r,\%prog_state);
269: return;
270: }
271:
272: sub build_student_data_worksheet {
273: my ($workbook,$format) = @_;
274: my $rows_output = 3;
275: my $cols_output = 0;
276: my $worksheet = $workbook->addworksheet('Student Data');
277: $worksheet->write($rows_output++,0,'Student Data',$format->{'h3'});
278: my @Headers = ('full name','username','domain','section',
279: "student\nnumber",'identifier');
280: $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
281: my @Students = @Apache::lonstatistics::Students;
282: my $studentrows = &Apache::loncoursedata::get_student_data(\@Students);
283: my %ids;
284: foreach my $row (@$studentrows) {
285: my ($mysqlid,$student) = @$row;
286: $ids{$student}=$mysqlid;
287: }
288: foreach my $student (@Students) {
289: my $name_domain = $student->{'username'}.':'.$student->{'domain'};
290: $worksheet->write_row($rows_output++,0,
291: [$student->{'fullname'},
292: $student->{'username'},$student->{'domain'},
293: $student->{'section'},$student->{'id'},
294: $ids{$name_domain}]);
295: }
296: return $worksheet;
297: }
298:
299: #########################################################
300: #########################################################
301: ##
302: ## Radio Response Routines
303: ##
304: #########################################################
305: #########################################################
306: sub RadioResponseAnalysis {
307: my ($r,$problem,$ProblemData,$Students) = @_;
308: my ($resource,$respid) = ($problem->{'resource'},
309: $problem->{'respid'});
310: my $analysis_html;
311: my $PerformanceData =
312: &Apache::loncoursedata::get_response_data
313: ($Students,$resource->{'symb'},$respid);
314: if (! defined($PerformanceData) ||
315: ref($PerformanceData) ne 'ARRAY' ) {
316: $analysis_html = '<h2>'.
317: &mt('There is no submission data for this resource').
318: '</h2>';
319: $r->print($analysis_html);
320: return;
321: }
322: if (exists($ENV{'form.ExcelOutput'})) {
323: $analysis_html .= &RR_Excel_output($r,$problem->{'resource'},
324: $PerformanceData,$ProblemData);
325: } elsif ($ENV{'form.AnalyzeOver'} eq 'Tries') {
326: $analysis_html .= &RR_Tries_Analysis($r,$problem->{'resource'},
327: $PerformanceData,$ProblemData);
328: } elsif ($ENV{'form.AnalyzeOver'} eq 'Time') {
329: $analysis_html .= &RR_Time_Analysis($r,$problem->{'resource'},
330: $PerformanceData,$ProblemData);
331: } else {
332: $analysis_html .= '<h2>'.
333: &mt('The analysis you have selected is not supported at this time').
334: '</h2>';
335: }
336: $r->print($analysis_html);
337: }
338:
339: sub RR_Excel_output {
340: my ($r,$PerformanceData,$ProblemData) = @_;
341: return '<h1>No!</h1>';
342: }
343:
344: sub RR_Tries_Analysis {
345: my ($r,$resource,$PerformanceData,$ProblemData) = @_;
346: my $analysis_html;
347: my $mintries = 1;
348: my $maxtries = $ENV{'form.NumPlots'};
349: my ($table,$Foils,$Concepts) = &build_foil_index($ProblemData);
350: if ((! defined($Concepts)) || ((@$Concepts < 2) &&
351: ($ENV{'form.AnalyzeAs'} ne 'Foils'))) {
352: $table = '<h3>'.
353: &mt('Not enough data for concept analysis. '.
354: 'Performing Foil Analysis').
355: '</h3>'.$table;
356: $ENV{'form.AnalyzeAs'} = 'Foils';
357: }
358: $analysis_html .= $table;
359: my @TryData = &RR_tries_data_analysis($r,$PerformanceData);
360: # if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
361: $analysis_html .= &RR_Tries_Foil_Analysis($mintries,$maxtries,$Foils,
362: \@TryData,$ProblemData);
363: # } else {
364: # $analysis_html = &RR_Tries_Concept_Analysis($mintries,$maxtries,
365: # $Concepts,
366: # \@TryData,
367: # $ProblemData);
368: # }
369: return $analysis_html;
370: }
371:
372: sub RR_tries_data_analysis {
373: my ($r,$Attempt_data) = @_;
374: my @TryData;
375: foreach my $attempt (@$Attempt_data) {
376: my %Attempt = &hashify_attempt($attempt);
377: my ($answer,undef) = split('=',$Attempt{'submission'});
378: $TryData[$Attempt{'tries'}]->{$answer}++;
379: }
380: return @TryData;
381: }
382:
383: sub RR_Time_Analysis {
384: my ($r,$PerformanceData,$ProblemData) = @_;
385: my $html;
386: return $html;
387: }
388:
389: sub RR_Tries_Foil_Analysis {
390: my ($min,$max,$Foils,$TryData,$ProblemData) = @_;
391: my $html;
392: #
393: # Compute the data neccessary to make the plots
394: for (my $try=$min;$try<=$max;$try++) {
395: my @PlotData_Correct;
396: my @PlotData_Incorrect;
397: next if ($try > scalar(@{$TryData}));
398: next if (! defined($TryData->[$try]));
399: my %DataSet = %{$TryData->[$try]};
400: my $total = 0;
401: foreach my $foilid (@$Foils) {
402: $total += $DataSet{$foilid};
403: }
404: foreach my $foilid (@$Foils) {
405: if ($total == 0) {
406: push (@PlotData_Correct,0);
407: push (@PlotData_Incorrect,0);
408: } else {
409: if ($ProblemData->{'_Foils'}->{$foilid}->{'value'} eq 'true') {
410: push (@PlotData_Correct,
411: int(100*$DataSet{$foilid}/$total));
412: push (@PlotData_Incorrect,0);
413: } else {
414: push (@PlotData_Correct,0);
415: push (@PlotData_Incorrect,
416: int(100*$DataSet{$foilid}/$total));
417: }
418: }
419: }
420: my $title='Attempt '.$try;
421: my $xlabel = $total.' Submissions';
422: $html.= &Apache::loncommon::DrawBarGraph($title,
423: $xlabel,
424: 'Percent Choosing',
425: 100,
426: ['#33ff00','#ff3300'],
427: undef,
428: \@PlotData_Correct,
429: \@PlotData_Incorrect);
430: }
431: return $html;
432: }
433:
434: sub RR_Tries_Concept_Analysis {
435: my ($min,$max,$Concepts,$ResponseData,$ProblemData) = @_;
436: my $html;
437: return $html;
438: }
439:
440: sub RR_Time_Foil_Analysis {
441: my ($min,$max,$Foils,$ResponseData,$ProblemData) = @_;
442: my $html;
443: return $html;
444: }
445:
446: sub RR_Time_Concept_Analysis {
447: my ($min,$max,$Concepts,$ResponseData,$ProblemData) = @_;
448: my $html;
449: return $html;
450: }
451:
452:
453: sub get_Radio_problem_data {
454: my ($url) = @_;
455: my $Answ=&Apache::lonnet::ssi($url,('grade_target' => 'analyze'));
456: (my $garbage,$Answ)=split('_HASH_REF__',$Answ,2);
457: my %Answer = &Apache::lonnet::str2hash($Answ);
458: my %Partdata;
459: foreach my $part (@{$Answer{'parts'}}) {
460: while (my($key,$value) = each(%Answer)) {
461: # if (ref($value) eq 'ARRAY') {
462: # &Apache::lonnet::logthis('is ref part:'.$part.' '.$key.'='.join(',',@$value));
463: # } else {
464: # &Apache::lonnet::logthis('notref part:'.$part.' '.$key.'='.$value);
465: # }
466: next if ($key !~ /^$part/);
467: $key =~ s/^$part\.//;
468: if ($key eq 'foils') {
469: $Partdata{$part}->{'_Foils'}=$value;
470: } elsif ($key eq 'options') {
471: $Partdata{$part}->{'_Options'}=$value;
472: } elsif ($key eq 'shown') {
473: $Partdata{$part}->{'_Shown'}=$value;
474: } elsif ($key =~ /^foil.value.(.*)$/) {
475: $Partdata{$part}->{$1}->{'value'}=$value;
476: } elsif ($key =~ /^foil.text.(.*)$/) {
477: $Partdata{$part}->{$1}->{'text'}=$value;
478: }
479: }
480: }
481: return %Partdata;
482: }
483:
484: #########################################################
485: #########################################################
486: ##
487: ## Option Response Routines
488: ##
489: #########################################################
490: #########################################################
491: sub OptionResponseAnalysis {
492: my ($r,$problem,$ProblemData,$Students) = @_;
493: my ($resource,$respid) = ($problem->{'resource'},
494: $problem->{'respid'});
495: # Note: part data is not needed.
496: my $PerformanceData =
497: &Apache::loncoursedata::get_response_data
498: ($Students,$resource->{'symb'},$respid);
499: if (! defined($PerformanceData) ||
500: ref($PerformanceData) ne 'ARRAY' ) {
501: $r->print('<h2>'.
502: &mt('There is no student data for this problem.').
503: '</h2>');
504: } else {
505: $r->rflush();
506: if (exists($ENV{'form.ExcelOutput'})) {
507: my $result = &OR_excel_sheet($r,$resource,
508: $PerformanceData,
509: $ProblemData);
510: $r->print($result);
511: $r->rflush();
512: } else {
513: if ($ENV{'form.AnalyzeOver'} eq 'Tries') {
514: my $analysis_html = &OR_tries_analysis($r,
515: $PerformanceData,
516: $ProblemData);
517: $r->print($analysis_html);
518: $r->rflush();
519: } elsif ($ENV{'form.AnalyzeOver'} eq 'Time') {
520: my $analysis_html = &OR_time_analysis($PerformanceData,
521: $ProblemData);
522: $r->print($analysis_html);
523: $r->rflush();
524: } else {
525: $r->print('<h2>'.
526: &mt('The analysis you have selected is '.
527: 'not supported at this time').
528: '</h2>');
529: }
530: }
531: }
532: }
533:
534: #########################################################
535: #
536: # Option Response: Tries Analysis
537: #
538: #########################################################
539: sub OR_tries_analysis {
540: my ($r,$PerformanceData,$ORdata) = @_;
541: my $mintries = 1;
542: my $maxtries = $ENV{'form.NumPlots'};
543: my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
544: if ((@$Concepts < 2) && ($ENV{'form.AnalyzeAs'} ne 'Foils')) {
545: $table = '<h3>'.
546: &mt('Not enough data for concept analysis. '.
547: 'Performing Foil Analysis').
548: '</h3>'.$table;
549: $ENV{'form.AnalyzeAs'} = 'Foils';
550: }
551: my %ResponseData = &OR_analyze_by_tries($r,$PerformanceData,
552: $mintries,$maxtries);
553: my $analysis = '';
554: if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
555: $analysis = &OR_Tries_Foil_Analysis($mintries,$maxtries,$Concepts,
556: \%ResponseData,$ORdata);
557: } else {
558: $analysis = &OR_Tries_Concept_Analysis($mintries,$maxtries,
559: $Concepts,\%ResponseData,$ORdata);
560: }
561: $table .= $analysis;
562: return $table;
563: }
564:
565: sub OR_Tries_Foil_Analysis {
566: my ($mintries,$maxtries,$Concepts,$respdat,$ORdata) = @_;
567: my %ResponseData = %$respdat;
568: #
569: # Compute the data neccessary to make the plots
570: my @PlotData;
571: foreach my $concept (@$Concepts) {
572: foreach my $foilid (@{$concept->{'foils'}}) {
573: for (my $try=$mintries;$try<=$maxtries;$try++) {
574: if ($ResponseData{$foilid}->[$try]->{'_total'} == 0) {
575: push(@{$PlotData[$try]->{'_correct'}},0);
576: } else {
577: push(@{$PlotData[$try]->{'_correct'}},
578: 100*$ResponseData{$foilid}->[$try]->{'_correct'}/
579: $ResponseData{$foilid}->[$try]->{'_total'});
580: }
581: foreach my $option (@{$ORdata->{'_Options'}}) {
582: push(@{$PlotData[$try]->{'_total'}},
583: $ResponseData{$foilid}->[$try]->{'_total'});
584: if ($ResponseData{$foilid}->[$try]->{'_total'} == 0) {
585: push (@{$PlotData[$try]->{$option}},0);
586: } else {
587: if ($ResponseData{$foilid}->[$try]->{'_total'} ==
588: $ResponseData{$foilid}->[$try]->{'_correct'}) {
589: push(@{$PlotData[$try]->{$option}},0);
590: } else {
591: push (@{$PlotData[$try]->{$option}},
592: 100 *
593: $ResponseData{$foilid}->[$try]->{$option} /
594: ($ResponseData{$foilid}->[$try]->{'_total'}
595: -
596: $ResponseData{$foilid}->[$try]->{'_correct'}
597: ));
598: }
599: }
600: } # End of foreach my $option
601: }
602: } # End of foreach my $foilid
603: } # End of foreach my $concept
604: #
605: # Build a table for the plots
606: my $analysis_html = "<table>\n";
607: my $optionkey = &build_option_index($ORdata);
608: for (my $try=$mintries;$try<=$maxtries;$try++) {
609: my $count = $ResponseData{'_total'}->[$try];
610: my $title = 'Submission '.$try.' (N='.$count.')';
611: my @Datasets;
612: foreach my $option ('_correct',@{$ORdata->{'_Options'}}) {
613: next if (! exists($PlotData[$try]->{$option}));
614: push(@Datasets,$PlotData[$try]->{$option});
615: }
616: #
617: # Put a blank in the data set between concepts
618: for (my $set =0;$set<=$#Datasets;$set++) {
619: my @Data = @{$Datasets[$set]};
620: my $idx = 0;
621: foreach my $concept (@{$Concepts}) {
622: foreach my $foilid (@{$concept->{'foils'}}) {
623: $Datasets[$set]->[$idx++]=shift(@Data);
624: }
625: if ($concept->{'name'} ne $Concepts->[-1]->{'name'}) {
626: $Datasets[$set]->[$idx++] = 0;
627: }
628: }
629: }
630: #
631: # Set up the labels needed for the bar graph
632: my @Labels;
633: my $idx = 1;
634: foreach my $concept (@{$Concepts}) {
635: foreach my $foilid (@{$concept->{'foils'}}) {
636: push(@Labels,$idx++);
637: }
638: push(@Labels,'');
639: }
640: #
641: my $correctgraph = &Apache::loncommon::DrawBarGraph
642: ($title,'Foil Number','Percent Correct',
643: 100,$plotcolors,\@Labels,$Datasets[0]);
644: $analysis_html.= '<tr><td>'.$correctgraph.'</td>';
645:
646: #
647: #
648: next if (! defined($Datasets[0]));
649: for (my $i=0; $i< scalar(@{$Datasets[0]});$i++) {
650: $Datasets[0]->[$i]=0;
651: }
652: $count = $ResponseData{'_total'}->[$try] -
653: $ResponseData{'_correct'}->[$try];
654: $title = 'Submission '.$try.' (N='.$count.')';
655: my $incorrectgraph = &Apache::loncommon::DrawBarGraph
656: ($title,'Foil Number','% Option Chosen Incorrectly',
657: 100,$plotcolors,\@Labels,@Datasets);
658: $analysis_html.= '<td>'.$incorrectgraph.'</td>';
659: $analysis_html.= '<td>'.$optionkey."<td></tr>\n";
660: }
661: $analysis_html .= "</table>\n";
662: return $analysis_html;
663: }
664:
665: sub OR_Tries_Concept_Analysis {
666: my ($mintries,$maxtries,$Concepts,$respdat,$ORdata) = @_;
667: my %ResponseData = %$respdat;
668: my $analysis_html = "<table>\n";
669: #
670: # Compute the data neccessary to make the plots
671: my @PlotData;
672: # Concept analysis
673: #
674: # Note: we do not bother with characterizing the students incorrect
675: # answers at the concept level because an incorrect answer for one foil
676: # may be a correct answer for another foil.
677: my %ConceptData;
678: foreach my $concept (@{$Concepts}) {
679: for (my $i=$mintries;$i<=$maxtries;$i++) {
680: #
681: # Gather the per-attempt data
682: my $cdata = $ConceptData{$concept}->[$i];
683: foreach my $foilid (@{$concept->{'foils'}}) {
684: $cdata->{'_correct'} +=
685: $ResponseData{$foilid}->[$i]->{'_correct'};
686: $cdata->{'_total'} +=
687: $ResponseData{$foilid}->[$i]->{'_total'};
688: }
689: push (@{$PlotData[$i]->{'_total'}},$cdata->{'_total'});
690: if ($cdata->{'_total'} == 0) {
691: push (@{$PlotData[$i]->{'_correct'}},0);
692: } else {
693: push (@{$PlotData[$i]->{'_correct'}},
694: 100*$cdata->{'_correct'}/$cdata->{'_total'});
695: }
696: }
697: }
698: # Build a table for the plots
699: for (my $i=$mintries;$i<=$maxtries;$i++) {
700: my $minstu = $PlotData[$i]->{'_total'}->[0];
701: my $maxstu = $PlotData[$i]->{'_total'}->[0];
702: foreach my $count (@{$PlotData[$i]->{'_total'}}) {
703: if ($minstu > $count) {
704: $minstu = $count;
705: }
706: if ($maxstu < $count) {
707: $maxstu = $count;
708: }
709: }
710: $maxstu = 0 if (! defined($maxstu));
711: $minstu = 0 if (! defined($minstu));
712: my $title;
713: my $count = $ResponseData{'_total'}->[$i];
714: if ($count == 0) {
715: $count = 'no submissions';
716: } elsif ($count == 1) {
717: $count = '1 submission';
718: } else {
719: $count = $count.' submissions';
720: }
721: $title = 'Attempt '.$i.', '.$count;
722: my $graphlink = &Apache::loncommon::DrawBarGraph
723: ($title,'Concept Number','Percent Correct',
724: 100,$plotcolors,undef,$PlotData[$i]->{'_correct'});
725: $analysis_html.= '<tr><td>'.$graphlink."</td></tr>\n";
726: }
727: $analysis_html .= "</table>\n";
728: return $analysis_html;
729: }
730:
731: sub OR_analyze_by_tries {
732: my ($r,$PerformanceData,$mintries,$maxtries) = @_;
733: my %Trydata;
734: $mintries = 1 if (! defined($mintries) || $mintries < 1);
735: $maxtries = $mintries if (! defined($maxtries) || $maxtries < $mintries);
736: foreach my $row (@$PerformanceData) {
737: next if (! defined($row));
738: my $tries = &get_tries_from_row($row);
739: my %Row = &Process_OR_Row($row);
740: next if (! %Row);
741: while (my ($foilid,$href) = each(%Row)) {
742: if (! ref($href)) {
743: $Trydata{$foilid}->[$tries] += $href;
744: next;
745: }
746: while (my ($option,$value) = each(%$href)) {
747: $Trydata{$foilid}->[$tries]->{$option}+=$value;
748: }
749: }
750: }
751: return %Trydata;
752: }
753:
754: #########################################################
755: #
756: # Option Response: Time Analysis
757: #
758: #########################################################
759: sub OR_time_analysis {
760: my ($PerformanceData,$ORdata) = @_;
761: my ($table,$Foils,$Concepts) = &build_foil_index($ORdata);
762: if ((@$Concepts < 2) && ($ENV{'form.AnalyzeAs'} ne 'Foils')) {
763: $table = '<h3>'.
764: &mt('Not enough data for concept analysis. '.
765: 'Performing Foil Analysis').
766: '</h3>'.$table;
767: $ENV{'form.AnalyzeAs'} = 'Foils';
768: }
769: my $num_plots = $ENV{'form.NumPlots'};
770: my $num_data = scalar(@$PerformanceData)-1;
771: my $percent = sprintf('%2f',100/$num_plots);
772: #
773: $table .= "<table>\n";
774: for (my $i=0;$i<$num_plots;$i++) {
775: ##
776: my $starttime = &Apache::lonhtmlcommon::get_date_from_form
777: ('startdate_'.$i);
778: my $endtime = &Apache::lonhtmlcommon::get_date_from_form
779: ('enddate_'.$i);
780: if (! defined($starttime) || ! defined($endtime)) {
781: my $sec_in_day = 86400;
782: my $last_sub_time = &get_time_from_row($PerformanceData->[-1]);
783: my ($sday,$smon,$syear);
784: (undef,undef,undef,$sday,$smon,$syear) =
785: localtime($last_sub_time - $sec_in_day*$i);
786: $starttime = &Time::Local::timelocal(0,0,0,$sday,$smon,$syear);
787: $endtime = $starttime + $sec_in_day;
788: if ($i == ($num_plots -1 )) {
789: $starttime = &get_time_from_row($PerformanceData->[0]);
790: }
791: }
792: my $startdateform = &Apache::lonhtmlcommon::date_setter
793: ('Statistics','startdate_'.$i,$starttime);
794: my $enddateform = &Apache::lonhtmlcommon::date_setter
795: ('Statistics','enddate_'.$i,$endtime);
796: #
797: my $begin_index;
798: my $end_index;
799: my $j;
800: while (++$j < scalar(@$PerformanceData)) {
801: last if (&get_time_from_row($PerformanceData->[$j])
802: > $starttime);
803: }
804: $begin_index = $j;
805: while (++$j < scalar(@$PerformanceData)) {
806: last if (&get_time_from_row($PerformanceData->[$j]) > $endtime);
807: }
808: $end_index = $j;
809: ##
810: my $interval = {
811: begin_index => $begin_index,
812: end_index => $end_index,
813: startdateform => $startdateform,
814: enddateform => $enddateform,
815: };
816: if ($ENV{'form.AnalyzeAs'} eq 'Foils') {
817: $table .= &OR_Foil_Time_Analysis($PerformanceData,$ORdata,$Foils,
818: $interval);
819: } else {
820: $table .= &OR_Concept_Time_Analysis($PerformanceData,$ORdata,
821: $Concepts,$interval);
822: }
823: }
824: #
825: return $table;
826: }
827:
828: sub OR_Foil_Time_Analysis {
829: my ($PerformanceData,$ORdata,$Foils,$interval) = @_;
830: my $analysis_html;
831: my $foilkey = &build_option_index($ORdata);
832: my ($begin_index,$end_index) = ($interval->{'begin_index'},
833: $interval->{'end_index'});
834: my %TimeData;
835: #
836: # Compute the number getting the foils correct or incorrects
837: for (my $j=$begin_index;$j<=$end_index;$j++) {
838: my $row = $PerformanceData->[$j];
839: next if (! defined($row));
840: my %Row = &Process_OR_Row($row);
841: while (my ($foilid,$href) = each(%Row)) {
842: if (! ref($href)) {
843: $TimeData{$foilid} += $href;
844: next;
845: }
846: while (my ($option,$value) = each(%$href)) {
847: $TimeData{$foilid}->{$option}+=$value;
848: }
849: }
850: }
851: my @Plotdata;
852: foreach my $foil (@$Foils) {
853: my $total = $TimeData{$foil}->{'_total'};
854: if ($total == 0) {
855: push(@{$Plotdata[0]},0);
856: } else {
857: push(@{$Plotdata[0]},
858: 100 * $TimeData{$foil}->{'_correct'} / $total);
859: }
860: my $total_incorrect = $total - $TimeData{$foil}->{'_correct'};
861: my $optionidx = 1;
862: foreach my $option (@{$ORdata->{'_Options'}}) {
863: if ($total_incorrect == 0) {
864: push(@{$Plotdata[$optionidx]},0);
865: } else {
866: push(@{$Plotdata[$optionidx]},
867: 100 * $TimeData{$foil}->{$option} / $total_incorrect);
868: }
869: } continue {
870: $optionidx++;
871: }
872: }
873: #
874: # Create the plot
875: my $count = $end_index-$begin_index;
876: my $title;
877: if ($count == 0) {
878: $title = 'no submissions';
879: } elsif ($count == 1) {
880: $title = 'one submission';
881: } else {
882: $title = $count.' submissions';
883: }
884: my $correctplot = &Apache::loncommon::DrawBarGraph($title,
885: 'Foil Number',
886: 'Percent Correct',
887: 100,
888: $plotcolors,
889: undef,
890: $Plotdata[0]);
891: for (my $j=0; $j< scalar(@{$Plotdata[0]});$j++) {
892: $Plotdata[0]->[$j]=0;
893: }
894: $count = $end_index-$begin_index-$TimeData{'_correct'};
895: if ($count == 0) {
896: $title = 'no submissions';
897: } elsif ($count == 1) {
898: $title = 'one submission';
899: } else {
900: $title = $count.' submissions';
901: }
902: my $incorrectplot = &Apache::loncommon::DrawBarGraph($title,
903: 'Foil Number',
904: 'Incorrect Option Choice',
905: 100,
906: $plotcolors,
907: undef,
908: @Plotdata);
909: $analysis_html.='<tr>'.
910: '<td>'.$correctplot.'</td>'.
911: '<td>'.$incorrectplot.'</td>'.
912: '<td align="left" valign="top">'.$foilkey.'</td>'."</tr>\n";
913: $analysis_html.= '<tr>'.'<td colspan="3">'.
914: '<b>Start Time</b>:'.
915: ' '.$interval->{'startdateform'}.'<br />'.
916: '<b>End Time</b> : '.
917: ' '.$interval->{'enddateform'}.'<br />'.
918: # '<b>Plot Title</b> :'.
919: # (" "x3).$interval->{'titleform'}.
920: '</td>'.
921: "</tr>\n";
922: return $analysis_html;
923: }
924:
925: sub OR_Concept_Time_Analysis {
926: my ($PerformanceData,$ORdata,$Concepts,$interval) = @_;
927: my $analysis_html;
928: ##
929: ## Determine starttime, endtime, startindex, endindex
930: my ($begin_index,$end_index) = ($interval->{'begin_index'},
931: $interval->{'end_index'});
932: my %TimeData;
933: #
934: # Compute the number getting the foils correct or incorrects
935: for (my $j=$begin_index;$j<=$end_index;$j++) {
936: my $row = $PerformanceData->[$j];
937: next if (! defined($row));
938: my %Row = &Process_OR_Row($row);
939: while (my ($foilid,$href) = each(%Row)) {
940: if (! ref($href)) {
941: $TimeData{$foilid} += $href;
942: next;
943: }
944: while (my ($option,$value) = each(%$href)) {
945: $TimeData{$foilid}->{$option}+=$value;
946: }
947: }
948: }
949: #
950: # Put the data in plottable form
951: my @Plotdata;
952: foreach my $concept (@$Concepts) {
953: my ($total,$correct);
954: foreach my $foil (@{$concept->{'foils'}}) {
955: $total += $TimeData{$foil}->{'_total'};
956: $correct += $TimeData{$foil}->{'_correct'};
957: }
958: if ($total == 0) {
959: push(@Plotdata,0);
960: } else {
961: push(@Plotdata,100 * $correct / $total);
962: }
963: }
964: #
965: # Create the plot
966: my $title = ($end_index - $begin_index).' submissions';
967: my $correctplot = &Apache::loncommon::DrawBarGraph($title,
968: 'Concept Number',
969: 'Percent Correct',
970: 100,
971: $plotcolors,
972: undef,
973: \@Plotdata);
974: $analysis_html.='<tr>'.
975: '<td>'.$correctplot.'</td>'.
976: '<td align="left" valign="top">'.
977: '<b>Start Time</b>: '.$interval->{'startdateform'}.'<br />'.
978: '<b>End Time</b> : '.
979: ' '.$interval->{'enddateform'}.'<br />'.
980: # '<b>Plot Title</b> :'.(" "x3).
981: # $interval->{'titleform'}.
982: '</td>'.
983: "</tr>\n";
984: return $analysis_html;
985: }
986:
987: #########################################################
988: #########################################################
989: ##
990: ## Excel output
991: ##
992: #########################################################
993: #########################################################
994: sub OR_excel_sheet {
995: my ($r,$resource,$PerformanceData,$ORdata) = @_;
996: my $response = '';
997: my (undef,$Foils,$Concepts) = &build_foil_index($ORdata);
998: #
999: # Create excel worksheet
1000: my $filename = '/prtspool/'.
1001: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
1002: time.'_'.rand(1000000000).'.xls';
1003: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1004: if (! defined($workbook)) {
1005: $r->log_error("Error creating excel spreadsheet $filename: $!");
1006: $r->print('<p>'.&mt("Unable to create new Excel file. ".
1007: "This error has been logged. ".
1008: "Please alert your LON-CAPA administrator").
1009: '</p>');
1010: return undef;
1011: }
1012: #
1013: $workbook->set_tempdir('/home/httpd/perl/tmp');
1014: my $format = &Apache::loncommon::define_excel_formats($workbook);
1015: #
1016: # Create and populate main worksheets
1017: my $problem_data_sheet = $workbook->addworksheet('Problem Data');
1018: my $student_data_sheet = &build_student_data_worksheet($workbook,$format);
1019: my $response_data_sheet = $workbook->addworksheet('Response Data');
1020: foreach my $sheet ($problem_data_sheet,$student_data_sheet,
1021: $response_data_sheet) {
1022: $sheet->write(0,0,$resource->{'title'},$format->{'h2'});
1023: $sheet->write(1,0,$resource->{'src'},$format->{'h3'});
1024: }
1025: #
1026: my $result;
1027: $result = &OR_build_problem_data_worksheet($problem_data_sheet,$format,
1028: $Concepts,$ORdata);
1029: if ($result ne 'okay') {
1030: # Do something useful
1031: }
1032: $result = &OR_build_response_data_worksheet($response_data_sheet,$format,
1033: $PerformanceData,$Foils,
1034: $ORdata);
1035: if ($result ne 'okay') {
1036: # Do something useful
1037: }
1038: $response_data_sheet->activate();
1039: #
1040: # Close the excel file
1041: $workbook->close();
1042: #
1043: # Write a link to allow them to download it
1044: $result .= '<h2>'.&mt('Excel Raw Data Output').'</h2>'.
1045: '<p><a href="'.$filename.'">'.
1046: &mt('Your Excel spreadsheet.').
1047: '</a></p>'."\n";
1048: return $result;
1049: }
1050:
1051: sub OR_build_problem_data_worksheet {
1052: my ($worksheet,$format,$Concepts,$ORdata) = @_;
1053: my $rows_output = 3;
1054: my $cols_output = 0;
1055: $worksheet->write($rows_output++,0,'Problem Structure',$format->{'h3'});
1056: ##
1057: ##
1058: my @Headers;
1059: if (@$Concepts > 1) {
1060: @Headers = ("Concept\nNumber",'Concept',"Foil\nNumber",
1061: 'Foil Name','Foil Text','Correct value');
1062: } else {
1063: @Headers = ('Foil Number','FoilName','Foil Text','Correct value');
1064: }
1065: $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
1066: my %Foildata = %{$ORdata->{'_Foils'}};
1067: my $conceptindex = 1;
1068: my $foilindex = 1;
1069: foreach my $concept (@$Concepts) {
1070: my @FoilsInConcept = @{$concept->{'foils'}};
1071: my $firstfoil = shift(@FoilsInConcept);
1072: if (@$Concepts > 1) {
1073: $worksheet->write_row($rows_output++,0,
1074: [$conceptindex,
1075: $concept->{'name'},
1076: $foilindex++,
1077: $Foildata{$firstfoil}->{'name'},
1078: $Foildata{$firstfoil}->{'text'},
1079: $Foildata{$firstfoil}->{'value'},]);
1080: } else {
1081: $worksheet->write_row($rows_output++,0,
1082: [ $foilindex++,
1083: $Foildata{$firstfoil}->{'name'},
1084: $Foildata{$firstfoil}->{'text'},
1085: $Foildata{$firstfoil}->{'value'},]);
1086: }
1087: foreach my $foilid (@FoilsInConcept) {
1088: if (@$Concepts > 1) {
1089: $worksheet->write_row($rows_output++,0,
1090: ['',
1091: '',
1092: $foilindex,
1093: $Foildata{$foilid}->{'name'},
1094: $Foildata{$foilid}->{'text'},
1095: $Foildata{$foilid}->{'value'},]);
1096: } else {
1097: $worksheet->write_row($rows_output++,0,
1098: [$foilindex,
1099: $Foildata{$foilid}->{'name'},
1100: $Foildata{$foilid}->{'text'},
1101: $Foildata{$foilid}->{'value'},]);
1102: }
1103: } continue {
1104: $foilindex++;
1105: }
1106: } continue {
1107: $conceptindex++;
1108: }
1109: $rows_output++;
1110: $rows_output++;
1111: ##
1112: ## Option data output
1113: $worksheet->write($rows_output++,0,'Options',$format->{'header'});
1114: foreach my $string (@{$ORdata->{'_Options'}}) {
1115: $worksheet->write($rows_output++,0,$string);
1116: }
1117: return 'okay';
1118: }
1119:
1120: sub OR_build_response_data_worksheet {
1121: my ($worksheet,$format,$PerformanceData,$Foils,$ORdata)=@_;
1122: my $rows_output = 3;
1123: my $cols_output = 0;
1124: $worksheet->write($rows_output++,0,'Response Data',$format->{'h3'});
1125: $worksheet->set_column(1,1,20);
1126: $worksheet->set_column(2,2,13);
1127: my @Headers = ('identifier','time','award detail','attempt');
1128: foreach my $foil (@$Foils) {
1129: push (@Headers,$foil.' submission');
1130: push (@Headers,$foil.' grading');
1131: }
1132: $worksheet->write_row($rows_output++,0,\@Headers,$format->{'header'});
1133: #
1134: foreach my $row (@$PerformanceData) {
1135: next if (! defined($row));
1136: my ($student,$award,$grading,$submission,$time,$tries) = @$row;
1137: my @Foilgrades = split('&',$grading);
1138: my @Foilsubs = split('&',$submission);
1139: my %ResponseData;
1140: for (my $j=0;$j<=$#Foilgrades;$j++) {
1141: my ($foilid,$correct) = split('=',$Foilgrades[$j]);
1142: my (undef,$submission) = split('=',$Foilsubs[$j]);
1143: $submission = &Apache::lonnet::unescape($submission);
1144: $ResponseData{$foilid.' submission'}=$submission;
1145: $ResponseData{$foilid.' award'}=$correct;
1146: }
1147: $worksheet->write($rows_output,$cols_output++,$student);
1148: $worksheet->write($rows_output,$cols_output++,
1149: &Apache::lonstathelpers::calc_serial($time),$format->{'date'});
1150: $worksheet->write($rows_output,$cols_output++,$award);
1151: $worksheet->write($rows_output,$cols_output++,$tries);
1152: foreach my $foilid (@$Foils) {
1153: $worksheet->write($rows_output,$cols_output++,
1154: $ResponseData{$foilid.' submission'});
1155: $worksheet->write($rows_output,$cols_output++,
1156: $ResponseData{$foilid.' award'});
1157: }
1158: $rows_output++;
1159: $cols_output = 0;
1160: }
1161: return;
1162: }
1163:
1164: sub build_foil_index {
1165: my ($ORdata) = @_;
1166: return if (! exists($ORdata->{'_Foils'}));
1167: my %Foildata = %{$ORdata->{'_Foils'}};
1168: my @Foils = sort(keys(%Foildata));
1169: my %Concepts;
1170: foreach my $foilid (@Foils) {
1171: push(@{$Concepts{$Foildata{$foilid}->{'_Concept'}}},
1172: $foilid);
1173: }
1174: undef(@Foils);
1175: # Having gathered the concept information in a hash, we now translate it
1176: # into an array because we need to be consistent about order.
1177: # Also put the foils in order, too.
1178: my $sortfunction = sub {
1179: my %Numbers = (one => 1,
1180: two => 2,
1181: three => 3,
1182: four => 4,
1183: five => 5,
1184: six => 6,
1185: seven => 7,
1186: eight => 8,
1187: nine => 9,
1188: ten => 10,);
1189: my $a1 = lc($a);
1190: my $b1 = lc($b);
1191: if (exists($Numbers{$a1})) {
1192: $a1 = $Numbers{$a1};
1193: }
1194: if (exists($Numbers{$b1})) {
1195: $b1 = $Numbers{$b1};
1196: }
1197: if (($a1 =~/^\d+$/) && ($b1 =~/^\d+$/)) {
1198: return $a1 <=> $b1;
1199: } else {
1200: return $a1 cmp $b1;
1201: }
1202: };
1203: my @Concepts;
1204: foreach my $concept (sort $sortfunction (keys(%Concepts))) {
1205: if (! defined($Concepts{$concept})) {
1206: $Concepts{$concept}=[];
1207: # next;
1208: }
1209: push(@Concepts,{ name => $concept,
1210: foils => [@{$Concepts{$concept}}]});
1211: push(@Foils,(@{$Concepts{$concept}}));
1212: }
1213: #
1214: # Build up the table of row labels.
1215: my $table = '<table border="1" >'."\n";
1216: if (@Concepts > 1) {
1217: $table .= '<tr>'.
1218: '<th>'.&mt('Concept Number').'</th>'.
1219: '<th>'.&mt('Concept').'</th>'.
1220: '<th>'.&mt('Foil Number').'</th>'.
1221: '<th>'.&mt('Foil Name').'</th>'.
1222: '<th>'.&mt('Foil Text').'</th>'.
1223: '<th>'.&mt('Correct Value').'</th>'.
1224: "</tr>\n";
1225: } else {
1226: $table .= '<tr>'.
1227: '<th>'.&mt('Foil Number').'</th>'.
1228: '<th>'.&mt('Foil Name').'</th>'.
1229: '<th>'.&mt('Foil Text').'</th>'.
1230: '<th>'.&mt('Correct Value').'</th>'.
1231: "</tr>\n";
1232: }
1233: my $conceptindex = 1;
1234: my $foilindex = 1;
1235: foreach my $concept (@Concepts) {
1236: my @FoilsInConcept = @{$concept->{'foils'}};
1237: my $firstfoil = shift(@FoilsInConcept);
1238: if (@Concepts > 1) {
1239: $table .= '<tr>'.
1240: '<td>'.$conceptindex.'</td>'.
1241: '<td>'.&HTML::Entities::encode($concept->{'name'}).'</td>'.
1242: '<td>'.$foilindex++.'</td>'.
1243: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'}).'</td>'.
1244: '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
1245: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'}).'</td>'.
1246: "</tr>\n";
1247: } else {
1248: $table .= '<tr>'.
1249: '<td>'.$foilindex++.'</td>'.
1250: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'name'}).'</td>'.
1251: '<td>'.$Foildata{$firstfoil}->{'text'}.'</td>'.
1252: '<td>'.&HTML::Entities::encode($Foildata{$firstfoil}->{'value'}).'</td>'.
1253: "</tr>\n";
1254: }
1255: foreach my $foilid (@FoilsInConcept) {
1256: if (@Concepts > 1) {
1257: $table .= '<tr>'.
1258: '<td></td>'.
1259: '<td></td>'.
1260: '<td>'.$foilindex.'</td>'.
1261: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'name'}).'</td>'.
1262: '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
1263: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'value'}).'</td>'.
1264: "</tr>\n";
1265: } else {
1266: $table .= '<tr>'.
1267: '<td>'.$foilindex.'</td>'.
1268: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'name'}).'</td>'.
1269: '<td>'.$Foildata{$foilid}->{'text'}.'</td>'.
1270: '<td>'.&HTML::Entities::encode($Foildata{$foilid}->{'value'}).'</td>'.
1271: "</tr>\n";
1272: }
1273: } continue {
1274: $foilindex++;
1275: }
1276: } continue {
1277: $conceptindex++;
1278: }
1279: $table .= "</table>\n";
1280: #
1281: # Build option index with color stuff
1282: return ($table,\@Foils,\@Concepts);
1283: }
1284:
1285: sub build_option_index {
1286: my ($ORdata)= @_;
1287: my $table = "<table>\n";
1288: my $optionindex = 0;
1289: my @Rows;
1290: foreach my $option (&mt('correct option chosen'),@{$ORdata->{'_Options'}}) {
1291: push (@Rows,
1292: '<tr>'.
1293: '<td bgcolor="'.$plotcolors->[$optionindex++].'">'.
1294: (' 'x4).'</td>'.
1295: '<td>'.&HTML::Entities::encode($option).'</td>'.
1296: "</tr>\n");
1297: }
1298: shift(@Rows); # Throw away 'correct option chosen' color
1299: $table .= join('',reverse(@Rows));
1300: $table .= "</table>\n";
1301: }
1302:
1303: #########################################################
1304: #########################################################
1305: ##
1306: ## Generic Interface Routines
1307: ##
1308: #########################################################
1309: #########################################################
1310: sub CreateInterface {
1311: ##
1312: ## Environment variable initialization
1313: if (! exists$ENV{'form.AnalyzeOver'}) {
1314: $ENV{'form.AnalyzeOver'} = 'Tries';
1315: }
1316: ##
1317: ## Build the menu
1318: my $Str = '';
1319: $Str .= &Apache::lonhtmlcommon::breadcrumbs
1320: (undef,'Detailed Problem Analysis');
1321: $Str .= '<table cellspacing="5">'."\n";
1322: $Str .= '<tr>';
1323: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
1324: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
1325: # $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
1326: $Str .= '<td align="center"> </td>';
1327: $Str .= '</tr>'."\n";
1328: ##
1329: ##
1330: $Str .= '<tr><td align="center">'."\n";
1331: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1332: $Str .= '</td>';
1333: #
1334: $Str .= '<td align="center">';
1335: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1336: $Str .= '</td>';
1337: #
1338: # $Str .= '<td align="center">';
1339: my $only_seq_with_assessments = sub {
1340: my $s=shift;
1341: if ($s->{'num_assess'} < 1) {
1342: return 0;
1343: } else {
1344: return 1;
1345: }
1346: };
1347: &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
1348: $only_seq_with_assessments);
1349: ##
1350: ##
1351: $Str .= '<td>';
1352: { # These braces are here to organize the code, not scope it.
1353: {
1354: $Str .= '<nobr>'.&mt('Analyze Over ');
1355: $Str .= &Apache::loncommon::help_open_topic
1356: ('Analysis_Analyze_Over');
1357: $Str .='<select name="AnalyzeOver" >';
1358: $Str .= '<option value="Tries" ';
1359: if (! exists($ENV{'form.AnalyzeOver'}) ||
1360: $ENV{'form.AnalyzeOver'} eq 'Tries'){
1361: # Default to Tries
1362: $Str .= ' selected ';
1363: }
1364: $Str .= '>'.&mt('Tries').'</option>';
1365: $Str .= '<option value="Time" ';
1366: $Str .= ' selected ' if ($ENV{'form.AnalyzeOver'} eq 'Time');
1367: $Str .= '>'.&mt('Time').'</option>';
1368: $Str .= '</select>';
1369: $Str .= '</nobr><br />';
1370: }
1371: {
1372: $Str .= '<nobr>'.&mt('Analyze as ');
1373: $Str .= &Apache::loncommon::help_open_topic
1374: ('Analysis_Analyze_as');
1375: $Str .='<select name="AnalyzeAs" >';
1376: $Str .= '<option value="Concepts" ';
1377: if (! exists($ENV{'form.AnalyzeAs'}) ||
1378: $ENV{'form.AnalyzeAs'} eq 'Concepts'){
1379: # Default to Concepts
1380: $Str .= ' selected ';
1381: }
1382: $Str .= '>'.&mt('Concepts').'</option>';
1383: $Str .= '<option value="Foils" ';
1384: $Str .= ' selected ' if ($ENV{'form.AnalyzeAs'} eq 'Foils');
1385: $Str .= '>'.&mt('Foils').'</option>';
1386: $Str .= '</select></nobr><br />';
1387: }
1388: {
1389: $Str .= '<br /><nobr>'.&mt('Number of Plots:');
1390: $Str .= &Apache::loncommon::help_open_topic
1391: ('Analysis_num_plots');
1392: $Str .= '<select name="NumPlots">';
1393: if (! exists($ENV{'form.NumPlots'})
1394: || $ENV{'form.NumPlots'} < 1
1395: || $ENV{'form.NumPlots'} > 20) {
1396: $ENV{'form.NumPlots'} = 5;
1397: }
1398: foreach my $i (1,2,3,4,5,6,7,8,10,15,20) {
1399: $Str .= '<option value="'.$i.'" ';
1400: if ($ENV{'form.NumPlots'} == $i) { $Str.=' selected '; }
1401: $Str .= '>'.$i.'</option>';
1402: }
1403: $Str .= '</select></nobr>';
1404: }
1405: }
1406: $Str .= '</td>';
1407: ##
1408: ##
1409: $Str .= '</tr>'."\n";
1410: $Str .= '</table>'."\n";
1411: return $Str;
1412: }
1413:
1414: #########################################################
1415: #########################################################
1416: ##
1417: ## Misc Option Response functions
1418: ##
1419: #########################################################
1420: #########################################################
1421: sub get_time_from_row {
1422: my ($row) = @_;
1423: if (ref($row)) {
1424: return $row->[&Apache::loncoursedata::RD_timestamp()];
1425: }
1426: return undef;
1427: }
1428:
1429: sub get_tries_from_row {
1430: my ($row) = @_;
1431: if (ref($row)) {
1432: return $row->[&Apache::loncoursedata::RD_tries()];
1433: }
1434: return undef;
1435: }
1436:
1437: sub hashify_attempt {
1438: my ($row) = @_;
1439: my %attempt;
1440: $attempt{'tries'} = $row->[&Apache::loncoursedata::RD_tries()];
1441: $attempt{'submission'} = $row->[&Apache::loncoursedata::RD_submission()];
1442: $attempt{'award'} = $row->[&Apache::loncoursedata::RD_awarddetail()];
1443: $attempt{'timestamp'} = $row->[&Apache::loncoursedata::RD_timestamp()];
1444: return %attempt;
1445: }
1446:
1447: sub Process_OR_Row {
1448: my ($row) = @_;
1449: my %RowData;
1450: my $student_id = $row->[&Apache::loncoursedata::RD_student_id()];
1451: my $award = $row->[&Apache::loncoursedata::RD_awarddetail()];
1452: my $grading = $row->[&Apache::loncoursedata::RD_response_eval()];
1453: my $submission = $row->[&Apache::loncoursedata::RD_submission()];
1454: my $time = $row->[&Apache::loncoursedata::RD_timestamp()];
1455: my $tries = $row->[&Apache::loncoursedata::RD_tries()];
1456: return undef if ($award eq 'MISSING_ANSWER');
1457: if ($award =~ /(APPROX_ANS|EXACT_ANS)/) {
1458: $RowData{'_correct'} = 1;
1459: }
1460: $RowData{'_total'} = 1;
1461: my @Foilgrades = split('&',$grading);
1462: my @Foilsubs = split('&',$submission);
1463: for (my $j=0;$j<=$#Foilgrades;$j++) {
1464: my ($foilid,$correct) = split('=',$Foilgrades[$j]);
1465: $foilid = &Apache::lonnet::unescape($foilid);
1466: my (undef,$submission) = split('=',$Foilsubs[$j]);
1467: if ($correct) {
1468: $RowData{$foilid}->{'_correct'}++;
1469: } else {
1470: $submission = &Apache::lonnet::unescape($submission);
1471: $RowData{$foilid}->{$submission}++;
1472: }
1473: $RowData{$foilid}->{'_total'}++;
1474: }
1475: return %RowData;
1476: }
1477:
1478: 1;
1479:
1480: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>