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