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