From b0ec4a8a63957f5ec4b1dbf1144e3fb9dc5e8a43 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sun, 28 Apr 2019 17:23:21 +1000 Subject: [PATCH] plan: add capacity planner --- plan.py | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/plan.py b/plan.py index e69de29..0ca8ae1 100755 --- a/plan.py +++ b/plan.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python3 + +import satisfactory + +import fractions +import collections + +if __name__ == '__main__': + recipes = satisfactory.Cookbook('data/recipes') + + required = collections.defaultdict(fractions.Fraction) + remain = [] + + target_name = 'supercomputer' + target = recipes[target_name] + target_recipe = target['recipes'][0] + + remain.append({ + target_name: fractions.Fraction( + target_recipe['output'][target_name], + target_recipe['crafting_time'] + ) + }) + + while remain: + for dst_name, dst_rate in remain.pop().items(): + required[dst_name] += dst_rate + + dst = recipes[dst_name] + if recipes.is_resource(dst_name): + continue + + dst_recipe = recipes[dst_name]['recipes'][0] + src_recipe = recipes[dst_name]['recipes'][0] + + normal_rate = fractions.Fraction( + dst_recipe['output'][dst_name], + dst_recipe['crafting_time'] + ) + + scale = dst_rate / normal_rate + + for src_name, src_count in src_recipe['input'].items(): + src_rate = fractions.Fraction( + src_count, + dst_recipe['crafting_time'] + ) * scale + remain.append({src_name: src_rate}) + + print(required) + + for name, rate in required.items(): + machine = recipes[name]['machine']