Skip to content

Commit

Permalink
Merge branch 'master' into fork/Runtee/sql-dump
Browse files Browse the repository at this point in the history
  • Loading branch information
djeck1432 committed Feb 27, 2025
2 parents 7a2f0f2 + 6bd8f9d commit dd8ebb0
Show file tree
Hide file tree
Showing 36 changed files with 5,041 additions and 10,526 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CI Workflow

on: [push]
on: [push, pull_request]


jobs:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dashboard_app_ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: DashBoard App CI Workflow

on: [push]
on: [push, pull_request]

jobs:
run_tests:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/dashboard_app_pylint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Dashboard App

on: [push]
on: [push, pull_request]

jobs:
lint:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/sdk_app_ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: SDK testing workflow

on: [push]
on: [push, pull_request]

jobs:
run_tests:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wep_app_ci.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Web App CI Workflow

on: [push]
on: [push, pull_request]

jobs:
run_tests:
Expand Down
10 changes: 9 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ __pycache__
.ipynb_checkpoints
.vscode
.env
.venv
shell.nix
storage_credentials.json
env/
.venv
.venv

.env.dev

.idea/
.DS_Store

2 changes: 1 addition & 1 deletion apps/dashboard_app/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ COPY legacy_app/src legacy_app/src
COPY legacy_app/app.py .
COPY legacy_app/update_data.py .

CMD ["streamlit", "run", "app.py"]
CMD ["streamlit", "run", "dashboard.py"]

12 changes: 9 additions & 3 deletions apps/dashboard_app/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ Interactive dashboard application for visualizing and analyzing DeRisk data.
### Docker Setup

1. Build the image:


```
docker-compose -f devops/dev/docker-compose.dashboard-app.yaml build
```
2. Run the container:

```
docker-compose -f devops/dev/docker-compose.dashboard-app.yaml up
```
3. stop container:
```
docker-compose -f devops/dev/docker-compose.dashboard-app.yaml down
```

## Key Features

Expand Down
59 changes: 59 additions & 0 deletions apps/dashboard_app/charts/main.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This module defines the Dashboard class for rendering a DeRisk dashboard using Streamlit.
"""

import numpy as np
import pandas as pd
import plotly
Expand All @@ -25,6 +26,7 @@
get_bar_chart_figures,
get_main_chart_figure,
get_specific_loan_usd_amounts,
get_user_history
)
from .utils import (
get_protocol_data_mappings,
Expand All @@ -33,6 +35,7 @@
transform_loans_data,
transform_main_chart_data,
)



class Dashboard:
Expand Down Expand Up @@ -385,7 +388,61 @@ def load_comparison_lending_protocols_chart(self):
figure = self._plot_chart(token, "supply")
st.plotly_chart(figure, True)

def get_user_history(self, wallet_id):
"""
Fetch and return the transaction history for a specific user.
"""
user_data = get_user_history(wallet_id)
if user_data is None or user_data.empty:
st.error("No data found for this user.")
return None

user_data.columns = [CommonValues.protocol.value, CommonValues.total_usd.value]
user_data = user_data.sort_values(CommonValues.total_usd.value, ascending=False)
user_data.reset_index(drop=True, inplace=True)

st.dataframe(user_data)
return user_data

# 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 +484,5 @@ def run(self):
self.load_top_loans_chart()
self.load_detail_loan_chart()
self.load_comparison_lending_protocols_chart()
self.get_user_history()
self.load_leaderboard()
26 changes: 25 additions & 1 deletion apps/dashboard_app/charts/main_chart_figure.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

import math
from decimal import Decimal

import pandas as pd
import streamlit as st
import plotly.express
import plotly.graph_objs
from shared.amms import SwapAmm
Expand Down Expand Up @@ -385,4 +385,28 @@ def get_user_history(user_id: str, df: pd.DataFrame) -> pd.DataFrame:
print(f"User ID {user_id} not found in the DataFrame.")
return pd.DataFrame()

def display_user_history_chart(df: pd.DataFrame):
"""
Displays a chart based on the user's wallet ID input to show their transaction history.
Args:
df (pd.DataFrame): The DataFrame containing all transactions.
"""
st.subheader("Input Wallet ID to View History")

wallet_id = st.text_input("Enter Wallet ID:")

if wallet_id:
user_history_data = get_user_history(wallet_id, df)

if not user_history_data.empty:
st.dataframe(user_history_data)

st.subheader(f"Collateral and Debt History for Wallet ID: {wallet_id}")
chart_data = user_history_data.set_index("Transaction")[["Collateral", "Debt"]]
st.line_chart(chart_data)
else:
st.error("No data found for this wallet ID.")



9 changes: 4 additions & 5 deletions apps/dashboard_app/charts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@
from shared.amms import SwapAmm
from shared.constants import PAIRS

from helpers.ekubo import EkuboLiquidity
from helpers.loans_table import get_loans_table_data
from helpers.settings import (
from dashboard_app.helpers.ekubo import EkuboLiquidity
from dashboard_app.helpers.loans_table import get_loans_table_data
from dashboard_app.helpers.settings import (
COLLATERAL_TOKENS,
DEBT_TOKENS,
STABLECOIN_BUNDLE_NAME,
TOKEN_SETTINGS,
UNDERLYING_SYMBOLS_TO_UNDERLYING_ADDRESSES,
)
from helpers.tools import get_main_chart_data, get_prices
from dashboard_app.helpers.tools import get_main_chart_data, get_prices

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -306,7 +306,6 @@ def transform_main_chart_data(

return main_chart_data


def infer_protocol_name(input_protocol: str, valid_protocols: list[str]) -> str:
"""Find the closest matching protocol name from a list of valid protocols using fuzzy matching.
Expand Down
Loading

0 comments on commit dd8ebb0

Please sign in to comment.