-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added new things so I am going to commit these new things
- Loading branch information
Showing
4 changed files
with
100 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
from typing import Optional | ||
|
||
from pydantic import BaseModel, ConfigDict, field_validator, ValidationInfo, computed_field | ||
|
||
from api.business.database import Database | ||
|
||
|
||
class SavedGame(BaseModel): | ||
game_id: str | ||
date: str | ||
home_team_name: str | ||
home_team_score: int | ||
away_team_name: str | ||
away_team_score: int | ||
model_name: str | ||
prediction: str | int | ||
|
||
@computed_field | ||
@property | ||
def prediction_was_correct(self) -> Optional[bool]: | ||
if self.model_name == "ou": | ||
return None | ||
|
||
winner = self.home_team_name if self.home_team_score > self.away_team_score else self.away_team_name | ||
return winner == self.prediction | ||
|
||
@classmethod | ||
def check_prediction(cls, value, values: ValidationInfo): | ||
if values.data.get("model_name") == "ou": | ||
return int(value) | ||
|
||
return value | ||
|
||
model_config = ConfigDict(protected_namespaces=(), extra="allow") | ||
|
||
@staticmethod | ||
async def from_db( | ||
db: Database, | ||
date: str, | ||
model_name: str | ||
) -> list["SavedGame"]: | ||
query = f""" | ||
SELECT * FROM saved_games | ||
WHERE date = $1 | ||
AND model_name = $2""" | ||
response = await db.query(query, values=[date, model_name]) | ||
return [SavedGame(**game) for game in response] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters