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