From e46596cb8ba20e05300b676f536baa073df9d971 Mon Sep 17 00:00:00 2001 From: Peter Ward Date: Wed, 28 Oct 2009 18:28:15 +1100 Subject: Added reliable colours. --- stats.py | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 stats.py (limited to 'stats.py') diff --git a/stats.py b/stats.py new file mode 100644 index 0000000..cb1037a --- /dev/null +++ b/stats.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +from collections import defaultdict +from pygooglechart import SimpleLineChart +from colour import hash_colour + +WIDTH = 600 +HEIGHT = 200 +RESULTS_FILE = 'results.csv' + +def main(): + data = {} + order = [] + snakes = [] + for line in open(RESULTS_FILE): + 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_data = [] + time_data = [] + colours = [] + 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) + + colours.append('%2X%2X%2X' % hash_colour(name)) + + time_data.append(time_series) + length_data.append(length_series) + + for filename, data in (('length_chart.png', length_data), + ('time_chart.png', time_data)): + chart = SimpleLineChart(WIDTH, HEIGHT, colours=colours) + for series in data: + chart.add_data(series) + chart.download(filename) + + print 'Chart update!' + +if __name__ == '__main__': + main() + -- cgit v1.2.3