123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- """Calculate production in different factories"""
- import json
- 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('factories.json') as file:
- RESOURCES = json.load(file)
- WP = WorkProduction()
- WP.user_level = 60
- WP.work_exp = 80000 + 200 * 30
- 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[REGIONS[str(factory['region_id'])]['state']][resource_name]
- WP.resource_max = REGIONS[str(factory['region_id'])]['resources'][resource_name]
- WP.wage_percentage = factory['wage']
- 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'], reverse=True):
- print('{:30} {:>12}'.format(
- factory['name'],
- int(factory['wage']),
- ))
- def print_all():
- """Print wages per resource"""
- factory_dict = all_factories()
- print("Total Wage %")
- print("———————————————————————————— ————— ———")
- 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} {:>4,}kk {:>3}'.format(
- factory['name'],
- round(int(factory['wage'])/1000000),
- 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[str(factory['region_id'])]['name'],
- ))
- def main():
- """Main function"""
- for resource_name, factories in RESOURCES.items():
- for factory_id, factory in factories.items():
- wage = calculate_wage(resource_name, factory)
- RESOURCES[resource_name][factory_id]['wage'] = wage
- # print_per_resource()
- print_all()
- # print_factory_list()
- if __name__ == '__main__':
- main()
|