39 lines
964 B
Python
39 lines
964 B
Python
from cyclinglib.force import Force
|
|
from cyclinglib.length import Length
|
|
from cyclinglib.power import Power
|
|
from cyclinglib.time import Time
|
|
|
|
|
|
class Energy:
|
|
|
|
def __init__(self, joules: float):
|
|
self._joules = joules
|
|
|
|
def joules(self) -> float:
|
|
return self._joules
|
|
|
|
def kilojoules(self) -> float:
|
|
return self._joules / 1_000
|
|
|
|
def kilocalories(self) -> float:
|
|
return self.kilojoules() / 4.184
|
|
|
|
def kcal(self) -> float:
|
|
"""
|
|
This is alias for kilocalories.
|
|
"""
|
|
return self.kilocalories()
|
|
|
|
def __str__(self) -> str:
|
|
return f"J: {self.joules()} kJ: {self.kilojoules()} kcal: {self.kcal()}"
|
|
|
|
|
|
def calculate_energy(force: Force, distance: Length) -> Energy:
|
|
joules = force.newtons() * distance.metre()
|
|
return Energy(joules)
|
|
|
|
|
|
def calculate_energy_cycling(power: Power, duration: Time) -> Energy:
|
|
joules = power.watts() * duration.seconds()
|
|
return Energy(joules)
|