Gear ratio can now calculate speed at given cadence.

This commit is contained in:
Filip 2025-02-21 22:42:04 +01:00
parent 5a154e1722
commit 07cffdea01

View file

@ -1,7 +1,20 @@
from cyclinglib.speed import Speed
class GearRatio:
def __init__(self, front_teeth: int, rear_teeth: int):
self._gear_ratio: float = front_teeth / rear_teeth
def speed_at_cadence(self, cadence: int,
wheel_circumference_mm: int) -> Speed:
"""
Cadence is specified in revolutions per minute.
"""
revolutions_per_second = cadence / 60
wheel_circumference_m = wheel_circumference_mm / 1_000
return Speed(wheel_circumference_m * revolutions_per_second *
self._gear_ratio)
def __str__(self) -> str:
return f"Gear ratio: {self._gear_ratio}"