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