Skip to content

Commit

Permalink
refactor: updated constants
Browse files Browse the repository at this point in the history
  • Loading branch information
borolepratik committed Mar 6, 2024
1 parent df41b50 commit 7443ae4
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 46 deletions.
20 changes: 11 additions & 9 deletions app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@
"Session5DateUtc",
]

MIN_SUPPORTED_YEAR = 1950
MAX_SUPPORTED_YEAR = datetime.today().year
MIN_YEAR_SUPPORTED = 1950
MIN_YEAR_WITH_TELEMETRY_SUPPORTED = 2018
MAX_YEAR_SUPPORTED = datetime.today().year

MIN_SUPPORTED_ROUND = 1 # testing events all share round number = 0
MAX_SUPPORTED_ROUND = 25
MIN_ROUND_SUPPORTED = 1 # testing events all share round number = 0
MAX_ROUND_SUPPORTED = 25

MIN_SUPPORTED_SESSION = 1
MAX_SUPPORTED_SESSION = 5
MIN_SESSION_SUPPORTED = 1
MAX_SESSION_SUPPORTED = 5

DEFAULT_SESSION = 5 # race

MIN_SUPPORTED_DRIVER_NUMBER = 1
MAX_SUPPORTED_DRIVER_NUMBER = 99
MIN_DRIVER_NUMBER_SUPPORTED = 1
MAX_DRIVER_NUMBER_SUPPORTED = 99

MIN_SUPPORTED_LAP_COUNT = 1
MIN_LAP_COUNT_SUPPORTED = 1
MAX_LAP_COUNT_SUPPORTED = 80
74 changes: 38 additions & 36 deletions app/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,17 @@
from .constants import (
DEFAULT_SESSION,
EVENT_SCHEDULE_DATETIME_DTYPE_LIST,
MAX_SUPPORTED_DRIVER_NUMBER,
MAX_SUPPORTED_ROUND,
MAX_SUPPORTED_SESSION,
MAX_SUPPORTED_YEAR,
MAX_DRIVER_NUMBER_SUPPORTED,
MAX_LAP_COUNT_SUPPORTED,
MAX_ROUND_SUPPORTED,
MAX_SESSION_SUPPORTED,
MAX_YEAR_SUPPORTED,
METADATA_DESCRIPTION,
MIN_SUPPORTED_DRIVER_NUMBER,
MIN_SUPPORTED_LAP_COUNT,
MIN_SUPPORTED_ROUND,
MIN_SUPPORTED_SESSION,
MIN_SUPPORTED_YEAR,
MIN_DRIVER_NUMBER_SUPPORTED,
MIN_LAP_COUNT_SUPPORTED,
MIN_ROUND_SUPPORTED,
MIN_SESSION_SUPPORTED,
MIN_YEAR_SUPPORTED,
)
from .models import (
EventSchedule,
Expand Down Expand Up @@ -130,8 +131,8 @@ def get_schedule(
Query(
title="The year for which to get the schedule",
description="The year for which to get the schedule",
ge=MIN_SUPPORTED_YEAR,
le=MAX_SUPPORTED_YEAR,
ge=MIN_YEAR_SUPPORTED,
le=MAX_YEAR_SUPPORTED,
),
] = None,
) -> Schedule:
Expand Down Expand Up @@ -226,17 +227,17 @@ def get_standings(
Query(
title="The year for which to get the driver and constructors standing. If the season hasn't ended you get the current standings.",
description="The year for which to get the driver and constructors standing. If the season hasn't ended you get the current standings.",
ge=MIN_SUPPORTED_YEAR,
le=MAX_SUPPORTED_YEAR,
ge=MIN_YEAR_SUPPORTED,
le=MAX_YEAR_SUPPORTED,
),
] = None,
round: Annotated[
int | None,
Query(
title="The round in a year for which to get the driver and constructor standings",
description="The round in a year for which to get the driver and constructor standings",
ge=MIN_SUPPORTED_ROUND,
le=MAX_SUPPORTED_ROUND,
ge=MIN_ROUND_SUPPORTED,
le=MAX_ROUND_SUPPORTED,
),
] = None,
) -> Standings:
Expand Down Expand Up @@ -317,26 +318,26 @@ def get_results(
Path(
title="The year for which to get the results",
description="The year for which to get the results",
ge=MIN_SUPPORTED_YEAR,
le=MAX_SUPPORTED_YEAR,
ge=MIN_YEAR_SUPPORTED,
le=MAX_YEAR_SUPPORTED,
),
],
round: Annotated[
int,
Path(
title="The round in a year for which to get the results",
description="The round in a year for which to get the results",
ge=MIN_SUPPORTED_ROUND,
le=MAX_SUPPORTED_ROUND,
ge=MIN_ROUND_SUPPORTED,
le=MAX_ROUND_SUPPORTED,
),
],
session: Annotated[
int,
Query(
title="The session in a round for which to get the results",
description="The session in a round for which to get the results. (Default = 5; ie race)",
ge=MIN_SUPPORTED_SESSION,
le=MAX_SUPPORTED_SESSION,
ge=MIN_SESSION_SUPPORTED,
le=MAX_SESSION_SUPPORTED,
),
] = DEFAULT_SESSION,
) -> List[Results]:
Expand Down Expand Up @@ -390,26 +391,26 @@ def get_laps(
Path(
title="The year for which to get the laps",
description="The year for which to get the laps",
ge=MIN_SUPPORTED_YEAR,
le=MAX_SUPPORTED_YEAR,
ge=MIN_YEAR_SUPPORTED,
le=MAX_YEAR_SUPPORTED,
),
],
round: Annotated[
int,
Path(
title="The round in a year for which to get the laps",
description="The round in a year for which to get the laps",
ge=MIN_SUPPORTED_ROUND,
le=MAX_SUPPORTED_ROUND,
ge=MIN_ROUND_SUPPORTED,
le=MAX_ROUND_SUPPORTED,
),
],
session: Annotated[
int,
Query(
title="The session in a round for which to get the laps",
description="The session in a round for which to get the laps. (Default = 5; ie race)",
ge=MIN_SUPPORTED_SESSION,
le=MAX_SUPPORTED_SESSION,
ge=MIN_SESSION_SUPPORTED,
le=MAX_SESSION_SUPPORTED,
),
] = DEFAULT_SESSION,
driver_number: Annotated[
Expand Down Expand Up @@ -475,43 +476,44 @@ def get_telemetry(
Path(
title="The year for which to get the telemetry",
description="The year for which to get the telemetry",
ge=MIN_SUPPORTED_YEAR,
le=MAX_SUPPORTED_YEAR,
ge=MIN_YEAR_SUPPORTED,
le=MAX_YEAR_SUPPORTED,
),
],
round: Annotated[
int,
Path(
title="The round in a year for which to get the telemetry",
description="The round in a year for which to get the telemetry",
ge=MIN_SUPPORTED_ROUND,
le=MAX_SUPPORTED_ROUND,
ge=MIN_ROUND_SUPPORTED,
le=MAX_ROUND_SUPPORTED,
),
],
driver_number: Annotated[
int,
Path(
title="Driver number for whom to get the telemetry",
description="Driver number for whom to get the telemetry",
ge=MIN_SUPPORTED_DRIVER_NUMBER,
le=MAX_SUPPORTED_DRIVER_NUMBER,
ge=MIN_DRIVER_NUMBER_SUPPORTED,
le=MAX_DRIVER_NUMBER_SUPPORTED,
),
],
lap: Annotated[
int,
Path(
title="List of laps of the driver for which to get the telemetry",
description="List of laps of the driver for which to get the telemetry",
ge=MIN_SUPPORTED_LAP_COUNT,
ge=MIN_LAP_COUNT_SUPPORTED,
le=MAX_LAP_COUNT_SUPPORTED,
),
],
session: Annotated[
int,
Query(
title="The session in a round for which to get the telemetry",
description="The session in a round for which to get the telemetry. (Default = 5; ie race)",
ge=MIN_SUPPORTED_SESSION,
le=MAX_SUPPORTED_SESSION,
ge=MIN_SESSION_SUPPORTED,
le=MAX_SESSION_SUPPORTED,
),
] = DEFAULT_SESSION,
weather: Annotated[
Expand Down
2 changes: 1 addition & 1 deletion tests/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def test_get_telemetry_bad_driver_number():


def test_get_telemetry_bad_lap():
response = client.get("/telemetry/2023/4/1/99?session=5&weather=false")
response = client.get("/telemetry/2023/4/1/80?session=5&weather=false")
assert response.status_code == status.HTTP_404_NOT_FOUND
assert response.json() == {"detail": "Requested lap for driver 1 not found."}

Expand Down

0 comments on commit 7443ae4

Please sign in to comment.