productivity.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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.profit_share = 75
  21. def calculate_wage(resource_name, factory):
  22. """Calculate production"""
  23. if 'fixed_wage' in factory:
  24. return factory['fixed_wage']
  25. resource = Item(resource_name)
  26. WP.resource = resource
  27. WP.factory_level = factory['level']
  28. WP.department_bonus = DEPARTMENTS[resource_name]
  29. WP.resource_max = REGIONS[str(factory['region_id'])]['resources'][resource_name]
  30. WP.wage_percentage = factory['wage_percentage']
  31. WP.tax_rate = REGIONS[str(factory['region_id'])]['tax'][resource_name]
  32. WP.calculate()
  33. return WP.wage() * PRICE[resource_name]
  34. def all_factories():
  35. """return all factories"""
  36. factory_dict = {}
  37. for factories in RESOURCES.values():
  38. factory_dict.update(factories)
  39. return factory_dict
  40. def print_per_resource():
  41. """Print wages per resource"""
  42. for resource_name, factories in RESOURCES.items():
  43. print(resource_name)
  44. for factory in sorted(factories.values(), key=lambda k: k['wage']):
  45. print('{}'.format(
  46. int(factory['wage']),
  47. ))
  48. def print_per_level():
  49. """Print wages per factory level"""
  50. factory_levels = {}
  51. for resource_name, factories in RESOURCES.items():
  52. for factory in sorted(factories.values(), key=lambda k: k['wage']):
  53. if factory['level'] not in factory_levels:
  54. factory_levels[factory['level']] = {}
  55. factory_levels[factory['level']][resource_name] = factory['wage']
  56. for level, resources in factory_levels.items():
  57. print('{},{},{},{},{}'.format(
  58. int(level),
  59. round(resources['oil']),
  60. round(resources['ore']),
  61. round(resources['uranium']),
  62. round(resources['diamond']),
  63. ))
  64. def print_all():
  65. """Print wages per resource"""
  66. factory_dict = all_factories()
  67. print("total")
  68. sorted_factories = sorted(factory_dict.values(), key=lambda k: k['wage'], reverse=True)
  69. top_wage = sorted_factories[0]['wage']
  70. for factory in sorted_factories:
  71. print('{:28} {:>11,} {:>3}'.format(
  72. factory['name'],
  73. int(factory['wage']),
  74. int(100 / top_wage * factory['wage']),
  75. ).replace(',', '.'))
  76. def print_factory_list():
  77. """print all factories"""
  78. for resource_name, factories in RESOURCES.items():
  79. print('[rr]{}[/rr]'.format(resource_name.capitalize()))
  80. for factory_id, factory in factories.items():
  81. print('[url=https://rivalregions.com/#factory/index/{}]Desktop[/url] [url=https://m.rivalregions.com/#factory/index/{}]Mobile[/url] {}, {} '.format(
  82. factory_id,
  83. factory_id,
  84. factory['name'],
  85. REGIONS[factory['region_id']]['name'],
  86. ))
  87. def main():
  88. """Main function"""
  89. for resource_name, factories in RESOURCES.items():
  90. factory = None
  91. factory_id = None
  92. for factory_id, factory in factories.items():
  93. factory = factory
  94. factory_id = factory_id
  95. RESOURCES[resource_name][factory_id]['wage'] = calculate_wage(resource_name, factory)
  96. for i in range(factory['level'], 221, 1):
  97. new_factory_id = int(factory_id) + i - 150
  98. new_factory = copy.copy(factory)
  99. new_factory['level'] = i
  100. new_factory['name'] = i
  101. new_factory['wage'] = calculate_wage(resource_name, new_factory)
  102. RESOURCES[resource_name][str(new_factory_id)] = new_factory
  103. #print_per_resource()
  104. print_per_level()
  105. # print_all()
  106. # print_factory_list()
  107. def print_json(json_text):
  108. """Print data to console"""
  109. print(json.dumps(json_text, sort_keys=True, indent=4))
  110. if __name__ == '__main__':
  111. main()