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