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