From 07cffdea01c43198bb278e2b8e4b69562a5827da Mon Sep 17 00:00:00 2001 From: Filip Date: Fri, 21 Feb 2025 22:42:04 +0100 Subject: [PATCH] Gear ratio can now calculate speed at given cadence. --- cyclinglib/gear_ratio.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/cyclinglib/gear_ratio.py b/cyclinglib/gear_ratio.py index e41cb32..7e32969 100644 --- a/cyclinglib/gear_ratio.py +++ b/cyclinglib/gear_ratio.py @@ -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}"