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