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