| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 | """Calculate production in different factories"""import jsonimport copyfrom rival_regions_calc import Item, WorkProductionDEPARTMENTS = Nonewith open('departments.json') as file:    DEPARTMENTS = json.load(file)PRICE = Nonewith open('prices.json') as file:    PRICE = json.load(file)REGIONS = Nonewith open('regions.json') as file:    REGIONS = json.load(file)RESOURCES = Nonewith open('resources.json') as file:    RESOURCES = json.load(file)WP = WorkProduction()WP.user_level = 80WP.work_exp = 80000 + 200 * 250WP.nation_bonus = TrueWP.profit_share = 75def 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_dictdef 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_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, 5):            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_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()
 |