Added /scouting
This commit is contained in:
parent
995735d878
commit
d5386f86f8
@ -3,7 +3,7 @@ from fastapi import FastAPI
|
|||||||
from.routers_v2 import (
|
from.routers_v2 import (
|
||||||
current, teams, rarity, cardsets, players, packtypes, packs, cards, events, results, rewards,
|
current, teams, rarity, cardsets, players, packtypes, packs, cards, events, results, rewards,
|
||||||
batstats, pitstats, notifications, paperdex, gamerewards, gauntletrewards, gauntletruns, battingcards,
|
batstats, pitstats, notifications, paperdex, gamerewards, gauntletrewards, gauntletruns, battingcards,
|
||||||
battingcardratings, pitchingcards, pitchingcardratings, cardpositions)
|
battingcardratings, pitchingcards, pitchingcardratings, cardpositions, scouting)
|
||||||
|
|
||||||
app = FastAPI(
|
app = FastAPI(
|
||||||
responses={404: {'description': 'Not found'}}
|
responses={404: {'description': 'Not found'}}
|
||||||
@ -32,3 +32,4 @@ app.include_router(battingcardratings.router)
|
|||||||
app.include_router(pitchingcards.router)
|
app.include_router(pitchingcards.router)
|
||||||
app.include_router(pitchingcardratings.router)
|
app.include_router(pitchingcardratings.router)
|
||||||
app.include_router(cardpositions.router)
|
app.include_router(cardpositions.router)
|
||||||
|
app.include_router(scouting.router)
|
||||||
|
|||||||
24
app/player_scouting.py
Normal file
24
app/player_scouting.py
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
from typing import Literal, Optional
|
||||||
|
from pybaseball import playerid_reverse_lookup
|
||||||
|
|
||||||
|
import pydantic
|
||||||
|
|
||||||
|
|
||||||
|
class PlayerIds(pydantic.BaseModel):
|
||||||
|
bbref: str = None
|
||||||
|
fangraphs: int = None
|
||||||
|
retro: str = None
|
||||||
|
mlbam: int = None
|
||||||
|
|
||||||
|
|
||||||
|
def get_player_ids(player_id: str, id_type: Literal['bbref', 'fangraphs']) -> PlayerIds | None:
|
||||||
|
q = playerid_reverse_lookup([player_id], key_type=id_type)
|
||||||
|
if len(q.values) == 0:
|
||||||
|
return None
|
||||||
|
else:
|
||||||
|
return PlayerIds(
|
||||||
|
bbref=q.loc[0].key_bbref,
|
||||||
|
fangraphs=q.loc[0].key_fangraphs,
|
||||||
|
retro=q.loc[0].key_retro,
|
||||||
|
mlbam=q.loc[0].key_mlbam
|
||||||
|
)
|
||||||
39
app/routers_v2/scouting.py
Normal file
39
app/routers_v2/scouting.py
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
from datetime import datetime
|
||||||
|
from fastapi import APIRouter, Depends, HTTPException, Response, Query
|
||||||
|
from typing import Optional
|
||||||
|
import logging
|
||||||
|
import pydantic
|
||||||
|
from pandas import DataFrame
|
||||||
|
|
||||||
|
from ..db_engine import db, model_to_dict, fn, query_to_csv, complex_data_to_csv, Player
|
||||||
|
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA, int_timestamp
|
||||||
|
from ..player_scouting import get_player_ids
|
||||||
|
|
||||||
|
logging.basicConfig(
|
||||||
|
filename=LOG_DATA['filename'],
|
||||||
|
format=LOG_DATA['format'],
|
||||||
|
level=LOG_DATA['log_level']
|
||||||
|
)
|
||||||
|
|
||||||
|
router = APIRouter(
|
||||||
|
prefix='/api/v2/scouting',
|
||||||
|
tags=['scouting']
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@router.get('/playerkeys')
|
||||||
|
async def get_player_keys(player_id: list = Query(default=None)):
|
||||||
|
all_keys = []
|
||||||
|
for x in player_id:
|
||||||
|
this_player = Player.get_or_none(Player.player_id == x)
|
||||||
|
if this_player is not None:
|
||||||
|
this_keys = get_player_ids(this_player.bbref_id, id_type='bbref')
|
||||||
|
if this_keys is not None:
|
||||||
|
all_keys.append(this_keys)
|
||||||
|
|
||||||
|
return_val = {'count': len(all_keys), 'keys': [
|
||||||
|
dict(x) for x in all_keys
|
||||||
|
]}
|
||||||
|
db.close()
|
||||||
|
return return_val
|
||||||
|
|
||||||
Loading…
Reference in New Issue
Block a user