This repository has been archived on 2022-08-24. You can view files and clone it, but cannot push or open issues or pull requests.

73 lines
2.3 KiB
Python
Raw Normal View History

""" Result class """
2022-06-01 14:31:52 +01:00
import datetime
from dataclasses import dataclass
2022-06-01 14:31:52 +01:00
from ergast_py.models.constructor import Constructor
2022-06-01 14:31:52 +01:00
from ergast_py.models.driver import Driver
from ergast_py.models.fastest_lap import FastestLap
2022-06-01 14:31:52 +01:00
@dataclass
2022-06-06 12:20:48 +01:00
class Result():
2022-06-01 14:31:52 +01:00
"""
Representation of a single Result from a Formula One race
2022-06-01 14:31:52 +01:00
Results may contain:
number: Integer
position: Integer
position_text: String
2022-06-01 14:31:52 +01:00
points: Integer
driver: Driver
constructor: Constructor
grid: Integer
laps: Integer
status: Integer
time: datetime.time
fastest_lap: FastestLap
qual_1: datetime.time
qual_2: datetime.time
qual_3: datetime.time
2022-06-01 14:31:52 +01:00
"""
def __init__(self, number: int, position: int, position_text: str, points: float,
driver: Driver, constructor: Constructor, grid: int, laps: int, status: int,
time: datetime.time, fastest_lap: FastestLap, qual_1: datetime.time,
qual_2: datetime.time, qual_3: datetime.time) -> None:
2022-06-01 14:31:52 +01:00
self.number = number
self.position = position
self.position_text = position_text
2022-06-01 14:31:52 +01:00
self.points = points
self.driver = driver
self.constructor = constructor
self.grid = grid
self.laps = laps
self.status = status
self.time = time
self.fastest_lap = fastest_lap
self.qual_1 = qual_1
self.qual_2 = qual_2
self.qual_3 = qual_3
2022-06-06 12:20:48 +01:00
def __repr__(self) -> str:
members = ', '.join(f"{key}={value}" for key, value in self.__dict__.items())
return f"{type(self).__name__}({members})"
2022-06-09 23:19:28 +01:00
def __eq__(self, __o: object) -> bool:
return isinstance(__o, Result) and (
self.number == __o.number and
self.position == __o.position and
self.position_text == __o.position_text and
self.points == __o.points and
self.driver == __o.driver and
self.constructor == __o.constructor and
self.grid == __o.grid and
self.laps == __o.laps and
self.status == __o.status and
self.time == __o.time and
self.fastest_lap == __o.fastest_lap and
self.qual_1 == __o.qual_1 and
self.qual_2 == __o.qual_2 and
self.qual_3 == __o.qual_3
)