plan: move the primary functionality into a function
This prevents reliance on global variables
This commit is contained in:
parent
6a82305479
commit
9e2d8dba8a
18
plan.py
18
plan.py
@ -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):
|
||||||
return fractions.Fraction(
|
for output, count in recipe['output'].items():
|
||||||
target_recipe['output'][target_name],
|
return fractions.Fraction(
|
||||||
target_recipe['crafting_time']
|
count, 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()
|
||||||
|
Loading…
Reference in New Issue
Block a user