#!/usr/bin/perl -w

my %sizes = (
    raw => {
	full => 2.3458,
	lossy => 0.3089,
	goto_compressed => 2.3458,
	goto_lossy => 2.64,
	keep => 2.3458,
	roc => 1.1729
    },
    chip => {
	full => 2.3811,
	cleaned => 0.0350,
	error_cleaned => 0.0350,
	goto_cleaned => 2.3811,
	new => 0.0,
	drop => 0.0,
	purged => 0.0350,
	scrubbed => 0.0350,
	update => 2.3811,
#	wait.for.now => 0.0
    },
    chip_lies => {
	full => 0.0350,
	new => 0.0,
	cleaned => 0.0350,
    },
    cam => {
	full => 0.2824,
	cleaned => 0.2824,
	drop => 0.0,
	error_cleaned => 0.2824,
	goto_cleaned => 0.2824,
	goto_purged => 0.2824,
	new => 0.0,
	purged => 0.0,
	update => 0.2824,
	wait => 0.0
    },
    warp => {
	full => 3.1354,
	cleaned => 0.0339,
	drop => 0.0339,
	keep => 3.1354,
	error_cleaned => 3.1354,
	goto_purged => 3.1354,
	new => 0.0,
	purged => 0.0339,
	scrubbed => 0.0339,
	update => 0.0339
    },
    warp_lies => {
	full => 0.0339,
	drop => 0.0339,
	new => 0.0
    },
    diff => {
	full => 8.0601,
	cleaned => 0.0964,
	drop => 0.0964,
	error_cleaned => 8.0601,
	goto_cleaned => 8.0601,
	goto_purged => 8.0601,
	new => 0.0,
	purged => 0.0964,
	update => 0.0964,
	wait => 0.0
    },
    diff_lies => {
	full => 0.0964,
	cleaned => 0.0964
    },
    stack => {
	# Old full value = 0.5015.  New value from 10k samples = 0.2748
	full => 0.2748,
	cleaned => 0.0028,
	drop => 0.0028,
	error_cleaned => 0.2748,
	error_purged => 0.2748,
	error_scrubbed => 0.2748,
	goto_cleaned => 0.2748,
	goto_purged => 0.2748,
	goto_scrubbed => 0.2748,
	new => 0.0,
	purged => 0.0028,
	scrubbed => 0.0028,
	wait => 0.0
    },
    ssky => {
	full => 0.2824/8,
	drop => 0.2824/8,
	new => 0.0,
	update => 0.2824/8,
	wait => 0.0
    },
    skycal => {
	full => 0.2824/40,
	goto_cleaned => 0.2824/40,
	drop => 0.2824/40,
	new => 0.0,
	update => 0.2824/40,
	wait => 0.0
    },
    ff => {
	full => 0.2824/3,
	drop => 0.2824/3,
	new => 0.0,
    }
    );
    

%sums = ();
%counts_full = ();
%counts_total = ();

foreach my $stage_name ('raw','chip','chip_lies','cam','warp','warp_lies','diff','diff_lies','stack','ssky','skycal','ff') {
    $sums{$stage_name} = 0;
    $counts_full{$stage_name} = 0;
    $counts_total{$stage_name} = 0;
}

while (<>) {
    chomp;

    my ($stage_name,$count,$state) = split /\s+/;
    if ($stage_name eq 'stage_name') { next; }
    my $z = $sizes{$stage_name}{$state};
    unless (defined($z)) {
#	print "Skipping undefined: $stage_name $state\n";
	next;
    }
    
    $sums{$stage_name} += $count * $z;
    if ($state eq 'full') {
	$counts_full{$stage_name} += $count;
    }
    $counts_total{$stage_name} += $count;

    $sum_total += $count * $z;
}

foreach my $stage_name ('raw','chip','chip_lies','cam','warp','warp_lies','diff','diff_lies','stack','ssky','skycal','ff') {
    printf("%10s  %8d  %8d  %1.4e\n",
	   $stage_name,$counts_full{$stage_name},$counts_total{$stage_name},$sums{$stage_name});
}
printf("%10s  %8s  %8s  %1.4e\n",
       "total","","",$sum_total);
printf("%10s  %8s  %8s  %1.4e\n",
       "dvo?","","",4.5e5);
my $neb;
chomp($neb = `neb-df | grep '/total'`);
$neb_size = (split /\s+/,$neb)[2];
printf("%10s  %8s  %8s  %1.4e\n",
       "nebulous","","",$neb_size / 1024 / 1024);
