"""Calculate production in different factories""" import json import copy from rival_regions_calc import Item, WorkProduction DEPARTMENTS = None with open('departments.json') as file: DEPARTMENTS = json.load(file) PRICE = None with open('prices.json') as file: PRICE = json.load(file) REGIONS = None with open('regions.json') as file: REGIONS = json.load(file) RESOURCES = None with open('resources.json') as file: RESOURCES = json.load(file) WP = WorkProduction() WP.user_level = 80 WP.work_exp = 80000 + 200 * 250 WP.profit_share = 75 def calculate_wage(resource_name, factory): """Calculate production""" if 'fixed_wage' in factory: return factory['fixed_wage'] resource = Item(resource_name) WP.resource = resource WP.factory_level = factory['level'] WP.department_bonus = DEPARTMENTS[resource_name] WP.resource_max = REGIONS[str(factory['region_id'])]['resources'][resource_name] WP.wage_percentage = factory['wage_percentage'] WP.tax_rate = REGIONS[str(factory['region_id'])]['tax'][resource_name] WP.calculate() return WP.wage() * PRICE[resource_name] def all_factories(): """return all factories""" factory_dict = {} for factories in RESOURCES.values(): factory_dict.update(factories) return factory_dict def print_per_resource(): """Print wages per resource""" for resource_name, factories in RESOURCES.items(): print(resource_name) for factory in sorted(factories.values(), key=lambda k: k['wage']): print('{}'.format( int(factory['wage']), )) def print_per_level(): """Print wages per factory level""" factory_levels = {} for resource_name, factories in RESOURCES.items(): for factory in sorted(factories.values(), key=lambda k: k['wage']): if factory['level'] not in factory_levels: factory_levels[factory['level']] = {} factory_levels[factory['level']][resource_name] = factory['wage'] for level, resources in factory_levels.items(): print('{},{},{},{},{}'.format( int(level), round(resources['oil']), round(resources['ore']), round(resources['uranium']), round(resources['diamond']), )) def print_all(): """Print wages per resource""" factory_dict = all_factories() print("total") sorted_factories = sorted(factory_dict.values(), key=lambda k: k['wage'], reverse=True) top_wage = sorted_factories[0]['wage'] for factory in sorted_factories: print('{:28} {:>11,} {:>3}'.format( factory['name'], int(factory['wage']), int(100 / top_wage * factory['wage']), ).replace(',', '.')) def print_factory_list(): """print all factories""" for resource_name, factories in RESOURCES.items(): print('[rr]{}[/rr]'.format(resource_name.capitalize())) for factory_id, factory in factories.items(): print('[url=https://rivalregions.com/#factory/index/{}]Desktop[/url] [url=https://m.rivalregions.com/#factory/index/{}]Mobile[/url] {}, {} '.format( factory_id, factory_id, factory['name'], REGIONS[factory['region_id']]['name'], )) def main(): """Main function""" for resource_name, factories in RESOURCES.items(): factory = None factory_id = None for factory_id, factory in factories.items(): factory = factory factory_id = factory_id RESOURCES[resource_name][factory_id]['wage'] = calculate_wage(resource_name, factory) for i in range(factory['level'], 221, 1): new_factory_id = int(factory_id) + i - 150 new_factory = copy.copy(factory) new_factory['level'] = i new_factory['name'] = i new_factory['wage'] = calculate_wage(resource_name, new_factory) RESOURCES[resource_name][str(new_factory_id)] = new_factory #print_per_resource() print_per_level() # print_all() # print_factory_list() def print_json(json_text): """Print data to console""" print(json.dumps(json_text, sort_keys=True, indent=4)) if __name__ == '__main__': main()