namazu-dev(ring)


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: (garbage) Development Power Graph



Kenji Suzuki <kenji@xxxxxxxxxxxxxxxx> wrote:

>以前高林さんがいっていた開発のパワーをグラフにするという
>話ですが、同じようなことをしている方がいました。

わはは。同じようなあほなことを考える人はいるものですね。:)


>http://yar-3.net/d/power.cgi
>http://yar-3.net/d/power_cgi.txt
>
>GD & gifgraphモジュール があれば結構簡単にできそうです。

changelog2graph を作りました。生成したグラフを 
<http://cl.aist-nara.ac.jp/~satoru-t/tmp/ChangeLog.png> に置
きました。

-- Satoru Takabayashi

#! /usr/bin/perl -w
#
# changelog2graph - a tool to graph ChangeLog file.
#
# Usage:
#
#   % changelog2graph ChangeLog > ChangeLog.png
#
# Copyright (C) 2000 Satoru Takabayashi <satoru-t@xxxxxxxxxxxxxxxxxx>
#     All rights reserved.
#     This is free software with ABSOLUTELY NO WARRANTY.
#
# You can redistribute it and/or modify it under the terms of 
# the GNU General Public License version 2.
#

use strict;
use PNGgraph::bars;
use Time::Local;

main();

sub main () {
    my %freqs = analyze_changelog();
    my $first_time = get_first_time(\%freqs);
    my $last_time  = get_last_time(\%freqs);
    my @data = generate_data(\%freqs, $first_time, $last_time);

    my $my_graph = new PNGgraph::bars(600,400);
    $my_graph->set( 
		    x_label       => 'Date',
		    y_label       => 'Changes',
		    title         => 'ChangeLog Graph',
		    x_label_skip  => int(@{$data[0]} / 8) + 1,
		    y_label_skip  => 2,
		    r_margin      => 40,
		    textclr       => "black",
		    );

    print $my_graph->plot(\@data);
}

sub analyze_changelog () {
    my %freqs = ();
    my $date  = undef;
    my $freq  = 0;
    while (<>) {
	next if /^\s*$/;
	chomp;

	if (/^([\d-]+)/) {
	    if (defined $date) {
		$freqs{$date} = $freq;
	    }
	    $date = $1;
	    $freq = 0;
	} elsif (/^\s+\*/) {
	    $freq++;
	}
    }
    $freqs{$date} = $freq;

    return %freqs;
}

sub get_first_time ($) {
    my ($freqs_ref) = @_;

    my $first_date = (sort keys %{$freqs_ref})[0];
    return date_to_time($first_date);
}

sub get_last_time ($) {
    my ($freqs_ref) = @_;

    my $last_date = (reverse sort keys %{$freqs_ref})[0];
    return date_to_time($last_date);
}

sub date_to_time ($) {
    my ($date) = @_;

    if ($date =~ /^(\d+)-(\d+)-(\d+)/) {
	my $year = $1;
	my $mon  = $2 - 1;
	my $day  = $3;
	return timelocal(0, 0, 0, $day, $mon, $year);
    } else {
	die "$date: invalid date format";
    }
}

sub generate_data ($$$) {
    my ($freqs_ref, $first_time, $last_time) = @_;

    my @dates = ();
    my @freqs = ();
    for (my $time = $first_time; $time <= $last_time; $time += 60 * 60 * 24) {
	my ($sec, $min, $hour, $mday, $mon, $year,
	    $wday, $yday, $isdst) = localtime($time);
	$year += 1900;
	$mon++;
	my $date = sprintf "%4d-%02d-%02d", $year, $mon, $mday;
	
	push @dates, $date;
	if (defined $freqs_ref->{$date}) {
	    push @freqs, $freqs_ref->{$date};
	} else {
	    push @freqs, 0;
	}
    }

    return ([ @dates ], [ @freqs ]);
}