1 |
#!/usr/bin/perl |
2 |
|
3 |
use warnings; |
4 |
use strict; |
5 |
|
6 |
# create.pl |
7 |
# |
8 |
# 10/17/08 12:29:51 CEST Dobrica Pavlinusic <dpavlin@rot13.org> |
9 |
|
10 |
use GD::Graph::sparklines; |
11 |
use Data::Dump qw/dump/; |
12 |
use File::Slurp; |
13 |
|
14 |
my $data; |
15 |
|
16 |
my $max_month = 0; |
17 |
|
18 |
foreach my $file ( @ARGV ) { |
19 |
|
20 |
open(my $fh, '<', $file) or die "$file: $!"; |
21 |
|
22 |
my $type = $1 if ($file =~ /monthly-([^\.]+)/); |
23 |
|
24 |
while(<$fh>) { |
25 |
chomp; |
26 |
my ( $instance, $count, $month, $from, $to ) = split(/\t/,$_); |
27 |
|
28 |
if ( ! defined $data->{$instance} ) { |
29 |
$data->{$instance} = []; |
30 |
} |
31 |
|
32 |
$max_month = $month if $month > $max_month; |
33 |
|
34 |
$data->{$instance}->[ $month ] = $count; |
35 |
} |
36 |
|
37 |
warn dump( $data ), "\nmax_month: $max_month"; |
38 |
|
39 |
foreach my $instance ( keys %$data ) { |
40 |
|
41 |
my $graph = GD::Graph::sparklines->new(128, 16); |
42 |
my ( @x, @y ); |
43 |
foreach my $month ( 1 .. $max_month ) { |
44 |
push @x, $month; |
45 |
my $y = $data->{$instance}->[$month] || 0; |
46 |
push @y, $y; |
47 |
} |
48 |
warn "x = ",dump( @x ), "\ny = ", dump( @y ); |
49 |
my $gd = $graph->plot( [ \@x, \@y ] ) or die $graph->error; |
50 |
write_file( "s/$instance-$type.png", $gd->png ); |
51 |
} |
52 |
|
53 |
close($fh); |
54 |
} |