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