Annotation of loncom/interface/lonchart.pm, revision 1.1
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
! 17:
! 18: package Apache::lonchart;
! 19:
! 20: use strict;
! 21: use Apache::Constants qw(:common :http);
! 22: use Apache::lonnet();
! 23: use HTML::TokeParser;
! 24: use GDBM_File;
! 25:
! 26: # -------------------------------------------------------------- Module Globals
! 27: my %hash;
! 28: my @cols;
! 29: my @rowlabels;
! 30: my @students;
! 31:
! 32: # ------------------------------------------------------------- Find out status
! 33:
! 34: sub astatus {
! 35: my $rid=shift;
! 36: my $code=' ';
! 37: $rid=~/(\d+)\.(\d+)/;
! 38: my $symb=&Apache::lonnet::declutter($hash{'map_id_'.$1}).'___'.$2.'___'.
! 39: &Apache::lonnet::declutter($hash{'src_'.$rid});
! 40: my $answer=&Apache::lonnet::reply(
! 41: "restore:$ENV{'user.domain'}:$ENV{'user.name'}:".
! 42: $ENV{'request.course.id'}.':'.
! 43: &Apache::lonnet::escape($symb),
! 44: "$ENV{'user.home'}");
! 45: my %returnhash=();
! 46: map {
! 47: my ($name,$value)=split(/\=/,$_);
! 48: $returnhash{&Apache::lonnet::unescape($name)}=
! 49: &Apache::lonnet::unescape($value);
! 50: } split(/\&/,$answer);
! 51: if ($returnhash{'version'}) {
! 52: my $version;
! 53: for ($version=1;$version<=$returnhash{'version'};$version++) {
! 54: map {
! 55: $returnhash{$_}=$returnhash{$version.':'.$_};
! 56: } split(/\:/,$returnhash{$version.':keys'});
! 57: }
! 58: my $totaltries=0;
! 59: map {
! 60: if (($_=~/\.(\w+)\.solved$/) && ($_!~/^\d+\:/)) {
! 61: my $part=$1;
! 62: if ($returnhash{$_} eq 'correct_by_student') {
! 63: unless (($code eq '.') || ($code eq '-')) { $code='*'; }
! 64: $totaltries+=$returnhash{'resource.'.$part.'.tries'};
! 65: } elsif ($returnhash{$_} eq 'correct_by_override') {
! 66: unless (($code eq '.') || ($code eq '-')) { $code='+'; }
! 67: } elsif ($returnhash{$_} eq 'incorrect_attempted') {
! 68: $code='.';
! 69: } elsif ($returnhash{$_} eq 'incorrect_by_override') {
! 70: $code='-';
! 71: } elsif ($returnhash{$_} eq 'excused') {
! 72: unless (($code eq '.') || ($code eq '-')) { $code='x'; }
! 73: }
! 74: }
! 75: } keys %returnhash;
! 76: if (($code eq '*') && ($totaltries<10)) { $code="$totaltries"; }
! 77: }
! 78: return $code;
! 79: }
! 80:
! 81: # ------------------------------------------------------------ Build page table
! 82:
! 83: sub tracetable {
! 84: my ($rid,$beenhere)=@_;
! 85: unless ($beenhere=~/\&$rid\&/) {
! 86: $beenhere.=$rid.'&';
! 87: if (defined($hash{'is_map_'.$rid})) {
! 88: if ($hash{'map_type_'.$hash{'map_pc_'.$hash{'src_'.$rid}}}
! 89: eq 'sequence') {
! 90: $cols[$#cols+1]=0;
! 91: }
! 92: if ((defined($hash{'map_start_'.$hash{'src_'.$rid}})) &&
! 93: (defined($hash{'map_finish_'.$hash{'src_'.$rid}}))) {
! 94: my $frid=$hash{'map_finish_'.$hash{'src_'.$rid}};
! 95:
! 96: &tracetable($hash{'map_start_'.$hash{'src_'.$rid}},
! 97: '&'.$frid.'&');
! 98:
! 99: if ($hash{'src_'.$frid}) {
! 100: if ($hash{'src_'.$frid}=~
! 101: /\.(problem|exam|quiz|assess|survey|form)$/) {
! 102: $cols[$#cols+1]=$frid;
! 103: }
! 104: }
! 105:
! 106: }
! 107: } else {
! 108: if ($hash{'src_'.$rid}) {
! 109: if ($hash{'src_'.$rid}=~
! 110: /\.(problem|exam|quiz|assess|survey|form)$/) {
! 111: $cols[$#cols+1]=$rid;
! 112: }
! 113: }
! 114: }
! 115: if (defined($hash{'to_'.$rid})) {
! 116: map {
! 117: &tracetable($hash{'goesto_'.$_},$beenhere);
! 118: } split(/\,/,$hash{'to_'.$rid});
! 119: }
! 120: }
! 121: }
! 122:
! 123: # ================================================================ Main Handler
! 124:
! 125: sub handler {
! 126: my $r=shift;
! 127:
! 128: if (&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
! 129: # ------------------------------------------- Set document type for header only
! 130:
! 131: if ($r->header_only) {
! 132: if ($ENV{'browser.mathml'}) {
! 133: $r->content_type('text/xml');
! 134: } else {
! 135: $r->content_type('text/html');
! 136: }
! 137: $r->send_http_header;
! 138: return OK;
! 139: }
! 140:
! 141: my $requrl=$r->uri;
! 142: # ----------------------------------------------------------------- Tie db file
! 143: if ($ENV{'request.course.fn'}) {
! 144: my $fn=$ENV{'request.course.fn'};
! 145: if (-e "$fn.db") {
! 146: if (tie(%hash,'GDBM_File',"$fn.db",&GDBM_READER,0640)) {
! 147: # ------------------------------------------------------------------- Hash tied
! 148:
! 149:
! 150: # ------------------------------------------------------------------ Build page
! 151:
! 152: # ---------------------------------------------------------------- Send headers
! 153:
! 154: $r->content_type('text/html');
! 155: $r->send_http_header;
! 156: $r->print(
! 157: '<html><head><title>LON-CAPA Assessment Chart</title></head>');
! 158:
! 159: $r->print('<body bgcolor="#FFFFFF">'.
! 160: '<script>window.focus();</script>'.
! 161: '<img align=right src=/adm/lonIcons/lonlogos.gif>'.
! 162: '<h1>Assessment Chart</h1>');
! 163:
! 164: # ---------------------------------------------------------------- Course title
! 165:
! 166: $r->print('<h1>'.
! 167: $ENV{'course.'.$ENV{'request.course.id'}.'.description'}.'</h1>');
! 168:
! 169:
! 170: # ------------------------------- This is going to take a while, produce output
! 171:
! 172: $r->rflush();
! 173:
! 174: # ----------------------- Get first and last resource, see if there is anything
! 175:
! 176:
! 177: my $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}};
! 178: my $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}};
! 179: if (($firstres) && ($lastres)) {
! 180: # ----------------------------------------------------------------- Render page
! 181:
! 182: my $cid=$ENV{'request.course.id'};
! 183: my $chome=$ENV{'course.'.$cid.'.home'};
! 184: my ($cdom,$cnum)=split(/\_/,$cid);
! 185:
! 186: # ---------------------------------------------- Read class list and row labels
! 187:
! 188: undef @rowlabels;
! 189: undef @students;
! 190:
! 191: my $classlst=&Apache::lonnet::reply
! 192: ('dump:'.$cdom.':'.$cnum.':classlist',$chome);
! 193: my $now=time;
! 194: unless ($classlst=~/^error\:/) {
! 195: map {
! 196: my ($name,$value)=split(/\=/,$_);
! 197: my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value));
! 198: my $active=1;
! 199: if (($end) && ($now>$end)) { $active=0; }
! 200: if ($active) {
! 201: my $thisindex=$#students+1;
! 202: $name=&Apache::lonnet::unescape($name);
! 203: $students[$thisindex]=$name;
! 204: my ($sname,$sdom)=split(/\:/,$name);
! 205: my $ssec=&Apache::lonnet::usection($sdom,$sname,$cid);
! 206: if ($ssec==-1) {
! 207: $rowlabels[$thisindex]=
! 208: 'Data not available: '.$name;
! 209: } else {
! 210: my %reply=&Apache::lonnet::idrget($sdom,$sname);
! 211: my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname.
! 212: ':environment:firstname&middlename&lastname&generation',
! 213: &Apache::lonnet::homeserver($sname,$sdom));
! 214: $rowlabels[$thisindex]=
! 215: $ssec.' '.$reply{$sname}.' ';
! 216: map {
! 217: $rowlabels[$thisindex].=&Apache::lonnet::unescape($_).' ';
! 218: } split(/\&/,$reply);
! 219: }
! 220: }
! 221: } sort split(/\&/,$classlst);
! 222:
! 223: } else {
! 224: $r->print('<h1>Could not access course data</h1>');
! 225: }
! 226:
! 227: my $allstudents=$#students+1;
! 228: $r->print('<h3>'.$allstudents.' students</h3>');
! 229: $r->rflush();
! 230:
! 231: # --------------- Find all assessments and put them into some linear-like order
! 232:
! 233: &tracetable($firstres,'&'.$lastres.'&');
! 234:
! 235: # ----------------------------------------------------------------- Start table
! 236:
! 237: $r->print('<p><pre>');
! 238: my $index;
! 239: for ($index=0;$index<=$#students;$index++) {
! 240: $r->print(
! 241: substr($students[$index].
! 242: ' ',0,14).' ! '.
! 243: substr($rowlabels[$index].
! 244: ' ',0,45).' ! ');
! 245: map {
! 246: if ($_) {
! 247: $r->print(&astatus($_,$students[$index]));
! 248: } else {
! 249: $r->print(' ! ');
! 250: }
! 251: } @cols;
! 252: $r->print("\n");
! 253: $r->rflush();
! 254: }
! 255: $r->print('</pre>');
! 256:
! 257: } else {
! 258: $r->print('<h3>Undefined course sequence</h3>');
! 259: }
! 260:
! 261: $r->print('</body></html>');
! 262:
! 263: # ------------------------------------------------------------- End render page
! 264: } else {
! 265: $r->content_type('text/html');
! 266: $r->send_http_header;
! 267: $r->print('<html><body>Coursemap undefined.</body></html>');
! 268: }
! 269: # ------------------------------------------------------------------ Untie hash
! 270: unless (untie(%hash)) {
! 271: &Apache::lonnet::logthis("<font color=blue>WARNING: ".
! 272: "Could not untie coursemap $fn (browse).</font>");
! 273: }
! 274:
! 275: # -------------------------------------------------------------------- All done
! 276: return OK;
! 277: # ----------------------------------------------- Errors, hash could no be tied
! 278: }
! 279: } else {
! 280: $ENV{'user.error.msg'}="$requrl:bre:0:0:Course not initialized";
! 281: return HTTP_NOT_ACCEPTABLE;
! 282: }
! 283: } else {
! 284: $ENV{'user.error.msg'}=
! 285: $r->uri.":vgr:0:0:Cannot view grades for complete course";
! 286: return HTTP_NOT_ACCEPTABLE;
! 287:
! 288: }
! 289: }
! 290: 1;
! 291: __END__
! 292:
! 293:
! 294:
! 295:
! 296:
! 297:
! 298:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>