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