nesticot commited on
Commit
1471665
·
verified ·
1 Parent(s): 6082024

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -38
app.py CHANGED
@@ -645,46 +645,47 @@ def server(input, output, session):
645
  }
646
  levelt = {
647
  11:1,
648
- 14:4
 
649
  }
650
 
651
-
652
- fg_api = f'https://www.fangraphs.com/api/leaders/minor-league/data?pos=all&level={levelt[sport_id]}&lg={lg_dict[sport_id]}&stats=pit&qual=0&type=2&team=&season=2024&seasonEnd=2024&org=&ind=0&splitTeam=false'
653
- response = requests.get(fg_api)
654
- data = response.json()
655
- df_fg = pl.DataFrame(data)
656
- if pitcher_id not in dict_mlb_fg.keys():
657
- #ax_fv_table.text(x=0.5, y=0.5, s='No Scouting Data', style='italic', ha='center', va='center', fontsize=20, bbox=dict(facecolor='white', alpha=1, pad=10))
658
- metrics_data = {
659
- "Pitches": new_player_metrics['pitches'][0],
660
- "PA": new_player_metrics['pa'][0],
661
- "BIP": new_player_metrics['bip'][0],
662
- "HR": f"{new_player_metrics['home_run'][0]:.0f}",
663
- "K": f"{new_player_metrics['k'][0]:.0f}",
664
- "BB": f"{new_player_metrics['bb'][0]:.0f}",
665
- }
666
- else:
667
- df_fg_filter = df_fg.filter(pl.col('minormasterid') == dict_mlb_fg[pitcher_id])
668
- # Metrics data table
669
- metrics_data = {
670
- "G": f"{df_fg_filter['G'][0]:.0f}",
671
- "IP": f"{df_fg_filter['IP'][0]:.1f}",
672
- "Pitches": f"{new_player_metrics['pitches'][0]:.0f}",
673
- "PA": f"{df_fg_filter['TBF'][0]:.0f}",
674
- "BIP": new_player_metrics['bip'][0],
675
- "ERA": f"{df_fg_filter['ERA'][0]:.2f}",
676
- "FIP": f"{df_fg_filter['FIP'][0]:.2f}",
677
- "WHIP": f"{df_fg_filter['WHIP'][0]:.2f}",
678
- }
679
- df_table = pd.DataFrame(metrics_data, index=[0])
680
- ax_table.axis('off')
681
- table = ax_table.table(cellText=df_table.values, colLabels=df_table.columns, cellLoc='center', loc='bottom', bbox=[0.07, 0, 0.86, 1])
682
- for key, cell in table.get_celld().items():
683
- if key[0] == 0:
684
- cell.set_text_props(fontweight='bold')
685
- table.auto_set_font_size(False)
686
- table.set_fontsize(12)
687
- table.scale(1, 1.5)
688
 
689
  # Additional subplots for spacing
690
  ax_top = fig.add_subplot(gs[0, :])
 
645
  }
646
  levelt = {
647
  11:1,
648
+ 14:4,
649
+
650
  }
651
 
652
+ if sport_id != 17:
653
+ fg_api = f'https://www.fangraphs.com/api/leaders/minor-league/data?pos=all&level={levelt[sport_id]}&lg={lg_dict[sport_id]}&stats=pit&qual=0&type=2&team=&season=2024&seasonEnd=2024&org=&ind=0&splitTeam=false'
654
+ response = requests.get(fg_api)
655
+ data = response.json()
656
+ df_fg = pl.DataFrame(data)
657
+ if pitcher_id not in dict_mlb_fg.keys():
658
+ #ax_fv_table.text(x=0.5, y=0.5, s='No Scouting Data', style='italic', ha='center', va='center', fontsize=20, bbox=dict(facecolor='white', alpha=1, pad=10))
659
+ metrics_data = {
660
+ "Pitches": new_player_metrics['pitches'][0],
661
+ "PA": new_player_metrics['pa'][0],
662
+ "BIP": new_player_metrics['bip'][0],
663
+ "HR": f"{new_player_metrics['home_run'][0]:.0f}",
664
+ "K": f"{new_player_metrics['k'][0]:.0f}",
665
+ "BB": f"{new_player_metrics['bb'][0]:.0f}",
666
+ }
667
+ else:
668
+ df_fg_filter = df_fg.filter(pl.col('minormasterid') == dict_mlb_fg[pitcher_id])
669
+ # Metrics data table
670
+ metrics_data = {
671
+ "G": f"{df_fg_filter['G'][0]:.0f}",
672
+ "IP": f"{df_fg_filter['IP'][0]:.1f}",
673
+ "Pitches": f"{new_player_metrics['pitches'][0]:.0f}",
674
+ "PA": f"{df_fg_filter['TBF'][0]:.0f}",
675
+ "BIP": new_player_metrics['bip'][0],
676
+ "ERA": f"{df_fg_filter['ERA'][0]:.2f}",
677
+ "FIP": f"{df_fg_filter['FIP'][0]:.2f}",
678
+ "WHIP": f"{df_fg_filter['WHIP'][0]:.2f}",
679
+ }
680
+ df_table = pd.DataFrame(metrics_data, index=[0])
681
+ ax_table.axis('off')
682
+ table = ax_table.table(cellText=df_table.values, colLabels=df_table.columns, cellLoc='center', loc='bottom', bbox=[0.07, 0, 0.86, 1])
683
+ for key, cell in table.get_celld().items():
684
+ if key[0] == 0:
685
+ cell.set_text_props(fontweight='bold')
686
+ table.auto_set_font_size(False)
687
+ table.set_fontsize(12)
688
+ table.scale(1, 1.5)
689
 
690
  # Additional subplots for spacing
691
  ax_top = fig.add_subplot(gs[0, :])