Added decisions/rest
This commit is contained in:
parent
c884f45c17
commit
57bb15cf1b
@ -5,7 +5,7 @@ import logging
|
||||
import pandas as pd
|
||||
import pydantic
|
||||
|
||||
from ..db_engine import db, Decision, StratGame, Player, model_to_dict, chunked, fn, Team
|
||||
from ..db_engine import db, Decision, StratGame, Player, model_to_dict, chunked, fn, Team, Card, StratPlay
|
||||
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA
|
||||
|
||||
logging.basicConfig(
|
||||
@ -119,6 +119,35 @@ async def get_decisions(
|
||||
return return_dec
|
||||
|
||||
|
||||
@router.get('/rest')
|
||||
async def get_decisions_for_rest(team_id: int, season: int = None, limit: int = 80, native_rest: bool = False):
|
||||
all_dec = Decision.select().order_by(-Decision.season, -Decision.week, -Decision.id).paginate(1, limit)
|
||||
|
||||
if season is not None:
|
||||
all_dec = all_dec.where(Decision.season == season)
|
||||
if team_id is not None:
|
||||
all_dec = all_dec.where(Decision.pitcher_team_id == team_id)
|
||||
|
||||
return_dec = []
|
||||
for x in all_dec:
|
||||
this_val = []
|
||||
this_card = Card.get_or_none(Card.player_id == x.pitcher.player_id, Card.team_id == x.pitcher_team.id)
|
||||
this_val.append(x.game.id)
|
||||
this_val.append(x.pitcher.player_id)
|
||||
this_val.append(this_card.id if this_card is not None else -1)
|
||||
this_val.append(1 if x.is_start else 0)
|
||||
if not native_rest:
|
||||
this_line = StratPlay.select(
|
||||
StratPlay.pitcher, StratPlay.game, fn.SUM(StratPlay.outs).alias('sum_outs')
|
||||
).where((StratPlay.game == x.game) & (StratPlay.pitcher == x.pitcher))
|
||||
this_val.append(float(this_line[0].sum_outs // 3) + (float(this_line[0].sum_outs % 3) * .1))
|
||||
|
||||
return_dec.append(this_val)
|
||||
|
||||
db.close()
|
||||
return Response(content=pd.DataFrame(return_dec).to_csv(index=False, header=False), media_type='text/csv')
|
||||
|
||||
|
||||
@router.patch('/{decision_id}')
|
||||
async def patch_decision(
|
||||
decision_id: int, win: Optional[int] = None, loss: Optional[int] = None, hold: Optional[int] = None,
|
||||
|
||||
Loading…
Reference in New Issue
Block a user