elite-engineering/elite_engineering/trade.py

21 lines
606 B
Python
Raw Normal View History

import fractions
2022-01-22 05:23:09 +00:00
import typing
2022-01-22 05:21:09 +00:00
MAX_CAPACITY: int = 300
def ratio(
grade_in: int, grade_out: int, across_categories: bool
2022-01-22 05:23:09 +00:00
) -> typing.Optional[fractions.Fraction]:
2022-01-22 05:21:09 +00:00
trading_up = grade_out > grade_in
grade_base = 6 if trading_up else 3
grade_ratio = fractions.Fraction(grade_base ** grade_out, grade_base ** grade_in)
category_ratio = (
fractions.Fraction(6, 1) if across_categories else fractions.Fraction(1, 1)
)
result = grade_ratio * category_ratio
if max(result.numerator, result.denominator) > MAX_CAPACITY:
2022-01-22 05:23:09 +00:00
return None
2022-01-22 05:21:09 +00:00
else:
2022-01-22 05:23:09 +00:00
return result