From 3c7779dbf19a58061587378e5d8938ba87075e06 Mon Sep 17 00:00:00 2001 From: "Bradley M. Kuhn" Date: Wed, 31 Dec 2014 13:30:44 -0500 Subject: [PATCH] Support UNIQUE_TOTAL count, counting each IP once. --- feed-count.plx | 14 +++++++++----- oggcast-count.plx | 14 +++++++++----- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/feed-count.plx b/feed-count.plx index e33b1a8..9107479 100755 --- a/feed-count.plx +++ b/feed-count.plx @@ -1,5 +1,5 @@ #!/usr/bin/perl -# Copyright (C) 2011, Bradley M. Kuhn +# Copyright (C) 2011, 2014 Bradley M. Kuhn # # This program gives you software freedom; you can copy, modify, convey, # and/or redistribute it under the terms of the GNU General Public License @@ -31,15 +31,19 @@ while (<>) { $url =~ s/\s*\.(ogg|mp3)\s*$/.audio/i; # Treat ogg and mp3 downloads same. $url =~ s/\s*\/$$//; # Always remove trailing slash - $data{$url}{$ip} = 0 unless defined $data{$url}{$ip}; $data{$url}{__TOTAL__} = 0 unless defined $data{$url}{__TOTAL__}; - $data{$url}{$ip}++; $data{$url}{__TOTAL__}++; + + $data{$url}{__UNIQUE_TOTAL__} = 0 unless defined $data{$url}{__UNIQUE_TOTAL__}; + $data{$url}{__UNIQUE_TOTAL__}++ if not defined $data{$url}{$ip}; + + $data{$url}{$ip} = 0 unless defined $data{$url}{$ip}; + $data{$url}{$ip}++; } -foreach my $url (sort { $data{$b}{__TOTAL__} <=> $data{$a}{__TOTAL__}} +foreach my $url (sort { $data{$b}{__UNIQUE_TOTAL__} <=> $data{$a}{__UNIQUE_TOTAL__}} keys %data) { - print "$url: $data{$url}{__TOTAL__}\n"; + print "$url: $data{$url}{__UNIQUE_TOTAL__}\n"; } ############################################################################### # Local variables: diff --git a/oggcast-count.plx b/oggcast-count.plx index e33b1a8..5c0795b 100755 --- a/oggcast-count.plx +++ b/oggcast-count.plx @@ -1,5 +1,5 @@ #!/usr/bin/perl -# Copyright (C) 2011, Bradley M. Kuhn +# Copyright (C) 2011, 2014, Bradley M. Kuhn # # This program gives you software freedom; you can copy, modify, convey, # and/or redistribute it under the terms of the GNU General Public License @@ -31,15 +31,19 @@ while (<>) { $url =~ s/\s*\.(ogg|mp3)\s*$/.audio/i; # Treat ogg and mp3 downloads same. $url =~ s/\s*\/$$//; # Always remove trailing slash - $data{$url}{$ip} = 0 unless defined $data{$url}{$ip}; $data{$url}{__TOTAL__} = 0 unless defined $data{$url}{__TOTAL__}; - $data{$url}{$ip}++; $data{$url}{__TOTAL__}++; + + $data{$url}{__UNIQUE_TOTAL__} = 0 unless defined $data{$url}{__UNIQUE_TOTAL__}; + $data{$url}{__UNIQUE_TOTAL__}++ if not defined $data{$url}{$ip}; + + $data{$url}{$ip} = 0 unless defined $data{$url}{$ip}; + $data{$url}{$ip}++; } -foreach my $url (sort { $data{$b}{__TOTAL__} <=> $data{$a}{__TOTAL__}} +foreach my $url (sort { $data{$b}{__UNIQUE_TOTAL__} <=> $data{$a}{__UNIQUE_TOTAL__}} keys %data) { - print "$url: $data{$url}{__TOTAL__}\n"; + print "$url: $data{$url}{__UNIQUE_TOTAL__}\n"; } ############################################################################### # Local variables: