#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $interval = shift || 60; my %hash; while( ) { my( $name, @times ) = split; # convert the 3 times into their time slot. # (eg) if the interval is 60 minutes (1 hour) # a queued time of 9:26 would be converted to 9:00. $_ -= $_ % ($interval * 60) for @times; for (my $slot = $times[0]; $slot < $times[1]; $slot += $interval * 60) { $hash{ date($slot) }{ time_bin($slot) }{ $name }{queued}++; } for (my $slot = $times[1]; $slot < $times[2]; $slot += $interval * 60) { $hash{ date($slot) }{ time_bin($slot) }{ $name }{running}++; } } { DATE: foreach my $date ( sort keys %hash ) { print_header( $date ); my $hour_hash = $hash{ $date }; HOUR: foreach my $hour ( sort keys %$hour_hash ) { my $queue_hash = $hour_hash->{$hour}; my $string = ''; QUEUE: foreach my $queue ( sort keys %$queue_hash ) { $string .= sprintf " %6s %4d %4d\n", $queue, $queue_hash->{$queue}{'queued'}||0, $queue_hash->{$queue}{'running'}||0; } # add the hour last to avoid a special case substr( $string, 0, 5 ) = $hour; print $string, "-" x 54, "\n"; } } } sub time_bin { sprintf "%02d:%02d", (localtime( $_[0] ) )[2,1]; } sub date { my @times = localtime( $_[0] ); $times[5] += 1900; $times[4] += 1; # join on / and make two digits for easy sorting return join "/", map { sprintf "%02d", $_ } @times[3,4,5]; } sub print_header { print <<"HERE"; Date: $_[0] Time Queue Queued Running ------------------------------------------------------ HERE }