From: Michael Tremer Date: Thu, 1 Nov 2018 13:23:34 +0000 (+0000) Subject: fireinfo: List all countries in which IPFire is running X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=574a88c79a55c103bd3c764c523867b1e3c62876;p=ipfire.org.git fireinfo: List all countries in which IPFire is running Signed-off-by: Michael Tremer --- diff --git a/src/backend/fireinfo.py b/src/backend/fireinfo.py index 251c8845..e1a07e02 100644 --- a/src/backend/fireinfo.py +++ b/src/backend/fireinfo.py @@ -1803,7 +1803,7 @@ class Fireinfo(Object): if res: return res.count - def get_geo_location_map(self, when=None, minimum_percentage=1): + def get_geo_location_map(self, when=None, minimum_percentage=0): res = self.db.query("WITH profiles AS (SELECT fireinfo_profiles_at(%s) AS id) \ SELECT location, COUNT(location)::float / (SELECT COUNT(*) FROM profiles) AS count FROM profiles \ LEFT JOIN fireinfo_profiles_locations ON profiles.id = fireinfo_profiles_locations.profile_id \ @@ -1811,7 +1811,7 @@ class Fireinfo(Object): HAVING COUNT(location)::float / (SELECT COUNT(*) FROM profiles) >= %s ORDER BY count DESC", when, minimum_percentage) - return ((r.location, r.count) for r in res) + return list(((r.location, r.count) for r in res)) @property def cpu_vendors(self): diff --git a/src/templates/fireinfo/index.html b/src/templates/fireinfo/index.html index 216534f0..6de5656d 100644 --- a/src/templates/fireinfo/index.html +++ b/src/templates/fireinfo/index.html @@ -53,6 +53,39 @@
+
+
+
+

{{ _("Locations") }}

+ +
+ {% for country_code, percentage in locations %} + {% if percentage >= 0.01 %} +
+ + {{ format_country_name(country_code) }} +
+ +
+ {% module ProgressBar(percentage, "success") %} +
+ {% end %} + {% end %} +
+
+
+ +
+
+ + {{ _("IPFire is also running in these countries: %s") % locale.list(list((format_country_name(c) for c, p in locations if p < 0.01))) }} + +
+
+
+
+ +
@@ -92,7 +125,7 @@
-
+
diff --git a/src/web/__init__.py b/src/web/__init__.py index 2e337d5e..5821fccb 100644 --- a/src/web/__init__.py +++ b/src/web/__init__.py @@ -10,6 +10,7 @@ import tornado.options import tornado.web import ipfire +import ipfire.countries from .handlers import * @@ -47,6 +48,7 @@ class Application(tornado.web.Application): # UI Modules "ui_methods" : { + "format_country_name" : self.format_country_name, "format_month_name" : self.format_month_name, "format_phone_number" : self.format_phone_number, "format_phone_number_to_e164" : self.format_phone_number_to_e164, @@ -276,6 +278,9 @@ class Application(tornado.web.Application): logging.info("Successfully initialied application") + def format_country_name(self, handler, country_code): + return ipfire.countries.get_name(country_code) + def format_month_name(self, handler, month): _ = handler.locale.translate diff --git a/src/web/fireinfo.py b/src/web/fireinfo.py index 3fa99547..18fd07b4 100644 --- a/src/web/fireinfo.py +++ b/src/web/fireinfo.py @@ -166,6 +166,9 @@ class IndexHandler(BaseHandler): # Virtualization "hypervisors" : self.fireinfo.get_hypervisor_map(when=self.when), "virtual_ratio" : self.fireinfo.get_virtual_ratio(when=self.when), + + # Location + "locations" : self.fireinfo.get_geo_location_map(when=self.when), } # Cache for 1h