]> git.ipfire.org Git - ipfire.org.git/commitdiff
fireinfo: List all countries in which IPFire is running
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Nov 2018 13:23:34 +0000 (13:23 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 1 Nov 2018 13:23:34 +0000 (13:23 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/fireinfo.py
src/templates/fireinfo/index.html
src/web/__init__.py
src/web/fireinfo.py

index 251c8845c680e24cb4725615a06425280e08b799..e1a07e023e2118b154ba95dd89fdbb066467e50d 100644 (file)
@@ -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):
index 216534f0603ee4a4fe3d169614767cd75c39bd9a..6de5656d9042d6667c0cd0219211dc7446bb0025 100644 (file)
        </section>
 
        <section>
+               <div class="container">
+                       <div class="row">
+                               <div class="col-12">
+                                       <h4>{{ _("Locations") }}</h4>
+
+                                       <dl class="row">
+                                               {% for country_code, percentage in locations %}
+                                                       {% if percentage >= 0.01 %}
+                                                               <dt class="col-sm-6">
+                                                                       <span class="flag-icon flag-icon-{{ country_code.lower() }} small mr-1"></span>
+                                                                       {{ format_country_name(country_code) }}
+                                                               </dt>
+
+                                                               <dd class="col-sm-6">
+                                                                       {% module ProgressBar(percentage, "success") %}
+                                                               </dd>
+                                                       {% end %}
+                                               {% end %}
+                                       </dl>
+                               </div>
+                       </div>
+
+                       <div class="row">
+                               <div class="col-12">
+                                       <small>
+                                               {{ _("IPFire is also running in these countries: %s") % locale.list(list((format_country_name(c) for c, p in locations if p < 0.01))) }}
+                                       </small>
+                               </div>
+                       </div>
+               </div>
+       </section>
+
+       <section class="inverse">
                <div class="container">
                        <div class="row align-items-center">
                                <div class="col-12 col-md-6">
                </div>
        </section>
 
-       <section class="inverse">
+       <section>
                <div class="container">
                        <div class="row">
                                <div class="col-12 col-md-6 d-flex align-items-center text-md-right">
index 2e337d5eb87fa513ee551ec0840b7a693a4b2425..5821fccbc26ba484bdb790796fc4ec07176a5d23 100644 (file)
@@ -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
 
index 3fa99547391f7355316d75f8dd6a957550850dec..18fd07b437ccc23d5d29098e9edb48caaaffed7e 100644 (file)
@@ -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