diff options
author | Peter Ward <peteraward@gmail.com> | 2009-11-12 10:27:10 +1100 |
---|---|---|
committer | Peter Ward <peteraward@gmail.com> | 2009-11-12 10:27:10 +1100 |
commit | 79a1077fb7b2b4b978e9dec687ea86b195a0c407 (patch) | |
tree | 80cbf3563b0637472e5a111d364ec903f9c4657a | |
parent | 62527ef65ec78124f97426ba1e7f44fafe1be134 (diff) |
Added average script.
-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 + |