diff --git a/plan.py b/plan.py index 0bfdadf..33f007d 100755 --- a/plan.py +++ b/plan.py @@ -1,16 +1,16 @@ #!/usr/bin/env python3 import math -import fractions import collections -from typing import Dict +from fractions import Fraction +from typing import Dict, Iterable import satisfactory -def calculate_rates(recipes, remain): - required_items = collections.defaultdict(fractions.Fraction) +def calculate_rates(recipes: Iterable[str], remain: Dict[str,Fraction]): + required_items = collections.defaultdict(Fraction) while remain: for dst_name, dst_rate in remain.pop().items(): @@ -23,7 +23,7 @@ def calculate_rates(recipes, remain): dst_recipe = recipes[dst_name]['recipes'][0] src_recipe = recipes[dst_name]['recipes'][0] - normal_rate = fractions.Fraction( + normal_rate = Fraction( dst_recipe['output'][dst_name], dst_recipe['crafting_time'] ) @@ -31,7 +31,7 @@ def calculate_rates(recipes, remain): scale = dst_rate / normal_rate for src_name, src_count in src_recipe['input'].items(): - src_rate = fractions.Fraction( + src_rate = Fraction( src_count, dst_recipe['crafting_time'] ) * scale @@ -40,14 +40,14 @@ def calculate_rates(recipes, remain): return required_items -def basic_rate(recipe: Dict) -> fractions.Fraction: +def basic_rate(recipe: Dict) -> Fraction: """ Calculate the rate at which the item is crafted with the default recipe. :param recipe: :return: """ for output, count in recipe['output'].items(): - return fractions.Fraction( + return Fraction( count, recipe['crafting_time'] ) @@ -59,7 +59,7 @@ conveyor_rates = [0, 60, 120, 270, 480, 780, 900] def main(): recipes = satisfactory.Cookbook('data/recipes') - required_items = collections.defaultdict(fractions.Fraction) + required_items = collections.defaultdict(Fraction) # Create a list of items we want to make #targets = [ 'supercomputer' ] @@ -89,7 +89,7 @@ def main(): descriptor = recipes[name] - normal_rate = fractions.Fraction( + normal_rate = Fraction( descriptor['recipes'][0]['output'][name], descriptor['recipes'][0]['crafting_time'] )