I reworked your code to allow for any time periods (15mins, 30mins, 60mins, ...)

Chris

#!/usr/bin/perl use strict; use warnings; use Data::Dumper; my $interval = shift || 60; my %hash; while( <DATA> ) { 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 }

In reply to Re^2: ASCII chart that displays jobs that are running and jobs that are queued for a day by Cristoforo
in thread ASCII chart that displays jobs that are running and jobs that are queued for a day by wishartz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.