Add total addr, user count to ranking (#51) #52

Merged
pluja merged 1 commits from brickedsalamander/iseeyour.cash:totals-on-ranking into main 9 months ago
  1. 4
      iseeyourcash.py
  2. 3
      templates/ranking.html
  3. 9
      utils.py

@ -131,7 +131,9 @@ async def ranking(request):
ranking = await utils.get_rankings(50)
return html(template.render(quote=quote, ranking=ranking))
tot_addr_count, tot_user_count = await utils.get_global_stats()
return html(template.render(quote=quote, ranking=ranking, tot_addr_count=tot_addr_count, tot_user_count=tot_user_count))
@app.exception(SanicException)
async def error(request, exception):

@ -9,6 +9,9 @@
<div class="logo">
The Most <span class="yellow"> Cash</span> I've Seen So Far
</div>
<h4 class="subtitle yellow" style="text-align: center;">
From a total of {{tot_addr_count}} addresses from {{tot_user_count}} users
</h4>
<div class="rankingContainer">
<table class="table ranking">

@ -490,3 +490,12 @@ async def get_rankings(max_rank):
ranking.append([i, r[0], f"${r[1]:,.2f}"])
return ranking
async def get_global_stats():
engine = create_async_engine(f"mysql+aiomysql://root:{data['db-password']}@{data['db-name']}:3307/iseeyourcash?charset=utf8mb4")
async with engine.begin() as conn:
tot_addr_count = await conn.execute(text("SELECT COUNT(*) FROM address"))
tot_addr_count = tot_addr_count.first()[0]
tot_user_count = await conn.execute(text("SELECT COUNT(*) FROM user"))
tot_user_count = tot_user_count.first()[0]
return tot_addr_count, tot_user_count

Loading…
Cancel
Save