diff options
author | Peter Ward <peteraward@gmail.com> | 2009-10-28 18:08:47 +1100 |
---|---|---|
committer | Peter Ward <peteraward@gmail.com> | 2009-10-28 18:08:47 +1100 |
commit | 16651873f1cc0be9134d00334e9337d09fec2ead (patch) | |
tree | 48e81d9c545f84f230059dec6d6cb27d0d8e876a /stats/stats.py | |
parent | 98412e53d4de308efbf91648f54d3150091f0213 (diff) |
Added statistics generation code.
Diffstat (limited to 'stats/stats.py')
-rw-r--r-- | stats/stats.py | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/stats/stats.py b/stats/stats.py new file mode 100644 index 0000000..6eada02 --- /dev/null +++ b/stats/stats.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python + +from pygooglechart import SimpleLineChart +from collections import defaultdict + +WIDTH = 600 +HEIGHT = 200 + +def main(): + data = {} + order = [] + snakes = [] + for line in open('../results.csv'): + game_id, name, length, life = line[:-1].split(',') + game_id = int(game_id) + length = int(length) + life = float(life) + + if name not in data: + snakes.append(name) + data[name] = {} + + if game_id not in order: + order.append(game_id) + + data[name][game_id] = (length, life) + + length_chart = SimpleLineChart(WIDTH, HEIGHT) + time_chart = SimpleLineChart(WIDTH, HEIGHT) + + for name in snakes: + time_series = [] + length_series = [] + + for game_id in order: + length, time = data[name].get(game_id, (None, None)) + time_series.append(time) + length_series.append(length) + + time_chart.add_data(time_series) + length_chart.add_data(length_series) + + length_chart.download('length_chart.png') + time_chart.download('time_chart.png') + + print 'Chart update!' + +if __name__ == '__main__': + main() + |