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