[LON-CAPA-cvs] cvs: loncom /interface/statistics lonclassifystudents.pm

minaeibi lon-capa-cvs@mail.lon-capa.org
Sat, 27 Jul 2002 20:50:15 -0000


minaeibi		Sat Jul 27 16:50:15 2002 EDT

  Added files:                 
    /loncom/interface/statistics	lonclassifystudents.pm 
  Log:
  
  Added activity log and student classification module.
  
  

Index: loncom/interface/statistics/lonclassifystudents.pm
+++ loncom/interface/statistics/lonclassifystudents.pm
# The LearningOnline Network with CAPA
# (Publication Handler
#
# $Id: lonclassifystudents.pm,v 1.1 2002/07/27 20:50:15 minaeibi Exp $
#
# Copyright Michigan State University Board of Trustees
#
# This file is part of the LearningOnline Network with CAPA (LON-CAPA).
#
# LON-CAPA is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# LON-CAPA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with LON-CAPA; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
# /home/httpd/html/adm/gpl.txt
#
# http://www.lon-capa.org/
#
# (Navigate problems for statistical reports
#
# YEAR=2002
# 5/12,7/27  Behrouz Minaei
#
###

package Apache::lonclassifystudents; 

use strict;
use Apache::lonnet();
use Apache::lonhtmlcommon;
use Apache::loncoursedata;
use GDBM_File;


#---- Activity log -------------------------------------------------------

sub LoadDoDiffFile {
    my $file="/home/minaeibi/183d.txt";
    open(FILEID, "<$file");
    my $line=<FILEID>;
    my %DoDiff=();
    my @Act=split('&',$line);
    
#    $r->print('<br>'.$#Act);
    for(my $n=0;$n<=$#Act;$n++){
       my ($res,$Degree)=split('@',$Act[$n]);
      $DoDiff{$res}=$Degree;
    }

    return \%DoDiff;
}

sub LoadClassFile {
    my $file="/home/minaeibi/class.txt";
    open(FILEID, "<$file");
    my $line;
    my %Grade=();
    while ($line=<FILEID>) {
        my ($id,$ex1,$ex2,$ex3,$ex4,$hw,$final,$grade)=split(' ',$line);
        $Grade{$id}=$grade;
    }
    return \%Grade;
}

#------- Classification  
sub Classify {
    my ($DiscFac, $students)=@_;
    my ($fileGrade) = &LoadClassFile();
    my $Count=0;
    my @List=();
    my @LS=();
    my @LF=();
    my @LM=();
    my $cf=0;
    my $cs=0;
    my $cm=0;
    foreach (keys(%$DiscFac)){  
	my @l=split(/\:/,$_);
	if (!($students->{$l[1]})) {next;}
	my $Grade=$fileGrade->{$students->{$l[1]}};
	if( $Grade > 3 ) {
	    $cs++;
	    push(@LS,("$l[6],$l[5],$l[4],$l[7],$l[8],$l[9],Successful"));
	} elsif ( $Grade > 2 ) {
	    $cm++;
	    push(@LM,("$l[6],$l[5],$l[4],$l[7],$l[8],$l[9],Average"));
	} else {
	    $cf++;
	    push(@LF,("$l[6],$l[5],$l[4],$l[7],$l[8],$l[9],Failed"));
	}
    }
    my $Str = '';
    for(my $n=0;$n<$cs;$n++){$Str .= '<br>'.$LS[$n];}
    for(my $n=0;$n<$cm;$n++){$Str .= '<br>'.$LM[$n];}  
    for(my $n=0;$n<$cf;$n++){$Str .= '<br>'.$LF[$n];}

    return $Str;
} 

sub ProcAct {
    # return;
    my ($Act,$Submit)=@_;
    my @Act=split(/\@/,$Act);
    @Act = sort(@Act);

    ##$r->print('<br>'.$#Act);
    ##for(my $n=0;$n<=$#Act;$n++){
##	$r->print('<br>n='.$n.')'.$Act[$n]);
##    }

#    my $Beg=$Act[0];
    my $Dif=$Submit-$Act[0];
    $Dif = ($Dif>0) ? ($Dif/3600) : 0; 

#    $r->print('<br>Access Number = '.$#Act.'<br>Submit Time='.$Submit.'<br>First Access='.$Act[0].'<br>Last Access='.$Act[$#Act].'<br> Submit - First = <b>'.$Dif.'</b>');


#time spent for solving the problem           
#    $r->print('<br>Def'.($Act[$#Act-1]-$Act[0]));

    return $Dif;
}

sub LoadActivityLog {
#    my $CacheDB = "/home/minaeibi/act183.log.cache";
    my $CacheDB = "/home/httpd/perl/tmp/act183.log.cache";

    my %Activity;
    if (-e "$CacheDB") {
	if (tie(%Activity,'GDBM_File',"$CacheDB",&GDBM_READER,0640)) {
	    return;
        }
        else {
#	    $r->print("Unable to tie log Cache hash to db file");
        }
    }
    else {
	if (tie(%Activity,'GDBM_File',$CacheDB,&GDBM_WRCREAT,0640)) {
	    foreach (keys %Activity) {delete $Activity{$_};}
	    &Build_log(\%Activity); 
	}
        else {
#	    $r->print("Unable to tie log Build hash to db file");
        }
    }
    return \%Activity;
}

sub Build_log {
    my ($Activity)=@_;
    my $file="/home/minaeibi/act183.log";
    open(FILEID, "<$file");
    my $line;
    my $count=0;
    while ($line=<FILEID>) {
	my ($time,$machine,$what)=split(':',$line);
	$what=&Apache::lonnet::unescape($what);
	my @accesses=split('&',$what);
	           
	foreach my $access (@accesses) {

	    $count++;

	    my ($date,$resource,$who,$domain,$post,@posts)=split(':',$access);
	    if (!$resource) { next; }
	    my $res=&Apache::lonnet::unescape($resource);
	    if (($res =~ /\.problem/)) {
		$Activity->{$who.':'.$res}.=$date.'@';
                #$r->print('<br>'.$time.':'.$who.'---'.$res);
		&Update_PrgInit($count);

	    }
	}
    }

# my $c=1;
# foreach (sort keys %Activity) {
#     $r->print('<br>'.$c.')'.$_.' ... '.$Activity{$_});
#     $c++;
# }

}

sub Activity {
    my $file="/home/minaeibi/activity.log";
    my $userid='adamsde1';
#    $r->print("<br>Using $file");
#    $r->rflush();
    open(FILEID, "<$file");
    my $line;
    my @allaccess;
    my $Count=0;
    while ($line=<FILEID>) {
	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 (($res =~ /\.(sequence|problem|htm|html|page)/)) {
	    	$Count++;
###888		$r->print("<br>$Count) ".localtime($date).": $who --> $res");
#	        if ($post) { 
#		    $Count++;
#		    $r->print("<br><b>$Count) Sent data ".join(':',
#                              &Apache::lonnet::unescape(@posts)).'</b>');
#		}
###888		$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("<br>$Count) $date: $who --> $resource");
#	$r->rflush();
#	if ($post) { 
#	    $r->print("<br><b>Sent data ".join(':',unescape(@posts)).'</b>');
#	}
#    }
}

#---- END Activity log ---------------------------------------------------

1;
__END__