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