rosacastillo
commited on
Commit
·
6ca7c50
1
Parent(s):
a8f865e
updating the metrics plot
Browse files- tabs/metrics.py +17 -9
tabs/metrics.py
CHANGED
@@ -93,15 +93,26 @@ def get_metrics(
|
|
93 |
return trades_filtered
|
94 |
|
95 |
|
96 |
-
def get_boxplot_metrics(
|
97 |
-
metric_name: str, column_name: str, trades_df: pd.DataFrame
|
98 |
-
) -> pd.DataFrame:
|
99 |
# this is to filter out the data before 2023-09-01
|
100 |
trades_filtered = trades_df[trades_df["creation_timestamp"] > "2023-09-01"]
|
101 |
trades_filtered = trades_filtered[
|
102 |
-
["month_year_week", "market_creator", column_name]
|
103 |
]
|
104 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
def plot2_trade_details(
|
107 |
metric_name: str, market_creator: str, trades_df: pd.DataFrame
|
@@ -164,16 +175,13 @@ def plot_trade_metrics(metric_name: str, trades_df: pd.DataFrame) -> gr.Plot:
|
|
164 |
column_name = metric_name
|
165 |
yaxis_title = "Gross profit per trade (xDAI)"
|
166 |
|
167 |
-
trades_filtered = trades_df
|
168 |
-
trades_filtered = trades_filtered[
|
169 |
-
["month_year_week", "market_creator", column_name]
|
170 |
-
]
|
171 |
fig = px.box(
|
172 |
trades_filtered,
|
173 |
x="month_year_week",
|
174 |
y=column_name,
|
175 |
color="market_creator",
|
176 |
-
color_discrete_sequence=["goldenrod", "purple"],
|
177 |
)
|
178 |
fig.update_traces(boxmean=True)
|
179 |
fig.update_layout(
|
|
|
93 |
return trades_filtered
|
94 |
|
95 |
|
96 |
+
def get_boxplot_metrics(column_name: str, trades_df: pd.DataFrame) -> pd.DataFrame:
|
|
|
|
|
97 |
# this is to filter out the data before 2023-09-01
|
98 |
trades_filtered = trades_df[trades_df["creation_timestamp"] > "2023-09-01"]
|
99 |
trades_filtered = trades_filtered[
|
100 |
+
["creation_timestamp", "month_year_week", "market_creator", column_name]
|
101 |
]
|
102 |
|
103 |
+
# adding the total
|
104 |
+
trades_filtered_all = trades_filtered.copy(deep=True)
|
105 |
+
trades_filtered_all["market_creator"] = "all"
|
106 |
+
|
107 |
+
# merging both dataframes
|
108 |
+
all_filtered_trades = pd.concat(
|
109 |
+
[trades_filtered, trades_filtered_all], ignore_index=True
|
110 |
+
)
|
111 |
+
all_filtered_trades = all_filtered_trades.sort_values(
|
112 |
+
by="creation_timestamp", ascending=True
|
113 |
+
)
|
114 |
+
return all_filtered_trades
|
115 |
+
|
116 |
|
117 |
def plot2_trade_details(
|
118 |
metric_name: str, market_creator: str, trades_df: pd.DataFrame
|
|
|
175 |
column_name = metric_name
|
176 |
yaxis_title = "Gross profit per trade (xDAI)"
|
177 |
|
178 |
+
trades_filtered = get_boxplot_metrics(column_name, trades_df)
|
|
|
|
|
|
|
179 |
fig = px.box(
|
180 |
trades_filtered,
|
181 |
x="month_year_week",
|
182 |
y=column_name,
|
183 |
color="market_creator",
|
184 |
+
color_discrete_sequence=["goldenrod", "darkgreen", "purple"],
|
185 |
)
|
186 |
fig.update_traces(boxmean=True)
|
187 |
fig.update_layout(
|