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