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