--- loncom/interface/lonstatistics.pm 2002/05/29 17:58:45 1.22 +++ loncom/interface/lonstatistics.pm 2002/05/31 16:02:11 1.26 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonstatistics.pm,v 1.22 2002/05/29 17:58:45 stredwic Exp $ +# $Id: lonstatistics.pm,v 1.26 2002/05/31 16:02:11 minaeibi Exp $ # # Copyright Michigan State University Board of Trustees # @@ -78,6 +78,7 @@ my $lastres; my $DiscFlag; my $HWN; my $P_Order; +my %color; my %foil_to_concept; my @Concepts; my %ConceptData; @@ -87,46 +88,49 @@ my %Header = (0,"Homework Sets Order",1, my %Answer = (); -sub unescape { - my $str=shift; - $str =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; - return $str; -} - sub Activity { - my $file="/home/minaeibi/minaei"; - my $userid='billskat'; + my $file="/home/minaeibi/activity.log"; + my $userid='adamsde1'; $r->print("
Using $file"); $r->rflush(); open(FILEID, "<$file"); my $line; my @allaccess; + my $Count=0; while ($line=) { my ($time,$machine,$what)=split(':',$line); - #$r->print("time=$time machine=$machine:-> $what\n"); - #$r->rflush(); - $what=&unescape($what); + $what=&Apache::lonnet::unescape($what); my @accesses=split('&',$what); foreach my $access (@accesses) { my ($date,$resource,$who,$domain,$post,@posts)=split(':',$access); if ($who ne $userid) { next; } - #if (!$resource) { next; } - push (@allaccess,unescape($access)); + if (!$resource) { next; } + my $res=&Apache::lonnet::unescape($resource); + if (($res =~ /\.(problem|htm|html)/)) { + $Count++; + $r->print("
$Count) ".localtime($date).": $who --> $res"); +# if ($post) { +# $Count++; +# $r->print("
$Count) Sent data ".join(':', +# &Apache::lonnet::unescape(@posts)).''); +# } + $r->rflush(); + } + ## push (@allaccess,unescape($access)); #print $machine; } } - @allaccess=sort(@allaccess); - my $Count=0; - foreach my $access (@allaccess) { - my ($date,$resource,$who,$domain,$post,@posts)=split(':',$access); - $Count++; -# $r->print("$Count ".localtime($date)." $who $resource\n"); - $r->print("
$Count) $date: $who --> $resource"); - $r->rflush(); - if ($post) { - $r->print("
Sent data ".join(':',unescape(@posts)).''); - } - } +# @allaccess=sort(@allaccess); +# $Count=0; +# foreach my $access (@allaccess) { +# my ($date,$resource,$who,$domain,$post,@posts)=split(':',$access); +# $Count++; +# $r->print("
$Count) $date: $who --> $resource"); +# $r->rflush(); +# if ($post) { +# $r->print("
Sent data ".join(':',unescape(@posts)).''); +# } +# } } @@ -265,9 +269,9 @@ sub DrawTable { for (my $n=0; $n<=$#Concepts; $n++ ) { $Str .= "\n"."". "\n"."".($n+1)."". - "\n"." ".$Concepts[$n]." ". - "\n"." ".$data1[$n]." ". - "\n"." ".$data2[$n]." ". + "\n".' '.$Concepts[$n]." ". + "\n".' '.$data1[$n]." ". + "\n".' '.$data2[$n]." ". "\n".""; } $Str.='From:['.localtime($ConceptData{'Int.'.$k}). @@ -309,7 +313,6 @@ sub DrawGraph { $Max = int($Max); } else { $Max = 1; } - my $Titr=($ConceptData{'Interval'}>1) ? $Src.'_interval_'.($k+1) : $Src; # $GData=$Titr.'&Concepts'.'&'.'Answers'.'&'.$Max.'&'.$P_No.'&'.$data1.'&'.$data2; $GData="$Titr&Concepts&Answers&$Max&$P_No&". @@ -351,8 +354,8 @@ sub AnalyzeProblem { '" target="_blank">'.$hash{'title_'.$rid}.''; $Str .= "\n"."". "\n"." $P_No ". - "\n"." ".$Temp." ". - "\n"." ".$hash{'src_'.$rid}." ". + "\n"." ".$Temp." ". + "\n"." ".$hash{'src_'.$rid}." ". "\n"." ".''.''. "\n".""; $P_No++; @@ -523,7 +526,7 @@ sub StudentReport { "\n".' Tries '. "\n".''; my ($temp)=keys(%result); - unless ($temp=~/^error\:/) { + unless ($temp=~/^(con_lost|error|no_such_host)/i) { foreach my $CurCol (@cols) { if (!$CurCol){ my $Set=&Apache::lonnet::declutter($hash{'map_id_'.$1}); @@ -751,6 +754,10 @@ sub usection { $courseid=~s/^(\w)/\/$1/; my %result=&Apache::lonnet::dump('roles',$udom,$unam); + my ($checkForResult)=keys(%result); + if ($checkForResult=~/^(con_lost|error|no_such_host)/i) { + return -1; + } foreach my $key (keys (%result)) { my $value=$result{$key}; if ($key=~/^$courseid(?:\/)*(\w+)*\_st$/) { @@ -803,7 +810,7 @@ sub ExtractStudentData { my $SecLimit; my $MapLimit; my ($temp)=keys(%result); - unless ($temp=~/^error\:/) { + unless ($temp=~/^(con_lost|error|no_such_host)/i) { foreach my $CurCol(@cols) { ($PrOrd,$ResId)=split(/\:/,$CurCol); if ( !$CurCol ) { next; } @@ -1287,18 +1294,18 @@ sub TableRow { "\n".''.($RealIdx+1).''. # "\n".''.$PrOrd.$Temp.''. "\n".''.$Temp.''. - "\n".' '.$StdNo.''. - "\n".''.$TotalTries.''. - "\n".''.$MxTries.''. - "\n".''.$Avg.''. - "\n".' '.$YES.''. - "\n".' '.$Override.''. - "\n".' '.$Wrng.''. - "\n".''.$DoD.''. - "\n".' '.$SD.''. - "\n".' '.$Sk.''. - "\n".' '.$_D1.''. - "\n".' '.$_D2.''; + "\n".' '.$StdNo.''. + "\n".''.$TotalTries.''. + "\n".''.$MxTries.''. + "\n".''.$Avg.''. + "\n".' '.$YES.''. + "\n".' '.$Override.''. + "\n".' '.$Wrng.''. + "\n".' '.$DoD.''. + "\n".' '.$SD.''. + "\n".' '.$Sk.''. + "\n".' '.$_D1.''. + "\n".' '.$_D2.''; $r->print("\n".$Ptr.'' ); } $GraphDat{$RealIdx}=$DoD.':'.$Wrng; @@ -1352,26 +1359,46 @@ sub GetGraphData { sub initial { # --------------------------------- Initialize the global varaibles - undef @students; - undef @cols; - undef %maps; - undef %section; - undef %StuBox; - undef @list; - undef %CachData; - undef %GraphDat; - undef %DiscFac; - undef %OpResp; - undef %ConceptData; - undef $CurMap; - undef $CurSec; - undef $CurStu; - undef $p_count; - undef $Pos; - undef $GData; - $DiscFlag=0; - $P_Order=100000; - $HWN=$P_Order; + undef @students; + undef @cols; + undef %maps; + undef %section; + undef %StuBox; + undef @list; + undef %CachData; + undef %GraphDat; + undef %DiscFac; + undef %OpResp; + undef %ConceptData; + undef $CurMap; + undef $CurSec; + undef $CurStu; + undef $p_count; + undef $Pos; + undef $GData; + $DiscFlag=0; + $P_Order=100000; + $HWN=$P_Order; + &setbgcolor(0); +} + +# For loading the colored table for display or un-colored for print +sub setbgcolor { + my $PrintTable=shift; + undef %color; + if ($PrintTable){ + $color{"gb"}="#FFFFFF"; + $color{"red"}="#FFFFFF"; + $color{"yellow"}="#FFFFFF"; + $color{"green"}="#FFFFFF"; + $color{"purple"}="#FFFFFF"; + } else { + $color{"gb"}="#DDFFFF"; + $color{"red"}="#FFDDDD"; + $color{"yellow"}="#EEFFCC"; + $color{"green"}="#DDFFDD"; + $color{"purple"}="#FFDDFF"; + } } # my $CacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}". @@ -1394,7 +1421,6 @@ sub initial { # } # untie(%students); - sub ClassList { &GetStatus(); @@ -1405,45 +1431,40 @@ sub ClassList { $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}}; $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}}; if (($firstres) && ($lastres)) { -# my %students = &Apache::lonnet::dump('classlist',$cdom,$cnum); -# $Apache::lonxml::debug=1; -# &Apache::lonhomework::showhash(%students); -# $Apache::lonxml::debug=0; -# my $StudNo = 0; -# my $now=time; -# my ($temp)=keys(%students); -# unless ($temp=~/^error\:/) { -# foreach my $KeyPoint(sort keys(%students)) { - - - my %classlist=&Apache::lonnet::dump('classlist',$cdom,$cnum); my $StudNo = 0; my $now=time; - foreach my $name (keys (%classlist)) { - my $value=$classlist{$name}; - my ($end,$start)=split(/\:/,$value); - my $active=1; - my $Status=$ENV{'form.status'}; - $Status = ($Status) ? $Status : 'Active'; - if ( ( ($end) && $now > $end ) && - ( ($Status eq 'Active') ) ) { $active=0; } - if ( ($Status eq 'Expired') && - ($end == 0 || $now < $end) ) { $active=0; } - if ($active) { - my $thisindex=$#students+1; - $students[$thisindex]=$name; - my ($sname,$sdom)=split(/\:/,$name); - my $ssec=&usection($sdom,$sname,$cid,$Status); - if ($ssec==-1 || $ssec eq 'adm' ) {next;} - $ssec=($ssec) ? $ssec : '(none)'; - #$ssec=(int($ssec)) ? int($ssec) : $ssec; - $section{$ssec}=$ssec; - if ($CurSec eq 'All Sections' || $ssec eq $CurSec) { - $students[$StudNo]=$name; - $StuBox{$sname}=$sdom; + my %classlist=&Apache::lonnet::dump('classlist',$cdom,$cnum); + + my ($checkForError)=keys(%classlist); + if($checkForError=~/^(con_lost|error|no_such_host)/i) { + $r->print('

Could not access course data

'); + } else { + foreach my $name (sort keys (%classlist)) { + my $value=$classlist{$name}; + my ($end,$start)=split(/\:/,$value); + my $active=1; + my $Status=$ENV{'form.status'}; + $Status = ($Status) ? $Status : 'Active'; + if ( ( ($end) && $now > $end ) && + ( ($Status eq 'Active') ) ) { $active=0; } + if ( ($Status eq 'Expired') && + ($end == 0 || $now < $end) ) { $active=0; } + if ($active) { + my $thisindex=$#students+1; + $students[$thisindex]=$name; + my ($sname,$sdom)=split(/\:/,$name); + my $ssec=&usection($sdom,$sname,$cid,$Status); + if ($ssec==-1 || $ssec eq 'adm' ) {next;} + $ssec=($ssec) ? $ssec : '(none)'; + #$ssec=(int($ssec)) ? int($ssec) : $ssec; + $section{$ssec}=$ssec; + if ($CurSec eq 'All Sections' || $ssec eq $CurSec) { + $students[$StudNo]=$name; + $StuBox{$sname}=$sdom; + } + $StudNo++; } - $StudNo++; } } @@ -1498,7 +1519,6 @@ sub CreateForm { $Ptr .= ''; $Ptr .= ''; #$Ptr .= ''; - #$Ptr .= ''; $r->print( $Ptr ); } else { @@ -1522,9 +1542,13 @@ sub CreateForm { sub Menu { &initial(); +# my $fn=$ENV{'request.course.fn'}; +# $r->print( '
'.$fn.'
' ); + # $Apache::lonxml::debug=1; # &Apache::lonhomework::showhash(%ENV); # $Apache::lonxml::debug=0; + &Title(); my $InpStr = $ENV{'form.sort'}; if ($InpStr eq 'Activity Log') {