factories.py 3.2 KB

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