Annotation of loncom/interface/lonchart.pm, revision 1.32
1.1 www 1: # The LearningOnline Network with CAPA
1.25 minaeibi 2: # (Publication Handler
3: #
1.32 ! albertel 4: # $Id: lonchart.pm,v 1.31 2002/02/19 20:22:00 minaeibi Exp $
1.25 minaeibi 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: #
1.1 www 29: # Homework Performance Chart
30: #
31: # (Navigate Maps Handler
32: #
33: # (Page Handler
34: #
35: # (TeX Content Handler
1.27 minaeibi 36: # YEAR=2000
1.1 www 37: # 05/29/00,05/30 Gerd Kortemeyer)
38: # 08/30,08/31,09/06,09/14,09/15,09/16,09/19,09/20,09/21,09/23,
39: # 10/02,10/10,10/14,10/16,10/18,10/19,10/31,11/6,11/14,11/16 Gerd Kortemeyer)
1.27 minaeibi 40: # YEAR=2001
1.14 minaeibi 41: # 3/1/1,6/1,17/1,29/1,30/1,31/1 Gerd Kortemeyer)
1.5 minaeibi 42: # 7/10/01 Behrouz Minaei
1.6 www 43: # 9/8 Gerd Kortemeyer
1.27 minaeibi 44: # 10/1, 10/19, 11/17, 11/22, 11/24, 11/28 12/18 Behrouz Minaei
45: # YEAR=2002
1.30 minaeibi 46: # 2/1, 2/6, 2/19 Behrouz Minaei
1.26 minaeibi 47: #
48: ###
1.1 www 49:
50: package Apache::lonchart;
51:
52: use strict;
53: use Apache::Constants qw(:common :http);
54: use Apache::lonnet();
1.28 albertel 55: use Apache::loncommon();
1.1 www 56: use HTML::TokeParser;
57: use GDBM_File;
58:
59: # -------------------------------------------------------------- Module Globals
60: my %hash;
1.30 minaeibi 61: my %CachData;
1.1 www 62: my @cols;
63: my @rowlabels;
64: my @students;
1.30 minaeibi 65: my @PreCol;
66: my $r;
1.1 www 67:
68: # ------------------------------------------------------------- Find out status
69:
1.5 minaeibi 70: sub ExtractStudentData {
71: my ($index,$coid)=@_;
72: my ($sname,$sdom) = split( /\:/, $students[$index] );
73: my $shome=&Apache::lonnet::homeserver( $sname,$sdom );
74: my $reply=&Apache::lonnet::reply('dump:'.$sdom.':'.$sname.':'.$coid,$shome );
75: my %result=();
76: my $ResId;
77: my $Code;
78: my $Tries;
79: my $Wrongs;
1.7 minaeibi 80: my %TempHash;
1.5 minaeibi 81: my $Version;
1.10 minaeibi 82: my $ProbNo;
1.26 minaeibi 83: my $ProbSolved;
84: my $ProbTotal;
1.22 minaeibi 85: my $LatestVersion;
1.5 minaeibi 86: my $Str=substr($students[$index].
87: ' ',0,14).' ! '.
88: substr($rowlabels[$index].
89: ' ',0,45).' ! ';
90: unless ($reply=~/^error\:/) {
1.31 minaeibi 91: foreach (split(/\&/,$reply)) {
1.5 minaeibi 92: my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));
93: $result{$name}=$value;
1.31 minaeibi 94: }
1.10 minaeibi 95: $ProbNo = 0;
1.26 minaeibi 96: $ProbTotal = 0;
97: $ProbSolved = 0;
1.10 minaeibi 98: my $IterationNo = 0;
1.5 minaeibi 99: foreach $ResId (@cols) {
1.10 minaeibi 100: if ($IterationNo == 0) {$IterationNo++; next;}
101: if (!$ResId) {
102: my $PrNo = sprintf( "%3d", $ProbNo );
103: $Str .= ' '.'<font color="#007700">'.$PrNo.'</font> ';
1.26 minaeibi 104: $ProbSolved += $ProbNo;
1.10 minaeibi 105: $ProbNo=0;
106: next;
107: }
1.5 minaeibi 108: $ResId=~/(\d+)\.(\d+)/;
1.11 minaeibi 109: my $meta=$hash{'src_'.$ResId};
110: my $PartNo = 0;
111: undef %TempHash;
1.31 minaeibi 112: foreach (split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) {
1.11 minaeibi 113: if ($_=~/^stores\_(\d+)\_tries$/) {
114: my $Part=&Apache::lonnet::metadata($meta,$_.'.part');
115: if ( $TempHash{"$Part"} eq '' ) {
116: $TempHash{"$Part"} = $Part;
117: $TempHash{$PartNo}=$Part;
118: $TempHash{"$Part.Code"} = ' ';
119: $PartNo++;
120: }
121: }
1.31 minaeibi 122: }
1.11 minaeibi 123:
1.5 minaeibi 124: my $Prob = &Apache::lonnet::declutter( $hash{'map_id_'.$1} ).
125: '___'.$2.'___'.
126: &Apache::lonnet::declutter( $hash{'src_'.$ResId} );
127: $Code=' ';
128: $Tries = 0;
1.7 minaeibi 129: $LatestVersion = $result{"version:$Prob"};
1.14 minaeibi 130:
1.7 minaeibi 131: if ( $LatestVersion ) {
132: for ( my $Version=1; $Version<=$LatestVersion; $Version++ ) {
133: my $vkeys = $result{"$Version:keys:$Prob"};
134: my @keys = split(/\:/,$vkeys);
1.14 minaeibi 135:
1.7 minaeibi 136: foreach my $Key (@keys) {
137: if (($Key=~/\.(\w+)\.solved$/) && ($Key!~/^\d+\:/)) {
138: my $Part = $1;
139: $Tries = $result{"$Version:$Prob:resource.$Part.tries"};
1.19 minaeibi 140: $TempHash{"$Part.Tries"}=($Tries) ? $Tries : 0;
1.16 minaeibi 141: my $Val = $result{"$Version:$Prob:resource.$Part.solved"};
1.19 minaeibi 142: if ($Val eq 'correct_by_student'){$Code='*';}
1.7 minaeibi 143: elsif ($Val eq 'correct_by_override'){$Code = '+';}
144: elsif ($Val eq 'incorrect_attempted'){$Code = '.';}
145: elsif ($Val eq 'incorrect_by_override'){$Code = '-';}
146: elsif ($Val eq 'excused'){$Code = 'x';}
1.23 albertel 147: elsif ($Val eq 'ungraded_attempted'){$Code = '#';}
1.13 minaeibi 148: else {$Code = ' ';}
1.7 minaeibi 149: $TempHash{"$Part.Code"} = $Code;
150: }
1.5 minaeibi 151: }
152: }
1.7 minaeibi 153: for ( my $n = 0; $n < $PartNo; $n++ ) {
154: my $part = $TempHash{$n};
1.25 minaeibi 155: my $Code = $TempHash{"$part.Code"};
156: if ( $Code eq '*') {
1.10 minaeibi 157: $ProbNo++;
1.19 minaeibi 158: if (($TempHash{"$part.Tries"}<10) ||
1.20 minaeibi 159: ($TempHash{"$part.Tries"} eq '')) {
1.19 minaeibi 160: $TempHash{"$part.Code"}=$TempHash{"$part.Tries"};
1.10 minaeibi 161: }
1.7 minaeibi 162: }
1.25 minaeibi 163: elsif ( $Code eq '+' ) {$ProbNo++;}
1.19 minaeibi 164: $Str .= $TempHash{"$part.Code"};
1.26 minaeibi 165: if ( $Code ne 'x' ) {$ProbTotal++;}
1.7 minaeibi 166: }
1.5 minaeibi 167: }
1.26 minaeibi 168: else {
169: for(my $n=0; $n<$PartNo; $n++) {
170: $Str.=' ';
171: $ProbTotal++;
172: }
173: }
1.5 minaeibi 174: }
1.1 www 175: }
1.26 minaeibi 176: my $PrTot = sprintf( "%5d", $ProbTotal );
177: my $PrSvd = sprintf( "%5d", $ProbSolved );
178: $Str .= ' '.'<font color="#000088">'.$PrSvd.' /'.$PrTot.'</font> ';
1.11 minaeibi 179:
1.10 minaeibi 180: return $Str ;
1.1 www 181: }
182:
1.5 minaeibi 183:
1.1 www 184: # ------------------------------------------------------------ Build page table
185:
186: sub tracetable {
187: my ($rid,$beenhere)=@_;
188: unless ($beenhere=~/\&$rid\&/) {
189: $beenhere.=$rid.'&';
1.7 minaeibi 190: # new ... updating the map according to sequence and page
1.1 www 191: if (defined($hash{'is_map_'.$rid})) {
1.7 minaeibi 192: my $cmap=$hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}};
193: if ( $cmap eq 'sequence' || $cmap eq 'page' ) {
1.1 www 194: $cols[$#cols+1]=0;
195: }
196: if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
197: (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
198: my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
199:
200: &tracetable($hash{'map_start_'.$hash{'src_'.$rid}},
201: '&'.$frid.'&');
202:
203: if ($hash{'src_'.$frid}) {
204: if ($hash{'src_'.$frid}=~
205: /\.(problem|exam|quiz|assess|survey|form)$/) {
206: $cols[$#cols+1]=$frid;
207: }
208: }
209:
210: }
211: } else {
212: if ($hash{'src_'.$rid}) {
213: if ($hash{'src_'.$rid}=~
214: /\.(problem|exam|quiz|assess|survey|form)$/) {
215: $cols[$#cols+1]=$rid;
216: }
217: }
218: }
219: if (defined($hash{'to_'.$rid})) {
1.31 minaeibi 220: foreach (split(/\,/,$hash{'to_'.$rid})){
1.1 www 221: &tracetable($hash{'goesto_'.$_},$beenhere);
1.31 minaeibi 222: }
1.1 www 223: }
224: }
225: }
226:
227:
1.30 minaeibi 228: sub BuildChart {
229: # ----------------------- Get first and last resource, see if there is anything
230: my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
231: my $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
232: if (($firstres) && ($lastres)) {
233: # ----------------------------------------------------------------- Render page
234: my $cid=$ENV{'request.course.id'};
235: my $chome=$ENV{'course.'.$cid.'.home'};
236: my ($cdom,$cnum)=split(/\_/,$cid);
237: # ---------------------------------------------- Read class list and row labels
238: my $classlst=&Apache::lonnet::reply
239: ('dump:'.$cdom.':'.$cnum.':classlist',$chome);
240: my $now=time;
241: unless ($classlst=~/^error\:/) {
1.31 minaeibi 242: foreach my $KeyPoint(sort split(/\&/,$classlst)) {
243: my ($name,$value)=split(/\=/,$KeyPoint);
1.30 minaeibi 244: my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value));
245: my $active=1;
246: if (($end) && ($now>$end)) { $active=0; }
247: if ($active) {
248: my $thisindex=$#students+1;
249: $name=&Apache::lonnet::unescape($name);
250: $students[$thisindex]=$name;
251: my ($sname,$sdom)=split(/\:/,$name);
252: $PreCol[$thisindex]=$sname.':';
253: my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
254: if ($ssec==-1) {
255: $rowlabels[$thisindex]=
256: 'Data not available: '.$name;
257: } else {
258: my %reply=&Apache::lonnet::idrget($sdom,$sname);
259: my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.
260: ':environment:lastname&generation&firstname&middlename',
261: &Apache::lonnet::homeserver($sname,$sdom));
262: #$ssec=(int($ssec)) ? int($ssec) : $ssec;
1.31 minaeibi 263: my $sec=sprintf('%3s',$ssec);
264: $rowlabels[$thisindex]=$sec.' '.$reply{$sname}.' ';
265: $PreCol[$thisindex] .= $reply.':'.$sec;
1.30 minaeibi 266: my $i=0;
1.31 minaeibi 267: foreach (split(/\&/,$reply)) {
1.30 minaeibi 268: $i++;
269: if ( $_ ne '') {
270: $rowlabels[$thisindex].=&Apache::lonnet::unescape($_).' ';
271: }
272: if ($i == 2) {
273: chop($rowlabels[$thisindex]);
274: $rowlabels[$thisindex].=', ';
275: }
1.31 minaeibi 276: }
1.30 minaeibi 277: }
278: }
1.31 minaeibi 279: }
1.24 minaeibi 280:
1.30 minaeibi 281: } else {
282: $r->print('<h1>Could not access course data</h1>');
283: }
284:
285: my $allstudents=$#students+1;
286: $r->print('<h3>'.$allstudents.' students</h3>');
287: &CreateForm();
288: $r->rflush();
1.24 minaeibi 289:
1.30 minaeibi 290: # --------------- Find all assessments and put them into some linear-like order
291: &tracetable($firstres,'&'.$lastres.'&');
292: # ----------------------------------------------------------------- Start table
1.1 www 293:
1.30 minaeibi 294: $r->print('<p><pre>');
295: my $index;
296: for ($index=0;$index<=$#students;$index++) {
297: my $Str=&ExtractStudentData($index,$cid);
298: $r->print($Str.'<br>');
299: $r->rflush();
300: $CachData{$PreCol[$index]}=$Str;
301: }
302: $r->print('</pre>');
303: } else {
304: $r->print('<h3>Undefined course sequence</h3>');
305: }
306: }
1.1 www 307:
1.30 minaeibi 308: sub CreateForm {
309: my $Ptr = '<form name=stat method=post action="/adm/chart" >'."\n";
310: $Ptr .= '<b> Sort by: </b>'."\n";
311: $Ptr .= ' ';
312: $Ptr .= '<input type=submit name=sort value="Email Name" />'."\n";
313: $Ptr .= ' ';
314: $Ptr .= '<input type=submit name=sort value="Last Name" />'."\n";
315: $Ptr .= ' ';
316: $Ptr .= '<input type=submit name=sort value="Section"/>'."\n";
317: $Ptr .= '<br>';
318: $Ptr .= '<input type=submit name=sort value="Recalculate Chart"/>'."\n";
319: $Ptr .= '</form>'."\n";
320: $r->print( $Ptr );
321: }
1.1 www 322:
1.30 minaeibi 323: sub CacheChart {
1.32 ! albertel 324: my %list = ();
1.30 minaeibi 325: my $count=0;
326:
327: my $Pos = $ENV{'form.sort'};
328: if ( $Pos eq 'Last Name' ) {$Pos=1;}
329: elsif ( $Pos eq 'Section' ) {$Pos=2;}
330: else {$Pos=0;}
331:
332: foreach my $key( keys %CachData) {
333: my @Temp=split(/\:/,$key);
334: my $Use = $Temp[$Pos];
1.32 ! albertel 335: $list{$Use.$key}=$key;
1.30 minaeibi 336: $count++;
337: }
1.1 www 338:
1.32 ! albertel 339: my @order = sort(keys(%list));
1.1 www 340:
1.30 minaeibi 341: $r->print('<h3>'.$count.' students</h3>');
342: &CreateForm();
343: $r->rflush();
344:
345: $r->print('<p><pre>');
346: for ( my $n; $n < $count; $n++) {
1.32 ! albertel 347: $r->print($CachData{$list{$order[$n]}}.'<br>');
1.30 minaeibi 348: }
349: $r->print('</pre>');
350: }
1.1 www 351:
1.30 minaeibi 352: sub Start {
353: undef %hash;
354: undef %CachData;
355: undef @students;
356: undef @cols;
357: undef @rowlabels;
358: undef @PreCol;
359:
360: $r->print('<html><head><title>'.
361: 'LON-CAPA Assessment Chart</title></head>');
362: $r->print('<body bgcolor="#FFFFFF">'.
363: '<script>window.focus();</script>'.
364: '<img align=right src=/adm/lonIcons/lonlogos.gif>'.
365: '<h1>Assessment Chart</h1>');
1.1 www 366: # ---------------------------------------------------------------- Course title
1.30 minaeibi 367: $r->print('<h1>'.$ENV{'course.'.$ENV{'request.course.id'}.
368: '.description'}.'</h1><h3>'.localtime().
369: "</h3><p><pre>1..9: correct by student in 1..9 tries\n".
370: " *: correct by student in more than 9 tries\n".
371: " +: correct by override\n".
372: " -: incorrect by override\n".
373: " .: incorrect attempted\n".
374: " #: ungraded attempted\n".
375: " : not attempted\n".
376: " x: excused</pre><p>");
1.1 www 377: # ------------------------------- This is going to take a while, produce output
1.30 minaeibi 378: $r->rflush();
1.1 www 379:
1.30 minaeibi 380: my $cid=$ENV{'request.course.id'};
381: my $ChartDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
382: "_$ENV{'user.domain'}_$cid\_chart.db";
383:
384: if ((-e "$ChartDB") && ($ENV{'form.sort'} ne 'Recalculate Chart')) {
385: if (tie(%CachData,'GDBM_File',"$ChartDB",&GDBM_READER,0640)) {
386: &CacheChart();
387: }
388: else {
389: $r->print("Unable to tie hash to db file");
390: }
391: }
392: else {
393: if (tie(%CachData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
394: foreach (keys %CachData) {delete $CachData{$_};}
395: &BuildChart();
396: }
397: else {
398: $r->print("Unable to tie hash to db file");
399: }
1.1 www 400: }
1.30 minaeibi 401: untie(%CachData);
402: }
1.1 www 403:
1.30 minaeibi 404: # ================================================================ Main Handler
1.1 www 405:
1.30 minaeibi 406: sub handler {
407: $r=shift;
408: if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
409: # ------------------------------------------- Set document type for header only
410: if ($r->header_only) {
411: if ($ENV{'browser.mathml'}) {
412: $r->content_type('text/xml');
413: } else {
414: $r->content_type('text/html');
415: }
416: &Apache::loncommon::no_cache($r);
417: $r->send_http_header;
418: return OK;
419: }
1.1 www 420:
1.30 minaeibi 421: my $requrl=$r->uri;
422: # ----------------------------------------------------------------- Tie db file
423: if ($ENV{'request.course.fn'}) {
424: my $fn=$ENV{'request.course.fn'};
425: if (-e "$fn.db") {
426: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
427: # ------------------------------------------------------------------- Hash tied
428: # ---------------------------------------------------------------- Send headers
429: $r->content_type('text/html');
430: $r->send_http_header;
431: &Start();
432: $r->print('</body></html>');
1.1 www 433: # ------------------------------------------------------------- End render page
1.30 minaeibi 434: } else {
435: $r->content_type('text/html');
436: $r->send_http_header;
437: $r->print('<html><body>Coursemap undefined.</body></html>');
438: }
1.1 www 439: # ------------------------------------------------------------------ Untie hash
1.30 minaeibi 440: unless (untie(%hash)) {
441: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
442: "Could not untie coursemap $fn (browse).</font>");
443: }
1.1 www 444:
445: # -------------------------------------------------------------------- All done
1.30 minaeibi 446: return OK;
1.1 www 447: # ----------------------------------------------- Errors, hash could no be tied
1.30 minaeibi 448: }
449: } else {
450: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
451: return HTTP_NOT_ACCEPTABLE;
452: }
453: } else {
454: $ENV{'user.error.msg'}=
1.1 www 455: $r->uri.":vgr:0:0:Cannot view grades for complete course";
1.30 minaeibi 456: return HTTP_NOT_ACCEPTABLE;
457: }
1.1 www 458: }
459: 1;
460: __END__
461:
462:
463:
464:
465:
466:
467:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>