Annotation of loncom/interface/lonstatistics.pm, revision 1.59
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.59 ! matthew 4: # $Id: lonstatistics.pm,v 1.58 2003/01/12 23:45:47 minaeibi Exp $
1.1 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
28: # (Navigate problems for statistical reports
29: # YEAR=2001
1.15 minaeibi 30: # 5/5,7/9,7/25/1,8/11,9/13,9/26,10/5,10/9,10/22,10/26 Behrouz Minaei
1.14 minaeibi 31: # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei
1.1 albertel 32: # YEAR=2002
1.18 minaeibi 33: # 1/22,2/1,2/6,2/25,3/2,3/6,3/17,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei
1.35 minaeibi 34: # 5/12,5/14,5/15,5/19,5/26,7/16,25/7,29/7 Behrouz Minaei
1.14 minaeibi 35: #
1.1 albertel 36: ###
37:
1.59 ! matthew 38: =pod
! 39:
! 40: =head1 NAME
! 41:
! 42: lonstatistics
! 43:
! 44: =head1 SYNOPSIS
! 45:
! 46: Main handler for statistics and chart.
! 47:
! 48: =head1 PACKAGES USED
! 49:
! 50: use strict;
! 51: use Apache::Constants qw(:common :http);
! 52: use Apache::lonnet();
! 53: use Apache::lonhomework;
! 54: use Apache::loncommon;
! 55: use Apache::loncoursedata;
! 56: use Apache::lonhtmlcommon;
! 57: use Apache::lonproblemanalysis;
! 58: use Apache::lonproblemstatistics;
! 59: use Apache::lonstudentassessment;
! 60: use Apache::lonpercentage;
! 61: use GDBM_File;
! 62:
! 63: =over 4
! 64:
! 65: =cut
! 66:
1.55 minaeibi 67: package Apache::lonstatistics;
1.1 albertel 68:
1.30 stredwic 69: use strict;
1.1 albertel 70: use Apache::Constants qw(:common :http);
71: use Apache::lonnet();
72: use Apache::lonhomework;
1.12 minaeibi 73: use Apache::loncommon;
1.29 stredwic 74: use Apache::loncoursedata;
75: use Apache::lonhtmlcommon;
1.30 stredwic 76: use Apache::lonproblemanalysis;
77: use Apache::lonproblemstatistics;
78: use Apache::lonstudentassessment;
1.49 stredwic 79: use Apache::lonpercentage;
1.1 albertel 80: use GDBM_File;
81:
1.59 ! matthew 82: my @FullClasslist;
! 83: my @Students;
! 84: my @Sections;
! 85: my $curr_student;
! 86: my $prev_student;
! 87: my $next_student;
! 88:
! 89: #######################################################
! 90: #######################################################
! 91:
! 92: =pod
! 93:
! 94: =item &clear_classlist_variables()
! 95:
! 96: undef the following package variables:
! 97:
! 98: =over
! 99:
! 100: =item @FullClasslist The full classlist
! 101:
! 102: =item @Students The students we are concerned with for this invocation
! 103:
! 104: =item @Sections The sections available in this class
! 105:
! 106: =item $curr_student The student currently being examined
! 107:
! 108: =item $prev_student The student previous in the classlist
! 109:
! 110: =item $next_student The student next in the classlist
! 111:
! 112: =back
! 113:
! 114: =cut
! 115:
! 116: #######################################################
! 117: #######################################################
! 118: sub clear_classlist_variables {
! 119: undef(@FullClasslist);
! 120: undef(@Students);
! 121: undef(@Sections);
! 122: undef($curr_student);
! 123: undef($prev_student);
! 124: undef($next_student);
! 125: }
! 126:
! 127: #######################################################
! 128: #######################################################
! 129:
! 130: =pod
! 131:
! 132: =item &PrepareClasslist()
! 133:
! 134: Build up the classlist information. The classlist information is kept in
! 135: the following package variables:
! 136:
! 137: =over
! 138:
! 139: =item @FullClasslist The full classlist
! 140:
! 141: =item @Students The students we are concerned with for this invocation
! 142:
! 143: =item @Sections The sections available in this class
! 144:
! 145: =item $curr_student The student currently being examined
! 146:
! 147: =item $prev_student The student previous in the classlist
! 148:
! 149: =item $next_student The student next in the classlist
! 150:
! 151: =back
! 152:
! 153: $curr_student, $prev_student, and $next_student may not be defined, depending
! 154: upon the calling context.
! 155:
! 156: =cut
! 157:
! 158: #######################################################
! 159: #######################################################
! 160: sub PrepareClasslist {
! 161: my $r = shift;
! 162: my %Sections;
! 163: &clear_classlist_variables();
! 164: #
! 165: # Retrieve the classlist
! 166: my $cid = $ENV{'request.course.id'};
! 167: my $cdom = $ENV{'course.'.$cid.'.domain'};
! 168: my $cnum = $ENV{'course.'.$cid.'.num'};
! 169: my ($classlist,$field_names) = &Apache::loncoursedata::get_classlist($cid,
! 170: $cdom,$cnum);
! 171: my %valid_section;
! 172: if (exists($ENV{'form.Section'}) && $ENV{'form.Section'} !~ /(all|any)/) {
! 173: if (ref($ENV{'form.Section'})) {
! 174: foreach (@$ENV{'form.section'}) {
! 175: $valid_section{$_}++;
! 176: }
! 177: } else {
! 178: $valid_section{$_}++;
! 179: }
! 180: }
! 181: #
! 182: # Process the classlist
! 183: while (my ($student,$student_data) = each (%$classlist)) {
! 184: my $studenthash = ();
! 185: for (my $i=0; $i< scalar(@$field_names);$i++) {
! 186: $studenthash->{$field_names->[$i]}=$student_data->[$i];
! 187: }
! 188: push (@FullClasslist,$studenthash);
! 189: #
! 190: # Build up a list of sections
! 191: my $section = $studenthash->{'section'};
! 192: $section = 'no section' if (! defined($section) || $section =~/^\s*/ );
! 193: $Sections{$section}++;
! 194: #
! 195: # Only put in the list those students we are interested in
! 196: if (defined($ENV{'form.Section'}) &&
! 197: $ENV{'form.Section'} !~ /(all|any)/ &&
! 198: ! exists($valid_section{$section})) {
! 199: next;
! 200: }
! 201: push (@Students,$studenthash);
! 202: }
! 203: #
! 204: # Put the consolidated section data in the right place
! 205: @Sections = sort {$a<=>$b} keys(%Sections);
! 206: #
! 207: # Sort the Students
! 208: my $sortby = 'fullname';
! 209: @Students = sort {$a->{$sortby} <=> $b->{$sortby}} @Students;
! 210: #
! 211: # Now deal with that current student thing....
! 212: if (exists($ENV{'form.StudentAssessmentStudent'})) {
! 213: my ($current_uname,$current_dom) =
! 214: split(':',$ENV{'form.StudentAssessmentStudent'});
! 215: my $i;
! 216: for ($i = 0; $i<=$#Students; $i++) {
! 217: next if (($Students[$i]->{'username'} ne $current_uname) ||
! 218: ($Students[$i]->{'domain'} ne $current_dom));
! 219: last; # If we get here, we have our student.
! 220: }
! 221: if ($i == 0) {
! 222: $prev_student = 'none';
! 223: } else {
! 224: $prev_student = $Students[$i-1];
! 225: }
! 226: if ($i == $#Students) {
! 227: $next_student = 'none';
! 228: } else {
! 229: $next_student = $Students[$i+1];
! 230: }
! 231: }
! 232: }
! 233:
! 234: #######################################################
! 235: #######################################################
1.27 stredwic 236:
237: sub CheckFormElement {
238: my ($cache, $ENVName, $cacheName, $default)=@_;
239:
240: if(defined($ENV{'form.'.$ENVName})) {
241: $cache->{$cacheName} = $ENV{'form.'.$ENVName};
242: } elsif(!defined($cache->{$cacheName})) {
243: $cache->{$cacheName} = $default;
244: }
245:
246: return;
247: }
248:
249: sub ProcessFormData{
1.29 stredwic 250: my ($cache)=@_;
1.27 stredwic 251:
1.29 stredwic 252: $cache->{'reportKey'} = 'false';
1.27 stredwic 253:
1.29 stredwic 254: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.34 stredwic 255: ['sort','download',
256: 'reportSelected',
1.41 stredwic 257: 'StudentAssessmentStudent',
258: 'ProblemStatisticsSort']);
1.56 matthew 259: &CheckFormElement($cache, 'DownloadAll', 'DownloadAll', 'false');
260: if ($cache->{'DownloadAll'} ne 'false') {
261: # Clean the hell out of that cache!
262: # We cannot untie the hash at this scope (stupid libgd :( )
263: # So, remove every single key. What a waste of time....
264: # Of course, if you are doing this you are probably resigned
265: # to waiting a while.
266: &Apache::lonnet::logthis("Cleaning out the cache file");
267: while (my ($key,undef)=each(%$cache)) {
268: next if ($key eq 'DownloadAll');
269: delete($cache->{$key});
270: }
271: }
1.29 stredwic 272: &CheckFormElement($cache, 'Status', 'Status', 'Active');
273: &CheckFormElement($cache, 'postdata', 'reportSelected', 'Class list');
274: &CheckFormElement($cache, 'reportSelected', 'reportSelected',
275: 'Class list');
1.30 stredwic 276: $cache->{'reportSelected'} =
277: &Apache::lonnet::unescape($cache->{'reportSelected'});
1.29 stredwic 278: &CheckFormElement($cache, 'sort', 'sort', 'fullname');
279: &CheckFormElement($cache, 'download', 'download', 'false');
1.44 stredwic 280: &CheckFormElement($cache, 'StatisticsMaps',
281: 'StatisticsMaps', 'All Maps');
1.49 stredwic 282: &CheckFormElement($cache, 'StatisticsProblemSelect',
283: 'StatisticsProblemSelect', 'All Problems');
284: &CheckFormElement($cache, 'StatisticsPartSelect',
285: 'StatisticsPartSelect', 'All Parts');
1.44 stredwic 286: if(defined($ENV{'form.Section'})) {
287: my @sectionsSelected = (ref($ENV{'form.Section'}) ?
288: @{$ENV{'form.Section'}} :
289: ($ENV{'form.Section'}));
290: $cache->{'sectionsSelected'} = join(':', @sectionsSelected);
291: } elsif(!defined($cache->{'sectionsSelected'})) {
292: $cache->{'sectionsSelected'} = $cache->{'sectionList'};
293: }
1.29 stredwic 294:
1.38 stredwic 295: # student assessment
1.29 stredwic 296: if(defined($ENV{'form.CreateStudentAssessment'}) ||
297: defined($ENV{'form.NextStudent'}) ||
298: defined($ENV{'form.PreviousStudent'})) {
299: $cache->{'reportSelected'} = 'Student Assessment';
300: }
301: if(defined($ENV{'form.NextStudent'})) {
302: $cache->{'StudentAssessmentMove'} = 'next';
303: } elsif(defined($ENV{'form.PreviousStudent'})) {
304: $cache->{'StudentAssessmentMove'} = 'previous';
305: } else {
306: $cache->{'StudentAssessmentMove'} = 'selected';
307: }
308: &CheckFormElement($cache, 'StudentAssessmentStudent',
1.30 stredwic 309: 'StudentAssessmentStudent', 'All Students');
310: $cache->{'StudentAssessmentStudent'} =
311: &Apache::lonnet::unescape($cache->{'StudentAssessmentStudent'});
1.34 stredwic 312: &CheckFormElement($cache, 'DefaultColumns', 'DefaultColumns', 'false');
1.29 stredwic 313:
1.38 stredwic 314: # Problem analysis
315: &CheckFormElement($cache, 'Interval', 'Interval', '1');
316:
317: # ProblemStatistcs
318: &CheckFormElement($cache, 'DisplayCSVFormat',
319: 'DisplayFormat', 'Display Table Format');
320: &CheckFormElement($cache, 'ProblemStatisticsAscend',
321: 'ProblemStatisticsAscend', 'Ascending');
1.41 stredwic 322: &CheckFormElement($cache, 'ProblemStatisticsSort',
323: 'ProblemStatisticsSort', 'Homework Sets Order');
1.49 stredwic 324: &CheckFormElement($cache, 'DisplayLegend', 'DisplayLegend',
325: 'Hide Legend');
1.45 stredwic 326: &CheckFormElement($cache, 'SortProblems', 'SortProblems',
327: 'Sort Within Sequence');
1.38 stredwic 328:
329: # Search only form elements
1.34 stredwic 330: my @headingColumns=();
331: my @sequenceColumns=();
332: my $foundColumn = 0;
333: if(defined($ENV{'form.ReselectColumns'})) {
334: my @reselected = (ref($ENV{'form.ReselectColumns'}) ?
335: @{$ENV{'form.ReselectColumns'}}
336: : ($ENV{'form.ReselectColumns'}));
337: foreach (@reselected) {
338: if(/HeadingColumn/) {
339: push(@headingColumns, $_);
340: $foundColumn = 1;
341: } elsif(/SequenceColumn/) {
342: push(@sequenceColumns, $_);
343: $foundColumn = 1;
344: }
345: }
346: }
347:
1.37 stredwic 348: $cache->{'reportKey'} = 'false';
349: if($cache->{'reportSelected'} eq 'Analyze') {
350: $cache->{'reportKey'} = 'Analyze';
1.38 stredwic 351: } elsif($cache->{'reportSelected'} eq 'DoDiffGraph') {
352: $cache->{'reportKey'} = 'DoDiffGraph';
353: } elsif($cache->{'reportSelected'} eq 'PercentWrongGraph') {
354: $cache->{'reportKey'} = 'PercentWrongGraph';
355: }
356:
357: if(defined($ENV{'form.DoDiffGraph'})) {
358: $cache->{'reportSelected'} = 'DoDiffGraph';
359: $cache->{'reportKey'} = 'DoDiffGraph';
360: } elsif(defined($ENV{'form.PercentWrongGraph'})) {
361: $cache->{'reportSelected'} = 'PercentWrongGraph';
362: $cache->{'reportKey'} = 'PercentWrongGraph';
1.37 stredwic 363: }
364:
1.29 stredwic 365: foreach (keys(%ENV)) {
1.37 stredwic 366: if(/form\.Analyze/) {
367: $cache->{'reportSelected'} = 'Analyze';
368: $cache->{'reportKey'} = 'Analyze';
369: my $data;
370: (undef, $data)=split(':::', $_);
371: $cache->{'AnalyzeInfo'}=$data;
1.34 stredwic 372: } elsif(/form\.HeadingColumn/) {
373: my $value = $_;
374: $value =~ s/form\.//;
375: push(@headingColumns, $value);
376: $foundColumn=1;
377: } elsif(/form\.SequenceColumn/) {
378: my $value = $_;
379: $value =~ s/form\.//;
380: push(@sequenceColumns, $value);
381: $foundColumn=1;
1.27 stredwic 382: }
1.29 stredwic 383: }
1.27 stredwic 384:
1.34 stredwic 385: if($foundColumn) {
386: $cache->{'HeadingsFound'} = join(':', @headingColumns);
387: $cache->{'SequencesFound'} = join(':', @sequenceColumns);;
388: }
389: if(!defined($cache->{'HeadingsFound'}) ||
390: $cache->{'DefaultColumns'} ne 'false') {
391: $cache->{'HeadingsFound'}='HeadingColumnFull Name';
392: }
393: if(!defined($cache->{'SequencesFound'}) ||
394: $cache->{'DefaultColumns'} ne 'false') {
395: $cache->{'SequencesFound'}='All Sequences';
396: }
397: $cache->{'DefaultColumns'} = 'false';
398:
1.29 stredwic 399: return;
1.27 stredwic 400: }
401:
402: =pod
403:
404: =item &SortStudents()
405:
406: Determines which students to display and in which order. Which are
407: displayed are determined by their status(active/expired). The order
408: is determined by the sort button pressed (default to username). The
409: type of sorting is username, lastname, or section.
410:
411: =over 4
412:
413: Input: $students, $CacheData
414:
415: $students: A array pointer to a list of students (username:domain)
416:
417: $CacheData: A pointer to the hash tied to the cached data
418:
419: Output: \@order
420:
421: @order: An ordered list of students (username:domain)
422:
423: =back
424:
425: =cut
426:
427: sub SortStudents {
1.29 stredwic 428: my ($cache)=@_;
1.27 stredwic 429:
1.29 stredwic 430: my @students = split(':::',$cache->{'NamesOfStudents'});
1.27 stredwic 431: my @sorted1Students=();
1.29 stredwic 432: foreach (@students) {
433: if($cache->{'Status'} eq 'Any' ||
434: $cache->{$_.':Status'} eq $cache->{'Status'}) {
435: push(@sorted1Students, $_);
436: }
1.1 albertel 437: }
1.27 stredwic 438:
1.29 stredwic 439: my $sortBy = '';
440: if(defined($cache->{'sort'})) {
441: $sortBy = ':'.$cache->{'sort'};
1.54 matthew 442: } else {
443: $sortBy = ':fullname';
1.27 stredwic 444: }
1.54 matthew 445: my @order = sort { lc($cache->{$a.$sortBy}) cmp lc($cache->{$b.$sortBy}) ||
446: lc($cache->{$a.':fullname'}) cmp lc($cache->{$b.':fullname'}) }
1.29 stredwic 447: @sorted1Students;
1.27 stredwic 448:
449: return \@order;
450: }
451:
1.32 stredwic 452: =pod
453:
454: =item &SpaceColumns()
455:
456: Determines the width of all the columns in the chart. It is based on
457: the max of the data for that column and its header.
458:
459: =over 4
460:
461: Input: $students, $studentInformation, $headings, $ChartDB
462:
463: $students: An array pointer to a list of students (username:domain)
464:
465: $studentInformatin: The type of data for the student information. It is
466: used as part of the key in $CacheData.
467:
468: $headings: The name of the student information columns.
469:
470: $ChartDB: The name of the cache database which is opened for read/write.
471:
472: Output: None - All data stored in cache.
473:
474: =back
475:
476: =cut
477:
478: sub SpaceColumns {
479: my ($students,$studentInformation,$headings,$cache)=@_;
480:
481: # Initialize Lengths
482: for(my $index=0; $index<(scalar @$headings); $index++) {
483: my @titleLength=split(//,$headings->[$index]);
484: $cache->{$studentInformation->[$index].':columnWidth'}=
485: scalar @titleLength;
486: }
487:
488: foreach my $name (@$students) {
489: foreach (@$studentInformation) {
490: my @dataLength=split(//,$cache->{$name.':'.$_});
491: my $length=(scalar @dataLength);
492: if($length > $cache->{$_.':columnWidth'}) {
493: $cache->{$_.':columnWidth'}=$length;
494: }
495: }
496: }
497:
498: return;
499: }
500:
1.27 stredwic 501: sub PrepareData {
1.38 stredwic 502: my ($c, $cacheDB, $studentInformation, $headings,$r)=@_;
1.27 stredwic 503:
504: # Test for access to the cache data
505: my $courseID=$ENV{'request.course.id'};
506: my $isRecalculate=0;
1.29 stredwic 507: if(defined($ENV{'form.Recalculate'})) {
1.27 stredwic 508: $isRecalculate=1;
509: }
510:
1.55 minaeibi 511: my $isCached = &Apache::loncoursedata::TestCacheData($cacheDB,
1.29 stredwic 512: $isRecalculate);
1.27 stredwic 513: if($isCached < 0) {
514: return "Unable to tie hash to db file.";
515: }
516:
517: # Download class list information if not using cached data
518: my %cache;
1.38 stredwic 519: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
1.29 stredwic 520: return "Unable to tie hash to db file.";
521: }
522:
1.50 stredwic 523: # if(!$isCached) {
1.27 stredwic 524: my $processTopResourceMapReturn=
1.50 stredwic 525: &Apache::loncoursedata::ProcessTopResourceMap(\%cache, $c);
1.27 stredwic 526: if($processTopResourceMapReturn ne 'OK') {
527: untie(%cache);
528: return $processTopResourceMapReturn;
529: }
1.50 stredwic 530: # }
1.27 stredwic 531:
1.29 stredwic 532: if($c->aborted()) {
533: untie(%cache);
534: return 'aborted';
535: }
1.27 stredwic 536:
1.29 stredwic 537: my $classlist=&Apache::loncoursedata::DownloadClasslist($courseID,
538: $cache{'ClasslistTimestamp'},
539: $c);
540: foreach (keys(%$classlist)) {
541: if(/^(con_lost|error|no_such_host)/i) {
1.27 stredwic 542: untie(%cache);
543: return "Error getting student data.";
544: }
1.29 stredwic 545: }
1.27 stredwic 546:
1.29 stredwic 547: if($c->aborted()) {
548: untie(%cache);
549: return 'aborted';
550: }
551:
552: # Active is a temporary solution, remember to change
553: Apache::loncoursedata::ProcessClasslist(\%cache,$classlist,$courseID,$c);
554: if($c->aborted()) {
555: untie(%cache);
556: return 'aborted';
557: }
1.27 stredwic 558:
1.29 stredwic 559: &ProcessFormData(\%cache);
560: my $students = &SortStudents(\%cache);
1.32 stredwic 561: &SpaceColumns($students, $studentInformation, $headings, \%cache);
562: $cache{'updateTime:columnWidth'}=24;
1.27 stredwic 563:
1.48 stredwic 564: my $download = $cache{'download'};
565: my $downloadAll = $cache{'DownloadAll'};
566: my @allStudents=();
567: if($download ne 'false') {
1.29 stredwic 568: $cache{'download'} = 'false';
1.48 stredwic 569: } elsif($downloadAll ne 'false') {
570: $cache{'DownloadAll'} = 'false';
571: if($downloadAll eq 'sorted') {
572: @allStudents = @$students;
573: } else {
574: @allStudents = split(':::', $cache{'NamesOfStudents'});
575: }
576: }
577:
578: untie(%cache);
579:
580: if($download ne 'false') {
581: my @who = ($download);
1.55 minaeibi 582: if(&Apache::loncoursedata::DownloadStudentCourseData(\@who, 'false',
583: $cacheDB, 'true',
1.41 stredwic 584: 'false', $courseID,
585: $r, $c) ne 'OK') {
586: return 'Stop at download individual';
587: }
1.48 stredwic 588: } elsif($downloadAll ne 'false') {
1.55 minaeibi 589: if(&Apache::loncoursedata::DownloadStudentCourseData(\@allStudents,
590: 'false',
591: $cacheDB, 'true',
1.41 stredwic 592: 'true', $courseID,
593: $r, $c) ne 'OK') {
594: return 'Stop at download all';
1.27 stredwic 595: }
1.29 stredwic 596: }
597:
598: return ('OK', $students);
1.27 stredwic 599: }
600:
1.29 stredwic 601: sub BuildClasslist {
1.39 stredwic 602: my ($cacheDB,$students,$studentInformation,$headings,$r)=@_;
1.29 stredwic 603:
604: my %cache;
1.38 stredwic 605: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.29 stredwic 606: return '<html><body>Unable to tie database.</body></html>';
1.1 albertel 607: }
608:
1.55 minaeibi 609: # my $Ptr = '';
610: # $Ptr .= '<table border="0"><tbody>';
611: # $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
612: # $Ptr .= '</td>'."\n";
613: # $Ptr .= '<td align="left">'."\n";
614: # my @sectionsSelected = split(':',$cache{'sectionsSelected'});
615: # my @sections = split(':',$cache{'sectionList'});
616: # $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
617: # \@sectionsSelected,
618: # 'Statistics');
619: # $Ptr .= '</td></tr></table><br>';
620: # $r->print($Ptr);
621: # $r->rflush();
622: # my %mySections = ();
623: # foreach (@sections) { $mySections{$_} = 'True'; }
624: # $r->print("<br>$cache{'sectionsSelected'}<br>");
625:
1.29 stredwic 626: my $Str='';
627: $Str .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
628: $Str .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";
629:
630: my $displayString = '<td align="left"><a href="/adm/statistics?';
631: $displayString .= 'sort=LINKDATA">DISPLAYDATA </a></td>'."\n";
1.55 minaeibi 632: $Str .= &Apache::lonhtmlcommon::CreateHeadings(\%cache,
1.39 stredwic 633: $studentInformation,
1.32 stredwic 634: $headings, $displayString);
1.29 stredwic 635: $Str .= '</tr>'."\n";
1.39 stredwic 636:
1.29 stredwic 637: my $alternate=0;
638: foreach (@$students) {
1.55 minaeibi 639: # if ($mySections{$cache{$_.':'.'section'}} ne 'True') {next;}
1.29 stredwic 640: my ($username, $domain) = split(':', $_);
641: if($alternate) {
1.32 stredwic 642: $Str .= '<tr bgcolor="#ffffe6">';
1.29 stredwic 643: } else {
1.32 stredwic 644: $Str .= '<tr bgcolor="#ffffc6">';
1.29 stredwic 645: }
646: $alternate = ($alternate + 1) % 2;
647: foreach my $data (@$studentInformation) {
1.32 stredwic 648: $Str .= '<td>';
1.29 stredwic 649: if($data eq 'fullname') {
650: $Str .= '<a href="/adm/statistics?reportSelected=';
1.30 stredwic 651: $Str .= &Apache::lonnet::escape('Student Assessment');
652: $Str .= '&StudentAssessmentStudent=';
653: $Str .= &Apache::lonnet::escape($cache{$_.':'.$data}).'">';
1.32 stredwic 654: $Str .= $cache{$_.':'.$data}.' ';
1.29 stredwic 655: $Str .= '</a>';
1.32 stredwic 656: } elsif($data eq 'updateTime') {
657: $Str .= '<a href="/adm/statistics?reportSelected=';
658: $Str .= &Apache::lonnet::escape('Class list');
659: $Str .= '&download='.$_.'">';
660: $Str .= $cache{$_.':'.$data}.' ';
661: $Str .= ' </a>';
662: } else {
663: $Str .= $cache{$_.':'.$data}.' ';
1.29 stredwic 664: }
665:
1.32 stredwic 666: $Str .= '</td>'."\n";
1.29 stredwic 667: }
1.1 albertel 668: }
1.29 stredwic 669:
1.32 stredwic 670: $Str .= '</tr>'."\n";
1.29 stredwic 671: $Str .= '</table></td></tr></table>'."\n";
1.39 stredwic 672: $r->print($Str);
673: $r->rflush();
1.29 stredwic 674:
1.27 stredwic 675: untie(%cache);
1.1 albertel 676:
1.39 stredwic 677: return;
1.1 albertel 678: }
679:
1.33 stredwic 680: sub CreateMainMenu {
681: my ($status, $reports)=@_;
682:
683: my $Str = '';
684:
685: $Str .= '<table border="0"><tbody><tr>'."\n";
686: $Str .= '<td></td><td></td>'."\n";
1.57 minaeibi 687: $Str .= '<td align="center"><b>Select a Report</b></td>'."\n";
688: $Str .= '<td align="center"><b>Student Status</b></td></tr>'."\n";
1.33 stredwic 689: $Str .= '<tr>'."\n";
690: $Str .= '<td align="center"><input type="submit" name="Refresh" ';
691: $Str .= 'value="Refresh" /></td>'."\n";
692: $Str .= '<td align="center"><input type="submit" name="DownloadAll" ';
693: $Str .= 'value="Update All Student Data" /></td>'."\n";
694: $Str .= '<td align="center">';
695: $Str .= '<select name="reportSelected" onchange="document.';
696: $Str .= 'Statistics.submit()">'."\n";
697:
698: foreach (sort(keys(%$reports))) {
699: next if($_ eq 'reportSelected');
700: $Str .= '<option name="'.$_.'"';
701: if($reports->{'reportSelected'} eq $reports->{$_}) {
702: $Str .= ' selected=""';
703: }
704: $Str .= '>'.$reports->{$_}.'</option>'."\n";
705: }
706: $Str .= '</select></td>'."\n";
707:
708: $Str .= '<td align="center">';
709: $Str .= &Apache::lonhtmlcommon::StatusOptions($status, 'Statistics');
710: $Str .= '</td>'."\n";
711:
712: $Str .= '</tr></tbody></table>'."\n";
713: $Str .= '<hr>'."\n";
714:
715: return $Str;
716: }
717:
1.29 stredwic 718: sub BuildStatistics {
719: my ($r)=@_;
720:
721: my $c = $r->connection;
1.32 stredwic 722: my @studentInformation=('fullname','section','id','domain','username',
723: 'updateTime');
724: my @headings=('Full Name', 'Section', 'PID', 'Domain', 'User Name',
725: 'Last Updated');
1.55 minaeibi 726: my $spacing = ' ';
1.52 minaeibi 727:
1.29 stredwic 728: my %reports = ('classlist' => 'Class list',
729: 'problem_statistics' => 'Problem Statistics',
730: 'student_assessment' => 'Student Assessment',
1.58 minaeibi 731: 'percentage' => 'Correct-problems Plot',
1.40 minaeibi 732: # 'activitylog' => 'Activity Log',
1.29 stredwic 733: 'reportSelected' => 'Class list');
1.27 stredwic 734:
735: my %cache;
1.29 stredwic 736: my $courseID=$ENV{'request.course.id'};
737: my $cacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
738: "_$ENV{'user.domain'}_$courseID\_statistics.db";
739:
1.47 www 740: $r->print(&Apache::lonhtmlcommon::Title('Course Statistics and Charts'));
1.41 stredwic 741:
1.55 minaeibi 742: my ($returnValue, $students) = &PrepareData($c, $cacheDB,
743: \@studentInformation,
1.38 stredwic 744: \@headings,$r);
1.29 stredwic 745: if($returnValue ne 'OK') {
1.41 stredwic 746: $r->print($returnValue."\n".'</body></html>');
1.29 stredwic 747: return OK;
748: }
1.41 stredwic 749: if(!$c->aborted()) {
1.55 minaeibi 750: &Apache::loncoursedata::CheckForResidualDownload($cacheDB,
1.41 stredwic 751: 'true', 'true',
752: $courseID,
753: $r, $c);
754: }
1.29 stredwic 755:
756: my $GoToPage;
1.38 stredwic 757: if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.29 stredwic 758: $GoToPage = $cache{'reportSelected'};
759: $reports{'reportSelected'} = $cache{'reportSelected'};
1.55 minaeibi 760: if(defined($cache{'reportKey'}) &&
761: !exists($reports{$cache{'reportKey'}}) &&
1.37 stredwic 762: $cache{'reportKey'} ne 'false') {
763: $reports{$cache{'reportKey'}} = $cache{'reportSelected'};
764: }
1.29 stredwic 765:
766: if(defined($cache{'OptionResponses'})) {
1.46 stredwic 767: $reports{'problem_analysis'} = 'Option Response Analysis';
1.29 stredwic 768: }
769:
770: $r->print('<form name="Statistics" ');
771: $r->print('method="post" action="/adm/statistics">');
1.33 stredwic 772: $r->print(&CreateMainMenu($cache{'Status'}, \%reports));
1.39 stredwic 773: $r->rflush();
1.29 stredwic 774: untie(%cache);
775: } else {
1.27 stredwic 776: $r->print('<html><body>Unable to tie database.</body></html>');
1.29 stredwic 777: return OK;
778: }
779:
780: if($GoToPage eq 'Activity Log') {
1.30 stredwic 781: &Apache::lonproblemstatistics::Activity();
1.29 stredwic 782: } elsif($GoToPage eq 'Problem Statistics') {
1.55 minaeibi 783: &Apache::lonproblemstatistics::BuildProblemStatisticsPage($cacheDB,
784: $students,
785: $courseID,
1.36 minaeibi 786: $c,$r);
1.46 stredwic 787: } elsif($GoToPage eq 'Option Response Analysis') {
1.39 stredwic 788: &Apache::lonproblemanalysis::BuildProblemAnalysisPage($cacheDB, $r);
1.29 stredwic 789: } elsif($GoToPage eq 'Student Assessment') {
1.39 stredwic 790: &Apache::lonstudentassessment::BuildStudentAssessmentPage($cacheDB,
1.37 stredwic 791: $students,
792: $courseID,
793: 'Statistics',
794: \@headings,
795: $spacing,
796: \@studentInformation,
1.39 stredwic 797: $r, $c);
1.29 stredwic 798: } elsif($GoToPage eq 'Analyze') {
1.55 minaeibi 799: &Apache::lonproblemanalysis::BuildAnalyzePage($cacheDB, $students,
1.39 stredwic 800: $courseID, $r);
1.40 minaeibi 801: } elsif($GoToPage eq 'DoDiffGraph' || $GoToPage eq 'PercentWrongGraph') {
1.43 stredwic 802: my $courseDescription = $ENV{'course.'.$courseID.'.description'};
803: $courseDescription =~ s/\ /"_"/eg;
804: &Apache::lonproblemstatistics::BuildGraphicChart($GoToPage, $cacheDB,
805: $courseDescription,
1.45 stredwic 806: $students, $courseID,
807: $r, $c);
1.29 stredwic 808: } elsif($GoToPage eq 'Class list') {
1.39 stredwic 809: &BuildClasslist($cacheDB, $students, \@studentInformation,
810: \@headings, $r);
1.58 minaeibi 811: } elsif($GoToPage eq 'Correct-problems Plot') {
1.49 stredwic 812: &Apache::lonpercentage::BuildPercentageGraph($cacheDB, $students,
813: $courseID, $c, $r);
1.27 stredwic 814: }
815:
816: $r->print('</form>'."\n");
1.29 stredwic 817: $r->print("\n".'</body>'."\n".'</html>');
818: $r->rflush();
1.27 stredwic 819:
1.29 stredwic 820: return OK;
1.27 stredwic 821: }
1.1 albertel 822:
823: # ================================================================ Main Handler
824:
825: sub handler {
1.31 minaeibi 826: my $r=shift;
1.34 stredwic 827:
828: # $jr = $r;
1.51 www 829:
830: my $loaderror=&Apache::lonnet::overloaderror($r);
831: if ($loaderror) { return $loaderror; }
832: $loaderror=
833: &Apache::lonnet::overloaderror($r,
834: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
835: if ($loaderror) { return $loaderror; }
1.1 albertel 836:
1.27 stredwic 837: unless(&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
838: $ENV{'user.error.msg'}=
839: $r->uri.":vgr:0:0:Cannot view grades for complete course";
1.55 minaeibi 840: return HTTP_NOT_ACCEPTABLE;
1.27 stredwic 841: }
842:
843: # Set document type for header only
844: if($r->header_only) {
845: if ($ENV{'browser.mathml'}) {
846: $r->content_type('text/xml');
847: } else {
848: $r->content_type('text/html');
849: }
850: &Apache::loncommon::no_cache($r);
851: $r->send_http_header;
852: return OK;
853: }
854:
855: unless($ENV{'request.course.fn'}) {
1.1 albertel 856: my $requrl=$r->uri;
1.27 stredwic 857: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
1.55 minaeibi 858: return HTTP_NOT_ACCEPTABLE;
1.27 stredwic 859: }
1.1 albertel 860:
1.27 stredwic 861: $r->content_type('text/html');
862: $r->send_http_header;
1.1 albertel 863:
1.59 ! matthew 864: &PrepareClasslist($r);
! 865:
1.29 stredwic 866: &BuildStatistics($r);
1.27 stredwic 867:
868: return OK;
1.1 albertel 869: }
870: 1;
1.59 ! matthew 871:
! 872: =pod
! 873:
! 874: =back
! 875:
! 876: =cut
! 877:
1.1 albertel 878: __END__
1.31 minaeibi 879:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>