Skip to content

Commit

Permalink
Fixed soem mroe things and changed model
Browse files Browse the repository at this point in the history
  • Loading branch information
day-mon committed Jan 19, 2024
1 parent 71825d7 commit 673adc4
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 22 deletions.
21 changes: 16 additions & 5 deletions api/api/business/daily_games.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

from api import constants
from api.business.factory import AbstractFactory, FactoryItem
from api.model.games.daily_game import NBALiveData, DailyGame, TeamData, PlayerLeader
from api.model.games.daily_game import NBALiveData, DailyGame, TeamData, PlayerLeader, Score


class DailyGamesSource(ABC):
source_url: str
Expand Down Expand Up @@ -52,8 +53,13 @@ async def fetch(self) -> list[DailyGame]:
game_start_unix=unix_timestamp,
home_team=TeamData(
id=game.homeTeam.teamId,
name=f"{game.homeTeam.teamCity} {game.homeTeam.teamName}",
score=game.homeTeam.score,
score=Score(
points=game.homeTeam.score,
periods=game.homeTeam.periods
),
city=game.homeTeam.teamCity,
seed=game.homeTeam.seed,
name=game.homeTeam.teamName,
wins=game.homeTeam.wins,
losses=game.homeTeam.losses,
abbreviation=game.homeTeam.teamTricode,
Expand All @@ -68,9 +74,14 @@ async def fetch(self) -> list[DailyGame]:
),
away_team=TeamData(
id=game.awayTeam.teamId,
name=f"{game.awayTeam.teamCity} {game.awayTeam.teamName}",
score=game.awayTeam.score,
city=game.awayTeam.teamCity,
name=game.awayTeam.teamName,
score=Score(
points=game.awayTeam.score,
periods=game.awayTeam.periods
),
wins=game.awayTeam.wins,
seed=game.awayTeam.seed,
losses=game.awayTeam.losses,
abbreviation=game.awayTeam.teamTricode,
leader=None
Expand Down
39 changes: 22 additions & 17 deletions api/api/model/games/daily_game.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@

from typing import Any, List, Optional

from pydantic import BaseModel
from pydantic import BaseModel, ConfigDict
from pydantic.alias_generators import to_snake

from api import constants
from api.model.games.injury import InjuryItem
Expand Down Expand Up @@ -51,6 +52,12 @@ class Period(BaseModel):
periodType: str
score: int

model_config = ConfigDict(
alias_generator=to_snake,
populate_by_name=True,
)



class HomeTeam(BaseModel):
teamId: int
Expand All @@ -66,11 +73,6 @@ class HomeTeam(BaseModel):
periods: List[Period]


class Period1(BaseModel):
period: int
periodType: str
score: int


class AwayTeam(BaseModel):
teamId: int
Expand All @@ -83,7 +85,7 @@ class AwayTeam(BaseModel):
seed: Any
inBonus: Any
timeoutsRemaining: int
periods: List[Period1]
periods: List[Period]


class GamePlayerLeader(BaseModel):
Expand All @@ -103,22 +105,17 @@ class GameLeaders(BaseModel):
awayLeaders: GamePlayerLeader

def home_is_empty(self) -> bool:
if self.homeLeaders is None:
if not self.homeLeaders:
return True

if self.homeLeaders.name is None:
return True

return False
return not self.homeLeaders.name

def away_is_empty(self) -> bool:
if self.awayLeaders is None:
if not self.awayLeaders:
return True

if self.awayLeaders.name is None:
return True
return not self.awayLeaders.name

return False


class PbOdds(BaseModel):
Expand Down Expand Up @@ -170,13 +167,19 @@ class PlayerLeader(BaseModel):

class TeamData(BaseModel):
id: int
city: str
name: str
score: int
score: Score
wins: int
losses: int
abbreviation: str
seed: Optional[int | str] = None
leader: Optional[PlayerLeader] = None

class Score(BaseModel):
points: int
periods: list[Period]


class DailyGame(BaseModel):
game_id: str
Expand Down Expand Up @@ -235,6 +238,7 @@ def craft_response(
home_team=TeamDataExt(
id=game.home_team.id,
name=game.home_team.name,
city=game.home_team.city,
score=game.home_team.score,
wins=game.home_team.wins,
losses=game.home_team.losses,
Expand All @@ -249,6 +253,7 @@ def craft_response(
away_team=TeamDataExt(
id=game.away_team.id,
name=game.away_team.name,
city=game.away_team.city,
score=game.away_team.score,
wins=game.away_team.wins,
losses=game.away_team.losses,
Expand Down

0 comments on commit 673adc4

Please sign in to comment.