Annotation of loncom/interface/lonstatistics.pm, revision 1.31
1.1 albertel 1: # The LearningOnline Network with CAPA
2: # (Publication Handler
3: #
1.31 ! minaeibi 4: # $Id: lonstatistics.pm,v 1.30 2002/07/24 14:52:32 stredwic 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.31 ! minaeibi 34: # 5/12,5/14,5/15,5/19,5/26,7/16,25/7 Behrouz Minaei
1.14 minaeibi 35: #
1.1 albertel 36: ###
37:
1.3 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.29 stredwic 50: use Apache::lonchart;
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.30 stredwic 73: ['sort','download','reportSelected',
74: 'StudentAssessmentStudent']);
1.29 stredwic 75: &CheckFormElement($cache, 'Status', 'Status', 'Active');
76: &CheckFormElement($cache, 'postdata', 'reportSelected', 'Class list');
77: &CheckFormElement($cache, 'reportSelected', 'reportSelected',
78: 'Class list');
1.30 stredwic 79: $cache->{'reportSelected'} =
80: &Apache::lonnet::unescape($cache->{'reportSelected'});
1.29 stredwic 81: &CheckFormElement($cache, 'DownloadAll', 'DownloadAll', 'false');
82: &CheckFormElement($cache, 'sort', 'sort', 'fullname');
83: &CheckFormElement($cache, 'download', 'download', 'false');
84:
85: if(defined($ENV{'form.CreateStudentAssessment'}) ||
86: defined($ENV{'form.NextStudent'}) ||
87: defined($ENV{'form.PreviousStudent'})) {
88: $cache->{'reportSelected'} = 'Student Assessment';
89: }
90: if(defined($ENV{'form.NextStudent'})) {
91: $cache->{'StudentAssessmentMove'} = 'next';
92: } elsif(defined($ENV{'form.PreviousStudent'})) {
93: $cache->{'StudentAssessmentMove'} = 'previous';
94: } else {
95: $cache->{'StudentAssessmentMove'} = 'selected';
96: }
97: &CheckFormElement($cache, 'StudentAssessmentMap', 'StudentAssessmentMap',
98: 'All Maps');
99: &CheckFormElement($cache, 'StudentAssessmentStudent',
1.30 stredwic 100: 'StudentAssessmentStudent', 'All Students');
101: $cache->{'StudentAssessmentStudent'} =
102: &Apache::lonnet::unescape($cache->{'StudentAssessmentStudent'});
1.29 stredwic 103:
104: foreach (keys(%ENV)) {
105: if(/form\.Analyze:::/) {
106: # $cache->{'reportSelected'} = 'Analyze';
107: # $cache->{'reportKey'} = 'Problem Analysis';
108: my ($uri, $title, $part, $problem);
109: (undef, $uri, $title, $part, $problem)=split(':::', $_);
110: $cache->{'AnalyzeURI'} = $uri;
111: $cache->{'AnalyzeTitle'} = $title;
112: $cache->{'AnalyzePart'} = $part;
113: $cache->{'AnalyzeProblem'} = $problem;
114:
115: &CheckFormElement($cache, 'Interval', 'Interval', '1');
1.27 stredwic 116: }
1.29 stredwic 117: }
1.27 stredwic 118:
1.29 stredwic 119: return;
1.27 stredwic 120:
1.29 stredwic 121: # Select page to display
122: if(defined($ENV{'form.ProblemStatistics'}) ||
123: defined($ENV{'form.ProblemStatisticsRecalculate'}) ||
124: defined($ENV{'form.DisplayCSVFormat'})) {
125: $cache->{'GoToPage'} = 'ProblemStatistics';
126: &CheckFormElement($cache, 'DisplayCSVFormat',
127: 'DisplayFormat', 'Display Table Format');
128: &CheckFormElement($cache, 'Ascend','ProblemStatisticsAscend',
129: 'Ascending');
130: &CheckFormElement($cache, 'Maps', 'ProblemStatisticsMap',
131: 'All Maps');
132: } elsif(defined($ENV{'form.ProblemAnalysis'})) {
133: $cache->{'GoToPage'} = 'ProblemAnalysis';
134: &CheckFormElement($cache, 'Interval', 'Interval', '1');
135: } elsif(defined($ENV{'form.DoDiffGraph'})) {
136: $cache->{'GoToPage'} = 'DoDiffGraph';
137: } elsif(defined($ENV{'form.PercentWrongGraph'})) {
138: $cache->{'GoToPage'} = 'PercentWrongGraph';
139: } elsif(defined($ENV{'form.ActivityLog'})) {
140: $cache->{'GoToPage'} = 'ActivityLog';
141: } else {
142: $cache->{'GoToPage'} = 'Menu';
143: }
1.27 stredwic 144:
1.29 stredwic 145: &CheckFormElement($cache, 'Status', 'Status', 'Active');
1.27 stredwic 146:
147: return;
148: }
149:
150: =pod
151:
152: =item &SortStudents()
153:
154: Determines which students to display and in which order. Which are
155: displayed are determined by their status(active/expired). The order
156: is determined by the sort button pressed (default to username). The
157: type of sorting is username, lastname, or section.
158:
159: =over 4
160:
161: Input: $students, $CacheData
162:
163: $students: A array pointer to a list of students (username:domain)
164:
165: $CacheData: A pointer to the hash tied to the cached data
166:
167: Output: \@order
168:
169: @order: An ordered list of students (username:domain)
170:
171: =back
172:
173: =cut
174:
175: sub SortStudents {
1.29 stredwic 176: my ($cache)=@_;
1.27 stredwic 177:
1.29 stredwic 178: my @students = split(':::',$cache->{'NamesOfStudents'});
1.27 stredwic 179: my @sorted1Students=();
1.29 stredwic 180: foreach (@students) {
181: if($cache->{'Status'} eq 'Any' ||
182: $cache->{$_.':Status'} eq $cache->{'Status'}) {
183: push(@sorted1Students, $_);
184: }
1.1 albertel 185: }
1.27 stredwic 186:
1.29 stredwic 187: my $sortBy = '';
188: if(defined($cache->{'sort'})) {
189: $sortBy = ':'.$cache->{'sort'};
1.27 stredwic 190: }
1.29 stredwic 191: my @order = sort { $cache->{$a.$sortBy} cmp $cache->{$b.$sortBy} ||
192: $cache->{$a.':fullname'} cmp $cache->{$b.':fullname'} }
193: @sorted1Students;
1.27 stredwic 194:
195: return \@order;
196: }
197:
198: sub PrepareData {
199: my ($c, $cacheDB)=@_;
200:
201: # Test for access to the cache data
202: my $courseID=$ENV{'request.course.id'};
203: my $isRecalculate=0;
1.29 stredwic 204: if(defined($ENV{'form.Recalculate'})) {
1.27 stredwic 205: $isRecalculate=1;
206: }
207:
1.29 stredwic 208: my $isCached = &Apache::loncoursedata::TestCacheData($cacheDB,
209: $isRecalculate);
1.27 stredwic 210: if($isCached < 0) {
211: return "Unable to tie hash to db file.";
212: }
213:
214: # Download class list information if not using cached data
215: my %cache;
1.29 stredwic 216: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_WRCREAT,0640)) {
217: return "Unable to tie hash to db file.";
218: }
219:
1.27 stredwic 220: if(!$isCached) {
221: my $processTopResourceMapReturn=
222: &Apache::loncoursedata::ProcessTopResourceMap(\%cache, $c);
223: if($processTopResourceMapReturn ne 'OK') {
224: untie(%cache);
225: return $processTopResourceMapReturn;
226: }
1.29 stredwic 227: }
1.27 stredwic 228:
1.29 stredwic 229: if($c->aborted()) {
230: untie(%cache);
231: return 'aborted';
232: }
1.27 stredwic 233:
1.29 stredwic 234: my $classlist=&Apache::loncoursedata::DownloadClasslist($courseID,
235: $cache{'ClasslistTimestamp'},
236: $c);
237: foreach (keys(%$classlist)) {
238: if(/^(con_lost|error|no_such_host)/i) {
1.27 stredwic 239: untie(%cache);
240: return "Error getting student data.";
241: }
1.29 stredwic 242: }
1.27 stredwic 243:
1.29 stredwic 244: if($c->aborted()) {
245: untie(%cache);
246: return 'aborted';
247: }
248:
249: # Active is a temporary solution, remember to change
250: Apache::loncoursedata::ProcessClasslist(\%cache,$classlist,$courseID,$c);
251: if($c->aborted()) {
252: untie(%cache);
253: return 'aborted';
254: }
1.27 stredwic 255:
1.29 stredwic 256: &ProcessFormData(\%cache);
257: my $students = &SortStudents(\%cache);
1.27 stredwic 258:
1.29 stredwic 259: if($cache{'download'} ne 'false') {
260: my $who = $cache{'download'};
261: my $courseData =
1.30 stredwic 262: &Apache::loncoursedata::DownloadCourseInformation(
1.29 stredwic 263: $who, $courseID,
264: $cache{$who.':lastDownloadTime'});
265: &Apache::loncoursedata::ProcessStudentData(\%cache, $courseData, $who);
266: $cache{'download'} = 'false';
267: } elsif($cache{'DownloadAll'} ne 'false') {
268: my @allStudents;
269: if($cache{'DownloadAll'} eq 'sorted') {
270: @allStudents = @$students;
271: } else {
272: @allStudents = split(':::', $cache{'NamesOfStudents'});
273: }
274: foreach (@allStudents) {
275: my $courseData =
1.30 stredwic 276: &Apache::loncoursedata::DownloadCourseInformation(
1.29 stredwic 277: $_, $courseID,
278: $cache{$_.':lastDownloadTime'});
279: &Apache::loncoursedata::ProcessStudentData(\%cache, $courseData,
280: $_);
281: if($c->aborted()) {
282: untie(%cache);
283: return 'aborted';
284: }
1.27 stredwic 285: }
1.29 stredwic 286: $cache{'DownloadAll'} = 'false';
287: }
1.27 stredwic 288:
1.29 stredwic 289: if($c->aborted()) {
1.27 stredwic 290: untie(%cache);
1.29 stredwic 291: return 'aborted';
292: }
293:
294: if($c->aborted()) {
295: untie(%cache);
296: return 'aborted';
1.27 stredwic 297: }
298:
1.29 stredwic 299: untie(%cache);
300:
301: return ('OK', $students);
1.27 stredwic 302: }
303:
1.31 ! minaeibi 304:
1.27 stredwic 305: # Create progress
306: sub Create_PrgWin {
1.31 ! minaeibi 307: my ($r)=@_;
1.27 stredwic 308: $r->print(<<ENDPOP);
309: <script>
310: popwin=open('','popwin','width=400,height=100');
311: popwin.document.writeln('<html><body bgcolor="#88DDFF">'+
312: '<title>LON-CAPA Statistics</title>'+
313: '<h4>Computation Progress</h4>'+
314: '<form name=popremain>'+
315: '<input type=text size=35 name=remaining value=Starting></form>'+
316: '</body></html>');
317: popwin.document.close();
318: </script>
319: ENDPOP
320:
321: $r->rflush();
1.1 albertel 322: }
323:
1.27 stredwic 324: # update progress
325: sub Update_PrgWin {
1.31 ! minaeibi 326: my ($totalStudents,$index,$name,$r)=@_;
1.27 stredwic 327: $r->print('<script>popwin.document.popremain.remaining.value="'.
328: 'Computing '.$index.'/'.$totalStudents.': '.
329: $name.'";</script>');
330: $r->rflush();
331: }
1.1 albertel 332:
1.27 stredwic 333: # close Progress Line
334: sub Close_PrgWin {
1.31 ! minaeibi 335: my ($r)=@_;
1.27 stredwic 336: $r->print('<script>popwin.close()</script>');
337: $r->rflush();
1.25 minaeibi 338: }
339:
340: # For loading the colored table for display or un-colored for print
341: sub setbgcolor {
342: my $PrintTable=shift;
1.31 ! minaeibi 343: my %color;
1.25 minaeibi 344: if ($PrintTable){
345: $color{"gb"}="#FFFFFF";
346: $color{"red"}="#FFFFFF";
347: $color{"yellow"}="#FFFFFF";
348: $color{"green"}="#FFFFFF";
349: $color{"purple"}="#FFFFFF";
350: } else {
351: $color{"gb"}="#DDFFFF";
352: $color{"red"}="#FFDDDD";
353: $color{"yellow"}="#EEFFCC";
354: $color{"green"}="#DDFFDD";
355: $color{"purple"}="#FFDDFF";
356: }
1.27 stredwic 357:
1.31 ! minaeibi 358: return \%color;
1.1 albertel 359: }
360:
1.29 stredwic 361: sub BuildClasslist {
362: my ($cacheDB,$students,$studentInformation,$headings,$spacePadding)=@_;
363:
364: my %cache;
365: unless(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
366: return '<html><body>Unable to tie database.</body></html>';
1.1 albertel 367: }
368:
1.29 stredwic 369: my $Str='';
370: $Str .= '<table border="0"><tr><td bgcolor="#777777">'."\n";
371: $Str .= '<table border="0" cellpadding="3"><tr bgcolor="#e6ffff">'."\n";
372:
373: my $displayString = '<td align="left"><a href="/adm/statistics?';
374: $displayString .= 'sort=LINKDATA">DISPLAYDATA </a></td>'."\n";
375: $Str .= &Apache::lonhtmlcommon::CreateStudentInformationHeadings(\%cache,
376: $studentInformation,
377: $headings,
378: $displayString);
379: $Str .= '<td align="left">';
380: $Str .= '<a href="/adm/statistics?sort=lastDownloadTime">';
1.30 stredwic 381: $Str .= 'Last Updated </a></td>'."\n";
1.29 stredwic 382: $Str .= '</tr>'."\n";
383: my $alternate=0;
384: foreach (@$students) {
385: my ($username, $domain) = split(':', $_);
386: if($alternate) {
387: $Str .= '<tr bgcolor="#ffffe6"><td>';
388: } else {
389: $Str .= '<tr bgcolor="#ffffc6"><td>';
390: }
391: $alternate = ($alternate + 1) % 2;
392: foreach my $data (@$studentInformation) {
393: if($data eq 'fullname') {
394: $Str .= '<a href="/adm/statistics?reportSelected=';
1.30 stredwic 395: $Str .= &Apache::lonnet::escape('Student Assessment');
396: $Str .= '&StudentAssessmentStudent=';
397: $Str .= &Apache::lonnet::escape($cache{$_.':'.$data}).'">';
398: #$Str .= 'Student Assessment'.'">';
1.29 stredwic 399: }
400:
401: $Str .= $cache{$_.':'.$data}.' ';
402:
403: if($data eq 'fullname') {
404: $Str .= '</a>';
405: }
406:
407: $Str .= '</td><td>';
408: }
409:
410: $Str .= '<a href="/adm/statistics?download='.$_.'">';
411: my $downloadTime = $cache{$_.':lastDownloadTime'};
412: if($downloadTime ne 'Not downloaded') {
413: $downloadTime = localtime($downloadTime);
414: }
415: $Str .= $downloadTime;
416:
417: $Str .= ' </a></td></tr>'."\n";
1.1 albertel 418: }
1.29 stredwic 419:
420: $Str .= '</table></td></tr></table>'."\n";
421:
1.27 stredwic 422: untie(%cache);
1.1 albertel 423:
1.29 stredwic 424: return $Str;
1.1 albertel 425: }
426:
1.29 stredwic 427: sub BuildStatistics {
428: my ($r)=@_;
429:
430: my $c = $r->connection;
431: my @studentInformation=('fullname','section','id','domain','username');
432: my @headings=('Full Name', 'Section', 'PID', 'Domain', 'User Name');
433: my $spacePadding = ' ';
434: my %reports = ('classlist' => 'Class list',
435: 'problem_statistics' => 'Problem Statistics',
436: 'student_assessment' => 'Student Assessment',
437: 'reportSelected' => 'Class list');
1.27 stredwic 438:
439: my %cache;
1.29 stredwic 440: my $courseID=$ENV{'request.course.id'};
441: my $cacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
442: "_$ENV{'user.domain'}_$courseID\_statistics.db";
443:
1.31 ! minaeibi 444: my %color=&setbgcolor(0);
1.29 stredwic 445: my ($returnValue, $students) = &PrepareData($c, $cacheDB);
446: if($returnValue ne 'OK') {
447: $r->print('<html><body>'.$returnValue."\n".'</body></html>');
448: return OK;
449: }
450:
451: my $GoToPage;
452: if(tie(%cache,'GDBM_File',$cacheDB,&GDBM_READER,0640)) {
453: $GoToPage = $cache{'reportSelected'};
454: $reports{'reportSelected'} = $cache{'reportSelected'};
455: # if(defined($cache{'reportKey'}) && $cache{'reportKey'} ne 'false') {
456: # $reports{$cache{'reportKey'}} = $cache{'reportSelected'};
457: # }
458:
459: if(defined($cache{'OptionResponses'})) {
460: $reports{'problem_analysis'} = 'Problem Analysis';
461: }
462:
463: $r->print(&Apache::lonhtmlcommon::Title('LON-CAPA Statistics'));
464: $r->print('<form name="Statistics" ');
465: $r->print('method="post" action="/adm/statistics">');
466: $r->print(&Apache::lonhtmlcommon::CreateStatisticsMainMenu(
467: $cache{'Status'},
468: \%reports));
469: untie(%cache);
470: } else {
1.27 stredwic 471: $r->print('<html><body>Unable to tie database.</body></html>');
1.29 stredwic 472: return OK;
473: }
474:
475: if($GoToPage eq 'Activity Log') {
1.30 stredwic 476: &Apache::lonproblemstatistics::Activity();
1.29 stredwic 477: } elsif($GoToPage eq 'Problem Statistics') {
1.30 stredwic 478: $r->print(
479: &Apache::lonproblemstatistics::BuildProblemStatisticsPage($cacheDB,
480: $students,
481: $courseID,
1.31 ! minaeibi 482: $c,$r,
! 483: \%color));
1.29 stredwic 484: } elsif($GoToPage eq 'Problem Analysis') {
1.30 stredwic 485: $r->print(
486: &Apache::lonproblemanalysis::BuildProblemAnalysisPage($cacheDB));
1.29 stredwic 487: } elsif($GoToPage eq 'Student Assessment') {
1.30 stredwic 488: $r->print(
489: &Apache::lonstudentassessment::BuildStudentAssessmentPage($cacheDB,
490: $students,
491: $courseID,
492: $c));
1.29 stredwic 493: } elsif($GoToPage eq 'Analyze') {
1.30 stredwic 494: $r->print(&Apache::lonproblemanalysis::BuildAnalyzePage($cacheDB,
495: $students,
496: $courseID));
1.29 stredwic 497: } elsif($GoToPage eq 'DoDiffGraph') {
1.31 ! minaeibi 498: &Apache::lonproblemstatistics::BuildDiffGraph($r);
1.29 stredwic 499: } elsif($GoToPage eq 'PercentWrongGraph') {
1.31 ! minaeibi 500: &Apache::lonproblemstatistics::BuildWrongGraph($r);
1.29 stredwic 501: } elsif($GoToPage eq 'Class list') {
502: $r->print(&BuildClasslist($cacheDB, $students, \@studentInformation,
503: \@headings, $spacePadding));
1.27 stredwic 504: }
505:
506: $r->print('</form>'."\n");
1.29 stredwic 507: $r->print("\n".'</body>'."\n".'</html>');
508: $r->rflush();
1.27 stredwic 509:
1.29 stredwic 510: return OK;
1.27 stredwic 511: }
1.1 albertel 512:
513: # ================================================================ Main Handler
514:
515: sub handler {
1.31 ! minaeibi 516: my $r=shift;
1.1 albertel 517:
1.27 stredwic 518: unless(&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
519: $ENV{'user.error.msg'}=
520: $r->uri.":vgr:0:0:Cannot view grades for complete course";
521: return HTTP_NOT_ACCEPTABLE;
522: }
523:
524: # Set document type for header only
525: if($r->header_only) {
526: if ($ENV{'browser.mathml'}) {
527: $r->content_type('text/xml');
528: } else {
529: $r->content_type('text/html');
530: }
531: &Apache::loncommon::no_cache($r);
532: $r->send_http_header;
533: return OK;
534: }
535:
536: unless($ENV{'request.course.fn'}) {
1.1 albertel 537: my $requrl=$r->uri;
1.27 stredwic 538: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
539: return HTTP_NOT_ACCEPTABLE;
540: }
1.1 albertel 541:
1.27 stredwic 542: $r->content_type('text/html');
543: $r->send_http_header;
1.1 albertel 544:
1.29 stredwic 545: &BuildStatistics($r);
1.27 stredwic 546:
547: return OK;
1.1 albertel 548: }
549: 1;
550: __END__
1.31 ! minaeibi 551:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>