1: #!/usr/bin/perl 2: use strict; 3: use warnings; 4: 5: print graph( @{[1..96]} ); 6: 7: ####################################################################### 8: ### give me an array of 96 integers that represent each of the 9: ### 15-minute intervals in 24 hours. I'll give you an ascii graph 10: ### (of, e.g., concurrent users?) 11: sub graph { 12: my( $i, $magic, $m, $p, $top, @g ) = ( 0, 20, 7, 96, 0, () ); 13: for (0..$p-1) { $top = $top > $_[$_] ? $top : $_[$_] } 14: my $s = $top > $magic ? ( $top / $magic ) : 1; ### calculate scale 15: for (0..$magic) { 16: $g[$_] = sprintf("%".($m-1)."d ",$_*$s) . ($_%5==0?'_':'.') x $p; 17: for $i (0..$p-1) { substr($g[$_],$i+$m,1) = '|' if $_[$i]/$s>$_ } } 18: join( "\n", reverse( @g ), ' Time: ' . '|^^^' x ( $p / 4 ), 19: ' ' x $m . "12am 1am 2am 3am 4am 5am 6am 7am 8am 9a 10a 11a " . 20: "12pm 1pm 2pm 3pm 4pm 5pm 6pm 7pm 8pm 9p 10p 11pm" ); 21: } # end sub graph 22: 23: __END__ 24: 96 ________________________________________________________________________________________________ 25: 91 ...........................................................................................||||| 26: 86 ......................................................................................|||||||||| 27: 81 .................................................................................||||||||||||||| 28: 76 ............................................................................|||||||||||||||||||| 29: 72 ________________________________________________________________________|||||||||||||||||||||||| 30: 67 ...................................................................||||||||||||||||||||||||||||| 31: 62 ..............................................................|||||||||||||||||||||||||||||||||| 32: 57 .........................................................||||||||||||||||||||||||||||||||||||||| 33: 52 ....................................................|||||||||||||||||||||||||||||||||||||||||||| 34: 48 ________________________________________________|||||||||||||||||||||||||||||||||||||||||||||||| 35: 43 ...........................................||||||||||||||||||||||||||||||||||||||||||||||||||||| 36: 38 ......................................|||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 37: 33 .................................||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 38: 28 ............................|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 39: 24 ________________________|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 40: 19 ...................||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 41: 14 ..............|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 42: 9 .........||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 43: 4 ....|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 44: 0 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| 45: Time: |^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^|^^^ 46: 12am 1am 2am 3am 4am 5am 6am 7am 8am 9a 10a 11a 12pm 1pm 2pm 3pm 4pm 5pm 6pm 7pm 8pm 9p 10p 11pm 47:
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: ascii graph
by Juerd (Abbot) on Mar 16, 2004 at 10:29 UTC | |
by bbaxter (Initiate) on Mar 16, 2004 at 17:34 UTC | |
by NateTut (Deacon) on May 12, 2009 at 16:31 UTC | |
Re: ascii graph
by NateTut (Deacon) on May 13, 2009 at 18:45 UTC |
Back to
Craft