From 301c2ea29a193d3e0e45a6f972f61b508d9a7d15 Mon Sep 17 00:00:00 2001 From: ross-spencer Date: Sat, 30 Nov 2024 15:02:55 +0100 Subject: [PATCH] Improve counts --- htmx/index.htm | 17 ++++++++++++++--- src/itn_api/api.py | 13 +++++++++++++ src/itn_api/htm_helpers.py | 19 ++++++++++++++++++- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/htmx/index.htm b/htmx/index.htm index b4dbe20..d324e49 100644 --- a/htmx/index.htm +++ b/htmx/index.htm @@ -29,12 +29,11 @@ +
+

ITN diagnostics

-

ITN diagnostics

License holders

-
-
License holders

+
+

Node counts

+
+
+
+
+

Active collector counts

Collector locations +
diff --git a/src/itn_api/api.py b/src/itn_api/api.py index 047709a..7d02e6b 100644 --- a/src/itn_api/api.py +++ b/src/itn_api/api.py @@ -241,6 +241,19 @@ async def get_locations_hx(): return htm_helpers.locations_table(locations) +@app.get("/count_active_participants", tags=[TAG_HTMX], response_class=HTMLResponse) +async def count_active_participants(): + """Count active participants.""" + try: + participants = app.state.connection.execute( + "select count(distinct address) as count from data_points;" + ) + except apsw.SQLError as err: + return {"error": f"{err}"} + data = list(participants) + return f"{data[0][0]}" + + def main(): """Primary entry point for this script.""" diff --git a/src/itn_api/htm_helpers.py b/src/itn_api/htm_helpers.py index feec128..c1be6d0 100644 --- a/src/itn_api/htm_helpers.py +++ b/src/itn_api/htm_helpers.py @@ -38,7 +38,10 @@ def aliases_to_html(alias_report: dict) -> str: """.strip() rows = "" + count = 0 for alias in alias_report: + if alias.alias != "": + count += 1 row = f""" {alias.staking} @@ -50,7 +53,21 @@ def aliases_to_html(alias_report: dict) -> str: rows = f"{rows}{row}\n" - return f"{head}\n{rows}\n" + count_row = f""" + + + + + + + + Count +  {count}  + + + + """ + return f"{head}\n{rows}\n{count_row}\n" def participants_count_table(participants_count_total):