Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add a tool that prints per-channel statts

  • Loading branch information...
commit 80824a7bfaab24f7d5b2c1b16235d7465fd7d0d6 1 parent 7def9ac
@moritz authored
Showing with 39 additions and 0 deletions.
  1. +39 −0 tools/stats.pl
View
39 tools/stats.pl
@@ -0,0 +1,39 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use Date::Simple qw/date today/;
+use 5.010;
+
+my $channel = shift // '#perl6';
+$channel =~ s/^(?!#)/#/;
+
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use IrcLog qw/get_dbh/;
+my $dbh = get_dbh;
+my $from_month;
+my $prev_count = 0;
+{
+ my $sth = $dbh->prepare('SELECT MIN(day) FROM irclog');
+ $sth->execute;
+ my ($month) = $sth->fetchrow_array;
+ $sth->finish;
+ ($from_month) = $month =~ /(\d{4}-\d{2})/;
+ $from_month = date("$from_month-01");
+}
+my $to_month = next_month($from_month);
+my $sth = $dbh->prepare('SELECT COUNT(*) FROM irclog WHERE day >= ? AND day < ? AND channel = ?');
+while ($from_month < today()) {
+ $sth->execute($from_month, $to_month, $channel);
+ my ($count) = $sth->fetchrow_array;
+ say $from_month->format('%Y-%m'), ' ', $count;
+} continue {
+ ($from_month, $to_month) = ($to_month, next_month($to_month));
+}
+
+
+sub next_month {
+ my $d = shift;
+ my $next = $d + 31;
+ date($next->year, $next->month, 1);
+}
Please sign in to comment.
Something went wrong with that request. Please try again.