]> git.ipfire.org Git - ipfire.org.git/commitdiff
fireinfo: Show popular country on index page
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 Apr 2018 18:23:12 +0000 (20:23 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 26 Apr 2018 18:23:12 +0000 (20:23 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
templates/index.html
webapp/backend/fireinfo.py
webapp/handlers.py

index 61aab0a93b0dfd1e34d647ccedf656843b2476a7..3e33db0149c534e6cc8857e2c65fdba5d1e7f045 100644 (file)
                <div class="container">
                        <h2 class="display-2 text-center">Fire<strong>Info</strong> Statistics</h2>
                        
-                       <div class="row mb-6 mb-md-5 pb-lg-5 mb-lg-6">
+                       <div class="row mb-6 mb-md-5 pb-lg-5 mb-lg-6 justify-content-center">
                                <div class="col-6 col-md-3 mb-6 text-center">
                                        <p class="mb-0 mb-sm-3 fireinfo_cat">Latest Release</p>
                                        <h5 class="pb-5 fireinfo">{{ latest_release.name }}</h5>
                                                $('.r_circle').circleProgress({ value: {{ latest_release.penetration }}, size: 128, thickness: 4, animation: false, startAngle: -Math.PI / 2, fill: { color: ["#1976d2"] } });
                                        </script>
                                </div>
-                               
-                               <div class="col-6 col-md-3 mb-6 text-center">
-                                       <p class="mb-0 mb-sm-3 fireinfo_cat">Favorite Kernel</p>
-                                       <h5 class="pb-5 fireinfo truncate">3.14.79-ipfire-pae</h5>
-                                       <div class="f_circle circle mt-5">
-                                               <p class="fireinfo_per">36%</p>
-                                       </div>
-                                       <script>
-                                               $('.f_circle').circleProgress({ value: 0.36, size: 128, thickness: 4, animation: false, startAngle: -Math.PI / 2, fill: { color: ["#00bcd4"] } });
-                                       </script>       
-                               </div>
-                               
-                               <div class="col-6 col-md-3 text-center">
-                                       <p class="mb-0 mb-sm-3 fireinfo_cat">Favorite CPU</p>
-                                       <h5 class="pb-5 fireinfo">Intel</h5>
-                                       <div class="c_circle circle mt-5">
-                                               <p class="fireinfo_per">73%</p>
-                                       </div>
-                                       <script>
-                                               $('.c_circle').circleProgress({ value: 0.73, size: 128, thickness: 4, animation: false, startAngle: -Math.PI / 2, fill: { color: ["#43a047"] } });
-                                       </script>       
-                               </div>
-                               
-                               <div class="col-6 col-md-3 text-center">
-                                       <p class="mb-0 mb-sm-3 fireinfo_cat truncate">Favorite Virtualisation</p>
-                                       <h5 class="pb-5 fireinfo">VMWare</h5>
-                                       <div class="v_circle circle mt-5">
-                                               <p class="fireinfo_per">46%</p>
-                                       </div>
-                                       <script>
-                                               $('.v_circle').circleProgress({ value: 0.46, size: 128, thickness: 4, animation: false, startAngle: -Math.PI / 2, fill: { color: ["#ff8f00"] } });
-                                       </script>       
-                               </div>
+
+                               {% if fireinfo_country %}
+                                       <div class="col-6 col-md-3 text-center">
+                                               <p class="mb-0 mb-sm-3 fireinfo_cat truncate">
+                                                       {{ _("%.0f%% of all IPFire systems are running in") % (fireinfo_country.percentage * 100) }}
+                                               </p>
+                                               <h5 class="pb-5 fireinfo">{{ fireinfo_country.country.name }}</h5>
+                                               <div class="v_circle circle mt-5">
+                                                       <p class="fireinfo_per">{{ "%.0f%%" % (fireinfo_country.percentage * 100) }}</p>
+                                               </div>
+                                               <script>
+                                                       $('.v_circle').circleProgress({ value: {{ fireinfo_country.percentage }}, size: 128, thickness: 4, animation: false, startAngle: -Math.PI / 2, fill: { color: ["#ff8f00"] } });
+                                               </script>
+                                       </div>
+                               {% end %}
                        </div>
                        
                        <div class="row justify-content-center">
index dff7e75c5f5cd8b5706e1c41bcf1573f4ad6427a..bff06689b4abc798e38a1a29438a926419d25f45 100644 (file)
@@ -4,9 +4,11 @@ from __future__ import division
 
 import datetime
 import hwdata
+import iso3166
 import logging
 import re
 
+import database
 import util
 from misc import Object
 
@@ -1693,6 +1695,16 @@ class Fireinfo(Object):
                if res:
                        return res.penetration
 
+       def get_random_country_penetration(self):
+               res = self.db.get("SELECT * FROM fireinfo_country_percentages \
+                       ORDER BY RANDOM() LIMIT 1")
+
+               if res:
+                       return database.Row({
+                               "country"    : iso3166.countries.get(res.location),
+                               "percentage" : res.count,
+                       })
+
        # Hypervisor
 
        def create_hypervisor(self, hypervisor):
index e8679f236e7e166dc7b9409751632af1c98608e9..bfadf619295d114cf8a96d96f43943982f37cf7d 100644 (file)
@@ -54,7 +54,8 @@ class IndexHandler(BaseHandler):
                latest_news = self.get_latest_news()
 
                return self.render("index.html", latest_news=latest_news,
-                       latest_release=latest_release)
+                       latest_release=latest_release,
+                       fireinfo_country=self.fireinfo.get_random_country_penetration())
 
        def get_latest_news(self, count=5):
                latest_news = []