Created basic calculations related to gears.
This commit is contained in:
parent
8e0bb9a66d
commit
5a154e1722
32
cyclinglib/gain_ratio.py
Normal file
32
cyclinglib/gain_ratio.py
Normal file
|
|
@ -0,0 +1,32 @@
|
||||||
|
from cyclinglib.gear_ratio import GearRatio
|
||||||
|
from math import pi
|
||||||
|
|
||||||
|
from cyclinglib.speed import Speed
|
||||||
|
|
||||||
|
|
||||||
|
class GainRatio:
|
||||||
|
|
||||||
|
def __init__(self, gear_ratio: GearRatio, wheel_circumference_mm: float,
|
||||||
|
crank_length_mm: float):
|
||||||
|
self._revolution_length_mm: float = crank_length_mm * 2 * pi
|
||||||
|
circumference_ratio: float = wheel_circumference_mm / self._revolution_length_mm
|
||||||
|
self._gain_ratio: float = circumference_ratio * gear_ratio._gear_ratio
|
||||||
|
|
||||||
|
def speed_at_cadence(self, cadence: int) -> Speed:
|
||||||
|
"""
|
||||||
|
Cadence is specified in revolutions per minute.
|
||||||
|
"""
|
||||||
|
revolutions_per_second = cadence / 60
|
||||||
|
meters_per_second_crank = revolutions_per_second * (
|
||||||
|
self._revolution_length_mm / 1_000)
|
||||||
|
return Speed(meters_per_second_crank * self._gain_ratio)
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"Gain ratio: {self._gain_ratio}"
|
||||||
|
|
||||||
|
|
||||||
|
def calculate_gain_ratio(front_teeth: int, rear_teeth: int,
|
||||||
|
wheel_circumference_mm: float,
|
||||||
|
crank_length_mm: float) -> GainRatio:
|
||||||
|
return GainRatio(GearRatio(front_teeth, rear_teeth),
|
||||||
|
wheel_circumference_mm, crank_length_mm)
|
||||||
7
cyclinglib/gear_ratio.py
Normal file
7
cyclinglib/gear_ratio.py
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
class GearRatio:
|
||||||
|
|
||||||
|
def __init__(self, front_teeth: int, rear_teeth: int):
|
||||||
|
self._gear_ratio: float = front_teeth / rear_teeth
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"Gear ratio: {self._gear_ratio}"
|
||||||
19
cyclinglib/speed.py
Normal file
19
cyclinglib/speed.py
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
class Speed:
|
||||||
|
|
||||||
|
def __init__(self, meters_per_second: float):
|
||||||
|
self._meters_per_second: float = meters_per_second
|
||||||
|
|
||||||
|
def meters_per_second(self):
|
||||||
|
return self._meters_per_second
|
||||||
|
|
||||||
|
def kilometers_per_hour(self):
|
||||||
|
return self._meters_per_second * 3.6
|
||||||
|
|
||||||
|
def miles_per_hour(self):
|
||||||
|
return self._meters_per_second * 2.23693629
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
mps = self.meters_per_second()
|
||||||
|
kph = self.kilometers_per_hour()
|
||||||
|
mph = self.miles_per_hour()
|
||||||
|
return f"m/s: {mps} km/h: {kph} mi/h: {mph}"
|
||||||
Loading…
Reference in a new issue