diff --git a/mozilla/webtools/webstats/addstats.pl b/mozilla/webtools/webstats/addstats.pl new file mode 100755 index 00000000000..ebc14d39fbc --- /dev/null +++ b/mozilla/webtools/webstats/addstats.pl @@ -0,0 +1,114 @@ +#!/usr/bonsaitools/bin/perl -w +# -*- Mode: perl; indent-tabs-mode: nil -*- +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# The Original Code is the Web Page Statistics Generator. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are Copyright (C) 1998 +# Netscape Communications Corporation. All Rights Reserved. +# +# Contributor(s): Terry Weissman + +use diagnostics; +use strict; + +use Mysql; +use Date::Format; +use Date::Parse; +require 'utils.pl'; + +# $F::debug = 1; + +$::db = Mysql->Connect("localhost", "webstats") + || die "Can't connect to database server"; + +$::db = $::db; # Make -w shut up. + +my $query = Query("select max(date) from stats"); +my @row = $query->fetchrow(); +my $maxdate = $row[0]; +if (!defined $maxdate) { + $maxdate = 0; +} + +my $lastdate = ""; + +my %ids; +my %counts; + + +sub Flush { + my $timeval = str2time($lastdate); + my $date = time2str("%Y-%m-%d", $timeval); + my $tick = 0; + foreach my $name (keys %counts) { + if ($tick++ % 100 == 0) { + print "+"; + } + my $id = $ids{$name}; + if (!defined $id) { + my $q = SqlQuote($name); + my $query = Query("select id from names where name = $q"); + my @row = $query->fetchrow(); + $id = $row[0]; + if (!defined $id) { + Query("insert into names (name) values ($q)"); + $query = Query("select LAST_INSERT_ID()"); + @row = $query->fetchrow(); + $id = $row[0]; + } + $ids{$name} = $id; + } + my $count = $counts{$name}; + my $query = + Query("select count from stats where id = $id and date = '$date'"); + my @row = $query->fetchrow(); + if (defined @row && defined $row[0]) { + $count += $row[0]; + Query("update stats set count=$count where id = $id and date = '$date'"); + } else { + Query("insert into stats (id, date, count) values ($id, '$date', $count)"); + } + } +} + + + + +my $tick = 0; +while () { + if ($tick++ % 100 == 0) { + print "."; + } + + chomp; + if (! m@\[(\d+)/(\w+)/(\d+):(\d+):(\d+):(\d+).*\].*GET (/\S+) HTTP@) { + next; + } + + my ($day,$month,$year,$hours,$mins,$secs,$name) = + ($1, $2, $3, $4, $5, $6, $7); + + my $date = "$month $day, $year"; + + if ($date ne $lastdate) { + Flush(); + $lastdate = $date; + } + $counts{$name}++; +} + +Flush(); + + + + diff --git a/mozilla/webtools/webstats/maketables.sh b/mozilla/webtools/webstats/maketables.sh new file mode 100755 index 00000000000..38afd5214a6 --- /dev/null +++ b/mozilla/webtools/webstats/maketables.sh @@ -0,0 +1,57 @@ +#!/bin/sh +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# The Original Code is the Web Page Statistics Generator. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are Copyright (C) 1998 +# Netscape Communications Corporation. All Rights Reserved. +# +# Contributor(s): Terry Weissman + +mysql > /dev/null 2>/dev/null << OK_ALL_DONE + +use webstats; + +drop table stats; +drop table names; + +OK_ALL_DONE + + + +mysql << OK_ALL_DONE + + + + +use webstats; + + +create table names ( + id smallint not null auto_increment primary key, + name varchar(255) not null, + + unique(name) +); + +create table stats ( + id smallint not null, + date date not null, + count mediumint not null, + + index(id), + index(date) +); + + +OK_ALL_DONE diff --git a/mozilla/webtools/webstats/utils.pl b/mozilla/webtools/webstats/utils.pl new file mode 100644 index 00000000000..ec4688b74cf --- /dev/null +++ b/mozilla/webtools/webstats/utils.pl @@ -0,0 +1,49 @@ +# -*- Mode: perl; indent-tabs-mode: nil -*- +# +# The contents of this file are subject to the Mozilla Public License +# Version 1.0 (the "License"); you may not use this file except in +# compliance with the License. You may obtain a copy of the License at +# http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS IS" +# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the +# License for the specific language governing rights and limitations +# under the License. +# +# The Original Code is the Web Page Statistics Generator. +# +# The Initial Developer of the Original Code is Netscape Communications +# Corporation. Portions created by Netscape are Copyright (C) 1998 +# Netscape Communications Corporation. All Rights Reserved. +# +# Contributor(s): Terry Weissman + +sub Query { + my ($qstr) = @_; + if ($F::debug) { + print $qstr . "
\n"; + } + return $main::db->query($qstr) || die "$qstr: $Mysql::db_errstr"; +} + + + +sub SqlQuote { + ($_) = (@_); + s/'/''/g; + s/\\/\\\\/g; + return "'$_'"; +} + +1; + + + +# Trim whitespace from front and back. + +sub trim { + ($_) = (@_); + s/^\s*//g; + s/\s*$//g; + return $_; +}