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