Annotation of loncom/interface/lonchart.pm, revision 1.30
1.1 www 1: # The LearningOnline Network with CAPA
1.25 minaeibi 2: # (Publication Handler
3: #
1.30 ! minaeibi 4: # $Id: lonchart.pm,v 1.29 2002/02/06 16:59:50 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\:/) {
91: map {
92: my ($name,$value)=split(/\=/,&Apache::lonnet::unescape($_));
93: $result{$name}=$value;
94: } split(/\&/,$reply);
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;
112: map {
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: }
122: } split(/\,/,&Apache::lonnet::metadata($meta,'keys'));
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})) {
220: map {
221: &tracetable($hash{'goesto_'.$_},$beenhere);
222: } split(/\,/,$hash{'to_'.$rid});
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\:/) {
! 242: map {
! 243: my ($name,$value)=split(/\=/,$_);
! 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;
! 263: $rowlabels[$thisindex]=
! 264: sprintf('%3s',$ssec).' '.$reply{$sname}.' ';
! 265: $PreCol[$thisindex] .= $reply.':'.$ssec;
! 266: my $i=0;
! 267: map {
! 268: $i++;
! 269: if ( $_ ne '') {
! 270: $rowlabels[$thisindex].=&Apache::lonnet::unescape($_).' ';
! 271: }
! 272: if ($i == 2) {
! 273: chop($rowlabels[$thisindex]);
! 274: $rowlabels[$thisindex].=', ';
! 275: }
! 276: } split(/\&/,$reply);
! 277: }
! 278: }
! 279: } sort split(/\&/,$classlst);
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 {
! 324: my @list = ();
! 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];
! 335: $list[$count]=$Use.$key.'*'.$CachData{$key};
! 336: $count++;
! 337: }
1.1 www 338:
1.30 ! minaeibi 339: @list = sort (@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++) {
! 347: my ($dummy, $Line) = split(/\*/,$list[$n]);
! 348: $r->print($Line.'<br>');
! 349: }
! 350: $r->print('</pre>');
! 351: }
1.1 www 352:
1.30 ! minaeibi 353: sub Start {
! 354: undef %hash;
! 355: undef %CachData;
! 356: undef @students;
! 357: undef @cols;
! 358: undef @rowlabels;
! 359: undef @PreCol;
! 360:
! 361: $r->print('<html><head><title>'.
! 362: 'LON-CAPA Assessment Chart</title></head>');
! 363: $r->print('<body bgcolor="#FFFFFF">'.
! 364: '<script>window.focus();</script>'.
! 365: '<img align=right src=/adm/lonIcons/lonlogos.gif>'.
! 366: '<h1>Assessment Chart</h1>');
1.1 www 367: # ---------------------------------------------------------------- Course title
1.30 ! minaeibi 368: $r->print('<h1>'.$ENV{'course.'.$ENV{'request.course.id'}.
! 369: '.description'}.'</h1><h3>'.localtime().
! 370: "</h3><p><pre>1..9: correct by student in 1..9 tries\n".
! 371: " *: correct by student in more than 9 tries\n".
! 372: " +: correct by override\n".
! 373: " -: incorrect by override\n".
! 374: " .: incorrect attempted\n".
! 375: " #: ungraded attempted\n".
! 376: " : not attempted\n".
! 377: " x: excused</pre><p>");
1.1 www 378: # ------------------------------- This is going to take a while, produce output
1.30 ! minaeibi 379: $r->rflush();
1.1 www 380:
1.30 ! minaeibi 381: my $cid=$ENV{'request.course.id'};
! 382: my $ChartDB = "/home/httpd/perl/tmp/$ENV{'user.name'}".
! 383: "_$ENV{'user.domain'}_$cid\_chart.db";
! 384:
! 385: if ((-e "$ChartDB") && ($ENV{'form.sort'} ne 'Recalculate Chart')) {
! 386: if (tie(%CachData,'GDBM_File',"$ChartDB",&GDBM_READER,0640)) {
! 387: &CacheChart();
! 388: }
! 389: else {
! 390: $r->print("Unable to tie hash to db file");
! 391: }
! 392: }
! 393: else {
! 394: if (tie(%CachData,'GDBM_File',$ChartDB,&GDBM_WRCREAT,0640)) {
! 395: foreach (keys %CachData) {delete $CachData{$_};}
! 396: &BuildChart();
! 397: }
! 398: else {
! 399: $r->print("Unable to tie hash to db file");
! 400: }
1.1 www 401: }
1.30 ! minaeibi 402: untie(%CachData);
! 403: }
1.1 www 404:
1.30 ! minaeibi 405: # ================================================================ Main Handler
1.1 www 406:
1.30 ! minaeibi 407: sub handler {
! 408: $r=shift;
! 409: if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
! 410: # ------------------------------------------- Set document type for header only
! 411: if ($r->header_only) {
! 412: if ($ENV{'browser.mathml'}) {
! 413: $r->content_type('text/xml');
! 414: } else {
! 415: $r->content_type('text/html');
! 416: }
! 417: &Apache::loncommon::no_cache($r);
! 418: $r->send_http_header;
! 419: return OK;
! 420: }
1.1 www 421:
1.30 ! minaeibi 422: my $requrl=$r->uri;
! 423: # ----------------------------------------------------------------- Tie db file
! 424: if ($ENV{'request.course.fn'}) {
! 425: my $fn=$ENV{'request.course.fn'};
! 426: if (-e "$fn.db") {
! 427: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
! 428: # ------------------------------------------------------------------- Hash tied
! 429: # ---------------------------------------------------------------- Send headers
! 430: $r->content_type('text/html');
! 431: $r->send_http_header;
! 432: &Start();
! 433: $r->print('</body></html>');
1.1 www 434: # ------------------------------------------------------------- End render page
1.30 ! minaeibi 435: } else {
! 436: $r->content_type('text/html');
! 437: $r->send_http_header;
! 438: $r->print('<html><body>Coursemap undefined.</body></html>');
! 439: }
1.1 www 440: # ------------------------------------------------------------------ Untie hash
1.30 ! minaeibi 441: unless (untie(%hash)) {
! 442: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
! 443: "Could not untie coursemap $fn (browse).</font>");
! 444: }
1.1 www 445:
446: # -------------------------------------------------------------------- All done
1.30 ! minaeibi 447: return OK;
1.1 www 448: # ----------------------------------------------- Errors, hash could no be tied
1.30 ! minaeibi 449: }
! 450: } else {
! 451: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
! 452: return HTTP_NOT_ACCEPTABLE;
! 453: }
! 454: } else {
! 455: $ENV{'user.error.msg'}=
1.1 www 456: $r->uri.":vgr:0:0:Cannot view grades for complete course";
1.30 ! minaeibi 457: return HTTP_NOT_ACCEPTABLE;
! 458: }
1.1 www 459: }
460: 1;
461: __END__
462:
463:
464:
465:
466:
467:
468:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>