#! /usr/bin/perl -w # Copyright (c) 1998 Greg Bacon. All Rights Reserved. # This program is free software. You may distribute or # modify it under the terms of the Artistic License that # comes with the Perl Kit. use strict; use Date::Parse; use GIFgraph::bars; sub usage { "Usage: $0 \n" } ## main $0 =~ s!^.*/!!; my $dir = shift || die usage; opendir DIR, $dir or die "$0: failed opendir $dir: $!\n"; $/ = ""; my $oldest = $^T - 7 * 24 * 60 * 60; ## a week ago my @hour; my $total = 0; my $earliest = $^T; my $latest = 0; my $file; while (defined( $file = readdir DIR )) { next unless -f "$dir/$file"; unless (open FILE, "$dir/$file") { warn "$0: failed open $dir/$file: $!\n"; next; } my $head = ; $head =~ s/\n\s+/ /g; my($date) = $head =~ /^Date:\s*(.+)/im; unless ($date) { warn "$0: no Date: in $dir/$file\n"; next; } my $time = str2time $date; next if $time < $oldest; my $hour = ( gmtime($time) )[2]; $hour[$hour]++; $total++; $earliest = $time if $time < $earliest; $latest = $time if $time > $latest; } my $max = 0; for (@hour) { $max = $_ if $_ > $max; } $max += 25 - ( ($max % 25) || 0 ); my @tmp; @tmp = ( gmtime $earliest )[3,4,5]; $earliest = sprintf "%d/%02d/%02d", $tmp[2] + 1900, ++$tmp[1], $tmp[0]; @tmp = ( gmtime $latest )[3,4,5]; $latest = sprintf "%d/%02d/%02d", $tmp[2] + 1900, ++$tmp[1], $tmp[0]; my $graph = new GIFgraph::bars; $graph->set( x_label => 'Hour (UTC)', y_label => 'Frequency', title => "$total posts from $earliest to $latest", x_label_position => 1/2, y_max_value => $max, ); my @data = ( [ map { sprintf "%02d", $_ } 0 .. 23 ], [ @hour ], ); $graph->plot_to_gif("out.gif", \@data);