12 |
use File::Slurp; |
use File::Slurp; |
13 |
use JSON; |
use JSON; |
14 |
|
|
15 |
my $json; |
my $debug = 0; |
16 |
|
|
17 |
|
my $json; |
18 |
my $max_month = 0; |
my $max_month = 0; |
19 |
|
|
20 |
foreach my $file ( @ARGV ) { |
foreach my $file ( @ARGV ) { |
40 |
$data->{$instance}->[ $month ] = $count; |
$data->{$instance}->[ $month ] = $count; |
41 |
} |
} |
42 |
|
|
43 |
warn dump( $data ), "\nmax_month: $max_month"; |
warn dump( $data ), "\nmax_month: $max_month" if $debug; |
44 |
|
|
45 |
foreach my $instance ( keys %$data ) { |
foreach my $instance ( keys %$data ) { |
46 |
|
|
54 |
$json->{$instance}->{$type}->{max} = $y if $json->{$instance}->{$type}->{max} < $y; |
$json->{$instance}->{$type}->{max} = $y if $json->{$instance}->{$type}->{max} < $y; |
55 |
$json->{$instance}->{$type}->{sum} += $y; |
$json->{$instance}->{$type}->{sum} += $y; |
56 |
} |
} |
57 |
warn "x = ",dump( @x ), "\ny = ", dump( @y ); |
warn "x = ",dump( @x ), "\ny = ", dump( @y ) if $debug; |
58 |
my $gd = $graph->plot( [ \@x, \@y ] ) or die $graph->error; |
my $gd = $graph->plot( [ \@x, \@y ] ) or die $graph->error; |
59 |
my $path = "s/$instance-$type.png"; |
my $path = "s/$instance-$type.png"; |
60 |
write_file( $path, $gd->png ); |
write_file( $path, $gd->png ); |
64 |
close($fh); |
close($fh); |
65 |
} |
} |
66 |
|
|
67 |
warn "# json = ",dump( $json ); |
warn "# json = ",dump( $json ) if $debug; |
68 |
my @items; |
my @items; |
69 |
foreach my $instance ( keys %$json ) { |
foreach my $instance ( keys %$json ) { |
70 |
|
my $item = { |
71 |
|
id => $instance, |
72 |
|
label => $instance, |
73 |
|
uri => "http://www.$instance.skole.hr", |
74 |
|
}; |
75 |
foreach my $type ( keys %{ $json->{$instance} } ) { |
foreach my $type ( keys %{ $json->{$instance} } ) { |
76 |
push @items, { |
foreach my $p ( keys %{ $json->{$instance}->{$type} } ) { |
77 |
id => $instance, |
$item->{ $type . '_' . $p } = $json->{$instance}->{$type}->{$p}; |
78 |
label => $instance, |
} |
|
url => "http://www.$instance.skole.hr", |
|
|
%{ $json->{$instance}->{$type} }, |
|
|
}; |
|
79 |
} |
} |
80 |
|
push @items, $item; |
81 |
} |
} |
82 |
|
|
83 |
write_file( 'sparklines.js', to_json({ items => \@items }) ); |
write_file( 'sparklines.js', to_json({ items => \@items }) ); |