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