Skip to content

Commit

Permalink
Merge pull request #459 from simplicityf/master
Browse files Browse the repository at this point in the history
Added load_leaderboard method
  • Loading branch information
djeck1432 authored Feb 25, 2025
2 parents cc22181 + c9260e1 commit fd8272e
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions apps/dashboard_app/charts/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,44 @@ def load_comparison_lending_protocols_chart(self):
st.plotly_chart(figure, True)

# TODO: add last update functionality

def load_leaderboard(self):
"""
Display a leaderboard of the top 5 biggest collateral and debt per token.
"""
st.header("Leaderboard: Top 5 Collateral & Debt per Token")

if self.collateral_stats.empty or self.debt_stats.empty:
st.warning("No data available for leaderboard.")
return

top_collateral = (
self.collateral_stats.groupby("token")["amount_usd"]
.sum()
.nlargest(5)
.reset_index()
)
top_collateral["type"] = "Collateral"

top_debt = (
self.debt_stats.groupby("token")["amount_usd"]
.sum()
.nlargest(5)
.reset_index()
)
top_debt["type"] = "Debt"

leaderboard_df = pd.concat([top_collateral, top_debt])

def highlight_values(row):
color = "green" if row["type"] == "Collateral" else "red"
return [f'background-color: {color}; color: white' for _ in row]

st.dataframe(
leaderboard_df.style.apply(highlight_values, axis=1),
hide_index=True,
use_container_width=True,
)

def _plot_chart(self, token: str, stats_type: str) -> plotly.express.data:
"""
Expand Down Expand Up @@ -427,3 +465,4 @@ def run(self):
self.load_top_loans_chart()
self.load_detail_loan_chart()
self.load_comparison_lending_protocols_chart()
self.load_leaderboard()

0 comments on commit fd8272e

Please sign in to comment.