app.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. """Main application"""
  2. def print_resources(regions):
  3. """print resources"""
  4. print('region expl max D left c % t %')
  5. for region in regions.values():
  6. region['explored_percentage'] = 100 / region['maximum'] * region['explored']
  7. region['total_left'] = region['explored'] + region['limit_left']
  8. region['total_percentage'] = 100 / 2500 * region['total_left']
  9. print('{:25}: {:7.2f}{:4}{:4}{:5}{:7.2f}{:7.2f}'.format(
  10. region['region_name'],
  11. region['explored'],
  12. region['maximum'],
  13. region['deep_exploration'],
  14. region['limit_left'],
  15. region['explored_percentage'],
  16. region['total_percentage'],
  17. ))
  18. def need_refill(regions, limit):
  19. """Check if refill is needed"""
  20. for region in regions.values():
  21. percentage = 100 / region['maximum'] * region['explored']
  22. if percentage < limit and region['limit_left']:
  23. return True
  24. return False
  25. def max_refill_seconds(regions, limit, max_time):
  26. """Give random seconds for next refill"""
  27. lowest_percentage = limit
  28. for region in regions.values():
  29. percentage = 100 / region['maximum'] * region['explored']
  30. if percentage < lowest_percentage:
  31. lowest_percentage = percentage
  32. return int(max_time / limit * lowest_percentage)