productivity.py 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. """Calculate production in different factories"""
  2. import json
  3. import copy
  4. from rival_regions_calc import Item, WorkProduction
  5. DEPARTMENTS = None
  6. with open('departments.json') as file:
  7. DEPARTMENTS = json.load(file)
  8. PRICE = None
  9. with open('prices.json') as file:
  10. PRICE = json.load(file)
  11. REGIONS = None
  12. with open('regions.json') as file:
  13. REGIONS = json.load(file)
  14. RESOURCES = None
  15. with open('resources.json') as file:
  16. RESOURCES = json.load(file)
  17. WP = WorkProduction()
  18. WP.user_level = 80
  19. WP.work_exp = 80000 + 200 * 250
  20. WP.nation_bonus = True
  21. WP.profit_share = 75
  22. def calculate_wage(resource_name, factory):
  23. """Calculate production"""
  24. if 'fixed_wage' in factory:
  25. return factory['fixed_wage']
  26. resource = Item(resource_name)
  27. WP.resource = resource
  28. WP.factory_level = factory['level']
  29. WP.department_bonus = DEPARTMENTS[resource_name]
  30. WP.resource_max = REGIONS[str(factory['region_id'])]['resources'][resource_name]
  31. WP.wage_percentage = factory['wage_percentage']
  32. WP.tax_rate = REGIONS[str(factory['region_id'])]['tax'][resource_name]
  33. WP.calculate()
  34. return WP.wage() * PRICE[resource_name]
  35. def all_factories():
  36. """return all factories"""
  37. factory_dict = {}
  38. for factories in RESOURCES.values():
  39. factory_dict.update(factories)
  40. return factory_dict
  41. def print_per_resource():
  42. """Print wages per resource"""
  43. for resource_name, factories in RESOURCES.items():
  44. print(resource_name)
  45. for factory in sorted(factories.values(), key=lambda k: k['wage']):
  46. print('{}'.format(
  47. int(factory['wage']),
  48. ))
  49. def print_all():
  50. """Print wages per resource"""
  51. factory_dict = all_factories()
  52. print("total")
  53. sorted_factories = sorted(factory_dict.values(), key=lambda k: k['wage'], reverse=True)
  54. top_wage = sorted_factories[0]['wage']
  55. for factory in sorted_factories:
  56. print('{:28} {:>11,} {:>3}'.format(
  57. factory['name'],
  58. int(factory['wage']),
  59. int(100 / top_wage * factory['wage']),
  60. ).replace(',', '.'))
  61. def print_factory_list():
  62. """print all factories"""
  63. for resource_name, factories in RESOURCES.items():
  64. print('[rr]{}[/rr]'.format(resource_name.capitalize()))
  65. for factory_id, factory in factories.items():
  66. print('[url=https://rivalregions.com/#factory/index/{}]Desktop[/url] [url=https://m.rivalregions.com/#factory/index/{}]Mobile[/url] {}, {} '.format(
  67. factory_id,
  68. factory_id,
  69. factory['name'],
  70. REGIONS[factory['region_id']]['name'],
  71. ))
  72. def main():
  73. """Main function"""
  74. for resource_name, factories in RESOURCES.items():
  75. factory = None
  76. factory_id = None
  77. for factory_id, factory in factories.items():
  78. factory = factory
  79. factory_id = factory_id
  80. RESOURCES[resource_name][factory_id]['wage'] = calculate_wage(resource_name, factory)
  81. for i in range(factory['level'], 221, 5):
  82. new_factory_id = int(factory_id) + i - 150
  83. new_factory = copy.copy(factory)
  84. new_factory['level'] = i
  85. new_factory['name'] = i
  86. new_factory['wage'] = calculate_wage(resource_name, new_factory)
  87. RESOURCES[resource_name][str(new_factory_id)] = new_factory
  88. print_per_resource()
  89. # print_all()
  90. # print_factory_list()
  91. def print_json(json_text):
  92. """Print data to console"""
  93. print(json.dumps(json_text, sort_keys=True, indent=4))
  94. if __name__ == '__main__':
  95. main()