# -*- perl -*- ################################################################ # # AccessWatch HTML Table Generation Functions # Copyright 1994-1998 David G. Maher. All Rights Reserved. # ############################################################################### #-----------------------------------------------------------------------------# # AccessWatch function - PrintBarHoriz # Purpose : Prints a horizontal bar with width as specified by argument. #-----------------------------------------------------------------------------# sub PrintBarHoriz { my($pct) = $_[0]; my($colorbar) = $horizbar{$_[1]}; my($scale) = 1; $scale = ($pct*8)/log $pct + 1 if ($pct > 0); print "\"";", $scale); } #-----------------------------------------------------------------------------# # AccessWatch function - PrintBarVert # Purpose : Prints a vertical bar with height as specified by argument. #-----------------------------------------------------------------------------# sub PrintBarVert { my($pct, $max) = ($_[0], $_[1]); my($colorbar) = $vertbar{$_[2]}; my($width) = $_[3]; $width = 10 if !($width); my($scale) = 0; $scale = $pct / $max * 200 if $max; print "\"$pct\"", $scale); } sub byReverseNumber { $b <=> $a; } #-----------------------------------------------------------------------------# # AccessWatch function - PrintTableRefStats # Purpose : Prints appropriate table. #-----------------------------------------------------------------------------# sub PrintTableRefStats { if (! %refs) { print "

No reference information is available. Please see the FAQ for more information.

\n"; return; } my($ref, $page, $refsTotal, $count); my(@refOrder) = (); foreach (keys %refs) { my($refUrl) = $siteBaseURL; $refURL =~ s/^http:\/\///i; $refURL =~ s/^https:\/\///i; $refURL =~ s/^ftp:\/\///i; if ($_ =~ /$siteBaseURL\//i || $_ =~ /www\.$sitebaseURL/i) { delete $refs{$_}; } else { $refsTotal += $refs{$_}; } } my(@countOrderList) = sort { $b <=> $a } values %refs; my($refCount) = $maxRefsToList - 1; $refCount = $#countOrderList if ($maxRefsToList == -1 || ($maxRefsToList - 1) > $#countOrderList); while (@countOrderList) { while (local($tag, $value) = each %refs) { if ($countOrderList[0] == $value) { push (@refOrder, $tag); shift @countOrderList; } } } my(@favRefs) = @refOrder[0..$refCount]; my(@othRefs) = @refOrder[@favRefs..$#refOrder]; print < References

EOM ; foreach (@favRefs) { /(.*)~~~(.*)/; ($siteurl, $page) = ($1, $2); ($sitename = $siteurl) =~ s/^.*:\/\/([^\/]+)/$1/; $sitename =~ s/([^\/]+)(.*)/$1$2<\/FONT>/; $pct = sprintf("%3.1f", $refs{$_}/$refsTotal*100) if $refsTotal; $pct = "0.0" if ! $refsTotal; if (! $sample) { print < EOM ; } else { print < EOM ; } } # print "\n"; print "
Referring Site / Page % of total
$sitename
$page
$pct
$sitename
$page
$pct
"; # foreach (@othRefs) { # /(.*)~~~(.*)/; # ($siteurl, $page) = ($1, $2); # ($sitename = $siteurl) =~ s/^.*:\/\/([^\/]+)/$1/; # $sitename =~ s/([^\/]+)(.*)/$1$2<\/FONT>/; # print "$sitename "; # } # print "
\n"; } #-----------------------------------------------------------------------------# # AccessWatch function - PrintTableAgentStats # Purpose : Prints appropriate table. #-----------------------------------------------------------------------------# sub PrintTableAgentStats { my($agent, $agentsTotal, $hour, $browser, $count, %classes, %platforms); if (! %agents) { print "

No browser information is available. Please see the FAQ for more information.

\n"; return; } %classes = ('Netscape Navigator', 0, 'Microsoft Internet Explorer', 0, 'Other', 0 ); %platforms = ('Windows 95', 0, 'Windows 98', 0, 'Windows NT', 0, 'Windows 3.1 or lower', 0, 'Macintosh', 0, 'UNIX', 0, 'OS/2', 0, 'Other', 0 ); %netscapeversions; %ieversions; my(@countOrderList) = sort { $b <=> $a } values %agents; while (($agent, $count) = each %agents) { if ($agent =~ /MSIE (\S+)/) { $classes{'Microsoft Internet Explorer'} += $count; my($version); if ($1 =~ /(.*)\./) { $ieversions{"$1\.\*"} += $count; } } elsif ($agent =~ /Mozilla\/(\S+)/ && $agent !~ /compatible/) { $classes{'Netscape Navigator'} += $count; my($version); if ($1 =~ /(.*)\./) { $netscapeversions{"$1\.\*"} += $count; } } else { $classes{'Other'} += $count; } if ($agent =~ /Macintosh/i || $agent =~ /Mac_PowerPC/ || $agent =~ /Mac_PPC/) { $platforms{'Macintosh'} += $count; } elsif ($agent =~ /Windows 95/i || $agent =~ /Win95/i) { $platforms{'Windows 95'} += $count; } elsif ($agent =~ /Windows 98/i || $agent =~ /Win98/i) { $platforms{'Windows 98'} += $count; } elsif ($agent =~ /Win16/i || $agent =~ /Windows [321]/) { $platforms{'Windows 3.1 or lower'} += $count; } elsif ($agent =~ /Windows NT/i || $agent =~ /WinNT/i) { $platforms{'Windows NT'} += $count; } elsif ($agent =~ /UNIX/i || $agent =~ /X11/ || $agent =~ /Lynx/) { $platforms{'UNIX'} += $count; } elsif ($agent =~ /OS\/2/i || $agent =~ /OS2/) { $platforms{'OS/2'} += $count; } else { $platforms{'Other'} += $count; } $agentsTotal += $count; } my(@agentOrder) = (); my($agentCount) = $maxAgentsToList - 1; $agentCount = $#countOrderList if ($maxAgentsToList == -1 || ($maxAgentsToList - 1) > $#countOrderList); while (@countOrderList) { while (local($tag, $value) = each %agents) { if ($countOrderList[0] == $value) { push (@agentOrder, $tag); shift @countOrderList; } } } my(@favAgents) = @agentOrder[0..$agentCount]; my(@othAgents) = @agentOrder[@favAgents..$#agentOrder]; print < Browsers

EOM sub byclass { $classes{$b} <=> $classes{$a}; } my($class); foreach $class (sort byclass keys %classes) { $count = $classes{$class}; my($pct) = sprintf("%3.1f", $count/$agentsTotal*100) if $agentsTotal; $pct = "0.0" if ! $agentsTotal; print "\n"; if ($class eq "Netscape Navigator") { my(@pcts); print "\n"; } elsif ($class eq "Microsoft Internet Explorer") { my(@pcts); print "\n"; } } print <
Browser Class% of total
$class$pct
Versions
"; sub byns { $netscapeversions{$b} <=> $netscapeversions{$a}; } my($version); foreach $version (sort byns keys %netscapeversions) { $count = $netscapeversions{$version}; my($pct) = sprintf("%3.1f", $count/$agentsTotal*100) if $agentsTotal; $pct = "0.0" if ! $agentsTotal; if ($pct > 0) { print "$version
\n"; push (@pcts, $pct); } } print "
"; foreach (@pcts) { print "$_
\n"; } print "
Versions
"; sub byie { $ieversions{$b} <=> $ieversions{$a}; } my($version); foreach $version (sort byie keys %ieversions) { $count = $ieversions{$version}; my($pct) = sprintf("%3.1f", $count/$agentsTotal*100) if $agentsTotal; $pct = "0.0" if ! $agentsTotal; if ($pct > 0) { print "$version
\n"; push (@pcts, $pct); } } print "
"; foreach (@pcts) { print "$_
\n"; } print "
EOM sub byplatform { $platforms{$b} <=> $platforms{$a}; } my($platform); foreach $platform (sort byplatform keys %platforms) { $count = $platforms{$platform}; my($pct) = sprintf("%3.1f", $count/$agentsTotal*100) if $agentsTotal; $pct = "0.0" if ! $agentsTotal; print "\n"; } print <
Platforms% of total
$platform$pct

EOM foreach (@favAgents) { # print "$_ - $agents{$_} - $agentsTotal\n"; $pct = sprintf("%3.1f", $agents{$_}/$agentsTotal*100) if $agentsTotal; $pct = "0.0" if ! $agentsTotal; print < EOM } print "
Top $maxAgentsToList Browsers% of total
$_$pct
\n\n"; } #-----------------------------------------------------------------------------# # AccessWatch function - PrintTableDomainStats # Purpose : Prints table of domains, sorted by number of accesses. #-----------------------------------------------------------------------------# sub PrintTableDomainStats { print < Accesses by Domain

EOM my(@countOrderList) = sort byReverseNumber values %domains; my(@domainOrder) = (); my($domainCount) = $maxDomainsToList - 1; $domainCount = $#countOrderList if ($maxDomainsToList == -1 || ($maxDomainsToList - 1) > $#countOrderList); while (@countOrderList) { while (local($tag, $value) = (each %domains)) { if ($countOrderList[0] == $value) { push (@domainOrder, $tag); shift @countOrderList; } } } my(@favDomains) = @domainOrder[0..$domainCount]; my(@othDomains) = @domainOrder[@favDomains..$#domainOrder]; foreach (@favDomains) { my($Mdomain) = $_; my($Mcount) = $domains{$_}; $Mdomain =~ tr/[A-Z]/[a-z]/; print ""; my($description) = &DescribeDomain($Mdomain); print ""; print ""; $pct = 0.00; $pct = $Mcount / $stats{'visits'} * 100 if ($stats{'visits'} > 0); printf ("\n", $pct); print "\n"; } print "\n
DomainDescription Visits% of total
$Mdomain $description $Mcount %3.1f"; &PrintBarHoriz($pct,0); print "
Additionally, there were visits from the following domains:
  " if (@othDomains); my($andCount) = 0; foreach (@othDomains) { tr/[A-Z]/[a-z]/; my($description) = &DescribeDomain($_); if ($andCount != $#othDomains) { print "$description [$domains{$_}], "; } else { print "and $description [$domains{$_}]."; } $andCount++; } print "
\n"; } #-----------------------------------------------------------------------------# # AccessWatch function - PrintTableHostStats # Purpose : Prints table of hosts, sorted by number of accesses. #-----------------------------------------------------------------------------# sub PrintTableHostStats { print < Hosts - Common Visitors

EOM my(@countOrderList) = sort byReverseNumber values %hosts; my(@hostOrder) = (); my($hostCount) = $maxHostsToList - 1; $hostCount = $#countOrderList if ($maxHostsToList == -1 || ($maxHostsToList - 1) > $#countOrderList); while (@countOrderList) { while (local($tag, $value) = (each %hosts)) { if ($countOrderList[0] == $value) { push (@hostOrder, $tag); shift @countOrderList; } } } my(@favHosts) = @hostOrder[0..$hostCount]; foreach (@favHosts) { my($Mhost) = $_; my($Mcount) = $hosts{$_}; print ""; print ""; $pct = 0.00; $pct = $Mcount / $stats{'hits'} * 100 if ($stats{'hits'} > 0); printf ("\n", $pct); print "\n"; } print < EOM print "
Host AddressHits% of total
$Mhost $Mcount %3.2f"; &PrintBarHoriz($pct,0); print "
Access Details: A list of individual accesses, sorted by host
\n"; } #-----------------------------------------------------------------------------# # AccessWatch function - PrintTableRegionStats # Purpose : Prints table of regions, sorted by number of accesses. #-----------------------------------------------------------------------------# sub PrintTableRegionStats { @americas = ('Antigua and Barbuda', 'Argentina', 'Aruba', 'Brazil', 'Canada', 'Chile', 'Dominican Republic', 'Guam', 'Guatemala', 'Mexico', 'Paraguay', 'Peru', 'Philippines', 'Saint Lucia', 'Trinidad and Tobago', 'United States'); @asia = ('Bahrain', 'China', 'Hong Kong', 'Indonesia', 'Japan', 'Kazakhstan', 'Korea (South)', 'Malaysia', 'New Zealand (Aotearoa)', 'Singapore', 'Sri Lanka', 'Taiwan', 'Thailand', 'United Arab Emirates'); @europe = ('Andorra', 'Anguilla', 'Australia', 'Austria', 'Belgium', 'Croatia (Hrvatska)', 'Cyprus', 'Denmark', 'Estonia', 'Finland', 'France', 'Germany', 'Greece', 'Hungary', 'Iceland', 'Ireland', 'Italy', 'Latvia', 'Lithuania', 'Luxembourg', 'Malta', 'Netherlands', 'Norway', 'Poland', 'Portugal', 'Romania', 'Slovenia', 'Spain', 'Sweden', 'Switzerland', 'Turkey', 'Ukraine', 'United Kingdom', 'Yugoslavia'); @rimea = ('Czech Republic', 'Egypt', 'India', 'Israel', 'Jordan', 'Kuwait', 'Lebanon', 'Russian Federation', 'Slovak Republic', 'South Africa', 'USSR (former)'); @other = ('Old-style Arpanet', 'Non-profit organization', 'International', 'IP Address', 'Network'); my($country, $total, $grandtotal); my(%revdomains) = reverse %domains; print <


Hits by Region
EOM print "\n"; print "\n"; print "\n"; $total = 0; foreach $country (@americas) { $count = ($domains{(&DescribeDomain($country))} || 0); if ($country eq "United States") { $count += $domains{'edu'} + $domains{'com'} + $domains{'gov'} + $domains{'mil'}; } print "\n" if $count; $total += $count; } print "\n"; print "
Americas
Country Hits
$country$count
Total$total

\n"; print "\n"; print "\n"; print "\n"; $grandtotal += $total; $total = 0; foreach $country (@asia) { $count = ($domains{(&DescribeDomain($country))} || 0); print "\n" if $count; $total += $count; } print "\n"; print "
Asia / Pac
Country Hits
$country$count
Total$total

\n"; print "\n"; print "\n"; print "\n"; $grandtotal += $total; $total = 0; foreach $country (@europe) { $count = ($domains{(&DescribeDomain($country))} || 0); print "\n" if $count; $total += $count; } print "\n"; print "
Europe
Country Hits
$country$count
Total$total

\n"; print "\n"; print "\n"; print "\n"; $grandtotal += $total; $total = 0; foreach $country (@rimea) { $count = ($domains{(&DescribeDomain($country))} || 0); print "\n" if $count; $total += $count; } print "\n"; print "
RIMEA
Country Hits
$country$count
Total$total

\n"; print "\n"; print "\n"; print "\n"; $grandtotal += $total; $total = 0; foreach $country (@other) { $count = ($domains{(&DescribeDomain($country))} || 0); print "\n" if $count; $total += $count; } print "\n"; print "
Other
Country Hits
$country$count
Total$total

\n"; $grandtotal += $total; print "\n"; print "\n"; print "
Grand total$grandtotal
\n"; print "\n"; } #-----------------------------------------------------------------------------# # AccessWatch function - PrintTablePageStats # Purpose : Prints table of pages, sorted by number of accesses. #-----------------------------------------------------------------------------# sub PrintTablePageStats { # outputs a table of pages accessed, ranked in order of demand print < Page Demand

Of the $stats{'visits'} visitors in this time period, each traversed an average of $stats{'pages-visit'} pages and downloaded an average of $stats{'kbytes-visit'} kilobytes.

EOM my(@countOrderList) = sort byReverseNumber values %pages; my(@pageOrder) = (); my($pageCount) = $maxPagesToList - 1; $pageCount = $#countOrderList if ($maxPagesToList == -1 || ($maxPagesToList - 1) > $#countOrderList); while (@countOrderList) { while (local($tag, $value) = (each %pages)) { if ($countOrderList[0] == $value) { push (@pageOrder, $tag); shift @countOrderList; } } } my(@favPages) = @pageOrder[0..$pageCount]; foreach (@favPages) { my($Mpage) = $_; my($Mcount) = $pages{$_}; my($pct) = 0.00; $pct = $Mcount / $stats{'pages'} * 100 if ($stats{'pages'} > 0); if ($sample) { print ""; print "\n"; printf ("\n", $pct); print "\n"; } print "
Page LocationAccesses\% of total
"; } else { print "
"; } my($description) = &DescribePage($Mpage); print "$description $Mcount %3.2f"; &PrintBarHoriz($pct,0); print "
\n"; } #-----------------------------------------------------------------------------# # AccessWatch function - PrintTableHourlyStats # Purpose : Prints bar graph of accesses over the course of the current # day. Thanks very much to Paul Blackman for his work on # this function. #-----------------------------------------------------------------------------# sub PrintTableHourlyStats { my($hour, $pct); print < Hourly Statistics

EOM my($barwidth) = 10; foreach $hour ('00'..'23') { print ""; } print ""; foreach ('12', '1' .. '12', '1' .. '11') { print ""; } print <
"; if ($stats{'hours'}{$hour} > 0.9*$stats{'maxhouraccess'}){ &PrintBarVert($stats{'hours'}{$hour}, $stats{'maxhouraccess'}, 9, $barwidth); } elsif ($stats{'hours'}{$hour} > 0.8*$stats{'maxhouraccess'}){ &PrintBarVert($stats{'hours'}{$hour}, $stats{'maxhouraccess'}, 8, $barwidth); } elsif ($stats{'hours'}{$hour} > 0.7*$stats{'maxhouraccess'}){ &PrintBarVert($stats{'hours'}{$hour}, $stats{'maxhouraccess'}, 7, $barwidth); } elsif ($stats{'hours'}{$hour} > 0.6*$stats{'maxhouraccess'}){ &PrintBarVert($stats{'hours'}{$hour}, $stats{'maxhouraccess'}, 6, $barwidth); } elsif ($stats{'hours'}{$hour} > 0.5*$stats{'maxhouraccess'}){ &PrintBarVert($stats{'hours'}{$hour}, $stats{'maxhouraccess'}, 5, $barwidth); } elsif ($stats{'hours'}{$hour} > 0.4*$stats{'maxhouraccess'}){ &PrintBarVert($stats{'hours'}{$hour}, $stats{'maxhouraccess'}, 4, $barwidth); } elsif ($stats{'hours'}{$hour} > 0.3*$stats{'maxhouraccess'}){ &PrintBarVert($stats{'hours'}{$hour}, $stats{'maxhouraccess'}, 3, $barwidth); } elsif ($stats{'hours'}{$hour} > 0.2*$stats{'maxhouraccess'}){ &PrintBarVert($stats{'hours'}{$hour}, $stats{'maxhouraccess'}, 2, $barwidth); } elsif ($stats{'hours'}{$hour} > 0.1*$stats{'maxhouraccess'}){ &PrintBarVert($stats{'hours'}{$hour}, $stats{'maxhouraccess'}, 1, $barwidth); } elsif ($stats{'hours'}{$hour} > 0) { &PrintBarVert($stats{'hours'}{$hour}, $stats{'maxhouraccess'}, 0, $barwidth); } else { &PrintBarVert(0, $stats{'maxhouraccess'}, -1, $barwidth); } print "
$_
AM PM
Avg Hits/Hour$stats{'avghouraccess'}
Max Hits/Hour$stats{'maxhouraccess'}
Min Hits/Hour$stats{'minhouraccess'}
Avg Hits/Day$stats{'avgdayaccess'}

EOM foreach $pct (0..9) { $img = 9 - $pct; print "", (9 - $pct)*10); printf ("\n", (1 - $pct/10) * $stats{'maxhouraccess'}); } print "
\"\" > "; printf ("%d%%%d hits
\n"; print "

"; print "Hour\tHits\n"; foreach $hour ('00'..'23') { printf("$hour\t%.02f\n", $stats{'hours'}{$hour}); } print "
\n"; } #-----------------------------------------------------------------------------# # AccessWatch function - PrintTableMonthWeekStats # Purpose : Prints bar graph of weekly accesses over the course of the # month. #-----------------------------------------------------------------------------# sub PrintTableMonthWeekStats { my($week, $pct); print < Weeks - Average accesses per week

EOM my($barwidth) = 55; foreach $week (1 .. 5) { print "\n"; } print "\n\n"; print "\n"; foreach $week (1 .. 5) { my($weekcount) = $monthweekStats{$week}; $weekcount = 0 if $weekcount < 0; if ($week eq $computedStats{'maxweekaccess'}) { print "\n"; } else { print "\n"; } } print <
Accesses
$monthweekStats{($computedStats{'maxweekaccess'})}

.
.
.
"; &PrintBarVert($monthweekStats{$week}, $monthweekStats{($computedStats{'maxweekaccess'})}, 9, $barwidth); print "
0
Week:
$weekcount
$week
$weekcount
$week
Average Accesses/Week:$computedStats{'accessesPerWeek'}
Maximum Accesses/Week:$monthweekStats{($computedStats{'maxweekaccess'})} during week $computedStats{'maxweekaccess'}.
Minimum Accesses/Week:$monthweekStats{($computedStats{'minweekaccess'})} during week $computedStats{'minweekaccess'}.
EOM } #-----------------------------------------------------------------------------# # AccessWatch function - PrintTableMonthDayStats # Purpose : Prints bar graph of daily accesses over the course of the # month. #-----------------------------------------------------------------------------# sub PrintTableMonthDayStats { my($day, $pct); print < Months - Average hits per month

EOM my($barwidth) = 8; my($max) = $monthdayStats{($computedStats{'maxdayaccess'})}; foreach $day ('01' .. '31') { print "\n"; } print "\n\n"; print "\n"; foreach $day ('01' .. '31') { my($dayval) = $monthdayStats{$day}; $dayval = 0 if ($dayval < 0); $day = int($day); if ($day == $computerStats{'maxdayaccess'}) { print "\n"; } else { print "\n"; } } print <
Hits
$monthdayStats{($computedStats{'maxdayaccess'})}

.
.
.
"; if ($monthdayStats{$day} > 0.9 * $max) { &PrintBarVert($monthdayStats{$day}, $max, 9, $barwidth); } elsif ($monthdayStats{$day} > 0.8 * $max) { &PrintBarVert($monthdayStats{$day}, $max, 8, $barwidth); } elsif ($monthdayStats{$day} > 0.7 * $max) { &PrintBarVert($monthdayStats{$day}, $max, 7, $barwidth); } elsif ($monthdayStats{$day} > 0.6 * $max) { &PrintBarVert($monthdayStats{$day}, $max, 6, $barwidth); } elsif ($monthdayStats{$day} > 0.5 * $max) { &PrintBarVert($monthdayStats{$day}, $max, 5, $barwidth); } elsif ($monthdayStats{$day} > 0.4 * $max) { &PrintBarVert($monthdayStats{$day}, $max, 4, $barwidth); } elsif ($monthdayStats{$day} > 0.3 * $max) { &PrintBarVert($monthdayStats{$day}, $max, 3, $barwidth); } elsif ($monthdayStats{$day} > 0.2 * $max) { &PrintBarVert($monthdayStats{$day}, $max, 2, $barwidth); } elsif ($monthdayStats{$day} > 0.1 * $max) { &PrintBarVert($monthdayStats{$day}, $max, 1, $barwidth); } elsif ($monthdayStats{$day} > 0) { &PrintBarVert($monthdayStats{$day}, $max, 0, $barwidth); } else { &PrintBarVert(0, $max, -1, $barwidth); } print "
0
Day:
$day$day
Average Hits/Day:$computedStats{'accessesPerDay'}
Maximum Hits/Day:$monthdayStats{($computedStats{'maxdayaccess'})} on day $computedStats{'maxdayaccess'}.
Minimum Hits/Day:$monthdayStats{($computedStats{'mindayaccess'})} on day $computedStats{'mindayaccess'}.
EOM print "

\n

\n\n"; print "\n"; foreach $day ('01' .. '31') { my($dayval) = $monthdayStats{$day}; $dayval = 0 if ($dayval < 0); $day = int($day); print "\n"; } print "
Day Hits
$day$dayval
\n
\n"; } #-----------------------------------------------------------------------------# # AccessWatch function - PrintTableDayStats # Purpose : Prints bar graph of accesses by day. #-----------------------------------------------------------------------------# sub PrintTableDayStats { my($day, $pct); print < Daily Statistics

EOM my($barwidth) = 8; my($max) = $stats{'maxdayaccess'}; foreach $day (sort keys %{ $stats{'days'} }) { print "\n"; } print "\n\n"; print "\n"; foreach $day (sort keys %{ $stats{'days'} }) { my($dayval) = $stats{'days'}{$day}; $dayval = 0 if ($dayval < 0); $day =~ /(\d\d\d\d)(\d\d)(\d\d)/; $day = int($2) . '/' . int($3) if $2 && $3; if ($day == $computedStats{'maxdayaccess'}) { print "\n"; } else { print "\n"; } } print <
Hits
$stats{'maxdayaccess'}

.
.
.
"; if ($stats{'days'}{$day} > 0.9 * $max) { &PrintBarVert($stats{'days'}{$day}, $max, 9, $barwidth); } elsif ($stats{'days'}{$day} > 0.8 * $max) { &PrintBarVert($stats{'days'}{$day}, $max, 8, $barwidth); } elsif ($stats{'days'}{$day} > 0.7 * $max) { &PrintBarVert($stats{'days'}{$day}, $max, 7, $barwidth); } elsif ($stats{'days'}{$day} > 0.6 * $max) { &PrintBarVert($stats{'days'}{$day}, $max, 6, $barwidth); } elsif ($stats{'days'}{$day} > 0.5 * $max) { &PrintBarVert($stats{'days'}{$day}, $max, 5, $barwidth); } elsif ($stats{'days'}{$day} > 0.4 * $max) { &PrintBarVert($stats{'days'}{$day}, $max, 4, $barwidth); } elsif ($stats{'days'}{$day} > 0.3 * $max) { &PrintBarVert($stats{'days'}{$day}, $max, 3, $barwidth); } elsif ($stats{'days'}{$day} > 0.2 * $max) { &PrintBarVert($stats{'days'}{$day}, $max, 2, $barwidth); } elsif ($stats{'days'}{$day} > 0.1 * $max) { &PrintBarVert($stats{'days'}{$day}, $max, 1, $barwidth); } elsif ($stats{'days'}{$day} > 0) { &PrintBarVert($stats{'days'}{$day}, $max, 0, $barwidth); } else { &PrintBarVert(0, $max, -1, $barwidth); } print "
0
Day:
$day$day
Average Hits/Day:$stats{'avgdayaccess'}
Maximum Hits/Day:$stats{'maxdayaccess'} on day $stats{'maxday'}.
Minimum Hits/Day:$stats{'mindayaccess'} on day $stats{'minday'}.
EOM print "

\n

\n\n"; print "\n"; foreach $day (sort keys %{ $stats{'days'} }) { my($dayval) = $stats{'days'}{$day}; $dayval = 0 if ($dayval < 0); $day = int($day); print "\n"; } print "
Day Accesses
$day$dayval
\n
\n"; } #-----------------------------------------------------------------------------# # AccessWatch function - PrintTableSummaryStats # Purpose : Prints a table which contains general statistics. #-----------------------------------------------------------------------------# sub PrintTableSummaryStats { my($extra); if ($stats{'pages-visit'} < 1) { $extra = '

Note: A pages per visit average that is below 1 indicates a large number of non-HTML hits linked outside the site.'; } print < Summary

During this period, there were $stats{'pages'} accesses and $stats{'hits'} hits. Each vistor viewed an average of $stats{'pages-visit'} pages and downloaded $stats{'kbytes-visit'} kilobytes. Hosts visited $siteName an average of $stats{'visits-uniq'} times, for a total of $stats{'visits'} unique visits by $stats{'uniquehosts'} unique hosts.

There were $stats{'visits-hour'} visits per hour, and a sustained rate of $stats{'hits-hour'} hits per hour.

Of these visits, $stats{'intvisits'} ($stats{'intvisitspct'}\%) originated from $orgname, and $stats{'extvisits'} ($stats{'extvisitspct'}\%) were from outside networks.

$siteName served $stats{'mbytes'} megabytes of information during this time period. $extra

EOM print ""; print < EOM print ""; print < EOM print ""; print <
Count% of total
Accesses from $orgname $stats{'intaccesses'} $stats{'intaccessespct'}\%"; &PrintBarHoriz($stats{'intaccessespct'}/2,0); print "
Outside Accesses $stats{'extaccesses'} $stats{'extaccessespct'}\%"; &PrintBarHoriz($stats{'extaccessespct'}/2,0); print "
Total Accesses $stats{'pages'}100%"; &PrintBarHoriz(50,1); print "
Total hits on site $stats{'hits'}
EOM } #-----------------------------------------------------------------------------# # AccessWatch function - PrintTableDetailsStats # Purpose : Prints verbose table of statistics details. #-----------------------------------------------------------------------------# sub PrintTableDetailsStats { print <


Hosts by Subdomain
Count\tHost

EOM

    my($subdom, $count, %subdoms);
    while (($subdom, $count) = each %hosts) {
        $subdom =~ /([^\.]+)\.([^\.]+)$/i;
	$subdoms{"$1\.$2"} += $count;
    }

    my(@hostsAR) = sort byDomain (keys %subdoms);
    my($host);

    foreach $host (@hostsAR) {
	print "$subdoms{$host}\t$host\n";
    }		       
    print <
EOM

}	

#-----------------------------------------------------------------------------#
#  AccessWatch sort routine - byDomain
#    Purpose  : Sort subroutine for sorting an array by domain suffix.
#-----------------------------------------------------------------------------#
sub byDomain { 
    my($aHost) = "";
    my($bHost) = "";
    my(@aTemp, @bTemp) = ();
    if ($a =~ /[^0-9].*\.[^0-9].*/) { 
	@aTemp = reverse split(/\./, $a); 
	foreach (@aTemp) { $aHost .= $_ };
    }
    else {
	$aHost = "zzzzzzz".$a;
    }
    if ($b =~ /[^0-9].*\.[^0-9].*/) { 
	@bTemp = reverse split(/\./, $b);
	foreach (@bTemp) { $bHost .= $_ };
    }
    else {
	$bHost = "zzzzzzz".$b;
    }
    return ($aHost cmp $bHost);
}

#-----------------------------------------------------------------------------#



#-----------------------------------------------------------------------------#
#  AccessWatch function - DescribePage
#    Purpose  : Takes a virtual URL as a parameter, and returns a detailed
#                   description as specified in the page descriptions file 
#                   provided. Caches file into memory if used more than once.
#-----------------------------------------------------------------------------#
sub DescribePage {

    my($url) = $_[0];
    my($description) = $url;

    if (!(keys %pageDesc)) {
	open (DESC, "<$pagedescriptions") || return $url;
#	    die "Page Desc. Error: Couldn't open $pagedescriptions... $!";
	while () { 
	    /^(\S+)\s+\"(.*)\"$/;
	    $pageDesc{$1} = $2;
	}
	close(DESC);
    }
    if ($pageDesc{$url}) {
	$description = $pageDesc{$url};
    }

    if ($truncate && length($url) > $toolong && $description eq $url) {
        $description = reverse $url;
	while (length($description) > $toolong) { chop $description; }
	$description = "..." . reverse $description;
    }
    return $description;
}				


1;