Skip to content

Commit

Permalink
Improve counts
Browse files Browse the repository at this point in the history
  • Loading branch information
ross-spencer committed Nov 30, 2024
1 parent 0349367 commit 301c2ea
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
17 changes: 14 additions & 3 deletions htmx/index.htm
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@
<body
hx-ext="pronom-api-params"
hx-vals='{"baseURLLocal": "http://0.0.0.0:24001", "baseURL": "https://itn.0.orcfax.io"}'>
<div>
<h1>ITN diagnostics</h1>
<section id="license-holders">
<h1>ITN diagnostics</h1>
<div>
<h2>License holders</h2>
<div>
<div>
<div
hx-get="{baseURL}/api/participants"
hx-trigger="load"
Expand All @@ -43,6 +42,17 @@ <h2>License holders</h2>
</div>
</section>
<hr>
<section id="node-counts">
<h2>Node counts</h2>
<div
hx-get="{baseURL}/api/count_active_participants"
hx-trigger="load"
hx-swap="innerHTML"
/>
</div>
</section>
<hr>

<section id="collector-counts">
<h2>Active collector counts</h2>
<div
Expand All @@ -66,5 +76,6 @@ <h2>Collector locations</h2>
<div class="footer__bottom text--center">
<div class="footer__copyright">ITN | Diagnostics</div>
</div>
</div>
</body>
</html>
13 changes: 13 additions & 0 deletions src/itn_api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""

Expand Down
19 changes: 18 additions & 1 deletion src/itn_api/htm_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
<tr>
<td>{alias.staking}</td>
Expand All @@ -50,7 +53,21 @@ def aliases_to_html(alias_report: dict) -> str:

rows = f"{rows}{row}\n"

return f"{head}\n{rows}</table>\n"
count_row = f"""
<tr>
<td></td>
<td nowrap></td>
<td nowrap></td>
<td></td>
</tr>
<tr>
<td>Count</td>
<td nowrap>&nbsp;{count}&nbsp;</td>
<td nowrap></td>
<td></td>
</tr>
"""
return f"{head}\n{rows}\n{count_row}</table>\n"


def participants_count_table(participants_count_total):
Expand Down

0 comments on commit 301c2ea

Please sign in to comment.