Annotation of loncom/interface/lonstatistics.pm, revision 1.58
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.58 ! minaeibi 4: # $Id: lonstatistics.pm,v 1.57 2003/01/12 23:31:22 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.55 minaeibi 38: package Apache::lonstatistics;
1.1 albertel 39:
1.30 stredwic 40: use strict;
1.1 albertel 41: use Apache::Constants qw(:common :http);
42: use Apache::lonnet();
43: use Apache::lonhomework;
1.12 minaeibi 44: use Apache::loncommon;
1.29 stredwic 45: use Apache::loncoursedata;
46: use Apache::lonhtmlcommon;
1.30 stredwic 47: use Apache::lonproblemanalysis;
48: use Apache::lonproblemstatistics;
49: use Apache::lonstudentassessment;
1.49 stredwic 50: use Apache::lonpercentage;
1.1 albertel 51: use HTML::TokeParser;
52: use GDBM_File;
53:
1.27 stredwic 54:
55: sub CheckFormElement {
56: my ($cache, $ENVName, $cacheName, $default)=@_;
57:
58: if(defined($ENV{'form.'.$ENVName})) {
59: $cache->{$cacheName} = $ENV{'form.'.$ENVName};
60: } elsif(!defined($cache->{$cacheName})) {
61: $cache->{$cacheName} = $default;
62: }
63:
64: return;
65: }
66:
67: sub ProcessFormData{
1.29 stredwic 68: my ($cache)=@_;
1.27 stredwic 69:
1.29 stredwic 70: $cache->{'reportKey'} = 'false';
1.27 stredwic 71:
1.29 stredwic 72: &Apache::loncommon::get_unprocessed_cgi($ENV{'QUERY_STRING'},
1.34 stredwic 73: ['sort','download',
74: 'reportSelected',
1.41 stredwic 75: 'StudentAssessmentStudent',
76: 'ProblemStatisticsSort']);
1.56 matthew 77: &CheckFormElement($cache, 'DownloadAll', 'DownloadAll', 'false');
78: if ($cache->{'DownloadAll'} ne 'false') {
79: # Clean the hell out of that cache!
80: # We cannot untie the hash at this scope (stupid libgd :( )
81: # So, remove every single key. What a waste of time....
82: # Of course, if you are doing this you are probably resigned
83: # to waiting a while.
84: &Apache::lonnet::logthis("Cleaning out the cache file");
85: while (my ($key,undef)=each(%$cache)) {
86: next if ($key eq 'DownloadAll');
87: delete($cache->{$key});
88: }
89: }
1.29 stredwic 90: &CheckFormElement($cache, 'Status', 'Status', 'Active');
91: &CheckFormElement($cache, 'postdata', 'reportSelected', 'Class list');
92: &CheckFormElement($cache, 'reportSelected', 'reportSelected',
93: 'Class list');
1.30 stredwic 94: $cache->{'reportSelected'} =
95: &Apache::lonnet::unescape($cache->{'reportSelected'});
1.29 stredwic 96: &CheckFormElement($cache, 'sort', 'sort', 'fullname');
97: &CheckFormElement($cache, 'download', 'download', 'false');
1.44 stredwic 98: &CheckFormElement($cache, 'StatisticsMaps',
99: 'StatisticsMaps', 'All Maps');
1.49 stredwic 100: &CheckFormElement($cache, 'StatisticsProblemSelect',
101: 'StatisticsProblemSelect', 'All Problems');
102: &CheckFormElement($cache, 'StatisticsPartSelect',
103: 'StatisticsPartSelect', 'All Parts');
1.44 stredwic 104: if(defined($ENV{'form.Section'})) {
105: my @sectionsSelected = (ref($ENV{'form.Section'}) ?
106: @{$ENV{'form.Section'}} :
107: ($ENV{'form.Section'}));
108: $cache->{'sectionsSelected'} = join(':', @sectionsSelected);
109: } elsif(!defined($cache->{'sectionsSelected'})) {
110: $cache->{'sectionsSelected'} = $cache->{'sectionList'};
111: }
1.29 stredwic 112:
1.38 stredwic 113: # student assessment
1.29 stredwic 114: if(defined($ENV{'form.CreateStudentAssessment'}) ||
115: defined($ENV{'form.NextStudent'}) ||
116: defined($ENV{'form.PreviousStudent'})) {
117: $cache->{'reportSelected'} = 'Student Assessment';
118: }
119: if(defined($ENV{'form.NextStudent'})) {
120: $cache->{'StudentAssessmentMove'} = 'next';
121: } elsif(defined($ENV{'form.PreviousStudent'})) {
122: $cache->{'StudentAssessmentMove'} = 'previous';
123: } else {
124: $cache->{'StudentAssessmentMove'} = 'selected';
125: }
126: &CheckFormElement($cache, 'StudentAssessmentStudent',
1.30 stredwic 127: 'StudentAssessmentStudent', 'All Students');
128: $cache->{'StudentAssessmentStudent'} =
129: &Apache::lonnet::unescape($cache->{'StudentAssessmentStudent'});
1.34 stredwic 130: &CheckFormElement($cache, 'DefaultColumns', 'DefaultColumns', 'false');
1.29 stredwic 131:
1.38 stredwic 132: # Problem analysis
133: &CheckFormElement($cache, 'Interval', 'Interval', '1');
134:
135: # ProblemStatistcs
136: &CheckFormElement($cache, 'DisplayCSVFormat',
137: 'DisplayFormat', 'Display Table Format');
138: &CheckFormElement($cache, 'ProblemStatisticsAscend',
139: 'ProblemStatisticsAscend', 'Ascending');
1.41 stredwic 140: &CheckFormElement($cache, 'ProblemStatisticsSort',
141: 'ProblemStatisticsSort', 'Homework Sets Order');
1.49 stredwic 142: &CheckFormElement($cache, 'DisplayLegend', 'DisplayLegend',
143: 'Hide Legend');
1.45 stredwic 144: &CheckFormElement($cache, 'SortProblems', 'SortProblems',
145: 'Sort Within Sequence');
1.38 stredwic 146:
147: # Search only form elements
1.34 stredwic 148: my @headingColumns=();
149: my @sequenceColumns=();
150: my $foundColumn = 0;
151: if(defined($ENV{'form.ReselectColumns'})) {
152: my @reselected = (ref($ENV{'form.ReselectColumns'}) ?
153: @{$ENV{'form.ReselectColumns'}}
154: : ($ENV{'form.ReselectColumns'}));
155: foreach (@reselected) {
156: if(/HeadingColumn/) {
157: push(@headingColumns, $_);
158: $foundColumn = 1;
159: } elsif(/SequenceColumn/) {
160: push(@sequenceColumns, $_);
161: $foundColumn = 1;
162: }
163: }
164: }
165:
1.37 stredwic 166: $cache->{'reportKey'} = 'false';
167: if($cache->{'reportSelected'} eq 'Analyze') {
168: $cache->{'reportKey'} = 'Analyze';
1.38 stredwic 169: } elsif($cache->{'reportSelected'} eq 'DoDiffGraph') {
170: $cache->{'reportKey'} = 'DoDiffGraph';
171: } elsif($cache->{'reportSelected'} eq 'PercentWrongGraph') {
172: $cache->{'reportKey'} = 'PercentWrongGraph';
173: }
174:
175: if(defined($ENV{'form.DoDiffGraph'})) {
176: $cache->{'reportSelected'} = 'DoDiffGraph';
177: $cache->{'reportKey'} = 'DoDiffGraph';
178: } elsif(defined($ENV{'form.PercentWrongGraph'})) {
179: $cache->{'reportSelected'} = 'PercentWrongGraph';
180: $cache->{'reportKey'} = 'PercentWrongGraph';
1.37 stredwic 181: }
182:
1.29 stredwic 183: foreach (keys(%ENV)) {
1.37 stredwic 184: if(/form\.Analyze/) {
185: $cache->{'reportSelected'} = 'Analyze';
186: $cache->{'reportKey'} = 'Analyze';
187: my $data;
188: (undef, $data)=split(':::', $_);
189: $cache->{'AnalyzeInfo'}=$data;
1.34 stredwic 190: } elsif(/form\.HeadingColumn/) {
191: my $value = $_;
192: $value =~ s/form\.//;
193: push(@headingColumns, $value);
194: $foundColumn=1;
195: } elsif(/form\.SequenceColumn/) {
196: my $value = $_;
197: $value =~ s/form\.//;
198: push(@sequenceColumns, $value);
199: $foundColumn=1;
1.27 stredwic 200: }
1.29 stredwic 201: }
1.27 stredwic 202:
1.34 stredwic 203: if($foundColumn) {
204: $cache->{'HeadingsFound'} = join(':', @headingColumns);
205: $cache->{'SequencesFound'} = join(':', @sequenceColumns);;
206: }
207: if(!defined($cache->{'HeadingsFound'}) ||
208: $cache->{'DefaultColumns'} ne 'false') {
209: $cache->{'HeadingsFound'}='HeadingColumnFull Name';
210: }
211: if(!defined($cache->{'SequencesFound'}) ||
212: $cache->{'DefaultColumns'} ne 'false') {
213: $cache->{'SequencesFound'}='All Sequences';
214: }
215: $cache->{'DefaultColumns'} = 'false';
216:
1.29 stredwic 217: return;
1.27 stredwic 218: }
219:
220: =pod
221:
222: =item &SortStudents()
223:
224: Determines which students to display and in which order. Which are
225: displayed are determined by their status(active/expired). The order
226: is determined by the sort button pressed (default to username). The
227: type of sorting is username, lastname, or section.
228:
229: =over 4
230:
231: Input: $students, $CacheData
232:
233: $students: A array pointer to a list of students (username:domain)
234:
235: $CacheData: A pointer to the hash tied to the cached data
236:
237: Output: \@order
238:
239: @order: An ordered list of students (username:domain)
240:
241: =back
242:
243: =cut
244:
245: sub SortStudents {
1.29 stredwic 246: my ($cache)=@_;
1.27 stredwic 247:
1.29 stredwic 248: my @students = split(':::',$cache->{'NamesOfStudents'});
1.27 stredwic 249: my @sorted1Students=();
1.29 stredwic 250: foreach (@students) {
251: if($cache->{'Status'} eq 'Any' ||
252: $cache->{$_.':Status'} eq $cache->{'Status'}) {
253: push(@sorted1Students, $_);
254: }
1.1 albertel 255: }
1.27 stredwic 256:
1.29 stredwic 257: my $sortBy = '';
258: if(defined($cache->{'sort'})) {
259: $sortBy = ':'.$cache->{'sort'};
1.54 matthew 260: } else {
261: $sortBy = ':fullname';
1.27 stredwic 262: }
1.54 matthew 263: my @order = sort { lc($cache->{$a.$sortBy}) cmp lc($cache->{$b.$sortBy}) ||
264: lc($cache->{$a.':fullname'}) cmp lc($cache->{$b.':fullname'}) }
1.29 stredwic 265: @sorted1Students;
1.27 stredwic 266:
267: return \@order;
268: }
269:
1.32 stredwic 270: =pod
271:
272: =item &SpaceColumns()
273:
274: Determines the width of all the columns in the chart. It is based on
275: the max of the data for that column and its header.
276:
277: =over 4
278:
279: Input: $students, $studentInformation, $headings, $ChartDB
280:
281: $students: An array pointer to a list of students (username:domain)
282:
283: $studentInformatin: The type of data for the student information. It is
284: used as part of the key in $CacheData.
285:
286: $headings: The name of the student information columns.
287:
288: $ChartDB: The name of the cache database which is opened for read/write.
289:
290: Output: None - All data stored in cache.
291:
292: =back
293:
294: =cut
295:
296: sub SpaceColumns {
297: my ($students,$studentInformation,$headings,$cache)=@_;
298:
299: # Initialize Lengths
300: for(my $index=0; $index<(scalar @$headings); $index++) {
301: my @titleLength=split(//,$headings->[$index]);
302: $cache->{$studentInformation->[$index].':columnWidth'}=
303: scalar @titleLength;
304: }
305:
306: foreach my $name (@$students) {
307: foreach (@$studentInformation) {
308: my @dataLength=split(//,$cache->{$name.':'.$_});
309: my $length=(scalar @dataLength);
310: if($length > $cache->{$_.':columnWidth'}) {
311: $cache->{$_.':columnWidth'}=$length;
312: }
313: }
314: }
315:
316: return;
317: }
318:
1.27 stredwic 319: sub PrepareData {
1.38 stredwic 320: my ($c, $cacheDB, $studentInformation, $headings,$r)=@_;
1.27 stredwic 321:
322: # Test for access to the cache data
323: my $courseID=$ENV{'request.course.id'};
324: my $isRecalculate=0;
1.29 stredwic 325: if(defined($ENV{'form.Recalculate'})) {
1.27 stredwic 326: $isRecalculate=1;
327: }
328:
1.55 minaeibi 329: my $isCached = &Apache::loncoursedata::TestCacheData($cacheDB,
1.29 stredwic 330: $isRecalculate);
1.27 stredwic 331: if($isCached < 0) {
332: return "Unable to tie hash to db file.";
333: }
334:
335: # Download class list information if not using cached data
336: my %cache;
1.38 stredwic 337: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT(),0640)) {
1.29 stredwic 338: return "Unable to tie hash to db file.";
339: }
340:
1.50 stredwic 341: # if(!$isCached) {
1.27 stredwic 342: my $processTopResourceMapReturn=
1.50 stredwic 343: &Apache::loncoursedata::ProcessTopResourceMap(\%cache, $c);
1.27 stredwic 344: if($processTopResourceMapReturn ne 'OK') {
345: untie(%cache);
346: return $processTopResourceMapReturn;
347: }
1.50 stredwic 348: # }
1.27 stredwic 349:
1.29 stredwic 350: if($c->aborted()) {
351: untie(%cache);
352: return 'aborted';
353: }
1.27 stredwic 354:
1.29 stredwic 355: my $classlist=&Apache::loncoursedata::DownloadClasslist($courseID,
356: $cache{'ClasslistTimestamp'},
357: $c);
358: foreach (keys(%$classlist)) {
359: if(/^(con_lost|error|no_such_host)/i) {
1.27 stredwic 360: untie(%cache);
361: return "Error getting student data.";
362: }
1.29 stredwic 363: }
1.27 stredwic 364:
1.29 stredwic 365: if($c->aborted()) {
366: untie(%cache);
367: return 'aborted';
368: }
369:
370: # Active is a temporary solution, remember to change
371: Apache::loncoursedata::ProcessClasslist(\%cache,$classlist,$courseID,$c);
372: if($c->aborted()) {
373: untie(%cache);
374: return 'aborted';
375: }
1.27 stredwic 376:
1.29 stredwic 377: &ProcessFormData(\%cache);
378: my $students = &SortStudents(\%cache);
1.32 stredwic 379: &SpaceColumns($students, $studentInformation, $headings, \%cache);
380: $cache{'updateTime:columnWidth'}=24;
1.27 stredwic 381:
1.48 stredwic 382: my $download = $cache{'download'};
383: my $downloadAll = $cache{'DownloadAll'};
384: my @allStudents=();
385: if($download ne 'false') {
1.29 stredwic 386: $cache{'download'} = 'false';
1.48 stredwic 387: } elsif($downloadAll ne 'false') {
388: $cache{'DownloadAll'} = 'false';
389: if($downloadAll eq 'sorted') {
390: @allStudents = @$students;
391: } else {
392: @allStudents = split(':::', $cache{'NamesOfStudents'});
393: }
394: }
395:
396: untie(%cache);
397:
398: if($download ne 'false') {
399: my @who = ($download);
1.55 minaeibi 400: if(&Apache::loncoursedata::DownloadStudentCourseData(\@who, 'false',
401: $cacheDB, 'true',
1.41 stredwic 402: 'false', $courseID,
403: $r, $c) ne 'OK') {
404: return 'Stop at download individual';
405: }
1.48 stredwic 406: } elsif($downloadAll ne 'false') {
1.55 minaeibi 407: if(&Apache::loncoursedata::DownloadStudentCourseData(\@allStudents,
408: 'false',
409: $cacheDB, 'true',
1.41 stredwic 410: 'true', $courseID,
411: $r, $c) ne 'OK') {
412: return 'Stop at download all';
1.27 stredwic 413: }
1.29 stredwic 414: }
415:
416: return ('OK', $students);
1.27 stredwic 417: }
418:
1.29 stredwic 419: sub BuildClasslist {
1.39 stredwic 420: my ($cacheDB,$students,$studentInformation,$headings,$r)=@_;
1.29 stredwic 421:
422: my %cache;
1.38 stredwic 423: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.29 stredwic 424: return '<html><body>Unable to tie database.</body></html>';
1.1 albertel 425: }
426:
1.55 minaeibi 427: # my $Ptr = '';
428: # $Ptr .= '<table border="0"><tbody>';
429: # $Ptr .= '<tr><td align="right"><b>Select Sections</b>';
430: # $Ptr .= '</td>'."\n";
431: # $Ptr .= '<td align="left">'."\n";
432: # my @sectionsSelected = split(':',$cache{'sectionsSelected'});
433: # my @sections = split(':',$cache{'sectionList'});
434: # $Ptr .= &Apache::lonhtmlcommon::MultipleSectionSelect(\@sections,
435: # \@sectionsSelected,
436: # 'Statistics');
437: # $Ptr .= '</td></tr></table><br>';
438: # $r->print($Ptr);
439: # $r->rflush();
440: # my %mySections = ();
441: # foreach (@sections) { $mySections{$_} = 'True'; }
442: # $r->print("<br>$cache{'sectionsSelected'}<br>");
443:
1.29 stredwic 444: my $Str='';
445: $Str .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
446: $Str .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";
447:
448: my $displayString = '<td align="left"><a href="/adm/statistics?';
449: $displayString .= 'sort=LINKDATA">DISPLAYDATA </a></td>'."\n";
1.55 minaeibi 450: $Str .= &Apache::lonhtmlcommon::CreateHeadings(\%cache,
1.39 stredwic 451: $studentInformation,
1.32 stredwic 452: $headings, $displayString);
1.29 stredwic 453: $Str .= '</tr>'."\n";
1.39 stredwic 454:
1.29 stredwic 455: my $alternate=0;
456: foreach (@$students) {
1.55 minaeibi 457: # if ($mySections{$cache{$_.':'.'section'}} ne 'True') {next;}
1.29 stredwic 458: my ($username, $domain) = split(':', $_);
459: if($alternate) {
1.32 stredwic 460: $Str .= '<tr bgcolor="#ffffe6">';
1.29 stredwic 461: } else {
1.32 stredwic 462: $Str .= '<tr bgcolor="#ffffc6">';
1.29 stredwic 463: }
464: $alternate = ($alternate + 1) % 2;
465: foreach my $data (@$studentInformation) {
1.32 stredwic 466: $Str .= '<td>';
1.29 stredwic 467: if($data eq 'fullname') {
468: $Str .= '<a href="/adm/statistics?reportSelected=';
1.30 stredwic 469: $Str .= &Apache::lonnet::escape('Student Assessment');
470: $Str .= '&StudentAssessmentStudent=';
471: $Str .= &Apache::lonnet::escape($cache{$_.':'.$data}).'">';
1.32 stredwic 472: $Str .= $cache{$_.':'.$data}.' ';
1.29 stredwic 473: $Str .= '</a>';
1.32 stredwic 474: } elsif($data eq 'updateTime') {
475: $Str .= '<a href="/adm/statistics?reportSelected=';
476: $Str .= &Apache::lonnet::escape('Class list');
477: $Str .= '&download='.$_.'">';
478: $Str .= $cache{$_.':'.$data}.' ';
479: $Str .= ' </a>';
480: } else {
481: $Str .= $cache{$_.':'.$data}.' ';
1.29 stredwic 482: }
483:
1.32 stredwic 484: $Str .= '</td>'."\n";
1.29 stredwic 485: }
1.1 albertel 486: }
1.29 stredwic 487:
1.32 stredwic 488: $Str .= '</tr>'."\n";
1.29 stredwic 489: $Str .= '</table></td></tr></table>'."\n";
1.39 stredwic 490: $r->print($Str);
491: $r->rflush();
1.29 stredwic 492:
1.27 stredwic 493: untie(%cache);
1.1 albertel 494:
1.39 stredwic 495: return;
1.1 albertel 496: }
497:
1.33 stredwic 498: sub CreateMainMenu {
499: my ($status, $reports)=@_;
500:
501: my $Str = '';
502:
503: $Str .= '<table border="0"><tbody><tr>'."\n";
504: $Str .= '<td></td><td></td>'."\n";
1.57 minaeibi 505: $Str .= '<td align="center"><b>Select a Report</b></td>'."\n";
506: $Str .= '<td align="center"><b>Student Status</b></td></tr>'."\n";
1.33 stredwic 507: $Str .= '<tr>'."\n";
508: $Str .= '<td align="center"><input type="submit" name="Refresh" ';
509: $Str .= 'value="Refresh" /></td>'."\n";
510: $Str .= '<td align="center"><input type="submit" name="DownloadAll" ';
511: $Str .= 'value="Update All Student Data" /></td>'."\n";
512: $Str .= '<td align="center">';
513: $Str .= '<select name="reportSelected" onchange="document.';
514: $Str .= 'Statistics.submit()">'."\n";
515:
516: foreach (sort(keys(%$reports))) {
517: next if($_ eq 'reportSelected');
518: $Str .= '<option name="'.$_.'"';
519: if($reports->{'reportSelected'} eq $reports->{$_}) {
520: $Str .= ' selected=""';
521: }
522: $Str .= '>'.$reports->{$_}.'</option>'."\n";
523: }
524: $Str .= '</select></td>'."\n";
525:
526: $Str .= '<td align="center">';
527: $Str .= &Apache::lonhtmlcommon::StatusOptions($status, 'Statistics');
528: $Str .= '</td>'."\n";
529:
530: $Str .= '</tr></tbody></table>'."\n";
531: $Str .= '<hr>'."\n";
532:
533: return $Str;
534: }
535:
1.29 stredwic 536: sub BuildStatistics {
537: my ($r)=@_;
538:
539: my $c = $r->connection;
1.32 stredwic 540: my @studentInformation=('fullname','section','id','domain','username',
541: 'updateTime');
542: my @headings=('Full Name', 'Section', 'PID', 'Domain', 'User Name',
543: 'Last Updated');
1.55 minaeibi 544: my $spacing = ' ';
1.52 minaeibi 545:
1.29 stredwic 546: my %reports = ('classlist' => 'Class list',
547: 'problem_statistics' => 'Problem Statistics',
548: 'student_assessment' => 'Student Assessment',
1.58 ! minaeibi 549: 'percentage' => 'Correct-problems Plot',
1.40 minaeibi 550: # 'activitylog' => 'Activity Log',
1.29 stredwic 551: 'reportSelected' => 'Class list');
1.27 stredwic 552:
553: my %cache;
1.29 stredwic 554: my $courseID=$ENV{'request.course.id'};
555: my $cacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
556: "_$ENV{'user.domain'}_$courseID\_statistics.db";
557:
1.47 www 558: $r->print(&Apache::lonhtmlcommon::Title('Course Statistics and Charts'));
1.41 stredwic 559:
1.55 minaeibi 560: my ($returnValue, $students) = &PrepareData($c, $cacheDB,
561: \@studentInformation,
1.38 stredwic 562: \@headings,$r);
1.29 stredwic 563: if($returnValue ne 'OK') {
1.41 stredwic 564: $r->print($returnValue."\n".'</body></html>');
1.29 stredwic 565: return OK;
566: }
1.41 stredwic 567: if(!$c->aborted()) {
1.55 minaeibi 568: &Apache::loncoursedata::CheckForResidualDownload($cacheDB,
1.41 stredwic 569: 'true', 'true',
570: $courseID,
571: $r, $c);
572: }
1.29 stredwic 573:
574: my $GoToPage;
1.38 stredwic 575: if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER(),0640)) {
1.29 stredwic 576: $GoToPage = $cache{'reportSelected'};
577: $reports{'reportSelected'} = $cache{'reportSelected'};
1.55 minaeibi 578: if(defined($cache{'reportKey'}) &&
579: !exists($reports{$cache{'reportKey'}}) &&
1.37 stredwic 580: $cache{'reportKey'} ne 'false') {
581: $reports{$cache{'reportKey'}} = $cache{'reportSelected'};
582: }
1.29 stredwic 583:
584: if(defined($cache{'OptionResponses'})) {
1.46 stredwic 585: $reports{'problem_analysis'} = 'Option Response Analysis';
1.29 stredwic 586: }
587:
588: $r->print('<form name="Statistics" ');
589: $r->print('method="post" action="/adm/statistics">');
1.33 stredwic 590: $r->print(&CreateMainMenu($cache{'Status'}, \%reports));
1.39 stredwic 591: $r->rflush();
1.29 stredwic 592: untie(%cache);
593: } else {
1.27 stredwic 594: $r->print('<html><body>Unable to tie database.</body></html>');
1.29 stredwic 595: return OK;
596: }
597:
598: if($GoToPage eq 'Activity Log') {
1.30 stredwic 599: &Apache::lonproblemstatistics::Activity();
1.29 stredwic 600: } elsif($GoToPage eq 'Problem Statistics') {
1.55 minaeibi 601: &Apache::lonproblemstatistics::BuildProblemStatisticsPage($cacheDB,
602: $students,
603: $courseID,
1.36 minaeibi 604: $c,$r);
1.46 stredwic 605: } elsif($GoToPage eq 'Option Response Analysis') {
1.39 stredwic 606: &Apache::lonproblemanalysis::BuildProblemAnalysisPage($cacheDB, $r);
1.29 stredwic 607: } elsif($GoToPage eq 'Student Assessment') {
1.39 stredwic 608: &Apache::lonstudentassessment::BuildStudentAssessmentPage($cacheDB,
1.37 stredwic 609: $students,
610: $courseID,
611: 'Statistics',
612: \@headings,
613: $spacing,
614: \@studentInformation,
1.39 stredwic 615: $r, $c);
1.29 stredwic 616: } elsif($GoToPage eq 'Analyze') {
1.55 minaeibi 617: &Apache::lonproblemanalysis::BuildAnalyzePage($cacheDB, $students,
1.39 stredwic 618: $courseID, $r);
1.40 minaeibi 619: } elsif($GoToPage eq 'DoDiffGraph' || $GoToPage eq 'PercentWrongGraph') {
1.43 stredwic 620: my $courseDescription = $ENV{'course.'.$courseID.'.description'};
621: $courseDescription =~ s/\ /"_"/eg;
622: &Apache::lonproblemstatistics::BuildGraphicChart($GoToPage, $cacheDB,
623: $courseDescription,
1.45 stredwic 624: $students, $courseID,
625: $r, $c);
1.29 stredwic 626: } elsif($GoToPage eq 'Class list') {
1.39 stredwic 627: &BuildClasslist($cacheDB, $students, \@studentInformation,
628: \@headings, $r);
1.58 ! minaeibi 629: } elsif($GoToPage eq 'Correct-problems Plot') {
1.49 stredwic 630: &Apache::lonpercentage::BuildPercentageGraph($cacheDB, $students,
631: $courseID, $c, $r);
1.27 stredwic 632: }
633:
634: $r->print('</form>'."\n");
1.29 stredwic 635: $r->print("\n".'</body>'."\n".'</html>');
636: $r->rflush();
1.27 stredwic 637:
1.29 stredwic 638: return OK;
1.27 stredwic 639: }
1.1 albertel 640:
641: # ================================================================ Main Handler
642:
643: sub handler {
1.31 minaeibi 644: my $r=shift;
1.34 stredwic 645:
646: # $jr = $r;
1.51 www 647:
648: my $loaderror=&Apache::lonnet::overloaderror($r);
649: if ($loaderror) { return $loaderror; }
650: $loaderror=
651: &Apache::lonnet::overloaderror($r,
652: $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
653: if ($loaderror) { return $loaderror; }
1.1 albertel 654:
1.27 stredwic 655: unless(&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
656: $ENV{'user.error.msg'}=
657: $r->uri.":vgr:0:0:Cannot view grades for complete course";
1.55 minaeibi 658: return HTTP_NOT_ACCEPTABLE;
1.27 stredwic 659: }
660:
661: # Set document type for header only
662: if($r->header_only) {
663: if ($ENV{'browser.mathml'}) {
664: $r->content_type('text/xml');
665: } else {
666: $r->content_type('text/html');
667: }
668: &Apache::loncommon::no_cache($r);
669: $r->send_http_header;
670: return OK;
671: }
672:
673: unless($ENV{'request.course.fn'}) {
1.1 albertel 674: my $requrl=$r->uri;
1.27 stredwic 675: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
1.55 minaeibi 676: return HTTP_NOT_ACCEPTABLE;
1.27 stredwic 677: }
1.1 albertel 678:
1.27 stredwic 679: $r->content_type('text/html');
680: $r->send_http_header;
1.1 albertel 681:
1.29 stredwic 682: &BuildStatistics($r);
1.27 stredwic 683:
684: return OK;
1.1 albertel 685: }
686: 1;
687: __END__
1.31 minaeibi 688:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>