]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/backend/fireinfo.py
people: Show pending registrations
[ipfire.org.git] / src / backend / fireinfo.py
index 0fbbbc408d5a748be85de1b966fe52f7dacc25cc..a295ca6c9479622724b41ef7be58548fa7b7d5ba 100644 (file)
@@ -1,14 +1,12 @@
 #!/usr/bin/python
 
-
-
 import datetime
-import hwdata
 import iso3166
 import logging
 import re
 
 from . import database
+from . import hwdata
 from . import util
 from .misc import Object
 
@@ -149,11 +147,11 @@ class Processor(Object):
        def __str__(self):
                s = []
 
-               if not self.model_string.startswith(self.vendor):
+               if self.model_string and not self.model_string.startswith(self.vendor):
                        s.append(self.vendor)
                        s.append("-")
 
-               s.append(self.model_string)
+               s.append(self.model_string or "Generic")
 
                if self.core_count > 1:
                        s.append("x%s" % self.core_count)
@@ -189,9 +187,10 @@ class Processor(Object):
 
        @property
        def model_string(self):
-               s = self.data.model_string.split()
+               if self.data.model_string:
+                       s = self.data.model_string.split()
 
-               return " ".join((e for e in s if e))
+                       return " ".join((e for e in s if e))
 
        @property
        def flags(self):
@@ -254,7 +253,7 @@ class Processor(Object):
                return caps
 
        def format_model(self):
-               s = self.model_string
+               s = self.model_string or ""
 
                # Remove everything after the @: Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz
                s, sep, rest = s.partition("@")
@@ -290,7 +289,8 @@ class Processor(Object):
                s = []
 
                model = self.format_model()
-               s.append(model)
+               if model:
+                       s.append(model)
 
                clock_speed = self.format_clock_speed()
                if clock_speed:
@@ -359,17 +359,17 @@ class Device(Object):
                return "<%s vendor=%s model=%s>" % (self.__class__.__name__,
                        self.vendor_string, self.model_string)
 
-       def __cmp__(self, other):
-               if self.id and self.id == other.id:
-                       return 0
+       def __eq__(self, other):
+               if isinstance(other, self.__class__):
+                       return self.id == other.id
 
-               return \
-                       cmp(self.subsystem, other.subsystem) or \
-                       cmp(self.vendor_string, other.vendor_string) or \
-                       cmp(self.vendor, other.vendor) or \
-                       cmp(self.model_string, other.model_string) or \
-                       cmp(self.model, other.model) or \
-                       cmp(self.driver, other.driver)
+       def __lt__(self, other):
+               if isinstance(other, self.__class__):
+                       return self.cls < other.cls or \
+                               self.vendor_string < other.vendor_string or \
+                               self.vendor < other.vendor or \
+                               self.model_string < other.model_string or \
+                               self.model < other.model
 
        @property
        def data(self):
@@ -728,8 +728,8 @@ class Profile(Object):
                        return False
 
                # WiFi module
-               if self.count_device("usb", "148f", "5572") < 1:
-                       return False
+               #if self.count_device("usb", "148f", "5572") < 1:
+               #       return False
 
                return True
 
@@ -1036,7 +1036,6 @@ class Profile(Object):
                pairs = (
                        ("-beta", " - Beta "),
                        ("-rc", " - Release Candidate "),
-                       ("rc", "Release Candidate "),
                        ("core", "Core Update "),
                        ("beta", "Beta "),
                )
@@ -1218,11 +1217,6 @@ class ProfileParser(Object):
                "flags",
        )
 
-       __processor_args_mandatory = (
-               "vendor",
-               "model_string",
-       )
-
        def __init__(self, backend, public_id, blob=None):
                Object.__init__(self, backend)
 
@@ -1398,10 +1392,6 @@ class ProfileParser(Object):
 
                        args[arg] = _processor.get(_arg, None)
 
-               for arg in self.__processor_args_mandatory:
-                       if not args.get(arg, None):
-                               raise ProfileParserError("Mandatory argument missing: %s" % arg)
-
                self.processor = self.fireinfo.get_processor(**args)
                if not self.processor:
                        self.processor = self.fireinfo.create_processor(**args)
@@ -1615,7 +1605,7 @@ class Fireinfo(Object):
        def create_processor(self, vendor, model_string, family, model, stepping, core_count, flags=None):
                res = self.db.get("INSERT INTO fireinfo_processors(vendor, model_string, \
                        family, model, stepping, core_count, flags) VALUES(%s, %s, %s, %s, %s, %s, %s) \
-                       RETURNING id", vendor, model_string, family, model, stepping, core_count, flags)
+                       RETURNING id", vendor or None, model_string or None, family, model, stepping, core_count, flags)
 
                if res:
                        return Processor(self.backend, res.id)
@@ -1632,11 +1622,11 @@ class Fireinfo(Object):
                        flags = []
 
                res = self.db.get("SELECT * FROM fireinfo_processors \
-                       WHERE vendor = %s AND model_string = %s \
+                       WHERE vendor IS NOT DISTINCT FROM %s AND model_string IS NOT DISTINCT FROM %s \
                        AND family IS NOT DISTINCT FROM %s AND model IS NOT DISTINCT FROM %s \
                        AND stepping IS NOT DISTINCT FROM %s AND core_count = %s \
-                       AND flags <@ %s AND flags @> %s", vendor, model_string, family, model,
-                       stepping, core_count, flags, flags)
+                       AND flags <@ %s AND flags @> %s", vendor or None, model_string or None,
+                       family, model, stepping, core_count, flags, flags)
 
                if res:
                        return Processor(self.backend, res.id, res)
@@ -1805,7 +1795,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 \
@@ -1813,15 +1803,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)
-
-       def get_language_map(self, when=None):
-               res = self.db.query("WITH profiles AS (SELECT fireinfo_profiles_with_data_at(%s) AS id) \
-                       SELECT language, COUNT(language)::float / (SELECT COUNT(*) FROM profiles) AS count FROM profiles \
-                       LEFT JOIN fireinfo_profiles_languages ON profiles.id = fireinfo_profiles_languages.profile_id \
-                       WHERE fireinfo_profiles_languages.language IS NOT NULL GROUP BY language ORDER BY count DESC", when)
-
-               return ((r.language, r.count) for r in res)
+               return list(((r.location, r.count) for r in res))
 
        @property
        def cpu_vendors(self):
@@ -1870,13 +1852,13 @@ class Fireinfo(Object):
        def get_common_cpu_flags_by_platform(self, platform, when=None):
                if platform == "arm":
                        flags = (
-                               "lpae", "neon", "thumb", "thumb2", "thumbee", "vfpv3", "vfpv4",
+                               "lpae", "neon", "thumb", "thumbee", "vfpv3", "vfpv4",
                        )
                elif platform == "x86":
                        flags = (
                                "aes", "avx", "avx2", "lm", "mmx", "mmxext", "nx", "pae",
                                "pni", "popcnt", "sse", "sse2", "rdrand", "ssse3", "sse4a",
-                               "sse4_1", "sse4_2", "sha", "pclmulqdq", "rdseed",
+                               "sse4_1", "sse4_2", "pclmulqdq", "rdseed",
                        )
                else:
                        return
@@ -1893,36 +1875,13 @@ class Fireinfo(Object):
 
                return sorted(ret, key=lambda x: x[1], reverse=True)
 
-       def get_common_memory_amounts(self, when=None):
-               amounts = (128, 256, 512, 1024, 2 * 1024, 4 * 1024, 8 * 1024, 16 * 1024, 32 * 1024, 64 * 1024)
-
-               ret = []
-               for amount in amounts:
-                       ret.append((amount, self.get_memory_amount(amount * 1024 * 0.95, when=when)))
-
-               return ret
-
-       def get_memory_amount(self, greather_than, when=None):
-               res = self.db.get("WITH profiles AS (SELECT fireinfo_profiles_with_data_at(%s) AS id) \
-                       SELECT COUNT(*)::float / (SELECT COUNT(*) FROM profiles \
-                       LEFT JOIN fireinfo_profiles_memory ON profiles.id = fireinfo_profiles_memory.profile_id \
-                       WHERE NOT fireinfo_profiles_memory.amount IS NULL) AS percentage FROM profiles \
-                       LEFT JOIN fireinfo_profiles_memory ON profiles.id = fireinfo_profiles_memory.profile_id \
-                       WHERE fireinfo_profiles_memory.amount >= %s", when, greather_than)
-
-               if res:
-                       return res.percentage
-
-       def get_memory_amounts(self, when=None):
+       def get_average_memory_amount(self, when=None):
                res = self.db.get("WITH profiles AS (SELECT fireinfo_profiles_with_data_at(%s) AS id) \
-                       SELECT AVG(fireinfo_profiles_memory.amount) AS avg, \
-                       STDDEV(fireinfo_profiles_memory.amount) AS stddev, \
-                       MIN(fireinfo_profiles_memory.amount) AS min, \
-                       MAX(fireinfo_profiles_memory.amount) AS max FROM profiles \
+                       SELECT AVG(fireinfo_profiles_memory.amount) AS avg FROM profiles \
                        LEFT JOIN fireinfo_profiles_memory ON profiles.id = fireinfo_profiles_memory.profile_id", when)
 
                if res:
-                       return (res.avg or 0, res.stddev or 0, res.min or 0, res.max or 0)
+                       return res.avg or 0
 
        def get_arch_map(self, when=None):
                res = self.db.query("WITH profiles AS (SELECT fireinfo_profiles_with_data_at(%s) AS id) \
@@ -2009,17 +1968,17 @@ class Fireinfo(Object):
                try:
                        cls = self.subsystem2class[subsystem]
                except KeyError:
-                       return
+                       return ""
 
-               return cls.get_vendor(vendor_id)
+               return cls.get_vendor(vendor_id) or ""
 
        def get_model_string(self, subsystem, vendor_id, model_id):
                try:
                        cls = self.subsystem2class[subsystem]
                except KeyError:
-                       return
+                       return ""
 
-               return cls.get_device(vendor_id, model_id)
+               return cls.get_device(vendor_id, model_id) or ""
 
        def get_vendor_list(self, when=None):
                res = self.db.query("WITH profiles AS (SELECT fireinfo_profiles_with_data_at(%s) AS id) \
@@ -2055,39 +2014,3 @@ class Fireinfo(Object):
                                GROUP BY subsystem, model, vendor, driver, deviceclass", when, IGNORED_DEVICES, subsystem, vendor)
 
                return self._process_devices(res)
-
-       def get_device_percentage(self, subsystem, vendor, model, when=None):
-               res = self.db.get("WITH profiles AS (SELECT fireinfo_profiles_with_data_at(%s) AS id), \
-                       devices AS (SELECT * FROM profiles \
-                               LEFT JOIN fireinfo_profiles_devices ON profiles.id = fireinfo_profiles_devices.profile_id \
-                               LEFT JOIN fireinfo_devices ON fireinfo_profiles_devices.device_id = fireinfo_devices.id) \
-                       SELECT COUNT(*)::float / (SELECT COUNT(*) FROM devices) AS percentage FROM devices \
-                               WHERE devices.subsystem = %s AND devices.vendor = %s AND devices.model = %s",
-                       when, subsystem, vendor, model)
-
-               if res:
-                       return res.percentage
-
-       def get_device_in_profile(self, subsystem, vendor, model, limit=10, when=None):
-               res = self.db.query("WITH profiles AS (SELECT fireinfo_profiles_with_data_at(%s) AS id), \
-                       profiles_with_device AS (SELECT DISTINCT fireinfo_profiles.public_id FROM profiles \
-                               LEFT JOIN fireinfo_profiles ON profiles.id = fireinfo_profiles.id \
-                               LEFT JOIN fireinfo_profiles_devices ON profiles.id = fireinfo_profiles_devices.profile_id \
-                               LEFT JOIN fireinfo_devices ON fireinfo_profiles_devices.device_id = fireinfo_devices.id \
-                               WHERE fireinfo_devices.subsystem = %s AND fireinfo_devices.vendor = %s \
-                               AND fireinfo_devices.model = %s) \
-                       SELECT * FROM profiles_with_device ORDER BY RANDOM() LIMIT %s",
-                       when, subsystem, vendor, model, limit)
-
-               return (r.public_id for r in res)
-
-       def get_network_zones_map(self, when=None):
-               res = self.db.get("WITH profiles AS (SELECT fireinfo_profiles_with_data_at(%s) AS id) \
-                       SELECT COUNT(NULLIF(has_red, FALSE))::float / (SELECT COUNT(*) FROM profiles) AS has_red, \
-                               COUNT(NULLIF(has_green, FALSE))::float / (SELECT COUNT(*) FROM profiles) AS has_green, \
-                               COUNT(NULLIF(has_orange, FALSE))::float / (SELECT COUNT(*) FROM profiles) AS has_orange, \
-                               COUNT(NULLIF(has_blue, FALSE))::float / (SELECT COUNT(*) FROM profiles) AS has_blue FROM profiles \
-                               LEFT JOIN fireinfo_profiles_networks ON profiles.id = fireinfo_profiles_networks.profile_id \
-                               WHERE fireinfo_profiles_networks.profile_id IS NOT NULL", when)
-
-               return res