--- sparklines/create.pl 2008/10/17 11:16:24 21 +++ sparklines/create.pl 2008/10/17 11:32:35 23 @@ -12,8 +12,9 @@ use File::Slurp; use JSON; -my $json; +my $debug = 0; +my $json; my $max_month = 0; foreach my $file ( @ARGV ) { @@ -39,7 +40,7 @@ $data->{$instance}->[ $month ] = $count; } - warn dump( $data ), "\nmax_month: $max_month"; + warn dump( $data ), "\nmax_month: $max_month" if $debug; foreach my $instance ( keys %$data ) { @@ -53,7 +54,7 @@ $json->{$instance}->{$type}->{max} = $y if $json->{$instance}->{$type}->{max} < $y; $json->{$instance}->{$type}->{sum} += $y; } - warn "x = ",dump( @x ), "\ny = ", dump( @y ); + warn "x = ",dump( @x ), "\ny = ", dump( @y ) if $debug; my $gd = $graph->plot( [ \@x, \@y ] ) or die $graph->error; my $path = "s/$instance-$type.png"; write_file( $path, $gd->png ); @@ -63,17 +64,20 @@ close($fh); } -warn "# json = ",dump( $json ); +warn "# json = ",dump( $json ) if $debug; my @items; foreach my $instance ( keys %$json ) { + my $item = { + id => $instance, + label => $instance, + uri => "http://www.$instance.skole.hr", + }; foreach my $type ( keys %{ $json->{$instance} } ) { - push @items, { - id => $instance, - label => $instance, - url => "http://www.$instance.skole.hr", - %{ $json->{$instance}->{$type} }, - }; + foreach my $p ( keys %{ $json->{$instance}->{$type} } ) { + $item->{ $type . '_' . $p } = $json->{$instance}->{$type}->{$p}; + } } + push @items, $item; } write_file( 'sparklines.js', to_json({ items => \@items }) );