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