/[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 28 by dpavlin, Mon Oct 20 18:59:48 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 30  foreach my $file ( @ARGV ) { Line 31  foreach my $file ( @ARGV ) {
31                  if ( ! defined $data->{$instance} ) {                  if ( ! defined $data->{$instance} ) {
32                          $data->{$instance} = [];                          $data->{$instance} = [];
33                          $json->{$instance}->{$type}->{sum} = 0;                          $json->{$instance}->{$type}->{sum} = 0;
34                          $json->{$instance}->{$type}->{min} = 0;  #                       $json->{$instance}->{$type}->{min} = 0;
35                          $json->{$instance}->{$type}->{max} = 0;  #                       $json->{$instance}->{$type}->{max} = 0;
36                  }                  }
37    
38                  $max_month = $month if $month > $max_month;                  $max_month = $month if $month > $max_month;
# 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 49  foreach my $file ( @ARGV ) { Line 50  foreach my $file ( @ARGV ) {
50                          push @x, $month;                          push @x, $month;
51                          my $y = $data->{$instance}->[$month] || 0;                          my $y = $data->{$instance}->[$month] || 0;
52                          push @y, $y;                          push @y, $y;
53                          $json->{$instance}->{$type}->{min} = $y if $json->{$instance}->{$type}->{min} > $y;  #                       $json->{$instance}->{$type}->{min} = $y if $json->{$instance}->{$type}->{min} > $y;
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                    visits_sum => 0,
75                    visits_anonymous_sum => 0,
76                    changes_sum => 0,
77                    categories_changed_sum => 0,
78                    unique_users_sum => 0,
79            };
80          foreach my $type ( keys %{ $json->{$instance} } ) {          foreach my $type ( keys %{ $json->{$instance} } ) {
81                  push @items, {                  foreach my $p ( keys %{ $json->{$instance}->{$type} } ) {
82                          id => $instance,                          my $val = $json->{$instance}->{$type}->{$p};
83                          label => $instance,                          $item->{ $type . '_' . $p } = $val;
84                          url => "http://www.$instance.skole.hr",                  }
                         %{ $json->{$instance}->{$type} },  
                 };  
85          }          }
86            push @items, $item;
87  }  }
88    
89  write_file( 'sparklines.js', to_json({ items => \@items }) );  #warn dump( @items );
90    
91    my $items_json = encode_json({
92            properties => {
93                    visits_sum => { valueType => 'number' },
94                    visits_anonymous_sum => { valueType => 'number' },
95                    changes_sum => { valueType => 'number' },
96                    categories_changed_sum => { valueType => 'number' },
97                    unique_users_sum => { valueType => 'number' },
98            },
99            items => [ @items ]
100    });
101    #$items_json =~ s/(_sum":)"(\d+)"/$1$2/gs;
102    write_file( 'sparklines.js', $items_json );
103    

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

  ViewVC Help
Powered by ViewVC 1.1.26