rosacastillo commited on
Commit
9e988e1
·
1 Parent(s): f7b82f6

missing updated file

Browse files
Files changed (1) hide show
  1. tabs/invalid_markets.py +44 -0
tabs/invalid_markets.py CHANGED
@@ -4,6 +4,7 @@ import matplotlib.pyplot as plt
4
  import seaborn as sns
5
  from seaborn import FacetGrid
6
  import plotly.express as px
 
7
 
8
 
9
  HEIGHT = 600
@@ -52,6 +53,49 @@ def plot_daily_nr_invalid_markets(invalid_trades: pd.DataFrame):
52
  )
53
 
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  def plot_ratio_invalid_trades_per_market(invalid_trades: pd.DataFrame):
56
  """Function to paint the number of invalid trades that the same market accummulates"""
57
  cat = invalid_trades["title"]
 
4
  import seaborn as sns
5
  from seaborn import FacetGrid
6
  import plotly.express as px
7
+ import plotly.graph_objs as go
8
 
9
 
10
  HEIGHT = 600
 
53
  )
54
 
55
 
56
+ def plotly_daily_nr_invalid_markets(invalid_trades: pd.DataFrame) -> gr.Plot:
57
+
58
+ daily_invalid_markets = (
59
+ invalid_trades.groupby("creation_date")
60
+ .agg(trades_count=("title", "count"), nr_markets=("title", "nunique"))
61
+ .reset_index()
62
+ )
63
+ # Create the Plotly figure
64
+ fig = go.Figure()
65
+
66
+ # Add the line trace
67
+ fig.add_trace(
68
+ go.Scatter(
69
+ x=daily_invalid_markets["creation_date"],
70
+ y=daily_invalid_markets["nr_markets"],
71
+ mode="lines+markers",
72
+ name="Number of Markets",
73
+ hovertemplate="<b>Date:</b> %{x}<br>"
74
+ + "<b>Number of Markets:</b> %{y}<br>"
75
+ + "<b>Trades Count:</b> %{text}<br>",
76
+ text=daily_invalid_markets["trades_count"], # Used in the tooltip
77
+ )
78
+ )
79
+
80
+ # Customize the layout
81
+ fig.update_layout(
82
+ title="Daily Invalid Markets",
83
+ xaxis_title="Market Creation Date",
84
+ yaxis_title="Number of Markets",
85
+ xaxis=dict(
86
+ tickangle=-45, # Rotate x-axis labels by -45 degrees
87
+ tickfont=dict(size=10), # Adjust font size if needed
88
+ ),
89
+ width=1000, # Adjusted for better fit on laptop screens
90
+ height=600, # Adjusted for better fit on laptop screens
91
+ hovermode="closest", # Improve tooltip behavior
92
+ # template="plotly_white", # Optional: set a cleaner background
93
+ )
94
+ return gr.Plot(
95
+ value=fig,
96
+ )
97
+
98
+
99
  def plot_ratio_invalid_trades_per_market(invalid_trades: pd.DataFrame):
100
  """Function to paint the number of invalid trades that the same market accummulates"""
101
  cat = invalid_trades["title"]