#!/usr/bin/perl
#
# Scrip que muestra en forma grafica la evolucion de los commits
#
# by Ricardo Markiewicz <rmarkie@fi.uba.ar>
#
# The PlaQui Development Team

my %hash, %users, %commits, %lines_count, $texto. $max;

if (shift eq "-d") {
	$texto = `svn log > ChangeLog`;
}
$texto = `egrep "rev [0-9]+" ChangeLog`;

@lines = split(/\n/, $texto);

$max = -1;
foreach $line (@lines) {
	@datos = split(/ /, $line);
	$hash{$datos[5]}++;
	$users{$datos[5]}{$datos[3]}++;
	$commits{$datos[3]}++;
	$lines_count{$datos[3]} += $datos[13];
	if ($hash{$datos[5]} > $max) {
		$max = $hash{$datos[5]};
	}
}

print "PlaQui - Grafica de Progreso SVN\n";
print "--------------------------------\n\n";
print "Fecha\t\tCommits\n";

foreach $date (sort keys %hash) {
	print "$date\t";
	
	$win = "";
	$win_pts = -1;
	foreach $name (keys %{$users{$date}}) {
		if ($users{$date}{$name} > $win_pts) {
			$win = $name;
			$win_pts = $users{$date}{$name};
		} else {
			if ($users{$date}{$name} == $win_pts) {
				$win = $win."|".$name;
			}
		}
	}

	for($i=0; $i<$max/2; $i++) {
		if ($i < $hash{$date}/2) {
			print "*";
		} else {
			print " ";
		}
	}
	print "  ($win)";
	print "\n";
}

print "\n";
print "Cantidad de commits por usuario:\n";
foreach $user (sort keys %commits) {
	print "\t$user\t$commits{$user}\t($lines_count{$user} lineas)\n";
}
print "\n";
print "( ) = Máximo/s Commiteador/es del Día | ";
print "* == 2 Commit\n";

