rosacastillo
commited on
Commit
·
b282311
1
Parent(s):
270b24f
Fixing size and graphs of invalid markets
Browse files- app.py +1 -1
- tabs/invalid_markets.py +31 -17
app.py
CHANGED
@@ -313,7 +313,7 @@ with demo:
|
|
313 |
with gr.Row():
|
314 |
gr.Markdown("# Top markets with invalid trades")
|
315 |
with gr.Row():
|
316 |
-
plot_top_invalid_markets(invalid_trades)
|
317 |
|
318 |
with gr.Row():
|
319 |
gr.Markdown("# Daily distribution of invalid markets")
|
|
|
313 |
with gr.Row():
|
314 |
gr.Markdown("# Top markets with invalid trades")
|
315 |
with gr.Row():
|
316 |
+
top_invalid_markets = plot_top_invalid_markets(invalid_trades)
|
317 |
|
318 |
with gr.Row():
|
319 |
gr.Markdown("# Daily distribution of invalid markets")
|
tabs/invalid_markets.py
CHANGED
@@ -3,16 +3,22 @@ import gradio as gr
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
import seaborn as sns
|
5 |
from seaborn import FacetGrid
|
|
|
|
|
|
|
|
|
6 |
|
7 |
|
8 |
def plot_daily_dist_invalid_trades(invalid_trades: pd.DataFrame):
|
9 |
"""Function to paint the distribution of daily invalid trades, no matter which market"""
|
10 |
-
|
11 |
-
plt.
|
12 |
plt.xlabel("Creation date")
|
13 |
plt.ylabel("Daily number of invalid trades")
|
14 |
-
plt.
|
15 |
-
|
|
|
|
|
16 |
|
17 |
|
18 |
def plot_daily_nr_invalid_markets(invalid_trades: pd.DataFrame):
|
@@ -22,13 +28,16 @@ def plot_daily_nr_invalid_markets(invalid_trades: pd.DataFrame):
|
|
22 |
.agg(trades_count=("title", "count"), nr_markets=("title", "nunique"))
|
23 |
.reset_index()
|
24 |
)
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
32 |
|
33 |
|
34 |
def plot_ratio_invalid_trades_per_market(invalid_trades: pd.DataFrame):
|
@@ -49,12 +58,17 @@ def plot_top_invalid_markets(invalid_trades: pd.DataFrame):
|
|
49 |
"""Function to paint the top markets with the highest number of invalid trades"""
|
50 |
top_invalid_markets = invalid_trades.title.value_counts().reset_index()
|
51 |
top_invalid_markets.rename(columns={"count": "nr_invalid_trades"}, inplace=True)
|
52 |
-
|
53 |
-
|
54 |
-
top_invalid_markets.head(),
|
55 |
x="nr_invalid_trades",
|
56 |
y="title",
|
57 |
-
|
58 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
)
|
60 |
-
return gr.Plot(value=plot.get_figure())
|
|
|
3 |
import matplotlib.pyplot as plt
|
4 |
import seaborn as sns
|
5 |
from seaborn import FacetGrid
|
6 |
+
from matplotlib.axes import Axes
|
7 |
+
|
8 |
+
HEIGHT = 600
|
9 |
+
WIDTH = 1000
|
10 |
|
11 |
|
12 |
def plot_daily_dist_invalid_trades(invalid_trades: pd.DataFrame):
|
13 |
"""Function to paint the distribution of daily invalid trades, no matter which market"""
|
14 |
+
|
15 |
+
plt.title("Distribution of daily invalid trades over time")
|
16 |
plt.xlabel("Creation date")
|
17 |
plt.ylabel("Daily number of invalid trades")
|
18 |
+
plt.xticks(rotation=45, ha="right")
|
19 |
+
plot2: Axes = sns.histplot(data=invalid_trades, x="creation_date", kde=True)
|
20 |
+
daily_trades_fig = plot2.get_figure()
|
21 |
+
return gr.Plot(value=daily_trades_fig)
|
22 |
|
23 |
|
24 |
def plot_daily_nr_invalid_markets(invalid_trades: pd.DataFrame):
|
|
|
28 |
.agg(trades_count=("title", "count"), nr_markets=("title", "nunique"))
|
29 |
.reset_index()
|
30 |
)
|
31 |
+
return gr.LinePlot(
|
32 |
+
value=daily_invalid_markets,
|
33 |
+
x="creation_date",
|
34 |
+
y="nr_markets",
|
35 |
+
interactive=True,
|
36 |
+
show_actions_button=True,
|
37 |
+
tooltip=["creation_date", "nr_markets", "count"],
|
38 |
+
height=HEIGHT,
|
39 |
+
width=WIDTH,
|
40 |
+
)
|
41 |
|
42 |
|
43 |
def plot_ratio_invalid_trades_per_market(invalid_trades: pd.DataFrame):
|
|
|
58 |
"""Function to paint the top markets with the highest number of invalid trades"""
|
59 |
top_invalid_markets = invalid_trades.title.value_counts().reset_index()
|
60 |
top_invalid_markets.rename(columns={"count": "nr_invalid_trades"}, inplace=True)
|
61 |
+
return gr.BarPlot(
|
62 |
+
title="Top markets with the highest number of invalid trades",
|
|
|
63 |
x="nr_invalid_trades",
|
64 |
y="title",
|
65 |
+
x_title="Nr_invalid_trades",
|
66 |
+
y_title="Market title",
|
67 |
+
show_label=True,
|
68 |
+
interactive=True,
|
69 |
+
show_actions_button=True,
|
70 |
+
value=top_invalid_markets,
|
71 |
+
tooltip=["title", "nr_invalid_trades"],
|
72 |
+
height=HEIGHT,
|
73 |
+
width=WIDTH,
|
74 |
)
|
|