plan: import Fraction directly
This commit is contained in:
parent
2f8fb25fe8
commit
2380faf59d
20
plan.py
20
plan.py
@ -1,16 +1,16 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
|
|
||||||
import math
|
import math
|
||||||
import fractions
|
|
||||||
import collections
|
import collections
|
||||||
|
|
||||||
from typing import Dict
|
from fractions import Fraction
|
||||||
|
from typing import Dict, Iterable
|
||||||
|
|
||||||
import satisfactory
|
import satisfactory
|
||||||
|
|
||||||
|
|
||||||
def calculate_rates(recipes, remain):
|
def calculate_rates(recipes: Iterable[str], remain: Dict[str,Fraction]):
|
||||||
required_items = collections.defaultdict(fractions.Fraction)
|
required_items = collections.defaultdict(Fraction)
|
||||||
|
|
||||||
while remain:
|
while remain:
|
||||||
for dst_name, dst_rate in remain.pop().items():
|
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]
|
dst_recipe = recipes[dst_name]['recipes'][0]
|
||||||
src_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['output'][dst_name],
|
||||||
dst_recipe['crafting_time']
|
dst_recipe['crafting_time']
|
||||||
)
|
)
|
||||||
@ -31,7 +31,7 @@ def calculate_rates(recipes, remain):
|
|||||||
scale = dst_rate / normal_rate
|
scale = dst_rate / normal_rate
|
||||||
|
|
||||||
for src_name, src_count in src_recipe['input'].items():
|
for src_name, src_count in src_recipe['input'].items():
|
||||||
src_rate = fractions.Fraction(
|
src_rate = Fraction(
|
||||||
src_count,
|
src_count,
|
||||||
dst_recipe['crafting_time']
|
dst_recipe['crafting_time']
|
||||||
) * scale
|
) * scale
|
||||||
@ -40,14 +40,14 @@ def calculate_rates(recipes, remain):
|
|||||||
return required_items
|
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.
|
Calculate the rate at which the item is crafted with the default recipe.
|
||||||
:param recipe:
|
:param recipe:
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
for output, count in recipe['output'].items():
|
for output, count in recipe['output'].items():
|
||||||
return fractions.Fraction(
|
return Fraction(
|
||||||
count, recipe['crafting_time']
|
count, recipe['crafting_time']
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -59,7 +59,7 @@ conveyor_rates = [0, 60, 120, 270, 480, 780, 900]
|
|||||||
def main():
|
def main():
|
||||||
recipes = satisfactory.Cookbook('data/recipes')
|
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
|
# Create a list of items we want to make
|
||||||
#targets = [ 'supercomputer' ]
|
#targets = [ 'supercomputer' ]
|
||||||
@ -89,7 +89,7 @@ def main():
|
|||||||
|
|
||||||
descriptor = recipes[name]
|
descriptor = recipes[name]
|
||||||
|
|
||||||
normal_rate = fractions.Fraction(
|
normal_rate = Fraction(
|
||||||
descriptor['recipes'][0]['output'][name],
|
descriptor['recipes'][0]['output'][name],
|
||||||
descriptor['recipes'][0]['crafting_time']
|
descriptor['recipes'][0]['crafting_time']
|
||||||
)
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user