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