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