head	1.8;
access;
symbols;
locks
	perlman:1.8; strict;
comment	@# @;


1.8
date	99.11.09.14.25.15;	author perlman;	state Exp;
branches;
next	1.7;

1.7
date	99.11.06.05.18.44;	author perlman;	state Exp;
branches;
next	1.6;

1.6
date	99.11.06.04.48.53;	author perlman;	state Exp;
branches;
next	1.5;

1.5
date	98.11.04.02.17.12;	author perlman;	state Exp;
branches;
next	1.4;

1.4
date	98.10.29.02.59.03;	author perlman;	state Exp;
branches;
next	1.3;

1.3
date	98.10.29.01.57.30;	author perlman;	state Exp;
branches;
next	1.2;

1.2
date	98.10.29.01.21.22;	author perlman;	state Exp;
branches;
next	1.1;

1.1
date	98.09.14.12.21.01;	author perlman;	state Exp;
branches;
next	;


desc
@@


1.8
log
@corrected total coutners
@
text
@#! /usr/local/bin/perl

# can check date of file to see if today applies to it

# wc -l csuq.log | colex 1 2

$mincount = 5;

local ($DAYSECS) = 86400;
local ($Timenow) = time;
while ($ARGV[0]) {
	if ($ARGV[0] =~ /-[0-9]/) { # set start date
		$Timenow += $DAYSECS * $ARGV[0];
	} elsif ($ARGV[0] =~ /-v/) { # verbose
		$mincount = -999;
	} else {
		@@dirlist = (@@dirlist, $ARGV[0]);
	}
	shift;
}
local ($Sec,$Min,$Hour,$Mday,$Mon,$Year,$Wday,$Yday,$Isdst) = localtime ($Timenow);
$Timenow -= $Sec + 60 * ($Min + 60 * $Hour); # set time to beginning of day
@@dirlist = ("$ENV{'HOME'}/WWW","$ENV{'BIB'}","$ENV{'CHI'}","$ENV{'CAPH'}/links") unless @@dirlist;
@@Weekdays = ("Sun", "Mon", "Tues", "Weds", "Thur", "Fri", "Sat");

# MAIN LOOP
for $dir (@@dirlist) {
	&countdir ($dir);
}

sub sizecmp { ($size{$b} <=> $size{$a}) || ($a cmp $b); }
sub countdir
{
	local ($dir) = (@@_);
	local (@@allfiles) = ();
	local (%size) = ();
	local (@@count) = ();
	# &reset();
	%sum = ();
	&header ($dir);
	chdir $dir || return;
	opendir DIR, ".";
	@@allfiles = grep /^[.].*[.](html|cgi)/, readdir DIR;
	closedir DIR;
	# get the size and dates of the files
	for $file (@@allfiles) {
		local ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,
			$size,$atime,$mtime,$ctime,$blksize,$blocks) = stat ($file);
		$size{$file} = $size;
		$mtime{$file} = $mtime;
	}
	# show file stats, sorted by file size
	for $file (sort sizecmp keys %size) {
		@@count = &countfile ($file);
		&fmtcount ($file, $size{$file}, @@count);
	}
	&fmtsum();
}

sub countfile
{
	local ($file) = (@@_);
	local (@@count) = ();
	if ($mtime{$file} >= $Timenow) {
		open FILE, $file;
		read FILE, $buf, $size{$file}; # read the whole file in
		close FILE;
		$end = $size{$file};
		# scan back to first match
		while (($end > 0) && (substr ($buf, $end-1, 1) ne $Wday)) {
			$end--;
		}
		# scan back and count matches
		for $offset (0 .. 13) {
			$count[$offset] = 0;
			$day = ($Wday - $offset + 70) % 7; # check this day of week
			while (($end > 0) && (substr ($buf, $end-1, 1) eq $day)) {
				$end--;
				$count[$offset]++;
			}
		}
	} else {
		$count[0] = - (($Timenow - $mtime{$file}) / $DAYSECS + 1)
	}
	return (@@count);
}

sub header
{
	local ($dir) = (@@_);
	local ($day, $wday);
	printf "%6.6s ", "==========";
	for $day (0 .. 6) {
		$wday = ($Wday - $day + 70) % 7;
		printf "%4s ", $Weekdays[$wday];
	}
	printf "%5s ", "WEEK";
	printf "%5s ", "LAST";
	print "$dir\n";
}

sub fmtcount
{
	local ($file, $total, @@count) = (@@_);
	local ($day);
	local ($week) = 0;
	local ($last) = 0;
	local ($missing) = 0;
	$count[0] < $mincount && return;
	if ($count[0] < 0) {
		$missing = 1;
		$week = -$count[0];
	} else {
		for $day (7 .. 13) {
			if ($count[$day] > 0) {
				$last += $count[$day];
			}
		}
	}
	printf "%6d ", $total;
	$sum{'total'} += $total;
	$sum{'nfiles'} += 1;
	for $day  (0 .. 6) {
		if ($missing && $day > 0) {
			$count[$day] = 0;
		} else {
			$week += $count[$day];
			$sum{$day} += $count[$day] if ($count[$day] > 0);
		}
		printf "%4d ", $count[$day];
	}
	printf "%5d ", $week;
	$sum{'week'} += $week;
	printf "%5d ", $last;
	$sum{'last'} += $last;
	print "$file\n";
}

sub fmtsum
{
	if ($sum{'nfiles'} > 1) {
		printf "%6d ", $sum{'total'};
		$sum{'total'} = 0;
		for $day (0 .. 6) {
			printf "%4d ", $sum{$day};
			$sum{$day} = 0;
		}
		printf "%5d ", $sum{'week'};
		$sum{'week'} = 0;
		printf "%5d ", $sum{'last'};
		$sum{'last'} = 0;
		print "TOTAL\n";
	}
}

sub reset
{
	%sum = (
		'total', 0,
		'0', 0,
		'1', 0,
		'2', 0,
		'3', 0,
		'4', 0,
		'5', 0,
		'7', 0,
		'week', 0,
		'last', 0
		);
}
@


1.7
log
@added totals
@
text
@d35 6
a40 2
	local (@@allfiles, %size);
	header ($dir);
d63 1
d122 1
d128 1
a128 1
			$sum[$day] += $count[$day] if ($count[$day] > 0);
d135 1
a135 1
	$sum{'last'} += $week;
d141 12
a152 3
	printf "%6d ", $sum{'total'};
	for $day (0 .. 6) {
		printf "%4d ", $sum[$day];
a153 4
	printf "%5d ", $sum{'week'};
	printf "%5d ", $sum{'last'};
	print "TOTAL\n";
	%sum = ();
d156 15
@


1.6
log
@*** empty log message ***
@
text
@d50 2
a51 1
		&countfile ($file);
d53 1
d80 1
a80 1
	fmtcount ($file, $size{$file}, @@count);
d110 3
a112 1
			$last += $count[$day];
d116 1
d122 1
d127 1
d129 1
d132 13
@


1.5
log
@*** empty log message ***
@
text
@d7 2
d14 2
d23 1
a23 1
@@dirlist = ("$ENV{'HOME'}/WWW","$ENV{'BIB'}","$ENV{'CHI'}") unless @@dirlist;
d39 1
a39 1
	@@allfiles = grep /^[.].*[.]html/, readdir DIR;
d67 1
a67 1
		for $offset (0 .. 6) {
d69 1
a69 1
			$day = ($Wday - $offset + 7) % 7; # check this day of week
d87 1
a87 1
		$wday = ($Wday - $day + 7) % 7;
d91 1
d100 1
d102 1
d106 4
d121 1
@


1.4
log
@added weekly stats
@
text
@a111 4




@


1.3
log
@broke out countfile
@
text
@d10 1
a10 1
	if ($ARGV[0] =~ /-[0-9]/) {
d18 1
a18 1
$Timenow -= $Sec + 60 * ($Min + 60 * $Hour);
d20 1
d32 1
a32 1
	print "============= $dir \n";
d63 7
a69 4
		$todaycount = 0;
		while (($end > 0) && (substr ($buf, $end-1, 1) eq $Wday)) {
			$end--;
			$todaycount++;
a70 1
		$today{$file} = $todaycount;
d72 13
a84 1
		$today{$file} = - (($Timenow - $mtime{$file}) / $DAYSECS + 1)
d86 2
a87 1
	fmtcount ($size{$file}, $today{$file}, $file);
d92 19
a110 2
	local ($total, $subtotal, $file) = (@@_);
	printf "%6d	%4d $file\n", $total, $subtotal;
@


1.2
log
@*** empty log message ***
@
text
@d36 1
d41 1
a41 19
		if ($mtime >= $Timenow) {
			open FILE, $file;
			read FILE, $buf, $size; # read the whole file in
			close FILE;
			$end = $size;
			# scan back to first match
			while (($end > 0) && (substr ($buf, $end-1, 1) ne $Wday)) {
				$end--;
			}
			# scan back and count matches
			$todaycount = 0;
			while (($end > 0) && (substr ($buf, $end-1, 1) eq $Wday)) {
				$end--;
				$todaycount++;
			}
			$today{$file} = $todaycount;
		} else {
			$today{$file} = - (($Timenow - $mtime) / $DAYSECS + 1)
		}
d43 1
d45 25
a69 1
		fmtcount ($size{$file}, $today{$file}, $file);
d71 1
d80 1
a80 15
sub countlog
{
	local ($DIR, $LOG) = (@@_);
	local ($hits) = 0;
	local (@@list);
	local ($last);

	chdir ($DIR);
	open (LOG, "<$LOG") || die "can't open $LOG";

	while (<LOG>) {
		@@items = split (/\s/);
		$items{$items[0]}++;
		$hits++;
	}
a81 1
	close (LOG);
a82 7
	for $item (keys (%items)) {
		if ($item gt $last) {
			$last = $item;
		}
	}
	fmtcount $hits, $items{$last}, "$LOG for $last";
}
@


1.1
log
@Initial revision
@
text
@a4 10
local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;

$wday = changeday ($wday, $ARGV[0]) if $ARGV[0];

&countdir ("$ENV{'HOME'}/WWW");
&countdir ("$ENV{'BIB'}");
# &countlog ($ENV{'BIB'}, "gs.log");
&countdir ("$ENV{'CHI'}");
# &countdir ("$ENV{'BUCK'}");

d7 17
a23 4
sub changeday
{
	local ($wday, $change) = (@@_);
	return (($wday + $change) % 7);
d40 18
a57 13
		open FILE, $file;
		read FILE, $buf, $size;
		close FILE;
		$end = $size;
		# scan back to first match
		while (($end > 0) && (substr ($buf, $end-1, 1) ne $wday)) {
			$end--;
		}
		# scan back and count matches
		$todaycount = 0;
		while (($end > 0) && (substr ($buf, $end-1, 1) eq $wday)) {
			$end--;
			$todaycount++;
a58 1
		$today{$file} = $todaycount;
@
