Annotation of loncom/interface/statistics/lonclassifystudents.pm, revision 1.2

1.1       minaeibi    1: # The LearningOnline Network with CAPA
                      2: # (Publication Handler
                      3: #
1.2     ! www         4: # $Id: lonclassifystudents.pm,v 1.1 2002/07/27 20:50:15 minaeibi Exp $
1.1       minaeibi    5: #
                      6: # Copyright Michigan State University Board of Trustees
                      7: #
                      8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                      9: #
                     10: # LON-CAPA is free software; you can redistribute it and/or modify
                     11: # it under the terms of the GNU General Public License as published by
                     12: # the Free Software Foundation; either version 2 of the License, or
                     13: # (at your option) any later version.
                     14: #
                     15: # LON-CAPA is distributed in the hope that it will be useful,
                     16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     18: # GNU General Public License for more details.
                     19: #
                     20: # You should have received a copy of the GNU General Public License
                     21: # along with LON-CAPA; if not, write to the Free Software
                     22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     23: #
                     24: # /home/httpd/html/adm/gpl.txt
                     25: #
                     26: # http://www.lon-capa.org/
                     27: #
                     28: # (Navigate problems for statistical reports
                     29: #
                     30: #
                     31: ###
                     32: 
                     33: package Apache::lonclassifystudents; 
                     34: 
                     35: use strict;
                     36: use Apache::lonnet();
                     37: use Apache::lonhtmlcommon;
                     38: use Apache::loncoursedata;
                     39: use GDBM_File;
1.2     ! www        40: use lib '/home/httpd/lib/perl/';
        !            41: use LONCAPA;
        !            42:   
1.1       minaeibi   43: 
                     44: 
                     45: #---- Activity log -------------------------------------------------------
                     46: 
                     47: sub LoadDoDiffFile {
                     48:     my $file="/home/minaeibi/183d.txt";
                     49:     open(FILEID, "<$file");
                     50:     my $line=<FILEID>;
                     51:     my %DoDiff=();
                     52:     my @Act=split('&',$line);
                     53:     
                     54: #    $r->print('<br>'.$#Act);
                     55:     for(my $n=0;$n<=$#Act;$n++){
                     56:        my ($res,$Degree)=split('@',$Act[$n]);
                     57:       $DoDiff{$res}=$Degree;
                     58:     }
                     59: 
                     60:     return \%DoDiff;
                     61: }
                     62: 
                     63: sub LoadClassFile {
                     64:     my $file="/home/minaeibi/class.txt";
                     65:     open(FILEID, "<$file");
                     66:     my $line;
                     67:     my %Grade=();
                     68:     while ($line=<FILEID>) {
                     69:         my ($id,$ex1,$ex2,$ex3,$ex4,$hw,$final,$grade)=split(' ',$line);
                     70:         $Grade{$id}=$grade;
                     71:     }
                     72:     return \%Grade;
                     73: }
                     74: 
                     75: #------- Classification  
                     76: sub Classify {
                     77:     my ($DiscFac, $students)=@_;
                     78:     my ($fileGrade) = &LoadClassFile();
                     79:     my $Count=0;
                     80:     my @List=();
                     81:     my @LS=();
                     82:     my @LF=();
                     83:     my @LM=();
                     84:     my $cf=0;
                     85:     my $cs=0;
                     86:     my $cm=0;
                     87:     foreach (keys(%$DiscFac)){  
                     88: 	my @l=split(/\:/,$_);
                     89: 	if (!($students->{$l[1]})) {next;}
                     90: 	my $Grade=$fileGrade->{$students->{$l[1]}};
                     91: 	if( $Grade > 3 ) {
                     92: 	    $cs++;
                     93: 	    push(@LS,("$l[6],$l[5],$l[4],$l[7],$l[8],$l[9],Successful"));
                     94: 	} elsif ( $Grade > 2 ) {
                     95: 	    $cm++;
                     96: 	    push(@LM,("$l[6],$l[5],$l[4],$l[7],$l[8],$l[9],Average"));
                     97: 	} else {
                     98: 	    $cf++;
                     99: 	    push(@LF,("$l[6],$l[5],$l[4],$l[7],$l[8],$l[9],Failed"));
                    100: 	}
                    101:     }
                    102:     my $Str = '';
                    103:     for(my $n=0;$n<$cs;$n++){$Str .= '<br>'.$LS[$n];}
                    104:     for(my $n=0;$n<$cm;$n++){$Str .= '<br>'.$LM[$n];}  
                    105:     for(my $n=0;$n<$cf;$n++){$Str .= '<br>'.$LF[$n];}
                    106: 
                    107:     return $Str;
                    108: } 
                    109: 
                    110: sub ProcAct {
                    111:     # return;
                    112:     my ($Act,$Submit)=@_;
                    113:     my @Act=split(/\@/,$Act);
                    114:     @Act = sort(@Act);
                    115: 
                    116:     ##$r->print('<br>'.$#Act);
                    117:     ##for(my $n=0;$n<=$#Act;$n++){
                    118: ##	$r->print('<br>n='.$n.')'.$Act[$n]);
                    119: ##    }
                    120: 
                    121: #    my $Beg=$Act[0];
                    122:     my $Dif=$Submit-$Act[0];
                    123:     $Dif = ($Dif>0) ? ($Dif/3600) : 0; 
                    124: 
                    125: #    $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>');
                    126: 
                    127: 
                    128: #time spent for solving the problem           
                    129: #    $r->print('<br>Def'.($Act[$#Act-1]-$Act[0]));
                    130: 
                    131:     return $Dif;
                    132: }
                    133: 
                    134: sub LoadActivityLog {
                    135: #    my $CacheDB = "/home/minaeibi/act183.log.cache";
                    136:     my $CacheDB = "/home/httpd/perl/tmp/act183.log.cache";
                    137: 
                    138:     my %Activity;
                    139:     if (-e "$CacheDB") {
                    140: 	if (tie(%Activity,'GDBM_File',"$CacheDB",&GDBM_READER,0640)) {
                    141: 	    return;
                    142:         }
                    143:         else {
                    144: #	    $r->print("Unable to tie log Cache hash to db file");
                    145:         }
                    146:     }
                    147:     else {
                    148: 	if (tie(%Activity,'GDBM_File',$CacheDB,&GDBM_WRCREAT,0640)) {
                    149: 	    foreach (keys %Activity) {delete $Activity{$_};}
                    150: 	    &Build_log(\%Activity); 
                    151: 	}
                    152:         else {
                    153: #	    $r->print("Unable to tie log Build hash to db file");
                    154:         }
                    155:     }
                    156:     return \%Activity;
                    157: }
                    158: 
                    159: sub Build_log {
                    160:     my ($Activity)=@_;
                    161:     my $file="/home/minaeibi/act183.log";
                    162:     open(FILEID, "<$file");
                    163:     my $line;
                    164:     my $count=0;
                    165:     while ($line=<FILEID>) {
                    166: 	my ($time,$machine,$what)=split(':',$line);
1.2     ! www       167: 	$what=&unescape($what);
1.1       minaeibi  168: 	my @accesses=split('&',$what);
                    169: 	           
                    170: 	foreach my $access (@accesses) {
                    171: 
                    172: 	    $count++;
                    173: 
                    174: 	    my ($date,$resource,$who,$domain,$post,@posts)=split(':',$access);
                    175: 	    if (!$resource) { next; }
1.2     ! www       176: 	    my $res=&unescape($resource);
1.1       minaeibi  177: 	    if (($res =~ /\.problem/)) {
                    178: 		$Activity->{$who.':'.$res}.=$date.'@';
                    179:                 #$r->print('<br>'.$time.':'.$who.'---'.$res);
                    180: 		&Update_PrgInit($count);
                    181: 
                    182: 	    }
                    183: 	}
                    184:     }
                    185: 
                    186: # my $c=1;
                    187: # foreach (sort keys %Activity) {
                    188: #     $r->print('<br>'.$c.')'.$_.' ... '.$Activity{$_});
                    189: #     $c++;
                    190: # }
                    191: 
                    192: }
                    193: 
                    194: sub Activity {
                    195:     my $file="/home/minaeibi/activity.log";
                    196:     my $userid='adamsde1';
                    197: #    $r->print("<br>Using $file");
                    198: #    $r->rflush();
                    199:     open(FILEID, "<$file");
                    200:     my $line;
                    201:     my @allaccess;
                    202:     my $Count=0;
                    203:     while ($line=<FILEID>) {
                    204: 	my ($time,$machine,$what)=split(':',$line);
1.2     ! www       205: 	$what=&unescape($what);
1.1       minaeibi  206: 	my @accesses=split('&',$what);
                    207: 	foreach my $access (@accesses) {
                    208: 	    my ($date,$resource,$who,$domain,$post,@posts)=split(':',$access);
                    209: 	    #if ($who ne $userid) { next; }
                    210: 	    if (!$resource) { next; }
1.2     ! www       211: 	    my $res=&unescape($resource);
1.1       minaeibi  212: 	    if (($res =~ /\.(sequence|problem|htm|html|page)/)) {
                    213: 	    	$Count++;
                    214: ###888		$r->print("<br>$Count) ".localtime($date).": $who --> $res");
                    215: #	        if ($post) { 
                    216: #		    $Count++;
                    217: #		    $r->print("<br><b>$Count) Sent data ".join(':',
1.2     ! www       218: #                              &unescape(@posts)).'</b>');
1.1       minaeibi  219: #		}
                    220: ###888		$r->rflush();
                    221: 	    }
                    222: 	    #push (@allaccess,unescape($access));
                    223: 	    #print $machine;
                    224: 	}
                    225:     }
                    226: #    @allaccess=sort(@allaccess);
                    227: #    $Count=0;
                    228: #    foreach my $access (@allaccess) {
                    229: #	my ($date,$resource,$who,$domain,$post,@posts)=split(':',$access);
                    230: #	$Count++;
                    231: #	$r->print("<br>$Count) $date: $who --> $resource");
                    232: #	$r->rflush();
                    233: #	if ($post) { 
                    234: #	    $r->print("<br><b>Sent data ".join(':',unescape(@posts)).'</b>');
                    235: #	}
                    236: #    }
                    237: }
                    238: 
                    239: #---- END Activity log ---------------------------------------------------
                    240: 
                    241: 1;
                    242: __END__

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>