Spaces:
Running
Running
gauravlochab
commited on
Commit
•
0b71f39
1
Parent(s):
9e04788
chore: added grpahs for swaps and corrected the plots for Transcations graph
Browse files
app.py
CHANGED
@@ -106,35 +106,46 @@ def create_visualizations():
|
|
106 |
df["sending_chain"] = df["sending_chain"].astype(str)
|
107 |
df["receiving_chain"] = df["receiving_chain"].astype(str)
|
108 |
|
109 |
-
#
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
x="date",
|
114 |
-
y="transaction_count",
|
115 |
-
color="sending_chain",
|
116 |
-
title="Chain Daily Activity: Transactions",
|
117 |
-
labels={"transaction_count": "Daily Transaction Nr"},
|
118 |
barmode="stack"
|
119 |
)
|
|
|
120 |
|
121 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
opportunities_per_agent = df.groupby(["date", "from_address"]).size().reset_index(name="opportunities_taken")
|
123 |
fig_opportunities_agent = px.bar(opportunities_per_agent, x="date", y="opportunities_taken", color="from_address",
|
124 |
title="Number of Opportunities Taken per Agent per Day")
|
125 |
|
126 |
-
#
|
127 |
-
# Since we might not have explicit data about pool investments, we'll use sending_amount_usd
|
128 |
investment_per_agent = df.groupby(["date", "from_address"])["sending_amount_usd"].sum().reset_index()
|
129 |
fig_investment_agent = px.bar(investment_per_agent, x="date", y="sending_amount_usd", color="from_address",
|
130 |
title="Amount of Investment (USD) per Agent per Day")
|
131 |
|
132 |
-
#
|
133 |
-
df["is_swap"] = df.apply(lambda x: x["sending_token_symbol"] != x["receiving_token_symbol"], axis=1)
|
134 |
-
swaps_per_day = df[df["is_swap"]].groupby("date").size().reset_index(name="swap_count")
|
135 |
-
fig_swaps_per_day = px.bar(swaps_per_day, x="date", y="swap_count", title="Number of Swaps per Day")
|
136 |
-
|
137 |
-
# 5. Aggregated Metrics over All Traders
|
138 |
amount_usd = df["sending_amount_usd"]
|
139 |
stats = {
|
140 |
"Total": amount_usd.sum(),
|
@@ -147,10 +158,10 @@ def create_visualizations():
|
|
147 |
}
|
148 |
stats_df = pd.DataFrame(list(stats.items()), columns=["Metric", "Value"])
|
149 |
|
150 |
-
# Visualization for
|
151 |
fig_stats = px.bar(stats_df, x="Metric", y="Value", title="Aggregated Transaction Amount Metrics (USD)")
|
152 |
|
153 |
-
return
|
154 |
|
155 |
# Gradio interface
|
156 |
def dashboard():
|
@@ -158,22 +169,22 @@ def dashboard():
|
|
158 |
gr.Markdown("# Valory Transactions Dashboard")
|
159 |
|
160 |
# Fetch and display visualizations
|
161 |
-
with gr.Tab("Transactions per Chain
|
162 |
-
|
163 |
-
gr.Plot(
|
|
|
|
|
|
|
|
|
164 |
|
165 |
with gr.Tab("Opportunities per Agent"):
|
166 |
-
_,
|
167 |
gr.Plot(fig_opportunities_agent)
|
168 |
|
169 |
with gr.Tab("Investment per Agent"):
|
170 |
-
_, _,
|
171 |
gr.Plot(fig_investment_agent)
|
172 |
|
173 |
-
with gr.Tab("Swaps per Day"):
|
174 |
-
_, _, _, fig_swaps_per_day, _ = create_visualizations()
|
175 |
-
gr.Plot(fig_swaps_per_day)
|
176 |
-
|
177 |
with gr.Tab("Aggregated Metrics"):
|
178 |
_, _, _, _, fig_stats = create_visualizations()
|
179 |
gr.Plot(fig_stats)
|
|
|
106 |
df["sending_chain"] = df["sending_chain"].astype(str)
|
107 |
df["receiving_chain"] = df["receiving_chain"].astype(str)
|
108 |
|
109 |
+
# Total transactions per chain per day
|
110 |
+
tx_per_chain = df.groupby(["date", "sending_chain"]).size().reset_index(name="transaction_count")
|
111 |
+
fig_tx_chain = px.bar(
|
112 |
+
tx_per_chain,
|
113 |
+
x="date",
|
114 |
+
y="transaction_count",
|
115 |
+
color="sending_chain",
|
116 |
+
title="Chain Daily Activity: Transactions",
|
117 |
+
labels={"transaction_count": "Daily Transaction Nr"},
|
118 |
barmode="stack"
|
119 |
)
|
120 |
+
fig_tx_chain.update_layout(xaxis_title=None)
|
121 |
|
122 |
+
# Identify swap transactions
|
123 |
+
df["is_swap"] = df.apply(lambda x: x["sending_token_symbol"] != x["receiving_token_symbol"], axis=1)
|
124 |
+
|
125 |
+
# Total swaps per chain per day
|
126 |
+
swaps_per_chain = df[df["is_swap"]].groupby(["date", "sending_chain"]).size().reset_index(name="swap_count")
|
127 |
+
fig_swaps_chain = px.bar(
|
128 |
+
swaps_per_chain,
|
129 |
+
x="date",
|
130 |
+
y="swap_count",
|
131 |
+
color="sending_chain",
|
132 |
+
title="Chain Daily Activity: Swaps",
|
133 |
+
labels={"swap_count": "Daily Swap Nr"},
|
134 |
+
barmode="stack"
|
135 |
+
)
|
136 |
+
fig_swaps_chain.update_layout(xaxis_title=None)
|
137 |
+
|
138 |
+
# Opportunities per agent per day
|
139 |
opportunities_per_agent = df.groupby(["date", "from_address"]).size().reset_index(name="opportunities_taken")
|
140 |
fig_opportunities_agent = px.bar(opportunities_per_agent, x="date", y="opportunities_taken", color="from_address",
|
141 |
title="Number of Opportunities Taken per Agent per Day")
|
142 |
|
143 |
+
# Investment per agent per day
|
|
|
144 |
investment_per_agent = df.groupby(["date", "from_address"])["sending_amount_usd"].sum().reset_index()
|
145 |
fig_investment_agent = px.bar(investment_per_agent, x="date", y="sending_amount_usd", color="from_address",
|
146 |
title="Amount of Investment (USD) per Agent per Day")
|
147 |
|
148 |
+
# Aggregated metrics over all traders
|
|
|
|
|
|
|
|
|
|
|
149 |
amount_usd = df["sending_amount_usd"]
|
150 |
stats = {
|
151 |
"Total": amount_usd.sum(),
|
|
|
158 |
}
|
159 |
stats_df = pd.DataFrame(list(stats.items()), columns=["Metric", "Value"])
|
160 |
|
161 |
+
# Visualization for aggregated metrics
|
162 |
fig_stats = px.bar(stats_df, x="Metric", y="Value", title="Aggregated Transaction Amount Metrics (USD)")
|
163 |
|
164 |
+
return fig_tx_chain, fig_swaps_chain, fig_opportunities_agent, fig_investment_agent, fig_stats
|
165 |
|
166 |
# Gradio interface
|
167 |
def dashboard():
|
|
|
169 |
gr.Markdown("# Valory Transactions Dashboard")
|
170 |
|
171 |
# Fetch and display visualizations
|
172 |
+
with gr.Tab("Transactions per Chain"):
|
173 |
+
fig_tx_chain, _, _, _, _ = create_visualizations()
|
174 |
+
gr.Plot(fig_tx_chain)
|
175 |
+
|
176 |
+
with gr.Tab("Swaps per Chain"):
|
177 |
+
_, fig_swaps_chain, _, _, _ = create_visualizations()
|
178 |
+
gr.Plot(fig_swaps_chain)
|
179 |
|
180 |
with gr.Tab("Opportunities per Agent"):
|
181 |
+
_, _, fig_opportunities_agent, _, _ = create_visualizations()
|
182 |
gr.Plot(fig_opportunities_agent)
|
183 |
|
184 |
with gr.Tab("Investment per Agent"):
|
185 |
+
_, _, _, fig_investment_agent, _ = create_visualizations()
|
186 |
gr.Plot(fig_investment_agent)
|
187 |
|
|
|
|
|
|
|
|
|
188 |
with gr.Tab("Aggregated Metrics"):
|
189 |
_, _, _, _, fig_stats = create_visualizations()
|
190 |
gr.Plot(fig_stats)
|