From: Michael Tremer Date: Tue, 4 Jan 2011 16:12:55 +0000 (+0100) Subject: Fix calculation of the network stats. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=e6cff1b10089758d7560f305808f3c151ff1d93b;p=ipfire.org.git Fix calculation of the network stats. --- diff --git a/www/templates/stasy-stats-network.html b/www/templates/stasy-stats-network.html index 83aa46fd..9d389cfa 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 a9ce4dd2..6050163e 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 2105385d..a9d6aa92 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