From 115a12b958d9280e1d7ecb31b72614a8d9a550f7 Mon Sep 17 00:00:00 2001 From: "simon.kagstrom" Date: Thu, 25 Feb 2010 11:57:25 +0000 Subject: [PATCH] Generate statistics on current number of active and waiting players --- network-broker/network-broker | 8 ++++++-- network-broker/stats.py | 15 +++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/network-broker/network-broker b/network-broker/network-broker index 182e082..2ad0945 100755 --- a/network-broker/network-broker +++ b/network-broker/network-broker @@ -604,15 +604,16 @@ class Broker(SocketServer.UDPServer): def log_connection(self, who, country): stats.add_connection(who, country) + stats.update_peer_nr(len(self.waiting_peers), len(self.active_peers)) try: stats.save(self.stat_data) except Exception, e: - error_log("saving stats failed with %s" % str(e) ) + log_error("saving stats failed with %s" % str(e) ) try: stats.generate_html(self.stat_html) except Exception, e: - error_log("generating HTML failed with %s" % str(e) ) + log_error("generating HTML failed with %s" % str(e) ) def send_data(self, dst, data): self.socket.sendto(data, dst) @@ -672,6 +673,7 @@ class Broker(SocketServer.UDPServer): self.active_peers[ peer.addr ] = peer except Exception, e: log_error("Moving peer %s to active failed: %s" % (str(peer.addr), str(e))) + stats.update_peer_nr(len(self.waiting_peers), len(self.active_peers)) def remove_peer(self, peer): try: @@ -685,6 +687,8 @@ class Broker(SocketServer.UDPServer): del self.waiting_peers[peer.addr] self.data_store.remove_peer(peer) + stats.update_peer_nr(len(self.waiting_peers), len(self.active_peers)) + print "VOBB: ", len(self.waiting_peers), len(self.active_peers) except Exception, e: log_error("Could not remove %s (probably wrong version): %s" % (str(peer.addr), str(e))) diff --git a/network-broker/stats.py b/network-broker/stats.py index f4be0e4..38c28d7 100644 --- a/network-broker/stats.py +++ b/network-broker/stats.py @@ -6,12 +6,22 @@ class Container: self.total_connections = 0 self.country_count = {} self.last_10 = [] + self.nr_active = 0 + self.nr_waiting = 0 + + def set_nr_active(self, nr_active): + self.nr_active = nr_active + + def set_nr_waiting(self, nr_waiting): + self.nr_waiting = nr_waiting def copy_from_other(self, other): try: self.total_connections = other.total_connections self.country_count = other.country_count self.last_10 = other.last_10 + self.nr_active = other.nr_active + self.nr_waiting = other.nr_waiting except: pass @@ -41,6 +51,7 @@ class HtmlGenerator: outf.write("\n") outf.write("

Frodo-Wii network statistics

\n") outf.write("The total number of connections is %d

\n" % (self.container.total_connections)) + outf.write("There are currently %d players waiting for connections and %d players playing

\n" % (self.container.nr_waiting, self.container.nr_active)) outf.write("\n") outf.write("\n" % (len(self.container.last_10)) ) @@ -106,6 +117,10 @@ def load(filename): except: pass +def update_peer_nr(waiting, active): + g_stat.set_nr_waiting(waiting) + g_stat.set_nr_active(active) + def add_connection(who, country): g_stat.add_connection(who, country)

Last %d connections

 

Random connection screenshots