diff options
author | Peter Ward <peteraward@gmail.com> | 2014-06-28 08:28:06 +1000 |
---|---|---|
committer | Peter Ward <peteraward@gmail.com> | 2014-06-28 08:28:06 +1000 |
commit | ef8545d1fcdfb8a52e3094bc2a92a1e3850a08b4 (patch) | |
tree | c72c5db269a81d2c0d6e97fa5cf1d4eba3fec1c1 | |
parent | fe9b989f1836499bb8fada3ea99476834d75a9dd (diff) | |
parent | 79a1077fb7b2b4b978e9dec687ea86b195a0c407 (diff) |
merged
-rw-r--r-- | average.py | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/average.py b/average.py new file mode 100644 index 0000000..01a98dc --- /dev/null +++ b/average.py @@ -0,0 +1,44 @@ +from collections import defaultdict +from itertools import imap as map +from operator import itemgetter + +RESULTS_FILE = 'results.csv' +results = defaultdict(list) + +for line in open(RESULTS_FILE, 'rU'): + game, name, length, time = line[:-1].split(',') + length = int(length) + time = int(time) + results[name].append((length, time)) + +def average(items): + s = 0.0 + l = 0 + for item in items: + s += item + l += 1 + return s / l + +lengths = [] +times = [] + +for name, series in results.items(): + length_average = average(map(itemgetter(0), series)) + lengths.append((length_average, name)) + time_average = average(map(itemgetter(1), series)) + times.append((time_average, name)) + +lengths.sort(reverse=True) +times.sort(reverse=True) + +print 'Lengths' +print '=======' +for length, name in lengths: + print name, length +print + +print 'Times' +print '=====' +for time, name in times: + print name, time + |