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