#!/usr/bin/perl -w

# Hacky code to turn derived data into a nice friendly chart.

# (Processes YAML files given as arguments.)

use strict;

use YAML;

my %count;

foreach (@ARGV) {
	my $doc = YAML::LoadFile($_) or die "Unable to load stats from $_: $!";

	# This can obviously be extended to aggregate instead of giving
	#  per-file results.

	my $s = $doc->{'stats'};

	while (my ($k, $v) = each%{$s}) {
		$count{$k} += $v;
	}
}

my @l;

while (my ($k, $v) = each %count) {
	push @l, [$v, $k];
}

@l = sort { $b->[0] <=> $a->[0] } @l;
if (@l > 30) {
	@l = @l[0..30];
}

foreach (@l) {
	print join(',', @{$_}),"\n";
}
