--- loncom/interface/lonstatistics.pm 2002/05/14 23:17:06 1.18 +++ loncom/interface/lonstatistics.pm 2002/05/31 13:47:01 1.25 @@ -1,7 +1,7 @@ # The LearningOnline Network with CAPA # (Publication Handler # -# $Id: lonstatistics.pm,v 1.18 2002/05/14 23:17:06 minaeibi Exp $ +# $Id: lonstatistics.pm,v 1.25 2002/05/31 13:47:01 minaeibi Exp $ # # Copyright Michigan State University Board of Trustees # @@ -31,7 +31,7 @@ # 11/1,11/4,11/16,12/14,12/16,12/18,12/20,12/31 Behrouz Minaei # YEAR=2002 # 1/22,2/1,2/6,2/25,3/2,3/6,3/17,3/21,3/22,3/26,4/7,5/6 Behrouz Minaei -# 5/12, 5/14 Behrouz Minaei +# 5/12,5/14,5/15,5/19,5/26 Behrouz Minaei # ### @@ -78,6 +78,7 @@ my $lastres; my $DiscFlag; my $HWN; my $P_Order; +my %color; my %foil_to_concept; my @Concepts; my %ConceptData; @@ -86,6 +87,59 @@ my %Header = (0,"Homework Sets Order",1, 9,"S.D.",10,"Skew.",11,"D.F.1st",12,"D.F.2nd"); my %Answer = (); + +sub Activity { + my $file="/home/minaeibi/minaei"; + my $userid='billskat'; + $r->print("
Using $file"); + $r->rflush(); + open(FILEID, "<$file"); + my $line; + my @allaccess; + my $Count=0; + while ($line=) { + my ($time,$machine,$what)=split(':',$line); + $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; } + my $res=&Apache::lonnet::unescape($resource); + #if (($key=~/\.(\w+)\.(\w+)\.submission$/)) { + #if ($meta=~/\.(problem|exam|quiz|assess|survey|form)$/) { + # foreach my $Key(split(/\,/,&Apache::lonnet::metadata($meta,'keys'))) { + # if ($Key=~/^stores\_(\w+)\_tries$/) { + + # if (($res =~ /^\/res\/adm/)) { + $Count++; + $r->print("
$Count) $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); +# $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)).''); +# } +# } +} + + + sub InitAnalysis { my ($rid, $student)=@_; my ($uname,$udom)=split(/\:/,$student); @@ -119,6 +173,7 @@ sub InitAnalysis { foreach my $concept (@{$Answer{"$parts.concepts"}}) { foreach my $foil (@{$Answer{"$parts.concept.$concept"}}) { $foil_to_concept{$foil} = $concept; + #$ConceptData{$foil} = $Answer{"$parts.foil.value.$foil"}; } } return $symb; @@ -150,7 +205,9 @@ sub ShowOpGraph { my ($InpStr, $Int_No)=@_; my ($rid,$part)=split(/\:/,substr($InpStr,8)); $ConceptData{"Interval"}=$Int_No; + #Initialize the option response true answers my $symb=&InitAnalysis($rid,$students[0]); + #compute the intervals &Interval($rid,$part,$symb); my $URI = $hash{'src_'.$rid}; my $Src = $hash{'title_'.$rid}; @@ -158,6 +215,7 @@ sub ShowOpGraph { $r->print('
'.$URI.''); $r->rflush(); + #Java script Progress window &Create_PrgWin(); &Update_PrgWin("Starting to analyze problem"); for (my $index=0;$index<=$#students;$index++) { @@ -166,9 +224,13 @@ sub ShowOpGraph { } &Close_PrgWin(); + $r->print('
'); for (my $k=0; $k<$Int_No; $k++ ) { &DrawGraph($k,$Src); } + for (my $k=0; $k<$Int_No; $k++ ) { + &DrawTable($k); + } #$Apache::lonxml::debug=1; #&Apache::lonhomework::showhash(%ConceptData); #$Apache::lonxml::debug=0; @@ -177,14 +239,13 @@ sub ShowOpGraph { } -sub DrawGraph { - my ($k,$Src)=@_; +sub DrawTable { + my $k=shift; my $Max=0; my @data1; my @data2; my $Correct=0; my $Wrong=0; - # Adjust Data and find the Max for (my $n=0; $n<=$#Concepts; $n++ ) { my $tmp=$Concepts[$n]; $data1[$n]=$ConceptData{"$tmp.$k.true"}; @@ -213,43 +274,65 @@ sub DrawGraph { 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-1)}). - '] To: ['.localtime($ConceptData{"Int.$k"}). + $Str.='From:['.localtime($ConceptData{'Int.'.$k}). + '] To: ['.localtime($ConceptData{'Int.'.($k+1)}-1). "]$Correct$Wrong"; $Str .= "\n".''; $r->print($Str); +#$Apache::lonxml::debug=1; +#&Apache::lonhomework::showhash(%ConceptData); +#$Apache::lonxml::debug=0; +} - if ( $Max > 1 ) { - $Max += (10 - $Max % 10); - $Max = int($Max); - } else { $Max = 1; } + +sub DrawGraph { + my ($k,$Src)=@_; + my $Max=0; + my @data1; + my @data2; + + # Adjust Data and find the Max + for (my $n=0; $n<=$#Concepts; $n++ ) { + my $tmp=$Concepts[$n]; + $data1[$n]=$ConceptData{"$tmp.$k.true"}; + $data2[$n]=$ConceptData{"$tmp.$k.false"}; + my $Sum=$data1[$n]+$data2[$n]; + if ( $Max<$Sum ) {$Max=$Sum;} + } + for (my $n=0; $n<=$#Concepts; $n++ ) { + if ($data1[$n]+$data2[$n]<$Max) { + $data2[$n]+=$Max-($data1[$n]+$data2[$n]); + } + } + my $P_No = $#data1+1; if ( $Max > 1 ) { $Max += (10 - $Max % 10); $Max = int($Max); } else { $Max = 1; } - my $Titr=($ConceptData{'Interval'}>1) ? $Src.'_interval_'.$k : $Src; + + 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&". (join(',',@data1)).'&'.(join(',',@data2)); - $r->print('
'); + $r->print(''); } sub AnalyzeProblem { -# -------------------------------- Selecting the number of intervals + # selecting the number of intervals my $OpSel=''; my $CurInt = $ENV{'form.interval'}; if ($CurInt eq '') {$CurMap = '1';} - my $Ptr = 'Select number of intervals'."\n". + my $Ptr = '
Select number of intervals'."\n". ''.''. "\n".""; $P_No++; @@ -289,6 +373,7 @@ sub AnalyzeProblem { sub Decide { + #deciding the true or false answer belongs to each interval my ($type,$foil,$time)=@_; my $k=0; while ($time>$ConceptData{'Int.'.($k+1)} && @@ -297,6 +382,7 @@ sub Decide { } +#restore the student submissions and finding the result sub OpStatus { my ($rid,$student)=@_; my ($uname,$udom)=split(/\:/,$student); @@ -445,7 +531,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}); @@ -538,7 +624,7 @@ sub StudentReport { sub CreateTable { my ($Hd, $Hid)=@_; - if ($ENV{'form.showcsv'}) { + if ($ENV{'form.showcsv'}) { if ( $Hd == 1 ) { $r->print('
"'.$hash{'title_'.$Hid}.'","'.$hash{'src_'.$Hid}.'"'); } @@ -573,6 +659,7 @@ sub CloseTable { # ------------------------------------------- Prepare Statistics Table sub PreStatTable { + my $CacheDB = "/home/httpd/perl/tmp/$ENV{'user.name'}". "_$ENV{'user.domain'}_$cid\_statistics.db"; my $GraphDB = "/home/httpd/perl/tmp/$ENV{'user.name'}". @@ -605,8 +692,8 @@ sub PreStatTable { $Ptr .= '
'.
     '  #Stdnts: Total Number of Students opened the problem.
'. ' Tries : Total Number of Tries for solving the problem.
'. - ' Max : Maximunm Number of Tries for solving the problem.
'. - ' Avg. : Average Number of the tries. [ Tries / #Stdnts ]
'. + ' Mod : Maximunm Number of Tries for solving the problem.
'. + ' Mean : Average Number of the tries. [ Tries / #Stdnts ]
'. ' #YES : Number of students solved the problem correctly.
'. ' #yes : Number of students solved the problem by override.
'. ' %Wrng : Percentage of students tried to solve the problem but'. @@ -614,10 +701,10 @@ sub PreStatTable { # ' DoDiff : Degree of Difficulty of the problem. [ Tries/(#YES+#yes+0.1) ]
'. Kashy formula ' DoDiff : Degree of Difficulty of the problem. [ 1 - ((#YES+#yes) / Tries) ]
'. #Gerd formula ' S.D. : Standard Deviation of the tries.'. - '[ sqrt(sum((Xi - Avg.)^2)) / (#Stdnts-1)'. + '[ sqrt(sum((Xi - Mean)^2)) / (#Stdnts-1)'. ' where Xi denotes every student\'s tries ]
'. ' Skew. : Skewness of the students tries.'. - ' [ (sqrt( sum((Xi - Avg.)^3) / #Stdnts)) / (S.D.^3) ]
'. + ' [ (sqrt( sum((Xi - Mean)^3) / #Stdnts)) / (S.D.^3) ]
'. ' Dis.F. : Discrimination Factor: A Standard for '. 'evaluating the problem according to a Criterion
'. ' [Applied Criterion in %27 Upper Students - '. @@ -670,15 +757,18 @@ sub usection { my ($udom,$unam,$courseid,$ActiveFlag)=@_; $courseid=~s/\_/\//g; $courseid=~s/^(\w)/\/$1/; - foreach (split(/\&/,&Apache::lonnet::reply('dump:'. - $udom.':'.$unam.':roles', - &Apache::lonnet::homeserver($unam,$udom)))){ - my ($key,$value)=split(/\=/,$_); - $key=&Apache::lonnet::unescape($key); + + 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$/) { my $section=$1; if ($key eq $courseid.'_st') { $section=''; } - my ($dummy,$end,$start)=split(/\_/,&Apache::lonnet::unescape($value)); + my ($dummy,$end,$start)=split(/\_/,$value); if ( $ActiveFlag ne 'Any' ) { my $now=time; my $notactive=0; @@ -725,7 +815,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; } @@ -848,6 +938,7 @@ sub ExtractStudentData { } + # ------------------------------------------------------------ Build page table sub tracetable { my ($rid,$beenhere)=@_; @@ -995,7 +1086,6 @@ sub Build_Statistics { @list = sort (@list); - &Discriminant(); $OpSel2=''; @@ -1135,6 +1225,7 @@ sub Cache_Statistics { my @list = (); my $Useful; my $UnUseful; +# $r->print(''."\n"); my %myHeader = reverse( %Header ); $Pos = $myHeader{$ENV{'form.sort'}}; if ($Pos > 0) {$Pos++;} @@ -1208,18 +1299,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; @@ -1273,68 +1364,115 @@ 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'}". +# "_$ENV{'user.domain'}_$cid\_classlist.db"; +# if (-e "$CacheDB") { +# if (tie(%students,'GDBM_File',"$CacheDB",&GDBM_READER,0640)) { +# &CachClassList(); +# } +# else { +# $r->print("Unable to tie hash to db file"); +# } +# } +# else { +# if (tie(%students,'GDBM_File',$CacheDB,&GDBM_WRCREAT,0640)) { +# &MakeClassList(); +# } +# else { +# $r->print("Unable to tie hash to db file"); +# } +# } +# untie(%students); + sub ClassList { &GetStatus(); $cid=$ENV{'request.course.id'}; - my $chome=$ENV{'course.'.$cid.'.home'}; my ($cdom,$cnum)=split(/\_/,$cid); # ----------------------- Get first and last resource, see if there is anything $firstres=$hash{'map_start_/res/'.$ENV{'request.course.uri'}}; $lastres=$hash{'map_finish_/res/'.$ENV{'request.course.uri'}}; if (($firstres) && ($lastres)) { - #my %result = &Apache::lonnet::dump('classlist',$sdom,$sname); - my $classlst=&Apache::lonnet::reply('dump:'.$cdom.':'.$cnum.':classlist',$chome); +# 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 $StudNo = 0; my $now=time; - unless ($classlst=~/^error\:/) { - foreach (sort split(/\&/,$classlst)) { - my ($name,$value)=split(/\=/,$_); - my ($end,$start)=split(/\:/,&Apache::lonnet::unescape($value)); - $name=&Apache::lonnet::unescape($name); - my ($sname,$sdom)=split(/\:/,$name); + + 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 (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; } + ( ($Status eq 'Active') ) ) { $active=0; } if ( ($Status eq 'Expired') && - ($end == 0 || $now < $end) ) { $active=0; } + ($end == 0 || $now < $end) ) { $active=0; } if ($active) { my $thisindex=$#students+1; - $name=&Apache::lonnet::unescape($name); $students[$thisindex]=$name; my ($sname,$sdom)=split(/\:/,$name); - #my %reply=&Apache::lonnet::idrget($sdom,$sname); - #my $reply=&Apache::lonnet::reply('get:'.$sdom.':'.$sname. - # ':environment:lastname&generation&firstname&middlename', - # &Apache::lonnet::homeserver($sname,$sdom)); my $ssec=&usection($sdom,$sname,$cid,$Status); -# if ($ssec==-1 ) {next;} if ($ssec==-1 || $ssec eq 'adm' ) {next;} $ssec=($ssec) ? $ssec : '(none)'; #$ssec=(int($ssec)) ? int($ssec) : $ssec; @@ -1344,12 +1482,10 @@ sub ClassList { $StuBox{$sname}=$sdom; } $StudNo++; - } + } } } - else { - $r->print('

Could not access course data

'); - } + $r->print("Total number of students : ".($#students+1)); $r->rflush(); # --------------- Find all assessments and put them into some linear-like order @@ -1387,10 +1523,12 @@ sub Title { $r->rflush(); } + sub CreateForm { $r->print("\n".'
'); my $content = $ENV{'form.sort'}; - if (!($ENV{'form.showcsv'}) && ($content eq '' || $content eq 'Return to Menu')) { + if (!($ENV{'form.showcsv'}) && + ($content eq '' || $content eq 'Return to Menu')) { my $Ptr = '

'; $Ptr .= ''; $Ptr .= '

'; @@ -1398,9 +1536,11 @@ sub CreateForm { $Ptr .= '

'; $Ptr .= ''; $Ptr .= '

'; + #$Ptr .= ''; $r->print( $Ptr ); } else { + &ClassList(); if ( $content eq 'Student Assessment' || $content eq 'Create Student Report' ) { &MapSecOptions(); @@ -1420,13 +1560,16 @@ sub CreateForm { sub Menu { &initial(); - #$Apache::lonxml::debug=1; - #&Apache::lonhomework::showhash(%ENV); - #$Apache::lonxml::debug=0; +# $Apache::lonxml::debug=1; +# &Apache::lonhomework::showhash(%ENV); +# $Apache::lonxml::debug=0; &Title(); - &ClassList(); my $InpStr = $ENV{'form.sort'}; - if ($InpStr=~/^Analyze\_/) { + if ($InpStr eq 'Activity Log') { + &Activity(); + } + elsif ($InpStr=~/^Analyze\_/) { + &ClassList(); &ShowOpGraph($InpStr,$ENV{'form.interval'}); } elsif ( $InpStr eq 'DoDiff Graph' || $InpStr eq '%Wrong Graph' ) { @@ -1442,6 +1585,7 @@ sub Menu { $r->rflush(); } + sub StudentOptions { my $OpSel5=''; $CurStu = $ENV{'form.student'}; @@ -1497,7 +1641,7 @@ sub GetStatus { sub MapSecOptions { # ----------------------------------- Loading the Maps Combobox - my $Ptr = ''; + my $Ptr = '
'; $Ptr .= ''; $Ptr .= '
Select   Map     '."\n". '