From e6cff1b10089758d7560f305808f3c151ff1d93b Mon Sep 17 00:00:00 2001 From: Michael Tremer Date: Tue, 4 Jan 2011 17:12:55 +0100 Subject: [PATCH] Fix calculation of the network stats. --- www/templates/stasy-stats-network.html | 2 +- www/webapp/backend/stasy.py | 4 +++- www/webapp/ui_modules.py | 7 +++++-- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/www/templates/stasy-stats-network.html b/www/templates/stasy-stats-network.html index 83aa46f..9d389cf 100644 --- a/www/templates/stasy-stats-network.html +++ b/www/templates/stasy-stats-network.html @@ -7,6 +7,6 @@

This chart shows us which is the most favourite network configuration.

- {{ modules.StasyTable(network_zones, sortby="percentage") }}´ + {{ modules.StasyTable(network_zones, sortby="percentage", percentage=True) }} {% end block %} diff --git a/www/webapp/backend/stasy.py b/www/webapp/backend/stasy.py index a9ce4dd..6050163 100644 --- a/www/webapp/backend/stasy.py +++ b/www/webapp/backend/stasy.py @@ -632,10 +632,12 @@ class Stasy(object): def get_network_zones_map(self): zones = { "green" : 0, "blue" : 0, "orange" : 0, "red" : 0 } + all = self.query({ "profile.network" : { "$exists" : True }}) + for zone in zones.keys(): zones[zone] = self.query({ "profile.network.%s" % zone : True, - }).count() + }).count() / all.count() return zones diff --git a/www/webapp/ui_modules.py b/www/webapp/ui_modules.py index 2105385..a9d6aa9 100644 --- a/www/webapp/ui_modules.py +++ b/www/webapp/ui_modules.py @@ -141,7 +141,7 @@ class TrackerPeerListModule(UIModule): class StasyTableModule(UIModule): - def render(self, items, sortby="key", reverse=False): + def render(self, items, sortby="key", reverse=False, percentage=False): hundred_percent = 0 for v in items.values(): hundred_percent += v @@ -159,7 +159,10 @@ class StasyTableModule(UIModule): if hundred_percent: _items = [] for k in keys: - v = items[k] * 100 / hundred_percent + if not percentage: + v = items[k] * 100 / hundred_percent + else: + v = items[k] * 100 _items.append((k, v)) items = _items -- 2.39.2