Spaces:
Runtime error
Runtime error
gauravlochab
commited on
Commit
·
1107b51
1
Parent(s):
ec2e5d2
refactor: Update daily and weekly agent counts
Browse files- app.py +4 -3
- app_trans_new.py +51 -1
app.py
CHANGED
@@ -6,7 +6,7 @@ import plotly.express as px
|
|
6 |
from datetime import datetime, timedelta
|
7 |
import json
|
8 |
from web3 import Web3
|
9 |
-
from app_trans_new import create_transcation_visualizations
|
10 |
from app_value_locked import fetch_daily_value_locked
|
11 |
OPTIMISM_RPC_URL = 'https://opt-mainnet.g.alchemy.com/v2/U5gnXPYxeyH43MJ9tP8ONBQHEDRav7H0'
|
12 |
|
@@ -270,7 +270,7 @@ def create_visualizations():
|
|
270 |
tickmode='array',
|
271 |
tickvals=[d for d in swaps_per_chain['date'] if d.weekday() == 0], # Show only Mondays
|
272 |
ticktext=[d.strftime('%m-%d') for d in swaps_per_chain['date'] if d.weekday() == 0],
|
273 |
-
tickangle
|
274 |
),
|
275 |
bargap=0.6, # Increase gap between bar groups (0-1)
|
276 |
bargroupgap=0.1, # Decrease gap between bars in a group (0-1)
|
@@ -315,7 +315,7 @@ def create_visualizations():
|
|
315 |
tickmode='array',
|
316 |
tickvals=[d for d in bridges_per_chain['date'] if d.weekday() == 0], # Show only Mondays
|
317 |
ticktext=[d.strftime('%m-%d') for d in bridges_per_chain['date'] if d.weekday() == 0],
|
318 |
-
tickangle
|
319 |
),
|
320 |
bargap=0.6, # Increase gap between bar groups (0-1)
|
321 |
bargroupgap=0.1, # Decrease gap between bars in a group (0-1)
|
@@ -455,6 +455,7 @@ def dashboard():
|
|
455 |
gr.Plot(fig_agents_registered)
|
456 |
|
457 |
with gr.Tab("DAA"):
|
|
|
458 |
#fig_swaps_chain, fig_bridges_chain, fig_agents_daily, fig_agents_with_transactions_daily,fig_tvl = create_visualizations()
|
459 |
gr.Plot(fig_agents_with_transactions_daily)
|
460 |
|
|
|
6 |
from datetime import datetime, timedelta
|
7 |
import json
|
8 |
from web3 import Web3
|
9 |
+
from app_trans_new import create_transcation_visualizations,create_active_agents_visualizations
|
10 |
from app_value_locked import fetch_daily_value_locked
|
11 |
OPTIMISM_RPC_URL = 'https://opt-mainnet.g.alchemy.com/v2/U5gnXPYxeyH43MJ9tP8ONBQHEDRav7H0'
|
12 |
|
|
|
270 |
tickmode='array',
|
271 |
tickvals=[d for d in swaps_per_chain['date'] if d.weekday() == 0], # Show only Mondays
|
272 |
ticktext=[d.strftime('%m-%d') for d in swaps_per_chain['date'] if d.weekday() == 0],
|
273 |
+
tickangle=-45,
|
274 |
),
|
275 |
bargap=0.6, # Increase gap between bar groups (0-1)
|
276 |
bargroupgap=0.1, # Decrease gap between bars in a group (0-1)
|
|
|
315 |
tickmode='array',
|
316 |
tickvals=[d for d in bridges_per_chain['date'] if d.weekday() == 0], # Show only Mondays
|
317 |
ticktext=[d.strftime('%m-%d') for d in bridges_per_chain['date'] if d.weekday() == 0],
|
318 |
+
tickangle=-45,
|
319 |
),
|
320 |
bargap=0.6, # Increase gap between bar groups (0-1)
|
321 |
bargroupgap=0.1, # Decrease gap between bars in a group (0-1)
|
|
|
455 |
gr.Plot(fig_agents_registered)
|
456 |
|
457 |
with gr.Tab("DAA"):
|
458 |
+
fig_agents_with_transactions_daily = create_active_agents_visualizations()
|
459 |
#fig_swaps_chain, fig_bridges_chain, fig_agents_daily, fig_agents_with_transactions_daily,fig_tvl = create_visualizations()
|
460 |
gr.Plot(fig_agents_with_transactions_daily)
|
461 |
|
app_trans_new.py
CHANGED
@@ -249,7 +249,13 @@ def create_transcation_visualizations():
|
|
249 |
# Group by date and chain, count transactions
|
250 |
daily_counts = df_transactions_new.groupby([df_transactions_new['timestamp'].dt.date, 'chain']).size().unstack(fill_value=0)
|
251 |
|
252 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
253 |
|
254 |
# Read the original data
|
255 |
daily_counts['timestamp'] = daily_counts.index
|
@@ -383,6 +389,47 @@ def create_transcation_visualizations():
|
|
383 |
# Show the plot
|
384 |
return fig
|
385 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
386 |
|
387 |
|
388 |
# Gradio interface
|
@@ -394,6 +441,9 @@ def dashboard():
|
|
394 |
with gr.Tab("Transactions"):
|
395 |
fig_tx_chain = create_transcation_visualizations()
|
396 |
gr.Plot(fig_tx_chain)
|
|
|
|
|
|
|
397 |
|
398 |
# Add more tabs as needed...
|
399 |
|
|
|
249 |
# Group by date and chain, count transactions
|
250 |
daily_counts = df_transactions_new.groupby([df_transactions_new['timestamp'].dt.date, 'chain']).size().unstack(fill_value=0)
|
251 |
|
252 |
+
# Ensure required chains are present
|
253 |
+
chains = ['optimism', 'base', 'ethereum']
|
254 |
+
for chain in chains:
|
255 |
+
if chain not in daily_counts.columns:
|
256 |
+
daily_counts[chain] = 0
|
257 |
+
|
258 |
+
daily_counts = daily_counts[chains]
|
259 |
|
260 |
# Read the original data
|
261 |
daily_counts['timestamp'] = daily_counts.index
|
|
|
389 |
# Show the plot
|
390 |
return fig
|
391 |
|
392 |
+
def create_active_agents_visualizations():
|
393 |
+
df_transactions_new = fetch_transactions()
|
394 |
+
df_transactions_new['timestamp'] = pd.to_datetime(df_transactions_new['timestamp'])
|
395 |
+
|
396 |
+
# Extract week and day information
|
397 |
+
df_transactions_new['week_start'] = df_transactions_new['timestamp'].dt.to_period('W').apply(lambda r: r.start_time)
|
398 |
+
df_transactions_new['weekday'] = df_transactions_new['timestamp'].dt.weekday
|
399 |
+
|
400 |
+
# Count unique agents per day
|
401 |
+
daily_agents = df_transactions_new.groupby(['week_start', 'weekday'])['from'].nunique().reset_index()
|
402 |
+
|
403 |
+
# Compute average unique agents per week
|
404 |
+
weekly_avg_agents = daily_agents.groupby('week_start')['from'].mean().reset_index()
|
405 |
+
weekly_avg_agents.rename(columns={'from': 'avg_daily_active_agents'}, inplace=True)
|
406 |
+
|
407 |
+
# Prepare data for plotting
|
408 |
+
weeks = weekly_avg_agents['week_start'].unique()
|
409 |
+
avg_agents_per_week = weekly_avg_agents['avg_daily_active_agents']
|
410 |
+
|
411 |
+
# Create the bar chart
|
412 |
+
fig = go.Figure()
|
413 |
+
|
414 |
+
fig.add_trace(go.Bar(
|
415 |
+
x=[f'Week of {week.strftime("%b %d")}' for week in weeks],
|
416 |
+
y=avg_agents_per_week,
|
417 |
+
name='Active Agents',
|
418 |
+
marker_color='blue'
|
419 |
+
))
|
420 |
+
|
421 |
+
# Update layout
|
422 |
+
fig.update_layout(
|
423 |
+
title='Daily Active Agents: Weekly Average Number of Agents with at Least 1 Transaction Daily',
|
424 |
+
xaxis_title='Week',
|
425 |
+
yaxis_title='Average Number of Active Agents',
|
426 |
+
xaxis=dict(
|
427 |
+
tickangle=-45 # Rotate x-axis labels to 45 degrees
|
428 |
+
),
|
429 |
+
template='plotly_white'
|
430 |
+
)
|
431 |
+
|
432 |
+
return fig
|
433 |
|
434 |
|
435 |
# Gradio interface
|
|
|
441 |
with gr.Tab("Transactions"):
|
442 |
fig_tx_chain = create_transcation_visualizations()
|
443 |
gr.Plot(fig_tx_chain)
|
444 |
+
with gr.Tab("DAA"):
|
445 |
+
fig_active_agents = create_active_agents_visualizations()
|
446 |
+
gr.Plot(fig_active_agents)
|
447 |
|
448 |
# Add more tabs as needed...
|
449 |
|