1: # The LearningOnline Network with CAPA
2: #
3: # $Id: lonproblemstatistics.pm,v 1.62 2003/12/08 19:37:44 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: # (Navigate problems for statistical reports
28: #
29: ###############################################
30: ###############################################
31:
32: =pod
33:
34: =head1 NAME
35:
36: lonproblemstatistics
37:
38: =head1 SYNOPSIS
39:
40: Routines to present problem statistics to instructors via tables,
41: Excel files, and plots.
42:
43: =over 4
44:
45: =cut
46:
47: ###############################################
48: ###############################################
49:
50: package Apache::lonproblemstatistics;
51:
52: use strict;
53: use Apache::lonnet();
54: use Apache::loncommon();
55: use Apache::lonhtmlcommon;
56: use Apache::loncoursedata;
57: use Apache::lonstatistics;
58: use Apache::lonlocal;
59: use Spreadsheet::WriteExcel;
60:
61: ##
62: ## Localization notes:
63: ##
64: ## in @Fields[0]->{'long_title'} is placed in Excel files and is used as the
65: ## header for plots created with Graph.pm, both of which more than likely do
66: ## not support localization.
67: ##
68: my @Fields = (
69: { name => 'problem_num',
70: title => 'P#',
71: align => 'right',
72: color => '#FFFFE6' },
73: { name => 'container',
74: title => 'Sequence or Folder',
75: align => 'left',
76: color => '#FFFFE6',
77: sortable => 'yes' },
78: { name => 'title',
79: title => 'Title',
80: align => 'left',
81: color => '#FFFFE6',
82: special => 'link',
83: sortable => 'yes', },
84: { name => 'part',
85: title => 'Part',
86: align => 'left',
87: color => '#FFFFE6',
88: },
89: { name => 'num_students',
90: title => '#Stdnts',
91: align => 'right',
92: color => '#EEFFCC',
93: format => '%d',
94: sortable => 'yes',
95: graphable => 'yes',
96: long_title => 'Number of Students Attempting Problem' },
97: { name => 'tries',
98: title => 'Tries',
99: align => 'right',
100: color => '#EEFFCC',
101: format => '%d',
102: sortable => 'yes',
103: graphable => 'yes',
104: long_title => 'Total Number of Tries' },
105: { name => 'max_tries',
106: title => 'Max Tries',
107: align => 'right',
108: color => '#DDFFFF',
109: format => '%d',
110: sortable => 'yes',
111: graphable => 'yes',
112: long_title => 'Maximum Number of Tries' },
113: { name => 'mean_tries',
114: title => 'Mean Tries',
115: align => 'right',
116: color => '#DDFFFF',
117: format => '%5.2f',
118: sortable => 'yes',
119: graphable => 'yes',
120: long_title => 'Average Number of Tries' },
121: { name => 'std_tries',
122: title => 'S.D. tries',
123: align => 'right',
124: color => '#DDFFFF',
125: format => '%5.2f',
126: sortable => 'yes',
127: graphable => 'yes',
128: long_title => 'Standard Deviation of Number of Tries' },
129: { name => 'skew_tries',
130: title => 'Skew Tries',
131: align => 'right',
132: color => '#DDFFFF',
133: format => '%5.2f',
134: sortable => 'yes',
135: graphable => 'yes',
136: long_title => 'Skew of Number of Tries' },
137: { name => 'deg_of_diff',
138: title => 'DoDiff',
139: align => 'right',
140: color => '#DDFFFF',
141: format => '%5.2f',
142: sortable => 'yes',
143: graphable => 'yes',
144: long_title => 'Degree of Difficulty'.
145: '[ 1 - ((#YES+#yes) / Tries) ]'},
146: { name => 'num_solved',
147: title => '#YES',
148: align => 'right',
149: color => '#FFDDDD',
150: format => '%d',
151: sortable => 'yes',
152: graphable => 'yes',
153: long_title => 'Number of Students able to Solve' },
154: { name => 'num_override',
155: title => '#yes',
156: align => 'right',
157: color => '#FFDDDD',
158: format => '%d',
159: sortable => 'yes',
160: graphable => 'yes',
161: long_title => 'Number of Students given Override' },
162: { name => 'per_wrong',
163: title => '%Wrng',
164: align => 'right',
165: color => '#FFFFE6',
166: format => '%4.1f',
167: sortable => 'yes',
168: graphable => 'yes',
169: long_title => 'Percent of students whose final answer is wrong' },
170: );
171:
172: ###############################################
173: ###############################################
174:
175: =pod
176:
177: =item &CreateInterface()
178:
179: Create the main intereface for the statistics page. Allows the user to
180: select sections, maps, and output.
181:
182: =cut
183:
184: ###############################################
185: ###############################################
186: my @OutputOptions =
187: (
188: { name => 'problem statistics grouped by sequence',
189: value => 'HTML problem statistics grouped',
190: description => 'Output statistics for the problem parts.',
191: mode => 'html',
192: show => 'grouped',
193: },
194: { name => 'problem statistics ungrouped',
195: value => 'HTML problem statistics ungrouped',
196: description => 'Output statistics for the problem parts.',
197: mode => 'html',
198: show => 'ungrouped',
199: },
200: { name => 'problem statistics, Excel',
201: value => 'Excel problem statistics',
202: description => 'Output statistics for the problem parts '.
203: 'in an Excel workbook',
204: mode => 'excel',
205: show => 'all',
206: },
207: );
208:
209: sub CreateInterface {
210: my $Str = '';
211: $Str .= '<table cellspacing="5">'."\n";
212: $Str .= '<tr>';
213: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
214: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
215: $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
216: $Str .= '<td align="center"><b>'.&mt('Output').'</b></td>';
217: $Str .= '</tr>'."\n";
218: #
219: $Str .= '<tr><td align="center">'."\n";
220: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
221: $Str .= '</td><td align="center">';
222: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
223: $Str .= '</td><td align="center">';
224: #
225: my $only_seq_with_assessments = sub {
226: my $s=shift;
227: if ($s->{'num_assess'} < 1) {
228: return 0;
229: } else {
230: return 1;
231: }
232: };
233: $Str .= &Apache::lonstatistics::MapSelect('Maps','multiple,all',5,
234: $only_seq_with_assessments);
235: $Str .= '</td><td>'."\n";
236: my ($html,$outputmode,$show) =
237: &Apache::lonstatistics::CreateAndParseOutputSelector(
238: 'statsoutputmode',
239: 'HTML problem statistics grouped',
240: @OutputOptions);
241: $Str .= $html;
242: $Str .= '</td></tr>'."\n";
243: $Str .= '</table>'."\n";
244: $Str .= '<input type="submit" name="GenerateStatistics" value="'.
245: &mt('Generate Statistics').'" />';
246: $Str .= ' 'x5;
247: $Str .= '<input type="submit" name="ClearCache" value="'.
248: &mt('Clear Caches').'" />';
249: $Str .= ' 'x5;
250: return ($Str,$outputmode,$show);
251: }
252:
253: ###############################################
254: ###############################################
255:
256: =pod
257:
258: =item &BuildProblemStatisticsPage()
259:
260: Main interface to problem statistics.
261:
262: =cut
263:
264: ###############################################
265: ###############################################
266: sub BuildProblemStatisticsPage {
267: my ($r,$c)=@_;
268: #
269: my %Saveable_Parameters = ('Status' => 'scalar',
270: 'statsoutputmode' => 'scalar',
271: 'Section' => 'array',
272: 'StudentData' => 'array',
273: 'Maps' => 'array');
274: &Apache::loncommon::store_course_settings('statistics',
275: \%Saveable_Parameters);
276: &Apache::loncommon::restore_course_settings('statistics',
277: \%Saveable_Parameters);
278: #
279: &Apache::lonstatistics::PrepareClasslist();
280: #
281: my ($interface,$output_mode,$show) = &CreateInterface();
282: $r->print($interface);
283: $r->print('<input type="hidden" name="statsfirstcall" value="no" />');
284: $r->print('<input type="hidden" name="sortby" value="'.$ENV{'form.sortby'}.
285: '" />');
286: $r->print('<input type="hidden" name="plot" value="" />');
287: if (! exists($ENV{'form.statsfirstcall'})) {
288: return;
289: }
290: #
291: &Apache::lonstatistics::Gather_Student_Data($r);
292: #
293: #
294: if ($output_mode eq 'html') {
295: $r->print("<h2>".
296: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.
297: "</h2>\n");
298: $r->print("<h3>".localtime(time)."</h3>");
299: $r->rflush();
300: if ($show eq 'grouped') {
301: &output_html_grouped_by_sequence($r);
302: } elsif ($show eq 'ungrouped') {
303: &output_html_ungrouped($r);
304: }
305: } elsif ($output_mode eq 'excel') {
306: $r->print('<h2>'.&mt('Preparing Excel Spreadsheet').'</h2>');
307: &output_excel($r);
308: } else {
309: $r->print('<h1>'.&mt('Not implemented').'</h1>');
310: }
311: return;
312: }
313:
314: ###############################################
315: ###############################################
316:
317: =pod
318:
319: =item &output_html_grouped_by_sequence()
320:
321: Presents the statistics data as an html table organized by the order
322: the assessments appear in the course.
323:
324: =cut
325:
326: ###############################################
327: ###############################################
328: sub output_html_grouped_by_sequence {
329: my ($r) = @_;
330: my $problem_num = 0;
331: #$r->print(&ProblemStatisticsLegend());
332: foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()) {
333: next if ($sequence->{'num_assess'}<1);
334: $r->print("<h3>".$sequence->{'title'}."</h3>");
335: $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
336: $r->print('<table border="0" cellpadding="3">'."\n");
337: $r->print('<tr bgcolor="#FFFFE6">');
338: my $Str = &statistics_table_header('no container no plots');
339: $r->print('<tr bgcolor="#FFFFE6">'.$Str."</tr>\n");
340: foreach my $resource (@{$sequence->{'contents'}}) {
341: next if ($resource->{'type'} ne 'assessment');
342: foreach my $part (@{$resource->{'parts'}}) {
343: $problem_num++;
344: my $data = &get_statistics($sequence,$resource,$part,
345: $problem_num);
346: my $option = '';
347: $r->print('<tr>'.&statistics_html_table_data($data,
348: 'no container').
349: "</tr>\n");
350: }
351: }
352: $r->print("</table>\n");
353: $r->print("</td></tr></table>\n");
354: $r->rflush();
355: }
356: #
357: return;
358: }
359:
360: ###############################################
361: ###############################################
362:
363: =pod
364:
365: =item &output_html_ungrouped()
366:
367: Presents the statistics data in a single html table which can be sorted by
368: different columns.
369:
370: =cut
371:
372: ###############################################
373: ###############################################
374: sub output_html_ungrouped {
375: my ($r,$option) = @_;
376: #
377: if (exists($ENV{'form.plot'}) && $ENV{'form.plot'} ne '') {
378: &plot_statistics($r,$ENV{'form.plot'});
379: }
380: #
381: my $problem_num = 0;
382: my $show_container = 0;
383: my $show_part = 0;
384: #$r->print(&ProblemStatisticsLegend());
385: my $sortby = undef;
386: foreach my $field (@Fields) {
387: if ($ENV{'form.sortby'} eq $field->{'name'}) {
388: $sortby = $field->{'name'};
389: }
390: }
391: if (! defined($sortby) || $sortby eq '' || $sortby eq 'problem_num') {
392: $sortby = 'container';
393: }
394: # If there is more than one sequence, list their titles
395: my @Sequences = &Apache::lonstatistics::Sequences_with_Assess();
396: if (@Sequences < 1) {
397: $option .= ' no container';
398: }
399: #
400: # Compile the data
401: my @Statsarray;
402: foreach my $sequence (@Sequences) {
403: next if ($sequence->{'num_assess'}<1);
404: foreach my $resource (@{$sequence->{'contents'}}) {
405: next if ($resource->{'type'} ne 'assessment');
406: foreach my $part (@{$resource->{'parts'}}) {
407: $problem_num++;
408: my $data = &get_statistics($sequence,$resource,$part,
409: $problem_num);
410: $show_part = 1 if ($part ne '0');
411: #
412: push (@Statsarray,$data);
413: }
414: }
415: }
416: #
417: # Sort the data
418: my @OutputOrder;
419: if ($sortby eq 'container') {
420: @OutputOrder = @Statsarray;
421: } else {
422: # $sortby is already defined, so we can charge ahead
423: if ($sortby =~ /^(title|part)$/i) {
424: # Alpha comparison
425: @OutputOrder = sort {
426: lc($a->{$sortby}) cmp lc($b->{$sortby}) ||
427: lc($a->{'title'}) cmp lc($b->{'title'}) ||
428: lc($a->{'part'}) cmp lc($b->{'part'});
429: } @Statsarray;
430: } else {
431: # Numerical comparison
432: @OutputOrder = sort {
433: my $retvalue = 0;
434: if ($b->{$sortby} eq 'nan') {
435: if ($a->{$sortby} ne 'nan') {
436: $retvalue = -1;
437: } else {
438: $retvalue = 0;
439: }
440: }
441: if ($a->{$sortby} eq 'nan') {
442: if ($b->{$sortby} ne 'nan') {
443: $retvalue = 1;
444: }
445: }
446: if ($retvalue eq '0') {
447: $retvalue = $b->{$sortby} <=> $a->{$sortby} ||
448: lc($a->{'title'}) <=> lc($b->{'title'}) ||
449: lc($a->{'part'}) <=> lc($b->{'part'});
450: }
451: $retvalue;
452: } @Statsarray;
453: }
454: }
455: $option .= 'no part' if (! $show_part);
456: my $num_output = 0;
457: #
458: # output the headers
459: $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
460: $r->print('<table border="0" cellpadding="3">'."\n");
461: my $Str = &statistics_table_header($option.' sortable');
462: $r->print('<tr bgcolor="#FFFFE6">'.$Str."</tr>\n");
463: #
464: foreach my $rowdata (@OutputOrder) {
465: $num_output++;
466: if ($num_output % 25 == 0) {
467: $r->print("</table>\n</td></tr></table>\n");
468: #
469: $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n");
470: $r->print('<table border="0" cellpadding="3">'."\n");
471: my $Str = &statistics_table_header($option.' sortable');
472: $r->print('<tr bgcolor="#FFFFE6">'.$Str."</tr>\n");
473: $r->rflush();
474: }
475: $r->print('<tr>'.&statistics_html_table_data($rowdata,$option).
476: "</tr>\n");
477: }
478: $r->print("</table>\n");
479: $r->print("</td></tr></table>\n");
480: $r->rflush();
481: #
482: return;
483: }
484:
485: ###############################################
486: ###############################################
487:
488: =pod
489:
490: =item &output_excel()
491:
492: Presents the statistical data in an Excel 95 compatable spreadsheet file.
493:
494: =cut
495:
496: ###############################################
497: ###############################################
498: sub output_excel {
499: my ($r) = @_;
500: my $filename = '/prtspool/'.
501: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
502: time.'_'.rand(1000000000).'.xls';
503: #
504: my $excel_workbook = undef;
505: my $excel_sheet = undef;
506: #
507: my $rows_output = 0;
508: my $cols_output = 0;
509: #
510: # Create sheet
511: $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
512: #
513: # Check for errors
514: if (! defined($excel_workbook)) {
515: $r->log_error("Error creating excel spreadsheet $filename: $!");
516: $r->print(&mt("Problems creating new Excel file. ".
517: "This error has been logged. ".
518: "Please alert your LON-CAPA administrator."));
519: return ;
520: }
521: #
522: # The excel spreadsheet stores temporary data in files, then put them
523: # together. If needed we should be able to disable this (memory only).
524: # The temporary directory must be specified before calling 'addworksheet'.
525: # File::Temp is used to determine the temporary directory.
526: $excel_workbook->set_tempdir($Apache::lonnet::tmpdir);
527: #
528: # Add a worksheet
529: my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
530: if (length($sheetname) > 31) {
531: $sheetname = substr($sheetname,0,31);
532: }
533: $excel_sheet = $excel_workbook->addworksheet(
534: &Apache::loncommon::clean_excel_name($sheetname)
535: );
536: #
537: # Put the course description in the header
538: $excel_sheet->write($rows_output,$cols_output++,
539: $ENV{'course.'.$ENV{'request.course.id'}.'.description'});
540: $cols_output += 3;
541: #
542: # Put a description of the sections listed
543: my $sectionstring = '';
544: my @Sections = @Apache::lonstatistics::SelectedSections;
545: if (scalar(@Sections) > 1) {
546: if (scalar(@Sections) > 2) {
547: my $last = pop(@Sections);
548: $sectionstring = "Sections ".join(', ',@Sections).', and '.$last;
549: } else {
550: $sectionstring = "Sections ".join(' and ',@Sections);
551: }
552: } else {
553: if ($Sections[0] eq 'all') {
554: $sectionstring = "All sections";
555: } else {
556: $sectionstring = "Section ".$Sections[0];
557: }
558: }
559: $excel_sheet->write($rows_output,$cols_output++,$sectionstring);
560: $cols_output += scalar(@Sections);
561: #
562: # Put the date in there too
563: $excel_sheet->write($rows_output,$cols_output++,
564: 'Compiled on '.localtime(time));
565: #
566: $rows_output++;
567: $cols_output=0;
568: #
569: # Long Headersheaders
570: foreach my $field (@Fields) {
571: next if ($field->{'name'} eq 'problem_num');
572: if (exists($field->{'long_title'})) {
573: $excel_sheet->write($rows_output,$cols_output++,
574: $field->{'long_title'});
575: } else {
576: $excel_sheet->write($rows_output,$cols_output++,'');
577: }
578: }
579: $rows_output++;
580: $cols_output=0;
581: # Brief headers
582: foreach my $field (@Fields) {
583: next if ($field->{'name'} eq 'problem_num');
584: # Use english for excel as I am not sure how well excel handles
585: # other character sets....
586: $excel_sheet->write($rows_output,$cols_output++,$field->{'title'});
587: }
588: $rows_output++;
589: #
590: # Write the data
591: my $problem_num=0;
592: foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()) {
593: next if ($sequence->{'num_assess'}<1);
594: foreach my $resource (@{$sequence->{'contents'}}) {
595: next if ($resource->{'type'} ne 'assessment');
596: foreach my $part (@{$resource->{'parts'}}) {
597: $cols_output=0;
598: $problem_num++;
599: my $data = &get_statistics($sequence,$resource,$part,
600: $problem_num);
601: #
602: if (!defined($part) || $part eq '') {
603: $part = ' ';
604: }
605: foreach my $field (@Fields) {
606: next if ($field->{'name'} eq 'problem_num');
607: $excel_sheet->write($rows_output,$cols_output++,
608: $data->{$field->{'name'}});
609: }
610: $rows_output++;
611: }
612: }
613: }
614: #
615: # Write the excel file
616: $excel_workbook->close();
617: # Tell the user where to get their excel file
618: $r->print('<br />'.
619: '<a href="'.$filename.'">'.
620: &mt('Your Excel Spreadsheet').'</a>'."\n");
621: $r->rflush();
622: return;
623: }
624:
625: ###############################################
626: ###############################################
627:
628: =pod
629:
630: =item &statistics_html_table_data()
631:
632: Help function used to format the rows for HTML table output.
633:
634: =cut
635:
636: ###############################################
637: ###############################################
638: sub statistics_html_table_data {
639: my ($data,$options) = @_;
640: my $row = '';
641: foreach my $field (@Fields) {
642: next if ($options =~ /no $field->{'name'}/);
643: $row .= '<td bgcolor="'.$field->{'color'}.'"';
644: if (exists($field->{'align'})) {
645: $row .= ' align="'.$field->{'align'}.'"';
646: }
647: $row .= '>';
648: if (exists($field->{'special'}) && $field->{'special'} eq 'link') {
649: $row .= '<a href="'.$data->{$field->{'name'}.'.link'}.'">';
650: }
651: if (exists($field->{'format'})) {
652: $row .= sprintf($field->{'format'},$data->{$field->{'name'}});
653: } else {
654: $row .= $data->{$field->{'name'}};
655: }
656: if (exists($field->{'special'}) && $field->{'special'} eq 'link') {
657: $row.= '</a>';
658: }
659: $row .= '</td>';
660: }
661: return $row;
662: }
663:
664: sub statistics_table_header {
665: my ($options) = @_;
666: my $header_row;
667: foreach my $field (@Fields) {
668: next if ($options =~ /no $field->{'name'}/);
669: $header_row .= '<th>';
670: if ($options =~ /sortable/ &&
671: exists($field->{'sortable'}) && $field->{'sortable'} eq 'yes') {
672: $header_row .= '<a href="javascript:'.
673: 'document.Statistics.sortby.value='."'".$field->{'name'}."'".
674: ';document.Statistics.submit();">';
675: }
676: $header_row .= &mt($field->{'title'});
677: if ($options =~ /sortable/) {
678: $header_row.= '</a>';
679: }
680: if ($options !~ /no plots/ &&
681: exists($field->{'graphable'}) &&
682: $field->{'graphable'} eq 'yes') {
683: $header_row.=' (';
684: $header_row .= '<a href="javascript:'.
685: "document.Statistics.plot.value='$field->{'name'}'".
686: ';document.Statistics.submit();">';
687: $header_row .= &mt('plot').'</a>)';
688: }
689: $header_row .= '</th>';
690: }
691: return $header_row;
692: }
693:
694: ###############################################
695: ###############################################
696:
697: =pod
698:
699: =item &plot_statistics()
700:
701: =cut
702:
703: ###############################################
704: ###############################################
705: sub plot_statistics {
706: my ($r,$datafield) = @_;
707: my @Data;
708: #
709: #
710: my $sortfield = undef;
711: my $title = undef;
712: foreach my $field (@Fields) {
713: if ($datafield eq $field->{'name'} &&
714: exists($field->{'graphable'}) && $field->{'graphable'} eq 'yes') {
715: $sortfield = $field->{'name'};
716: $title = $field->{'long_title'};
717: }
718: }
719: return if (! defined($sortfield) || $sortfield eq '');
720: #
721: my $Max = 0;
722: my $problem_num = 0;
723: foreach my $sequence (&Apache::lonstatistics::Sequences_with_Assess()) {
724: next if ($sequence->{'num_assess'}<1);
725: foreach my $resource (@{$sequence->{'contents'}}) {
726: next if ($resource->{'type'} ne 'assessment');
727: foreach my $part (@{$resource->{'parts'}}) {
728: my $problem_number++;
729: my $data = &get_statistics($sequence,$resource,$part,
730: $problem_num);
731: my $value = $data->{$sortfield};
732: $Max = $value if ($Max < $value);
733: push (@Data,$value);
734: }
735: }
736: }
737: #
738: # Print out plot request
739: my $yaxis = '';
740: if ($sortfield eq 'per_wrong') {
741: $yaxis = 'Percent';
742: }
743: #
744: # Determine appropriate value for $Max
745: if ($sortfield eq 'deg_of_diff') {
746: if ($Max > 0.5) {
747: $Max = 1;
748: } elsif ($Max > 0.2) {
749: $Max = 0.5;
750: } elsif ($Max > 0.1) {
751: $Max = 0.2;
752: }
753: } elsif ($sortfield eq 'per_wrong') {
754: if ($Max > 50) {
755: $Max = 100;
756: } elsif ($Max > 25) {
757: $Max = 50;
758: } elsif ($Max > 20) {
759: $Max = 25;
760: } elsif ($Max > 10) {
761: $Max = 20;
762: } elsif ($Max > 5) {
763: $Max = 10;
764: } else {
765: $Max = 5;
766: }
767: }
768:
769: $r->print("<p>".&Apache::loncommon::DrawBarGraph($title,
770: 'Problem Number',
771: $yaxis,
772: $Max,
773: undef,
774: \@Data)."</p>\n");
775: #
776: # Print out the data
777: $ENV{'form.sortby'} = 'Contents';
778: # &output_html_ungrouped($r);
779: return;
780: }
781:
782: sub get_statistics {
783: my ($sequence,$resource,$part,$problem_num) = @_;
784: #
785: my $symb = $resource->{'symb'};
786: my $courseid = $ENV{'request.course.id'};
787: #
788: my $students = \@Apache::lonstatistics::Students;
789: if ($Apache::lonstatistics::SelectedSections[0] eq 'all') {
790: $students = undef;
791: }
792: my $data = &Apache::loncoursedata::get_problem_statistics
793: ($students,$symb,$part,$courseid);
794: $data->{'part'} = $part;
795: $data->{'problem_num'} = $problem_num;
796: $data->{'container'} = $sequence->{'title'};
797: $data->{'title'} = $resource->{'title'};
798: $data->{'title.link'} = $resource->{'src'}.'?symb='.
799: &Apache::lonnet::escape($resource->{'symb'});
800: #
801: return $data;
802: }
803:
804: ###############################################
805: ###############################################
806:
807: =pod
808:
809: =item &ProblemStatisticsLegend()
810:
811: HELP This needs to be localized, or at least generated automatically.
812:
813: =cut
814:
815: ###############################################
816: ###############################################
817: sub ProblemStatisticsLegend {
818: my $Ptr = '';
819: $Ptr = '<table border="0">';
820: $Ptr .= '<tr><td>';
821: $Ptr .= '<b>#Stdnts</b></td>';
822: $Ptr .= '<td>Total number of students attempted the problem.';
823: $Ptr .= '</td></tr><tr><td>';
824: $Ptr .= '<b>Tries</b></td>';
825: $Ptr .= '<td>Total number of tries for solving the problem.';
826: $Ptr .= '</td></tr><tr><td>';
827: $Ptr .= '<b>Max Tries</b></td>';
828: $Ptr .= '<td>Largest number of tries for solving the problem by a student.';
829: $Ptr .= '</td></tr><tr><td>';
830: $Ptr .= '<b>Mean</b></td>';
831: $Ptr .= '<td>Average number of tries. [ Tries / #Stdnts ]';
832: $Ptr .= '</td></tr><tr><td>';
833: $Ptr .= '<b>#YES</b></td>';
834: $Ptr .= '<td>Number of students solved the problem correctly.';
835: $Ptr .= '</td></tr><tr><td>';
836: $Ptr .= '<b>#yes</b></td>';
837: $Ptr .= '<td>Number of students solved the problem by override.';
838: $Ptr .= '</td></tr><tr><td>';
839: $Ptr .= '<b>%Wrong</b></td>';
840: $Ptr .= '<td>Percentage of students who tried to solve the problem ';
841: $Ptr .= 'but is still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]';
842: $Ptr .= '</td></tr><tr><td>';
843: $Ptr .= '<b>DoDiff</b></td>';
844: $Ptr .= '<td>Degree of Difficulty of the problem. ';
845: $Ptr .= '[ 1 - ((#YES+#yes) / Tries) ]';
846: $Ptr .= '</td></tr><tr><td>';
847: $Ptr .= '<b>S.D.</b></td>';
848: $Ptr .= '<td>Standard Deviation of the tries. ';
849: $Ptr .= '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1) ';
850: $Ptr .= 'where Xi denotes every student\'s tries ]';
851: $Ptr .= '</td></tr><tr><td>';
852: $Ptr .= '<b>Skew.</b></td>';
853: $Ptr .= '<td>Skewness of the students tries.';
854: $Ptr .= '[(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]';
855: $Ptr .= '</td></tr><tr><td>';
856: $Ptr .= '<b>Dis.F.</b></td>';
857: $Ptr .= '<td>Discrimination Factor: A Standard for evaluating the ';
858: $Ptr .= 'problem according to a Criterion<br>';
859: $Ptr .= '<b>[Criterion to group students into %27 Upper Students - ';
860: $Ptr .= 'and %27 Lower Students]</b><br>';
861: $Ptr .= '<b>1st Criterion</b> for Sorting the Students: ';
862: $Ptr .= '<b>Sum of Partial Credit Awarded / Total Number of Tries</b><br>';
863: $Ptr .= '<b>2nd Criterion</b> for Sorting the Students: ';
864: $Ptr .= '<b>Total number of Correct Answers / Total Number of Tries</b>';
865: $Ptr .= '</td></tr>';
866: $Ptr .= '<tr><td><b>Disc.</b></td>';
867: $Ptr .= '<td>Number of Students had at least one discussion.';
868: $Ptr .= '</td></tr></table>';
869: return $Ptr;
870: }
871:
872: #---- END Problem Statistics Web Page ----------------------------------------
873:
874: 1;
875: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>