]> git.ipfire.org Git - ipfire.org.git/commitdiff
fireinfo: Only list countries on start page when >= 1% usage
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 11 May 2018 20:35:30 +0000 (22:35 +0200)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 11 May 2018 20:35:30 +0000 (22:35 +0200)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
webapp/backend/fireinfo.py

index bff06689b4abc798e38a1a29438a926419d25f45..dd4aa506b6a16c1a7596578ebd60a26072cad9df 100644 (file)
@@ -1805,11 +1805,13 @@ class Fireinfo(Object):
                if res:
                        return res.count
 
-       def get_geo_location_map(self, when=None):
+       def get_geo_location_map(self, when=None, minimum_percentage=1):
                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 \
-                       WHERE fireinfo_profiles_locations.location IS NOT NULL GROUP BY location ORDER BY count DESC", when)
+                       WHERE fireinfo_profiles_locations.location IS NOT NULL GROUP BY location \
+                       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)