/[simile]/sparklines/create.pl
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /sparklines/create.pl

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 21 by dpavlin, Fri Oct 17 11:16:24 2008 UTC revision 23 by dpavlin, Fri Oct 17 11:32:35 2008 UTC
# Line 12  use Data::Dump qw/dump/; Line 12  use Data::Dump qw/dump/;
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 ) {
# Line 39  foreach my $file ( @ARGV ) { Line 40  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    
# Line 53  foreach my $file ( @ARGV ) { Line 54  foreach my $file ( @ARGV ) {
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 );
# Line 63  foreach my $file ( @ARGV ) { Line 64  foreach my $file ( @ARGV ) {
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 }) );

Legend:
Removed from v.21  
changed lines
  Added in v.23

  ViewVC Help
Powered by ViewVC 1.1.26