Annotation of loncom/interface/statistics/lonproblemstatistics.pm, revision 1.98
1.1 stredwic 1: # The LearningOnline Network with CAPA
2: #
1.98 ! matthew 3: # $Id: lonproblemstatistics.pm,v 1.97 2005/03/01 00:07:21 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.84 matthew 58: use LONCAPA::lonmetadata();
1.59 matthew 59: use Apache::lonlocal;
1.44 matthew 60: use Spreadsheet::WriteExcel;
1.70 matthew 61: use Apache::lonstathelpers();
1.71 matthew 62: use Time::HiRes;
1.73 matthew 63:
64: my @StatsArray;
1.79 matthew 65: my %SeqStat; # keys are symbs, values are hash refs
1.73 matthew 66:
1.59 matthew 67: ##
68: ## Localization notes:
69: ##
70: ## in @Fields[0]->{'long_title'} is placed in Excel files and is used as the
71: ## header for plots created with Graph.pm, both of which more than likely do
72: ## not support localization.
73: ##
1.79 matthew 74: #
75: #
76: ##
77: ## Description of Field attributes
78: ##
79: ## Attribute Required Value Meaning or Use
80: ##
81: ## name yes any scalar Used to uniquely identify field
82: ## title yes any scalar This is what the user sees to identify
83: ## the field. Passed through &mt().
84: ## long_title yes any scalar Used as graph heading and in excel
85: ## output. NOT translated
86: ## align no (left|right|center) HTML cell contents alignment
87: ## color yes html color HTML cell background color
88: ## used to visually group statistics
89: ## special no (link) Indicates a link, target is name.link
90: ## Currently set in &get_statistics()
91: ## graphable no (yes|no) Can a bar graph of the field be
92: ## produced?
93: ## sortable no (yes|no) Should a sort link be put in the
94: ## column header?
95: ## selectable yes (yes|no) Can the column be removed from the
96: ## statistics display?
97: ## selected yes (yes|no) Is the column selected by default?
98: ##
1.85 matthew 99: ## format no sprintf format string
100: ##
101: ## excel_format no excel format type
102: ## (see &Apache::loncommon::define_excel_formats
1.49 matthew 103: my @Fields = (
104: { name => 'problem_num',
105: title => 'P#',
106: align => 'right',
1.76 matthew 107: color => '#FFFFE6',
108: selectable => 'no',
1.80 matthew 109: defaultselected => 'yes',
1.76 matthew 110: },
1.49 matthew 111: { name => 'container',
1.51 matthew 112: title => 'Sequence or Folder',
1.49 matthew 113: align => 'left',
114: color => '#FFFFE6',
1.76 matthew 115: sortable => 'yes',
116: selectable => 'no',
1.80 matthew 117: defaultselected => 'yes',
1.76 matthew 118: },
1.49 matthew 119: { name => 'title',
120: title => 'Title',
121: align => 'left',
122: color => '#FFFFE6',
123: special => 'link',
1.76 matthew 124: sortable => 'yes',
125: selectable => 'no',
1.80 matthew 126: defaultselected => 'yes',
1.76 matthew 127: },
1.49 matthew 128: { name => 'part',
129: title => 'Part',
130: align => 'left',
1.55 matthew 131: color => '#FFFFE6',
1.76 matthew 132: selectable => 'no',
1.80 matthew 133: defaultselected => 'yes',
1.76 matthew 134: },
1.49 matthew 135: { name => 'num_students',
136: title => '#Stdnts',
137: align => 'right',
138: color => '#EEFFCC',
139: format => '%d',
140: sortable => 'yes',
141: graphable => 'yes',
1.76 matthew 142: long_title => 'Number of Students Attempting Problem',
143: selectable => 'yes',
1.80 matthew 144: defaultselected => 'yes',
1.76 matthew 145: },
1.49 matthew 146: { name => 'tries',
147: title => 'Tries',
148: align => 'right',
149: color => '#EEFFCC',
150: format => '%d',
151: sortable => 'yes',
152: graphable => 'yes',
1.76 matthew 153: long_title => 'Total Number of Tries',
154: selectable => 'yes',
1.80 matthew 155: defaultselected => 'yes',
1.76 matthew 156: },
1.49 matthew 157: { name => 'max_tries',
158: title => 'Max Tries',
159: align => 'right',
160: color => '#DDFFFF',
161: format => '%d',
162: sortable => 'yes',
163: graphable => 'yes',
1.76 matthew 164: long_title => 'Maximum Number of Tries',
165: selectable => 'yes',
1.80 matthew 166: defaultselected => 'yes',
1.76 matthew 167: },
1.73 matthew 168: { name => 'min_tries',
169: title => 'Min Tries',
170: align => 'right',
171: color => '#DDFFFF',
172: format => '%d',
173: sortable => 'yes',
174: graphable => 'yes',
1.76 matthew 175: long_title => 'Minumum Number of Tries',
176: selectable => 'yes',
1.80 matthew 177: defaultselected => 'yes',
1.76 matthew 178: },
1.49 matthew 179: { name => 'mean_tries',
180: title => 'Mean Tries',
181: align => 'right',
182: color => '#DDFFFF',
183: format => '%5.2f',
184: sortable => 'yes',
185: graphable => 'yes',
1.76 matthew 186: long_title => 'Average Number of Tries',
187: selectable => 'yes',
1.80 matthew 188: defaultselected => 'yes',
1.76 matthew 189: },
1.49 matthew 190: { name => 'std_tries',
191: title => 'S.D. tries',
192: align => 'right',
193: color => '#DDFFFF',
194: format => '%5.2f',
195: sortable => 'yes',
196: graphable => 'yes',
1.76 matthew 197: long_title => 'Standard Deviation of Number of Tries',
198: selectable => 'yes',
1.80 matthew 199: defaultselected => 'yes',
1.76 matthew 200: },
1.49 matthew 201: { name => 'skew_tries',
202: title => 'Skew Tries',
203: align => 'right',
204: color => '#DDFFFF',
205: format => '%5.2f',
206: sortable => 'yes',
207: graphable => 'yes',
1.76 matthew 208: long_title => 'Skew of Number of Tries',
209: selectable => 'yes',
1.80 matthew 210: defaultselected => 'no',
1.76 matthew 211: },
1.49 matthew 212: { name => 'num_solved',
213: title => '#YES',
214: align => 'right',
215: color => '#FFDDDD',
1.63 matthew 216: format => '%4.1f',# format => '%d',
1.49 matthew 217: sortable => 'yes',
218: graphable => 'yes',
1.76 matthew 219: long_title => 'Number of Students able to Solve',
1.77 matthew 220: selectable => 'yes',
1.80 matthew 221: defaultselected => 'yes',
1.76 matthew 222: },
1.49 matthew 223: { name => 'num_override',
224: title => '#yes',
225: align => 'right',
226: color => '#FFDDDD',
1.63 matthew 227: format => '%4.1f',# format => '%d',
1.49 matthew 228: sortable => 'yes',
229: graphable => 'yes',
1.76 matthew 230: long_title => 'Number of Students given Override',
231: selectable => 'yes',
1.80 matthew 232: defaultselected => 'yes',
1.76 matthew 233: },
1.95 matthew 234: { name => 'tries_per_correct',
235: title => 'tries/correct',
236: align => 'right',
237: color => '#FFDDDD',
238: format => '%4.1f',
239: sortable => 'yes',
240: graphable => 'yes',
241: long_title => 'Tries per Correct Answer',
242: selectable => 'yes',
243: defaultselected => 'yes',
244: },
1.73 matthew 245: { name => 'num_wrong',
246: title => '#Wrng',
1.49 matthew 247: align => 'right',
1.73 matthew 248: color => '#FFDDDD',
1.49 matthew 249: format => '%4.1f',
250: sortable => 'yes',
251: graphable => 'yes',
1.93 matthew 252: long_title => 'Number of students whose final answer is wrong',
253: selectable => 'yes',
254: defaultselected => 'yes',
255: },
256: { name => 'per_wrong',
257: title => '%Wrng',
258: align => 'right',
259: color => '#FFDDDD',
260: format => '%4.1f',
261: sortable => 'yes',
262: graphable => 'yes',
1.76 matthew 263: long_title => 'Percent of students whose final answer is wrong',
264: selectable => 'yes',
1.80 matthew 265: defaultselected => 'yes',
1.76 matthew 266: },
1.73 matthew 267: { name => 'deg_of_diff',
268: title => 'DoDiff',
269: align => 'right',
270: color => '#FFFFE6',
271: format => '%5.2f',
272: sortable => 'yes',
273: graphable => 'yes',
274: long_title => 'Degree of Difficulty'.
1.76 matthew 275: '[ 1 - ((#YES+#yes) / Tries) ]',
276: selectable => 'yes',
1.80 matthew 277: defaultselected => 'yes',
1.76 matthew 278: },
1.71 matthew 279: { name => 'deg_of_disc',
1.73 matthew 280: title => 'DoDisc',
1.71 matthew 281: align => 'right',
282: color => '#FFFFE6',
283: format => '%4.2f',
284: sortable => 'yes',
285: graphable => 'yes',
1.76 matthew 286: long_title => 'Degree of Discrimination',
287: selectable => 'yes',
1.89 matthew 288: defaultselected => 'yes',
1.76 matthew 289: },
1.85 matthew 290: ## duedate included for research purposes. Commented out most of the time.
291: # { name => 'duedate',
292: # title => 'Due Date',
293: # align => 'left',
294: # color => '#FFFFFF',
295: # sortable => 'yes',
296: # graphable => 'no',
297: # long_title => 'Due date of resource for instructor',
298: # selectable => 'no',
299: # defaultselected => 'yes',
300: # },
301: ## opendate included for research purposes. Commented out most of the time.
302: # { name => 'opendate',
303: # title => 'Open Date',
304: # align => 'left',
305: # color => '#FFFFFF',
306: # sortable => 'yes',
307: # graphable => 'no',
308: # long_title => 'date resource became answerable',
309: # selectable => 'no',
310: # defaultselected => 'yes',
311: # },
312: ## symb included for research purposes. Commented out most of the time.
313: # { name => 'symb',
314: # title => 'Symb',
315: # align => 'left',
316: # color => '#FFFFFF',
317: # sortable => 'yes',
318: # graphable => 'no',
319: # long_title => 'Unique LON-CAPA identifier for problem',
320: # selectable => 'no',
321: # defaultselected => 'yes',
322: # },
1.86 matthew 323: ## resptypes included for research purposes. Commented out most of the time.
324: # { name => 'resptypes',
325: # title => 'Response Types',
326: # align => 'left',
327: # color => '#FFFFFF',
328: # sortable => 'no',
329: # graphable => 'no',
330: # long_title => 'Response Types used in this problem',
331: # selectable => 'no',
332: # defaultselected => 'yes',
333: # },
1.94 matthew 334: ## maxtries included for research purposes. Commented out most of the time.
335: # { name => 'maxtries',
336: # title => 'Maxtries',
337: # align => 'left',
338: # color => '#FFFFFF',
339: # sortable => 'no',
340: # graphable => 'no',
341: # long_title => 'Maximum number of tries',
342: # selectable => 'no',
343: # defaultselected => 'yes',
344: # },
345: ## hinttries included for research purposes. Commented out most of the time.
346: # { name => 'hinttries',
347: # title => 'hinttries',
348: # align => 'left',
349: # color => '#FFFFFF',
350: # sortable => 'no',
351: # graphable => 'no',
352: # long_title => 'Number of tries before a hint appears',
353: # selectable => 'no',
354: # defaultselected => 'yes',
355: # },
1.98 ! matthew 356: #
! 357: ## problem weight for instructor
! 358: { name => 'weight',
! 359: title => 'weight',
! 360: align => 'right',
! 361: color => '#FFFFFF',
! 362: sortable => 'no',
! 363: graphable => 'no',
! 364: long_title => 'Problem weight (for instructor)',
! 365: selectable => 'no',
! 366: defaultselected => 'yes',
! 367: },
1.49 matthew 368: );
369:
1.79 matthew 370: my @SeqFields = (
371: { name => 'title',
372: title => 'Sequence',
373: align => 'left',
374: color => '#FFFFE6',
375: special => 'no',
376: sortable => 'no',
377: selectable => 'yes',
1.80 matthew 378: defaultselected => 'no',
1.79 matthew 379: },
380: { name => 'items',
381: title => '#Items',
382: align => 'right',
383: color => '#FFFFE6',
384: format => '%4d',
385: sortable => 'no',
386: graphable => 'no',
387: long_title => 'Number of Items in Sequence',
388: selectable => 'yes',
1.80 matthew 389: defaultselected => 'no',
1.79 matthew 390: },
391: { name => 'scoremean',
392: title => 'Score Mean',
393: align => 'right',
394: color => '#FFFFE6',
395: format => '%4.2f',
396: sortable => 'no',
397: graphable => 'no',
398: long_title => 'Mean Sequence Score',
399: selectable => 'yes',
1.80 matthew 400: defaultselected => 'no',
1.79 matthew 401: },
402: { name => 'scorestd',
403: title => 'Score STD',
404: align => 'right',
405: color => '#FFFFE6',
406: format => '%4.2f',
407: sortable => 'no',
408: graphable => 'no',
409: long_title => 'Standard Deviation of Sequence Scores',
410: selectable => 'yes',
1.80 matthew 411: defaultselected => 'no',
1.79 matthew 412: },
413: { name => 'scoremax',
414: title => 'Score Max',
415: align => 'right',
416: color => '#FFFFE6',
417: format => '%4.2f',
418: sortable => 'no',
419: graphable => 'no',
420: long_title => 'Maximum Sequence Score',
421: selectable => 'yes',
1.80 matthew 422: defaultselected => 'no',
1.79 matthew 423: },
424: { name => 'scoremin',
425: title => 'Score Min',
426: align => 'right',
427: color => '#FFFFE6',
428: format => '%4.2f',
429: sortable => 'no',
430: graphable => 'no',
431: long_title => 'Minumum Sequence Score',
432: selectable => 'yes',
1.80 matthew 433: defaultselected => 'no',
1.79 matthew 434: },
435: { name => 'scorecount',
436: title => 'Score N',
437: align => 'right',
438: color => '#FFFFE6',
439: format => '%4d',
440: sortable => 'no',
441: graphable => 'no',
442: long_title => 'Number of Students in score computations',
443: selectable => 'yes',
1.80 matthew 444: defaultselected => 'no',
1.79 matthew 445: },
446: { name => 'countmean',
447: title => 'Count Mean',
448: align => 'right',
449: color => '#FFFFFF',
450: format => '%4.2f',
451: sortable => 'no',
452: graphable => 'no',
453: long_title => 'Mean Sequence Score',
454: selectable => 'yes',
1.80 matthew 455: defaultselected => 'no',
1.79 matthew 456: },
457: { name => 'countstd',
458: title => 'Count STD',
459: align => 'right',
460: color => '#FFFFFF',
461: format => '%4.2f',
462: sortable => 'no',
463: graphable => 'no',
464: long_title => 'Standard Deviation of Sequence Scores',
465: selectable => 'yes',
1.80 matthew 466: defaultselected => 'no',
1.79 matthew 467: },
468: { name => 'countmax',
469: title => 'Count Max',
470: align => 'right',
471: color => '#FFFFFF',
472: format => '%4.2f',
473: sortable => 'no',
474: graphable => 'no',
475: long_title => 'Maximum Number of Correct Problems',
476: selectable => 'yes',
1.80 matthew 477: defaultselected => 'no',
1.79 matthew 478: },
479: { name => 'countmin',
480: title => 'Count Min',
481: align => 'right',
482: color => '#FFFFFF',
483: format => '%4.2f',
484: sortable => 'no',
485: graphable => 'no',
486: long_title => 'Minumum Number of Correct Problems',
487: selectable => 'yes',
1.80 matthew 488: defaultselected => 'no',
1.79 matthew 489: },
490: { name => 'count',
491: title => 'Count N',
492: align => 'right',
493: color => '#FFFFFF',
494: format => '%4d',
495: sortable => 'no',
496: graphable => 'no',
497: long_title => 'Number of Students in score computations',
498: selectable => 'yes',
1.80 matthew 499: defaultselected => 'no',
1.79 matthew 500: },
501: { name => 'KR-21',
502: title => 'KR-21',
503: align => 'right',
504: color => '#FFAAAA',
505: format => '%4.2f',
506: sortable => 'no',
507: graphable => 'no',
508: long_title => 'KR-21 reliability statistic',
509: selectable => 'yes',
1.80 matthew 510: defaultselected => 'no',
1.79 matthew 511: },
512: );
513:
1.76 matthew 514: my %SelectedFields;
515:
516: sub parse_field_selection {
517: #
518: # Pull out the defaults
519: if (! defined($ENV{'form.fieldselections'})) {
520: $ENV{'form.fieldselections'} = [];
521: foreach my $field (@Fields) {
522: next if ($field->{'selectable'} ne 'yes');
1.80 matthew 523: if ($field->{'defaultselected'} eq 'yes') {
1.76 matthew 524: push(@{$ENV{'form.fieldselections'}},$field->{'name'});
525: }
526: }
527: }
528: #
1.80 matthew 529: # Make sure the data we are plotting is there
530: my %NeededFields;
531: if (exists($ENV{'form.plot'}) && $ENV{'form.plot'} ne '' &&
532: $ENV{'form.plot'} ne 'none') {
533: if ($ENV{'form.plot'} eq 'degrees') {
534: $NeededFields{'deg_of_diff'}++;
535: $NeededFields{'deg_of_disc'}++;
536: } elsif ($ENV{'form.plot'} eq 'tries statistics') {
537: $NeededFields{'mean_tries'}++;
538: $NeededFields{'std_tries'}++;
539: $NeededFields{'problem_num'}++;
540: } else {
541: $NeededFields{$ENV{'form.plot'}}++;
542: }
543: }
544: #
1.76 matthew 545: # This should not happen, but in case it does...
546: if (ref($ENV{'form.fieldselections'}) ne 'ARRAY') {
547: $ENV{'form.fieldselections'} = [$ENV{'form.fieldselections'}];
548: }
549: #
550: # Set the field data and the selected fields (for easier checking)
551: undef(%SelectedFields);
552: foreach my $field (@Fields) {
1.80 matthew 553: if ($field->{'selectable'} ne 'yes') {
554: $field->{'selected'} = 'yes';
555: } else {
556: $field->{'selected'} = 'no';
557: }
558: if (exists($NeededFields{$field->{'name'}})) {
559: $field->{'selected'} = 'yes';
560: $SelectedFields{$field->{'name'}}++;
561: }
1.76 matthew 562: foreach my $selection (@{$ENV{'form.fieldselections'}}) {
563: if ($selection eq $field->{'name'} || $selection eq 'all') {
564: $field->{'selected'} = 'yes';
565: $SelectedFields{$field->{'name'}}++;
566: }
567: }
568: }
1.82 matthew 569: #
570: # Always show all the sequence statistics (for now)
571: foreach my $field (@SeqFields) {
572: $field->{'selected'} = 'yes';
573: }
1.76 matthew 574: return;
575: }
576:
577: sub field_selection_input {
578: my $Str = '<select name="fieldselections" multiple size="5">'."\n";
579: $Str .= '<option value="all">all</option>'."\n";
580: foreach my $field (@Fields) {
581: next if ($field->{'selectable'} ne 'yes');
582: $Str .= ' <option value="'.$field->{'name'}.'" ';
583: if ($field->{'selected'} eq 'yes') {
584: $Str .= 'selected ';
585: }
586: $Str .= '>'.$field->{'title'}.'</option>'."\n";
587: }
588: $Str .= "</select>\n";
589: }
590:
1.47 matthew 591: ###############################################
592: ###############################################
593:
594: =pod
595:
596: =item &CreateInterface()
597:
598: Create the main intereface for the statistics page. Allows the user to
599: select sections, maps, and output.
600:
601: =cut
1.1 stredwic 602:
1.47 matthew 603: ###############################################
604: ###############################################
1.41 matthew 605: sub CreateInterface {
1.87 matthew 606: my ($r) = @_;
1.80 matthew 607: #
1.76 matthew 608: &parse_field_selection();
1.80 matthew 609: #
1.41 matthew 610: my $Str = '';
1.67 matthew 611: $Str .= &Apache::lonhtmlcommon::breadcrumbs
1.69 matthew 612: (undef,'Overall Problem Statistics','Statistics_Overall_Key');
1.41 matthew 613: $Str .= '<table cellspacing="5">'."\n";
614: $Str .= '<tr>';
1.59 matthew 615: $Str .= '<td align="center"><b>'.&mt('Sections').'</b></td>';
616: $Str .= '<td align="center"><b>'.&mt('Enrollment Status').'</b></td>';
617: $Str .= '<td align="center"><b>'.&mt('Sequences and Folders').'</b></td>';
1.76 matthew 618: $Str .= '<td align="center"><b>'.&mt('Statistics').'</b></td>';
1.70 matthew 619: $Str .= '<td rowspan="2">'.
620: &Apache::lonstathelpers::limit_by_time_form().'</td>';
1.41 matthew 621: $Str .= '</tr>'."\n";
622: #
623: $Str .= '<tr><td align="center">'."\n";
624: $Str .= &Apache::lonstatistics::SectionSelect('Section','multiple',5);
1.50 matthew 625: $Str .= '</td><td align="center">';
626: $Str .= &Apache::lonhtmlcommon::StatusOptions(undef,undef,5);
1.41 matthew 627: $Str .= '</td><td align="center">';
628: #
1.97 matthew 629: $Str .= &Apache::lonstatistics::map_select('Maps','multiple,all',5);
1.76 matthew 630: $Str .= '</td><td>'.&field_selection_input();
1.41 matthew 631: $Str .= '</td></tr>'."\n";
632: $Str .= '</table>'."\n";
1.87 matthew 633: #
634: $Str .= '<p>'.&mt('Status: [_1]',
635: '<input type="text" '.
636: 'name="stats_status" size="60" value="" />'
637: ).
638: '</nobr></p>';
639: #
1.59 matthew 640: $Str .= '<input type="submit" name="GenerateStatistics" value="'.
641: &mt('Generate Statistics').'" />';
1.54 matthew 642: $Str .= ' 'x5;
1.73 matthew 643: $Str .= 'Plot '.&plot_dropdown().(' 'x10);
1.87 matthew 644: #
1.73 matthew 645: return $Str;
1.41 matthew 646: }
1.25 stredwic 647:
1.41 matthew 648: ###############################################
649: ###############################################
1.28 stredwic 650:
1.47 matthew 651: =pod
652:
653: =item &BuildProblemStatisticsPage()
654:
655: Main interface to problem statistics.
656:
657: =cut
658:
1.41 matthew 659: ###############################################
660: ###############################################
1.97 matthew 661: my $navmap;
662: my @sequences;
663:
1.41 matthew 664: sub BuildProblemStatisticsPage {
665: my ($r,$c)=@_;
1.97 matthew 666: undef($navmap);
667: undef(@sequences);
1.61 matthew 668: #
669: my %Saveable_Parameters = ('Status' => 'scalar',
670: 'statsoutputmode' => 'scalar',
671: 'Section' => 'array',
672: 'StudentData' => 'array',
1.77 matthew 673: 'Maps' => 'array',
674: 'fieldselections'=> 'array');
1.61 matthew 675: &Apache::loncommon::store_course_settings('statistics',
676: \%Saveable_Parameters);
677: &Apache::loncommon::restore_course_settings('statistics',
678: \%Saveable_Parameters);
679: #
680: &Apache::lonstatistics::PrepareClasslist();
1.41 matthew 681: #
1.73 matthew 682: # Clear the package variables
683: undef(@StatsArray);
1.79 matthew 684: undef(%SeqStat);
1.71 matthew 685: #
1.73 matthew 686: # Finally let the user know we are here
1.87 matthew 687: my $interface = &CreateInterface($r);
1.57 matthew 688: $r->print($interface);
1.41 matthew 689: $r->print('<input type="hidden" name="sortby" value="'.$ENV{'form.sortby'}.
690: '" />');
1.73 matthew 691: #
1.87 matthew 692: my @CacheButtonHTML =
693: &Apache::lonstathelpers::manage_caches($r,'Statistics','stats_status');
694: my $Str;
695: foreach my $html (@CacheButtonHTML) {
696: $Str.=$html.(' 'x5);
697: }
698: #
699: $r->print($Str);
700: if (! exists($ENV{'form.firstrun'})) {
1.73 matthew 701: $r->print('<h3>'.
702: &mt('Press "Generate Statistics" when you are ready.').
703: '</h3><p>'.
704: &mt('It may take some time to update the student data '.
705: 'for the first analysis. Future analysis this session '.
706: ' will not have this delay.').
707: '</p>');
1.41 matthew 708: return;
1.28 stredwic 709: }
1.73 matthew 710: $r->rflush();
1.41 matthew 711: #
1.73 matthew 712: # This probably does not need to be done each time we are called, but
713: # it does not slow things down noticably.
714: &Apache::loncoursedata::populate_weight_table();
1.75 matthew 715: #
1.73 matthew 716: if (exists($ENV{'form.Excel'})) {
717: &Excel_output($r);
1.87 matthew 718: } else {
719: $r->print('<input type="submit" name="Excel" value="'.
720: &mt('Produce Excel Output').'" />'.' 'x5);
721: $r->rflush();
1.75 matthew 722: my $count = 0;
1.97 matthew 723: ($navmap,@sequences) =
724: &Apache::lonstatistics::selected_sequences_with_assessments();
725: if (! ref($navmap)) {
726: $r->print('<h1>'.&mt('A course-wide error occured.').'</h1>'.
727: '<h3>'.$navmap.'</h3>');
728: return;
729: }
730: foreach my $seq (@sequences) {
731: my @resources =
732: &Apache::lonstathelpers::get_resources($navmap,$seq);
733: $count += scalar(@resources);
1.75 matthew 734: }
735: if ($count > 10) {
736: $r->print('<h2>'.
737: &mt('Compiling statistics for [_1] problems',$count).
738: '</h2>');
739: if ($count > 30) {
740: $r->print('<h3>'.&mt('This will take some time.').'</h3>');
741: }
742: $r->rflush();
743: }
744: #
1.73 matthew 745: my $sortby = $ENV{'form.sortby'};
746: $sortby = 'container' if (! defined($sortby) || $sortby =~ /^\s*$/);
747: my $plot = $ENV{'form.plot'};
1.75 matthew 748: if ($plot eq '' || $plot eq 'none') {
749: undef($plot);
750: }
1.73 matthew 751: if ($sortby eq 'container' && ! defined($plot)) {
1.79 matthew 752: &output_sequence_statistics($r);
1.73 matthew 753: &output_html_by_sequence($r);
754: } else {
755: if (defined($plot)) {
756: &make_plot($r,$plot);
757: }
758: &output_html_stats($r);
1.79 matthew 759: &output_sequence_statistics($r);
1.73 matthew 760: }
761: }
762: return;
763: }
764:
1.79 matthew 765: sub output_sequence_statistics {
766: my ($r) = @_;
767: my $c=$r->connection();
1.90 matthew 768: $r->print('<h2>'.&mt('Sequence Statistics').
769: &Apache::loncommon::help_open_topic('Statistics_Sequence').
770: '</h2>');
1.79 matthew 771: $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n".
772: '<table border="0" cellpadding="3">'."\n".
773: '<tr bgcolor="#FFFFE6">');
774: $r->print(&sequence_html_header());
1.97 matthew 775: foreach my $seq (@sequences) {
1.79 matthew 776: last if ($c->aborted);
777: &compute_sequence_statistics($seq);
778: $r->print(&sequence_html_output($seq));
779: }
780: $r->print('</table>');
781: $r->print('</table>');
782: $r->rflush();
783: return;
784: }
785:
786:
1.73 matthew 787: ##########################################################
788: ##########################################################
789: ##
790: ## HTML output routines
791: ##
792: ##########################################################
793: ##########################################################
794: sub output_html_by_sequence {
795: my ($r) = @_;
796: my $c = $r->connection();
797: $r->print(&html_preamble());
1.41 matthew 798: #
1.97 matthew 799: foreach my $seq (@sequences) {
1.73 matthew 800: last if ($c->aborted);
1.97 matthew 801: $r->print("<h3>".$seq->compTitle."</h3>".
1.73 matthew 802: '<table border="0"><tr><td bgcolor="#777777">'."\n".
803: '<table border="0" cellpadding="3">'."\n".
804: '<tr bgcolor="#FFFFE6">'.
805: &statistics_table_header('no container')."</tr>\n");
806: my @Data = &compute_statistics_on_sequence($seq);
807: foreach my $data (@Data) {
808: $r->print('<tr>'.&statistics_html_table_data($data,
809: 'no container').
810: "</tr>\n");
1.70 matthew 811: }
1.73 matthew 812: $r->print('</table>'."\n".'</table>'."\n");
1.41 matthew 813: $r->rflush();
1.28 stredwic 814: }
1.41 matthew 815: return;
816: }
1.21 stredwic 817:
1.73 matthew 818: sub output_html_stats {
819: my ($r)=@_;
820: &compute_all_statistics($r);
821: $r->print(&html_preamble());
822: &sort_data($ENV{'form.sortby'});
823: #
824: my $count=0;
825: foreach my $data (@StatsArray) {
826: if ($count++ % 50 == 0) {
827: $r->print("</table>\n</table>\n");
828: $r->print('<table border="0"><tr><td bgcolor="#777777">'."\n".
829: '<table border="0" cellpadding="3">'."\n".
830: '<tr bgcolor="#FFFFE6">'.
831: '<tr bgcolor="#FFFFE6">'.
832: &statistics_table_header().
833: "</tr>\n");
834: }
835: $r->print('<tr>'.&statistics_html_table_data($data)."</tr>\n");
836: }
837: $r->print("</table>\n</table>\n");
838: return;
839: }
1.47 matthew 840:
1.73 matthew 841: sub html_preamble {
842: my $Str='';
843: $Str .= "<h2>".
844: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.
845: "</h2>\n";
846: my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
847: if (defined($starttime) || defined($endtime)) {
848: # Inform the user what the time limits on the data are.
849: $Str .= '<h3>'.&mt('Statistics on submissions from [_1] to [_2]',
850: &Apache::lonlocal::locallocaltime($starttime),
851: &Apache::lonlocal::locallocaltime($endtime)
852: ).'</h3>';
853: }
854: $Str .= "<h3>".&mt('Compiled on [_1]',
855: &Apache::lonlocal::locallocaltime(time))."</h3>";
856: return $Str;
857: }
1.47 matthew 858:
859:
1.44 matthew 860: ###############################################
861: ###############################################
1.73 matthew 862: ##
863: ## Misc HTML output routines
864: ##
865: ###############################################
866: ###############################################
867: sub statistics_html_table_data {
868: my ($data,$options) = @_;
869: my $row = '';
870: foreach my $field (@Fields) {
871: next if ($options =~ /no $field->{'name'}/);
1.76 matthew 872: next if ($field->{'selected'} ne 'yes');
1.73 matthew 873: $row .= '<td bgcolor="'.$field->{'color'}.'"';
874: if (exists($field->{'align'})) {
875: $row .= ' align="'.$field->{'align'}.'"';
1.41 matthew 876: }
1.73 matthew 877: $row .= '>';
878: if (exists($field->{'special'}) && $field->{'special'} eq 'link') {
879: $row .= '<a href="'.$data->{$field->{'name'}.'.link'}.'">';
1.41 matthew 880: }
1.92 matthew 881: if (exists($field->{'format'}) && $data->{$field->{'name'}} !~ /[A-Z]/i) {
1.73 matthew 882: $row .= sprintf($field->{'format'},$data->{$field->{'name'}});
883: } else {
884: $row .= $data->{$field->{'name'}};
885: }
886: if (exists($field->{'special'}) && $field->{'special'} eq 'link') {
887: $row.= '</a>';
888: }
889: $row .= '</td>';
1.21 stredwic 890: }
1.73 matthew 891: return $row;
1.41 matthew 892: }
1.25 stredwic 893:
1.73 matthew 894: sub statistics_table_header {
895: my ($options) = @_;
896: my $header_row;
897: foreach my $field (@Fields) {
898: next if ($options =~ /no $field->{'name'}/);
1.76 matthew 899: next if ($field->{'selected'} ne 'yes');
1.73 matthew 900: $header_row .= '<th>';
901: if (exists($field->{'sortable'}) && $field->{'sortable'} eq 'yes') {
902: $header_row .= '<a href="javascript:'.
903: 'document.Statistics.sortby.value='."'".$field->{'name'}."'".
904: ';document.Statistics.submit();">';
905: }
906: $header_row .= &mt($field->{'title'});
907: if ($options =~ /sortable/) {
908: $header_row.= '</a>';
909: }
910: if ($options !~ /no plots/ &&
911: exists($field->{'graphable'}) &&
912: $field->{'graphable'} eq 'yes') {
913: $header_row.=' (';
914: $header_row .= '<a href="javascript:'.
915: "document.Statistics.plot.value='$field->{'name'}'".
916: ';document.Statistics.submit();">';
917: $header_row .= &mt('plot').'</a>)';
918: }
919: $header_row .= '</th>';
920: }
921: return $header_row;
922: }
1.26 stredwic 923:
1.79 matthew 924: sub sequence_html_header {
925: my $Str .= '<tr>';
926: foreach my $field (@SeqFields) {
927: # next if ($field->{'selected'} ne 'yes');
928: $Str .= '<th bgcolor="'.$field->{'color'}.'"';
929: $Str .= '>'.$field->{'title'}.'</th>';
930: }
931: $Str .= '</tr>';
932: return $Str;
933: }
934:
935:
936: sub sequence_html_output {
937: my ($seq) = @_;
1.97 matthew 938: my $data = $SeqStat{$seq->symb};
1.79 matthew 939: my $row = '<tr>';
940: foreach my $field (@SeqFields) {
1.82 matthew 941: next if ($field->{'selected'} ne 'yes');
1.79 matthew 942: $row .= '<td bgcolor="'.$field->{'color'}.'"';
943: if (exists($field->{'align'})) {
944: $row .= ' align="'.$field->{'align'}.'"';
945: }
946: $row .= '>';
947: if (exists($field->{'format'})) {
948: $row .= sprintf($field->{'format'},$data->{$field->{'name'}});
949: } else {
950: $row .= $data->{$field->{'name'}};
951: }
952: $row .= '</td>';
953: }
954: $row .= '</tr>'."\n";
955: return $row;
956: }
957:
1.73 matthew 958: ####################################################
959: ####################################################
960: ##
961: ## Plotting Routines
962: ##
963: ####################################################
964: ####################################################
965: sub make_plot {
966: my ($r,$plot) = @_;
967: &compute_all_statistics($r);
968: &sort_data($ENV{'form.sortby'});
969: if ($plot eq 'degrees') {
970: °rees_plot($r);
1.74 matthew 971: } elsif ($plot eq 'tries statistics') {
972: &tries_data_plot($r);
1.73 matthew 973: } else {
974: &make_single_stat_plot($r,$plot);
975: }
976: return;
977: }
1.47 matthew 978:
1.73 matthew 979: sub make_single_stat_plot {
980: my ($r,$datafield) = @_;
1.41 matthew 981: #
1.73 matthew 982: my $title; my $yaxis;
983: foreach my $field (@Fields) {
984: next if ($field->{'name'} ne $datafield);
985: $title = $field->{'long_title'};
986: $yaxis = $field->{'title'};
987: last;
988: }
989: if ($title eq '' || $yaxis eq '') {
990: # datafield is something we do not know enough about to plot
991: $r->print('<h3>'.
992: &mt('Unable to plot the requested statistic.').
993: '</h3>');
994: return;
1.49 matthew 995: }
996: #
1.73 matthew 997: # Build up the data sets to plot
998: my @Labels;
999: my @Data;
1000: my $max = 1;
1001: foreach my $data (@StatsArray) {
1002: push(@Labels,$data->{'problem_num'});
1003: push(@Data,$data->{$datafield});
1004: if ($data->{$datafield}>$max) {
1005: $max = $data->{$datafield};
1006: }
1007: }
1008: foreach (1,2,3,4,5,10,15,20,25,40,50,75,100,150,200,250,300,500,600,750,
1009: 1000,1500,2000,2500,3000,3500,4000,5000,7500,10000,15000,20000) {
1010: if ($max <= $_) {
1011: $max = $_;
1012: last;
1.42 matthew 1013: }
1014: }
1.73 matthew 1015: if ($max > 20000) {
1016: $max = 10000*(int($max/10000)+1);
1.42 matthew 1017: }
1.73 matthew 1018: #
1019: $r->print("<p>".&Apache::loncommon::DrawBarGraph($title,
1020: 'Problem Number',
1021: $yaxis,
1022: $max,
1023: undef, # colors
1024: \@Labels,
1025: \@Data)."</p>\n");
1026: return;
1027: }
1028:
1029: sub degrees_plot {
1030: my ($r)=@_;
1031: my $count = scalar(@StatsArray);
1032: my $width = 50 + 10*$count;
1033: $width = 300 if ($width < 300);
1034: my $height = 300;
1035: my $plot = '';
1036: my $ymax = 0;
1037: my $ymin = 0;
1038: my @Disc; my @Diff; my @Labels;
1039: foreach my $data (@StatsArray) {
1040: push(@Labels,$data->{'problem_num'});
1041: my $disc = $data->{'deg_of_disc'};
1042: my $diff = $data->{'deg_of_diff'};
1043: push(@Disc,$disc);
1044: push(@Diff,$diff);
1045: #
1046: $ymin = $disc if ($ymin > $disc);
1047: $ymin = $diff if ($ymin > $diff);
1048: $ymax = $disc if ($ymax < $disc);
1049: $ymax = $diff if ($ymax < $diff);
1050: }
1051: #
1052: # Make sure we show relevant information.
1053: if ($ymin < 0) {
1054: if (abs($ymin) < 0.05) {
1055: $ymin = 0;
1056: } else {
1057: $ymin = -1;
1.42 matthew 1058: }
1059: }
1.73 matthew 1060: if ($ymax > 0) {
1061: if (abs($ymax) < 0.05) {
1062: $ymax = 0;
1.42 matthew 1063: } else {
1.73 matthew 1064: $ymax = 1;
1.42 matthew 1065: }
1.43 matthew 1066: }
1.49 matthew 1067: #
1.73 matthew 1068: my $xmax = $Labels[-1];
1069: if ($xmax > 50) {
1070: if ($xmax % 10 != 0) {
1071: $xmax = 10 * (int($xmax/10)+1);
1072: }
1073: } else {
1074: if ($xmax % 5 != 0) {
1075: $xmax = 5 * (int($xmax/5)+1);
1.49 matthew 1076: }
1.26 stredwic 1077: }
1.41 matthew 1078: #
1.73 matthew 1079: my $discdata .= '<data>'.join(',',@Labels).'</data>'.$/.
1080: '<data>'.join(',',@Disc).'</data>'.$/;
1081: #
1082: my $diffdata .= '<data>'.join(',',@Labels).'</data>'.$/.
1083: '<data>'.join(',',@Diff).'</data>'.$/;
1084: #
1.81 matthew 1085: my $title = 'Degree of Discrimination\nand Degree of Difficulty';
1086: if ($xmax > 50) {
1087: $title = 'Degree of Discrimination and Degree of Difficulty';
1088: }
1089: #
1.73 matthew 1090: $plot=<<"END";
1091: <gnuplot
1092: texfont="10"
1093: fgcolor="x000000"
1094: plottype="Cartesian"
1095: font="large"
1096: grid="on"
1097: align="center"
1098: border="on"
1099: transparent="on"
1.81 matthew 1100: alttag="Degree of Discrimination and Degree of Difficulty Plot"
1.73 matthew 1101: samples="100"
1102: bgcolor="xffffff"
1103: height="$height"
1104: width="$width">
1105: <key
1106: pos="top right"
1107: title=""
1108: box="off" />
1.81 matthew 1109: <title>$title</title>
1.73 matthew 1110: <axis xmin="0" ymin="$ymin" xmax="$xmax" ymax="$ymax" color="x000000" />
1111: <xlabel>Problem Number</xlabel>
1112: <curve
1113: linestyle="linespoints"
1114: name="DoDisc"
1115: pointtype="0"
1116: color="x000000">
1117: $discdata
1118: </curve>
1119: <curve
1120: linestyle="linespoints"
1121: name="DoDiff"
1122: pointtype="0"
1123: color="xFF0000">
1124: $diffdata
1125: </curve>
1126: </gnuplot>
1127: END
1128: my $plotresult =
1129: '<p>'.&Apache::lonxml::xmlparse($r,'web',$plot).'</p>'.$/;
1130: $r->print($plotresult);
1.41 matthew 1131: return;
1.42 matthew 1132: }
1133:
1.74 matthew 1134: sub tries_data_plot {
1135: my ($r)=@_;
1136: my $count = scalar(@StatsArray);
1137: my $width = 50 + 10*$count;
1138: $width = 300 if ($width < 300);
1139: my $height = 300;
1140: my $plot = '';
1141: my @STD; my @Mean; my @Max; my @Min;
1142: my @Labels;
1143: my $ymax = 5;
1144: foreach my $data (@StatsArray) {
1145: my $max = $data->{'mean_tries'} + $data->{'std_tries'};
1146: $ymax = $max if ($ymax < $max);
1147: $ymax = $max if ($ymax < $max);
1148: push(@Labels,$data->{'problem_num'});
1149: push(@STD,$data->{'std_tries'});
1150: push(@Mean,$data->{'mean_tries'});
1151: }
1152: #
1153: # Make sure we show relevant information.
1154: my $xmax = $Labels[-1];
1155: if ($xmax > 50) {
1156: if ($xmax % 10 != 0) {
1157: $xmax = 10 * (int($xmax/10)+1);
1158: }
1159: } else {
1160: if ($xmax % 5 != 0) {
1161: $xmax = 5 * (int($xmax/5)+1);
1162: }
1163: }
1164: $ymax = int($ymax)+1+2;
1165: #
1166: my $std_data .= '<data>'.join(',',@Labels).'</data>'.$/.
1167: '<data>'.join(',',@Mean).'</data>'.$/;
1168: #
1169: my $std_error_data .= '<data>'.join(',',@Labels).'</data>'.$/.
1170: '<data>'.join(',',@Mean).'</data>'.$/.
1171: '<data>'.join(',',@STD).'</data>'.$/;
1172: #
1.81 matthew 1173: my $title = 'Mean and S.D. of Tries';
1174: if ($xmax > 25) {
1175: $title = 'Mean and Standard Deviation of Tries';
1176: }
1177: #
1.74 matthew 1178: $plot=<<"END";
1179: <gnuplot
1180: texfont="10"
1181: fgcolor="x000000"
1182: plottype="Cartesian"
1183: font="large"
1184: grid="on"
1185: align="center"
1186: border="on"
1187: transparent="on"
1.81 matthew 1188: alttag="Mean and S.D of Tries Plot"
1.74 matthew 1189: samples="100"
1190: bgcolor="xffffff"
1191: height="$height"
1192: width="$width">
1.81 matthew 1193: <title>$title</title>
1.74 matthew 1194: <axis xmin="0" ymin="0" xmax="$xmax" ymax="$ymax" color="x000000" />
1195: <xlabel>Problem Number</xlabel>
1.81 matthew 1196: <ylabel>Number of Tries</ylabel>
1.74 matthew 1197: <curve
1198: linestyle="yerrorbars"
1199: name="S.D. Tries"
1200: pointtype="1"
1201: color="x666666">
1202: $std_error_data
1203: </curve>
1204: <curve
1205: linestyle="points"
1206: name="Mean Tries"
1207: pointtype="1"
1208: color="xCC4444">
1209: $std_data
1210: </curve>
1211: </gnuplot>
1212: END
1213: my $plotresult =
1214: '<p>'.&Apache::lonxml::xmlparse($r,'web',$plot).'</p>'.$/;
1215: $r->print($plotresult);
1216: return;
1217: }
1218:
1.73 matthew 1219: sub plot_dropdown {
1220: my $current = '';
1221: #
1222: if (defined($ENV{'form.plot'})) {
1223: $current = $ENV{'form.plot'};
1224: }
1225: #
1226: my @Additional_Plots = (
1227: { graphable=>'yes',
1228: name => 'degrees',
1.81 matthew 1229: title => 'Difficulty Indexes' },
1.74 matthew 1230: { graphable=>'yes',
1231: name => 'tries statistics',
1.81 matthew 1232: title => 'Tries Statistics' });
1.73 matthew 1233: #
1234: my $Str= "\n".'<select name="plot" size="1">';
1235: $Str .= '<option name="none"></option>'."\n";
1236: $Str .= '<option name="none2">none</option>'."\n";
1.81 matthew 1237: foreach my $field (@Additional_Plots,@Fields) {
1.73 matthew 1238: if (! exists($field->{'graphable'}) ||
1239: $field->{'graphable'} ne 'yes') {
1240: next;
1241: }
1242: $Str .= '<option value="'.$field->{'name'}.'"';
1243: if ($field->{'name'} eq $current) {
1244: $Str .= ' selected ';
1245: }
1246: $Str.= '>'.&mt($field->{'title'}).'</option>'."\n";
1247: }
1248: $Str .= '</select>'."\n";
1249: return $Str;
1250: }
1251:
1.41 matthew 1252: ###############################################
1253: ###############################################
1.73 matthew 1254: ##
1255: ## Excel output routines
1256: ##
1.41 matthew 1257: ###############################################
1258: ###############################################
1.73 matthew 1259: sub Excel_output {
1.44 matthew 1260: my ($r) = @_;
1.73 matthew 1261: $r->print('<h2>'.&mt('Preparing Excel Spreadsheet').'</h2>');
1262: ##
1263: ## Compute the statistics
1264: &compute_all_statistics($r);
1265: my $c = $r->connection;
1266: return if ($c->aborted());
1267: ##
1268: ## Create the excel workbook
1.44 matthew 1269: my $filename = '/prtspool/'.
1270: $ENV{'user.name'}.'_'.$ENV{'user.domain'}.'_'.
1.73 matthew 1271: time.'_'.rand(1000000000).'.xls';
1.70 matthew 1272: my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
1273: #
1.44 matthew 1274: # Create sheet
1.73 matthew 1275: my $excel_workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1.44 matthew 1276: #
1277: # Check for errors
1278: if (! defined($excel_workbook)) {
1279: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.59 matthew 1280: $r->print(&mt("Problems creating new Excel file. ".
1.44 matthew 1281: "This error has been logged. ".
1.59 matthew 1282: "Please alert your LON-CAPA administrator."));
1.73 matthew 1283: return 0;
1.44 matthew 1284: }
1285: #
1286: # The excel spreadsheet stores temporary data in files, then put them
1287: # together. If needed we should be able to disable this (memory only).
1288: # The temporary directory must be specified before calling 'addworksheet'.
1289: # File::Temp is used to determine the temporary directory.
1290: $excel_workbook->set_tempdir($Apache::lonnet::tmpdir);
1291: #
1292: # Add a worksheet
1293: my $sheetname = $ENV{'course.'.$ENV{'request.course.id'}.'.description'};
1294: if (length($sheetname) > 31) {
1295: $sheetname = substr($sheetname,0,31);
1296: }
1.73 matthew 1297: my $excel_sheet = $excel_workbook->addworksheet(
1298: &Apache::loncommon::clean_excel_name($sheetname));
1.82 matthew 1299: #
1300: my $format = &Apache::loncommon::define_excel_formats($excel_workbook);
1.73 matthew 1301: ##
1302: ## Begin creating excel sheet
1303: ##
1304: my ($rows_output,$cols_output) = (0,0);
1.44 matthew 1305: #
1306: # Put the course description in the header
1307: $excel_sheet->write($rows_output,$cols_output++,
1.82 matthew 1308: $ENV{'course.'.$ENV{'request.course.id'}.'.description'},
1309: $format->{'h1'});
1.44 matthew 1310: $cols_output += 3;
1311: #
1312: # Put a description of the sections listed
1313: my $sectionstring = '';
1.82 matthew 1314: $excel_sheet->write($rows_output,$cols_output++,
1315: &Apache::lonstathelpers::sections_description
1316: (@Apache::lonstatistics::SelectedSections),
1317: $format->{'h3'});
1318: $cols_output += scalar(@Apache::lonstatistics::SelectedSections);
1.44 matthew 1319: #
1.70 matthew 1320: # Time restrictions
1321: my $time_string;
1322: if (defined($starttime)) {
1323: # call localtime but not lonlocal:locallocaltime because excel probably
1324: # cannot handle localized text. Probably.
1325: $time_string .= 'Data collected from '.localtime($time_string);
1326: if (defined($endtime)) {
1327: $time_string .= ' to '.localtime($endtime);
1328: }
1329: $time_string .= '.';
1330: } elsif (defined($endtime)) {
1331: # See note above about lonlocal:locallocaltime
1332: $time_string .= 'Data collected before '.localtime($endtime).'.';
1333: }
1.82 matthew 1334: if (defined($time_string)) {
1335: $excel_sheet->write($rows_output,$cols_output++,$time_string);
1336: $cols_output+= 5;
1337: }
1.70 matthew 1338: #
1.44 matthew 1339: # Put the date in there too
1340: $excel_sheet->write($rows_output,$cols_output++,
1341: 'Compiled on '.localtime(time));
1342: #
1343: $rows_output++;
1344: $cols_output=0;
1.82 matthew 1345: ##
1346: ## Sequence Statistics
1347: ##
1348: &write_headers($excel_sheet,$format,\$rows_output,\$cols_output,
1349: \@SeqFields);
1.97 matthew 1350: foreach my $seq (@sequences) {
1351: my $data = $SeqStat{$seq->symb};
1.82 matthew 1352: $cols_output=0;
1353: foreach my $field (@SeqFields) {
1354: next if ($field->{'selected'} ne 'yes');
1.85 matthew 1355: my $fieldformat = undef;
1356: if (exists($field->{'excel_format'})) {
1357: $fieldformat = $format->{$field->{'excel_format'}};
1358: }
1.55 matthew 1359: $excel_sheet->write($rows_output,$cols_output++,
1.85 matthew 1360: $data->{$field->{'name'}},$fieldformat);
1.55 matthew 1361: }
1.82 matthew 1362: $rows_output++;
1363: $cols_output=0;
1.55 matthew 1364: }
1.82 matthew 1365: ##
1366: ## Resource Statistics
1367: ##
1.55 matthew 1368: $rows_output++;
1369: $cols_output=0;
1.82 matthew 1370: &write_headers($excel_sheet,$format,\$rows_output,\$cols_output,
1371: \@Fields);
1372: #
1.73 matthew 1373: foreach my $data (@StatsArray) {
1374: $cols_output=0;
1375: foreach my $field (@Fields) {
1.76 matthew 1376: next if ($field->{'selected'} ne 'yes');
1.73 matthew 1377: next if ($field->{'name'} eq 'problem_num');
1.85 matthew 1378: my $fieldformat = undef;
1379: if (exists($field->{'excel_format'})) {
1380: $fieldformat = $format->{$field->{'excel_format'}};
1381: }
1.73 matthew 1382: $excel_sheet->write($rows_output,$cols_output++,
1.85 matthew 1383: $data->{$field->{'name'}},$fieldformat);
1.44 matthew 1384: }
1.73 matthew 1385: $rows_output++;
1.82 matthew 1386: $cols_output=0;
1.44 matthew 1387: }
1388: #
1389: $excel_workbook->close();
1.73 matthew 1390: #
1.44 matthew 1391: # Tell the user where to get their excel file
1392: $r->print('<br />'.
1.59 matthew 1393: '<a href="'.$filename.'">'.
1394: &mt('Your Excel Spreadsheet').'</a>'."\n");
1.44 matthew 1395: $r->rflush();
1396: return;
1397: }
1398:
1.82 matthew 1399: ##
1400: ## &write_headers
1401: ##
1402: sub write_headers {
1403: my ($excel_sheet,$format,$rows_output,$cols_output,$Fields) = @_;
1404: ##
1405: ## First the long titles
1406: foreach my $field (@{$Fields}) {
1407: next if ($field->{'name'} eq 'problem_num');
1408: next if ($field->{'selected'} ne 'yes');
1409: if (exists($field->{'long_title'})) {
1410: $excel_sheet->write($$rows_output,${$cols_output},
1411: $field->{'long_title'},
1412: $format->{'bold'});
1413: } else {
1414: $excel_sheet->write($$rows_output,${$cols_output},'');
1415: }
1416: ${$cols_output}+= 1;
1417: }
1418: ${$cols_output} =0;
1419: ${$rows_output}+=1;
1420: ##
1421: ## Then the short titles
1422: foreach my $field (@{$Fields}) {
1423: next if ($field->{'selected'} ne 'yes');
1424: next if ($field->{'name'} eq 'problem_num');
1425: # Use english for excel as I am not sure how well excel handles
1426: # other character sets....
1427: $excel_sheet->write($$rows_output,$$cols_output,
1428: $field->{'title'},
1429: $format->{'bold'});
1430: $$cols_output+=1;
1431: }
1432: ${$cols_output} =0;
1433: ${$rows_output}+=1;
1434: return;
1435: }
1436:
1.73 matthew 1437: ##################################################
1438: ##################################################
1439: ##
1440: ## Statistics Gathering and Manipulation Routines
1441: ##
1442: ##################################################
1443: ##################################################
1444: sub compute_statistics_on_sequence {
1445: my ($seq) = @_;
1446: my @Data;
1.97 matthew 1447: foreach my $res (&Apache::lonstathelpers::get_resources($navmap,$seq)) {
1448: foreach my $part (@{$res->parts}) {
1449: next if ($res->is_survey($part));
1.73 matthew 1450: #
1451: # This is where all the work happens
1452: my $data = &get_statistics($seq,$res,$part,scalar(@StatsArray)+1);
1453: push (@Data,$data);
1454: push (@StatsArray,$data);
1.49 matthew 1455: }
1.26 stredwic 1456: }
1.73 matthew 1457: return @Data;
1.41 matthew 1458: }
1.26 stredwic 1459:
1.73 matthew 1460: sub compute_all_statistics {
1461: my ($r) = @_;
1462: if (@StatsArray > 0) {
1463: # Assume we have already computed the statistics
1464: return;
1465: }
1466: my $c = $r->connection;
1.97 matthew 1467: foreach my $seq (@sequences) {
1.73 matthew 1468: last if ($c->aborted);
1.82 matthew 1469: &compute_sequence_statistics($seq);
1.73 matthew 1470: &compute_statistics_on_sequence($seq);
1.49 matthew 1471: }
1472: }
1473:
1.73 matthew 1474: sub sort_data {
1475: my ($sortkey) = @_;
1476: return if (! @StatsArray);
1.45 matthew 1477: #
1.73 matthew 1478: # Sort the data
1479: my $sortby = undef;
1.49 matthew 1480: foreach my $field (@Fields) {
1.73 matthew 1481: if ($sortkey eq $field->{'name'}) {
1482: $sortby = $field->{'name'};
1.45 matthew 1483: }
1.26 stredwic 1484: }
1.73 matthew 1485: if (! defined($sortby) || $sortby eq '' || $sortby eq 'problem_num') {
1486: $sortby = 'container';
1487: }
1488: if ($sortby ne 'container') {
1489: # $sortby is already defined, so we can charge ahead
1490: if ($sortby =~ /^(title|part)$/i) {
1491: # Alpha comparison
1492: @StatsArray = sort {
1493: lc($a->{$sortby}) cmp lc($b->{$sortby}) ||
1494: lc($a->{'title'}) cmp lc($b->{'title'}) ||
1495: lc($a->{'part'}) cmp lc($b->{'part'});
1496: } @StatsArray;
1.24 stredwic 1497: } else {
1.73 matthew 1498: # Numerical comparison
1499: @StatsArray = sort {
1500: my $retvalue = 0;
1501: if ($b->{$sortby} eq 'nan') {
1502: if ($a->{$sortby} ne 'nan') {
1503: $retvalue = -1;
1504: } else {
1505: $retvalue = 0;
1506: }
1507: }
1508: if ($a->{$sortby} eq 'nan') {
1509: if ($b->{$sortby} ne 'nan') {
1510: $retvalue = 1;
1511: }
1512: }
1513: if ($retvalue eq '0') {
1514: $retvalue = $b->{$sortby} <=> $a->{$sortby} ||
1515: lc($a->{'title'}) <=> lc($b->{'title'}) ||
1516: lc($a->{'part'}) <=> lc($b->{'part'});
1517: }
1518: $retvalue;
1519: } @StatsArray;
1.24 stredwic 1520: }
1521: }
1.45 matthew 1522: #
1.73 matthew 1523: # Renumber the data set
1524: my $count;
1525: foreach my $data (@StatsArray) {
1526: $data->{'problem_num'} = ++$count;
1527: }
1.24 stredwic 1528: return;
1.48 matthew 1529: }
1530:
1.70 matthew 1531: ########################################################
1532: ########################################################
1533:
1534: =pod
1535:
1536: =item &get_statistics()
1537:
1538: Wrapper routine from the call to loncoursedata::get_problem_statistics.
1.73 matthew 1539: Calls lonstathelpers::get_time_limits() to limit the data set by time
1540: and &compute_discrimination_factor
1.70 matthew 1541:
1542: Inputs: $sequence, $resource, $part, $problem_num
1543:
1544: Returns: Hash reference with statistics data from
1545: loncoursedata::get_problem_statistics.
1546:
1547: =cut
1548:
1549: ########################################################
1550: ########################################################
1.48 matthew 1551: sub get_statistics {
1.49 matthew 1552: my ($sequence,$resource,$part,$problem_num) = @_;
1.48 matthew 1553: #
1.70 matthew 1554: my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
1.97 matthew 1555: my $symb = $resource->symb;
1.48 matthew 1556: my $courseid = $ENV{'request.course.id'};
1557: #
1.49 matthew 1558: my $data = &Apache::loncoursedata::get_problem_statistics
1.66 matthew 1559: (\@Apache::lonstatistics::SelectedSections,
1560: $Apache::lonstatistics::enrollment_status,
1.70 matthew 1561: $symb,$part,$courseid,$starttime,$endtime);
1.85 matthew 1562: $data->{'symb'} = $symb;
1.49 matthew 1563: $data->{'part'} = $part;
1564: $data->{'problem_num'} = $problem_num;
1.97 matthew 1565: $data->{'container'} = $sequence->compTitle;
1566: $data->{'title'} = $resource->compTitle;
1567: $data->{'title.link'} = $resource->src.'?symb='.
1568: &Apache::lonnet::escape($resource->symb);
1.49 matthew 1569: #
1.76 matthew 1570: if ($SelectedFields{'deg_of_disc'}) {
1571: $data->{'deg_of_disc'} =
1572: &compute_discrimination_factor($resource,$part,$sequence);
1573: }
1.83 matthew 1574: #
1575: # Store in metadata if computations were done for all students
1.84 matthew 1576: if ($data->{'num_students'} > 1) {
1577: my @Sections = @Apache::lonstatistics::SelectedSections;
1578: my $sections = '"'.join(' ',@Sections).'"';
1579: $sections =~ s/&+/_/g; # Ensure no special characters
1580: $data->{'sections'}=$sections;
1581: $data->{'course'} = $ENV{'request.course.id'};
1.97 matthew 1582: my $urlres=(&Apache::lonnet::decode_symb($resource->symb))[2];
1.84 matthew 1583: $data->{'urlres'}=$urlres;
1584: my %storestats =
1585: &LONCAPA::lonmetadata::dynamic_metadata_storage($data);
1.83 matthew 1586: my ($dom,$user) = $urlres=~/^(\w+)\/(\w+)/;
1587: &Apache::lonnet::put('nohist_resevaldata',\%storestats,$dom,$user);
1588: }
1.85 matthew 1589: #
1.95 matthew 1590: $data->{'tries_per_correct'} = $data->{'tries'} /
1591: ($data->{'num_solved'}+0.1);
1592: #
1.85 matthew 1593: # Get the due date for research purposes (commented out most of the time)
1594: # $data->{'duedate'} =
1595: # &Apache::lonnet::EXT('resource.'.$part.'.duedate',$symb);
1596: # $data->{'opendate'} =
1597: # &Apache::lonnet::EXT('resource.'.$part.'.opendate',$symb);
1.94 matthew 1598: # $data->{'maxtries'} =
1599: # &Apache::lonnet::EXT('resource.'.$part.'.maxtries',$symb);
1600: # $data->{'hinttries'} =
1601: # &Apache::lonnet::EXT('resource.'.$part.'.hinttries',$symb);
1.98 ! matthew 1602: $data->{'weight'} =
! 1603: &Apache::lonnet::EXT('resource.'.$part.'.weight',$symb);
1.86 matthew 1604: # $data->{'resptypes'} = join(',',@{$resource->{'partdata'}->{$part}->{'ResponseTypes'}});
1.49 matthew 1605: return $data;
1.71 matthew 1606: }
1607:
1608: ###############################################
1609: ###############################################
1610:
1611: =pod
1612:
1613: =item &compute_discrimination_factor()
1614:
1615: Inputs: $Resource, $Sequence
1616:
1617: Returns: integer between -1 and 1
1618:
1619: =cut
1620:
1621: ###############################################
1622: ###############################################
1623: sub compute_discrimination_factor {
1.97 matthew 1624: my ($resource,$part,$seq) = @_;
1625: my $symb = $resource->symb;
1.71 matthew 1626: my @Resources;
1.97 matthew 1627: foreach my $res (&Apache::lonstathelpers::get_resources($navmap,$seq)){
1628: next if ($res->symb eq $symb);
1629: push (@Resources,$res->symb);
1.71 matthew 1630: }
1631: #
1632: # rank
1.83 matthew 1633: my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
1.71 matthew 1634: my $ranking =
1635: &Apache::loncoursedata::rank_students_by_scores_on_resources
1636: (\@Resources,
1637: \@Apache::lonstatistics::SelectedSections,
1.83 matthew 1638: $Apache::lonstatistics::enrollment_status,undef,
1639: $starttime,$endtime);
1.71 matthew 1640: #
1641: # compute their percent scores on the problems in the sequence,
1642: my $number_to_grab = int(scalar(@{$ranking})/4);
1643: my $num_students = scalar(@{$ranking});
1644: my @BottomSet = map { $_->[&Apache::loncoursedata::RNK_student()];
1645: } @{$ranking}[0..$number_to_grab];
1646: my @TopSet =
1647: map {
1648: $_->[&Apache::loncoursedata::RNK_student()];
1649: } @{$ranking}[($num_students-$number_to_grab)..($num_students-1)];
1.91 matthew 1650: if (! @BottomSet || (@BottomSet == 1 && $BottomSet[0] eq '') ||
1651: ! @TopSet || (@TopSet == 1 && $TopSet[0] eq '')) {
1652: return 'nan';
1653: }
1.71 matthew 1654: my ($bottom_sum,$bottom_max) =
1.97 matthew 1655: &Apache::loncoursedata::get_sum_of_scores($symb,$part,\@BottomSet,
1.83 matthew 1656: undef,$starttime,$endtime);
1.71 matthew 1657: my ($top_sum,$top_max) =
1.97 matthew 1658: &Apache::loncoursedata::get_sum_of_scores($symb,$part,\@TopSet,
1.83 matthew 1659: undef,$starttime,$endtime);
1.71 matthew 1660: my $deg_of_disc;
1661: if ($top_max == 0 || $bottom_max==0) {
1662: $deg_of_disc = 'nan';
1663: } else {
1664: $deg_of_disc = ($top_sum/$top_max) - ($bottom_sum/$bottom_max);
1665: }
1666: #&Apache::lonnet::logthis(' '.$top_sum.'/'.$top_max.
1667: # ' - '.$bottom_sum.'/'.$bottom_max);
1668: return $deg_of_disc;
1.1 stredwic 1669: }
1.12 minaeibi 1670:
1.45 matthew 1671: ###############################################
1672: ###############################################
1.79 matthew 1673: ##
1674: ## Compute KR-21
1675: ##
1676: ## To compute KR-21, you need the following information:
1677: ##
1678: ## K=the number of items in your test
1679: ## M=the mean score on the test
1680: ## s=the standard deviation of the scores on your test
1681: ##
1682: ## then:
1683: ##
1684: ## KR-21 rk= [K/(K-1)] * [1- (M*(K-M))/(K*s^2))]
1685: ##
1686: ###############################################
1687: ###############################################
1688: sub compute_sequence_statistics {
1689: my ($seq) = @_;
1.97 matthew 1690: my $symb = $seq->symb;
1.79 matthew 1691: my @Resources;
1.97 matthew 1692: my $part_count;
1693: foreach my $res (&Apache::lonstathelpers::get_resources($navmap,$seq)) {
1694: push (@Resources,$res->symb);
1695: $part_count += scalar(@{$res->parts});
1.79 matthew 1696: }
1697: my ($starttime,$endtime) = &Apache::lonstathelpers::get_time_limits();
1698: #
1699: # First compute statistics based on student scores
1700: my ($smin,$smax,$sMean,$sSTD,$scount,$sMAX) =
1701: &Apache::loncoursedata::score_stats
1702: (\@Apache::lonstatistics::SelectedSections,
1703: $Apache::lonstatistics::enrollment_status,
1704: \@Resources,$starttime,$endtime,undef);
1.97 matthew 1705: $SeqStat{$symb}->{'title'} = $seq->compTitle;
1.79 matthew 1706: $SeqStat{$symb}->{'scoremax'} = $smax;
1707: $SeqStat{$symb}->{'scoremin'} = $smin;
1708: $SeqStat{$symb}->{'scoremean'} = $sMean;
1709: $SeqStat{$symb}->{'scorestd'} = $sSTD;
1710: $SeqStat{$symb}->{'scorecount'} = $scount;
1711: $SeqStat{$symb}->{'max_possible'} = $sMAX;
1712: #
1713: # Compute statistics based on the number of correct problems
1714: # 'correct' is taken to mean
1715: my ($cmin,$cmax,$cMean,$cSTD,$ccount)=
1716: &Apache::loncoursedata::count_stats
1717: (\@Apache::lonstatistics::SelectedSections,
1718: $Apache::lonstatistics::enrollment_status,
1719: \@Resources,$starttime,$endtime,undef);
1.97 matthew 1720: my $K = $part_count;
1.79 matthew 1721: my $kr_21;
1722: if ($K > 1 && $cSTD > 0) {
1723: $kr_21 = ($K/($K-1)) * (1 - $cMean*($K-$cMean)/($K*$cSTD**2));
1724: } else {
1725: $kr_21 = 'nan';
1726: }
1727: $SeqStat{$symb}->{'countmax'} = $cmax;
1728: $SeqStat{$symb}->{'countmin'} = $cmin;
1729: $SeqStat{$symb}->{'countstd'} = $cSTD;
1.82 matthew 1730: $SeqStat{$symb}->{'countmean'} = $cMean;
1.79 matthew 1731: $SeqStat{$symb}->{'count'} = $ccount;
1732: $SeqStat{$symb}->{'items'} = $K;
1733: $SeqStat{$symb}->{'KR-21'}=$kr_21;
1734: return;
1735: }
1736:
1737:
1.47 matthew 1738:
1739: =pod
1740:
1.73 matthew 1741: =item ProblemStatisticsLegend
1742:
1743: =over 4
1744:
1745: =item #Stdnts
1746: Total number of students attempted the problem.
1747:
1748: =item Tries
1749: Total number of tries for solving the problem.
1.59 matthew 1750:
1.73 matthew 1751: =item Max Tries
1752: Largest number of tries for solving the problem by a student.
1753:
1754: =item Mean
1755: Average number of tries. [ Tries / #Stdnts ]
1756:
1757: =item #YES
1758: Number of students solved the problem correctly.
1759:
1760: =item #yes
1761: Number of students solved the problem by override.
1762:
1763: =item %Wrong
1764: Percentage of students who tried to solve the problem
1765: but is still incorrect. [ 100*((#Stdnts-(#YES+#yes))/#Stdnts) ]
1766:
1767: =item DoDiff
1768: Degree of Difficulty of the problem.
1769: [ 1 - ((#YES+#yes) / Tries) ]
1770:
1771: =item S.D.
1772: Standard Deviation of the tries.
1773: [ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1)
1774: where Xi denotes every student\'s tries ]
1775:
1776: =item Skew.
1777: Skewness of the students tries.
1778: [(sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3)]
1779:
1780: =item Dis.F.
1781: Discrimination Factor: A Standard for evaluating the
1782: problem according to a Criterion<br>
1783:
1784: =item [Criterion to group students into %27 Upper Students -
1785: and %27 Lower Students]
1786: 1st Criterion for Sorting the Students:
1787: Sum of Partial Credit Awarded / Total Number of Tries
1788: 2nd Criterion for Sorting the Students:
1789: Total number of Correct Answers / Total Number of Tries
1790:
1791: =item Disc.
1792: Number of Students had at least one discussion.
1793:
1794: =back
1.47 matthew 1795:
1796: =cut
1.73 matthew 1797:
1798: ############################################################
1799: ############################################################
1.4 minaeibi 1800:
1.1 stredwic 1801: 1;
1802: __END__
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>