Annotation of loncom/interface/lonstatistics.pm, revision 1.156.2.2
1.1 albertel 1: # The LearningOnline Network with CAPA
2: #
1.156.2.2! raeburn 3: # $Id: lonstatistics.pm,v 1.156.2.1 2012/05/10 18:47:29 raeburn Exp $
1.1 albertel 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
1.14 minaeibi 28: #
1.1 albertel 29: ###
30:
1.59 matthew 31:
32:
1.55 minaeibi 33: package Apache::lonstatistics;
1.1 albertel 34:
1.30 stredwic 35: use strict;
1.1 albertel 36: use Apache::Constants qw(:common :http);
1.61 matthew 37: use vars qw(
38: @FullClasslist
39: @Students
1.130 raeburn 40: @Sections
41: @Groups
1.61 matthew 42: %StudentData
43: @StudentDataOrder
44: @SelectedStudentData
1.94 matthew 45: $enrollment_status);
1.61 matthew 46:
1.123 albertel 47: use Apache::lonnet;
1.1 albertel 48: use Apache::lonhomework;
1.12 minaeibi 49: use Apache::loncommon;
1.29 stredwic 50: use Apache::loncoursedata;
51: use Apache::lonhtmlcommon;
1.97 matthew 52: use Apache::lonmysql;
53: use Apache::lonlocal;
1.135 raeburn 54: use Apache::longroup;
1.97 matthew 55: use Time::HiRes;
56: #
57: # Statistics Packages
1.61 matthew 58: use Apache::lonproblemanalysis();
1.89 matthew 59: use Apache::lonsubmissiontimeanalysis();
1.94 matthew 60: use Apache::loncorrectproblemplot();
1.61 matthew 61: use Apache::lonproblemstatistics();
62: use Apache::lonstudentassessment();
1.49 stredwic 63: use Apache::lonpercentage;
1.97 matthew 64: use Apache::lonstudentsubmissions();
1.104 matthew 65: use Apache::lonsurveyreports();
1.128 albertel 66: use Apache::longradinganalysis();
1.154 www 67: use Apache::lonquickgrades();
1.136 www 68: use LONCAPA;
1.60 matthew 69:
70: #
71: # Classlist variables
72: #
1.59 matthew 73: my $curr_student;
74: my $prev_student;
75: my $next_student;
76:
1.61 matthew 77:
1.59 matthew 78: sub clear_classlist_variables {
79: undef(@FullClasslist);
80: undef(@Students);
81: undef(@Sections);
1.130 raeburn 82: undef(@Groups);
1.61 matthew 83: undef(%StudentData);
84: undef(@SelectedStudentData);
1.59 matthew 85: undef($curr_student);
86: undef($prev_student);
87: undef($next_student);
88: }
89:
1.130 raeburn 90:
1.59 matthew 91: sub PrepareClasslist {
92: my %Sections;
93: &clear_classlist_variables();
94: #
95: # Retrieve the classlist
1.123 albertel 96: my $cid = $env{'request.course.id'};
97: my $cdom = $env{'course.'.$cid.'.domain'};
98: my $cnum = $env{'course.'.$cid.'.num'};
1.125 albertel 99: my ($classlist,$field_names) = &Apache::loncoursedata::get_classlist($cdom,
100: $cnum);
1.119 matthew 101: my @selected_sections = &get_selected_sections();
1.130 raeburn 102: my @selected_groups = &get_selected_groups();
1.61 matthew 103: #
1.69 matthew 104: # Deal with instructors with restricted section access
1.123 albertel 105: if ($env{'request.course.sec'} !~ /^\s*$/) {
106: @selected_sections = ($env{'request.course.sec'});
1.69 matthew 107: }
108: #
1.61 matthew 109: # Set up %StudentData
1.130 raeburn 110: @StudentDataOrder = qw/fullname username domain id section status groups comments/;
1.61 matthew 111: foreach my $field (@StudentDataOrder) {
1.108 matthew 112: $StudentData{$field}->{'title'} = &mt($field);
113: $StudentData{$field}->{'base_width'} = length(&mt($field));
1.61 matthew 114: $StudentData{$field}->{'width'} =
115: $StudentData{$field}->{'base_width'};
116: }
1.59 matthew 117: #
1.68 matthew 118: # get the status requested
1.94 matthew 119: $enrollment_status = 'Active';
1.123 albertel 120: $enrollment_status = $env{'form.Status'} if (exists($env{'form.Status'}));
1.68 matthew 121: #
1.130 raeburn 122: # Get groupmembership
1.133 albertel 123: my ($classgroups,$studentgroups);
1.135 raeburn 124: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
1.133 albertel 125: if (%curr_groups) {
1.130 raeburn 126: ($classgroups,$studentgroups) =
1.133 albertel 127: &Apache::loncoursedata::get_group_memberships($classlist,
1.134 raeburn 128: $field_names,
1.133 albertel 129: $cdom,$cnum);
1.130 raeburn 130: }
131: my $now = time;
132:
1.59 matthew 133: # Process the classlist
134: while (my ($student,$student_data) = each (%$classlist)) {
135: my $studenthash = ();
136: for (my $i=0; $i< scalar(@$field_names);$i++) {
1.61 matthew 137: my $field = $field_names->[$i];
138: # Store the data
139: $studenthash->{$field}=$student_data->[$i];
140: # Keep track of the width of the fields
141: next if (! exists($StudentData{$field}));
1.63 matthew 142: my $length = length($student_data->[$i]);
1.61 matthew 143: if ($StudentData{$field}->{'width'} < $length) {
144: $StudentData{$field}->{'width'} = $length;
145: }
1.59 matthew 146: }
1.130 raeburn 147: my @studentsgroups = &Apache::loncoursedata::get_students_groups
148: ($student,$enrollment_status,
149: $classgroups);
150: if (@studentsgroups) {
151: $studenthash->{'groups'} = join(', ',@studentsgroups);
152: $studenthash->{'groupref'} = \@studentsgroups;
153: } else {
154: $studenthash->{'groups'} = 'none';
155: $studenthash->{'groupref'} = [];
156: }
1.59 matthew 157: push (@FullClasslist,$studenthash);
158: #
159: # Build up a list of sections
160: my $section = $studenthash->{'section'};
1.60 matthew 161: if (! defined($section) || $section =~/^\s*$/ || $section == -1) {
162: $studenthash->{'section'} = 'none';
163: $section = $studenthash->{'section'};
164: }
1.59 matthew 165: $Sections{$section}++;
166: #
167: # Only put in the list those students we are interested in
1.119 matthew 168: foreach my $sect (@selected_sections) {
1.68 matthew 169: if ( (($sect eq 'all') ||
170: ($section eq $sect)) &&
1.94 matthew 171: (($studenthash->{'status'} eq $enrollment_status) ||
172: ($enrollment_status eq 'Any'))
1.68 matthew 173: ){
1.130 raeburn 174: my $groupcheck = 0;
1.131 albertel 175: if (grep(/^all$/,@selected_groups)) {
176: push(@Students,$studenthash);
1.130 raeburn 177: last;
1.131 albertel 178: } elsif (grep(/^none$/,@selected_groups)) {
1.130 raeburn 179: if ($studenthash->{'groups'} eq 'none') {
1.131 albertel 180: push(@Students,$studenthash);
1.130 raeburn 181: last;
182: }
183: } else {
184: foreach my $group (@selected_groups) {
1.131 albertel 185: if (grep(/^$group$/,@studentsgroups)) {
186: push(@Students,$studenthash);
1.130 raeburn 187: $groupcheck = 1;
188: last;
189: }
190: }
191: if ($groupcheck) {
192: last;
193: }
194: }
1.60 matthew 195: }
1.59 matthew 196: }
197: }
198: #
199: # Put the consolidated section data in the right place
1.123 albertel 200: if ($env{'request.course.sec'} !~ /^\s*$/) {
201: @Sections = ($env{'request.course.sec'});
1.69 matthew 202: } else {
1.138 albertel 203: @Sections = sort {
204: if ($a == $a && $b == $b ) { return $a <=> $b; }
205: return $a cmp $b;
206: } keys(%Sections);
207:
1.69 matthew 208: unshift(@Sections,'all'); # Put 'all' at the front of the list
209: }
1.130 raeburn 210: # Sort the groups
211: @Groups = sort {$a cmp $b} keys(%{$studentgroups});
212: unshift(@Groups,'all'); # Put 'all' at the front of the list
213:
1.59 matthew 214: #
215: # Sort the Students
216: my $sortby = 'fullname';
1.123 albertel 217: $sortby = $env{'form.sort'} if (exists($env{'form.sort'}));
1.127 albertel 218: my @TmpStudents = sort { lc($a->{$sortby}) cmp lc($b->{$sortby}) ||
1.126 albertel 219: lc($a->{'fullname'}) cmp lc($b->{'fullname'}) ||
220: lc($a->{'username'}) cmp lc($b->{'username'}) } @Students;
1.60 matthew 221: @Students = @TmpStudents;
1.59 matthew 222: #
223: # Now deal with that current student thing....
1.72 matthew 224: $curr_student = undef;
1.123 albertel 225: if (exists($env{'form.SelectedStudent'})) {
1.59 matthew 226: my ($current_uname,$current_dom) =
1.123 albertel 227: split(':',$env{'form.SelectedStudent'});
1.59 matthew 228: my $i;
229: for ($i = 0; $i<=$#Students; $i++) {
230: next if (($Students[$i]->{'username'} ne $current_uname) ||
231: ($Students[$i]->{'domain'} ne $current_dom));
1.60 matthew 232: $curr_student = $Students[$i];
1.59 matthew 233: last; # If we get here, we have our student.
234: }
1.72 matthew 235: if (defined($curr_student)) {
236: if ($i == 0) {
237: $prev_student = undef;
238: } else {
239: $prev_student = $Students[$i-1];
240: }
241: if ($i == $#Students) {
242: $next_student = undef;
243: } else {
244: $next_student = $Students[$i+1];
245: }
1.59 matthew 246: }
247: }
1.61 matthew 248: #
1.123 albertel 249: if (exists($env{'form.StudentData'})) {
1.124 albertel 250: @SelectedStudentData =
251: &Apache::loncommon::get_env_multiple('form.StudentData');
1.61 matthew 252: } else {
1.72 matthew 253: @SelectedStudentData = ('username');
1.61 matthew 254: }
255: foreach (@SelectedStudentData) {
256: if ($_ eq 'all') {
257: @SelectedStudentData = ('all');
258: last;
259: }
260: }
261: #
262: return;
263: }
264:
1.119 matthew 265:
266: sub get_selected_sections {
1.124 albertel 267: my @selected_sections =
268: &Apache::loncommon::get_env_multiple('form.Section');
1.119 matthew 269: @selected_sections = ('all') if (! @selected_sections);
270: foreach (@selected_sections) {
271: if ($_ eq 'all') {
272: @selected_sections = ('all');
273: }
274: }
275: #
276: # Deal with instructors with restricted section access
1.123 albertel 277: if ($env{'request.course.sec'} !~ /^\s*$/) {
278: @selected_sections = ($env{'request.course.sec'});
1.119 matthew 279: }
280: return @selected_sections;
281: }
282:
1.144 jms 283:
1.130 raeburn 284: sub get_selected_groups {
285: my @selected_groups =
286: &Apache::loncommon::get_env_multiple('form.Group');
287: @selected_groups = ('all') if (! @selected_groups);
288: foreach my $grp (@selected_groups) {
289: if ($grp eq 'all') {
290: @selected_groups = ('all');
291: last;
292: }
293: }
294: return @selected_groups;
295: }
296:
1.122 matthew 297:
1.119 matthew 298:
299: sub section_and_enrollment_description {
1.122 matthew 300: my ($mode) = @_;
301: if (! defined($mode)) { $mode = 'localized'; }
1.119 matthew 302: my @sections = &Apache::lonstatistics::get_selected_sections();
1.130 raeburn 303: my @groups = &Apache::lonstatistics::get_selected_groups();
1.122 matthew 304: my $description;
305: if ($mode eq 'localized') {
1.137 raeburn 306: $description = &mt('Unable to determine section, groups and access status');
1.122 matthew 307: } elsif ($mode eq 'plaintext') {
1.137 raeburn 308: $description = 'Unable to determine section, groups and access status';
1.122 matthew 309: } else {
310: $description = 'Bad parameter passed to lonstatistics::section_and_enrollment_description';
311: &Apache::lonnet::logthis($description);
312: }
1.130 raeburn 313: $description = §ion_or_group_text($mode,'section',@sections).
1.131 albertel 314: ' '.§ion_or_group_text($mode,'group',@groups);
1.130 raeburn 315: if ($mode eq 'localized') {
1.142 bisitz 316: $description .= ' '.&mt($env{'form.Status'}.' access status.');
1.130 raeburn 317: } elsif ($mode eq 'plaintext') {
1.137 raeburn 318: $description .= ' '.$env{'form.Status'}.' access status.';
1.130 raeburn 319: }
320: return $description;
321: }
322:
1.144 jms 323:
324:
1.130 raeburn 325:
326: sub section_or_group_text {
327: my ($mode,$type,@items) = @_;
328: my $text;
329: my %phrases = ();
330: %{$phrases{'section'}} = (
331: single => 'Section',
332: all => 'All sections',
333: plural => 'Sections',
334: );
335: %{$phrases{'group'}} = (
336: single => 'Group',
337: all => 'All groups',
338: plural => 'Groups',
339: );
340: if (scalar(@items) == 1 && $items[0] ne 'all') {
1.122 matthew 341: if ($mode eq 'localized') {
1.142 bisitz 342: $text = &mt($phrases{$type}{single}.' [_1].',$items[0]);
1.122 matthew 343: } elsif ($mode eq 'plaintext') {
1.130 raeburn 344: $text = $phrases{$type}{single}.' '.$items[0].'.';
345:
1.122 matthew 346: }
1.130 raeburn 347: } elsif (scalar(@items) && $items[0] eq 'all') {
1.122 matthew 348: if ($mode eq 'localized') {
1.142 bisitz 349: $text = &mt($phrases{$type}{all}.'.');
1.122 matthew 350: } elsif ($mode eq 'plaintext') {
1.130 raeburn 351: $text = $phrases{$type}{all}.'.';
1.122 matthew 352: }
1.130 raeburn 353: } elsif (scalar(@items)) {
354: my $lastitem = pop(@items);
1.122 matthew 355: if ($mode eq 'localized') {
1.142 bisitz 356: $text = &mt($phrases{$type}{plural}.' [_1] and [_2].',
1.130 raeburn 357: join(', ',@items),$lastitem);
1.122 matthew 358: } elsif ($mode eq 'plaintext') {
1.130 raeburn 359: $text = $phrases{$type}{plural}.' '.join(', ',@items).' and '.
360: $lastitem.'.';
1.122 matthew 361: }
1.119 matthew 362: }
1.130 raeburn 363: return $text;
1.119 matthew 364: }
1.71 matthew 365:
366:
367: sub get_students {
368: if (! @Students) {
369: &PrepareClasslist()
370: }
371: return @Students;
372: }
373:
1.61 matthew 374:
375:
376: sub current_student {
1.72 matthew 377: return $curr_student;
1.61 matthew 378: }
379:
380:
381:
382: sub previous_student {
1.72 matthew 383: return $prev_student;
1.59 matthew 384: }
385:
1.61 matthew 386:
387:
388: sub next_student {
1.72 matthew 389: return $next_student;
1.61 matthew 390: }
1.60 matthew 391:
392:
393:
1.61 matthew 394: sub StudentDataSelect {
395: my ($elementname,$status,$numvisible)=@_;
396: if ($numvisible < 1) {
397: return;
398: }
399: #
400: # Build the form element
401: my $Str = "\n";
402: $Str .= '<select name="'.$elementname.'" ';
403: if ($status ne 'single') {
1.147 bisitz 404: $Str .= 'multiple="multiple" ';
1.61 matthew 405: }
406: $Str .= 'size="'.$numvisible.'" >'."\n";
407: #
408: # Deal with 'all'
1.149 bisitz 409: $Str .= ' <option value="all"';
1.61 matthew 410: foreach (@SelectedStudentData) {
411: if ($_ eq 'all') {
1.149 bisitz 412: $Str .= ' selected="selected"';
1.61 matthew 413: last;
414: }
415: }
1.155 bisitz 416: $Str .= '>'.&mt('all')."</option>\n";
1.61 matthew 417: #
418: # Loop through the student data fields
419: foreach my $item (@StudentDataOrder) {
1.149 bisitz 420: $Str .= ' <option value="'.$item.'"';
1.61 matthew 421: foreach (@SelectedStudentData) {
422: if ($item eq $_ ) {
1.149 bisitz 423: $Str .= ' selected="selected"';
1.61 matthew 424: last;
425: }
426: }
1.155 bisitz 427: $Str .= '>'.&mt($item)."</option>\n";
1.61 matthew 428: }
429: $Str .= "</select>\n";
430: return $Str;
1.60 matthew 431: }
432:
1.115 matthew 433:
434:
435: sub get_selected_maps {
436: my ($elementname) = @_;
1.124 albertel 437: my @selected_maps =
438: &Apache::loncommon::get_env_multiple('form.'.$elementname);
439: @selected_maps = ('all') if (! @selected_maps);
1.118 matthew 440: foreach my $map (@selected_maps) {
441: if ($map eq 'all') {
442: @selected_maps = ('all');
443: last;
444: }
445: }
1.115 matthew 446: return @selected_maps;
447: }
448:
449:
450:
451:
1.116 matthew 452: sub selected_sequences_with_assessments {
1.115 matthew 453: my ($mode) = @_;
454: $mode = 'selected' if (! defined($mode));
455: my $navmap = Apache::lonnavmaps::navmap->new();
456: if (!defined($navmap)) {
457: return ('Can not open Coursemap');
458: }
459: #
460: my @sequences = $navmap->retrieveResources(undef,
461: sub { shift->is_map(); },1,0,1);
1.139 raeburn 462: my $toplevelseq = $navmap->getById('0.0');
463: if (!grep(/^\Q$toplevelseq\E$/,@sequences)) {
464: unshift(@sequences,$toplevelseq);
465: }
466:
1.115 matthew 467: my @sequences_with_assessments;
1.139 raeburn 468: foreach my $sequence (@sequences) {
1.120 matthew 469: if ($navmap->hasResource($sequence,sub { shift->is_problem(); },0,1)){
1.115 matthew 470: push(@sequences_with_assessments,$sequence);
471: }
472: }
473: #
474: my @sequences_to_show;
475: foreach my $sequence (@sequences_with_assessments) {
476: if ($mode eq 'all') {
477: push (@sequences_to_show,$sequence);
478: } elsif ($mode eq 'selected') {
1.116 matthew 479: foreach my $map_symb (&get_selected_maps('Maps')) {
1.115 matthew 480: if ($sequence->symb eq $map_symb || $map_symb eq 'all'){
481: push (@sequences_to_show,$sequence);
482: last; # Only put it in once
483: }
484: }
485: }
486:
487: }
488: return $navmap,@sequences_to_show;
489: }
490:
1.60 matthew 491:
1.115 matthew 492: sub map_select {
493: my ($elementname,$status,$numvisible)=@_;
1.60 matthew 494: if ($numvisible < 1) {
495: return;
496: }
497: #
498: # Set up array of selected items
1.115 matthew 499: my @selected_maps = &get_selected_maps($elementname);
1.60 matthew 500: #
501: # Build the form element
1.115 matthew 502: my $form = "\n";
503: $form .= '<select name="'.$elementname.'" ';
1.60 matthew 504: if ($status ne 'single') {
1.147 bisitz 505: $form .= 'multiple="multiple" ';
1.60 matthew 506: }
1.115 matthew 507: $form .= 'size="'.$numvisible.'" >'."\n";
1.60 matthew 508: #
1.61 matthew 509: # Put in option for 'all'
1.149 bisitz 510: $form .= ' <option value="all"';
1.118 matthew 511: if ($selected_maps[0] eq 'all') {
1.149 bisitz 512: $form .= ' selected="selected"';
1.61 matthew 513: }
1.115 matthew 514: $form .= ">all</option>\n";
1.61 matthew 515: #
1.60 matthew 516: # Loop through the sequences
1.117 matthew 517: my @sequences = &selected_sequences_with_assessments('all');
1.115 matthew 518: my $navmap;
519: if (!ref($sequences[0])) {
520: return $sequences[0];
521: } else {
522: $navmap = shift(@sequences);
523: }
524: foreach my $seq (@sequences){
1.149 bisitz 525: $form .= ' <option value="'.$seq->symb.'"';
1.115 matthew 526: foreach (@selected_maps) {
527: if ($seq->symb eq $_) {
1.149 bisitz 528: $form .= ' selected="selected"';
1.60 matthew 529: last;
530: }
531: }
1.115 matthew 532: $form .= '>'.$seq->compTitle."</option>\n";
1.60 matthew 533: }
1.115 matthew 534: $form .= "</select>\n";
535: return $form;
1.60 matthew 536: }
537:
538:
539: sub SectionSelect {
540: my ($elementname,$status,$numvisible)=@_;
541: if ($numvisible < 1) {
542: return;
543: }
544: #
1.71 matthew 545: # Make sure we have the data we need to continue
546: if (! @Sections) {
547: &PrepareClasslist()
548: }
549: #
1.60 matthew 550: # Build the form element
551: my $Str = "\n";
552: $Str .= '<select name="'.$elementname.'" ';
553: if ($status ne 'single') {
1.147 bisitz 554: $Str .= 'multiple="multiple" ';
1.60 matthew 555: }
556: $Str .= 'size="'.$numvisible.'" >'."\n";
557: #
558: # Loop through the sequences
559: foreach my $s (@Sections) {
1.149 bisitz 560: $Str .= ' <option value="'.$s.'"';
1.119 matthew 561: foreach (&get_selected_sections()) {
1.61 matthew 562: if ($s eq $_) {
1.149 bisitz 563: $Str .= ' selected="selected"';
1.60 matthew 564: last;
565: }
566: }
567: $Str .= '>'.$s."</option>\n";
568: }
569: $Str .= "</select>\n";
570: return $Str;
1.80 matthew 571: }
572:
1.144 jms 573:
1.130 raeburn 574: sub GroupSelect {
575: my ($elementname,$status,$numvisible)=@_;
576: if ($numvisible < 1) {
577: return;
578: }
579: #
580: # Make sure we have the data we need to continue
581: if (! @Groups) {
582: &PrepareClasslist();
583: }
584: #
585: # Build the form element
586: my $Str = "\n";
587: $Str .= '<select name="'.$elementname.'" ';
588: if ($status ne 'single') {
1.147 bisitz 589: $Str .= 'multiple="multiple" ';
1.130 raeburn 590: }
591: $Str .= 'size="'.$numvisible.'" >'."\n";
592: #
593: # Loop through the groups
594: foreach my $s (@Groups) {
1.149 bisitz 595: $Str .= ' <option value="'.$s.'"';
1.130 raeburn 596: foreach my $group (&get_selected_groups()) {
597: if ($s eq $group) {
1.149 bisitz 598: $Str .= ' selected="selected"';
1.130 raeburn 599: last;
600: }
601: }
602: $Str .= '>'.$s."</option>\n";
603: }
604: $Str .= "</select>\n";
605: }
606:
607:
1.144 jms 608:
609:
1.60 matthew 610: sub DisplayClasslist {
611: my ($r)=@_;
1.107 matthew 612: &Apache::lonhtmlcommon::add_breadcrumb
613: ({text=>'Select One Student'});
1.60 matthew 614: #
1.105 matthew 615: # Output some of the standard interface components
616: my $Str;
1.132 albertel 617: $Str .= &Apache::lonhtmlcommon::breadcrumbs('Select One Student');
1.105 matthew 618: $Str .= '<p><table cellspacing="5">'."\n";
619: $Str .= '<tr>';
620: $Str .= '<th align="center"><b>'.&mt('Sections').'</b></th>';
1.130 raeburn 621: $Str .= '<th align="center"><b>'.&mt('Groups').'</b></th>';
1.137 raeburn 622: $Str .= '<th align="center"><b>'.&mt('Access Status').'</b></th>';
1.105 matthew 623: $Str .= '</tr>'.$/;
624: $Str .= '<tr>';
625: $Str .= '<td>'.
626: &Apache::lonstatistics::SectionSelect('Section','multiple',5).
627: '</td>';
1.130 raeburn 628: $Str .= '<td>'.
629: &Apache::lonstatistics::GroupSelect('Group','multiple',5).
630: '</td>';
1.105 matthew 631: $Str .= '<td>'.
632: &Apache::lonhtmlcommon::StatusOptions(undef,undef,5).
633: '</td>';
634:
635: $Str .= '</tr>'.$/;
636: $Str .= '</table></p>';
637: $Str .= '<input type="submit" name="selectstudent" value="'.
638: &mt('Update Display').'" />';
639: $r->print($Str);
640: $r->rflush();
641: #
1.130 raeburn 642: my @Fields = ('fullname','username','domain','id','section','status','groups');
1.60 matthew 643: #
1.105 matthew 644: $Str = '';
1.119 matthew 645: my @selected_sections = &get_selected_sections();
1.78 matthew 646: if (! @Students) {
1.119 matthew 647: if ($selected_sections[0] eq 'all') {
1.141 bisitz 648: if (lc($env{'form.Status'}) eq 'active') {
649: $Str .= '<p class="LC_info">'.
1.106 matthew 650: &mt('There are no currently enrolled students in the course.').
1.141 bisitz 651: '</p>';
1.123 albertel 652: } elsif (lc($env{'form.Status'}) eq 'expired') {
1.141 bisitz 653: $Str .= '<p class="LC_info">'.
1.106 matthew 654: &mt('There are no previously enrolled students in the course.').
1.141 bisitz 655: '</p>';
656: } elsif (lc($env{'form.Status'}) eq 'future') {
657: $Str .= '<p class="LC_info">'.
658: &mt('There are no students with future access in the course.').
659: '</p>';
660: } else { # 'any' and any others
661: $Str .= '<p class="LC_info">'.
662: &mt('There are no students in the course.').
663: '</p>';
1.78 matthew 664: }
665: } else {
1.141 bisitz 666: if (lc($env{'form.Status'}) eq 'active') {
667: $Str .= '<p class="LC_info">'.
1.106 matthew 668: &mt('There are no currently enrolled students in the selected sections.').
1.141 bisitz 669: '</p>';
1.123 albertel 670: } elsif (lc($env{'form.Status'}) eq 'expired') {
1.141 bisitz 671: $Str .= '<p class="LC_info">'.
1.106 matthew 672: &mt('There are no previously enrolled students in the selected sections.').
1.141 bisitz 673: '</p>';
674: } elsif (lc($env{'form.Status'}) eq 'future') {
675: $Str .= '<p class="LC_info">'.
676: &mt('There are no students with future access in the selected sections.').
677: '</p>';
678: } else { # 'any' and any others
679: $Str .= '<p class="LC_info">'.
680: &mt('There are no students in the selected sections.').
681: '</p>';
1.78 matthew 682: }
683: }
1.141 bisitz 684: $Str.= '<p>'
685: .'<a href="/adm/statistics?reportSelected=student_assessment">'
686: .&mt('Return to the chart').'</a>'
687: .'</p>';
1.78 matthew 688: $r->print($Str);
689: $r->rflush();
690: return;
691: }
692:
1.141 bisitz 693: $Str .= '<h2>'.&mt('Select One Student').'</h2>'
1.156.2.2! raeburn 694: .'<p>'.&mt("Click on a student's name or username to view their chart.").'</p>'
1.141 bisitz 695: .&Apache::loncommon::start_data_table()
696: .&Apache::loncommon::start_data_table_header_row();
1.60 matthew 697: foreach my $field (@Fields) {
1.101 matthew 698: $Str .= '<th><a href="/adm/statistics?'.
699: 'reportSelected=student_assessment&'.
700: 'selectstudent=1&'.
1.106 matthew 701: 'sort='.$field.'">'.&mt($field).
1.60 matthew 702: '</a></th>';
703: }
1.141 bisitz 704: $Str .= &Apache::loncommon::end_data_table_header_row();
1.60 matthew 705: #
1.65 matthew 706: foreach my $student (@Students) { # @Students is a package variable
1.60 matthew 707: my $sname = $student->{'username'}.':'.$student->{'domain'};
1.141 bisitz 708: $Str .= &Apache::loncommon::start_data_table_row();
1.60 matthew 709: #
710: foreach my $field (@Fields) {
711: $Str .= '<td>';
1.78 matthew 712: if ($field eq 'fullname' || $field eq 'username') {
1.60 matthew 713: $Str .= '<a href="/adm/statistics?reportSelected=';
1.136 www 714: $Str .= &escape('student_assessment');
715: $Str .= '&sort='.&escape($env{'form.sort'});
1.72 matthew 716: $Str .= '&SelectedStudent=';
1.136 www 717: $Str .= &escape($sname).'">';
1.156.2.2! raeburn 718: $Str .= $student->{$field};
1.60 matthew 719: $Str .= '</a>';
1.106 matthew 720: } elsif ($field eq 'status') {
721: $Str .= &mt($student->{$field});
1.60 matthew 722: } else {
1.156.2.2! raeburn 723: if ($student->{$field} eq 'none') {
! 724: $Str .= &mt('none')
! 725: } else {
! 726: $Str .= $student->{$field};
! 727: }
1.60 matthew 728: $Str .= $student->{$field};
729: }
730: $Str .= '</td>';
731: }
1.141 bisitz 732: $Str .= &Apache::loncommon::end_data_table_row();
1.60 matthew 733: }
1.141 bisitz 734: $Str .= &Apache::loncommon::end_data_table();
1.60 matthew 735: #
736: $r->print($Str);
737: $r->rflush();
738: #
739: return;
740: }
741:
1.144 jms 742:
743:
1.33 stredwic 744: sub CreateMainMenu {
1.65 matthew 745: #
1.85 matthew 746: # Define menu data
1.145 diwert 747: my @reports = (
748: {categorytitle => 'Statistics and Analyses',
749: items => [
750: {url => '/adm/statistics?reportSelected=problem_statistics',
751: permission => 'F',
752: icon => 'document-open.png',
753: linktext => ('Overall Problem Statistics'),
754: linktitle => ('Student performance statistics on all problems.')},
755:
756: {url => '/adm/statistics?reportSelected=problem_analysis',
757: permission => 'F',
1.151 wenzelju 758: icon => 'prob_ana.png',
1.145 diwert 759: linktext => ('Detailed Problem Analysis'),
760: linktitle => ('Detailed statistics and graphs of student performance on problems.')},
761: ]},
762: {categorytitle => 'Plots',
763: items => [
764: {url => '/adm/statistics?reportSelected=submissiontime_analysis',
765: permission => 'F',
766: icon => 'subtimpl.png',
767: linktext => ('Submission Time Plots'),
768: linktitle => ('Display and analysis of submission times on assessments.')},
769:
770: {url => '/adm/statistics?reportSelected=correct_problems_plot',
771: permission => 'F',
772: icon => 'coprplot.png',
773: linktext => ('Correct Problems Plot'),
774: linktitle => ('Display a histogram of student performance in the course.')},
775: ]},
776: {categorytitle => 'Reports',
777: items => [
778: {url => '/adm/statistics?reportSelected=student_submission_reports',
779: permission => 'F',
780: icon => 'edit-copy.png',
781: linktext => ('Student Submission Reports'),
782: linktitle => ('Prepare reports of student submissions.')},
783:
784: {url => '/adm/statistics?reportSelected=survey_reports',
785: permission => 'F',
1.151 wenzelju 786: icon => 'survey_rep.png',
1.145 diwert 787: linktext => ('Survey Reports'),
788: linktitle => ('Prepare reports on survey results.')},
789: ]});
790:
791: return &Apache::lonhtmlcommon::generate_menu(@reports);
792:
1.33 stredwic 793: }
794:
1.144 jms 795:
796:
1.1 albertel 797: sub handler {
1.31 minaeibi 798: my $r=shift;
1.65 matthew 799: my $c = $r->connection();
800: #
801: # Check for access
1.123 albertel 802: if (! &Apache::lonnet::allowed('vgr',$env{'request.course.id'})) {
803: $env{'user.error.msg'}=
1.69 matthew 804: $r->uri.":vgr:0:0:Cannot view grades for complete course";
805: if (! &Apache::lonnet::allowed('vgr',
1.123 albertel 806: $env{'request.course.id'}.'/'.$env{'request.course.sec'})) {
807: $env{'user.error.msg'}=
1.69 matthew 808: $r->uri.":vgr:0:0:Cannot view grades with given role";
809: return HTTP_NOT_ACCEPTABLE;
810: }
1.27 stredwic 811: }
1.65 matthew 812: #
813: # Send the header
1.92 www 814: &Apache::loncommon::no_cache($r);
815: &Apache::loncommon::content_type($r,'text/html');
1.27 stredwic 816: $r->send_http_header;
1.92 www 817: if ($r->header_only) { return OK; }
1.65 matthew 818: #
819: # Extract form elements from query string
1.60 matthew 820: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.65 matthew 821: ['sort','reportSelected',
1.72 matthew 822: 'SelectedStudent']);
1.65 matthew 823: #
824: # Give the LON-CAPA page header
1.109 matthew 825: my $style = <<ENDSTYLE;
826: <style type="text/css">
827: ul.sub_studentans { list-style-type: none }
828: ul.sub_correctans { list-style-type: none }
1.110 matthew 829: tr.even { background-color: \#CCCCCC }
830: td.essay { border: 1px solid gray; }
1.109 matthew 831: </style>
832: ENDSTYLE
1.129 albertel 833:
834: $r->print(&Apache::loncommon::start_page('Course Statistics and Charts',
835: $style));
1.65 matthew 836: $r->rflush();
1.85 matthew 837: #
838: # Either print out a menu for them or send them to a report
1.98 matthew 839: &Apache::lonhtmlcommon::clear_breadcrumbs();
840: &Apache::lonhtmlcommon::add_breadcrumb({href=>'/adm/statistics',
1.100 matthew 841: title=>'Statistics',
842: text =>'Statistics',
1.98 matthew 843: faq=>139,
844: bug=>'Statistics and Charts'});
1.123 albertel 845: if (! exists($env{'form.reportSelected'}) ||
846: $env{'form.reportSelected'} eq '') {
1.156.2.1 raeburn 847: $r->print(&Apache::lonhtmlcommon::breadcrumbs('Statistics Main Page').
848: &CreateMainMenu());
1.85 matthew 849: } else {
1.65 matthew 850: #
1.85 matthew 851: if (! &Apache::lonmysql::verify_sql_connection()) {
852: my $serveradmin = $r->dir_config('lonAdmEMail');
1.156 golterma 853: $r->print('<p class="LC_error">'.
1.85 matthew 854: &mt('Unable to connect to database!').
1.156 golterma 855: '</p>');
1.140 bisitz 856: $r->print('<p>'
857: .&mt('Please notify the server administrator [_1]',
858: ,'<b>'.$serveradmin.'</b>')
859: .'</p>');
1.85 matthew 860: $r->print('<p>'.
861: &mt('Course Statistics and Charts cannot be '.
1.148 bisitz 862: 'retrieved until the database is restarted. '.
1.85 matthew 863: 'Your data is intact but cannot be displayed '.
864: 'at this time.').'</p>');
1.129 albertel 865: $r->print(&Apache::loncommon::end_page());
1.85 matthew 866: return;
867: }
868: #
869: # Clean out the caches
1.123 albertel 870: if (exists($env{'form.ClearCache'})) {
871: &Apache::loncoursedata::delete_caches($env{'requres.course.id'});
1.85 matthew 872: }
873: #
1.153 raeburn 874: my $GoToPage = $env{'form.reportSelected'};
875: #
1.85 matthew 876: # Begin form output
877: $r->print('<form name="Statistics" ');
1.153 raeburn 878: if ($GoToPage eq 'student_submission_reports') {
879: $r->print('onsubmit="return checkanon();" ');
880: }
1.85 matthew 881: $r->print('method="post" action="/adm/statistics">');
882: $r->rflush();
883: $r->print('<input type="hidden" name="reportSelected" value="'.
1.149 bisitz 884: $GoToPage.'" />');
1.85 matthew 885: if($GoToPage eq 'activitylog') {
1.65 matthew 886: # &Apache::lonproblemstatistics::Activity();
1.85 matthew 887: } elsif($GoToPage eq 'problem_statistics') {
1.98 matthew 888: &Apache::lonhtmlcommon::add_breadcrumb
889: ({href=>'/adm/statistics?reportselected=problem_statistics',
1.100 matthew 890: text=>'Overall Problem Statistics'});
1.85 matthew 891: &Apache::lonproblemstatistics::BuildProblemStatisticsPage($r,$c);
892: } elsif($GoToPage eq 'problem_analysis') {
1.98 matthew 893: &Apache::lonhtmlcommon::add_breadcrumb
894: ({href=>'/adm/statistics?reportselected=problem_analysis',
1.100 matthew 895: text=>'Detailed Problem Analysis'});
1.85 matthew 896: &Apache::lonproblemanalysis::BuildProblemAnalysisPage($r,$c);
1.89 matthew 897: } elsif($GoToPage eq 'submissiontime_analysis') {
1.98 matthew 898: &Apache::lonhtmlcommon::add_breadcrumb
899: ({href=>
900: '/adm/statistics?reportselected=submissiontime_analysis',
1.100 matthew 901: text=>'Submission Time Plots'});
1.89 matthew 902: &Apache::lonsubmissiontimeanalysis::BuildSubmissionTimePage($r,$c);
1.97 matthew 903: } elsif($GoToPage eq 'student_submission_reports') {
1.98 matthew 904: &Apache::lonhtmlcommon::add_breadcrumb
905: ({href=>
906: '/adm/statistics?reportselected=student_submission_reports',
1.100 matthew 907: text=>'Student Submission Reports'});
1.97 matthew 908: &Apache::lonstudentsubmissions::BuildStudentSubmissionsPage($r,$c);
1.104 matthew 909: } elsif($GoToPage eq 'survey_reports') {
910: &Apache::lonhtmlcommon::add_breadcrumb
911: ({href=>
912: '/adm/statistics?reportselected=survey_reports',
913: text=>'Survey Reports'});
914: &Apache::lonsurveyreports::BuildSurveyReportsPage($r,$c);
1.94 matthew 915: } elsif($GoToPage eq 'correct_problems_plot') {
1.98 matthew 916: &Apache::lonhtmlcommon::add_breadcrumb
917: ({href=>'/adm/statistics?reportselected=correct_problems_plot',
1.100 matthew 918: text=>'Correct Problems Plot'});
1.94 matthew 919: &Apache::loncorrectproblemplot::BuildCorrectProblemsPage($r,$c);
1.85 matthew 920: } elsif($GoToPage eq 'student_assessment') {
1.98 matthew 921: &Apache::lonhtmlcommon::clear_breadcrumbs();
922: &Apache::lonhtmlcommon::add_breadcrumb
923: ({href=>'/adm/statistics?reportselected=student_assessment',
1.100 matthew 924: text=>'Chart'});
1.85 matthew 925: &Apache::lonstudentassessment::BuildStudentAssessmentPage($r,$c);
1.128 albertel 926: } elsif($GoToPage eq 'grading_analysis') {
927: &Apache::lonhtmlcommon::add_breadcrumb
928: ({href=>'/adm/statistics?reportselected=grading_anaylsis',
929: text=>'Grading Analysis'});
930: &Apache::longradinganalysis::build_grading_analysis_page($r,$c);
931: }
1.85 matthew 932: #
933: $r->print("</form>\n");
1.65 matthew 934: }
1.129 albertel 935: $r->print(&Apache::loncommon::end_page());
1.65 matthew 936: $r->rflush();
937: #
1.27 stredwic 938: return OK;
1.1 albertel 939: }
1.65 matthew 940:
1.1 albertel 941: 1;
1.59 matthew 942:
1.144 jms 943: __END__
1.65 matthew 944:
1.59 matthew 945: =pod
946:
1.144 jms 947: =head1 NAME
948:
949: lonstatistics
950:
951: =head1 SYNOPSIS
952:
953: Main handler for statistics and chart.
954:
955: This is part of the LearningOnline Network with CAPA project
956: described at http://www.lon-capa.org.
957:
958:
959: =head1 PACKAGE VARIABLES
960:
961: =over
962:
963: =item @FullClasslist The full classlist
964:
965: =item @Students The students we are concerned with for this invocation
966:
967: =item @Sections The sections available in this class
968:
969: =item @Groups The groups available in the class
970:
971: =item $curr_student The student currently being examined
972:
973: =item $prev_student The student previous in the classlist
974:
975: =item $next_student The student next in the classlist
976:
977: =back
978:
979: =head1 SUBROUTINES
980:
981: =over
982:
983: =item &clear_classlist_variables()
984:
985: undef the following package variables:
986:
987: =over 4
988:
989: =item * @FullClasslist
990:
991: =item * @Students
992:
993: =item * @Sections
994:
995: =item * @Groups
996:
997: =item * %StudentData
998:
999: =item * @StudentDataOrder
1000:
1001: =item * @SelectedStudentData
1002:
1003: =item * $curr_student
1004:
1005: =item * $prev_student
1006:
1007: =item * $next_student
1008:
1009: =back
1010:
1011: =item &PrepareClasslist()
1012:
1013: Build up the classlist information. The classlist information is kept in
1014: the following package variables:
1015:
1016: =over 4
1017:
1018: =item * @FullClasslist
1019:
1020: =item * @Students
1021:
1022: =item * @Sections
1023:
1024: =item * @Groups
1025:
1026: =item * %StudentData
1027:
1028: =item * @SelectedStudentData
1029:
1030: =item * $curr_student
1031:
1032: =item * $prev_student
1033:
1034: =item * $next_student
1035:
1036: =back
1037:
1038: $curr_student, $prev_student, and $next_student may not be defined, depending
1039: upon the calling context.
1040:
1041: =item get_selected_sections()
1042:
1043: Returns an array of the selected sections
1044:
1045: =item get_selected_groups()
1046:
1047: Returns an array of the selected groups
1048:
1049: =item §ion_and_enrollment_description()
1050:
1051: Returns a string describing the currently selected section(s), group(s) and
1052: access status.
1053:
1054: Inputs: mode = 'plaintext' or 'localized' (defaults to 'localized')
1055: 'plaintext' is used for example in Excel spreadsheets.
1056: Returns: scalar description string.
1057:
1058: =item section_or_group_text()
1059:
1060: =item get_students()
1061:
1062: Returns a list of the selected students
1063:
1064: =item ¤t_student()
1065:
1066: Returns a pointer to a hash containing data about the currently
1067: selected student.
1068:
1069: =item &previous_student()
1070:
1071: Returns a pointer to a hash containing data about the student prior
1072: in the list of students. Or something.
1073:
1074: =item &next_student()
1075:
1076: Returns a pointer to a hash containing data about the next student
1077: to be viewed.
1078:
1079: =item &StudentDataSelect($elementname,$status,$numvisible,$selected)
1080:
1081: Returns html for a selection box allowing the user to choose one (or more)
1082: of the fields of student data available (fullname, username, id, section, etc)
1083:
1084: =over 4
1085:
1086: =item * $elementname The name of the HTML form element
1087:
1088: =item * $status 'multiple' or 'single' selection box
1089:
1090: =item * $numvisible The number of options to be visible
1091:
1092: =back
1093:
1094: =item &get_selected_maps($elementname)
1095:
1096: Input: Name of the <select> form element used to specify the maps.
1097:
1098: Returns: Array of symbs of selected maps or the description 'all'.
1099: If form.$elementname does not exist, 'all' is returned.
1100:
1101: =item &selected_sequences_with_assessments()
1102:
1103: Retrieve the sequences which were selected by the user to show.
1104:
1105: Input: $mode: scalar. Either 'selected' or 'all'. If not specified,
1106: 'selected' is used.
1107:
1108: Returns: an array containing a navmap object and navmap resources,
1109: or an array containing a scalar with an error message.
1110:
1111: =item &map_select($elementname,$status,$numvisible,$restriction)
1112:
1113: Returns html for a selection box allowing the user to choose one (or more)
1114: of the sequences in the course. The values of the sequences are the symbs.
1115: If the top sequence is selected, the value 'top' will result.
1116:
1117: =over 4
1118:
1119: =item * $elementname The name of the HTML form element
1120:
1121: =item * $status 'multiple' or 'single' selection box
1122:
1123: =item * $numvisible The number of options to be visible
1124:
1.59 matthew 1125: =back
1126:
1.144 jms 1127: =item &SectionSelect($elementname,$status,$numvisible)
1128:
1129: Returns html for a selection box allowing the user to choose one (or more)
1130: of the sections in the course.
1131:
1132: Uses the package variables @Sections
1133:
1134: =over 4
1135:
1136: =item * $elementname The name of the HTML form element
1137:
1138: =item * $status 'multiple' or 'single' selection box
1139:
1140: =item * $numvisible The number of options to be visible
1141:
1142: =back
1143:
1144: =item &GroupSelect($elementname,$status,$numvisible)
1145:
1146: Returns html for a selection box allowing the user to choose one (or more)
1147: of the groups in the course.
1148:
1149: Uses the package variables @Groups
1150:
1151: =over 4
1152:
1153: =item * $elementname The name of the HTML form element
1154:
1155: =item * $status 'multiple' or 'single' selection box
1156:
1157: =item * $numvisible The number of options to be visible
1158:
1159: =back
1160:
1161: =item CreateMainMenu()
1.65 matthew 1162:
1.144 jms 1163: =back
1.59 matthew 1164:
1.144 jms 1165: =cut
1.31 minaeibi 1166:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>