tessida commited on
Commit
548dd58
·
verified ·
1 Parent(s): 3ff20a2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -5
app.py CHANGED
@@ -52,13 +52,28 @@ def on_bettype_change(selected):
52
  return gr.update(value=is_all)
53
 
54
  def generate_stacked_bar(data, x, y, category, title, y_label):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  fig = go.Figure()
56
  for cat in sorted(data[category].unique()):
57
  sub_df = data[data[category] == cat]
58
  fig.add_trace(go.Bar(
59
  x=sub_df[x],
60
  y=sub_df[y],
61
- name=str(cat)
 
62
  ))
63
 
64
  fig.add_hline(y=0, line_dash="dash", line_color="gray", opacity=0.6)
@@ -123,7 +138,7 @@ def generate_charts(market_type, player_name, bettype_filters):
123
 
124
  summary = (
125
  filtered
126
- .groupby(['line', 'direction', 'customerlevelid'], as_index=False)
127
  .agg(
128
  pot_risk=('pot_risk', 'sum'),
129
  bet_count=('geallbetid', 'nunique')
@@ -137,17 +152,16 @@ def generate_charts(market_type, player_name, bettype_filters):
137
  lambda row: -row['bet_count'] if row['direction'] == 'Under' else row['bet_count'], axis=1
138
  )
139
 
140
- summary['customerlevelid'] = summary['customerlevelid'].astype(str)
141
  bettype_str = ", ".join(bettype_filters) if bettype_filters else "All"
142
 
143
  fig_risk = generate_stacked_bar(
144
- summary, 'line', 'pot_risk', 'customerlevelid',
145
  f"Liability for {player_name} - {market_type} ({bettype_str})",
146
  f"Potential Risk ({bettype_str})"
147
  )
148
 
149
  fig_bets = generate_stacked_bar(
150
- summary, 'line', 'bet_count', 'customerlevelid',
151
  f"Bet Count for {player_name} - {market_type} ({bettype_str})",
152
  f"Bet Count ({bettype_str})"
153
  )
 
52
  return gr.update(value=is_all)
53
 
54
  def generate_stacked_bar(data, x, y, category, title, y_label):
55
+ segment_colors = {
56
+ 'New': 'white',
57
+ 'Normal': 'gray',
58
+ 'Retail': 'black',
59
+ 'Outstanding': 'green',
60
+ 'VIP': 'purple',
61
+ 'Monitored': 'yellow',
62
+ 'Live Advantage': 'orange',
63
+ 'No Value': 'red',
64
+ 'Marker': 'blue',
65
+ 'Concerning': 'pink',
66
+ 'Other': 'brown'
67
+ }
68
+
69
  fig = go.Figure()
70
  for cat in sorted(data[category].unique()):
71
  sub_df = data[data[category] == cat]
72
  fig.add_trace(go.Bar(
73
  x=sub_df[x],
74
  y=sub_df[y],
75
+ name=cat,
76
+ marker_color=segment_colors.get(cat, 'gray')
77
  ))
78
 
79
  fig.add_hline(y=0, line_dash="dash", line_color="gray", opacity=0.6)
 
138
 
139
  summary = (
140
  filtered
141
+ .groupby(['line', 'direction', 'customerbracket'], as_index=False)
142
  .agg(
143
  pot_risk=('pot_risk', 'sum'),
144
  bet_count=('geallbetid', 'nunique')
 
152
  lambda row: -row['bet_count'] if row['direction'] == 'Under' else row['bet_count'], axis=1
153
  )
154
 
 
155
  bettype_str = ", ".join(bettype_filters) if bettype_filters else "All"
156
 
157
  fig_risk = generate_stacked_bar(
158
+ summary, 'line', 'pot_risk', 'customerbracket',
159
  f"Liability for {player_name} - {market_type} ({bettype_str})",
160
  f"Potential Risk ({bettype_str})"
161
  )
162
 
163
  fig_bets = generate_stacked_bar(
164
+ summary, 'line', 'bet_count', 'customerbracket',
165
  f"Bet Count for {player_name} - {market_type} ({bettype_str})",
166
  f"Bet Count ({bettype_str})"
167
  )