]> git.ipfire.org Git - ipfire.org.git/blobdiff - src/backend/fireinfo.py
backend: show checksum on thank-you page
[ipfire.org.git] / src / backend / fireinfo.py
index 277ad7816b4f4cde105ef37ca475d61484f4d4e9..702739bd6dfe10eeeab7a98aeabc95a793dd05cd 100644 (file)
@@ -113,7 +113,7 @@ PROFILE_SCHEMA = {
                                        },
                                },
                                "model" : {
-                                       "type" : "integer",
+                                       "type" : ["integer", "null"],
                                },
                                "model_string" : {
                                        "type" : ["string", "null"],
@@ -123,7 +123,7 @@ PROFILE_SCHEMA = {
                                        "type" : "number",
                                },
                                "stepping" : {
-                                       "type" : "integer",
+                                       "type" : ["integer", "null"],
                                },
                                "vendor" : {
                                        "type"    : "string",
@@ -175,7 +175,7 @@ PROFILE_SCHEMA = {
                                                "pattern" : r"^[a-z]{3}$",
                                        },
                                        "vendor" : {
-                                               "type"    : "string",
+                                               "type"    : ["string", "null"],
                                                "pattern" : r"^[a-z0-9]{4}$",
                                        },
                                },
@@ -234,10 +234,10 @@ PROFILE_SCHEMA = {
                                        "pattern" : r"^.{,80}$",
                                },
                                "root_size" : {
-                                       "type" : "number",
+                                       "type" : ["number", "null"],
                                },
                                "vendor" : {
-                                       "type"    : "string",
+                                       "type"    : ["string", "null"],
                                        "pattern" : r"^.{,80}$",
                                },
                                "virtual" : {
@@ -337,6 +337,10 @@ class Processor(Object):
 
                return " ".join(s)
 
+       @property
+       def arch(self):
+               return self.blob.get("arch")
+
        @property
        def vendor(self):
                vendor = self.blob.get("vendor")
@@ -388,7 +392,7 @@ class Processor(Object):
 
        @property
        def clock_speed(self):
-               return self.__clock_speed
+               return self.blob.get("speed", 0)
 
        def format_clock_speed(self):
                if not self.clock_speed:
@@ -595,10 +599,6 @@ class System(Object):
        def init(self, blob):
                self.blob = blob
 
-       @property
-       def arch(self):
-               return self.blob.get("arch")
-
        @property
        def language(self):
                return self.blob.get("language")
@@ -615,6 +615,16 @@ class System(Object):
        def release(self):
                return self.blob.get("release")
 
+       # Memory
+
+       @property
+       def memory(self):
+               return self.blob.get("memory") * 1024
+
+       @property
+       def friendly_memory(self):
+               return util.format_size(self.memory or 0)
+
        @property
        def storage(self):
                return self.blob.get("storage_size", 0)
@@ -688,16 +698,6 @@ class Profile(Object):
        def processor(self):
                return Processor(self.backend, self.blob.get("cpu", {}))
 
-       # Memory
-
-       @property
-       def memory(self):
-               return self.blob.get("memory")
-
-       @property
-       def friendly_memory(self):
-               return util.format_size(self.memory or 0)
-
        # Virtual
 
        def is_virtual(self):
@@ -757,27 +757,6 @@ class Fireinfo(Object):
 
                return res.count if res else 0
 
-       def get_profile_histogram(self):
-               today = datetime.date.today()
-
-               t1 = datetime.date(year=today.year - 10, month=today.month, day=1)
-               t2 = datetime.date(year=today.year, month=today.month, day=1)
-
-               res = self.db.query("""
-                       SELECT
-                               date,
-                               COUNT(*) AS count
-                       FROM
-                               generate_series(%s, %s, INTERVAL '1 month') date
-                       JOIN
-                               fireinfo ON date >= created_at
-                                       AND (expired_at IS NULL OR expired_at > date)
-                       GROUP BY
-                               date
-               """, t1, t2)
-
-               return { row.date : row.count for row in res }
-
        # Profiles
 
        def get_profile(self, profile_id, when=None):
@@ -855,6 +834,10 @@ class Fireinfo(Object):
                        self.db.execute("UPDATE fireinfo SET expired_at = CURRENT_TIMESTAMP \
                                WHERE profile_id = %s AND expired_at IS NULL", profile_id)
 
+               # Serialise the profile
+               if profile:
+                       profile = json.dumps(profile)
+
                # Store the new profile
                self.db.execute("""
                        INSERT INTO
@@ -876,7 +859,7 @@ class Fireinfo(Object):
                                %s,
                                %s
                        )
-                       """, profile_id, private_id, version, json.dumps(profile), country_code, asn,
+                       """, profile_id, private_id, version, profile, country_code, asn,
                )
 
        def _validate(self, profile_id, version, blob):
@@ -935,6 +918,8 @@ class Fireinfo(Object):
                                        OR
                                                expired_at > %s
                                        )
+                               AND
+                                       blob IS NOT NULL
                                ORDER BY
                                        RANDOM()
                                LIMIT
@@ -949,6 +934,8 @@ class Fireinfo(Object):
                                fireinfo
                        WHERE
                                expired_at IS NULL
+                       AND
+                               blob IS NOT NULL
                        ORDER BY
                                RANDOM()
                        LIMIT
@@ -1080,7 +1067,7 @@ class Fireinfo(Object):
                else:
                        res = self.db.query("""
                                SELECT
-                                       blob->'cpu'->'vendor' AS vendor,
+                                       NULLIF(blob->'cpu'->'vendor', '""'::jsonb) AS vendor,
                                        fireinfo_percentage(
                                                COUNT(*), SUM(COUNT(*)) OVER ()
                                        ) AS p
@@ -1090,10 +1077,8 @@ class Fireinfo(Object):
                                        expired_at IS NULL
                                AND
                                        blob IS NOT NULL
-                               AND
-                                       blob->'cpu'->'vendor' IS NOT NULL
                                GROUP BY
-                                       blob->'cpu'->'vendor'
+                                       NULLIF(blob->'cpu'->'vendor', '""'::jsonb)
                        """)
 
                return { CPU_VENDORS.get(row.vendor, row.vendor) : row.p for row in res }
@@ -1293,7 +1278,10 @@ class Fireinfo(Object):
                else:
                        res = self.db.query("""
                                SELECT
-                                       blob->'system'->'kernel' AS kernel,
+                                       COALESCE(
+                        blob->'system'->'kernel_release',
+                        blob->'system'->'kernel'
+                    ) AS kernel,
                                        fireinfo_percentage(
                                                COUNT(*), SUM(COUNT(*)) OVER ()
                                        ) AS p
@@ -1304,9 +1292,16 @@ class Fireinfo(Object):
                                AND
                                        blob IS NOT NULL
                                AND
-                                       blob->'system'->'kernel' IS NOT NULL
+                                       (
+                        blob->'system'->'kernel_release' IS NOT NULL
+                    OR
+                        blob->'system'->'kernel' IS NOT NULL
+                    )
                                GROUP BY
-                                       blob->'system'->'kernel'
+                                       COALESCE(
+                        blob->'system'->'kernel_release',
+                        blob->'system'->'kernel'
+                    )
                        """)
 
                return { row.kernel : row.p for row in res }
@@ -1481,7 +1476,7 @@ class Fireinfo(Object):
                                                driver      text
                                        )
                                WHERE
-                                       devices.device->>'driver' = '%s'
+                                       devices.device->>'driver' = %s
                                GROUP BY
                                        device.deviceclass,
                                        device.subsystem,