new issue
[andk-cpan-tools.git] / bin / time-series-20130113 / time-series-20130113.pl
blob921239faefec1bd6603850942dd458a30710ff82
1 =pod
3 The inspiration came from Brandon Byrd in the form of the topic
4 I<looking at CPAN's Health from a macro-level>
6 And then I said: the most interesting graph we came up with would be a
7 (x-axis: time, y-axis: number of pass/fail/unknown/na(stacked)). Let
8 me try. And this is the result.
10 I used the data I gather from log.txt on analysis and this explains
11 the interval of the chart: I have these data quickly accessible.
13 =cut
15 use strict;
16 use Chart::Clicker;
17 use Chart::Clicker::Axis::DateTime;
18 use Chart::Clicker::Data::Series;
19 use Chart::Clicker::Data::DataSet;
20 use DateTime::Format::Strptime;
21 use Chart::Clicker::Renderer::StackedArea;
23 # build the chart
24 my $chart = Chart::Clicker->new(width => 650, height => 400);
26 my $yfile = __FILE__;
27 $yfile =~ s/.pl$/.yaml/;
28 use YAML::Syck;
29 my $y = YAML::Syck::LoadFile $yfile;
30 my @X = sort keys %$y;
31 pop @X;
32 my $strp = DateTime::Format::Strptime->new
34 pattern => '%Y-%m-%d',
35 # locale => 'UTC',
36 time_zone => 'UTC',
37 on_error => 'croak',
39 my @Xepoch = map {
40 my $dt = $strp->parse_datetime($_);
41 $dt->epoch;
42 } @X;
44 my @series;
45 for my $state (qw(pass/10 fail unknown na)) {
46 my(@v);
47 if ($state =~ m!(.+)/(\d+)!) {
48 my($statename,$divisor) = ($1,$2);
49 @v = map {$y->{$_}{$statename}/$divisor} @X;
50 } else {
51 @v = map {$y->{$_}{$state}} @X;
53 push @series, Chart::Clicker::Data::Series->new
55 name => $state,
56 keys => \@Xepoch,
57 values => \@v,
60 # build the dataset
61 my $dataset = Chart::Clicker::Data::DataSet->new
63 series => \@series
66 # add the dataset to the chart
67 $chart->add_to_datasets($dataset);
68 my $def = $chart->get_context('default');
69 my $dtaxis = Chart::Clicker::Axis::DateTime->new
71 format => '%Y-%m-%d',
72 position => 'bottom',
73 orientation => 'horizontal'
75 $def->domain_axis($dtaxis);
76 my $yaxis = Chart::Clicker::Axis->new
78 format => "%s",
79 position => 'left',
80 orientation => 'vertical',
81 range => Chart::Clicker::Data::Range->new
83 lower => 0,
84 upper => 4000,
85 }),
87 $def->range_axis($yaxis);
89 my $title = "cpan health check";
90 $chart->title->text($title);
91 $chart->legend->visible(1);
92 # $chart->title->font->size(20);
94 # 1351728000,1354320000,1356998400
95 $def->domain_axis->tick_values([$Xepoch[0],grep {
96 my $dt = DateTime->from_epoch(epoch => $_);
97 $dt->day == 1;
98 } @Xepoch]);
100 my $area = Chart::Clicker::Renderer::StackedArea->new(opacity => .6);
101 $area->brush->width(3);
102 $def->renderer($area);
103 $def->renderer->additive(1);
105 # write the chart to a file
106 my($png) = __FILE__;
107 $png =~ s/\.pl$/.png/;
108 $chart->write_output($png);