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