Skip to content

Commit

Permalink
Generate a JSON file with activity graph data
Browse files Browse the repository at this point in the history
towards #52
  • Loading branch information
moritz committed Apr 16, 2017
1 parent d1b1fc0 commit 4514f9d
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions util/cron-graphs.pl
Expand Up @@ -7,6 +7,7 @@
use Ilbot::Config;
use Date::Simple qw/date/;
use Getopt::Long;
use JSON qw(encode_json);
use 5.010;

my $dir = config(www => 'static_path') . '/s/images/index/';
Expand Down Expand Up @@ -34,6 +35,8 @@
<$IN>;
};

my %channels;

for my $channel (@{ $backend->channels }) {
my $b = $backend->channel(channel => $channel);
my @counts;
Expand All @@ -43,6 +46,7 @@

# the last data point is probably wrong due to rounding:
pop @counts;
$channels{$channel} = \@counts;

(my $filename = $channel) =~ s/[^\w-]//g;
$filename = "$dir/$filename.png";
Expand All @@ -61,3 +65,10 @@
system('gnuplot', $gnu_file);
unlink $tmp_file, $gnu_file;
}

my $json_file = "$dir/plots.json";
open my $OUT, '>', $json_file
or die "Cannot open '$json_file' for writing: $!";
print { $OUT } encode_json({ channels => \%channels }), "\n";
close $OUT
or die "Cannot write to '$json_file': $!";

0 comments on commit 4514f9d

Please sign in to comment.