Implement data types contract
This commit is contained in:
@@ -1,21 +1,64 @@
|
|||||||
from abc import ABC
|
from abc import ABC, abstractmethod
|
||||||
from enum import Enum
|
from enum import Enum
|
||||||
|
from typing import Literal
|
||||||
|
|
||||||
from pydantic.dataclasses import dataclass
|
from pydantic.dataclasses import dataclass
|
||||||
from typing import Callable
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
class TicketType(str, Enum):
|
class TicketType(str, Enum):
|
||||||
WIN_DRAW_LOSE = "win_draw_lose"
|
WIN_DRAW_LOSE = "win_draw_lose"
|
||||||
# postup?
|
ADVANCED = "advance"
|
||||||
WIN_DRAW_LOSE_DOUBLE = "win_draw_lose_double"
|
WIN_DRAW_LOSE_DOUBLE = "win_draw_lose_double"
|
||||||
WIN_LOSE = "win_lose"
|
WIN_LOSE = "win_lose"
|
||||||
BOTH_TEAM_SCORED = "both_team_scored"
|
BOTH_TEAM_SCORED = "both_team_scored"
|
||||||
GOAL_AMOUNT = "goal_amount"
|
GOAL_AMOUNT = "goal_amount"
|
||||||
...
|
...
|
||||||
|
|
||||||
# Classes that inherit from this are defined in resolution file, so the deciding function can be used
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class Ticket(ABC):
|
class Ticket(ABC):
|
||||||
ticketType: TicketType
|
ticketType: TicketType
|
||||||
decidingFunction: Callable
|
team1Name: str
|
||||||
|
team2Name: str
|
||||||
|
date: datetime
|
||||||
|
# other fields that might be interesting for resolving (like bet type in WinDrawLose)
|
||||||
|
@abstractmethod
|
||||||
|
def resolve(self): pass
|
||||||
|
|
||||||
|
class WinDrawLose(Ticket):
|
||||||
|
"""Výsledek zápasu 1X2"""
|
||||||
|
ticketType: TicketType.WIN_DRAW_LOSE
|
||||||
|
betType: Literal["X", "0", "1", "2"]
|
||||||
|
def resolve(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
class Advance(Ticket):
|
||||||
|
"""What team advances to next round"""
|
||||||
|
ticketType: TicketType.WIN_DRAW_LOSE
|
||||||
|
def resolve(self):
|
||||||
|
raise NotImplementedError("Vyser si voko vine")
|
||||||
|
|
||||||
|
class WinDrawLoseDouble(Ticket):
|
||||||
|
"""Výsledek zápasu - double"""
|
||||||
|
ticketType: TicketType.WIN_DRAW_LOSE_DOUBLE
|
||||||
|
betType: Literal["01", "12", "02"]
|
||||||
|
def resolve(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
class WinLose(Ticket):
|
||||||
|
"""Výsledek zápasu bez remízy"""
|
||||||
|
ticketType: TicketType.WIN_LOSE
|
||||||
|
betType: Literal["0", "1"]
|
||||||
|
def resolve(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
class BothTeamScored(Ticket):
|
||||||
|
ticketType: TicketType.BOTH_TEAM_SCORED
|
||||||
|
def resolve(self):
|
||||||
|
...
|
||||||
|
|
||||||
|
class GoalAmount(Ticket):
|
||||||
|
ticketType: TicketType.GOAL_AMOUNT
|
||||||
|
team_bet: Literal["1", "2"] # if we are betting for team 1 or team 2
|
||||||
|
handicap_amount: float # -0.5, +1.5 ....
|
||||||
|
def resolve(self):
|
||||||
|
...
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
Class WinDrawLose(Ticket):
|
|
||||||
ticketType: TicketType.WIN_DRAW_LOSE
|
|
||||||
decidingFunc: f
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def f(ticket: WinDrawLose):
|
|
||||||
call endpoint
|
|
||||||
return True
|
|
||||||
Reference in New Issue
Block a user