From 2380faf59d6d1da89a3307ea60a8d131f1ba4bfe Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 14 Jul 2019 11:36:54 +1000 Subject: [PATCH] plan: import Fraction directly --- plan.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) 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'] )