return { row.country_code : row.p for row in res }
+ def get_asn_map(self, when=None):
+ if when:
+ res = self.db.query("""
+ SELECT
+ asn,
+ fireinfo_percentage(
+ COUNT(*), SUM(COUNT(*)) OVER ()
+ ) AS p,
+ COUNT(*) AS c
+ FROM
+ fireinfo
+ WHERE
+ created_at <= %s
+ AND
+ (
+ expired_at IS NULL
+ OR
+ expired_at > %s
+ )
+ AND
+ asn IS NOT NULL
+ GROUP BY
+ asn
+ """, when, when)
+ else:
+ res = self.db.query("""
+ SELECT
+ asn,
+ fireinfo_percentage(
+ COUNT(*), SUM(COUNT(*)) OVER ()
+ ) AS p,
+ COUNT(*) AS c
+ FROM
+ fireinfo
+ WHERE
+ expired_at IS NULL
+ AND
+ asn IS NOT NULL
+ GROUP BY
+ asn
+ """)
+
+ return { self.backend.location.get_as(row.asn) : (row.c, row.p) for row in res }
+
@property
def cpu_vendors(self):
res = self.db.query("""
</div>
</section>
+ {% if asn_map %}
+ <section class="section">
+ <div class="container">
+ <h4 class="title is-4">{{ _("Autonomous Systems") }}</h4>
+
+ <table class="table is-fullwidth">
+ <tr>
+ <th>{{ _("Autonomous System") }}</th>
+ <th class="has-text-right">{{ _("Total Profiles") }}</th>
+ <th class="has-text-right">{{ _("Percentage") }}</th>
+ </tr>
+
+ {% for asn in sorted(asn_map, key=lambda asn: asn_map[asn], reverse=True) %}
+ {% set c, p = asn_map[asn] %}
+
+ <tr>
+ <th scope="row">{{ asn }}</th>
+ <td class="has-text-right">
+ {{ c }}
+ </td>
+ <td class="has-text-right">
+ {{ "%.2f%%" % (p * 100) }}
+ </td>
+ </tr>
+ {% end %}
+ </table>
+ </div>
+ </section>
+ {% end %}
+
{% if histogram %}
<section class="section">
<div class="container">
def get(self):
with_data, total = self.backend.fireinfo.get_active_profiles()
+ # Fetch the ASN map
+ asn_map = self.backend.fireinfo.get_asn_map()
+
+ # Fetch the histogram
histogram = self.backend.fireinfo.get_profile_histogram()
self.render("fireinfo/admin.html", with_data=with_data, total=total,
- histogram=histogram)
+ asn_map=asn_map, histogram=histogram)