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