From 5b91b2732ed339a1c2559e06833cc4f1daec01ae Mon Sep 17 00:00:00 2001 From: Florian Jung Date: Tue, 25 Aug 2015 19:53:35 +0200 Subject: statistics --- main.py | 2 ++ stats.py | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/main.py b/main.py index 0cd9b30..c0e9a21 100644 --- a/main.py +++ b/main.py @@ -80,4 +80,6 @@ while gui.running: else: autorespawn_counter-=1 +stats.save("stats.pickle") + print("bye") diff --git a/stats.py b/stats.py index 9a745ab..aed7b42 100644 --- a/stats.py +++ b/stats.py @@ -1,4 +1,6 @@ import time +from collections import defaultdict +import pickle class Stats: def __init__(self,c): @@ -12,6 +14,10 @@ class Stats: self.cell_aggressivity = {} self.cell_split_frequency = {} self.cell_defensiveness = {} + + self.size_vs_speed = defaultdict(lambda : defaultdict(lambda : 0)) + self.size_vs_visible_window = defaultdict(lambda : []) + self.mass_vs_visible_window = defaultdict(lambda : []) def log_mass(self, mass): self.mass_history.append((time.time(), mass)) @@ -39,3 +45,31 @@ class Stats: def process_frame(self): self.log_pos(self.c.player.center) self.log_mass(self.c.player.total_mass) + + cells = self.c.world.cells.values() + own_cells = self.c.player.own_cells + + own_total_size = sum( map(lambda cell : cell.size, own_cells) ) + own_total_mass = sum( map(lambda cell : cell.mass, own_cells) ) + + n = 3 + for cell in filter(lambda cell : not cell.is_food and not cell.is_virus and not cell.is_ejected_mass, cells): + if hasattr(cell,'poslog') and len(cell.poslog) > n+1: + cellspeed = 0 + for i in range(1,n+1): + cellspeed += (cell.poslog[-i] - cell.poslog[-i-1]).len() / n + + cellspeed = int(cellspeed) + self.size_vs_speed[cell.size][cellspeed] += 1 + + visible_width = max( map(lambda cell : cell.pos.x - cell.size, cells) ) - min( map(lambda cell : cell.pos.x + cell.size, cells) ) + visible_height = max( map(lambda cell : cell.pos.y - cell.size, cells) ) - min( map(lambda cell : cell.pos.y + cell.size, cells) ) + + self.size_vs_visible_window[own_total_size].append((visible_width,visible_height)) + self.mass_vs_visible_window[own_total_mass].append((visible_width,visible_height)) + + def save(self,filename): + pickle.dump(self, open(filename,"wb")) + + def load(filename): + return pickle.load(open(filename,"rb")) -- cgit v1.2.3