nesticot commited on
Commit
09ff1fe
·
verified ·
1 Parent(s): d307d31

Update functions/PitchPlotFunctions.py

Browse files
Files changed (1) hide show
  1. functions/PitchPlotFunctions.py +23 -4
functions/PitchPlotFunctions.py CHANGED
@@ -180,7 +180,7 @@ class PitchPlotFunctions:
180
  ax.axis('off')
181
 
182
  # Function to display player bio information on the given axis
183
- def player_bio(self, pitcher_id: str, ax: plt.Axes, start_date: str, end_date: str, batter_hand: list):
184
  """
185
  Fetches and displays the player's bio information on the given axis.
186
 
@@ -191,6 +191,16 @@ class PitchPlotFunctions:
191
  end_date (str): The end date for the bio information.
192
  batter_hand (list): The list of batter hands (e.g., ['R'] or ['L']).
193
  """
 
 
 
 
 
 
 
 
 
 
194
  # Construct the URL to fetch player data
195
  url = f"https://statsapi.mlb.com/api/v1/people?personIds={pitcher_id}&hydrate=currentTeam"
196
  # Send a GET request to the URL and parse the JSON response
@@ -211,7 +221,16 @@ class PitchPlotFunctions:
211
  batter_hand_text = ', vs LHH'
212
  else:
213
  batter_hand_text = ''
214
- ax.text(0.5, 0.40, f'{start_date} to {end_date}{batter_hand_text}', va='top', ha='center', fontsize=12, fontstyle='italic')
 
 
 
 
 
 
 
 
 
215
  # Turn off the axis
216
  ax.axis('off')
217
 
@@ -540,7 +559,7 @@ class PitchPlotFunctions:
540
  )
541
  return df
542
 
543
- def final_plot(self, df: pl.DataFrame, pitcher_id: str, plot_picker: str, sport_id: int):
544
  """
545
  Creates a final plot with player headshot, bio, logo, and pitch movement plots.
546
 
@@ -570,7 +589,7 @@ class PitchPlotFunctions:
570
 
571
  # Plot player headshot, bio, and logo
572
  self.player_headshot(pitcher_id=pitcher_id, ax=ax_headshot, sport_id=sport_id)
573
- self.player_bio(pitcher_id=pitcher_id, ax=ax_bio, start_date=start_date, end_date=end_date, batter_hand=batter_hand)
574
  self.plot_logo(pitcher_id=pitcher_id, ax=ax_logo)
575
 
576
  # Create subplot for the main plot
 
180
  ax.axis('off')
181
 
182
  # Function to display player bio information on the given axis
183
+ def player_bio(self, pitcher_id: str, ax: plt.Axes, start_date: str, end_date: str, batter_hand: list,game_type: list = ['R']):
184
  """
185
  Fetches and displays the player's bio information on the given axis.
186
 
 
191
  end_date (str): The end date for the bio information.
192
  batter_hand (list): The list of batter hands (e.g., ['R'] or ['L']).
193
  """
194
+ type_dict = {'R':'Regular Season',
195
+ 'S':'Spring',
196
+ 'P':'Playoffs' }
197
+
198
+ split_title = {
199
+ 'all':'',
200
+ 'right':' vs RHH',
201
+ 'left':' vs LHH'
202
+ }
203
+
204
  # Construct the URL to fetch player data
205
  url = f"https://statsapi.mlb.com/api/v1/people?personIds={pitcher_id}&hydrate=currentTeam"
206
  # Send a GET request to the URL and parse the JSON response
 
221
  batter_hand_text = ', vs LHH'
222
  else:
223
  batter_hand_text = ''
224
+
225
+ # Set header text
226
+ if game_type[0] in ['S','P']:
227
+ ax.text(0.5, 0.4, f'{start_date} to {end_date} ({type_dict[game_type[0]]}){batter_hand_text}', va='bottom', ha='center',
228
+ fontsize=12, fontstyle='italic')
229
+
230
+ else:
231
+ ax.text(0.5, 0.4, f'{start_date} to {end_date}{batter_hand_text}', va='bottom', ha='center',
232
+ fontsize=12, fontstyle='italic')
233
+ # ax.text(0.5, 0.40, f'{start_date} to {end_date}{batter_hand_text}', va='top', ha='center', fontsize=12, fontstyle='italic')
234
  # Turn off the axis
235
  ax.axis('off')
236
 
 
559
  )
560
  return df
561
 
562
+ def final_plot(self, df: pl.DataFrame, pitcher_id: str, plot_picker: str, sport_id: int,game_type: list = ['R']):
563
  """
564
  Creates a final plot with player headshot, bio, logo, and pitch movement plots.
565
 
 
589
 
590
  # Plot player headshot, bio, and logo
591
  self.player_headshot(pitcher_id=pitcher_id, ax=ax_headshot, sport_id=sport_id)
592
+ self.player_bio(pitcher_id=pitcher_id, ax=ax_bio, start_date=start_date, end_date=end_date, batter_hand=batter_hand,game_type=game_type)
593
  self.plot_logo(pitcher_id=pitcher_id, ax=ax_logo)
594
 
595
  # Create subplot for the main plot