[t/spec] Rewrite a bunch more series test into modern form. Also shorten and make...
[pugs.git] / util / svnlog2graph.pl
blobcc21ed05e24597ccbb3904a77c32373dd2824012
1 #!/usr/bin/perl
2 # Creates a statistic of Pugs' development.
3 # Usage: svn log | util/svnlog2graph.pl > /tmp/graph.png --or
4 # svn log > /tmp/log; util/svnlog2graph /tmp/log > /tmp/graph.png
6 use warnings;
7 use strict;
9 use GD::Graph::lines;
10 use Time::Piece;
11 use Time::Seconds;
13 local $_;
14 my $num_commits;
15 my @commits;
16 my @developers;
17 my %devs_seen;
19 print STDERR <<INFO unless @ARGV;
20 Pipe output of "svn log" or save "svn log" output in a file and
21 specify this file as parameter.
22 Output will go to STDOUT in PNG format.
23 INFO
25 # Read the logfile
26 while(<>) {
27 # Only process headlines
28 next unless m/^r/ and m/lines?$/ and m/\|/;
29 my ($dev, $date) = (split / \| /)[1, 2];
30 $date =~ s/ [+-]\d+ \(.*$//;
32 # Example: $date is now "2005-02-06 17:52:06"
33 my $time = Time::Piece->strptime($date, "%Y-%m-%d %H:%M:%S");
34 push @commits, $time;
35 push @developers, $time unless $devs_seen{$dev}++;
36 $num_commits++;
39 # $commits[0] should be first commit, not last
40 @commits = reverse @commits;
41 @developers = reverse @developers;
43 # Collect commits in days
44 # E.g. $commits_till_day[42] = 1500 (1500 commits from day 1 to day 42)
45 my @commits_till_day = dayify(@commits);
46 my @devs_till_day = dayify(@developers);
47 # @devs_till_day should have the same length as @commits_till_day --
48 # fill if needed
49 push @devs_till_day, $devs_till_day[-1] while
50 @devs_till_day < @commits_till_day;
52 # Create the graph.
53 my $graph = GD::Graph::lines->new(500, 350);
54 $graph->set(
55 title => "Pugs development",
56 x_label => "Days",
57 y_label => "Commits/Developers",
58 x_label_skip => 10,
59 y_max_value => (int(@commits / 500) + 1) * 500,
60 ) or die $graph->error;
62 my @data = (
63 [ 0..@commits_till_day ], # Day#
64 [ 0, @commits_till_day ], # Commits
65 [ 0, map { 50 * $_ } @devs_till_day ], # Developers (scaled)
68 my $gd = $graph->plot(\@data) or die $graph->error;
69 binmode STDOUT;
70 print $gd->png;
72 # Input: (2, 5, 9, 86400+17, 2*86400+35, 4*86400+50)
73 # Output: (3, 4, 5, 5, 6)
74 sub dayify {
75 my @till_day;
77 for(@_) {
78 my $cur_day = int(($_ - $_[0]) / ONE_DAY);
80 if($cur_day != $#till_day) {
81 push @till_day, $till_day[-1] || 0
82 while $#till_day < $cur_day;
83 } else {
84 $till_day[-1]++;
88 return @till_day;