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