Bug fixes
This commit is contained in:
parent
48e3089e50
commit
635baa91ad
@ -4,7 +4,7 @@ import logging
|
|||||||
import pydantic
|
import pydantic
|
||||||
from pandas import DataFrame
|
from pandas import DataFrame
|
||||||
|
|
||||||
from ..db_engine import db, Player, model_to_dict, chunked
|
from ..db_engine import db, Player, model_to_dict, chunked, fn
|
||||||
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA
|
from ..dependencies import oauth2_scheme, valid_token, LOG_DATA
|
||||||
|
|
||||||
logging.basicConfig(filename=LOG_DATA['filename'], format=LOG_DATA['format'], level=LOG_DATA['log_level'])
|
logging.basicConfig(filename=LOG_DATA['filename'], format=LOG_DATA['format'], level=LOG_DATA['log_level'])
|
||||||
@ -46,14 +46,17 @@ class PlayerList(pydantic.BaseModel):
|
|||||||
|
|
||||||
@router.get('')
|
@router.get('')
|
||||||
async def get_players(
|
async def get_players(
|
||||||
season: Optional[int], team_id: list = Query(default=None), pos: list = Query(default=None),
|
season: Optional[int], name: Optional[str] = None, team_id: list = Query(default=None),
|
||||||
is_injured: Optional[bool] = None, sort: Optional[str] = None, short_output: Optional[bool] = False,
|
pos: list = Query(default=None), is_injured: Optional[bool] = None, sort: Optional[str] = None,
|
||||||
csv: Optional[bool] = False):
|
short_output: Optional[bool] = False, csv: Optional[bool] = False):
|
||||||
all_players = Player.select_season(season)
|
all_players = Player.select_season(season)
|
||||||
|
|
||||||
if team_id is not None:
|
if team_id is not None:
|
||||||
all_players = all_players.where(Player.team_id << team_id)
|
all_players = all_players.where(Player.team_id << team_id)
|
||||||
|
|
||||||
|
if name is not None:
|
||||||
|
all_players = all_players.where(fn.lower(Player.name) == name.lower())
|
||||||
|
|
||||||
if pos is not None:
|
if pos is not None:
|
||||||
p_list = [x.upper() for x in pos]
|
p_list = [x.upper() for x in pos]
|
||||||
all_players = all_players.where(
|
all_players = all_players.where(
|
||||||
|
|||||||
@ -26,12 +26,12 @@ async def get_standings(
|
|||||||
t_query = Team.select().where(fn.Lower(Team.abbrev) << [x.lower() for x in team_abbrev])
|
t_query = Team.select().where(fn.Lower(Team.abbrev) << [x.lower() for x in team_abbrev])
|
||||||
standings = standings.where(Standings.team << t_query)
|
standings = standings.where(Standings.team << t_query)
|
||||||
|
|
||||||
if league_abbrev:
|
if league_abbrev is not None:
|
||||||
l_query = Division.select().where(fn.Lower(Division.league_abbrev) << league_abbrev.lower())
|
l_query = Division.select().where(fn.Lower(Division.league_abbrev) == league_abbrev.lower())
|
||||||
standings = standings.where(Standings.team.division << l_query)
|
standings = standings.where(Standings.team.division << l_query)
|
||||||
|
|
||||||
if division_abbrev:
|
if division_abbrev is not None:
|
||||||
d_query = Division.select().where(fn.Lower(Division.division_abbrev) << division_abbrev.lower())
|
d_query = Division.select().where(fn.Lower(Division.division_abbrev) == division_abbrev.lower())
|
||||||
standings = standings.where(Standings.team.division << d_query)
|
standings = standings.where(Standings.team.division << d_query)
|
||||||
|
|
||||||
def win_pct(this_team_stan):
|
def win_pct(this_team_stan):
|
||||||
@ -41,7 +41,7 @@ async def get_standings(
|
|||||||
return (this_team_stan.wins / (this_team_stan.wins + this_team_stan.losses)) + \
|
return (this_team_stan.wins / (this_team_stan.wins + this_team_stan.losses)) + \
|
||||||
(this_team_stan.run_diff * .000001)
|
(this_team_stan.run_diff * .000001)
|
||||||
|
|
||||||
div_teams = [team_stan for team_stan in standings]
|
div_teams = [x for x in standings]
|
||||||
div_teams.sort(key=lambda team: win_pct(team), reverse=True)
|
div_teams.sort(key=lambda team: win_pct(team), reverse=True)
|
||||||
|
|
||||||
return_standings = {
|
return_standings = {
|
||||||
|
|||||||
@ -3,7 +3,7 @@ from typing import List, Optional
|
|||||||
import logging
|
import logging
|
||||||
import pydantic
|
import pydantic
|
||||||
|
|
||||||
from ..db_engine import db, Team, Manager, Division, model_to_dict, chunked
|
from ..db_engine import db, Team, Manager, Division, model_to_dict, chunked, fn
|
||||||
from ..dependencies import oauth2_scheme, valid_token
|
from ..dependencies import oauth2_scheme, valid_token
|
||||||
|
|
||||||
router = APIRouter(
|
router = APIRouter(
|
||||||
@ -50,7 +50,8 @@ async def get_teams(
|
|||||||
if owner_id:
|
if owner_id:
|
||||||
all_teams = all_teams.where((Team.gmid << owner_id) | (Team.gmid2 << owner_id))
|
all_teams = all_teams.where((Team.gmid << owner_id) | (Team.gmid2 << owner_id))
|
||||||
if team_abbrev is not None:
|
if team_abbrev is not None:
|
||||||
all_teams = all_teams.where(Team.abbrev << team_abbrev)
|
team_list = [x.lower() for x in team_abbrev]
|
||||||
|
all_teams = all_teams.where(fn.lower(Team.abbrev) << team_list)
|
||||||
if active_only:
|
if active_only:
|
||||||
all_teams = all_teams.where(
|
all_teams = all_teams.where(
|
||||||
~(Team.abbrev.endswith('IL')) & ~(Team.abbrev.endswith('MiL'))
|
~(Team.abbrev.endswith('IL')) & ~(Team.abbrev.endswith('MiL'))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user