rosacastillo
commited on
Commit
·
da55889
1
Parent(s):
2ca4655
updating daily info
Browse files- app.py +1 -5
- data/all_trades_profitability.parquet +2 -2
- data/daily_info.parquet +2 -2
- data/fpmmTrades.parquet +2 -2
- data/fpmms.parquet +2 -2
- data/new_fpmmTrades.parquet +2 -2
- data/new_tools.parquet +2 -2
- data/outliers.parquet +2 -2
- data/summary_profitability.parquet +2 -2
- data/t_map.pkl +2 -2
- data/tools.parquet +2 -2
- data/tools_accuracy.csv +2 -2
- historical_data/all_trades_profitability_20241128_145606.parquet +3 -0
- historical_data/tools_20241128_145606.parquet +3 -0
- scripts/cleaning_old_info.py +1 -0
- scripts/pull_data.py +31 -1
- tabs/metrics.py +12 -22
- tabs/staking.py +13 -3
- tabs/trades.py +25 -7
app.py
CHANGED
@@ -7,11 +7,8 @@ from tabs.trades import (
|
|
7 |
prepare_trades,
|
8 |
get_overall_trades,
|
9 |
get_overall_by_market_trades,
|
10 |
-
get_overall_winning_trades,
|
11 |
get_overall_winning_by_market_trades,
|
12 |
-
integrated_plot_trades_per_market_by_week,
|
13 |
integrated_plot_trades_per_market_by_week_v2,
|
14 |
-
integrated_plot_winning_trades_per_market_by_week,
|
15 |
integrated_plot_winning_trades_per_market_by_week_v2,
|
16 |
)
|
17 |
from tabs.staking import plot_staking_trades_per_market_by_week
|
@@ -173,7 +170,7 @@ def prepare_data():
|
|
173 |
|
174 |
|
175 |
tools_df, trades_df, tools_accuracy_info, invalid_trades = prepare_data()
|
176 |
-
|
177 |
|
178 |
demo = gr.Blocks()
|
179 |
|
@@ -184,7 +181,6 @@ error_overall_by_markets = get_error_data_overall_by_market(error_df=error_by_ma
|
|
184 |
winning_df = get_tool_winning_rate_by_market(tools_df, inc_tools=INC_TOOLS)
|
185 |
# preparing data for the trades graph
|
186 |
trades_count_df = get_overall_trades(trades_df=trades_df)
|
187 |
-
trades_winning_rate_df = get_overall_winning_trades(trades_df=trades_df)
|
188 |
trades_by_market = get_overall_by_market_trades(trades_df=trades_df)
|
189 |
winning_trades_by_market = get_overall_winning_by_market_trades(trades_df=trades_df)
|
190 |
with demo:
|
|
|
7 |
prepare_trades,
|
8 |
get_overall_trades,
|
9 |
get_overall_by_market_trades,
|
|
|
10 |
get_overall_winning_by_market_trades,
|
|
|
11 |
integrated_plot_trades_per_market_by_week_v2,
|
|
|
12 |
integrated_plot_winning_trades_per_market_by_week_v2,
|
13 |
)
|
14 |
from tabs.staking import plot_staking_trades_per_market_by_week
|
|
|
170 |
|
171 |
|
172 |
tools_df, trades_df, tools_accuracy_info, invalid_trades = prepare_data()
|
173 |
+
trades_df = trades_df.sort_values(by="creation_timestamp", ascending=True)
|
174 |
|
175 |
demo = gr.Blocks()
|
176 |
|
|
|
181 |
winning_df = get_tool_winning_rate_by_market(tools_df, inc_tools=INC_TOOLS)
|
182 |
# preparing data for the trades graph
|
183 |
trades_count_df = get_overall_trades(trades_df=trades_df)
|
|
|
184 |
trades_by_market = get_overall_by_market_trades(trades_df=trades_df)
|
185 |
winning_trades_by_market = get_overall_winning_by_market_trades(trades_df=trades_df)
|
186 |
with demo:
|
data/all_trades_profitability.parquet
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:52f72088df284d5addddb5d6dd3e2226c8fc98c58b9048c0cf145d52016da783
|
3 |
+
size 3136886
|
data/daily_info.parquet
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:aa46e26ddf79ae4565e8572d489d377884e071f20eb19ea3c8d99684c2c00548
|
3 |
+
size 611323
|
data/fpmmTrades.parquet
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:82b8e872c454048229fd0fc85ddd3b848d9d52b6e336113f239b8ed90d745141
|
3 |
+
size 19295640
|
data/fpmms.parquet
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:bcee66dc9b6b8f6be7e8cd33f57344f126af01c503c9e08f05d571b0157109f5
|
3 |
+
size 529819
|
data/new_fpmmTrades.parquet
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:f8bf44ce187a57486f821f934fbb8f6676b14b4c4a1a1d25806c5cf6255614aa
|
3 |
+
size 2265950
|
data/new_tools.parquet
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:6b4d38de15b4da119a9706cc5addd45f1979bac11eac70442f45155805a9d5bc
|
3 |
+
size 25083815
|
data/outliers.parquet
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:81f07e9f5a1ad5c39b73068888e94260f86782f4f9511cbf548cd366ff827218
|
3 |
+
size 19361
|
data/summary_profitability.parquet
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:3047c4a75c6c90fb8132d625f7501d979ebb1fb5711ede766fa66009c6dad5e3
|
3 |
+
size 92478
|
data/t_map.pkl
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:45a4dd3205c972655bece22f01445b44cf9f445a41a8492f60083a22bd734a95
|
3 |
+
size 25661723
|
data/tools.parquet
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:87d50073d2f75f1a5f09353ac46747180046ade9be74cf8bb52167e30da2085d
|
3 |
+
size 446483909
|
data/tools_accuracy.csv
CHANGED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:c6c7f4a8a992798d4920949a1e1d839474512a6b291b3fe19138d8f921574253
|
3 |
+
size 1325
|
historical_data/all_trades_profitability_20241128_145606.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:223f85e66279e8e12547e53f16efb0af7c9c902578b1cc529c878f7ee7379ce6
|
3 |
+
size 3551233
|
historical_data/tools_20241128_145606.parquet
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:993153ec73833d33a2c28499837ee0547a9e92fdd598766faccdfff0a6eced18
|
3 |
+
size 488681078
|
scripts/cleaning_old_info.py
CHANGED
@@ -7,6 +7,7 @@ from staking import label_trades_by_staking
|
|
7 |
|
8 |
|
9 |
def clean_old_data_from_parquet_files(cutoff_date: str):
|
|
|
10 |
# Convert the string to datetime64[ns, UTC]
|
11 |
min_date_utc = pd.to_datetime(cutoff_date, format="%Y-%m-%d", utc=True)
|
12 |
|
|
|
7 |
|
8 |
|
9 |
def clean_old_data_from_parquet_files(cutoff_date: str):
|
10 |
+
print("Cleaning oldest data")
|
11 |
# Convert the string to datetime64[ns, UTC]
|
12 |
min_date_utc = pd.to_datetime(cutoff_date, format="%Y-%m-%d", utc=True)
|
13 |
|
scripts/pull_data.py
CHANGED
@@ -28,6 +28,7 @@ logging.basicConfig(level=logging.INFO)
|
|
28 |
SCRIPTS_DIR = Path(__file__).parent
|
29 |
ROOT_DIR = SCRIPTS_DIR.parent
|
30 |
DATA_DIR = ROOT_DIR / "data"
|
|
|
31 |
|
32 |
|
33 |
def block_number_to_timestamp(block_number: int, web3: Web3) -> str:
|
@@ -119,6 +120,33 @@ def updating_timestamps(rpc: str, tools_filename: str):
|
|
119 |
gc.collect()
|
120 |
|
121 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
122 |
@measure_execution_time
|
123 |
def only_new_weekly_analysis():
|
124 |
"""Run weekly analysis for the FPMMS project."""
|
@@ -166,7 +194,9 @@ def only_new_weekly_analysis():
|
|
166 |
logging.error("Error while updating timestamps of tools")
|
167 |
print(e)
|
168 |
|
169 |
-
|
|
|
|
|
170 |
|
171 |
compute_tools_accuracy()
|
172 |
|
|
|
28 |
SCRIPTS_DIR = Path(__file__).parent
|
29 |
ROOT_DIR = SCRIPTS_DIR.parent
|
30 |
DATA_DIR = ROOT_DIR / "data"
|
31 |
+
HIST_DIR = ROOT_DIR / "historical_data"
|
32 |
|
33 |
|
34 |
def block_number_to_timestamp(block_number: int, web3: Web3) -> str:
|
|
|
120 |
gc.collect()
|
121 |
|
122 |
|
123 |
+
def save_historical_data():
|
124 |
+
"""Function to save a copy of the main trades and tools file
|
125 |
+
into the historical folder"""
|
126 |
+
print("Saving historical data copies")
|
127 |
+
current_datetime = datetime.now()
|
128 |
+
|
129 |
+
timestamp = current_datetime.strftime("%Y%m%d_%H%M%S")
|
130 |
+
|
131 |
+
try:
|
132 |
+
tools = pd.read_parquet(DATA_DIR / "tools.parquet")
|
133 |
+
filename = f"tools_{timestamp}.parquet"
|
134 |
+
tools.to_parquet(HIST_DIR / filename, index=False)
|
135 |
+
|
136 |
+
except Exception as e:
|
137 |
+
print(f"Error saving tools file in the historical folder {e}")
|
138 |
+
|
139 |
+
try:
|
140 |
+
all_trades = pd.read_parquet(DATA_DIR / "all_trades_profitability.parquet")
|
141 |
+
filename = f"all_trades_profitability_{timestamp}.parquet"
|
142 |
+
all_trades.to_parquet(HIST_DIR / filename, index=False)
|
143 |
+
|
144 |
+
except Exception as e:
|
145 |
+
print(
|
146 |
+
f"Error saving all_trades_profitability file in the historical folder {e}"
|
147 |
+
)
|
148 |
+
|
149 |
+
|
150 |
@measure_execution_time
|
151 |
def only_new_weekly_analysis():
|
152 |
"""Run weekly analysis for the FPMMS project."""
|
|
|
194 |
logging.error("Error while updating timestamps of tools")
|
195 |
print(e)
|
196 |
|
197 |
+
save_historical_data()
|
198 |
+
|
199 |
+
clean_old_data_from_parquet_files("2024-09-29")
|
200 |
|
201 |
compute_tools_accuracy()
|
202 |
|
tabs/metrics.py
CHANGED
@@ -2,6 +2,7 @@ import pandas as pd
|
|
2 |
import gradio as gr
|
3 |
import plotly.express as px
|
4 |
import gc
|
|
|
5 |
|
6 |
trade_metric_choices = [
|
7 |
"mech calls",
|
@@ -155,6 +156,15 @@ def plot_trade_metrics(
|
|
155 |
)
|
156 |
else:
|
157 |
trades_filtered = get_boxplot_metrics(column_name, trades_df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
158 |
fig = px.box(
|
159 |
trades_filtered,
|
160 |
x="month_year_week",
|
@@ -170,33 +180,13 @@ def plot_trade_metrics(
|
|
170 |
legend=dict(yanchor="top", y=0.5),
|
171 |
)
|
172 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
|
|
|
|
173 |
return gr.Plot(
|
174 |
value=fig,
|
175 |
)
|
176 |
|
177 |
|
178 |
-
def plot_average_roi_per_market_by_week(trades_df: pd.DataFrame) -> gr.LinePlot:
|
179 |
-
|
180 |
-
mean_roi_per_market_by_week = (
|
181 |
-
trades_df.groupby(["market_creator", "month_year_week"])["roi"]
|
182 |
-
.mean()
|
183 |
-
.reset_index()
|
184 |
-
)
|
185 |
-
mean_roi_per_market_by_week.rename(columns={"roi": "mean_roi"}, inplace=True)
|
186 |
-
return gr.LinePlot(
|
187 |
-
value=mean_roi_per_market_by_week,
|
188 |
-
x="month_year_week",
|
189 |
-
y="ROI",
|
190 |
-
color="market_creator",
|
191 |
-
show_label=True,
|
192 |
-
interactive=True,
|
193 |
-
show_actions_button=True,
|
194 |
-
tooltip=["month_year_week", "market_creator", "mean_roi"],
|
195 |
-
height=HEIGHT,
|
196 |
-
width=WIDTH,
|
197 |
-
)
|
198 |
-
|
199 |
-
|
200 |
def get_trade_metrics_text() -> gr.Markdown:
|
201 |
metric_text = """
|
202 |
## Description of the graph
|
|
|
2 |
import gradio as gr
|
3 |
import plotly.express as px
|
4 |
import gc
|
5 |
+
from datetime import datetime
|
6 |
|
7 |
trade_metric_choices = [
|
8 |
"mech calls",
|
|
|
156 |
)
|
157 |
else:
|
158 |
trades_filtered = get_boxplot_metrics(column_name, trades_df)
|
159 |
+
# Convert string dates to datetime and sort them
|
160 |
+
all_dates_dt = sorted(
|
161 |
+
[
|
162 |
+
datetime.strptime(date, "%b-%d")
|
163 |
+
for date in trades_filtered["month_year_week"].unique()
|
164 |
+
]
|
165 |
+
)
|
166 |
+
# Convert back to string format
|
167 |
+
all_dates = [date.strftime("%b-%d") for date in all_dates_dt]
|
168 |
fig = px.box(
|
169 |
trades_filtered,
|
170 |
x="month_year_week",
|
|
|
180 |
legend=dict(yanchor="top", y=0.5),
|
181 |
)
|
182 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
183 |
+
# Update layout to force x-axis category order (hotfix for a sorting issue)
|
184 |
+
fig.update_layout(xaxis={"categoryorder": "array", "categoryarray": all_dates})
|
185 |
return gr.Plot(
|
186 |
value=fig,
|
187 |
)
|
188 |
|
189 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
def get_trade_metrics_text() -> gr.Markdown:
|
191 |
metric_text = """
|
192 |
## Description of the graph
|
tabs/staking.py
CHANGED
@@ -1,6 +1,7 @@
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
|
|
4 |
|
5 |
|
6 |
def get_overall_by_staking_traders(trades_df: pd.DataFrame) -> pd.DataFrame:
|
@@ -24,7 +25,6 @@ def plot_staking_trades_per_market_by_week(
|
|
24 |
trades_all["market_creator"] = "all"
|
25 |
|
26 |
# choose colour
|
27 |
-
|
28 |
market_colour = "green"
|
29 |
if market_creator == "pearl":
|
30 |
market_colour = "darkviolet"
|
@@ -36,11 +36,9 @@ def plot_staking_trades_per_market_by_week(
|
|
36 |
all_filtered_trades = all_filtered_trades.sort_values(
|
37 |
by="creation_timestamp", ascending=True
|
38 |
)
|
39 |
-
print(f"filtering by market creator = {market_creator}")
|
40 |
all_filtered_trades = all_filtered_trades.loc[
|
41 |
all_filtered_trades["market_creator"] == market_creator
|
42 |
]
|
43 |
-
print(all_filtered_trades.market_creator.value_counts())
|
44 |
|
45 |
if market_creator != "all":
|
46 |
all_filtered_trades["staking"] = all_filtered_trades["staking"].replace(
|
@@ -68,6 +66,16 @@ def plot_staking_trades_per_market_by_week(
|
|
68 |
]
|
69 |
}
|
70 |
trades = get_overall_by_staking_traders(all_filtered_trades)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
71 |
fig = px.bar(
|
72 |
trades,
|
73 |
x="month_year_week",
|
@@ -86,4 +94,6 @@ def plot_staking_trades_per_market_by_week(
|
|
86 |
height=600, # Adjusted for better fit on laptop screens
|
87 |
)
|
88 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
|
|
|
|
89 |
return gr.Plot(value=fig)
|
|
|
1 |
import gradio as gr
|
2 |
import pandas as pd
|
3 |
import plotly.express as px
|
4 |
+
from datetime import datetime
|
5 |
|
6 |
|
7 |
def get_overall_by_staking_traders(trades_df: pd.DataFrame) -> pd.DataFrame:
|
|
|
25 |
trades_all["market_creator"] = "all"
|
26 |
|
27 |
# choose colour
|
|
|
28 |
market_colour = "green"
|
29 |
if market_creator == "pearl":
|
30 |
market_colour = "darkviolet"
|
|
|
36 |
all_filtered_trades = all_filtered_trades.sort_values(
|
37 |
by="creation_timestamp", ascending=True
|
38 |
)
|
|
|
39 |
all_filtered_trades = all_filtered_trades.loc[
|
40 |
all_filtered_trades["market_creator"] == market_creator
|
41 |
]
|
|
|
42 |
|
43 |
if market_creator != "all":
|
44 |
all_filtered_trades["staking"] = all_filtered_trades["staking"].replace(
|
|
|
66 |
]
|
67 |
}
|
68 |
trades = get_overall_by_staking_traders(all_filtered_trades)
|
69 |
+
# Convert string dates to datetime and sort them
|
70 |
+
all_dates_dt = sorted(
|
71 |
+
[
|
72 |
+
datetime.strptime(date, "%b-%d")
|
73 |
+
for date in trades["month_year_week"].unique()
|
74 |
+
]
|
75 |
+
)
|
76 |
+
# Convert back to string format
|
77 |
+
all_dates = [date.strftime("%b-%d") for date in all_dates_dt]
|
78 |
+
|
79 |
fig = px.bar(
|
80 |
trades,
|
81 |
x="month_year_week",
|
|
|
94 |
height=600, # Adjusted for better fit on laptop screens
|
95 |
)
|
96 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
97 |
+
# Update layout to force x-axis category order (hotfix for a sorting issue)
|
98 |
+
fig.update_layout(xaxis={"categoryorder": "array", "categoryarray": all_dates})
|
99 |
return gr.Plot(value=fig)
|
tabs/trades.py
CHANGED
@@ -3,7 +3,7 @@ import pandas as pd
|
|
3 |
import plotly.express as px
|
4 |
import plotly.graph_objects as go
|
5 |
from plotly.subplots import make_subplots
|
6 |
-
|
7 |
|
8 |
HEIGHT = 400
|
9 |
WIDTH = 1100
|
@@ -163,7 +163,6 @@ def integrated_plot_trades_per_market_by_week_v2(trades_df: pd.DataFrame) -> gr.
|
|
163 |
all_filtered_trades = all_filtered_trades.sort_values(
|
164 |
by="creation_timestamp", ascending=True
|
165 |
)
|
166 |
-
|
167 |
# Create binary staking category
|
168 |
all_filtered_trades["staking_type"] = all_filtered_trades["staking"].apply(
|
169 |
lambda x: "non_agent" if x == "non_agent" else "agent"
|
@@ -177,7 +176,15 @@ def integrated_plot_trades_per_market_by_week_v2(trades_df: pd.DataFrame) -> gr.
|
|
177 |
.size()
|
178 |
.reset_index(name="trades")
|
179 |
)
|
180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
181 |
# Combine the traces
|
182 |
final_traces = []
|
183 |
market_colors = {"pearl": "darkviolet", "quickstart": "goldenrod", "all": "green"}
|
@@ -185,7 +192,6 @@ def integrated_plot_trades_per_market_by_week_v2(trades_df: pd.DataFrame) -> gr.
|
|
185 |
for market in ["pearl", "quickstart", "all"]:
|
186 |
market_data = trades[trades["market_creator"] == market]
|
187 |
agent_data = market_data[market_data["staking_type"] == "agent"]
|
188 |
-
|
189 |
trace = go.Bar(
|
190 |
x=agent_data["month_year_week"],
|
191 |
y=agent_data["trades"],
|
@@ -205,7 +211,6 @@ def integrated_plot_trades_per_market_by_week_v2(trades_df: pd.DataFrame) -> gr.
|
|
205 |
for market in ["pearl", "quickstart", "all"]:
|
206 |
market_data = trades[trades["market_creator"] == market]
|
207 |
non_agent_data = market_data[market_data["staking_type"] == "non_agent"]
|
208 |
-
|
209 |
trace = go.Bar(
|
210 |
x=non_agent_data["month_year_week"],
|
211 |
y=non_agent_data["trades"],
|
@@ -231,6 +236,8 @@ def integrated_plot_trades_per_market_by_week_v2(trades_df: pd.DataFrame) -> gr.
|
|
231 |
|
232 |
# Update x-axis format
|
233 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
|
|
|
|
234 |
|
235 |
return gr.Plot(value=fig)
|
236 |
|
@@ -270,7 +277,7 @@ def integrated_plot_winning_trades_per_market_by_week(
|
|
270 |
|
271 |
|
272 |
def integrated_plot_winning_trades_per_market_by_week_v2(
|
273 |
-
trades_df: pd.DataFrame, trader_filter: str =
|
274 |
) -> gr.Plot:
|
275 |
# adding the total
|
276 |
trades_all = trades_df.copy(deep=True)
|
@@ -285,11 +292,20 @@ def integrated_plot_winning_trades_per_market_by_week_v2(
|
|
285 |
all_filtered_trades["staking_type"] = all_filtered_trades["staking"].apply(
|
286 |
lambda x: "non_agent" if x == "non_agent" else "agent"
|
287 |
)
|
288 |
-
if trader_filter
|
289 |
final_df = get_overall_winning_by_market_trades(all_filtered_trades)
|
290 |
else:
|
291 |
final_df = get_overall_winning_by_market_and_trader_type(all_filtered_trades)
|
292 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
293 |
color_discrete_sequence = ["darkviolet", "goldenrod", "green"]
|
294 |
if trader_filter == "agent":
|
295 |
final_df = final_df[final_df["staking_type"] == "agent"]
|
@@ -313,6 +329,8 @@ def integrated_plot_winning_trades_per_market_by_week_v2(
|
|
313 |
)
|
314 |
# fig.update_layout(width=WIDTH, height=HEIGHT)
|
315 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
|
|
|
|
316 |
return gr.Plot(
|
317 |
value=fig,
|
318 |
)
|
|
|
3 |
import plotly.express as px
|
4 |
import plotly.graph_objects as go
|
5 |
from plotly.subplots import make_subplots
|
6 |
+
from datetime import datetime
|
7 |
|
8 |
HEIGHT = 400
|
9 |
WIDTH = 1100
|
|
|
163 |
all_filtered_trades = all_filtered_trades.sort_values(
|
164 |
by="creation_timestamp", ascending=True
|
165 |
)
|
|
|
166 |
# Create binary staking category
|
167 |
all_filtered_trades["staking_type"] = all_filtered_trades["staking"].apply(
|
168 |
lambda x: "non_agent" if x == "non_agent" else "agent"
|
|
|
176 |
.size()
|
177 |
.reset_index(name="trades")
|
178 |
)
|
179 |
+
# Convert string dates to datetime and sort them
|
180 |
+
all_dates_dt = sorted(
|
181 |
+
[
|
182 |
+
datetime.strptime(date, "%b-%d")
|
183 |
+
for date in trades["month_year_week"].unique()
|
184 |
+
]
|
185 |
+
)
|
186 |
+
# Convert back to string format
|
187 |
+
all_dates = [date.strftime("%b-%d") for date in all_dates_dt]
|
188 |
# Combine the traces
|
189 |
final_traces = []
|
190 |
market_colors = {"pearl": "darkviolet", "quickstart": "goldenrod", "all": "green"}
|
|
|
192 |
for market in ["pearl", "quickstart", "all"]:
|
193 |
market_data = trades[trades["market_creator"] == market]
|
194 |
agent_data = market_data[market_data["staking_type"] == "agent"]
|
|
|
195 |
trace = go.Bar(
|
196 |
x=agent_data["month_year_week"],
|
197 |
y=agent_data["trades"],
|
|
|
211 |
for market in ["pearl", "quickstart", "all"]:
|
212 |
market_data = trades[trades["market_creator"] == market]
|
213 |
non_agent_data = market_data[market_data["staking_type"] == "non_agent"]
|
|
|
214 |
trace = go.Bar(
|
215 |
x=non_agent_data["month_year_week"],
|
216 |
y=non_agent_data["trades"],
|
|
|
236 |
|
237 |
# Update x-axis format
|
238 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
239 |
+
# Update layout to force x-axis category order (hotfix for a sorting issue)
|
240 |
+
fig.update_layout(xaxis={"categoryorder": "array", "categoryarray": all_dates})
|
241 |
|
242 |
return gr.Plot(value=fig)
|
243 |
|
|
|
277 |
|
278 |
|
279 |
def integrated_plot_winning_trades_per_market_by_week_v2(
|
280 |
+
trades_df: pd.DataFrame, trader_filter: str = "all"
|
281 |
) -> gr.Plot:
|
282 |
# adding the total
|
283 |
trades_all = trades_df.copy(deep=True)
|
|
|
292 |
all_filtered_trades["staking_type"] = all_filtered_trades["staking"].apply(
|
293 |
lambda x: "non_agent" if x == "non_agent" else "agent"
|
294 |
)
|
295 |
+
if trader_filter == "all":
|
296 |
final_df = get_overall_winning_by_market_trades(all_filtered_trades)
|
297 |
else:
|
298 |
final_df = get_overall_winning_by_market_and_trader_type(all_filtered_trades)
|
299 |
|
300 |
+
# Convert string dates to datetime and sort them
|
301 |
+
all_dates_dt = sorted(
|
302 |
+
[
|
303 |
+
datetime.strptime(date, "%b-%d")
|
304 |
+
for date in final_df["month_year_week"].unique()
|
305 |
+
]
|
306 |
+
)
|
307 |
+
# Convert back to string format
|
308 |
+
all_dates = [date.strftime("%b-%d") for date in all_dates_dt]
|
309 |
color_discrete_sequence = ["darkviolet", "goldenrod", "green"]
|
310 |
if trader_filter == "agent":
|
311 |
final_df = final_df[final_df["staking_type"] == "agent"]
|
|
|
329 |
)
|
330 |
# fig.update_layout(width=WIDTH, height=HEIGHT)
|
331 |
fig.update_xaxes(tickformat="%b %d\n%Y")
|
332 |
+
# Update layout to force x-axis category order (hotfix for a sorting issue)
|
333 |
+
fig.update_layout(xaxis={"categoryorder": "array", "categoryarray": all_dates})
|
334 |
return gr.Plot(
|
335 |
value=fig,
|
336 |
)
|