def average(stats):
    """ Compute the average of all values for the next structure:
        {peer1: {block1: value11, block2: value2}, peer2: {...}, ...}
    """
    total = 0
    count = 0
    for peer_stats in stats.itervalues():
        total += sum(peer_stats.itervalues())
        count += len(peer_stats)
    return total / count