plan: move the primary functionality into a function

This prevents reliance on global variables
This commit is contained in:
Danny Robson 2019-07-14 11:12:34 +10:00
parent 6a82305479
commit 9e2d8dba8a

14
plan.py
View File

@ -37,14 +37,14 @@ def calculate_rates(recipes, remain):
return required_items return required_items
def basic_rate(recipes, name: str): def basic_rate(recipe):
for output, count in recipe['output'].items():
return fractions.Fraction( return fractions.Fraction(
target_recipe['output'][target_name], count, recipe['crafting_time']
target_recipe['crafting_time']
) )
if __name__ == '__main__': def main():
recipes = satisfactory.Cookbook('data/recipes') recipes = satisfactory.Cookbook('data/recipes')
required_items = collections.defaultdict(fractions.Fraction) required_items = collections.defaultdict(fractions.Fraction)
@ -56,7 +56,7 @@ if __name__ == '__main__':
target = recipes[target_name] target = recipes[target_name]
target_recipe = target['recipes'][0] target_recipe = target['recipes'][0]
remain = [{n: basic_rate(recipes, n) for n in targets}] remain = [{n: basic_rate(recipes[n]['recipes'][0]) for n in targets}]
required_items = calculate_rates(recipes, remain) required_items = calculate_rates(recipes, remain)
for name, rate in required_items.items(): for name, rate in required_items.items():
@ -92,3 +92,7 @@ if __name__ == '__main__':
print(required_power) print(required_power)
print(math.ceil(required_power / 150), "fuel generators") print(math.ceil(required_power / 150), "fuel generators")
if __name__ == '__main__':
main()